Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
3.3 KiB

  1. rwspy.dll uses detours (available at
  2. http://www.research.microsoft.com/sn/detours/ or
  3. \\bustard\contrib\galenh\detours) to spy on all file or device
  4. operations for the specified file in the process in which rwpsy.dll
  5. is injected. This is what rwspy.dll output looks like:
  6. Created '\\.\Usbscan0', handle: 1f0
  7. DeviceIoControl Code=80002018, 8 bytes in:
  8. 0000 B0 04 03 01 00 01 00 00 ........
  9. 8 bytes out:
  10. 0000 B0 04 03 01 00 01 00 00 ........
  11. Wrote 8 bytes:
  12. 0000 1B 43 02 00 04 43 FF FF .C...C..
  13. DeviceIoControl Code=8000201c, 4 bytes in:
  14. 0000 01 00 00 00 ....
  15. Read 94 bytes:
  16. 0000 03 00 58 00 10 00 00 00 00 00 00 00 00 00 00 00 ..X.............
  17. 0010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
  18. 0020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
  19. 0030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
  20. 0040 00 00 00 00 00 00 00 00 00 80 CF 03 00 70 1E 03 .............p..
  21. 0050 00 00 00 00 00 00 00 00 00 00 00 00 FF FF ..............
  22. Closed handle 1f0
  23. To build rwspy.dll you need detours.h and detours.lib. Either put
  24. them in this directory or modify 'sources' file.
  25. To use rwpsy.dll you'll also need either somehow inject it into target process.
  26. Detours has three samples for doing just this:
  27. a) setdll.exe /d:rwspy.dll <target binary>
  28. b) withdll.exe /d:rwpsy.dll <target command line>
  29. c) injdll.exe /d:rwspy.dll <target process id>
  30. spyon.cmd helps to use the third form.
  31. There are two registry entries controlling rwspy.dll behavior:
  32. REG_EXPAND_SZ at "HKLM\Software\Microsoft\RWSpy\Log File" specifies
  33. the log file to write. Default is %SystemRoot%\RWSpy.Log.
  34. REG_SZ at "HKLM\Software\Microsoft\RWSpy\FileToSpyOn" specifies the
  35. file to spy on. If this value is not set, RWSpy records all
  36. CreateFile() operations so you could verify if the process indeed
  37. CreateFile() the file or device you are interested in. If this entry
  38. is present (for instance, is set to \\.\UsbScan0), then RWSpy records
  39. all calls to
  40. CreateFile()
  41. ReadFile()
  42. WriteFile()
  43. FileIoControl()
  44. WriteFileEx()
  45. and (partially)
  46. ReadFileEx()
  47. Caveats of the current implementation:
  48. 1. Rwspy.dll has to be on path or in the current directory of the
  49. target process at the moment of injection. Detours can't diagnose the
  50. case when its remote thread can't load rwspy.dll. Please, use
  51. tlist.exe to make sure that rwspy.dll ineed is present in the target
  52. process.
  53. 2. You can only spy on one process at a time. We want to minimize
  54. timing disruptions induced by our spying, so our log file writing is
  55. intentionally thread-unsafe and because of this we open log file in
  56. SHARE_READ mode.
  57. 3. There is no way to stop spying while the target process is
  58. running. So if you spy on something like Explorer.exe, please, use
  59. kill.exe, but wait a few seconds for lazy log writing to flush out.
  60. 4. Since RWSPY.DLL reads as well as writes to HKLM\Software you have
  61. to have sufficient privileges to do so. (Your process have to have
  62. either Admin or SYSTEM privileges). If you have to run under lesser
  63. privileges, please feel free to modify PrepareLogger() function.
  64. If you have any questions or comments, please talk to me (akozlov).