Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7489167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:12:33+00:00 2026-05-29T15:12:33+00:00

i am trying to listen to ETW kernel events. Step 1: Call OpenTrace ,

  • 0

i am trying to listen to ETW kernel events.

  • Step 1: Call OpenTrace, specifying the EventCallback and optional BufferCallback functions that will be called during my call to ProcessTrace:

    var
        logFile: EVENT_TRACE_LOGFILE;
        currentTrace: TRACEHANDLE;
    begin
        ZeroMemory(@logFile, sizeof(logFile));
    
        logFile.LoggerName := KERNEL_LOGGER_NAME;
        logFile.LogFileName := 'C:\Users\Ian\foo.etl';
        logFile.ProcessTraceMode := 0;
        logFile.EventCallback := RealtimeEventCallback;
        logFile.BufferCallback := BufferCallback; //optional
    
        currentTrace := OpenTrace(@logFile);
        if (currentTrace = INVALID_PROCESSTRACE_HANDLE) or (currentTrace = -1) then
               RaiseLastWin32Error();
    
  • Step 2: Enable kernel events. This is done by calling StartTrace. In my case i want to trace kernel interrupts (EVENT_TRACE_FLAG_INTERRUPT) and deferred procedure calls (EVENT_TRACE_FLAG_DPC):

    var
        sessionProperties: PEVENT_TRACE_PROPERTIES;
        bufferSize: Int64;
        th: TRACEHANDLE;
        loggerName: string;
        logFilePath: string;
    begin
        loggerName := KERNEL_LOGGER_NAME;
        logFilePath := 'C:\Users\Ian\foo.etl';
    
        bufferSize := sizeof(EVENT_TRACE_PROPERTIES)
            + 1024 //maximum session name is 1024 characters
            + 1024; //maximum log file name is 1024 characters
    
        sessionProperties := AllocMem(bufferSize);
        ZeroMemory(sessionProperties, bufferSize);
    
        sessionProperties.Wnode.BufferSize := bufferSize;
        sessionProperties.Wnode.ClientContext := 1; //QPC clock resolution
        sessionProperties.Wnode.Flags := WNODE_FLAG_TRACED_GUID;
        sessionProperties.Wnode.Guid := SystemTraceControlGuid;
        sessionProperties.EnableFlags := EVENT_TRACE_FLAG_INTERRUPT or EVENT_TRACE_FLAG_DPC;
        sessionProperties.LogFileMode := EVENT_TRACE_FILE_MODE_CIRCULAR;
        sessionProperties.MaximumFileSize := 5;  // 5 MB
        sessionProperties.LoggerNameOffset := sizeof(EVENT_TRACE_PROPERTIES);
        sessionProperties.LogFileNameOffset := sizeof(EVENT_TRACE_PROPERTIES)+1024;
    
        //Copy LoggerName to the offset address
        MoveMemory(Pointer(Cardinal(sessionProperties)+sessionProperties.LoggerNameOffset), PChar(loggerName), Length(loggerName)+1);
    
        //Copy LogFilePath to the offset address
        MoveMemory(Pointer(Cardinal(sessionProperties)+sessionProperties.LogFileNameOffset), PChar(logFilePath), Length(logFilePath)+1);
    
        hr := StartTrace({var}th, PChar(loggerName), sessionProperties);
        if (hr <> ERROR_SUCCESS) then
              raise EWin32Error.Create(SysErrorMessage(hr));
    

    And the log is started sucessfully (i can see foo.etl begin to grow to its 5 MB circuluar limit).

  • Step 3: Call ProcessTrace, which blocks until it has delivered all pending events to the EventCallback handler specified in Step 1:

    var
       res: LongWord;
    begin
       res := EventTrace.ProcessTrace(@currentTrace, 1, nil, nil);
       if (res <> ERROR_SUCCESS) then
          raise EWin32Error.Create(SysErrorMessage(res));
    

Except that ProcessTrace repeatedly returns immediately, and no callback is called – even though the etl file is present and growing.


If i change the logging from File Based to Realtime logging:

  • Step 1 – OpenTrace changes to support realtime:

    logFile.ProcessTraceMode := PROCESS_TRACE_MODE_REAL_TIME;
    
  • Step 2 – StartTrace changes to support realtime:

    sessionProperties.LogFileMode := EVENT_TRACE_REAL_TIME_MODE;
    

In this case ProcessTrace never returns, but neither EventCallback or BufferCallback are ever called.

What am i doing wrong?


Update: My callback functions:

function BufferCallback(Logfile: PEVENT_TRACE_LOGFILE): LongWord; stdcall;
begin
   ShowMessage('BufferCallback');
   Result := 1; //return true to keep processing rows
end;

procedure RealtimeEventCallback(pEvent: PEVENT_TRACE); stdcall;
begin
   ShowMessage('EventCallback');
   nEvents := nEvents+1;
end;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T15:12:34+00:00Added an answer on May 29, 2026 at 3:12 pm

    i found the problem.

    The headers i was using were not quad-word aligned.

    In Delphi parlance, the keyword packed was being used.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to find the correct event to listen for that will ensure that
I am trying to create a UDP listener that will listen on a separate
I'm trying to develop an agent/client that will listen to HTTP requests on a
I am trying to write a python application that will listen for HTTP responses
I'm trying to make my own application that will listen to the media-keys in
I am trying to implement an app that will only listen for a certain
I am trying to listen tab-in tab-out action for my swing gui that is
I am trying to listen to mouse events coming from both a JLabel and
I'm trying to figure out how I can listen to the Cancel button that
I'm trying to figure out how I can listen to the Cancel button that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.