Open MingweiSamuel opened 3 months ago
StartTraceA is what's returning error code 183 (File already exists). From the docs, this means:
ERROR_ALREADY_EXISTS
A session with the same name or GUID is already running.
We are using a session name, specifically KERNEL_LOGGER_NAME
There's a comment that explains why we use it:
// Build the trace properties, we want EVENT_TRACE_FLAG_PROFILE for the "SampledProfile" event
// https://docs.microsoft.com/en-us/windows/win32/etw/sampledprofile
// In https://docs.microsoft.com/en-us/windows/win32/etw/event-tracing-mof-classes that event is listed as a "kernel event"
// And https://docs.microsoft.com/en-us/windows/win32/etw/nt-kernel-logger-constants says
// "The NT Kernel Logger session is the only session that can accept events from kernel event providers."
// Therefore we must use GUID SystemTraceControlGuid/KERNEL_LOGGER_NAME as the session
Brieefly thinking about it, maybe we could store the session globally somewhere with refcounting to know when to close it. And then we'd need to modify the event_record_callback since it currently ignores all events except the ones for the target process, probably with some global array of process ids to filter. And then somehow correectly route the results to each trace.
The global session check would be around here and the event filtering here
Seems like Block until processing thread is done
for a specific process would have to be different if the session continues
Edit: I guess it is fine:
(Safeguard to make sure we don't deallocate the context before the other thread finishes using it)
Where does the const EVENT_TRACE_TYPE_LOAD: u8 = 10;
magic opcode number come from?
Edit: oh how obscure
[EventType(10, 2, 3, 4), EventTypeName("Load", "Unload", "DCStart", "DCEnd")]
https://learn.microsoft.com/en-us/windows/win32/etw/image-load#syntax
Minimal example:
Output