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.

244 lines
4.1 KiB

  1. #include "precomp.h"
  2. #ifdef TESTPROGRAM
  3. WINDBG_EXTENSION_APIS ExtensionApis;
  4. VOID
  5. WinDbgExtensionDllInit(
  6. PWINDBG_EXTENSION_APIS lpExtensionApis,
  7. USHORT MajorVersion,
  8. USHORT MinorVersion
  9. );
  10. //
  11. // dprintf (ExtensionApis.lpOutputRoutine)
  12. // GetExpression (ExtensionApis.lpGetExpressionRoutine)
  13. // GetSymbol (ExtensionApis.lpGetSymbolRoutine)
  14. // Disassm (ExtensionApis.lpDisasmRoutine)
  15. // CheckControlC (ExtensionApis.lpCheckControlCRoutine)
  16. // ReadMemory (ExtensionApis.lpReadProcessMemoryRoutine)
  17. // WriteMemory (ExtensionApis.lpWriteProcessMemoryRoutine)
  18. // GetContext (ExtensionApis.lpGetThreadContextRoutine)
  19. // SetContext (ExtensionApis.lpSetThreadContextRoutine)
  20. // Ioctl (ExtensionApis.lpIoctlRoutine)
  21. // StackTrace (ExtensionApis.lpStackTraceRoutine)
  22. //
  23. #if 0
  24. //
  25. // Dummy global vars for "GetExpression".
  26. //
  27. UINT g1;
  28. UINT g2;
  29. #endif // 0
  30. ULONG
  31. DummyMyGetExpression (
  32. PCSTR lpExpression
  33. );
  34. void setup_dummy_vars(void);
  35. ULONG
  36. WDBGAPI
  37. MyGetExpression (
  38. PCSTR lpExpression
  39. )
  40. {
  41. return DummyMyGetExpression(lpExpression);
  42. }
  43. ULONG
  44. WDBGAPI
  45. MyReadMemory (
  46. ULONG offset,
  47. PVOID lpBuffer,
  48. ULONG cb,
  49. PULONG lpcbBytesRead
  50. )
  51. {
  52. BOOL fRet = FALSE;
  53. _try
  54. {
  55. CopyMemory(lpBuffer, (void*)offset, cb);
  56. *lpcbBytesRead = cb;
  57. fRet = TRUE;
  58. }
  59. _except (EXCEPTION_EXECUTE_HANDLER)
  60. {
  61. MyDbgPrintf("Read memory exception at 0x%lu[%lu]\n", offset, cb);
  62. fRet = FALSE;
  63. }
  64. return fRet;
  65. }
  66. ULONG
  67. WDBGAPI
  68. MyWriteMemory(
  69. ULONG offset,
  70. LPCVOID lpBuffer,
  71. ULONG cb,
  72. PULONG lpcbBytesWritten
  73. )
  74. {
  75. BOOL fRet = FALSE;
  76. _try
  77. {
  78. CopyMemory((void*)offset, lpBuffer, cb);
  79. *lpcbBytesWritten = cb;
  80. fRet = TRUE;
  81. }
  82. _except (EXCEPTION_EXECUTE_HANDLER)
  83. {
  84. fRet = FALSE;
  85. }
  86. return fRet;
  87. }
  88. void test_walklist(void);
  89. int __cdecl main(
  90. int argc,
  91. char *argv[]
  92. )
  93. {
  94. UINT u=0;
  95. ExtensionApis.lpOutputRoutine = printf;
  96. ExtensionApis.lpGetExpressionRoutine = MyGetExpression;
  97. ExtensionApis.lpReadProcessMemoryRoutine = MyReadMemory;
  98. ExtensionApis.lpWriteProcessMemoryRoutine = MyWriteMemory;
  99. WinDbgExtensionDllInit(
  100. &ExtensionApis,
  101. 0xc, // MajorVersion,
  102. 0x0 // MinorVersion
  103. );
  104. //
  105. // This sets up some dummy global variables.
  106. //
  107. setup_dummy_vars();
  108. #if 0
  109. test_walklist();
  110. #else // 0
  111. do
  112. {
  113. char rgch[256];
  114. printf("> ");
  115. u = scanf("%[^\n]", rgch);
  116. if (!u || u==EOF) break;
  117. // printf("Input = [%s]\n", rgch);
  118. if (*rgch == 'q') break;
  119. do_aac(rgch);
  120. // skip past EOL
  121. {
  122. char c;
  123. u = scanf("%c", &c);
  124. }
  125. } while (u!=EOF);
  126. #endif // 0
  127. return 0;
  128. }
  129. typedef struct _LIST
  130. {
  131. struct _LIST *pNext;
  132. UINT uKey;
  133. } LIST;
  134. LIST L3 = {NULL, 0x4000};
  135. LIST L2 = {&L3, 0x3000};
  136. LIST L1 = {&L2, 0X2000};
  137. LIST L0 = {&L1, 0X1000};
  138. ULONG
  139. NodeFunc_DumpLIST (
  140. UINT_PTR uNodeAddr,
  141. UINT uIndex,
  142. void *pvContext
  143. )
  144. {
  145. LIST L;
  146. BOOL fRet = dbgextReadMemory(
  147. uNodeAddr,
  148. &L,
  149. sizeof(L),
  150. "LIST"
  151. );
  152. if (fRet)
  153. {
  154. MyDbgPrintf(
  155. "LIST[%lu]@0x%08lx = {Next=0x%08lx, Key=0x%lx}\n",
  156. uIndex,
  157. uNodeAddr,
  158. L.pNext,
  159. L.uKey
  160. );
  161. }
  162. return 0;
  163. }
  164. void test_walklist(void)
  165. {
  166. UINT uRet = 0;
  167. uRet = WalkList(
  168. (UINT_PTR) &L0,
  169. 0,
  170. 0, // 0 start
  171. -1,// -1 end
  172. NULL,
  173. //NodeFunc_DumpAddress,
  174. NodeFunc_DumpLIST,
  175. "Test list"
  176. );
  177. }
  178. ULONG
  179. DummyMyGetExpression (
  180. PCSTR lpExpression
  181. )
  182. {
  183. extern void *pvDummyAtmArpGlobalInfo;
  184. extern void *pvDummyAtmArpProtocolCharacteristics;
  185. extern void *pvDummyAtmArpClientCharacteristics;
  186. if (!lstrcmpi(lpExpression, "atmarpc!AtmArpGlobalInfo"))
  187. {
  188. return (ULONG) pvDummyAtmArpGlobalInfo;
  189. }
  190. if (!lstrcmpi(lpExpression, "atmarpc!AtmArpProtocolCharacteristics"))
  191. {
  192. return (ULONG) pvDummyAtmArpProtocolCharacteristics;
  193. }
  194. if (!lstrcmpi(lpExpression, "atmarpc!AtmArpClientCharacteristics"))
  195. {
  196. return (ULONG) pvDummyAtmArpClientCharacteristics;
  197. }
  198. return 0;
  199. }
  200. #endif // TESTPROGRAM