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.

251 lines
5.1 KiB

  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. kdexts.c
  5. Abstract:
  6. This file contains the generic routines and initialization code
  7. for the kernel debugger extensions dll.
  8. Author:
  9. Nar Ganapathy - 9/21/99
  10. Environment:
  11. User Mode
  12. --*/
  13. #include <stdio.h>
  14. #include <windows.h>
  15. #include "wdbgexts.h"
  16. #include <ntverp.h>
  17. #include <imagehlp.h>
  18. //
  19. // globals
  20. //
  21. EXT_API_VERSION ApiVersion = { 3, 5, EXT_API_VERSION_NUMBER, 0 };
  22. WINDBG_EXTENSION_APIS ExtensionApis;
  23. ULONG STeip;
  24. ULONG STebp;
  25. ULONG STesp;
  26. USHORT SavedMajorVersion;
  27. USHORT SavedMinorVersion;
  28. ULONG NpDumpFlags = 0;
  29. extern VOID NpDump(IN PVOID Ptr);
  30. DllInit(
  31. HANDLE hModule,
  32. DWORD dwReason,
  33. DWORD dwReserved
  34. )
  35. {
  36. UNREFERENCED_PARAMETER( hModule );
  37. UNREFERENCED_PARAMETER( dwReserved );
  38. switch (dwReason) {
  39. case DLL_THREAD_ATTACH:
  40. break;
  41. case DLL_THREAD_DETACH:
  42. break;
  43. case DLL_PROCESS_DETACH:
  44. break;
  45. case DLL_PROCESS_ATTACH:
  46. break;
  47. }
  48. return TRUE;
  49. }
  50. VOID
  51. WinDbgExtensionDllInit(
  52. PWINDBG_EXTENSION_APIS lpExtensionApis,
  53. USHORT MajorVersion,
  54. USHORT MinorVersion
  55. )
  56. {
  57. ExtensionApis = *lpExtensionApis;
  58. SavedMajorVersion = MajorVersion;
  59. SavedMinorVersion = MinorVersion;
  60. return;
  61. }
  62. DECLARE_API( version )
  63. {
  64. #if DBG
  65. PCHAR DebuggerType = "Checked";
  66. #else
  67. PCHAR DebuggerType = "Free";
  68. #endif
  69. UNREFERENCED_PARAMETER( args );
  70. UNREFERENCED_PARAMETER( dwProcessor );
  71. UNREFERENCED_PARAMETER( dwCurrentPc );
  72. UNREFERENCED_PARAMETER( hCurrentThread );
  73. UNREFERENCED_PARAMETER( hCurrentProcess );
  74. dprintf( "%s Extension dll for Build %d debugging %s kernel for Build %d\n",
  75. DebuggerType,
  76. VER_PRODUCTBUILD,
  77. SavedMajorVersion == 0x0c ? "Checked" : "Free",
  78. SavedMinorVersion
  79. );
  80. }
  81. VOID
  82. CheckVersion(
  83. VOID
  84. )
  85. {
  86. #if DBG
  87. if ((SavedMajorVersion != 0x0c) || (SavedMinorVersion != VER_PRODUCTBUILD)) {
  88. dprintf("\r\n*** Extension DLL(%d Checked) does not match target system(%d %s)\r\n\r\n",
  89. VER_PRODUCTBUILD, SavedMinorVersion, (SavedMajorVersion==0x0f) ? "Free" : "Checked" );
  90. }
  91. #else
  92. if ((SavedMajorVersion != 0x0f) || (SavedMinorVersion != VER_PRODUCTBUILD)) {
  93. dprintf("\r\n*** Extension DLL(%d Free) does not match target system(%d %s)\r\n\r\n",
  94. VER_PRODUCTBUILD, SavedMinorVersion, (SavedMajorVersion==0x0f) ? "Free" : "Checked" );
  95. }
  96. #endif
  97. }
  98. LPEXT_API_VERSION
  99. ExtensionApiVersion(
  100. VOID
  101. )
  102. {
  103. return &ApiVersion;
  104. }
  105. BOOLEAN
  106. IsHexNumber(
  107. const char *szExpression
  108. )
  109. {
  110. if (!szExpression[0]) {
  111. return FALSE ;
  112. }
  113. for(;*szExpression; szExpression++) {
  114. if ((*szExpression)< '0') { return FALSE ; }
  115. else if ((*szExpression)> 'f') { return FALSE ; }
  116. else if ((*szExpression)>='a') { continue ; }
  117. else if ((*szExpression)> 'F') { return FALSE ; }
  118. else if ((*szExpression)<='9') { continue ; }
  119. else if ((*szExpression)>='A') { continue ; }
  120. else { return FALSE ; }
  121. }
  122. return TRUE ;
  123. }
  124. DECLARE_API(npcb)
  125. {
  126. ULONG_PTR ptrToDump;
  127. char ExprBuf[256] ;
  128. char FlagBuf[256] ;
  129. int ret;
  130. if (!*args) {
  131. dprintf("Usage: !npcb <pointer> <Flag>");
  132. return;
  133. }
  134. ExprBuf[0] = '\0' ;
  135. FlagBuf[0] = '\0' ;
  136. NpDumpFlags = 0;
  137. ret = sscanf(args,"%s %lx", ExprBuf, &NpDumpFlags);
  138. if (ret != EOF) {
  139. if (IsHexNumber(ExprBuf)) {
  140. ret = sscanf(ExprBuf, "%lx", &ptrToDump) ;
  141. if (ret == EOF) {
  142. ptrToDump = 0;
  143. }
  144. } else {
  145. ptrToDump = GetExpression( ExprBuf ) ;
  146. if (ptrToDump == 0) {
  147. dprintf("An error occured trying to evaluate the expression\n");
  148. return ;
  149. }
  150. }
  151. NpDump((PVOID)ptrToDump);
  152. } else {
  153. dprintf("An error occured trying to evaluate the expression\n");
  154. }
  155. }
  156. VOID
  157. NpfskdPrint(
  158. PCHAR String,
  159. ULONG_PTR Val
  160. )
  161. {
  162. dprintf("%-50s 0x%x\n",String, Val);
  163. }
  164. VOID
  165. NpfskdPrintString(
  166. PCHAR String1,
  167. PCHAR String2
  168. )
  169. {
  170. dprintf("%-50s %s\n",String1, String2);
  171. }
  172. VOID
  173. NpfskdPrintWideString(
  174. PWCHAR String1,
  175. PWCHAR String2
  176. )
  177. {
  178. dprintf("%-50S %S\n",String1, String2);
  179. }
  180. BOOLEAN
  181. NpfskdReadMemory(
  182. PVOID TargetPtr,
  183. PVOID LocalPtr,
  184. ULONG Length
  185. )
  186. {
  187. ULONG Result;
  188. if (!ReadMemory((ULONG_PTR)TargetPtr, LocalPtr, Length, &Result)) {
  189. dprintf("Cannot read memory at 0x%x\n", TargetPtr);
  190. return FALSE;
  191. }
  192. if (Result != Length) {
  193. dprintf("Expected length 0x%x != Actual length 0x%x\n", Length, Result);
  194. return FALSE;
  195. }
  196. return TRUE;
  197. }
  198. ULONG
  199. NpfskdCheckControlC()
  200. {
  201. return (CheckControlC());
  202. }