Advertisement
CleverSnake

Intercept windows DebugView

Apr 24th, 2022
1,397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. # source: http://timgolden.me.uk/python/win32_how_do_i/capture-OutputDebugString.html
  2. import sys
  3. import mmap
  4. import struct
  5. import win32event
  6.  
  7. buffer_ready = win32event.CreateEvent (
  8.   None, 0, 0,
  9.   "DBWIN_BUFFER_READY"
  10. )
  11. data_ready = win32event.CreateEvent (
  12.   None, 0, 0,
  13.   "DBWIN_DATA_READY"
  14. )
  15. buffer = mmap.mmap (0, 4096, "DBWIN_BUFFER", mmap.ACCESS_WRITE)
  16.  
  17. while True:
  18.   #
  19.   # Signal that we're ready to accept debug output
  20.   #
  21.   win32event.SetEvent (buffer_ready)
  22.   if win32event.WaitForSingleObject (data_ready, win32event.INFINITE) == win32event.WAIT_OBJECT_0:
  23.     buffer.seek (0)
  24.     #
  25.     # The first DWORD is the process id which generated the output
  26.     #
  27.     process_id, = struct.unpack ("L", buffer.read (4))
  28.     data = buffer.read (4092)
  29.     if b"\0" in bytes(data):
  30.       string = data[:data.index (b"\0")]
  31.     else:
  32.       string = data
  33.  
  34.     print(f"Process {process_id}: {string}")
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement