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.

247 lines
6.0 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Module list abstraction.
  4. //
  5. // Copyright (C) Microsoft Corporation, 2001-2002.
  6. //
  7. //----------------------------------------------------------------------------
  8. #ifndef __MODINFO_HPP__
  9. #define __MODINFO_HPP__
  10. //----------------------------------------------------------------------------
  11. //
  12. // ModuleInfo hierarchy.
  13. //
  14. //----------------------------------------------------------------------------
  15. // If the image header is paged out the true values for
  16. // certain fields cannot be retrieved. These placeholders
  17. // are used instead.
  18. #define UNKNOWN_CHECKSUM 0xffffffff
  19. #define UNKNOWN_TIMESTAMP 0xfffffffe
  20. typedef struct _MODULE_INFO_ENTRY
  21. {
  22. // NamePtr should include a path if one is available.
  23. // It is the responsibility of callers to find the
  24. // file tail if that's all they care about.
  25. // If UnicodeNamePtr is false NameLength is ignored.
  26. PSTR NamePtr;
  27. ULONG UnicodeNamePtr:1;
  28. ULONG ImageInfoValid:1;
  29. ULONG ImageInfoPartial:1;
  30. ULONG ImageDebugHeader:1;
  31. ULONG ImageVersionValid:1;
  32. ULONG ImageMachineTypeValid:1;
  33. ULONG UserMode:1;
  34. ULONG Unused:25;
  35. // Length in bytes not including the terminator.
  36. ULONG NameLength;
  37. PSTR ModuleName;
  38. HANDLE File;
  39. ULONG64 Base;
  40. ULONG Size;
  41. ULONG SizeOfCode;
  42. ULONG SizeOfData;
  43. ULONG CheckSum;
  44. ULONG TimeDateStamp;
  45. USHORT MajorImageVersion;
  46. USHORT MinorImageVersion;
  47. ULONG MachineType;
  48. PVOID DebugHeader;
  49. ULONG SizeOfDebugHeader;
  50. CHAR Buffer[MAX_IMAGE_PATH * sizeof(WCHAR)];
  51. } MODULE_INFO_ENTRY, *PMODULE_INFO_ENTRY;
  52. enum MODULE_INFO_LEVEL
  53. {
  54. // Only the base and size are guaranteed to be valid.
  55. MODULE_INFO_BASE_SIZE,
  56. // Attempt to retrieve all available information.
  57. MODULE_INFO_ALL,
  58. };
  59. class ModuleInfo
  60. {
  61. public:
  62. virtual HRESULT Initialize(ThreadInfo* Thread) = 0;
  63. virtual HRESULT GetEntry(PMODULE_INFO_ENTRY Entry) = 0;
  64. // Base implementation does nothing.
  65. // Updates the entry image info by reading the
  66. // image header.
  67. void ReadImageHeaderInfo(PMODULE_INFO_ENTRY Entry);
  68. void InitSource(ThreadInfo* Thread);
  69. TargetInfo* m_Target;
  70. MachineInfo* m_Machine;
  71. ProcessInfo* m_Process;
  72. ThreadInfo* m_Thread;
  73. MODULE_INFO_LEVEL m_InfoLevel;
  74. };
  75. class NtModuleInfo : public ModuleInfo
  76. {
  77. public:
  78. virtual HRESULT GetEntry(PMODULE_INFO_ENTRY Entry);
  79. protected:
  80. ULONG64 m_Head;
  81. ULONG64 m_Cur;
  82. };
  83. class NtKernelModuleInfo : public NtModuleInfo
  84. {
  85. public:
  86. virtual HRESULT Initialize(ThreadInfo* Thread);
  87. virtual HRESULT GetEntry(PMODULE_INFO_ENTRY Entry);
  88. };
  89. extern NtKernelModuleInfo g_NtKernelModuleIterator;
  90. class NtUserModuleInfo : public NtModuleInfo
  91. {
  92. public:
  93. virtual HRESULT Initialize(ThreadInfo* Thread);
  94. virtual HRESULT GetEntry(PMODULE_INFO_ENTRY Entry);
  95. protected:
  96. ULONG64 m_Peb;
  97. };
  98. class NtTargetUserModuleInfo : public NtUserModuleInfo
  99. {
  100. public:
  101. virtual HRESULT Initialize(ThreadInfo* Thread);
  102. };
  103. extern NtTargetUserModuleInfo g_NtTargetUserModuleIterator;
  104. class NtWow64UserModuleInfo : public NtUserModuleInfo
  105. {
  106. public:
  107. virtual HRESULT Initialize(ThreadInfo* Thread);
  108. private:
  109. HRESULT GetPeb32(PULONG64 Peb32);
  110. };
  111. extern NtWow64UserModuleInfo g_NtWow64UserModuleIterator;
  112. class DebuggerModuleInfo : public ModuleInfo
  113. {
  114. public:
  115. virtual HRESULT Initialize(ThreadInfo* Thread);
  116. virtual HRESULT GetEntry(PMODULE_INFO_ENTRY Entry);
  117. private:
  118. ImageInfo* m_Image;
  119. };
  120. extern DebuggerModuleInfo g_DebuggerModuleIterator;
  121. //
  122. // Define a generic maximum unloaded name length for all
  123. // callers of the unloaded iterators. This includes the terminator.
  124. //
  125. // Kernel mode dumps define a limit (MAX_UNLOADED_NAME_LENGTH) which
  126. // works out to 13 characters.
  127. //
  128. // User-mode is currently limited to 32 characters.
  129. //
  130. // Pick a value which exceeds both to allow room for either.
  131. //
  132. #define MAX_INFO_UNLOADED_NAME 32
  133. class UnloadedModuleInfo
  134. {
  135. public:
  136. virtual HRESULT Initialize(ThreadInfo* Thread) = 0;
  137. virtual HRESULT GetEntry(PSTR Name, PDEBUG_MODULE_PARAMETERS Params) = 0;
  138. void InitSource(ThreadInfo* Thread);
  139. TargetInfo* m_Target;
  140. MachineInfo* m_Machine;
  141. ProcessInfo* m_Process;
  142. ThreadInfo* m_Thread;
  143. };
  144. class NtKernelUnloadedModuleInfo : public UnloadedModuleInfo
  145. {
  146. public:
  147. virtual HRESULT Initialize(ThreadInfo* Thread);
  148. virtual HRESULT GetEntry(PSTR Name, PDEBUG_MODULE_PARAMETERS Params);
  149. protected:
  150. ULONG64 m_Base;
  151. ULONG m_Index;
  152. ULONG m_Count;
  153. };
  154. extern NtKernelUnloadedModuleInfo g_NtKernelUnloadedModuleIterator;
  155. class NtUserUnloadedModuleInfo : public UnloadedModuleInfo
  156. {
  157. public:
  158. virtual HRESULT Initialize(ThreadInfo* Thread);
  159. virtual HRESULT GetEntry(PSTR Name, PDEBUG_MODULE_PARAMETERS Params);
  160. protected:
  161. ULONG64 m_Base;
  162. ULONG m_Index;
  163. };
  164. extern NtUserUnloadedModuleInfo g_NtUserUnloadedModuleIterator;
  165. class ToolHelpModuleInfo : public ModuleInfo
  166. {
  167. public:
  168. virtual HRESULT Initialize(ThreadInfo* Thread);
  169. virtual HRESULT GetEntry(PMODULE_INFO_ENTRY Entry);
  170. protected:
  171. HANDLE m_Snap;
  172. BOOL m_First;
  173. ULONG m_LastId;
  174. };
  175. extern ToolHelpModuleInfo g_ToolHelpModuleIterator;
  176. //----------------------------------------------------------------------------
  177. //
  178. // Functions.
  179. //
  180. //----------------------------------------------------------------------------
  181. BOOL
  182. GetUserModuleListAddress(
  183. ThreadInfo* Thread,
  184. MachineInfo* Machine,
  185. ULONG64 Peb,
  186. BOOL Quiet,
  187. PULONG64 OrderModuleListStart,
  188. PULONG64 FirstEntry
  189. );
  190. BOOL
  191. GetModNameFromLoaderList(
  192. ThreadInfo* Thread,
  193. MachineInfo* Machine,
  194. ULONG64 Peb,
  195. ULONG64 ModuleBase,
  196. PSTR NameBuffer,
  197. ULONG BufferSize,
  198. BOOL FullPath
  199. );
  200. void
  201. ConvertLoaderEntry32To64(
  202. PKLDR_DATA_TABLE_ENTRY32 b32,
  203. PKLDR_DATA_TABLE_ENTRY64 b64
  204. );
  205. #endif // #ifndef __MODINFO_HPP__