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.

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