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.

222 lines
6.1 KiB

  1. /*++
  2. Copyright (c) 2000-2001 Microsoft Corporation
  3. Module Name:
  4. wmiexts.h
  5. Author:
  6. Ivan Brugiolo
  7. Revision History:
  8. --*/
  9. # ifndef _WMIEXTS_H_
  10. # define _WMIEXTS_H_
  11. #ifdef _WIN64
  12. #define KDEXT_64BIT
  13. #else
  14. #define KDEXT_32BIT
  15. #endif
  16. #ifdef KDEXT_64BIT
  17. #define MEMORY_ADDRESS ULONG64
  18. #else
  19. #define MEMORY_ADDRESS ULONG_PTR
  20. #endif
  21. #include <nt.h>
  22. #include <ntrtl.h>
  23. #include <nturtl.h>
  24. #include <ntexapi.h>
  25. #ifdef PowerSystemMaximum
  26. #undef PowerSystemMaximum
  27. #endif
  28. #include <windows.h>
  29. #include <wdbgexts.h>
  30. #define STRSAFE_NO_DEPRECATE
  31. #include <strsafe.h>
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. #include <string.h>
  35. #include <wchar.h>
  36. #include <stdlib.h>
  37. //
  38. // To obtain the private & protected members of C++ class,
  39. // fake the "private" keyword
  40. //
  41. #define private public
  42. #define protected public
  43. //
  44. // Turn off dllexp et al so this DLL won't export tons of unnecessary garbage.
  45. //
  46. /************************************************************
  47. * Macro Definitions
  48. ************************************************************/
  49. extern WINDBG_EXTENSION_APIS ExtensionApis;
  50. extern HANDLE ExtensionCurrentProcess;
  51. extern USHORT g_MajorVersion;
  52. extern USHORT g_MinorVersion;
  53. extern BOOL g_KD;
  54. #define moveBlock(dst, src, size)\
  55. __try {\
  56. ReadMemory( (ULONG_PTR)(src), (PVOID)&(dst), (size), NULL);\
  57. } __except (EXCEPTION_EXECUTE_HANDLER) {\
  58. return;\
  59. }
  60. #define MoveWithRet(dst, src, retVal)\
  61. __try {\
  62. ReadMemory( (ULONG_PTR)(src), (PVOID)&(dst), sizeof(dst), NULL);\
  63. } __except (EXCEPTION_EXECUTE_HANDLER) {\
  64. return retVal;\
  65. }
  66. #define MoveBlockWithRet(dst, src, size, retVal)\
  67. __try {\
  68. ReadMemory( (ULONG_PTR)(src), (PVOID)&(dst), (size), NULL);\
  69. } __except (EXCEPTION_EXECUTE_HANDLER) {\
  70. return retVal;\
  71. }
  72. #ifdef _WIN64
  73. #define INIT_API() \
  74. LPSTR lpArgumentString = (LPSTR)args; \
  75. ExtensionCurrentProcess = hCurrentProcess;
  76. #else
  77. #define INIT_API() \
  78. LPSTR lpArgumentString = (LPSTR)args; \
  79. ExtensionCurrentProcess = hCurrentProcess; \
  80. if (ExtensionApis.nSize != sizeof(WINDBG_EXTENSION_APIS)){ \
  81. WINDBG_OLD_EXTENSION_APIS * pOld = (WINDBG_OLD_EXTENSION_APIS *)&ExtensionApis; \
  82. *pOld = *((WINDBG_OLD_EXTENSION_APIS *)dwProcessor); \
  83. }
  84. #endif
  85. # define BoolValue( b) ((b) ? " TRUE" : " FALSE")
  86. #define DumpDword( symbol ) \
  87. { \
  88. ULONG_PTR dw = 0; \
  89. if (ExtensionApis.nSize != sizeof(WINDBG_EXTENSION_APIS)){ \
  90. dw = GetExpression( "&" symbol ); \
  91. } else { \
  92. dw = GetExpression( symbol ); \
  93. }; \
  94. \
  95. ULONG_PTR dwValue = 0; \
  96. if ( dw ) \
  97. { \
  98. if ( ReadMemory( (ULONG_PTR) dw, \
  99. &dwValue, \
  100. sizeof(dwValue), \
  101. NULL )) \
  102. { \
  103. dprintf( "\t" symbol " = %8d (0x%p)\n", \
  104. dwValue, \
  105. dwValue ); \
  106. } \
  107. } \
  108. }
  109. //
  110. // C++ Structures typically require the constructors and most times
  111. // we may not have default constructors
  112. // => trouble in defining a copy of these struct/class inside the
  113. // Debugger extension DLL for debugger process
  114. // So we will define them as CHARACTER arrays with appropriate sizes.
  115. // This is okay, since we are not really interested in structure as is,
  116. // however, we will copy over data block from the debuggee process to
  117. // these structure variables in the debugger process.
  118. //
  119. # define DEFINE_CPP_VAR( className, classVar) \
  120. CHAR classVar[sizeof(className)]
  121. # define GET_CPP_VAR_PTR( className, classVar) \
  122. (className * ) &classVar
  123. //
  124. //
  125. // commonly used functions
  126. //
  127. ////////////////////////////////////////////////////////////////
  128. void GetPeb(HANDLE hSourceProcess, PEB ** ppPeb, ULONG_PTR * pId = NULL);
  129. void GetTeb(HANDLE hThread,TEB ** ppTeb);
  130. void GetCid(HANDLE hThread,CLIENT_ID * pCid);
  131. void PrintStackTrace(MEMORY_ADDRESS ArrayAddr_OOP,DWORD dwNum,BOOL bOOP);
  132. #ifndef KDEXT_64BIT
  133. /**
  134. Routine to get offset of a "Field" of "Type" on a debugee machine. This uses
  135. Ioctl call for type info.
  136. Returns 0 on success, Ioctl error value otherwise.
  137. **/
  138. __inline
  139. ULONG
  140. GetFieldOffset (
  141. IN LPCSTR Type,
  142. IN LPCSTR Field,
  143. OUT PULONG pOffset
  144. )
  145. {
  146. FIELD_INFO flds = {
  147. (PUCHAR)Field,
  148. (PUCHAR)"",
  149. 0,
  150. DBG_DUMP_FIELD_FULL_NAME | DBG_DUMP_FIELD_RETURN_ADDRESS,
  151. 0,
  152. NULL};
  153. SYM_DUMP_PARAM Sym = {
  154. sizeof (SYM_DUMP_PARAM),
  155. (PUCHAR)Type,
  156. DBG_DUMP_NO_PRINT,
  157. 0,
  158. NULL,
  159. NULL,
  160. NULL,
  161. 1,
  162. &flds
  163. };
  164. ULONG Err;
  165. Sym.nFields = 1;
  166. Err = Ioctl( IG_DUMP_SYMBOL_INFO, &Sym, Sym.size );
  167. *pOffset = (ULONG) (flds.address - Sym.addr);
  168. return Err;
  169. }
  170. #endif
  171. # endif // _WMIEXTS_H_