microsoft / krabsetw

KrabsETW provides a modern C++ wrapper and a .NET wrapper around the low-level ETW trace consumption functions.
Other
588 stars 147 forks source link

A Way to do have a 'catch-all' callback function #147

Closed pathtofile closed 3 years ago

pathtofile commented 3 years ago

Sometimes you can subscribe to a provider, but the events received are for a different GUID. For example if you subscribe to a Provider Group. This currently can be annoying to debug, as Krabs will just silently drop these events.

It would be very useful to have some sort of 'catch-all' callback for a session, to receive events that aren't handled by the specified Krabs::Providers. Otherwise, it would be very useful for Krabs to print/log that there are events from a particular Provider GUID that are being dropped.

Possible Options could be:

If this is already sort possibly great, I'd love to know how :-)

jdu2600 commented 3 years ago

The EventTrace library has this feature - and it's very useful. :-)

Implementing a per-trace "catch all" callback is pretty straight forward - but I don't think it meets your entire requirement? i.e. it'll be called for all events, not just unhandled ones? Note - I already use GUID_NULL as a valid guid to match when handling WPP events...this is what TDH returns when a schema lookup fails. :-) See WppTrace001.cs I have a quick poc for this here - is this approach "good enough"?

The middle option is really the most useful - a callback to call only if no callbacks handle the event. However, I think this is an API breaking change. The callbacks are currently blindly called if the provider guid matches. They'll all need to return a (bool) indicator of whether they have handled the event or not.

jdu2600 commented 3 years ago

Actually, I misread your options. A callback to call if no providers are registered for that guid is more straightforward. I've updated the poc.

(I was originally envisioning checking to see if any filters for a given provider matched etc).

jdu2600 commented 3 years ago

Tidied it up and submitted a PR.

pathtofile commented 3 years ago

PR looks to provide what I was looking for (ha), lgtm

swannman commented 3 years ago

Resolved by #151. Thanks for submitting this @jdu2600!