Leaked source code of windows server 2003
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.

235 lines
4.3 KiB

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