09.02.2014 Views

Windows sysinternals

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Injecting Debug Output into Procmon Traces<br />

Chapter 4 Process Monitor 141<br />

Procmon provides an application programming interface (API) allowing developers to<br />

create debug output events that appear in the Procmon event stream with custom text. For<br />

example, you can inject custom debug output in the trace upon entering or exiting a function<br />

to correlate those activities with file, registry, or other events. By applying the Exclude<br />

Events Before and Exclude Events After filters on these debug events, you can easily focus<br />

on the areas of interest in your program. Unlike standard <strong>Windows</strong> debug output that is<br />

captured by DebugView (described in Chapter 7, “Process and Diagnostic Utilities”) or other<br />

debuggers, this interface specifically targets Procmon.<br />

These events appear as Debug Output Profiling operations and are part of the Profiling<br />

events class, along with Process Profiling and Thread Profiling events. Note that by default all<br />

Profiling events are filtered out. To see your debug output events, enable the Show Profiling<br />

Events toggle button on the toolbar. After doing so, you might also want to highlight Debug<br />

Output Profiling operations and exclude the display of Process Profiling operations. Figure<br />

4-33 shows debug output highlighted and interspersed with registry operations.<br />

FIGURE 4-33 Debug Output Profiling events.<br />

Any process, including one running at Low integrity, can use this interface, which accepts<br />

wide character (Unicode) text strings of up to 2048 characters in length. The following code<br />

sample demonstrates how to use the interface:<br />

#include <br />

#include <br />

const ULONG FILE_DEVICE_PROCMON_LOG = 0x00009535;<br />

const ULONG IOCTL_EXTERNAL_LOG_DEBUGOUT =<br />

(ULONG) CTL_CODE( FILE_DEVICE_PROCMON_LOG, 0x81, METHOD_BUFFERED, FILE_WRITE_ACCESS );<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!