1
0

ntusrsup.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. /*++
  2. Copyright (c) 2013 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. ntusrsup.h
  9. Abstract:
  10. This header contains definitions for the Win32 private interface for
  11. supporting user mode debugging. This go-between interface is needed because
  12. the debug protocol headers don't include well with Win32 headers.
  13. Author:
  14. Evan Green 4-Jun-2013
  15. --*/
  16. //
  17. // ------------------------------------------------------------------- Includes
  18. //
  19. //
  20. // ---------------------------------------------------------------- Definitions
  21. //
  22. //
  23. // ------------------------------------------------------ Data Type Definitions
  24. //
  25. typedef enum _NT_DEBUGGER_EVENT_TYPE {
  26. NtDebuggerEventInvalid,
  27. NtDebuggerEventBreak,
  28. NtDebuggerEventShutdown,
  29. } NT_DEBUGGER_EVENT_TYPE, *PNT_DEBUGGER_EVENT_TYPE;
  30. typedef enum _NT_EXCEPTION_TYPE {
  31. NtExceptionInvalid,
  32. NtExceptionDebugBreak,
  33. NtExceptionSingleStep,
  34. NtExceptionAssertionFailure,
  35. NtExceptionAccessViolation,
  36. NtExceptionUnknown
  37. } NT_EXCEPTION_TYPE, *PNT_EXCEPTION_TYPE;
  38. typedef struct _NT_X86_REGISTERS {
  39. DWORD SegGs;
  40. DWORD SegFs;
  41. DWORD SegEs;
  42. DWORD SegDs;
  43. DWORD Edi;
  44. DWORD Esi;
  45. DWORD Ebx;
  46. DWORD Edx;
  47. DWORD Ecx;
  48. DWORD Eax;
  49. DWORD Ebp;
  50. DWORD Eip;
  51. DWORD SegCs;
  52. DWORD EFlags;
  53. DWORD Esp;
  54. DWORD SegSs;
  55. } NT_X86_REGISTERS, *PNT_X86_REGISTERS;
  56. typedef struct _NT_DEBUGGER_EVENT {
  57. NT_DEBUGGER_EVENT_TYPE Type;
  58. NT_EXCEPTION_TYPE Exception;
  59. ULONG ThreadNumber;
  60. ULONG ThreadCount;
  61. ULONG LoadedModuleCount;
  62. ULONGLONG LoadedModuleSignature;
  63. PVOID InstructionPointer;
  64. BYTE InstructionStream[16];
  65. NT_X86_REGISTERS Registers;
  66. ULONG Process;
  67. ULONG ExitCode;
  68. } NT_DEBUGGER_EVENT, *PNT_DEBUGGER_EVENT;
  69. //
  70. // -------------------------------------------------------------------- Globals
  71. //
  72. //
  73. // -------------------------------------------------------- Function Prototypes
  74. //
  75. BOOL
  76. DbgpNtLaunchChildProcess (
  77. ULONG ArgumentCount,
  78. PSTR *Arguments
  79. );
  80. /*++
  81. Routine Description:
  82. This routine launches a new child process to be debugged.
  83. Arguments:
  84. ArgumentCount - Supplies the number of command line arguments for the
  85. executable.
  86. Arguments - Supplies the array of arguments to pass.
  87. Return Value:
  88. TRUE on success.
  89. FALSE on failure.
  90. --*/
  91. BOOL
  92. DbgpNtUserContinue (
  93. ULONG SignalToDeliver
  94. );
  95. /*++
  96. Routine Description:
  97. This routine sends the "go" command to the target, signaling to continue
  98. execution.
  99. Arguments:
  100. SignalToDeliver - Supplies the signal number to actually send to the
  101. application. For kernel debugging, this parameter is ignored.
  102. Return Value:
  103. Returns TRUE if successful, or FALSE if there was an error.
  104. --*/
  105. BOOL
  106. DbgpNtUserSetRegisters (
  107. PNT_X86_REGISTERS Registers
  108. );
  109. /*++
  110. Routine Description:
  111. This routine sets the registers of the debugging target.
  112. Arguments:
  113. Registers - Supplies a pointer to the registers to set. All register values
  114. will be written.
  115. Return Value:
  116. Returns TRUE if successful, or FALSE if there was an error.
  117. --*/
  118. BOOL
  119. DbgpNtUserSingleStep (
  120. ULONG SignalToDeliver
  121. );
  122. /*++
  123. Routine Description:
  124. This routine steps the target by one instruction.
  125. Arguments:
  126. SignalToDeliver - Supplies the signal number to actually send to the
  127. application. For kernel debugging, this parameter is ignored.
  128. Return Value:
  129. Returns TRUE if successful, or FALSE if there was an error.
  130. --*/
  131. BOOL
  132. DbgpNtUserWaitForEvent (
  133. PNT_DEBUGGER_EVENT Event
  134. );
  135. /*++
  136. Routine Description:
  137. This routine gets an event from the target, such as a break event or other
  138. exception.
  139. Arguments:
  140. Event - Supplies a pointer where the event details will be returned.
  141. Return Value:
  142. Returns TRUE on success, or FALSE on failure.
  143. --*/
  144. BOOL
  145. DbgpNtUserReadWriteMemory (
  146. BOOL WriteOperation,
  147. BOOL VirtualMemory,
  148. ULONGLONG Address,
  149. PVOID Buffer,
  150. ULONG BufferSize,
  151. PULONG BytesCompleted
  152. );
  153. /*++
  154. Routine Description:
  155. This routine retrieves or writes to the target's memory.
  156. Arguments:
  157. WriteOperation - Supplies a flag indicating whether this is a read
  158. operation (FALSE) or a write operation (TRUE).
  159. VirtualMemory - Supplies a flag indicating whether the memory accessed
  160. should be virtual or physical.
  161. Address - Supplies the address to read from or write to in the target's
  162. memory.
  163. Buffer - Supplies a pointer to the buffer where the memory contents will be
  164. returned for read operations, or supplies a pointer to the values to
  165. write to memory on for write operations.
  166. BufferSize - Supplies the size of the supplied buffer, in bytes.
  167. BytesCompleted - Supplies a pointer that receive the number of bytes that
  168. were actually read from or written to the target.
  169. Return Value:
  170. Returns TRUE if the operation was successful.
  171. FALSE if there was an error.
  172. --*/
  173. BOOL
  174. DbgpNtUserGetThreadList (
  175. PULONG ThreadCount,
  176. PULONG *ThreadIds
  177. );
  178. /*++
  179. Routine Description:
  180. This routine gets the list of active threads in the process (or active
  181. processors in the machine for kernel mode).
  182. Arguments:
  183. ThreadCount - Supplies a pointer where the number of threads will be
  184. returned on success.
  185. ThreadIds - Supplies a pointer where an array of thread IDs (or processor
  186. numbers) will be returned on success. It is the caller's responsibility
  187. to free this memory.
  188. Return Value:
  189. Returns TRUE if successful, FALSE on failure.
  190. --*/
  191. BOOL
  192. DbgpNtUserSwitchThread (
  193. ULONG ThreadId,
  194. PNT_DEBUGGER_EVENT NewBreakInformation
  195. );
  196. /*++
  197. Routine Description:
  198. This routine switches the debugger to another thread.
  199. Arguments:
  200. ThreadId - Supplies the ID of the thread to switch to.
  201. NewBreakInformation - Supplies a pointer where the updated break information
  202. will be returned.
  203. Return Value:
  204. Returns TRUE if successful, or FALSE if there was no change.
  205. --*/
  206. BOOL
  207. DbgpNtUserGetImageDetails (
  208. PSTR *ImageName,
  209. PVOID *Base,
  210. PVOID *LowestAddress,
  211. PULONGLONG Size
  212. );
  213. /*++
  214. Routine Description:
  215. This routine retrieves information about where the primary image of the
  216. process was loaded.
  217. Arguments:
  218. ImageName - Supplies a pointer where a string will be returned containing
  219. the image name. The caller does not own this memory after it's returned,
  220. and should not modify or free it.
  221. Base - Supplies a pointer where the image base will be returned.
  222. LowestAddress - Supplies a pointer where the loaded lowest address of the
  223. image will be returned.
  224. Size - Supplies a pointer where the size of the image in bytes will be
  225. returned.
  226. Return Value:
  227. Returns TRUE on success, or FALSE on failure.
  228. --*/
  229. VOID
  230. DbgpNtUserRequestBreakIn (
  231. VOID
  232. );
  233. /*++
  234. Routine Description:
  235. This routine attempts to stop the running target.
  236. Arguments:
  237. None.
  238. Return Value:
  239. None.
  240. --*/
  241. BOOL
  242. DbgpNtGetLoadedModuleList (
  243. PMODULE_LIST_HEADER *ModuleList
  244. );
  245. /*++
  246. Routine Description:
  247. This routine retrieves the list of loaded binaries from the kernel
  248. debugging target.
  249. Arguments:
  250. ModuleList - Supplies a pointer where a pointer to the loaded module header
  251. and subsequent array of entries will be returned. It is the caller's
  252. responsibility to free this allocated memory when finished.
  253. Return Value:
  254. Returns TRUE on success, or FALSE on failure.
  255. --*/