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.

304 lines
5.7 KiB

  1. /*******************************************************************
  2. *
  3. * File : dnsexts.cxx
  4. * Author : Eyal Schwartz
  5. * Copyrights : Microsoft Corp (C) 1996
  6. * Date : 7/14/1998
  7. * Description : dnsext.dll debugger extension.
  8. *
  9. * Revisions : <date> <name> <description>
  10. *******************************************************************/
  11. #ifndef DNSEXTS_CXX
  12. #define DNSEXTS_CXX
  13. // include //
  14. // #include <dns.h>
  15. #include "common.h"
  16. #include "dump.hxx"
  17. #include "util.hxx"
  18. #include <ntverp.h>
  19. #include <string.h>
  20. // defines //
  21. // types //
  22. // global variables //
  23. PNTSD_EXTENSION_APIS glpExtensionApis=NULL;
  24. LPSTR glpArgumentString=NULL;
  25. HANDLE ghCurrentProcess=NULL;
  26. LPVOID gCurrentAllocation=NULL;
  27. // prototypes //
  28. INT GetDumpTableIndex(LPSTR szName);
  29. DWORD ExceptionHandler(DWORD dwException);
  30. // functions //
  31. /*+++
  32. Function : DllAttach
  33. Description: initializes the library upon attach
  34. Parameters : none.
  35. Return :
  36. Remarks : none.
  37. ---*/
  38. BOOL DllAttach(void)
  39. {
  40. INT i=0;
  41. BOOL bRet=TRUE;
  42. //
  43. // Nothing to do yet
  44. //
  45. return bRet;
  46. }
  47. /*+++
  48. Function : DllDetach
  49. Description: initializes the library upon attach
  50. Parameters : none.
  51. Return :
  52. Remarks : none.
  53. ---*/
  54. BOOL DllDetach(void)
  55. {
  56. BOOL bRet=TRUE;
  57. //
  58. // Nothing to do yet
  59. //
  60. return bRet;
  61. }
  62. /*+++
  63. Function : ExceptionHandler
  64. Description:
  65. Parameters :
  66. Return :
  67. Remarks : none.
  68. ---*/
  69. DWORD ExceptionHandler(DWORD dwException){
  70. Printf("Exception 0x%x: dnsexts exception failure\n", dwException);
  71. CleanMemory();
  72. return EXCEPTION_EXECUTE_HANDLER;
  73. }
  74. /*+++
  75. Function : help
  76. Description: dump usage
  77. Parameters : as specified in ntdsexts.h
  78. Return :
  79. Remarks : none.
  80. ---*/
  81. PNTSD_EXTENSION_ROUTINE (help)(
  82. HANDLE hCurrentProcess,
  83. HANDLE hCurrentThread,
  84. DWORD dwCurrentPc,
  85. PNTSD_EXTENSION_APIS lpExtensionApis,
  86. LPSTR lpArgumentString
  87. )
  88. {
  89. ASSIGN_NTSDEXTS_GLOBAL(lpExtensionApis, lpArgumentString, hCurrentProcess);
  90. Printf("dnsexts usage (version %s):\n", VER_PRODUCTVERSION_STR);
  91. Printf(" help: this help screen.\n");
  92. Printf(" dump <DATATYPE> <ADDRESS>: dumps structure at <address> in <DATATYPE> format.\n");
  93. Printf("---\n");
  94. return 0;
  95. }
  96. /*+++
  97. Function : GetDumpTableIndex
  98. Description: Get index into dump table if the entry by that name exist
  99. Parameters : szName: function name to find
  100. Return : -1 if failed, otherwise index value
  101. Remarks : none.
  102. ---*/
  103. INT GetDumpTableIndex(LPSTR szName)
  104. {
  105. INT i=0;
  106. for(i=0;i<gcbDumpTable; i++){
  107. if(!_stricmp(szName,gfDumpTable[i].szName)){
  108. return i;
  109. }
  110. }
  111. return -1;
  112. }
  113. /*+++
  114. Function : dump
  115. Description: dumps give data structure
  116. Parameters : as specified in ntdsexts.h
  117. Return :
  118. Remarks : command line gives structure name & hex value
  119. ---*/
  120. PNTSD_EXTENSION_ROUTINE (dump)(
  121. HANDLE hCurrentProcess,
  122. HANDLE hCurrentThread,
  123. DWORD dwCurrentPc,
  124. PNTSD_EXTENSION_APIS lpExtensionApis,
  125. LPSTR lpArgumentString
  126. )
  127. {
  128. __try{
  129. INT i=0; // generic index
  130. //
  131. // make interface availabe globally
  132. //
  133. ASSIGN_NTSDEXTS_GLOBAL(lpExtensionApis, lpArgumentString, hCurrentProcess);
  134. DEBUG1("DEBUG: Argstring=[%s]\n", lpArgumentString);
  135. //
  136. // process argument string
  137. //
  138. //
  139. // Format: DATATYPE ADDRESS
  140. //
  141. LPVOID lpVoid=0x0;
  142. const LPSTR cDelimiters=" \t";
  143. LPSTR szDataType = NULL, szAddress=NULL;
  144. if(NULL != (szDataType = strtok(lpArgumentString, cDelimiters)) &&
  145. NULL != (szAddress = strtok(NULL, cDelimiters)) &&
  146. NULL == strtok(NULL, cDelimiters) ||
  147. ((szDataType != NULL && szAddress == NULL && !_stricmp(szDataType,"HELP")))){
  148. //
  149. // Got all arguments
  150. //
  151. if(szAddress != NULL){
  152. lpVoid = (LPVOID)GetExpr(szAddress);
  153. }
  154. //
  155. // BUGBUG: DEBUG!
  156. //
  157. DEBUG1("DEBUG: szDataType=[%s]\n", szDataType);
  158. DEBUG1("DEBUG: szAddress=[%s]\n", szAddress);
  159. DEBUG1("DEBUG: lpVoid =[%p]\n", lpVoid);
  160. //
  161. // find in function table & call function
  162. //
  163. if(0 > (i = GetDumpTableIndex(szDataType))){
  164. Printf("Usage error: Cannot find function %s. Type dnsexts.dump help.\n", szDataType);
  165. }
  166. else{
  167. //
  168. // call function
  169. //
  170. BOOL bRet=TRUE;
  171. bRet = gfDumpTable[i].function(lpVoid);
  172. if(!bRet){
  173. Printf("Error: function %s failed\n", szDataType);
  174. }
  175. }
  176. }
  177. else{
  178. //
  179. // error
  180. //
  181. Printf("Usage error (2). Type dnsexts.dump help.\n");
  182. }
  183. } // try-except
  184. __except(ExceptionHandler(GetExceptionCode())){
  185. Printf("Aborting dump funtion\n");
  186. }
  187. return 0;
  188. }
  189. ////////////////////// ENTRY POINT //////////////////////
  190. /*+++
  191. Function : DllMain
  192. Description: <<<DLL entry point>>>
  193. Parameters : standard DllMain
  194. Return : init success bool
  195. Remarks : none.
  196. ---*/
  197. BOOL APIENTRY DllMain(HANDLE hModule,
  198. DWORD ul_reason_for_call,
  199. LPVOID lpReserved)
  200. {
  201. BOOL bRet = TRUE;
  202. switch( ul_reason_for_call ) {
  203. case DLL_PROCESS_ATTACH:
  204. bRet = DllAttach();
  205. break;
  206. case DLL_THREAD_ATTACH:
  207. break;
  208. case DLL_THREAD_DETACH:
  209. break;
  210. case DLL_PROCESS_DETACH:
  211. bRet = DllDetach();
  212. break;
  213. }
  214. return bRet;
  215. }
  216. #endif
  217. /******************* EOF *********************/