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.

3110 lines
87 KiB

  1. /*++ BUILD Version: 0001 Increment this if a change has global effects
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. imagehlp.h
  5. Abstract:
  6. This module defines the prototypes and constants required for the image
  7. help routines.
  8. Revision History:
  9. --*/
  10. #ifndef _IMAGEHLP_
  11. #define _IMAGEHLP_
  12. #if _MSC_VER > 1020
  13. #pragma once
  14. #endif
  15. // As a general principal always call the 64 bit version
  16. // of every API, if a choice exists. The 64 bit version
  17. // works great on 32 bit platforms, and is forward
  18. // compatible to 64 bit platforms.
  19. #ifdef _WIN64
  20. #ifndef _IMAGEHLP64
  21. #define _IMAGEHLP64
  22. #endif
  23. #endif
  24. #ifndef WINTRUST_H
  25. #include <wintrust.h>
  26. #endif
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. #ifdef _IMAGEHLP_SOURCE_
  31. #define IMAGEAPI __stdcall
  32. #define DBHLP_DEPRECIATED
  33. #else
  34. #define IMAGEAPI DECLSPEC_IMPORT __stdcall
  35. #if (_MSC_VER >= 1300) && !defined(MIDL_PASS)
  36. #define DBHLP_DEPRECIATED __declspec(deprecated)
  37. #else
  38. #define DBHLP_DEPRECIATED
  39. #endif
  40. #endif
  41. #define DBHLPAPI IMAGEAPI
  42. #define IMAGE_SEPARATION (64*1024)
  43. typedef struct _LOADED_IMAGE {
  44. PSTR ModuleName;
  45. HANDLE hFile;
  46. PUCHAR MappedAddress;
  47. #ifdef _IMAGEHLP64
  48. PIMAGE_NT_HEADERS64 FileHeader;
  49. #else
  50. PIMAGE_NT_HEADERS32 FileHeader;
  51. #endif
  52. PIMAGE_SECTION_HEADER LastRvaSection;
  53. ULONG NumberOfSections;
  54. PIMAGE_SECTION_HEADER Sections;
  55. ULONG Characteristics;
  56. BOOLEAN fSystemImage;
  57. BOOLEAN fDOSImage;
  58. LIST_ENTRY Links;
  59. ULONG SizeOfImage;
  60. } LOADED_IMAGE, *PLOADED_IMAGE;
  61. #define MAX_SYM_NAME 2000
  62. BOOL
  63. IMAGEAPI
  64. BindImage(
  65. IN PSTR ImageName,
  66. IN PSTR DllPath,
  67. IN PSTR SymbolPath
  68. );
  69. typedef enum _IMAGEHLP_STATUS_REASON {
  70. BindOutOfMemory,
  71. BindRvaToVaFailed,
  72. BindNoRoomInImage,
  73. BindImportModuleFailed,
  74. BindImportProcedureFailed,
  75. BindImportModule,
  76. BindImportProcedure,
  77. BindForwarder,
  78. BindForwarderNOT,
  79. BindImageModified,
  80. BindExpandFileHeaders,
  81. BindImageComplete,
  82. BindMismatchedSymbols,
  83. BindSymbolsNotUpdated,
  84. BindImportProcedure32,
  85. BindImportProcedure64,
  86. BindForwarder32,
  87. BindForwarder64,
  88. BindForwarderNOT32,
  89. BindForwarderNOT64
  90. } IMAGEHLP_STATUS_REASON;
  91. typedef
  92. BOOL
  93. (__stdcall *PIMAGEHLP_STATUS_ROUTINE)(
  94. IMAGEHLP_STATUS_REASON Reason,
  95. PSTR ImageName,
  96. PSTR DllName,
  97. ULONG_PTR Va,
  98. ULONG_PTR Parameter
  99. );
  100. typedef
  101. BOOL
  102. (__stdcall *PIMAGEHLP_STATUS_ROUTINE32)(
  103. IMAGEHLP_STATUS_REASON Reason,
  104. PSTR ImageName,
  105. PSTR DllName,
  106. ULONG Va,
  107. ULONG_PTR Parameter
  108. );
  109. typedef
  110. BOOL
  111. (__stdcall *PIMAGEHLP_STATUS_ROUTINE64)(
  112. IMAGEHLP_STATUS_REASON Reason,
  113. PSTR ImageName,
  114. PSTR DllName,
  115. ULONG64 Va,
  116. ULONG_PTR Parameter
  117. );
  118. BOOL
  119. IMAGEAPI
  120. BindImageEx(
  121. IN DWORD Flags,
  122. IN PSTR ImageName,
  123. IN PSTR DllPath,
  124. IN PSTR SymbolPath,
  125. IN PIMAGEHLP_STATUS_ROUTINE StatusRoutine
  126. );
  127. #define BIND_NO_BOUND_IMPORTS 0x00000001
  128. #define BIND_NO_UPDATE 0x00000002
  129. #define BIND_ALL_IMAGES 0x00000004
  130. #define BIND_CACHE_IMPORT_DLLS 0x00000008 // Cache dll's across
  131. // calls to BindImageEx
  132. // (same as NT 3.1->NT 4.0)
  133. #define BIND_REPORT_64BIT_VA 0x00000010
  134. BOOL
  135. IMAGEAPI
  136. ReBaseImage(
  137. IN PSTR CurrentImageName,
  138. IN PSTR SymbolPath,
  139. IN BOOL fReBase, // TRUE if actually rebasing, false if only summing
  140. IN BOOL fRebaseSysfileOk, // TRUE is system images s/b rebased
  141. IN BOOL fGoingDown, // TRUE if the image s/b rebased below the given base
  142. IN ULONG CheckImageSize, // Max size allowed (0 if don't care)
  143. OUT ULONG *OldImageSize, // Returned from the header
  144. OUT ULONG_PTR *OldImageBase, // Returned from the header
  145. OUT ULONG *NewImageSize, // Image size rounded to next separation boundary
  146. IN OUT ULONG_PTR *NewImageBase, // (in) Desired new address.
  147. // (out) Next address (actual if going down)
  148. IN ULONG TimeStamp // new timestamp for image, if non-zero
  149. );
  150. BOOL
  151. IMAGEAPI
  152. ReBaseImage64(
  153. IN PSTR CurrentImageName,
  154. IN PSTR SymbolPath,
  155. IN BOOL fReBase, // TRUE if actually rebasing, false if only summing
  156. IN BOOL fRebaseSysfileOk, // TRUE is system images s/b rebased
  157. IN BOOL fGoingDown, // TRUE if the image s/b rebased below the given base
  158. IN ULONG CheckImageSize, // Max size allowed (0 if don't care)
  159. OUT ULONG *OldImageSize, // Returned from the header
  160. OUT ULONG64 *OldImageBase, // Returned from the header
  161. OUT ULONG *NewImageSize, // Image size rounded to next separation boundary
  162. IN OUT ULONG64 *NewImageBase, // (in) Desired new address.
  163. // (out) Next address (actual if going down)
  164. IN ULONG TimeStamp // new timestamp for image, if non-zero
  165. );
  166. //
  167. // Define checksum return codes.
  168. //
  169. #define CHECKSUM_SUCCESS 0
  170. #define CHECKSUM_OPEN_FAILURE 1
  171. #define CHECKSUM_MAP_FAILURE 2
  172. #define CHECKSUM_MAPVIEW_FAILURE 3
  173. #define CHECKSUM_UNICODE_FAILURE 4
  174. // Define Splitsym flags.
  175. #define SPLITSYM_REMOVE_PRIVATE 0x00000001 // Remove CV types/symbols and Fixup debug
  176. // Used for creating .dbg files that ship
  177. // as part of the product.
  178. #define SPLITSYM_EXTRACT_ALL 0x00000002 // Extract all debug info from image.
  179. // Normally, FPO is left in the image
  180. // to allow stack traces through the code.
  181. // Using this switch is similar to linking
  182. // with -debug:none except the .dbg file
  183. // exists...
  184. #define SPLITSYM_SYMBOLPATH_IS_SRC 0x00000004 // The SymbolFilePath contains an alternate
  185. // path to locate the pdb.
  186. //
  187. // Define checksum function prototypes.
  188. //
  189. PIMAGE_NT_HEADERS
  190. IMAGEAPI
  191. CheckSumMappedFile (
  192. PVOID BaseAddress,
  193. DWORD FileLength,
  194. PDWORD HeaderSum,
  195. PDWORD CheckSum
  196. );
  197. DWORD
  198. IMAGEAPI
  199. MapFileAndCheckSumA (
  200. PSTR Filename,
  201. PDWORD HeaderSum,
  202. PDWORD CheckSum
  203. );
  204. DWORD
  205. IMAGEAPI
  206. MapFileAndCheckSumW (
  207. PWSTR Filename,
  208. PDWORD HeaderSum,
  209. PDWORD CheckSum
  210. );
  211. #ifdef UNICODE
  212. #define MapFileAndCheckSum MapFileAndCheckSumW
  213. #else
  214. #define MapFileAndCheckSum MapFileAndCheckSumA
  215. #endif // !UNICODE
  216. BOOL
  217. IMAGEAPI
  218. GetImageConfigInformation(
  219. PLOADED_IMAGE LoadedImage,
  220. PIMAGE_LOAD_CONFIG_DIRECTORY ImageConfigInformation
  221. );
  222. DWORD
  223. IMAGEAPI
  224. GetImageUnusedHeaderBytes(
  225. PLOADED_IMAGE LoadedImage,
  226. PDWORD SizeUnusedHeaderBytes
  227. );
  228. BOOL
  229. IMAGEAPI
  230. SetImageConfigInformation(
  231. PLOADED_IMAGE LoadedImage,
  232. PIMAGE_LOAD_CONFIG_DIRECTORY ImageConfigInformation
  233. );
  234. // Image Integrity API's
  235. #define CERT_PE_IMAGE_DIGEST_DEBUG_INFO 0x01
  236. #define CERT_PE_IMAGE_DIGEST_RESOURCES 0x02
  237. #define CERT_PE_IMAGE_DIGEST_ALL_IMPORT_INFO 0x04
  238. #define CERT_PE_IMAGE_DIGEST_NON_PE_INFO 0x08 // include data outside the PE image
  239. #define CERT_SECTION_TYPE_ANY 0xFF // Any Certificate type
  240. typedef PVOID DIGEST_HANDLE;
  241. typedef BOOL (WINAPI *DIGEST_FUNCTION) (DIGEST_HANDLE refdata, PBYTE pData, DWORD dwLength);
  242. BOOL
  243. IMAGEAPI
  244. ImageGetDigestStream(
  245. IN HANDLE FileHandle,
  246. IN DWORD DigestLevel,
  247. IN DIGEST_FUNCTION DigestFunction,
  248. IN DIGEST_HANDLE DigestHandle
  249. );
  250. BOOL
  251. IMAGEAPI
  252. ImageAddCertificate(
  253. IN HANDLE FileHandle,
  254. IN LPWIN_CERTIFICATE Certificate,
  255. OUT PDWORD Index
  256. );
  257. BOOL
  258. IMAGEAPI
  259. ImageRemoveCertificate(
  260. IN HANDLE FileHandle,
  261. IN DWORD Index
  262. );
  263. BOOL
  264. IMAGEAPI
  265. ImageEnumerateCertificates(
  266. IN HANDLE FileHandle,
  267. IN WORD TypeFilter,
  268. OUT PDWORD CertificateCount,
  269. IN OUT PDWORD Indices OPTIONAL,
  270. IN OUT DWORD IndexCount OPTIONAL
  271. );
  272. BOOL
  273. IMAGEAPI
  274. ImageGetCertificateData(
  275. IN HANDLE FileHandle,
  276. IN DWORD CertificateIndex,
  277. OUT LPWIN_CERTIFICATE Certificate,
  278. IN OUT PDWORD RequiredLength
  279. );
  280. BOOL
  281. IMAGEAPI
  282. ImageGetCertificateHeader(
  283. IN HANDLE FileHandle,
  284. IN DWORD CertificateIndex,
  285. IN OUT LPWIN_CERTIFICATE Certificateheader
  286. );
  287. PLOADED_IMAGE
  288. IMAGEAPI
  289. ImageLoad(
  290. PSTR DllName,
  291. PSTR DllPath
  292. );
  293. BOOL
  294. IMAGEAPI
  295. ImageUnload(
  296. PLOADED_IMAGE LoadedImage
  297. );
  298. BOOL
  299. IMAGEAPI
  300. MapAndLoad(
  301. PSTR ImageName,
  302. PSTR DllPath,
  303. PLOADED_IMAGE LoadedImage,
  304. BOOL DotDll,
  305. BOOL ReadOnly
  306. );
  307. BOOL
  308. IMAGEAPI
  309. UnMapAndLoad(
  310. PLOADED_IMAGE LoadedImage
  311. );
  312. BOOL
  313. IMAGEAPI
  314. TouchFileTimes (
  315. HANDLE FileHandle,
  316. PSYSTEMTIME pSystemTime
  317. );
  318. BOOL
  319. IMAGEAPI
  320. SplitSymbols (
  321. PSTR ImageName,
  322. PSTR SymbolsPath,
  323. PSTR SymbolFilePath,
  324. DWORD Flags // Combination of flags above
  325. );
  326. BOOL
  327. IMAGEAPI
  328. UpdateDebugInfoFile(
  329. PSTR ImageFileName,
  330. PSTR SymbolPath,
  331. PSTR DebugFilePath,
  332. PIMAGE_NT_HEADERS32 NtHeaders
  333. );
  334. BOOL
  335. IMAGEAPI
  336. UpdateDebugInfoFileEx(
  337. PSTR ImageFileName,
  338. PSTR SymbolPath,
  339. PSTR DebugFilePath,
  340. PIMAGE_NT_HEADERS32 NtHeaders,
  341. DWORD OldChecksum
  342. );
  343. HANDLE
  344. IMAGEAPI
  345. FindDebugInfoFile (
  346. PSTR FileName,
  347. PSTR SymbolPath,
  348. PSTR DebugFilePath
  349. );
  350. typedef BOOL
  351. (CALLBACK *PFIND_DEBUG_FILE_CALLBACK)(
  352. HANDLE FileHandle,
  353. PSTR FileName,
  354. PVOID CallerData
  355. );
  356. HANDLE
  357. IMAGEAPI
  358. FindDebugInfoFileEx (
  359. PSTR FileName,
  360. PSTR SymbolPath,
  361. PSTR DebugFilePath,
  362. PFIND_DEBUG_FILE_CALLBACK Callback,
  363. PVOID CallerData
  364. );
  365. typedef BOOL
  366. (CALLBACK *PFINDFILEINPATHCALLBACK)(
  367. PSTR filename,
  368. PVOID context
  369. );
  370. BOOL
  371. IMAGEAPI
  372. SymFindFileInPath(
  373. HANDLE hprocess,
  374. LPSTR SearchPath,
  375. LPSTR FileName,
  376. PVOID id,
  377. DWORD two,
  378. DWORD three,
  379. DWORD flags,
  380. LPSTR FoundFile,
  381. PFINDFILEINPATHCALLBACK callback,
  382. PVOID context
  383. );
  384. HANDLE
  385. IMAGEAPI
  386. FindExecutableImage(
  387. PSTR FileName,
  388. PSTR SymbolPath,
  389. PSTR ImageFilePath
  390. );
  391. typedef BOOL
  392. (CALLBACK *PFIND_EXE_FILE_CALLBACK)(
  393. HANDLE FileHandle,
  394. PSTR FileName,
  395. PVOID CallerData
  396. );
  397. HANDLE
  398. IMAGEAPI
  399. FindExecutableImageEx(
  400. PSTR FileName,
  401. PSTR SymbolPath,
  402. PSTR ImageFilePath,
  403. PFIND_EXE_FILE_CALLBACK Callback,
  404. PVOID CallerData
  405. );
  406. PIMAGE_NT_HEADERS
  407. IMAGEAPI
  408. ImageNtHeader (
  409. IN PVOID Base
  410. );
  411. PVOID
  412. IMAGEAPI
  413. ImageDirectoryEntryToDataEx (
  414. IN PVOID Base,
  415. IN BOOLEAN MappedAsImage,
  416. IN USHORT DirectoryEntry,
  417. OUT PULONG Size,
  418. OUT PIMAGE_SECTION_HEADER *FoundHeader OPTIONAL
  419. );
  420. PVOID
  421. IMAGEAPI
  422. ImageDirectoryEntryToData (
  423. IN PVOID Base,
  424. IN BOOLEAN MappedAsImage,
  425. IN USHORT DirectoryEntry,
  426. OUT PULONG Size
  427. );
  428. PIMAGE_SECTION_HEADER
  429. IMAGEAPI
  430. ImageRvaToSection(
  431. IN PIMAGE_NT_HEADERS NtHeaders,
  432. IN PVOID Base,
  433. IN ULONG Rva
  434. );
  435. PVOID
  436. IMAGEAPI
  437. ImageRvaToVa(
  438. IN PIMAGE_NT_HEADERS NtHeaders,
  439. IN PVOID Base,
  440. IN ULONG Rva,
  441. IN OUT PIMAGE_SECTION_HEADER *LastRvaSection
  442. );
  443. // Symbol server exports
  444. typedef BOOL (WINAPI *PSYMBOLSERVERPROC)(LPCSTR, LPCSTR, PVOID, DWORD, DWORD, LPSTR);
  445. typedef BOOL (WINAPI *PSYMBOLSERVEROPENPROC)(VOID);
  446. typedef BOOL (WINAPI *PSYMBOLSERVERCLOSEPROC)(VOID);
  447. typedef BOOL (WINAPI *PSYMBOLSERVERSETOPTIONSPROC)(UINT_PTR, ULONG64);
  448. typedef BOOL (CALLBACK WINAPI *PSYMBOLSERVERCALLBACKPROC)(UINT_PTR action, ULONG64 data, ULONG64 context);
  449. typedef UINT_PTR (WINAPI *PSYMBOLSERVERGETOPTIONSPROC)();
  450. typedef BOOL (WINAPI *PSYMBOLSERVERPINGPROC)(LPCSTR);
  451. #define SSRVOPT_CALLBACK 0x0001
  452. #define SSRVOPT_DWORD 0x0002
  453. #define SSRVOPT_DWORDPTR 0x0004
  454. #define SSRVOPT_GUIDPTR 0x0008
  455. #define SSRVOPT_OLDGUIDPTR 0x0010
  456. #define SSRVOPT_UNATTENDED 0x0020
  457. #define SSRVOPT_NOCOPY 0x0040
  458. #define SSRVOPT_PARENTWIN 0x0080
  459. #define SSRVOPT_PARAMTYPE 0x0100
  460. #define SSRVOPT_SECURE 0x0200
  461. #define SSRVOPT_TRACE 0x0400
  462. #define SSRVOPT_SETCONTEXT 0x0800
  463. #define SSRVOPT_PROXY 0x1000
  464. #define SSRVOPT_DOWNSTREAM_STORE 0x2000
  465. #define SSRVOPT_RESET ((ULONG_PTR)-1)
  466. #define SSRVACTION_TRACE 1
  467. #define SSRVACTION_QUERYCANCEL 2
  468. #define SSRVACTION_EVENT 3
  469. #ifndef _WIN64
  470. // This api won't be ported to Win64 - Fix your code.
  471. typedef struct _IMAGE_DEBUG_INFORMATION {
  472. LIST_ENTRY List;
  473. DWORD ReservedSize;
  474. PVOID ReservedMappedBase;
  475. USHORT ReservedMachine;
  476. USHORT ReservedCharacteristics;
  477. DWORD ReservedCheckSum;
  478. DWORD ImageBase;
  479. DWORD SizeOfImage;
  480. DWORD ReservedNumberOfSections;
  481. PIMAGE_SECTION_HEADER ReservedSections;
  482. DWORD ReservedExportedNamesSize;
  483. PSTR ReservedExportedNames;
  484. DWORD ReservedNumberOfFunctionTableEntries;
  485. PIMAGE_FUNCTION_ENTRY ReservedFunctionTableEntries;
  486. DWORD ReservedLowestFunctionStartingAddress;
  487. DWORD ReservedHighestFunctionEndingAddress;
  488. DWORD ReservedNumberOfFpoTableEntries;
  489. PFPO_DATA ReservedFpoTableEntries;
  490. DWORD SizeOfCoffSymbols;
  491. PIMAGE_COFF_SYMBOLS_HEADER CoffSymbols;
  492. DWORD ReservedSizeOfCodeViewSymbols;
  493. PVOID ReservedCodeViewSymbols;
  494. PSTR ImageFilePath;
  495. PSTR ImageFileName;
  496. PSTR ReservedDebugFilePath;
  497. DWORD ReservedTimeDateStamp;
  498. BOOL ReservedRomImage;
  499. PIMAGE_DEBUG_DIRECTORY ReservedDebugDirectory;
  500. DWORD ReservedNumberOfDebugDirectories;
  501. DWORD ReservedOriginalFunctionTableBaseAddress;
  502. DWORD Reserved[ 2 ];
  503. } IMAGE_DEBUG_INFORMATION, *PIMAGE_DEBUG_INFORMATION;
  504. PIMAGE_DEBUG_INFORMATION
  505. IMAGEAPI
  506. MapDebugInformation(
  507. HANDLE FileHandle,
  508. PSTR FileName,
  509. PSTR SymbolPath,
  510. DWORD ImageBase
  511. );
  512. BOOL
  513. IMAGEAPI
  514. UnmapDebugInformation(
  515. PIMAGE_DEBUG_INFORMATION DebugInfo
  516. );
  517. #endif
  518. BOOL
  519. IMAGEAPI
  520. SearchTreeForFile(
  521. PSTR RootPath,
  522. PSTR InputPathName,
  523. PSTR OutputPathBuffer
  524. );
  525. typedef BOOL
  526. (CALLBACK *PENUMDIRTREE_CALLBACK)(
  527. LPCSTR FilePath,
  528. PVOID CallerData
  529. );
  530. BOOL
  531. IMAGEAPI
  532. EnumDirTree(
  533. HANDLE hProcess,
  534. PSTR RootPath,
  535. PSTR InputPathName,
  536. PSTR OutputPathBuffer,
  537. PENUMDIRTREE_CALLBACK Callback,
  538. PVOID CallbackData
  539. );
  540. BOOL
  541. IMAGEAPI
  542. MakeSureDirectoryPathExists(
  543. PCSTR DirPath
  544. );
  545. //
  546. // UnDecorateSymbolName Flags
  547. //
  548. #define UNDNAME_COMPLETE (0x0000) // Enable full undecoration
  549. #define UNDNAME_NO_LEADING_UNDERSCORES (0x0001) // Remove leading underscores from MS extended keywords
  550. #define UNDNAME_NO_MS_KEYWORDS (0x0002) // Disable expansion of MS extended keywords
  551. #define UNDNAME_NO_FUNCTION_RETURNS (0x0004) // Disable expansion of return type for primary declaration
  552. #define UNDNAME_NO_ALLOCATION_MODEL (0x0008) // Disable expansion of the declaration model
  553. #define UNDNAME_NO_ALLOCATION_LANGUAGE (0x0010) // Disable expansion of the declaration language specifier
  554. #define UNDNAME_NO_MS_THISTYPE (0x0020) // NYI Disable expansion of MS keywords on the 'this' type for primary declaration
  555. #define UNDNAME_NO_CV_THISTYPE (0x0040) // NYI Disable expansion of CV modifiers on the 'this' type for primary declaration
  556. #define UNDNAME_NO_THISTYPE (0x0060) // Disable all modifiers on the 'this' type
  557. #define UNDNAME_NO_ACCESS_SPECIFIERS (0x0080) // Disable expansion of access specifiers for members
  558. #define UNDNAME_NO_THROW_SIGNATURES (0x0100) // Disable expansion of 'throw-signatures' for functions and pointers to functions
  559. #define UNDNAME_NO_MEMBER_TYPE (0x0200) // Disable expansion of 'static' or 'virtual'ness of members
  560. #define UNDNAME_NO_RETURN_UDT_MODEL (0x0400) // Disable expansion of MS model for UDT returns
  561. #define UNDNAME_32_BIT_DECODE (0x0800) // Undecorate 32-bit decorated names
  562. #define UNDNAME_NAME_ONLY (0x1000) // Crack only the name for primary declaration;
  563. // return just [scope::]name. Does expand template params
  564. #define UNDNAME_NO_ARGUMENTS (0x2000) // Don't undecorate arguments to function
  565. #define UNDNAME_NO_SPECIAL_SYMS (0x4000) // Don't undecorate special names (v-table, vcall, vector xxx, metatype, etc)
  566. DWORD
  567. IMAGEAPI
  568. WINAPI
  569. UnDecorateSymbolName(
  570. PCSTR DecoratedName, // Name to undecorate
  571. PSTR UnDecoratedName, // If NULL, it will be allocated
  572. DWORD UndecoratedLength, // The maximym length
  573. DWORD Flags // See above.
  574. );
  575. //
  576. // these values are used for synthesized file types
  577. // that can be passed in as image headers instead of
  578. // the standard ones from ntimage.h
  579. //
  580. #define DBHHEADER_DEBUGDIRS 0x1
  581. typedef struct _MODLOAD_DATA {
  582. DWORD ssize; // size of this struct
  583. DWORD ssig; // signature identifying the passed data
  584. PVOID data; // pointer to passed data
  585. DWORD size; // size of passed data
  586. DWORD flags; // options
  587. } MODLOAD_DATA, *PMODLOAD_DATA;
  588. //
  589. // StackWalking API
  590. //
  591. typedef enum {
  592. AddrMode1616,
  593. AddrMode1632,
  594. AddrModeReal,
  595. AddrModeFlat
  596. } ADDRESS_MODE;
  597. typedef struct _tagADDRESS64 {
  598. DWORD64 Offset;
  599. WORD Segment;
  600. ADDRESS_MODE Mode;
  601. } ADDRESS64, *LPADDRESS64;
  602. #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64)
  603. #define ADDRESS ADDRESS64
  604. #define LPADDRESS LPADDRESS64
  605. #else
  606. typedef struct _tagADDRESS {
  607. DWORD Offset;
  608. WORD Segment;
  609. ADDRESS_MODE Mode;
  610. } ADDRESS, *LPADDRESS;
  611. __inline
  612. void
  613. Address32To64(
  614. LPADDRESS a32,
  615. LPADDRESS64 a64
  616. )
  617. {
  618. a64->Offset = (ULONG64)(LONG64)(LONG)a32->Offset;
  619. a64->Segment = a32->Segment;
  620. a64->Mode = a32->Mode;
  621. }
  622. __inline
  623. void
  624. Address64To32(
  625. LPADDRESS64 a64,
  626. LPADDRESS a32
  627. )
  628. {
  629. a32->Offset = (ULONG)a64->Offset;
  630. a32->Segment = a64->Segment;
  631. a32->Mode = a64->Mode;
  632. }
  633. #endif
  634. //
  635. // This structure is included in the STACKFRAME structure,
  636. // and is used to trace through usermode callbacks in a thread's
  637. // kernel stack. The values must be copied by the kernel debugger
  638. // from the DBGKD_GET_VERSION and WAIT_STATE_CHANGE packets.
  639. //
  640. //
  641. // New KDHELP structure for 64 bit system support.
  642. // This structure is preferred in new code.
  643. //
  644. typedef struct _KDHELP64 {
  645. //
  646. // address of kernel thread object, as provided in the
  647. // WAIT_STATE_CHANGE packet.
  648. //
  649. DWORD64 Thread;
  650. //
  651. // offset in thread object to pointer to the current callback frame
  652. // in kernel stack.
  653. //
  654. DWORD ThCallbackStack;
  655. //
  656. // offset in thread object to pointer to the current callback backing
  657. // store frame in kernel stack.
  658. //
  659. DWORD ThCallbackBStore;
  660. //
  661. // offsets to values in frame:
  662. //
  663. // address of next callback frame
  664. DWORD NextCallback;
  665. // address of saved frame pointer (if applicable)
  666. DWORD FramePointer;
  667. //
  668. // Address of the kernel function that calls out to user mode
  669. //
  670. DWORD64 KiCallUserMode;
  671. //
  672. // Address of the user mode dispatcher function
  673. //
  674. DWORD64 KeUserCallbackDispatcher;
  675. //
  676. // Lowest kernel mode address
  677. //
  678. DWORD64 SystemRangeStart;
  679. DWORD64 Reserved[8];
  680. } KDHELP64, *PKDHELP64;
  681. #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64)
  682. #define KDHELP KDHELP64
  683. #define PKDHELP PKDHELP64
  684. #else
  685. typedef struct _KDHELP {
  686. //
  687. // address of kernel thread object, as provided in the
  688. // WAIT_STATE_CHANGE packet.
  689. //
  690. DWORD Thread;
  691. //
  692. // offset in thread object to pointer to the current callback frame
  693. // in kernel stack.
  694. //
  695. DWORD ThCallbackStack;
  696. //
  697. // offsets to values in frame:
  698. //
  699. // address of next callback frame
  700. DWORD NextCallback;
  701. // address of saved frame pointer (if applicable)
  702. DWORD FramePointer;
  703. //
  704. // Address of the kernel function that calls out to user mode
  705. //
  706. DWORD KiCallUserMode;
  707. //
  708. // Address of the user mode dispatcher function
  709. //
  710. DWORD KeUserCallbackDispatcher;
  711. //
  712. // Lowest kernel mode address
  713. //
  714. DWORD SystemRangeStart;
  715. //
  716. // offset in thread object to pointer to the current callback backing
  717. // store frame in kernel stack.
  718. //
  719. DWORD ThCallbackBStore;
  720. DWORD Reserved[8];
  721. } KDHELP, *PKDHELP;
  722. __inline
  723. void
  724. KdHelp32To64(
  725. PKDHELP p32,
  726. PKDHELP64 p64
  727. )
  728. {
  729. p64->Thread = p32->Thread;
  730. p64->ThCallbackStack = p32->ThCallbackStack;
  731. p64->NextCallback = p32->NextCallback;
  732. p64->FramePointer = p32->FramePointer;
  733. p64->KiCallUserMode = p32->KiCallUserMode;
  734. p64->KeUserCallbackDispatcher = p32->KeUserCallbackDispatcher;
  735. p64->SystemRangeStart = p32->SystemRangeStart;
  736. }
  737. #endif
  738. typedef struct _tagSTACKFRAME64 {
  739. ADDRESS64 AddrPC; // program counter
  740. ADDRESS64 AddrReturn; // return address
  741. ADDRESS64 AddrFrame; // frame pointer
  742. ADDRESS64 AddrStack; // stack pointer
  743. ADDRESS64 AddrBStore; // backing store pointer
  744. PVOID FuncTableEntry; // pointer to pdata/fpo or NULL
  745. DWORD64 Params[4]; // possible arguments to the function
  746. BOOL Far; // WOW far call
  747. BOOL Virtual; // is this a virtual frame?
  748. DWORD64 Reserved[3];
  749. KDHELP64 KdHelp;
  750. } STACKFRAME64, *LPSTACKFRAME64;
  751. #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64)
  752. #define STACKFRAME STACKFRAME64
  753. #define LPSTACKFRAME LPSTACKFRAME64
  754. #else
  755. typedef struct _tagSTACKFRAME {
  756. ADDRESS AddrPC; // program counter
  757. ADDRESS AddrReturn; // return address
  758. ADDRESS AddrFrame; // frame pointer
  759. ADDRESS AddrStack; // stack pointer
  760. PVOID FuncTableEntry; // pointer to pdata/fpo or NULL
  761. DWORD Params[4]; // possible arguments to the function
  762. BOOL Far; // WOW far call
  763. BOOL Virtual; // is this a virtual frame?
  764. DWORD Reserved[3];
  765. KDHELP KdHelp;
  766. ADDRESS AddrBStore; // backing store pointer
  767. } STACKFRAME, *LPSTACKFRAME;
  768. #endif
  769. typedef
  770. BOOL
  771. (__stdcall *PREAD_PROCESS_MEMORY_ROUTINE64)(
  772. HANDLE hProcess,
  773. DWORD64 qwBaseAddress,
  774. PVOID lpBuffer,
  775. DWORD nSize,
  776. LPDWORD lpNumberOfBytesRead
  777. );
  778. typedef
  779. PVOID
  780. (__stdcall *PFUNCTION_TABLE_ACCESS_ROUTINE64)(
  781. HANDLE hProcess,
  782. DWORD64 AddrBase
  783. );
  784. typedef
  785. DWORD64
  786. (__stdcall *PGET_MODULE_BASE_ROUTINE64)(
  787. HANDLE hProcess,
  788. DWORD64 Address
  789. );
  790. typedef
  791. DWORD64
  792. (__stdcall *PTRANSLATE_ADDRESS_ROUTINE64)(
  793. HANDLE hProcess,
  794. HANDLE hThread,
  795. LPADDRESS64 lpaddr
  796. );
  797. BOOL
  798. IMAGEAPI
  799. StackWalk64(
  800. DWORD MachineType,
  801. HANDLE hProcess,
  802. HANDLE hThread,
  803. LPSTACKFRAME64 StackFrame,
  804. PVOID ContextRecord,
  805. PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine,
  806. PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine,
  807. PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine,
  808. PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress
  809. );
  810. #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64)
  811. #define PREAD_PROCESS_MEMORY_ROUTINE PREAD_PROCESS_MEMORY_ROUTINE64
  812. #define PFUNCTION_TABLE_ACCESS_ROUTINE PFUNCTION_TABLE_ACCESS_ROUTINE64
  813. #define PGET_MODULE_BASE_ROUTINE PGET_MODULE_BASE_ROUTINE64
  814. #define PTRANSLATE_ADDRESS_ROUTINE PTRANSLATE_ADDRESS_ROUTINE64
  815. #define StackWalk StackWalk64
  816. #else
  817. typedef
  818. BOOL
  819. (__stdcall *PREAD_PROCESS_MEMORY_ROUTINE)(
  820. HANDLE hProcess,
  821. DWORD lpBaseAddress,
  822. PVOID lpBuffer,
  823. DWORD nSize,
  824. PDWORD lpNumberOfBytesRead
  825. );
  826. typedef
  827. PVOID
  828. (__stdcall *PFUNCTION_TABLE_ACCESS_ROUTINE)(
  829. HANDLE hProcess,
  830. DWORD AddrBase
  831. );
  832. typedef
  833. DWORD
  834. (__stdcall *PGET_MODULE_BASE_ROUTINE)(
  835. HANDLE hProcess,
  836. DWORD Address
  837. );
  838. typedef
  839. DWORD
  840. (__stdcall *PTRANSLATE_ADDRESS_ROUTINE)(
  841. HANDLE hProcess,
  842. HANDLE hThread,
  843. LPADDRESS lpaddr
  844. );
  845. BOOL
  846. IMAGEAPI
  847. StackWalk(
  848. DWORD MachineType,
  849. HANDLE hProcess,
  850. HANDLE hThread,
  851. LPSTACKFRAME StackFrame,
  852. PVOID ContextRecord,
  853. PREAD_PROCESS_MEMORY_ROUTINE ReadMemoryRoutine,
  854. PFUNCTION_TABLE_ACCESS_ROUTINE FunctionTableAccessRoutine,
  855. PGET_MODULE_BASE_ROUTINE GetModuleBaseRoutine,
  856. PTRANSLATE_ADDRESS_ROUTINE TranslateAddress
  857. );
  858. #endif
  859. #define API_VERSION_NUMBER 9
  860. typedef struct API_VERSION {
  861. USHORT MajorVersion;
  862. USHORT MinorVersion;
  863. USHORT Revision;
  864. USHORT Reserved;
  865. } API_VERSION, *LPAPI_VERSION;
  866. LPAPI_VERSION
  867. IMAGEAPI
  868. ImagehlpApiVersion(
  869. VOID
  870. );
  871. LPAPI_VERSION
  872. IMAGEAPI
  873. ImagehlpApiVersionEx(
  874. LPAPI_VERSION AppVersion
  875. );
  876. DWORD
  877. IMAGEAPI
  878. GetTimestampForLoadedLibrary(
  879. HMODULE Module
  880. );
  881. //
  882. // typedefs for function pointers
  883. //
  884. typedef BOOL
  885. (CALLBACK *PSYM_ENUMMODULES_CALLBACK64)(
  886. PSTR ModuleName,
  887. DWORD64 BaseOfDll,
  888. PVOID UserContext
  889. );
  890. typedef BOOL
  891. (CALLBACK *PSYM_ENUMSYMBOLS_CALLBACK64)(
  892. PSTR SymbolName,
  893. DWORD64 SymbolAddress,
  894. ULONG SymbolSize,
  895. PVOID UserContext
  896. );
  897. typedef BOOL
  898. (CALLBACK *PSYM_ENUMSYMBOLS_CALLBACK64W)(
  899. PWSTR SymbolName,
  900. DWORD64 SymbolAddress,
  901. ULONG SymbolSize,
  902. PVOID UserContext
  903. );
  904. typedef BOOL
  905. (CALLBACK *PENUMLOADED_MODULES_CALLBACK64)(
  906. PSTR ModuleName,
  907. DWORD64 ModuleBase,
  908. ULONG ModuleSize,
  909. PVOID UserContext
  910. );
  911. typedef BOOL
  912. (CALLBACK *PSYMBOL_REGISTERED_CALLBACK64)(
  913. HANDLE hProcess,
  914. ULONG ActionCode,
  915. ULONG64 CallbackData,
  916. ULONG64 UserContext
  917. );
  918. typedef
  919. PVOID
  920. (CALLBACK *PSYMBOL_FUNCENTRY_CALLBACK)(
  921. HANDLE hProcess,
  922. DWORD AddrBase,
  923. PVOID UserContext
  924. );
  925. typedef
  926. PVOID
  927. (CALLBACK *PSYMBOL_FUNCENTRY_CALLBACK64)(
  928. HANDLE hProcess,
  929. ULONG64 AddrBase,
  930. ULONG64 UserContext
  931. );
  932. #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64)
  933. #define PSYM_ENUMMODULES_CALLBACK PSYM_ENUMMODULES_CALLBACK64
  934. #define PSYM_ENUMSYMBOLS_CALLBACK PSYM_ENUMSYMBOLS_CALLBACK64
  935. #define PSYM_ENUMSYMBOLS_CALLBACKW PSYM_ENUMSYMBOLS_CALLBACK64W
  936. #define PENUMLOADED_MODULES_CALLBACK PENUMLOADED_MODULES_CALLBACK64
  937. #define PSYMBOL_REGISTERED_CALLBACK PSYMBOL_REGISTERED_CALLBACK64
  938. #define PSYMBOL_FUNCENTRY_CALLBACK PSYMBOL_FUNCENTRY_CALLBACK64
  939. #else
  940. typedef BOOL
  941. (CALLBACK *PSYM_ENUMMODULES_CALLBACK)(
  942. PSTR ModuleName,
  943. ULONG BaseOfDll,
  944. PVOID UserContext
  945. );
  946. typedef BOOL
  947. (CALLBACK *PSYM_ENUMSYMBOLS_CALLBACK)(
  948. PSTR SymbolName,
  949. ULONG SymbolAddress,
  950. ULONG SymbolSize,
  951. PVOID UserContext
  952. );
  953. typedef BOOL
  954. (CALLBACK *PSYM_ENUMSYMBOLS_CALLBACKW)(
  955. PWSTR SymbolName,
  956. ULONG SymbolAddress,
  957. ULONG SymbolSize,
  958. PVOID UserContext
  959. );
  960. typedef BOOL
  961. (CALLBACK *PENUMLOADED_MODULES_CALLBACK)(
  962. PSTR ModuleName,
  963. ULONG ModuleBase,
  964. ULONG ModuleSize,
  965. PVOID UserContext
  966. );
  967. typedef BOOL
  968. (CALLBACK *PSYMBOL_REGISTERED_CALLBACK)(
  969. HANDLE hProcess,
  970. ULONG ActionCode,
  971. PVOID CallbackData,
  972. PVOID UserContext
  973. );
  974. #endif
  975. //
  976. // flags found in SYMBOL_INFO.Flags
  977. //
  978. #define SYMFLAG_VALUEPRESENT 0x00000001
  979. #define SYMFLAG_REGISTER 0x00000008
  980. #define SYMFLAG_REGREL 0x00000010
  981. #define SYMFLAG_FRAMEREL 0x00000020
  982. #define SYMFLAG_PARAMETER 0x00000040
  983. #define SYMFLAG_LOCAL 0x00000080
  984. #define SYMFLAG_CONSTANT 0x00000100
  985. #define SYMFLAG_EXPORT 0x00000200
  986. #define SYMFLAG_FORWARDER 0x00000400
  987. #define SYMFLAG_FUNCTION 0x00000800
  988. #define SYMFLAG_VIRTUAL 0x00001000
  989. #define SYMFLAG_THUNK 0x00002000
  990. #define SYMFLAG_TLSREL 0x00004000
  991. //
  992. // symbol type enumeration
  993. //
  994. typedef enum {
  995. SymNone = 0,
  996. SymCoff,
  997. SymCv,
  998. SymPdb,
  999. SymExport,
  1000. SymDeferred,
  1001. SymSym, // .sym file
  1002. SymDia,
  1003. SymVirtual,
  1004. NumSymTypes
  1005. } SYM_TYPE;
  1006. //
  1007. // symbol data structure
  1008. //
  1009. typedef struct _IMAGEHLP_SYMBOL64 {
  1010. DWORD SizeOfStruct; // set to sizeof(IMAGEHLP_SYMBOL64)
  1011. DWORD64 Address; // virtual address including dll base address
  1012. DWORD Size; // estimated size of symbol, can be zero
  1013. DWORD Flags; // info about the symbols, see the SYMF defines
  1014. DWORD MaxNameLength; // maximum size of symbol name in 'Name'
  1015. CHAR Name[1]; // symbol name (null terminated string)
  1016. } IMAGEHLP_SYMBOL64, *PIMAGEHLP_SYMBOL64;
  1017. typedef struct _IMAGEHLP_SYMBOL64_PACKAGE {
  1018. IMAGEHLP_SYMBOL64 sym;
  1019. CHAR name[MAX_SYM_NAME + 1];
  1020. } IMAGEHLP_SYMBOL64_PACKAGE, *PIMAGEHLP_SYMBOL64_PACKAGE;
  1021. #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64)
  1022. #define IMAGEHLP_SYMBOL IMAGEHLP_SYMBOL64
  1023. #define PIMAGEHLP_SYMBOL PIMAGEHLP_SYMBOL64
  1024. #define IMAGEHLP_SYMBOL_PACKAGE IMAGEHLP_SYMBOL64_PACKAGE
  1025. #define PIMAGEHLP_SYMBOL_PACKAGE PIMAGEHLP_SYMBOL64_PACKAGE
  1026. #else
  1027. typedef struct _IMAGEHLP_SYMBOL {
  1028. DWORD SizeOfStruct; // set to sizeof(IMAGEHLP_SYMBOL)
  1029. DWORD Address; // virtual address including dll base address
  1030. DWORD Size; // estimated size of symbol, can be zero
  1031. DWORD Flags; // info about the symbols, see the SYMF defines
  1032. DWORD MaxNameLength; // maximum size of symbol name in 'Name'
  1033. CHAR Name[1]; // symbol name (null terminated string)
  1034. } IMAGEHLP_SYMBOL, *PIMAGEHLP_SYMBOL;
  1035. typedef struct _IMAGEHLP_SYMBOL_PACKAGE {
  1036. IMAGEHLP_SYMBOL sym;
  1037. CHAR name[MAX_SYM_NAME + 1];
  1038. } IMAGEHLP_SYMBOL_PACKAGE, *PIMAGEHLP_SYMBOL_PACKAGE;
  1039. #endif
  1040. //
  1041. // module data structure
  1042. //
  1043. typedef struct _IMAGEHLP_MODULE64 {
  1044. DWORD SizeOfStruct; // set to sizeof(IMAGEHLP_MODULE64)
  1045. DWORD64 BaseOfImage; // base load address of module
  1046. DWORD ImageSize; // virtual size of the loaded module
  1047. DWORD TimeDateStamp; // date/time stamp from pe header
  1048. DWORD CheckSum; // checksum from the pe header
  1049. DWORD NumSyms; // number of symbols in the symbol table
  1050. SYM_TYPE SymType; // type of symbols loaded
  1051. CHAR ModuleName[32]; // module name
  1052. CHAR ImageName[256]; // image name
  1053. // new elements: 07-Jun-2002
  1054. CHAR LoadedImageName[256]; // symbol file name
  1055. CHAR LoadedPdbName[256]; // pdb file name
  1056. DWORD CVSig; // Signature of the CV record in the debug directories
  1057. CHAR CVData[MAX_PATH * 3]; // Contents of the CV record
  1058. DWORD PdbSig; // Signature of PDB
  1059. GUID PdbSig70; // Signature of PDB (VC 7 and up)
  1060. DWORD PdbAge; // DBI age of pdb
  1061. BOOL PdbUnmatched; // loaded an unmatched pdb
  1062. BOOL DbgUnmatched; // loaded an unmatched dbg
  1063. BOOL LineNumbers; // we have line number information
  1064. BOOL GlobalSymbols; // we have internal symbol information
  1065. BOOL TypeInfo; // we have type information
  1066. } IMAGEHLP_MODULE64, *PIMAGEHLP_MODULE64;
  1067. typedef struct _IMAGEHLP_MODULE64W {
  1068. DWORD SizeOfStruct; // set to sizeof(IMAGEHLP_MODULE64)
  1069. DWORD64 BaseOfImage; // base load address of module
  1070. DWORD ImageSize; // virtual size of the loaded module
  1071. DWORD TimeDateStamp; // date/time stamp from pe header
  1072. DWORD CheckSum; // checksum from the pe header
  1073. DWORD NumSyms; // number of symbols in the symbol table
  1074. SYM_TYPE SymType; // type of symbols loaded
  1075. WCHAR ModuleName[32]; // module name
  1076. WCHAR ImageName[256]; // image name
  1077. // new elements: 07-Jun-2002
  1078. WCHAR LoadedImageName[256]; // symbol file name
  1079. WCHAR LoadedPdbName[256]; // pdb file name
  1080. DWORD CVSig; // Signature of the CV record in the debug directories
  1081. WCHAR CVData[MAX_PATH * 3]; // Contents of the CV record
  1082. DWORD PdbSig; // Signature of PDB
  1083. GUID PdbSig70; // Signature of PDB (VC 7 and up)
  1084. DWORD PdbAge; // DBI age of pdb
  1085. BOOL PdbUnmatched; // loaded an unmatched pdb
  1086. BOOL DbgUnmatched; // loaded an unmatched dbg
  1087. BOOL LineNumbers; // we have line number information
  1088. BOOL GlobalSymbols; // we have internal symbol information
  1089. BOOL TypeInfo; // we have type information
  1090. } IMAGEHLP_MODULEW64, *PIMAGEHLP_MODULEW64;
  1091. #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64)
  1092. #define IMAGEHLP_MODULE IMAGEHLP_MODULE64
  1093. #define PIMAGEHLP_MODULE PIMAGEHLP_MODULE64
  1094. #define IMAGEHLP_MODULEW IMAGEHLP_MODULEW64
  1095. #define PIMAGEHLP_MODULEW PIMAGEHLP_MODULEW64
  1096. #else
  1097. typedef struct _IMAGEHLP_MODULE {
  1098. DWORD SizeOfStruct; // set to sizeof(IMAGEHLP_MODULE)
  1099. DWORD BaseOfImage; // base load address of module
  1100. DWORD ImageSize; // virtual size of the loaded module
  1101. DWORD TimeDateStamp; // date/time stamp from pe header
  1102. DWORD CheckSum; // checksum from the pe header
  1103. DWORD NumSyms; // number of symbols in the symbol table
  1104. SYM_TYPE SymType; // type of symbols loaded
  1105. CHAR ModuleName[32]; // module name
  1106. CHAR ImageName[256]; // image name
  1107. CHAR LoadedImageName[256]; // symbol file name
  1108. } IMAGEHLP_MODULE, *PIMAGEHLP_MODULE;
  1109. typedef struct _IMAGEHLP_MODULEW {
  1110. DWORD SizeOfStruct; // set to sizeof(IMAGEHLP_MODULE)
  1111. DWORD BaseOfImage; // base load address of module
  1112. DWORD ImageSize; // virtual size of the loaded module
  1113. DWORD TimeDateStamp; // date/time stamp from pe header
  1114. DWORD CheckSum; // checksum from the pe header
  1115. DWORD NumSyms; // number of symbols in the symbol table
  1116. SYM_TYPE SymType; // type of symbols loaded
  1117. WCHAR ModuleName[32]; // module name
  1118. WCHAR ImageName[256]; // image name
  1119. WCHAR LoadedImageName[256]; // symbol file name
  1120. } IMAGEHLP_MODULEW, *PIMAGEHLP_MODULEW;
  1121. #endif
  1122. //
  1123. // source file line data structure
  1124. //
  1125. typedef struct _IMAGEHLP_LINE64 {
  1126. DWORD SizeOfStruct; // set to sizeof(IMAGEHLP_LINE64)
  1127. PVOID Key; // internal
  1128. DWORD LineNumber; // line number in file
  1129. PCHAR FileName; // full filename
  1130. DWORD64 Address; // first instruction of line
  1131. } IMAGEHLP_LINE64, *PIMAGEHLP_LINE64;
  1132. #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64)
  1133. #define IMAGEHLP_LINE IMAGEHLP_LINE64
  1134. #define PIMAGEHLP_LINE PIMAGEHLP_LINE64
  1135. #else
  1136. typedef struct _IMAGEHLP_LINE {
  1137. DWORD SizeOfStruct; // set to sizeof(IMAGEHLP_LINE)
  1138. PVOID Key; // internal
  1139. DWORD LineNumber; // line number in file
  1140. PCHAR FileName; // full filename
  1141. DWORD Address; // first instruction of line
  1142. } IMAGEHLP_LINE, *PIMAGEHLP_LINE;
  1143. #endif
  1144. //
  1145. // source file structure
  1146. //
  1147. typedef struct _SOURCEFILE {
  1148. DWORD64 ModBase; // base address of loaded module
  1149. PCHAR FileName; // full filename of source
  1150. } SOURCEFILE, *PSOURCEFILE;
  1151. //
  1152. // data structures used for registered symbol callbacks
  1153. //
  1154. #define CBA_DEFERRED_SYMBOL_LOAD_START 0x00000001
  1155. #define CBA_DEFERRED_SYMBOL_LOAD_COMPLETE 0x00000002
  1156. #define CBA_DEFERRED_SYMBOL_LOAD_FAILURE 0x00000003
  1157. #define CBA_SYMBOLS_UNLOADED 0x00000004
  1158. #define CBA_DUPLICATE_SYMBOL 0x00000005
  1159. #define CBA_READ_MEMORY 0x00000006
  1160. #define CBA_DEFERRED_SYMBOL_LOAD_CANCEL 0x00000007
  1161. #define CBA_SET_OPTIONS 0x00000008
  1162. #define CBA_EVENT 0x00000010
  1163. #define CBA_DEFERRED_SYMBOL_LOAD_PARTIAL 0x00000020
  1164. #define CBA_DEBUG_INFO 0x10000000
  1165. typedef struct _IMAGEHLP_CBA_READ_MEMORY {
  1166. DWORD64 addr; // address to read from
  1167. PVOID buf; // buffer to read to
  1168. DWORD bytes; // amount of bytes to read
  1169. DWORD *bytesread; // pointer to store amount of bytes read
  1170. } IMAGEHLP_CBA_READ_MEMORY, *PIMAGEHLP_CBA_READ_MEMORY;
  1171. enum {
  1172. sevInfo = 0,
  1173. sevProblem,
  1174. sevAttn,
  1175. sevFatal,
  1176. sevMax // unused
  1177. };
  1178. typedef struct _IMAGEHLP_CBA_EVENT {
  1179. DWORD severity; // values from sevInfo to sevFatal
  1180. DWORD code; // numerical code IDs the error
  1181. PCHAR desc; // may contain a text description of the error
  1182. PVOID object; // value dependant upon the error code
  1183. } IMAGEHLP_CBA_EVENT, *PIMAGEHLP_CBA_EVENT;
  1184. typedef struct _IMAGEHLP_DEFERRED_SYMBOL_LOAD64 {
  1185. DWORD SizeOfStruct; // set to sizeof(IMAGEHLP_DEFERRED_SYMBOL_LOAD64)
  1186. DWORD64 BaseOfImage; // base load address of module
  1187. DWORD CheckSum; // checksum from the pe header
  1188. DWORD TimeDateStamp; // date/time stamp from pe header
  1189. CHAR FileName[MAX_PATH]; // symbols file or image name
  1190. BOOLEAN Reparse; // load failure reparse
  1191. HANDLE hFile; // file handle, if passed
  1192. DWORD Flags; //
  1193. } IMAGEHLP_DEFERRED_SYMBOL_LOAD64, *PIMAGEHLP_DEFERRED_SYMBOL_LOAD64;
  1194. #define DSLFLAG_MISMATCHED_PDB 0x1
  1195. #define DSLFLAG_MISMATCHED_DBG 0x2
  1196. #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64)
  1197. #define IMAGEHLP_DEFERRED_SYMBOL_LOAD IMAGEHLP_DEFERRED_SYMBOL_LOAD64
  1198. #define PIMAGEHLP_DEFERRED_SYMBOL_LOAD PIMAGEHLP_DEFERRED_SYMBOL_LOAD64
  1199. #else
  1200. typedef struct _IMAGEHLP_DEFERRED_SYMBOL_LOAD {
  1201. DWORD SizeOfStruct; // set to sizeof(IMAGEHLP_DEFERRED_SYMBOL_LOAD)
  1202. DWORD BaseOfImage; // base load address of module
  1203. DWORD CheckSum; // checksum from the pe header
  1204. DWORD TimeDateStamp; // date/time stamp from pe header
  1205. CHAR FileName[MAX_PATH]; // symbols file or image name
  1206. BOOLEAN Reparse; // load failure reparse
  1207. HANDLE hFile; // file handle, if passed
  1208. } IMAGEHLP_DEFERRED_SYMBOL_LOAD, *PIMAGEHLP_DEFERRED_SYMBOL_LOAD;
  1209. #endif
  1210. typedef struct _IMAGEHLP_DUPLICATE_SYMBOL64 {
  1211. DWORD SizeOfStruct; // set to sizeof(IMAGEHLP_DUPLICATE_SYMBOL64)
  1212. DWORD NumberOfDups; // number of duplicates in the Symbol array
  1213. PIMAGEHLP_SYMBOL64 Symbol; // array of duplicate symbols
  1214. DWORD SelectedSymbol; // symbol selected (-1 to start)
  1215. } IMAGEHLP_DUPLICATE_SYMBOL64, *PIMAGEHLP_DUPLICATE_SYMBOL64;
  1216. #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64)
  1217. #define IMAGEHLP_DUPLICATE_SYMBOL IMAGEHLP_DUPLICATE_SYMBOL64
  1218. #define PIMAGEHLP_DUPLICATE_SYMBOL PIMAGEHLP_DUPLICATE_SYMBOL64
  1219. #else
  1220. typedef struct _IMAGEHLP_DUPLICATE_SYMBOL {
  1221. DWORD SizeOfStruct; // set to sizeof(IMAGEHLP_DUPLICATE_SYMBOL)
  1222. DWORD NumberOfDups; // number of duplicates in the Symbol array
  1223. PIMAGEHLP_SYMBOL Symbol; // array of duplicate symbols
  1224. DWORD SelectedSymbol; // symbol selected (-1 to start)
  1225. } IMAGEHLP_DUPLICATE_SYMBOL, *PIMAGEHLP_DUPLICATE_SYMBOL;
  1226. #endif
  1227. // If dbghelp ever needs to display graphical UI, it will use this as the parent window.
  1228. BOOL
  1229. IMAGEAPI
  1230. SymSetParentWindow(
  1231. HWND hwnd
  1232. );
  1233. PCHAR
  1234. IMAGEAPI
  1235. SymSetHomeDirectory(
  1236. PCSTR dir
  1237. );
  1238. PCHAR
  1239. IMAGEAPI
  1240. SymGetHomeDirectory(
  1241. DWORD type,
  1242. PSTR dir,
  1243. size_t size
  1244. );
  1245. typedef enum {
  1246. hdBase = 0, // root directory for dbghelp
  1247. hdSym, // where symbols are stored
  1248. hdSrc, // where source is stored
  1249. hdMax // end marker
  1250. };
  1251. //
  1252. // options that are set/returned by SymSetOptions() & SymGetOptions()
  1253. // these are used as a mask
  1254. //
  1255. #define SYMOPT_CASE_INSENSITIVE 0x00000001
  1256. #define SYMOPT_UNDNAME 0x00000002
  1257. #define SYMOPT_DEFERRED_LOADS 0x00000004
  1258. #define SYMOPT_NO_CPP 0x00000008
  1259. #define SYMOPT_LOAD_LINES 0x00000010
  1260. #define SYMOPT_OMAP_FIND_NEAREST 0x00000020
  1261. #define SYMOPT_LOAD_ANYTHING 0x00000040
  1262. #define SYMOPT_IGNORE_CVREC 0x00000080
  1263. #define SYMOPT_NO_UNQUALIFIED_LOADS 0x00000100
  1264. #define SYMOPT_FAIL_CRITICAL_ERRORS 0x00000200
  1265. #define SYMOPT_EXACT_SYMBOLS 0x00000400
  1266. #define SYMOPT_ALLOW_ABSOLUTE_SYMBOLS 0x00000800
  1267. #define SYMOPT_IGNORE_NT_SYMPATH 0x00001000
  1268. #define SYMOPT_INCLUDE_32BIT_MODULES 0x00002000
  1269. #define SYMOPT_PUBLICS_ONLY 0x00004000
  1270. #define SYMOPT_NO_PUBLICS 0x00008000
  1271. #define SYMOPT_AUTO_PUBLICS 0x00010000
  1272. #define SYMOPT_NO_IMAGE_SEARCH 0x00020000
  1273. #define SYMOPT_SECURE 0x00040000
  1274. #define SYMOPT_NO_PROMPTS 0x00080000
  1275. #define SYMOPT_DEBUG 0x80000000
  1276. DWORD
  1277. IMAGEAPI
  1278. SymSetOptions(
  1279. IN DWORD SymOptions
  1280. );
  1281. DWORD
  1282. IMAGEAPI
  1283. SymGetOptions(
  1284. VOID
  1285. );
  1286. BOOL
  1287. IMAGEAPI
  1288. SymCleanup(
  1289. IN HANDLE hProcess
  1290. );
  1291. BOOL
  1292. IMAGEAPI
  1293. SymMatchString(
  1294. IN LPSTR string,
  1295. IN LPSTR expression,
  1296. IN BOOL fCase
  1297. );
  1298. typedef BOOL
  1299. (CALLBACK *PSYM_ENUMSOURCFILES_CALLBACK)(
  1300. PSOURCEFILE pSourceFile,
  1301. PVOID UserContext
  1302. );
  1303. BOOL
  1304. IMAGEAPI
  1305. SymEnumSourceFiles(
  1306. IN HANDLE hProcess,
  1307. IN ULONG64 ModBase,
  1308. IN LPSTR Mask,
  1309. IN PSYM_ENUMSOURCFILES_CALLBACK cbSrcFiles,
  1310. IN PVOID UserContext
  1311. );
  1312. BOOL
  1313. IMAGEAPI
  1314. SymEnumerateModules64(
  1315. IN HANDLE hProcess,
  1316. IN PSYM_ENUMMODULES_CALLBACK64 EnumModulesCallback,
  1317. IN PVOID UserContext
  1318. );
  1319. #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64)
  1320. #define SymEnumerateModules SymEnumerateModules64
  1321. #else
  1322. BOOL
  1323. IMAGEAPI
  1324. SymEnumerateModules(
  1325. IN HANDLE hProcess,
  1326. IN PSYM_ENUMMODULES_CALLBACK EnumModulesCallback,
  1327. IN PVOID UserContext
  1328. );
  1329. #endif
  1330. BOOL
  1331. IMAGEAPI
  1332. SymEnumerateSymbols64(
  1333. IN HANDLE hProcess,
  1334. IN DWORD64 BaseOfDll,
  1335. IN PSYM_ENUMSYMBOLS_CALLBACK64 EnumSymbolsCallback,
  1336. IN PVOID UserContext
  1337. );
  1338. BOOL
  1339. IMAGEAPI
  1340. SymEnumerateSymbolsW64(
  1341. IN HANDLE hProcess,
  1342. IN DWORD64 BaseOfDll,
  1343. IN PSYM_ENUMSYMBOLS_CALLBACK64W EnumSymbolsCallback,
  1344. IN PVOID UserContext
  1345. );
  1346. #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64)
  1347. #define SymEnumerateSymbols SymEnumerateSymbols64
  1348. #define SymEnumerateSymbolsW SymEnumerateSymbolsW64
  1349. #else
  1350. BOOL
  1351. IMAGEAPI
  1352. SymEnumerateSymbols(
  1353. IN HANDLE hProcess,
  1354. IN DWORD BaseOfDll,
  1355. IN PSYM_ENUMSYMBOLS_CALLBACK EnumSymbolsCallback,
  1356. IN PVOID UserContext
  1357. );
  1358. BOOL
  1359. IMAGEAPI
  1360. SymEnumerateSymbolsW(
  1361. IN HANDLE hProcess,
  1362. IN DWORD BaseOfDll,
  1363. IN PSYM_ENUMSYMBOLS_CALLBACKW EnumSymbolsCallback,
  1364. IN PVOID UserContext
  1365. );
  1366. #endif
  1367. BOOL
  1368. IMAGEAPI
  1369. EnumerateLoadedModules64(
  1370. IN HANDLE hProcess,
  1371. IN PENUMLOADED_MODULES_CALLBACK64 EnumLoadedModulesCallback,
  1372. IN PVOID UserContext
  1373. );
  1374. #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64)
  1375. #define EnumerateLoadedModules EnumerateLoadedModules64
  1376. #else
  1377. BOOL
  1378. IMAGEAPI
  1379. EnumerateLoadedModules(
  1380. IN HANDLE hProcess,
  1381. IN PENUMLOADED_MODULES_CALLBACK EnumLoadedModulesCallback,
  1382. IN PVOID UserContext
  1383. );
  1384. #endif
  1385. PVOID
  1386. IMAGEAPI
  1387. SymFunctionTableAccess64(
  1388. HANDLE hProcess,
  1389. DWORD64 AddrBase
  1390. );
  1391. #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64)
  1392. #define SymFunctionTableAccess SymFunctionTableAccess64
  1393. #else
  1394. PVOID
  1395. IMAGEAPI
  1396. SymFunctionTableAccess(
  1397. HANDLE hProcess,
  1398. DWORD AddrBase
  1399. );
  1400. #endif
  1401. BOOL
  1402. IMAGEAPI
  1403. SymGetModuleInfo64(
  1404. IN HANDLE hProcess,
  1405. IN DWORD64 qwAddr,
  1406. OUT PIMAGEHLP_MODULE64 ModuleInfo
  1407. );
  1408. BOOL
  1409. IMAGEAPI
  1410. SymGetModuleInfoW64(
  1411. IN HANDLE hProcess,
  1412. IN DWORD64 qwAddr,
  1413. OUT PIMAGEHLP_MODULEW64 ModuleInfo
  1414. );
  1415. #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64)
  1416. #define SymGetModuleInfo SymGetModuleInfo64
  1417. #define SymGetModuleInfoW SymGetModuleInfoW64
  1418. #else
  1419. BOOL
  1420. IMAGEAPI
  1421. SymGetModuleInfo(
  1422. IN HANDLE hProcess,
  1423. IN DWORD dwAddr,
  1424. OUT PIMAGEHLP_MODULE ModuleInfo
  1425. );
  1426. BOOL
  1427. IMAGEAPI
  1428. SymGetModuleInfoW(
  1429. IN HANDLE hProcess,
  1430. IN DWORD dwAddr,
  1431. OUT PIMAGEHLP_MODULEW ModuleInfo
  1432. );
  1433. #endif
  1434. DWORD64
  1435. IMAGEAPI
  1436. SymGetModuleBase64(
  1437. IN HANDLE hProcess,
  1438. IN DWORD64 qwAddr
  1439. );
  1440. #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64)
  1441. #define SymGetModuleBase SymGetModuleBase64
  1442. #else
  1443. DWORD
  1444. IMAGEAPI
  1445. SymGetModuleBase(
  1446. IN HANDLE hProcess,
  1447. IN DWORD dwAddr
  1448. );
  1449. #endif
  1450. BOOL
  1451. IMAGEAPI
  1452. SymGetSymNext64(
  1453. IN HANDLE hProcess,
  1454. IN OUT PIMAGEHLP_SYMBOL64 Symbol
  1455. );
  1456. #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64)
  1457. #define SymGetSymNext SymGetSymNext64
  1458. #else
  1459. BOOL
  1460. IMAGEAPI
  1461. SymGetSymNext(
  1462. IN HANDLE hProcess,
  1463. IN OUT PIMAGEHLP_SYMBOL Symbol
  1464. );
  1465. #endif
  1466. BOOL
  1467. IMAGEAPI
  1468. SymGetSymPrev64(
  1469. IN HANDLE hProcess,
  1470. IN OUT PIMAGEHLP_SYMBOL64 Symbol
  1471. );
  1472. #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64)
  1473. #define SymGetSymPrev SymGetSymPrev64
  1474. #else
  1475. BOOL
  1476. IMAGEAPI
  1477. SymGetSymPrev(
  1478. IN HANDLE hProcess,
  1479. IN OUT PIMAGEHLP_SYMBOL Symbol
  1480. );
  1481. #endif
  1482. typedef struct _SRCCODEINFO {
  1483. DWORD SizeOfStruct; // set to sizeof(SRCCODEINFO)
  1484. PVOID Key; // not used
  1485. DWORD64 ModBase; // base address of module this applies to
  1486. CHAR Obj[MAX_PATH + 1]; // the object file within the module
  1487. CHAR FileName[MAX_PATH + 1]; // full filename
  1488. DWORD LineNumber; // line number in file
  1489. DWORD64 Address; // first instruction of line
  1490. } SRCCODEINFO, *PSRCCODEINFO;
  1491. typedef BOOL
  1492. (CALLBACK *PSYM_ENUMLINES_CALLBACK)(
  1493. PSRCCODEINFO LineInfo,
  1494. PVOID UserContext
  1495. );
  1496. BOOL
  1497. IMAGEAPI
  1498. SymEnumLines(
  1499. IN HANDLE hProcess,
  1500. IN ULONG64 Base,
  1501. IN PCSTR Obj,
  1502. IN PCSTR File,
  1503. IN PSYM_ENUMLINES_CALLBACK EnumLinesCallback,
  1504. IN PVOID UserContext
  1505. );
  1506. BOOL
  1507. IMAGEAPI
  1508. SymGetLineFromAddr64(
  1509. IN HANDLE hProcess,
  1510. IN DWORD64 qwAddr,
  1511. OUT PDWORD pdwDisplacement,
  1512. OUT PIMAGEHLP_LINE64 Line64
  1513. );
  1514. #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64)
  1515. #define SymGetLineFromAddr SymGetLineFromAddr64
  1516. #else
  1517. BOOL
  1518. IMAGEAPI
  1519. SymGetLineFromAddr(
  1520. IN HANDLE hProcess,
  1521. IN DWORD dwAddr,
  1522. OUT PDWORD pdwDisplacement,
  1523. OUT PIMAGEHLP_LINE Line
  1524. );
  1525. #endif
  1526. BOOL
  1527. IMAGEAPI
  1528. SymGetLineFromName64(
  1529. IN HANDLE hProcess,
  1530. IN PSTR ModuleName,
  1531. IN PSTR FileName,
  1532. IN DWORD dwLineNumber,
  1533. OUT PLONG plDisplacement,
  1534. IN OUT PIMAGEHLP_LINE64 Line
  1535. );
  1536. #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64)
  1537. #define SymGetLineFromName SymGetLineFromName64
  1538. #else
  1539. BOOL
  1540. IMAGEAPI
  1541. SymGetLineFromName(
  1542. IN HANDLE hProcess,
  1543. IN PSTR ModuleName,
  1544. IN PSTR FileName,
  1545. IN DWORD dwLineNumber,
  1546. OUT PLONG plDisplacement,
  1547. IN OUT PIMAGEHLP_LINE Line
  1548. );
  1549. #endif
  1550. BOOL
  1551. IMAGEAPI
  1552. SymGetLineNext64(
  1553. IN HANDLE hProcess,
  1554. IN OUT PIMAGEHLP_LINE64 Line
  1555. );
  1556. #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64)
  1557. #define SymGetLineNext SymGetLineNext64
  1558. #else
  1559. BOOL
  1560. IMAGEAPI
  1561. SymGetLineNext(
  1562. IN HANDLE hProcess,
  1563. IN OUT PIMAGEHLP_LINE Line
  1564. );
  1565. #endif
  1566. BOOL
  1567. IMAGEAPI
  1568. SymGetLinePrev64(
  1569. IN HANDLE hProcess,
  1570. IN OUT PIMAGEHLP_LINE64 Line
  1571. );
  1572. #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64)
  1573. #define SymGetLinePrev SymGetLinePrev64
  1574. #else
  1575. BOOL
  1576. IMAGEAPI
  1577. SymGetLinePrev(
  1578. IN HANDLE hProcess,
  1579. IN OUT PIMAGEHLP_LINE Line
  1580. );
  1581. #endif
  1582. BOOL
  1583. IMAGEAPI
  1584. SymMatchFileName(
  1585. IN PSTR FileName,
  1586. IN PSTR Match,
  1587. OUT PSTR *FileNameStop,
  1588. OUT PSTR *MatchStop
  1589. );
  1590. BOOL
  1591. IMAGEAPI
  1592. SymInitialize(
  1593. IN HANDLE hProcess,
  1594. IN PSTR UserSearchPath,
  1595. IN BOOL fInvadeProcess
  1596. );
  1597. BOOL
  1598. IMAGEAPI
  1599. SymGetSearchPath(
  1600. IN HANDLE hProcess,
  1601. OUT PSTR SearchPath,
  1602. IN DWORD SearchPathLength
  1603. );
  1604. BOOL
  1605. IMAGEAPI
  1606. SymSetSearchPath(
  1607. IN HANDLE hProcess,
  1608. IN PSTR SearchPath
  1609. );
  1610. DWORD64
  1611. IMAGEAPI
  1612. SymLoadModule64(
  1613. IN HANDLE hProcess,
  1614. IN HANDLE hFile,
  1615. IN PSTR ImageName,
  1616. IN PSTR ModuleName,
  1617. IN DWORD64 BaseOfDll,
  1618. IN DWORD SizeOfDll
  1619. );
  1620. #define SLMFLAG_VIRTUAL 0x1
  1621. DWORD64
  1622. IMAGEAPI
  1623. SymLoadModuleEx(
  1624. IN HANDLE hProcess,
  1625. IN HANDLE hFile,
  1626. IN PSTR ImageName,
  1627. IN PSTR ModuleName,
  1628. IN DWORD64 BaseOfDll,
  1629. IN DWORD DllSize,
  1630. IN PMODLOAD_DATA Data,
  1631. IN DWORD Flags
  1632. );
  1633. #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64)
  1634. #define SymLoadModule SymLoadModule64
  1635. #else
  1636. DWORD
  1637. IMAGEAPI
  1638. SymLoadModule(
  1639. IN HANDLE hProcess,
  1640. IN HANDLE hFile,
  1641. IN PSTR ImageName,
  1642. IN PSTR ModuleName,
  1643. IN DWORD BaseOfDll,
  1644. IN DWORD SizeOfDll
  1645. );
  1646. #endif
  1647. BOOL
  1648. IMAGEAPI
  1649. SymUnloadModule64(
  1650. IN HANDLE hProcess,
  1651. IN DWORD64 BaseOfDll
  1652. );
  1653. #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64)
  1654. #define SymUnloadModule SymUnloadModule64
  1655. #else
  1656. BOOL
  1657. IMAGEAPI
  1658. SymUnloadModule(
  1659. IN HANDLE hProcess,
  1660. IN DWORD BaseOfDll
  1661. );
  1662. #endif
  1663. BOOL
  1664. IMAGEAPI
  1665. SymUnDName64(
  1666. IN PIMAGEHLP_SYMBOL64 sym, // Symbol to undecorate
  1667. OUT PSTR UnDecName, // Buffer to store undecorated name in
  1668. IN DWORD UnDecNameLength // Size of the buffer
  1669. );
  1670. #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64)
  1671. #define SymUnDName SymUnDName64
  1672. #else
  1673. BOOL
  1674. IMAGEAPI
  1675. SymUnDName(
  1676. IN PIMAGEHLP_SYMBOL sym, // Symbol to undecorate
  1677. OUT PSTR UnDecName, // Buffer to store undecorated name in
  1678. IN DWORD UnDecNameLength // Size of the buffer
  1679. );
  1680. #endif
  1681. BOOL
  1682. IMAGEAPI
  1683. SymRegisterCallback64(
  1684. IN HANDLE hProcess,
  1685. IN PSYMBOL_REGISTERED_CALLBACK64 CallbackFunction,
  1686. IN ULONG64 UserContext
  1687. );
  1688. BOOL
  1689. IMAGEAPI
  1690. SymRegisterFunctionEntryCallback64(
  1691. IN HANDLE hProcess,
  1692. IN PSYMBOL_FUNCENTRY_CALLBACK64 CallbackFunction,
  1693. IN ULONG64 UserContext
  1694. );
  1695. #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64)
  1696. #define SymRegisterCallback SymRegisterCallback64
  1697. #define SymRegisterFunctionEntryCallback SymRegisterFunctionEntryCallback64
  1698. #else
  1699. BOOL
  1700. IMAGEAPI
  1701. SymRegisterCallback(
  1702. IN HANDLE hProcess,
  1703. IN PSYMBOL_REGISTERED_CALLBACK CallbackFunction,
  1704. IN PVOID UserContext
  1705. );
  1706. BOOL
  1707. IMAGEAPI
  1708. SymRegisterFunctionEntryCallback(
  1709. IN HANDLE hProcess,
  1710. IN PSYMBOL_FUNCENTRY_CALLBACK CallbackFunction,
  1711. IN PVOID UserContext
  1712. );
  1713. #endif
  1714. typedef struct _IMAGEHLP_SYMBOL_SRC {
  1715. DWORD sizeofstruct;
  1716. DWORD type;
  1717. char file[MAX_PATH];
  1718. } IMAGEHLP_SYMBOL_SRC, *PIMAGEHLP_SYMBOL_SRC;
  1719. typedef struct _MODULE_TYPE_INFO { // AKA TYPTYP
  1720. USHORT dataLength;
  1721. USHORT leaf;
  1722. BYTE data[1];
  1723. } MODULE_TYPE_INFO, *PMODULE_TYPE_INFO;
  1724. typedef struct _SYMBOL_INFO {
  1725. ULONG SizeOfStruct;
  1726. ULONG TypeIndex; // Type Index of symbol
  1727. ULONG64 Reserved[2];
  1728. ULONG info;
  1729. ULONG Size;
  1730. ULONG64 ModBase; // Base Address of module comtaining this symbol
  1731. ULONG Flags;
  1732. ULONG64 Value; // Value of symbol, ValuePresent should be 1
  1733. ULONG64 Address; // Address of symbol including base address of module
  1734. ULONG Register; // register holding value or pointer to value
  1735. ULONG Scope; // scope of the symbol
  1736. ULONG Tag; // pdb classification
  1737. ULONG NameLen; // Actual length of name
  1738. ULONG MaxNameLen;
  1739. CHAR Name[1]; // Name of symbol
  1740. } SYMBOL_INFO, *PSYMBOL_INFO;
  1741. typedef struct _SYMBOL_INFO_PACKAGE {
  1742. SYMBOL_INFO si;
  1743. CHAR name[MAX_SYM_NAME + 1];
  1744. } SYMBOL_INFO_PACKAGE, *PSYMBOL_INFO_PACKAGE;
  1745. typedef struct _IMAGEHLP_STACK_FRAME
  1746. {
  1747. ULONG64 InstructionOffset;
  1748. ULONG64 ReturnOffset;
  1749. ULONG64 FrameOffset;
  1750. ULONG64 StackOffset;
  1751. ULONG64 BackingStoreOffset;
  1752. ULONG64 FuncTableEntry;
  1753. ULONG64 Params[4];
  1754. ULONG64 Reserved[5];
  1755. BOOL Virtual;
  1756. ULONG Reserved2;
  1757. } IMAGEHLP_STACK_FRAME, *PIMAGEHLP_STACK_FRAME;
  1758. typedef VOID IMAGEHLP_CONTEXT, *PIMAGEHLP_CONTEXT;
  1759. BOOL
  1760. IMAGEAPI
  1761. SymSetContext(
  1762. HANDLE hProcess,
  1763. PIMAGEHLP_STACK_FRAME StackFrame,
  1764. PIMAGEHLP_CONTEXT Context
  1765. );
  1766. BOOL
  1767. IMAGEAPI
  1768. SymFromAddr(
  1769. IN HANDLE hProcess,
  1770. IN DWORD64 Address,
  1771. OUT PDWORD64 Displacement,
  1772. IN OUT PSYMBOL_INFO Symbol
  1773. );
  1774. BOOL
  1775. IMAGEAPI
  1776. SymFromToken(
  1777. IN HANDLE hProcess,
  1778. IN DWORD64 Base,
  1779. IN DWORD Token,
  1780. IN OUT PSYMBOL_INFO Symbol
  1781. );
  1782. // While SymFromName will provide a symbol from a name,
  1783. // SymEnumSymbols can provide the same matching information
  1784. // for ALL symbols with a matching name, even regular
  1785. // expressions. That way you can search across modules
  1786. // and differentiate between identically named symbols.
  1787. BOOL
  1788. IMAGEAPI
  1789. SymFromName(
  1790. IN HANDLE hProcess,
  1791. IN LPSTR Name,
  1792. OUT PSYMBOL_INFO Symbol
  1793. );
  1794. typedef BOOL
  1795. (CALLBACK *PSYM_ENUMERATESYMBOLS_CALLBACK)(
  1796. PSYMBOL_INFO pSymInfo,
  1797. ULONG SymbolSize,
  1798. PVOID UserContext
  1799. );
  1800. BOOL
  1801. IMAGEAPI
  1802. SymEnumSymbols(
  1803. IN HANDLE hProcess,
  1804. IN ULONG64 BaseOfDll,
  1805. IN PCSTR Mask,
  1806. IN PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback,
  1807. IN PVOID UserContext
  1808. );
  1809. BOOL
  1810. IMAGEAPI
  1811. SymEnumSymbolsForAddr(
  1812. IN HANDLE hProcess,
  1813. IN DWORD64 Address,
  1814. IN PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback,
  1815. IN PVOID UserContext
  1816. );
  1817. #define SYMENUMFLAG_FULLSRCH 1
  1818. #define SYMENUMFLAG_SPEEDSRCH 2
  1819. typedef enum _IMAGEHLP_SYMBOL_TYPE_INFO {
  1820. TI_GET_SYMTAG,
  1821. TI_GET_SYMNAME,
  1822. TI_GET_LENGTH,
  1823. TI_GET_TYPE,
  1824. TI_GET_TYPEID,
  1825. TI_GET_BASETYPE,
  1826. TI_GET_ARRAYINDEXTYPEID,
  1827. TI_FINDCHILDREN,
  1828. TI_GET_DATAKIND,
  1829. TI_GET_ADDRESSOFFSET,
  1830. TI_GET_OFFSET,
  1831. TI_GET_VALUE,
  1832. TI_GET_COUNT,
  1833. TI_GET_CHILDRENCOUNT,
  1834. TI_GET_BITPOSITION,
  1835. TI_GET_VIRTUALBASECLASS,
  1836. TI_GET_VIRTUALTABLESHAPEID,
  1837. TI_GET_VIRTUALBASEPOINTEROFFSET,
  1838. TI_GET_CLASSPARENTID,
  1839. TI_GET_NESTED,
  1840. TI_GET_SYMINDEX,
  1841. TI_GET_LEXICALPARENT,
  1842. TI_GET_ADDRESS,
  1843. TI_GET_THISADJUST,
  1844. TI_GET_UDTKIND,
  1845. TI_IS_EQUIV_TO,
  1846. TI_GET_CALLING_CONVENTION,
  1847. } IMAGEHLP_SYMBOL_TYPE_INFO;
  1848. typedef struct _TI_FINDCHILDREN_PARAMS {
  1849. ULONG Count;
  1850. ULONG Start;
  1851. ULONG ChildId[1];
  1852. } TI_FINDCHILDREN_PARAMS;
  1853. BOOL
  1854. IMAGEAPI
  1855. SymGetTypeInfo(
  1856. IN HANDLE hProcess,
  1857. IN DWORD64 ModBase,
  1858. IN ULONG TypeId,
  1859. IN IMAGEHLP_SYMBOL_TYPE_INFO GetType,
  1860. OUT PVOID pInfo
  1861. );
  1862. BOOL
  1863. IMAGEAPI
  1864. SymEnumTypes(
  1865. IN HANDLE hProcess,
  1866. IN ULONG64 BaseOfDll,
  1867. IN PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback,
  1868. IN PVOID UserContext
  1869. );
  1870. BOOL
  1871. IMAGEAPI
  1872. SymGetTypeFromName(
  1873. IN HANDLE hProcess,
  1874. IN ULONG64 BaseOfDll,
  1875. IN LPSTR Name,
  1876. OUT PSYMBOL_INFO Symbol
  1877. );
  1878. BOOL
  1879. IMAGEAPI
  1880. SymAddSymbol(
  1881. IN HANDLE hProcess,
  1882. IN ULONG64 BaseOfDll,
  1883. IN PCSTR Name,
  1884. IN DWORD64 Address,
  1885. IN DWORD Size,
  1886. IN DWORD Flags
  1887. );
  1888. BOOL
  1889. IMAGEAPI
  1890. SymDeleteSymbol(
  1891. IN HANDLE hProcess,
  1892. IN ULONG64 BaseOfDll,
  1893. IN PCSTR Name,
  1894. IN DWORD64 Address,
  1895. IN DWORD Flags
  1896. );
  1897. //
  1898. // Full user-mode dump creation.
  1899. //
  1900. typedef BOOL (WINAPI *PDBGHELP_CREATE_USER_DUMP_CALLBACK)(
  1901. DWORD DataType,
  1902. PVOID* Data,
  1903. LPDWORD DataLength,
  1904. PVOID UserData
  1905. );
  1906. BOOL
  1907. WINAPI
  1908. DbgHelpCreateUserDump(
  1909. IN LPSTR FileName,
  1910. IN PDBGHELP_CREATE_USER_DUMP_CALLBACK Callback,
  1911. IN PVOID UserData
  1912. );
  1913. BOOL
  1914. WINAPI
  1915. DbgHelpCreateUserDumpW(
  1916. IN LPWSTR FileName,
  1917. IN PDBGHELP_CREATE_USER_DUMP_CALLBACK Callback,
  1918. IN PVOID UserData
  1919. );
  1920. // -----------------------------------------------------------------
  1921. // The following 4 legacy APIs are fully supported, but newer
  1922. // ones are recommended. SymFromName and SymFromAddr provide
  1923. // much more detailed info on the returned symbol.
  1924. BOOL
  1925. IMAGEAPI
  1926. SymGetSymFromAddr64(
  1927. IN HANDLE hProcess,
  1928. IN DWORD64 qwAddr,
  1929. OUT PDWORD64 pdwDisplacement,
  1930. OUT PIMAGEHLP_SYMBOL64 Symbol
  1931. );
  1932. #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64)
  1933. #define SymGetSymFromAddr SymGetSymFromAddr64
  1934. #else
  1935. BOOL
  1936. IMAGEAPI
  1937. SymGetSymFromAddr(
  1938. IN HANDLE hProcess,
  1939. IN DWORD dwAddr,
  1940. OUT PDWORD pdwDisplacement,
  1941. OUT PIMAGEHLP_SYMBOL Symbol
  1942. );
  1943. #endif
  1944. // While following two APIs will provide a symbol from a name,
  1945. // SymEnumSymbols can provide the same matching information
  1946. // for ALL symbols with a matching name, even regular
  1947. // expressions. That way you can search across modules
  1948. // and differentiate between identically named symbols.
  1949. BOOL
  1950. IMAGEAPI
  1951. SymGetSymFromName64(
  1952. IN HANDLE hProcess,
  1953. IN PSTR Name,
  1954. OUT PIMAGEHLP_SYMBOL64 Symbol
  1955. );
  1956. #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64)
  1957. #define SymGetSymFromName SymGetSymFromName64
  1958. #else
  1959. BOOL
  1960. IMAGEAPI
  1961. SymGetSymFromName(
  1962. IN HANDLE hProcess,
  1963. IN PSTR Name,
  1964. OUT PIMAGEHLP_SYMBOL Symbol
  1965. );
  1966. #endif
  1967. // -----------------------------------------------------------------
  1968. // The following APIs exist only for backwards compatibility
  1969. // with a pre-release version documented in an MSDN release.
  1970. // You should use SymFindFileInPath if you want to maintain
  1971. // future compatibility.
  1972. DBHLP_DEPRECIATED
  1973. BOOL
  1974. IMAGEAPI
  1975. FindFileInPath(
  1976. HANDLE hprocess,
  1977. LPSTR SearchPath,
  1978. LPSTR FileName,
  1979. PVOID id,
  1980. DWORD two,
  1981. DWORD three,
  1982. DWORD flags,
  1983. LPSTR FilePath
  1984. );
  1985. // You should use SymFindFileInPath if you want to maintain
  1986. // future compatibility.
  1987. DBHLP_DEPRECIATED
  1988. BOOL
  1989. IMAGEAPI
  1990. FindFileInSearchPath(
  1991. HANDLE hprocess,
  1992. LPSTR SearchPath,
  1993. LPSTR FileName,
  1994. DWORD one,
  1995. DWORD two,
  1996. DWORD three,
  1997. LPSTR FilePath
  1998. );
  1999. DBHLP_DEPRECIATED
  2000. BOOL
  2001. IMAGEAPI
  2002. SymEnumSym(
  2003. IN HANDLE hProcess,
  2004. IN ULONG64 BaseOfDll,
  2005. IN PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback,
  2006. IN PVOID UserContext
  2007. );
  2008. // These values should not be used.
  2009. // They have been replaced by SYMFLAG_ values.
  2010. #define SYMF_OMAP_GENERATED 0x00000001
  2011. #define SYMF_OMAP_MODIFIED 0x00000002
  2012. #define SYMF_REGISTER 0x00000008
  2013. #define SYMF_REGREL 0x00000010
  2014. #define SYMF_FRAMEREL 0x00000020
  2015. #define SYMF_PARAMETER 0x00000040
  2016. #define SYMF_LOCAL 0x00000080
  2017. #define SYMF_CONSTANT 0x00000100
  2018. #define SYMF_EXPORT 0x00000200
  2019. #define SYMF_FORWARDER 0x00000400
  2020. #define SYMF_FUNCTION 0x00000800
  2021. #define SYMF_VIRTUAL 0x00001000
  2022. #define SYMF_THUNK 0x00002000
  2023. #define SYMF_TLSREL 0x00004000
  2024. // These values should also not be used.
  2025. // They have been replaced by SYMFLAG_ values.
  2026. #define IMAGEHLP_SYMBOL_INFO_VALUEPRESENT 1
  2027. #define IMAGEHLP_SYMBOL_INFO_REGISTER SYMF_REGISTER // 0x0008
  2028. #define IMAGEHLP_SYMBOL_INFO_REGRELATIVE SYMF_REGREL // 0x0010
  2029. #define IMAGEHLP_SYMBOL_INFO_FRAMERELATIVE SYMF_FRAMEREL // 0x0020
  2030. #define IMAGEHLP_SYMBOL_INFO_PARAMETER SYMF_PARAMETER // 0x0040
  2031. #define IMAGEHLP_SYMBOL_INFO_LOCAL SYMF_LOCAL // 0x0080
  2032. #define IMAGEHLP_SYMBOL_INFO_CONSTANT SYMF_CONSTANT // 0x0100
  2033. #define IMAGEHLP_SYMBOL_FUNCTION SYMF_FUNCTION // 0x0800
  2034. #define IMAGEHLP_SYMBOL_VIRTUAL SYMF_VIRTUAL // 0x1000
  2035. #define IMAGEHLP_SYMBOL_THUNK SYMF_THUNK // 0x2000
  2036. #define IMAGEHLP_SYMBOL_INFO_TLSRELATIVE SYMF_TLSREL // 0x4000
  2037. #include <pshpack4.h>
  2038. #if defined(_MSC_VER)
  2039. #if _MSC_VER >= 800
  2040. #if _MSC_VER >= 1200
  2041. #pragma warning(push)
  2042. #endif
  2043. #pragma warning(disable:4200) /* Zero length array */
  2044. #pragma warning(disable:4201) /* Nameless struct/union */
  2045. #endif
  2046. #endif
  2047. #define MINIDUMP_SIGNATURE ('PMDM')
  2048. #define MINIDUMP_VERSION (42899)
  2049. typedef DWORD RVA;
  2050. typedef ULONG64 RVA64;
  2051. typedef struct _MINIDUMP_LOCATION_DESCRIPTOR {
  2052. ULONG32 DataSize;
  2053. RVA Rva;
  2054. } MINIDUMP_LOCATION_DESCRIPTOR;
  2055. typedef struct _MINIDUMP_LOCATION_DESCRIPTOR64 {
  2056. ULONG64 DataSize;
  2057. RVA64 Rva;
  2058. } MINIDUMP_LOCATION_DESCRIPTOR64;
  2059. typedef struct _MINIDUMP_MEMORY_DESCRIPTOR {
  2060. ULONG64 StartOfMemoryRange;
  2061. MINIDUMP_LOCATION_DESCRIPTOR Memory;
  2062. } MINIDUMP_MEMORY_DESCRIPTOR, *PMINIDUMP_MEMORY_DESCRIPTOR;
  2063. // DESCRIPTOR64 is used for full-memory minidumps where
  2064. // all of the raw memory is laid out sequentially at the
  2065. // end of the dump. There is no need for individual RVAs
  2066. // as the RVA is the base RVA plus the sum of the preceeding
  2067. // data blocks.
  2068. typedef struct _MINIDUMP_MEMORY_DESCRIPTOR64 {
  2069. ULONG64 StartOfMemoryRange;
  2070. ULONG64 DataSize;
  2071. } MINIDUMP_MEMORY_DESCRIPTOR64, *PMINIDUMP_MEMORY_DESCRIPTOR64;
  2072. typedef struct _MINIDUMP_HEADER {
  2073. ULONG32 Signature;
  2074. ULONG32 Version;
  2075. ULONG32 NumberOfStreams;
  2076. RVA StreamDirectoryRva;
  2077. ULONG32 CheckSum;
  2078. union {
  2079. ULONG32 Reserved;
  2080. ULONG32 TimeDateStamp;
  2081. };
  2082. ULONG64 Flags;
  2083. } MINIDUMP_HEADER, *PMINIDUMP_HEADER;
  2084. //
  2085. // The MINIDUMP_HEADER field StreamDirectoryRva points to
  2086. // an array of MINIDUMP_DIRECTORY structures.
  2087. //
  2088. typedef struct _MINIDUMP_DIRECTORY {
  2089. ULONG32 StreamType;
  2090. MINIDUMP_LOCATION_DESCRIPTOR Location;
  2091. } MINIDUMP_DIRECTORY, *PMINIDUMP_DIRECTORY;
  2092. typedef struct _MINIDUMP_STRING {
  2093. ULONG32 Length; // Length in bytes of the string
  2094. WCHAR Buffer [0]; // Variable size buffer
  2095. } MINIDUMP_STRING, *PMINIDUMP_STRING;
  2096. //
  2097. // The MINIDUMP_DIRECTORY field StreamType may be one of the following types.
  2098. // Types will be added in the future, so if a program reading the minidump
  2099. // header encounters a stream type it does not understand it should ignore
  2100. // the data altogether. Any tag above LastReservedStream will not be used by
  2101. // the system and is reserved for program-specific information.
  2102. //
  2103. typedef enum _MINIDUMP_STREAM_TYPE {
  2104. UnusedStream = 0,
  2105. ReservedStream0 = 1,
  2106. ReservedStream1 = 2,
  2107. ThreadListStream = 3,
  2108. ModuleListStream = 4,
  2109. MemoryListStream = 5,
  2110. ExceptionStream = 6,
  2111. SystemInfoStream = 7,
  2112. ThreadExListStream = 8,
  2113. Memory64ListStream = 9,
  2114. CommentStreamA = 10,
  2115. CommentStreamW = 11,
  2116. HandleDataStream = 12,
  2117. FunctionTableStream = 13,
  2118. UnloadedModuleListStream = 14,
  2119. MiscInfoStream = 15,
  2120. LastReservedStream = 0xffff
  2121. } MINIDUMP_STREAM_TYPE;
  2122. //
  2123. // The minidump system information contains processor and
  2124. // Operating System specific information.
  2125. //
  2126. //
  2127. // CPU information is obtained from one of two places.
  2128. //
  2129. // 1) On x86 computers, CPU_INFORMATION is obtained from the CPUID
  2130. // instruction. You must use the X86 portion of the union for X86
  2131. // computers.
  2132. //
  2133. // 2) On non-x86 architectures, CPU_INFORMATION is obtained by calling
  2134. // IsProcessorFeatureSupported().
  2135. //
  2136. typedef union _CPU_INFORMATION {
  2137. //
  2138. // X86 platforms use CPUID function to obtain processor information.
  2139. //
  2140. struct {
  2141. //
  2142. // CPUID Subfunction 0, register EAX (VendorId [0]),
  2143. // EBX (VendorId [1]) and ECX (VendorId [2]).
  2144. //
  2145. ULONG32 VendorId [ 3 ];
  2146. //
  2147. // CPUID Subfunction 1, register EAX
  2148. //
  2149. ULONG32 VersionInformation;
  2150. //
  2151. // CPUID Subfunction 1, register EDX
  2152. //
  2153. ULONG32 FeatureInformation;
  2154. //
  2155. // CPUID, Subfunction 80000001, register EBX. This will only
  2156. // be obtained if the vendor id is "AuthenticAMD".
  2157. //
  2158. ULONG32 AMDExtendedCpuFeatures;
  2159. } X86CpuInfo;
  2160. //
  2161. // Non-x86 platforms use processor feature flags.
  2162. //
  2163. struct {
  2164. ULONG64 ProcessorFeatures [ 2 ];
  2165. } OtherCpuInfo;
  2166. } CPU_INFORMATION, *PCPU_INFORMATION;
  2167. typedef struct _MINIDUMP_SYSTEM_INFO {
  2168. //
  2169. // ProcessorArchitecture, ProcessorLevel and ProcessorRevision are all
  2170. // taken from the SYSTEM_INFO structure obtained by GetSystemInfo( ).
  2171. //
  2172. USHORT ProcessorArchitecture;
  2173. USHORT ProcessorLevel;
  2174. USHORT ProcessorRevision;
  2175. union {
  2176. USHORT Reserved0;
  2177. struct {
  2178. UCHAR NumberOfProcessors;
  2179. UCHAR ProductType;
  2180. };
  2181. };
  2182. //
  2183. // MajorVersion, MinorVersion, BuildNumber, PlatformId and
  2184. // CSDVersion are all taken from the OSVERSIONINFO structure
  2185. // returned by GetVersionEx( ).
  2186. //
  2187. ULONG32 MajorVersion;
  2188. ULONG32 MinorVersion;
  2189. ULONG32 BuildNumber;
  2190. ULONG32 PlatformId;
  2191. //
  2192. // RVA to a CSDVersion string in the string table.
  2193. //
  2194. RVA CSDVersionRva;
  2195. union {
  2196. ULONG32 Reserved1;
  2197. struct {
  2198. USHORT SuiteMask;
  2199. USHORT Reserved2;
  2200. };
  2201. };
  2202. CPU_INFORMATION Cpu;
  2203. } MINIDUMP_SYSTEM_INFO, *PMINIDUMP_SYSTEM_INFO;
  2204. //
  2205. // The minidump thread contains standard thread
  2206. // information plus an RVA to the memory for this
  2207. // thread and an RVA to the CONTEXT structure for
  2208. // this thread.
  2209. //
  2210. //
  2211. // ThreadId must be 4 bytes on all architectures.
  2212. //
  2213. C_ASSERT (sizeof ( ((PPROCESS_INFORMATION)0)->dwThreadId ) == 4);
  2214. typedef struct _MINIDUMP_THREAD {
  2215. ULONG32 ThreadId;
  2216. ULONG32 SuspendCount;
  2217. ULONG32 PriorityClass;
  2218. ULONG32 Priority;
  2219. ULONG64 Teb;
  2220. MINIDUMP_MEMORY_DESCRIPTOR Stack;
  2221. MINIDUMP_LOCATION_DESCRIPTOR ThreadContext;
  2222. } MINIDUMP_THREAD, *PMINIDUMP_THREAD;
  2223. //
  2224. // The thread list is a container of threads.
  2225. //
  2226. typedef struct _MINIDUMP_THREAD_LIST {
  2227. ULONG32 NumberOfThreads;
  2228. MINIDUMP_THREAD Threads [0];
  2229. } MINIDUMP_THREAD_LIST, *PMINIDUMP_THREAD_LIST;
  2230. typedef struct _MINIDUMP_THREAD_EX {
  2231. ULONG32 ThreadId;
  2232. ULONG32 SuspendCount;
  2233. ULONG32 PriorityClass;
  2234. ULONG32 Priority;
  2235. ULONG64 Teb;
  2236. MINIDUMP_MEMORY_DESCRIPTOR Stack;
  2237. MINIDUMP_LOCATION_DESCRIPTOR ThreadContext;
  2238. MINIDUMP_MEMORY_DESCRIPTOR BackingStore;
  2239. } MINIDUMP_THREAD_EX, *PMINIDUMP_THREAD_EX;
  2240. //
  2241. // The thread list is a container of threads.
  2242. //
  2243. typedef struct _MINIDUMP_THREAD_EX_LIST {
  2244. ULONG32 NumberOfThreads;
  2245. MINIDUMP_THREAD_EX Threads [0];
  2246. } MINIDUMP_THREAD_EX_LIST, *PMINIDUMP_THREAD_EX_LIST;
  2247. //
  2248. // The MINIDUMP_EXCEPTION is the same as EXCEPTION on Win64.
  2249. //
  2250. typedef struct _MINIDUMP_EXCEPTION {
  2251. ULONG32 ExceptionCode;
  2252. ULONG32 ExceptionFlags;
  2253. ULONG64 ExceptionRecord;
  2254. ULONG64 ExceptionAddress;
  2255. ULONG32 NumberParameters;
  2256. ULONG32 __unusedAlignment;
  2257. ULONG64 ExceptionInformation [ EXCEPTION_MAXIMUM_PARAMETERS ];
  2258. } MINIDUMP_EXCEPTION, *PMINIDUMP_EXCEPTION;
  2259. //
  2260. // The exception information stream contains the id of the thread that caused
  2261. // the exception (ThreadId), the exception record for the exception
  2262. // (ExceptionRecord) and an RVA to the thread context where the exception
  2263. // occured.
  2264. //
  2265. typedef struct MINIDUMP_EXCEPTION_STREAM {
  2266. ULONG32 ThreadId;
  2267. ULONG32 __alignment;
  2268. MINIDUMP_EXCEPTION ExceptionRecord;
  2269. MINIDUMP_LOCATION_DESCRIPTOR ThreadContext;
  2270. } MINIDUMP_EXCEPTION_STREAM, *PMINIDUMP_EXCEPTION_STREAM;
  2271. //
  2272. // The MINIDUMP_MODULE contains information about a
  2273. // a specific module. It includes the CheckSum and
  2274. // the TimeDateStamp for the module so the module
  2275. // can be reloaded during the analysis phase.
  2276. //
  2277. typedef struct _MINIDUMP_MODULE {
  2278. ULONG64 BaseOfImage;
  2279. ULONG32 SizeOfImage;
  2280. ULONG32 CheckSum;
  2281. ULONG32 TimeDateStamp;
  2282. RVA ModuleNameRva;
  2283. VS_FIXEDFILEINFO VersionInfo;
  2284. MINIDUMP_LOCATION_DESCRIPTOR CvRecord;
  2285. MINIDUMP_LOCATION_DESCRIPTOR MiscRecord;
  2286. ULONG64 Reserved0; // Reserved for future use.
  2287. ULONG64 Reserved1; // Reserved for future use.
  2288. } MINIDUMP_MODULE, *PMINIDUMP_MODULE;
  2289. //
  2290. // The minidump module list is a container for modules.
  2291. //
  2292. typedef struct _MINIDUMP_MODULE_LIST {
  2293. ULONG32 NumberOfModules;
  2294. MINIDUMP_MODULE Modules [ 0 ];
  2295. } MINIDUMP_MODULE_LIST, *PMINIDUMP_MODULE_LIST;
  2296. //
  2297. // Memory Ranges
  2298. //
  2299. typedef struct _MINIDUMP_MEMORY_LIST {
  2300. ULONG32 NumberOfMemoryRanges;
  2301. MINIDUMP_MEMORY_DESCRIPTOR MemoryRanges [0];
  2302. } MINIDUMP_MEMORY_LIST, *PMINIDUMP_MEMORY_LIST;
  2303. typedef struct _MINIDUMP_MEMORY64_LIST {
  2304. ULONG64 NumberOfMemoryRanges;
  2305. RVA64 BaseRva;
  2306. MINIDUMP_MEMORY_DESCRIPTOR64 MemoryRanges [0];
  2307. } MINIDUMP_MEMORY64_LIST, *PMINIDUMP_MEMORY64_LIST;
  2308. //
  2309. // Support for user supplied exception information.
  2310. //
  2311. typedef struct _MINIDUMP_EXCEPTION_INFORMATION {
  2312. DWORD ThreadId;
  2313. PEXCEPTION_POINTERS ExceptionPointers;
  2314. BOOL ClientPointers;
  2315. } MINIDUMP_EXCEPTION_INFORMATION, *PMINIDUMP_EXCEPTION_INFORMATION;
  2316. typedef struct _MINIDUMP_EXCEPTION_INFORMATION64 {
  2317. DWORD ThreadId;
  2318. ULONG64 ExceptionRecord;
  2319. ULONG64 ContextRecord;
  2320. BOOL ClientPointers;
  2321. } MINIDUMP_EXCEPTION_INFORMATION64, *PMINIDUMP_EXCEPTION_INFORMATION64;
  2322. //
  2323. // Support for capturing system handle state at the time of the dump.
  2324. //
  2325. typedef struct _MINIDUMP_HANDLE_DESCRIPTOR {
  2326. ULONG64 Handle;
  2327. RVA TypeNameRva;
  2328. RVA ObjectNameRva;
  2329. ULONG32 Attributes;
  2330. ULONG32 GrantedAccess;
  2331. ULONG32 HandleCount;
  2332. ULONG32 PointerCount;
  2333. } MINIDUMP_HANDLE_DESCRIPTOR, *PMINIDUMP_HANDLE_DESCRIPTOR;
  2334. typedef struct _MINIDUMP_HANDLE_DATA_STREAM {
  2335. ULONG32 SizeOfHeader;
  2336. ULONG32 SizeOfDescriptor;
  2337. ULONG32 NumberOfDescriptors;
  2338. ULONG32 Reserved;
  2339. } MINIDUMP_HANDLE_DATA_STREAM, *PMINIDUMP_HANDLE_DATA_STREAM;
  2340. //
  2341. // Support for capturing dynamic function table state at the time of the dump.
  2342. //
  2343. typedef struct _MINIDUMP_FUNCTION_TABLE_DESCRIPTOR {
  2344. ULONG64 MinimumAddress;
  2345. ULONG64 MaximumAddress;
  2346. ULONG64 BaseAddress;
  2347. ULONG32 EntryCount;
  2348. ULONG32 SizeOfAlignPad;
  2349. } MINIDUMP_FUNCTION_TABLE_DESCRIPTOR, *PMINIDUMP_FUNCTION_TABLE_DESCRIPTOR;
  2350. typedef struct _MINIDUMP_FUNCTION_TABLE_STREAM {
  2351. ULONG32 SizeOfHeader;
  2352. ULONG32 SizeOfDescriptor;
  2353. ULONG32 SizeOfNativeDescriptor;
  2354. ULONG32 SizeOfFunctionEntry;
  2355. ULONG32 NumberOfDescriptors;
  2356. ULONG32 SizeOfAlignPad;
  2357. } MINIDUMP_FUNCTION_TABLE_STREAM, *PMINIDUMP_FUNCTION_TABLE_STREAM;
  2358. //
  2359. // The MINIDUMP_UNLOADED_MODULE contains information about a
  2360. // a specific module that was previously loaded but no
  2361. // longer is. This can help with diagnosing problems where
  2362. // callers attempt to call code that is no longer loaded.
  2363. //
  2364. typedef struct _MINIDUMP_UNLOADED_MODULE {
  2365. ULONG64 BaseOfImage;
  2366. ULONG32 SizeOfImage;
  2367. ULONG32 CheckSum;
  2368. ULONG32 TimeDateStamp;
  2369. RVA ModuleNameRva;
  2370. } MINIDUMP_UNLOADED_MODULE, *PMINIDUMP_UNLOADED_MODULE;
  2371. //
  2372. // The minidump unloaded module list is a container for unloaded modules.
  2373. //
  2374. typedef struct _MINIDUMP_UNLOADED_MODULE_LIST {
  2375. ULONG32 SizeOfHeader;
  2376. ULONG32 SizeOfEntry;
  2377. ULONG32 NumberOfEntries;
  2378. } MINIDUMP_UNLOADED_MODULE_LIST, *PMINIDUMP_UNLOADED_MODULE_LIST;
  2379. //
  2380. // The miscellaneous information stream contains a variety
  2381. // of small pieces of information. A member is valid if
  2382. // it's within the available size and its corresponding
  2383. // bit is set.
  2384. //
  2385. #define MINIDUMP_MISC1_PROCESS_ID 0x00000001
  2386. #define MINIDUMP_MISC1_PROCESS_TIMES 0x00000002
  2387. typedef struct _MINIDUMP_MISC_INFO {
  2388. ULONG32 SizeOfInfo;
  2389. ULONG32 Flags1;
  2390. ULONG32 ProcessId;
  2391. ULONG32 ProcessCreateTime;
  2392. ULONG32 ProcessUserTime;
  2393. ULONG32 ProcessKernelTime;
  2394. } MINIDUMP_MISC_INFO, *PMINIDUMP_MISC_INFO;
  2395. //
  2396. // Support for arbitrary user-defined information.
  2397. //
  2398. typedef struct _MINIDUMP_USER_RECORD {
  2399. ULONG32 Type;
  2400. MINIDUMP_LOCATION_DESCRIPTOR Memory;
  2401. } MINIDUMP_USER_RECORD, *PMINIDUMP_USER_RECORD;
  2402. typedef struct _MINIDUMP_USER_STREAM {
  2403. ULONG32 Type;
  2404. ULONG BufferSize;
  2405. PVOID Buffer;
  2406. } MINIDUMP_USER_STREAM, *PMINIDUMP_USER_STREAM;
  2407. typedef struct _MINIDUMP_USER_STREAM_INFORMATION {
  2408. ULONG UserStreamCount;
  2409. PMINIDUMP_USER_STREAM UserStreamArray;
  2410. } MINIDUMP_USER_STREAM_INFORMATION, *PMINIDUMP_USER_STREAM_INFORMATION;
  2411. //
  2412. // Callback support.
  2413. //
  2414. typedef enum _MINIDUMP_CALLBACK_TYPE {
  2415. ModuleCallback,
  2416. ThreadCallback,
  2417. ThreadExCallback,
  2418. IncludeThreadCallback,
  2419. IncludeModuleCallback,
  2420. MemoryCallback,
  2421. } MINIDUMP_CALLBACK_TYPE;
  2422. typedef struct _MINIDUMP_THREAD_CALLBACK {
  2423. ULONG ThreadId;
  2424. HANDLE ThreadHandle;
  2425. CONTEXT Context;
  2426. ULONG SizeOfContext;
  2427. ULONG64 StackBase;
  2428. ULONG64 StackEnd;
  2429. } MINIDUMP_THREAD_CALLBACK, *PMINIDUMP_THREAD_CALLBACK;
  2430. typedef struct _MINIDUMP_THREAD_EX_CALLBACK {
  2431. ULONG ThreadId;
  2432. HANDLE ThreadHandle;
  2433. CONTEXT Context;
  2434. ULONG SizeOfContext;
  2435. ULONG64 StackBase;
  2436. ULONG64 StackEnd;
  2437. ULONG64 BackingStoreBase;
  2438. ULONG64 BackingStoreEnd;
  2439. } MINIDUMP_THREAD_EX_CALLBACK, *PMINIDUMP_THREAD_EX_CALLBACK;
  2440. typedef struct _MINIDUMP_INCLUDE_THREAD_CALLBACK {
  2441. ULONG ThreadId;
  2442. } MINIDUMP_INCLUDE_THREAD_CALLBACK, *PMINIDUMP_INCLUDE_THREAD_CALLBACK;
  2443. typedef enum _THREAD_WRITE_FLAGS {
  2444. ThreadWriteThread = 0x0001,
  2445. ThreadWriteStack = 0x0002,
  2446. ThreadWriteContext = 0x0004,
  2447. ThreadWriteBackingStore = 0x0008,
  2448. ThreadWriteInstructionWindow = 0x0010,
  2449. ThreadWriteThreadData = 0x0020,
  2450. } THREAD_WRITE_FLAGS;
  2451. typedef struct _MINIDUMP_MODULE_CALLBACK {
  2452. PWCHAR FullPath;
  2453. ULONG64 BaseOfImage;
  2454. ULONG SizeOfImage;
  2455. ULONG CheckSum;
  2456. ULONG TimeDateStamp;
  2457. VS_FIXEDFILEINFO VersionInfo;
  2458. PVOID CvRecord;
  2459. ULONG SizeOfCvRecord;
  2460. PVOID MiscRecord;
  2461. ULONG SizeOfMiscRecord;
  2462. } MINIDUMP_MODULE_CALLBACK, *PMINIDUMP_MODULE_CALLBACK;
  2463. typedef struct _MINIDUMP_INCLUDE_MODULE_CALLBACK {
  2464. ULONG64 BaseOfImage;
  2465. } MINIDUMP_INCLUDE_MODULE_CALLBACK, *PMINIDUMP_INCLUDE_MODULE_CALLBACK;
  2466. typedef enum _MODULE_WRITE_FLAGS {
  2467. ModuleWriteModule = 0x0001,
  2468. ModuleWriteDataSeg = 0x0002,
  2469. ModuleWriteMiscRecord = 0x0004,
  2470. ModuleWriteCvRecord = 0x0008,
  2471. ModuleReferencedByMemory = 0x0010
  2472. } MODULE_WRITE_FLAGS;
  2473. typedef struct _MINIDUMP_CALLBACK_INPUT {
  2474. ULONG ProcessId;
  2475. HANDLE ProcessHandle;
  2476. ULONG CallbackType;
  2477. union {
  2478. MINIDUMP_THREAD_CALLBACK Thread;
  2479. MINIDUMP_THREAD_EX_CALLBACK ThreadEx;
  2480. MINIDUMP_MODULE_CALLBACK Module;
  2481. MINIDUMP_INCLUDE_THREAD_CALLBACK IncludeThread;
  2482. MINIDUMP_INCLUDE_MODULE_CALLBACK IncludeModule;
  2483. };
  2484. } MINIDUMP_CALLBACK_INPUT, *PMINIDUMP_CALLBACK_INPUT;
  2485. typedef struct _MINIDUMP_CALLBACK_OUTPUT {
  2486. union {
  2487. ULONG ModuleWriteFlags;
  2488. ULONG ThreadWriteFlags;
  2489. struct {
  2490. ULONG64 MemoryBase;
  2491. ULONG MemorySize;
  2492. };
  2493. };
  2494. } MINIDUMP_CALLBACK_OUTPUT, *PMINIDUMP_CALLBACK_OUTPUT;
  2495. //
  2496. // A normal minidump contains just the information
  2497. // necessary to capture stack traces for all of the
  2498. // existing threads in a process.
  2499. //
  2500. // A minidump with data segments includes all of the data
  2501. // sections from loaded modules in order to capture
  2502. // global variable contents. This can make the dump much
  2503. // larger if many modules have global data.
  2504. //
  2505. // A minidump with full memory includes all of the accessible
  2506. // memory in the process and can be very large. A minidump
  2507. // with full memory always has the raw memory data at the end
  2508. // of the dump so that the initial structures in the dump can
  2509. // be mapped directly without having to include the raw
  2510. // memory information.
  2511. //
  2512. // Stack and backing store memory can be filtered to remove
  2513. // data unnecessary for stack walking. This can improve
  2514. // compression of stacks and also deletes data that may
  2515. // be private and should not be stored in a dump.
  2516. // Memory can also be scanned to see what modules are
  2517. // referenced by stack and backing store memory to allow
  2518. // omission of other modules to reduce dump size.
  2519. // In either of these modes the ModuleReferencedByMemory flag
  2520. // is set for all modules referenced before the base
  2521. // module callbacks occur.
  2522. //
  2523. // On some operating systems a list of modules that were
  2524. // recently unloaded is kept in addition to the currently
  2525. // loaded module list. This information can be saved in
  2526. // the dump if desired.
  2527. //
  2528. // Stack and backing store memory can be scanned for referenced
  2529. // pages in order to pick up data referenced by locals or other
  2530. // stack memory. This can increase the size of a dump significantly.
  2531. //
  2532. // Module paths may contain undesired information such as user names
  2533. // or other important directory names so they can be stripped. This
  2534. // option reduces the ability to locate the proper image later
  2535. // and should only be used in certain situations.
  2536. //
  2537. // Complete operating system per-process and per-thread information can
  2538. // be gathered and stored in the dump.
  2539. //
  2540. // The virtual address space can be scanned for various types
  2541. // of memory to be included in the dump.
  2542. //
  2543. // Code which is concerned with potentially private information
  2544. // getting into the minidump can set a flag that automatically
  2545. // modifies all existing and future flags to avoid placing
  2546. // unnecessary data in the dump. Basic data, such as stack
  2547. // information, will still be included but optional data, such
  2548. // as indirect memory, will not.
  2549. //
  2550. typedef enum _MINIDUMP_TYPE {
  2551. MiniDumpNormal = 0x0000,
  2552. MiniDumpWithDataSegs = 0x0001,
  2553. MiniDumpWithFullMemory = 0x0002,
  2554. MiniDumpWithHandleData = 0x0004,
  2555. MiniDumpFilterMemory = 0x0008,
  2556. MiniDumpScanMemory = 0x0010,
  2557. MiniDumpWithUnloadedModules = 0x0020,
  2558. MiniDumpWithIndirectlyReferencedMemory = 0x0040,
  2559. MiniDumpFilterModulePaths = 0x0080,
  2560. MiniDumpWithProcessThreadData = 0x0100,
  2561. MiniDumpWithPrivateReadWriteMemory = 0x0200,
  2562. MiniDumpWithoutOptionalData = 0x0400,
  2563. } MINIDUMP_TYPE;
  2564. //
  2565. // The minidump callback should modify the FieldsToWrite parameter to reflect
  2566. // what portions of the specified thread or module should be written to the
  2567. // file.
  2568. //
  2569. typedef
  2570. BOOL
  2571. (WINAPI * MINIDUMP_CALLBACK_ROUTINE) (
  2572. IN PVOID CallbackParam,
  2573. IN CONST PMINIDUMP_CALLBACK_INPUT CallbackInput,
  2574. IN OUT PMINIDUMP_CALLBACK_OUTPUT CallbackOutput
  2575. );
  2576. typedef struct _MINIDUMP_CALLBACK_INFORMATION {
  2577. MINIDUMP_CALLBACK_ROUTINE CallbackRoutine;
  2578. PVOID CallbackParam;
  2579. } MINIDUMP_CALLBACK_INFORMATION, *PMINIDUMP_CALLBACK_INFORMATION;
  2580. //++
  2581. //
  2582. // PVOID
  2583. // RVA_TO_ADDR(
  2584. // PVOID Mapping,
  2585. // ULONG Rva
  2586. // )
  2587. //
  2588. // Routine Description:
  2589. //
  2590. // Map an RVA that is contained within a mapped file to it's associated
  2591. // flat address.
  2592. //
  2593. // Arguments:
  2594. //
  2595. // Mapping - Base address of mapped file containing the RVA.
  2596. //
  2597. // Rva - An Rva to fixup.
  2598. //
  2599. // Return Values:
  2600. //
  2601. // A pointer to the desired data.
  2602. //
  2603. //--
  2604. #define RVA_TO_ADDR(Mapping,Rva) ((PVOID)(((ULONG_PTR) (Mapping)) + (Rva)))
  2605. BOOL
  2606. WINAPI
  2607. MiniDumpWriteDump(
  2608. IN HANDLE hProcess,
  2609. IN DWORD ProcessId,
  2610. IN HANDLE hFile,
  2611. IN MINIDUMP_TYPE DumpType,
  2612. IN CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, OPTIONAL
  2613. IN CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam, OPTIONAL
  2614. IN CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam OPTIONAL
  2615. );
  2616. BOOL
  2617. WINAPI
  2618. MiniDumpReadDumpStream(
  2619. IN PVOID BaseOfDump,
  2620. IN ULONG StreamNumber,
  2621. OUT PMINIDUMP_DIRECTORY * Dir, OPTIONAL
  2622. OUT PVOID * StreamPointer, OPTIONAL
  2623. OUT ULONG * StreamSize OPTIONAL
  2624. );
  2625. #if defined(_MSC_VER)
  2626. #if _MSC_VER >= 800
  2627. #if _MSC_VER >= 1200
  2628. #pragma warning(pop)
  2629. #else
  2630. #pragma warning(default:4200) /* Zero length array */
  2631. #pragma warning(default:4201) /* Nameless struct/union */
  2632. #endif
  2633. #endif
  2634. #endif
  2635. #include <poppack.h>
  2636. #ifdef __cplusplus
  2637. }
  2638. #endif
  2639. #endif // _IMAGEHLP_