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.

274 lines
12 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 2000
  6. //
  7. // File: moduleinfo.h
  8. //
  9. //--------------------------------------------------------------------------
  10. // ModuleInfo.h: interface for the CModuleInfo class.
  11. //
  12. //////////////////////////////////////////////////////////////////////
  13. #if !defined(AFX_MODULEINFO_H__0D2E8509_A01A_11D2_83A8_000000000000__INCLUDED_)
  14. #define AFX_MODULEINFO_H__0D2E8509_A01A_11D2_83A8_000000000000__INCLUDED_
  15. #if _MSC_VER > 1000
  16. #pragma once
  17. #endif // _MSC_VER > 1000
  18. #ifndef NO_STRICT
  19. #ifndef STRICT
  20. #define STRICT 1
  21. #endif
  22. #endif /* NO_STRICT */
  23. #include <windows.h>
  24. #include <tchar.h>
  25. #include <time.h>
  26. #include <stdlib.h>
  27. #include "globals.h"
  28. //
  29. //#include "oemdbi.h"
  30. //
  31. // Bug MSINFO V4.1:655
  32. #define PDB_LIBRARY
  33. #pragma warning( push )
  34. #pragma warning( disable : 4201 ) // Disable "nonstandard extension used : nameless struct/union" warning
  35. #include "PDB.H"
  36. #pragma warning( pop ) // Enable
  37. const ULONG sigRSDS = 'SDSR';
  38. const ULONG sigNB09 = '90BN';
  39. const ULONG sigNB10 = '01BN';
  40. const ULONG sigNB11 = '11BN';
  41. // Forward declarations
  42. //class CProgramOptions;
  43. class CSymbolVerification;
  44. class CFileData;
  45. class CDmpFile;
  46. class CModuleInfo
  47. {
  48. // Definition of Class Constants
  49. enum { MAX_SEARCH_PATH_LEN=512 };
  50. // CodeView Debug OMF signature. The signature at the end of the file is
  51. // a negative offset from the end of the file to another signature. At
  52. // the negative offset (base address) is another signature whose filepos
  53. // field points to the first OMFDirHeader in a chain of directories.
  54. // The NB05 signature is used by the link utility to indicated a completely
  55. // unpacked file. The NB06 signature is used by ilink to indicate that the
  56. // executable has had CodeView information from an incremental link appended
  57. // to the executable. The NB08 signature is used by cvpack to indicate that
  58. // the CodeView Debug OMF has been packed. CodeView will only process
  59. // executables with the NB08 signature.
  60. typedef struct OMFSignature
  61. {
  62. char Signature[4]; // "NBxx"
  63. long filepos; // offset in file
  64. };
  65. typedef struct PDB_INFO
  66. {
  67. unsigned long sig;
  68. unsigned long age;
  69. char sz[_MAX_PATH];
  70. };
  71. //
  72. // These types are likely to be defined in a header file I include later for the latest
  73. // OEMDBI toolkit...
  74. //
  75. struct NB10I // NB10 debug info
  76. {
  77. DWORD nb10; // NB10
  78. DWORD off; // offset, always 0
  79. DWORD sig;
  80. DWORD age;
  81. };
  82. struct RSDSI // RSDS debug info
  83. {
  84. DWORD rsds; // RSDS
  85. GUID guidSig;
  86. DWORD age;
  87. };
  88. public:
  89. CModuleInfo();
  90. virtual ~CModuleInfo();
  91. bool GoodSymbolNotFound();
  92. bool SetPEImageModuleName(LPTSTR tszNewModuleName);
  93. bool SetPEImageModulePath(LPTSTR tszNewPEImageModulePath);
  94. bool SetDebugDirectoryDBGPath(LPTSTR tszNewDebugDirectoryDBGPath);
  95. bool SetPEDebugDirectoryPDBPath(LPTSTR tszNewDebugDirectoryPDBPath);
  96. bool Initialize(CFileData * lpInputFile, CFileData * lpOutputFile, CDmpFile * lpDmpFile);
  97. bool SetModulePath(LPTSTR tszModulePath);
  98. bool VerifySymbols(CSymbolVerification * lpSymbolVerification);
  99. static BOOL VerifyDBGFile(HANDLE hFileHandle, LPTSTR tszFileName, PVOID CallerData);
  100. static BOOL VerifyPDBFile(HANDLE hFileHandle, LPTSTR tszFileName, PVOID CallerData);
  101. bool OutputData(LPTSTR tszProcessName, DWORD iProcessID, unsigned int dwModuleNumber);
  102. bool GetModuleInfo(LPTSTR tszModulePath, bool fDmpFile = false, DWORD64 dw64ModAddress = 0, bool fGetDataFromCSVFile = false);
  103. LPTSTR GetModulePath();
  104. enum SymbolModuleStatus { SYMBOL_NOT_FOUND, SYMBOL_MATCH, SYMBOL_POSSIBLE_MISMATCH, SYMBOL_INVALID_FORMAT, SYMBOL_NO_HELPER_DLL };
  105. enum SymbolInformationForPEImage {SYMBOL_INFORMATION_UNKNOWN, SYMBOLS_NO, SYMBOLS_LOCAL, SYMBOLS_DBG, SYMBOLS_DBG_AND_PDB, SYMBOLS_PDB};
  106. // INLINE Methods!
  107. inline enum SymbolInformationForPEImage GetPESymbolInformation() { return m_enumPEImageSymbolStatus; };
  108. inline enum SymbolModuleStatus GetDBGSymbolModuleStatus() { return m_enumDBGModuleStatus; };
  109. inline enum SymbolModuleStatus GetPDBSymbolModuleStatus() { return m_enumPDBModuleStatus; };
  110. inline DWORD GetRefCount() { return m_dwRefCount; };
  111. inline DWORD AddRef() { return InterlockedIncrement((long *)&m_dwRefCount); };
  112. inline bool IsDLL() { return (m_wCharacteristics & IMAGE_FILE_DLL) == IMAGE_FILE_DLL; };
  113. inline DWORD GetPEImageTimeDateStamp() { return m_dwPEImageTimeDateStamp; };
  114. inline DWORD GetPEImageSizeOfImage() { return m_dwPEImageSizeOfImage; };
  115. inline LPTSTR GetPDBModulePath() { return m_tszPDBModuleFileSystemPath; };
  116. inline LPTSTR GetDebugDirectoryPDBPath() { return (m_tszPEImageDebugDirectoryPDBPath == NULL) ? m_tszDBGDebugDirectoryPDBPath : m_tszPEImageDebugDirectoryPDBPath; };
  117. inline DWORD GetReadPointer() { return m_dwCurrentReadPosition; };
  118. inline LPTSTR SourceEnabledPEImage() { return ( (m_dwPEImageDebugDirectoryPDBFormatSpecifier == sigNB09) || (m_dwPEImageDebugDirectoryPDBFormatSpecifier == sigNB11) ) ? TEXT("(Source Enabled)") : TEXT(""); };
  119. inline LPTSTR SourceEnabledDBGImage() { return ( (m_dwDBGDebugDirectoryPDBFormatSpecifier == sigNB09) || (m_dwDBGDebugDirectoryPDBFormatSpecifier == sigNB11) ) ? TEXT("(Source Enabled)") : TEXT(""); };
  120. // return (m_dwPEImageDebugDirectoryOMAPtoSRCSize && m_dwPEImageDebugDirectoryOMAPfromSRCSize) || (m_dwDBGImageDebugDirectoryOMAPtoSRCSize && m_dwDBGImageDebugDirectoryOMAPfromSRCSize) ? TEXT("(Source Enabled)") : TEXT("");
  121. inline LPTSTR SourceEnabledPDB() { return (m_dwPDBTotalBytesOfLineInformation && m_dwPDBTotalBytesOfSymbolInformation && m_dwPDBTotalSymbolTypesRange) ? TEXT("(Source Enabled)") : TEXT("");};
  122. protected:
  123. bool FSourceEnabledPdb(void);
  124. enum VerificationLevels {IGNORE_BAD_CHECKSUM, IGNORE_NOTHING};
  125. enum PEImageType {PEImageTypeUnknown, PE32, PE64};
  126. DWORD m_dwCurrentReadPosition;
  127. DWORD m_dwRefCount;
  128. CFileData * m_lpInputFile;
  129. CFileData * m_lpOutputFile;
  130. CDmpFile * m_lpDmpFile;
  131. // PE Image File Version Information
  132. bool m_fPEImageFileVersionInfo;
  133. LPTSTR m_tszPEImageFileVersionDescription;
  134. LPTSTR m_tszPEImageFileVersionCompanyName;
  135. LPTSTR m_tszPEImageFileVersionString;
  136. DWORD m_dwPEImageFileVersionMS;
  137. DWORD m_dwPEImageFileVersionLS;
  138. LPTSTR m_tszPEImageProductVersionString;
  139. DWORD m_dwPEImageProductVersionMS;
  140. DWORD m_dwPEImageProductVersionLS;
  141. // PE Image Properties
  142. LPTSTR m_tszPEImageModuleName;
  143. LPTSTR m_tszPEImageModuleFileSystemPath;
  144. DWORD m_dwPEImageFileSize;
  145. FILETIME m_ftPEImageFileTimeDateStamp;
  146. DWORD m_dwPEImageCheckSum;
  147. DWORD m_dwPEImageTimeDateStamp;
  148. DWORD m_dwPEImageSizeOfImage; // New for SYMSRV support
  149. PEImageType m_enumPEImageType;
  150. DWORD64 m_dw64BaseAddress;
  151. WORD m_wPEImageMachineArchitecture;
  152. WORD m_wCharacteristics;
  153. // PE Image has a reference to DBG file
  154. SymbolInformationForPEImage m_enumPEImageSymbolStatus;
  155. LPTSTR m_tszPEImageDebugDirectoryDBGPath;
  156. // PE Image has internal symbols
  157. DWORD m_dwPEImageDebugDirectoryCoffSize;
  158. DWORD m_dwPEImageDebugDirectoryFPOSize;
  159. DWORD m_dwPEImageDebugDirectoryCVSize;
  160. DWORD m_dwPEImageDebugDirectoryOMAPtoSRCSize;
  161. DWORD m_dwPEImageDebugDirectoryOMAPfromSRCSize;
  162. // PE Image has a reference to PDB file...
  163. LPTSTR m_tszPEImageDebugDirectoryPDBPath;
  164. DWORD m_dwPEImageDebugDirectoryPDBFormatSpecifier; // NB10, RSDS, etc...
  165. DWORD m_dwPEImageDebugDirectoryPDBAge;
  166. DWORD m_dwPEImageDebugDirectoryPDBSignature;
  167. LPTSTR m_tszPEImageDebugDirectoryPDBGuid;
  168. // DBG File Information
  169. SymbolModuleStatus m_enumDBGModuleStatus;
  170. LPTSTR m_tszDBGModuleFileSystemPath; // Actual path
  171. DWORD m_dwDBGTimeDateStamp;
  172. DWORD m_dwDBGCheckSum;
  173. DWORD m_dwDBGSizeOfImage;
  174. DWORD m_dwDBGImageDebugDirectoryCoffSize;
  175. DWORD m_dwDBGImageDebugDirectoryFPOSize;
  176. DWORD m_dwDBGImageDebugDirectoryCVSize;
  177. DWORD m_dwDBGImageDebugDirectoryOMAPtoSRCSize;
  178. DWORD m_dwDBGImageDebugDirectoryOMAPfromSRCSize;
  179. // DBG File has a reference to a PDB file...
  180. LPTSTR m_tszDBGDebugDirectoryPDBPath;
  181. DWORD m_dwDBGDebugDirectoryPDBFormatSpecifier; // NB10, RSDS, etc...
  182. DWORD m_dwDBGDebugDirectoryPDBAge;
  183. DWORD m_dwDBGDebugDirectoryPDBSignature;
  184. LPTSTR m_tszDBGDebugDirectoryPDBGuid;
  185. // PDB File Information
  186. SymbolModuleStatus m_enumPDBModuleStatus;
  187. LPTSTR m_tszPDBModuleFileSystemPath;
  188. DWORD m_dwPDBFormatSpecifier;
  189. DWORD m_dwPDBSignature;
  190. DWORD m_dwPDBAge;
  191. LPTSTR m_tszPDBGuid;
  192. DWORD m_dwPDBTotalBytesOfLineInformation;
  193. DWORD m_dwPDBTotalBytesOfSymbolInformation;
  194. DWORD m_dwPDBTotalSymbolTypesRange;
  195. // Conversion routines...
  196. LPTSTR SymbolInformationString(enum SymbolInformationForPEImage enumSymbolInformationForPEImage);
  197. LPTSTR SymbolModuleStatusString(enum SymbolModuleStatus enumModuleStatus);
  198. SymbolInformationForPEImage SymbolInformation(LPSTR szSymbolInformationString);
  199. bool DoRead(bool fDmpFile, HANDLE hModuleHandle, LPVOID lpBuffer, DWORD cNumberOfBytesToRead);
  200. ULONG SetReadPointer(bool fDmpFile, HANDLE hModuleHandle, LONG cbOffset, int iFrom);
  201. bool GetModuleInfoFromCSVFile(LPTSTR tszModulePath);
  202. bool GetModuleInfoFromPEImage(LPTSTR tszModulePath, const bool fDmpFile, const DWORD64 dw64ModAddress);
  203. //
  204. // Output Methods
  205. //
  206. bool OutputDataToStdout(DWORD dwModuleNumber);
  207. bool OutputDataToStdoutThisModule();
  208. bool OutputDataToStdoutModuleInfo(DWORD dwModuleNumber);
  209. bool OutputDataToStdoutInternalSymbolInfo(DWORD dwCoffSize, DWORD dwFPOSize, DWORD dwCVSize, DWORD dwOMAPtoSRC, DWORD dwOMAPfromSRC);
  210. bool OutputDataToStdoutDbgSymbolInfo(LPCTSTR tszModulePointerToDbg, DWORD dwTimeDateStamp, DWORD dwChecksum, DWORD dwSizeOfImage, LPCTSTR tszDbgComment = NULL, DWORD dwExpectedTimeDateStamp = 0, DWORD dwExpectedChecksum = 0, DWORD dwExpectedSizeOfImage = 0);
  211. bool OutputDataToStdoutPdbSymbolInfo(DWORD dwPDBFormatSpecifier, LPTSTR tszModulePointerToPDB, DWORD dwPDBSignature, LPTSTR tszPDBGuid, DWORD dwPDBAge, LPCTSTR tszPdbComment = NULL);
  212. bool OutputDataToFile(LPTSTR tszProcessName, DWORD iProcessID);
  213. bool OutputFileTime(FILETIME ftFileTime, LPTSTR tszFileTime, int iFileTimeBufferSize);
  214. bool fCheckPDBSignature(bool fDmpFile, HANDLE hModuleHandle, OMFSignature *pSig, PDB_INFO *ppdb);
  215. bool LocatePdb(LPTSTR tszPDB, ULONG PdbAge, ULONG PdbSignature, LPTSTR tszSymbolPath, LPTSTR tszImageExt, bool fImagePathPassed);
  216. bool GetPDBModuleFileUsingSymbolPath();
  217. bool HandlePDBOpenValidateReturn(PDB * lpPdb, LPTSTR tszPDBLocal, EC ec);
  218. bool ProcessDebugDirectory(const bool fPEImage, const bool fDmpFile, const HANDLE hModuleHandle, unsigned int iDebugDirectorySize, ULONG OffsetImageDebugDirectory);
  219. bool ProcessDebugTypeCVDirectoryEntry(const bool fPEImage, const bool fDmpFile, const HANDLE hModuleHandle, const PIMAGE_DEBUG_DIRECTORY lpImageDebugDirectory);
  220. bool ProcessDebugTypeFPODirectoryEntry(const bool fPEImage, const PIMAGE_DEBUG_DIRECTORY lpImageDebugDirectory);
  221. bool ProcessDebugTypeCoffDirectoryEntry(const bool fPEImage, const PIMAGE_DEBUG_DIRECTORY lpImageDebugDirectory);
  222. bool ProcessDebugTypeMiscDirectoryEntry(const bool fPEImage, const bool fDmpFile, const HANDLE hModuleHandle, const PIMAGE_DEBUG_DIRECTORY lpImageDebugDirectory);
  223. bool ProcessDebugTypeOMAPDirectoryEntry(const bool fPEImage, const PIMAGE_DEBUG_DIRECTORY lpImageDebugDirectory);
  224. bool ProcessPDBSourceInfo(PDB *lpPdb);
  225. bool fValidDBGTimeDateStamp();
  226. bool fValidDBGCheckSum();
  227. bool GetDBGModuleFileUsingSymbolPath(LPTSTR tszSymbolPath);
  228. bool GetDBGModuleFileUsingSQLServer(CSymbolVerification * lpSymbolVerification);
  229. // SQL2 - mjl 12/14/99
  230. bool GetDBGModuleFileUsingSQLServer2(CSymbolVerification * lpSymbolVerification);
  231. bool GetPDBModuleFileUsingSQLServer2(CSymbolVerification * lpSymbolVerification);
  232. };
  233. #endif // !defined(AFX_MODULEINFO_H__0D2E8509_A01A_11D2_83A8_000000000000__INCLUDED_)