Skip to main content

dr_enable_console_printing

Function dr_enable_console_printing 

Source
pub unsafe extern "C" fn dr_enable_console_printing() -> bool_
Expand description

Enables dr_printf() and dr_fprintf() to work with a legacy console window (viz., \p cmd on Windows 7 or earlier). Loads a private copy of kernel32.dll (if not already loaded) in order to accomplish this. To keep the default DR lean and mean, loading kernel32.dll is not performed by default.

This routine must be called during client initialization (\p dr_client_main()). If called later, it will fail.

Without calling this routine, dr_printf() and dr_fprintf() will not print anything in a console window on Windows 7 or earlier, nor will they print anything when running a graphical application.

Even after calling this routine, there are significant limitations to console printing support in DR:

  • On Windows versions prior to Vista, and for WOW64 applications on Vista, it does not work from the exit event. Once the application terminates its state with csrss (toward the very end of ExitProcess), no output will show up on the console. We have no good solution here yet as exiting early is not ideal.
  • In the future, with earliest injection (Issue 234), writing to the console may not work from the client init event on Windows 7 and earlier (it will work on Windows 8).

These limitations stem from the complex arrangement of the console window in Windows (prior to Windows 8), where printing to it involves sending a message in an undocumented format to the \p csrss process, rather than a simple write to a file handle. We recommend using a terminal window such as cygwin’s \p rxvt rather than the \p cmd window, or alternatively redirecting all output to a file, which will solve all of the above limitations.

Returns whether successful. \note Windows only.