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.

919 lines
23 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. imagehlp.h
  5. Abstract:
  6. This is a private header file for imagehlp.
  7. Revision History:
  8. --*/
  9. #ifndef _IMAGEHLP_PRV_
  10. #define _IMAGEHLP_PRV_
  11. #define _IMAGEHLP_SOURCE_
  12. #define _IA64REG_
  13. #include <windows.h>
  14. #include <imagehlp.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <ctype.h>
  18. #include <memory.h>
  19. #include <malloc.h>
  20. #include <dbgeng.h>
  21. #if DBG
  22. // disable the -DNDEBUG set by oak\bin\makefile.def
  23. #undef NDEBUG
  24. #endif // DBG
  25. #include <assert.h>
  26. #include <string.h>
  27. #include <time.h>
  28. #include <ntverp.h>
  29. #include <cvexefmt.h>
  30. #define PDB_LIBRARY
  31. #include <pdb.h>
  32. #include "pdbp.h"
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. // used for delayloading the pdb handler
  37. #define REGKEY_DBGHELP "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\dbgHelp"
  38. #define REGVAL_PDBHANDLER "PDBHandler"
  39. // define the module
  40. #ifdef BUILD_DBGHELP
  41. #define MOD_FILENAME "dbghelp.dll"
  42. #define MOD_NAME "dbghelp"
  43. #else
  44. #define MOD_FILENAME "imagehlp.dll"
  45. #define MOD_NAME "imagehlp"
  46. #endif
  47. #ifndef SIZEOF_ARRAY
  48. #define SIZEOF_ARRAY(_ar) (sizeof(_ar)/sizeof((_ar)[0]))
  49. #endif // !defined(SIZEOF_ARRAY)
  50. /******************************************************************************
  51. On a Hydra System, we don't want imaghlp.dll to load user32.dll since it
  52. prevents CSRSS from exiting when running a under a debugger.
  53. The following two functions have been copied from user32.dll so that we don't
  54. link to user32.dll.
  55. ******************************************************************************/
  56. #undef CharNext
  57. #undef CharPrev
  58. LPSTR CharNext(
  59. LPCSTR lpCurrentChar);
  60. LPSTR CharPrev(
  61. LPCSTR lpStart,
  62. LPCSTR lpCurrentChar);
  63. // Define some list prototypes
  64. #define InitializeListHead(ListHead) (\
  65. (ListHead)->Flink = (ListHead)->Blink = (ListHead))
  66. #define IsListEmpty(ListHead) \
  67. ((ListHead)->Flink == (ListHead))
  68. #define InsertTailList(ListHead,Entry) {\
  69. PLIST_ENTRY _EX_Blink;\
  70. PLIST_ENTRY _EX_ListHead;\
  71. _EX_ListHead = (ListHead);\
  72. _EX_Blink = _EX_ListHead->Blink;\
  73. (Entry)->Flink = _EX_ListHead;\
  74. (Entry)->Blink = _EX_Blink;\
  75. _EX_Blink->Flink = (Entry);\
  76. _EX_ListHead->Blink = (Entry);\
  77. }
  78. #define RemoveEntryList(Entry) {\
  79. PLIST_ENTRY _EX_Blink;\
  80. PLIST_ENTRY _EX_Flink;\
  81. _EX_Flink = (Entry)->Flink;\
  82. _EX_Blink = (Entry)->Blink;\
  83. _EX_Blink->Flink = _EX_Flink;\
  84. _EX_Flink->Blink = _EX_Blink;\
  85. }
  86. //
  87. // some helpers for PE32/PE64 issues
  88. //
  89. #define OPTIONALHEADER(field) (OptionalHeader32 ? (OptionalHeader32->field) : (OptionalHeader64 ? OptionalHeader64->field : 0))
  90. #define OPTIONALHEADER_LV(field) (*(OptionalHeader32 ? &(OptionalHeader32->field) : &(OptionalHeader64->field)))
  91. #define OPTIONALHEADER_ASSIGN(field,value) (OptionalHeader32 ? (OptionalHeader32->field=(value)) : (OptionalHeader64->field=(value)))
  92. #define OPTIONALHEADER_SET_FLAG(field,flag) (OptionalHeader32 ? (OptionalHeader32->field |=(flag)) : (OptionalHeader64->field|=(flag)))
  93. #define OPTIONALHEADER_CLEAR_FLAG(field,flag) (OptionalHeader32 ? (OptionalHeader32->field &=(~flag)) : (OptionalHeader64->field&=(~flag)))
  94. // IA64 unwind specific structures
  95. #define VWNDIA64_FIXUP_TABLE_SIZE 5
  96. #define VWNDIA64_UNWIND_CONTEXT_TABLE_SIZE 5
  97. typedef struct _VWNDIA64_FUXUP_REGION {
  98. ULONGLONG Ip;
  99. ULONGLONG Begin;
  100. ULONGLONG End;
  101. ULONGLONG Fixup;
  102. } VWNDIA64_FUXUP_REGION, *PVWNDIA64_FUXUP_REGION;
  103. typedef struct _VWNDIA64_UNWIND_CONTEXT {
  104. BOOL bFailureReported;
  105. VWNDIA64_FUXUP_REGION FixupTable[VWNDIA64_FIXUP_TABLE_SIZE];
  106. } VWNDIA64_UNWIND_CONTEXT, *PVWNDIA64_UNWIND_CONTEXT;
  107. // stackwalk operation flags
  108. #define WALK_FIX_FPO_EBP 0x1
  109. __inline
  110. void
  111. OptionalHeadersFromNtHeaders(
  112. PIMAGE_NT_HEADERS32 NtHeaders,
  113. PIMAGE_OPTIONAL_HEADER32 *OptionalHeader32,
  114. PIMAGE_OPTIONAL_HEADER64 *OptionalHeader64
  115. )
  116. {
  117. if (NtHeaders->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
  118. if ( OptionalHeader32 ) {
  119. *OptionalHeader32 = (PIMAGE_OPTIONAL_HEADER32)&NtHeaders->OptionalHeader;
  120. }
  121. if ( OptionalHeader64 ) {
  122. *OptionalHeader64 = NULL;
  123. }
  124. } else
  125. if (NtHeaders->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
  126. if ( OptionalHeader64 ) {
  127. *OptionalHeader64 = (PIMAGE_OPTIONAL_HEADER64)&NtHeaders->OptionalHeader;
  128. }
  129. if ( OptionalHeader32 ) {
  130. *OptionalHeader32 = NULL;
  131. }
  132. }
  133. }
  134. #define DebugDirectoryIsUseful(Pointer, Size) ( \
  135. (Pointer != NULL) && \
  136. (Size >= sizeof(IMAGE_DEBUG_DIRECTORY)) && \
  137. ((Size % sizeof(IMAGE_DEBUG_DIRECTORY)) == 0) \
  138. )
  139. ULONG
  140. IMAGEAPI
  141. SymGetFileLineOffsets64(
  142. IN HANDLE hProcess,
  143. IN LPSTR ModuleName,
  144. IN LPSTR FileName,
  145. OUT PDWORD64 Buffer,
  146. IN ULONG BufferLines
  147. );
  148. BOOL
  149. CalculateImagePtrs(
  150. PLOADED_IMAGE LoadedImage
  151. );
  152. typedef void * ( __cdecl * Alloc_t )( unsigned int );
  153. typedef void ( __cdecl * Free_t )( void * );
  154. typedef BOOL (__stdcall *PINTERNAL_GET_MODULE)(HANDLE,LPSTR,DWORD64,DWORD,PVOID);
  155. typedef PCHAR (__cdecl *PUNDNAME)( char *, const char *, int, Alloc_t, Free_t, unsigned short);
  156. #ifdef IMAGEHLP_HEAP_DEBUG
  157. #define HEAP_SIG 0x69696969
  158. typedef struct _HEAP_BLOCK {
  159. LIST_ENTRY ListEntry;
  160. ULONG Signature;
  161. ULONG_PTR Size;
  162. ULONG Line;
  163. CHAR File[16];
  164. } HEAP_BLOCK, *PHEAP_BLOCK;
  165. #define MemAlloc(s) pMemAlloc(s,__LINE__,__FILE__)
  166. #define MemReAlloc(s,n) pMemReAlloc(s,n,__LINE__,__FILE__)
  167. #define MemFree(p) pMemFree(p,__LINE__,__FILE__)
  168. #define CheckHeap(p) pCheckHeap(p,__LINE__,__FILE__)
  169. #define HeapDump(s) pHeapDump(s,__LINE__,__FILE__)
  170. #define MemSize(p) pMemSize(p)
  171. #define HeapInitList(p) InitializeListHead(p);
  172. #else
  173. #define MemAlloc(s) pMemAlloc(s)
  174. #define MemReAlloc(s,n) pMemReAlloc(s,n)
  175. #define MemFree(p) pMemFree(p)
  176. #define CheckHeap(p)
  177. #define HeapDump(s)
  178. #define MemSize(p) pMemSize(p)
  179. #define HeapInitList(p)
  180. #endif
  181. #ifdef IMAGEHLP_HEAP_DEBUG
  182. BOOL
  183. pCheckHeap(
  184. PVOID MemPtr,
  185. ULONG Line,
  186. LPSTR File
  187. );
  188. BOOL
  189. pHeapDump(
  190. LPSTR sz,
  191. ULONG line,
  192. LPSTR file
  193. );
  194. VOID PrintAllocations(VOID);
  195. #endif
  196. PVOID
  197. pMemAlloc(
  198. ULONG_PTR AllocSize
  199. #ifdef IMAGEHLP_HEAP_DEBUG
  200. ,ULONG Line
  201. ,LPSTR File
  202. #endif
  203. );
  204. PVOID
  205. pMemReAlloc(
  206. PVOID OldAlloc,
  207. ULONG_PTR AllocSize
  208. #ifdef IMAGEHLP_HEAP_DEBUG
  209. ,ULONG Line
  210. ,LPSTR File
  211. #endif
  212. );
  213. VOID
  214. pMemFree(
  215. PVOID MemPtr
  216. #ifdef IMAGEHLP_HEAP_DEBUG
  217. ,ULONG Line
  218. ,LPSTR File
  219. #endif
  220. );
  221. ULONG_PTR
  222. pMemSize(
  223. PVOID MemPtr
  224. );
  225. #define MAP_READONLY TRUE
  226. #define MAP_READWRITE FALSE
  227. BOOL
  228. MapIt(
  229. HANDLE FileHandle,
  230. PLOADED_IMAGE LoadedImage,
  231. BOOL ReadOnly
  232. );
  233. VOID
  234. UnMapIt(
  235. PLOADED_IMAGE LoadedImage
  236. );
  237. BOOL
  238. GrowMap(
  239. PLOADED_IMAGE LoadedImage,
  240. LONG lSizeOfDelta
  241. );
  242. DWORD
  243. ImagepSetLastErrorFromStatus(
  244. IN DWORD Status
  245. );
  246. BOOL
  247. UnloadAllImages(
  248. void
  249. );
  250. #define CALLBACK_STACK(f) (f->KdHelp.ThCallbackStack)
  251. #define CALLBACK_BSTORE(f) (f->KdHelp.ThCallbackBStore)
  252. #define CALLBACK_NEXT(f) (f->KdHelp.NextCallback)
  253. #define CALLBACK_FUNC(f) (f->KdHelp.KiCallUserMode)
  254. #define CALLBACK_THREAD(f) (f->KdHelp.Thread)
  255. #define CALLBACK_FP(f) (f->KdHelp.FramePointer)
  256. #define CALLBACK_DISPATCHER(f) (f->KdHelp.KeUserCallbackDispatcher)
  257. #define SYSTEM_RANGE_START(f) (f->KdHelp.SystemRangeStart)
  258. // These modifications of the RF_ macros are required because of the need
  259. // for an explicit ULONG64 result
  260. #define ALPHA_RF_FIXED_RETURN64(RF) (((ULONG64)(RF)->ExceptionHandler) & (~3))
  261. #define ALPHA_RF_ALT_PROLOG64(RF) (((ULONG64)(RF)->ExceptionHandler) & (~3))
  262. extern ULONG g_vc7fpo;
  263. BOOL
  264. WalkX86(
  265. HANDLE hProcess,
  266. HANDLE hThread,
  267. LPSTACKFRAME64 StackFrame,
  268. PVOID ContextRecord,
  269. PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine,
  270. PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine,
  271. PGET_MODULE_BASE_ROUTINE64 GetModuleBase,
  272. PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress,
  273. DWORD flags
  274. );
  275. BOOL
  276. WalkIa64(
  277. HANDLE hProcess,
  278. LPSTACKFRAME64 StackFrame,
  279. PVOID ContextRecord,
  280. PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine,
  281. PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine,
  282. PGET_MODULE_BASE_ROUTINE64 GetModuleBase
  283. );
  284. BOOL
  285. WalkAlpha(
  286. HANDLE hProcess,
  287. LPSTACKFRAME64 StackFrame,
  288. PVOID ContextRecord,
  289. PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine,
  290. PGET_MODULE_BASE_ROUTINE64 GetModuleBase,
  291. PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine,
  292. BOOL Use64
  293. );
  294. BOOL
  295. WalkAmd64(
  296. HANDLE hProcess,
  297. LPSTACKFRAME64 StackFrame,
  298. PVOID ContextRecord,
  299. PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine,
  300. PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine,
  301. PGET_MODULE_BASE_ROUTINE64 GetModuleBase
  302. );
  303. void
  304. ConvertAlphaRf32To64(
  305. PIMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY rf32,
  306. PIMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY rf64
  307. );
  308. void
  309. SymParseArgs(
  310. LPCSTR args
  311. );
  312. VOID
  313. EnsureTrailingBackslash(
  314. LPSTR sz
  315. );
  316. enum {
  317. dsNone = 0,
  318. dsInProc,
  319. dsImage,
  320. dsDbg,
  321. dsPdb,
  322. dsDia,
  323. dsCallerData
  324. };
  325. typedef struct _OMAP {
  326. ULONG rva;
  327. ULONG rvaTo;
  328. } OMAP, *POMAP;
  329. typedef struct _OMAPLIST {
  330. struct _OMAPLIST *next;
  331. OMAP omap;
  332. ULONG cb;
  333. } OMAPLIST, *POMAPLIST;
  334. enum {
  335. mdHeader = 100,
  336. mdSecHdrs,
  337. mdNum
  338. };
  339. #define NUM_MODULE_DATA_ENTRIES 14
  340. typedef BOOL (*PGETINFOPROC)(struct _IMGHLP_DEBUG_DATA *);
  341. typedef struct _MODULE_DATA {
  342. DWORD id;
  343. DWORD hint;
  344. DWORD src;
  345. BOOL required;
  346. PGETINFOPROC fn;
  347. } MODULE_DATA, *PMODULE_DATA;
  348. typedef struct _IMGHLP_DEBUG_DATA {
  349. PCHAR SymbolPath;
  350. ULONG64 InProcImageBase;
  351. ULONG64 ImageBaseFromImage;
  352. DWORD SizeOfImage;
  353. DWORD CheckSum;
  354. DWORD TimeDateStamp;
  355. DWORD Characteristics;
  356. USHORT Machine;
  357. CHAR ImageFilePath[_MAX_PATH];
  358. CHAR OriginalImageFileName[_MAX_PATH]; // Retrieved from the .dbg file for cases when we only have a file handle...
  359. HANDLE ImageFileHandle;
  360. PVOID ImageMap;
  361. USHORT iohMagic;
  362. CHAR DbgFilePath[_MAX_PATH];
  363. CHAR OriginalDbgFileName[_MAX_PATH];
  364. HANDLE DbgFileHandle;
  365. PVOID DbgFileMap;
  366. DWORD PdbAge;
  367. DWORD PdbSignature;
  368. BOOL PdbRSDS;
  369. GUID PdbGUID;
  370. CHAR PdbFileName[_MAX_PATH];
  371. CHAR PdbReferencePath[_MAX_PATH];
  372. ULONG ImageType;
  373. ULONG ImageSrc;
  374. ULONG PdbSrc;
  375. PCHAR pMappedCv;
  376. PCHAR pMappedCoff;
  377. // PCHAR pMappedExportDirectory;
  378. PCHAR pMappedDbgFunction; // PIMAGE_FUNCTION_ENTRY from the .dbg file
  379. PVOID pFpo;
  380. PVOID pPData; // PIMAGE_RUNTIME_FUNCTION_ENTRY from the image.
  381. PVOID pXData;
  382. POMAP pOmapTo;
  383. POMAP pOmapFrom;
  384. PIMAGE_SECTION_HEADER pImageSections;
  385. PIMAGE_SECTION_HEADER pDbgSections;
  386. PIMAGE_SECTION_HEADER pOriginalSections;
  387. PIMAGE_SECTION_HEADER pCurrentSections;
  388. DWORD ddva; // only used by MapDebugInformation - virtual addr of debug dirs
  389. DWORD cdd; // only used by MapDebugInformation - number of debug dirs
  390. // ULONG NumberOfPdataFunctionEntries;
  391. ULONG cFpo;
  392. ULONG cPData;
  393. ULONG cbPData;
  394. ULONG cXData;
  395. ULONG cbXData;
  396. ULONG cOmapTo;
  397. ULONG cOmapFrom;
  398. ULONG cImageSections;
  399. ULONG cDbgSections;
  400. ULONG cOriginalSections;
  401. ULONG cCurrentSections;
  402. ULONG cMappedCv;
  403. ULONG cMappedCoff;
  404. ULONG ImageAlign;
  405. BOOL fPE64;
  406. BOOL fROM;
  407. BOOL fCoffMapped;
  408. BOOL fCvMapped;
  409. BOOL fFpoMapped;
  410. BOOL fPDataMapped;
  411. BOOL fXDataMapped;
  412. BOOL fOmapToMapped;
  413. BOOL fOmapFromMapped;
  414. BOOL fCurrentSectionsMapped;
  415. BOOL fInProcHeader;
  416. HANDLE hProcess;
  417. CHAR ImageName[_MAX_PATH];
  418. DWORD dsExports;
  419. DWORD dsCoff;
  420. DWORD dsCV;
  421. DWORD dsMisc;
  422. DWORD dsFPO;
  423. DWORD dsOmapTo;
  424. DWORD dsOmapFrom;
  425. DWORD dsExceptions;
  426. IMAGE_EXPORT_DIRECTORY expdir;
  427. DWORD fNeedImage;
  428. PVOID dia;
  429. DWORD flags;
  430. PMODULE_DATA md;
  431. DWORD64 oExports;
  432. DWORD cExports;
  433. PMODLOAD_DATA mld;
  434. } IMGHLP_DEBUG_DATA, *PIMGHLP_DEBUG_DATA;
  435. typedef struct {
  436. DWORD rvaBeginAddress;
  437. DWORD rvaEndAddress;
  438. DWORD rvaPrologEndAddress;
  439. DWORD rvaExceptionHandler;
  440. DWORD rvaHandlerData;
  441. } IMGHLP_RVA_FUNCTION_DATA, *PIMGHLP_RVA_FUNCTION_DATA;
  442. #ifndef _WIN64
  443. typedef struct {
  444. PIMGHLP_DEBUG_DATA pIDD;
  445. } PIDI_HEADER, *PPIDI_HEADER;
  446. typedef struct {
  447. PIDI_HEADER hdr;
  448. IMAGE_DEBUG_INFORMATION idi;
  449. } PIDI, *PPIDI;
  450. #endif
  451. PIMGHLP_DEBUG_DATA
  452. GetDebugData(
  453. HANDLE hProcess,
  454. HANDLE FileHandle,
  455. LPSTR FileName,
  456. LPSTR SymbolPath,
  457. ULONG64 ImageBase,
  458. PMODLOAD_DATA mld,
  459. ULONG dwFlags
  460. );
  461. BOOL
  462. CopyPdb(
  463. CHAR const * SrcPdb,
  464. CHAR const * DestPdb,
  465. BOOL StripPrivate
  466. );
  467. BOOL
  468. IMAGEAPI
  469. RemovePrivateCvSymbolic(
  470. PCHAR DebugData,
  471. PCHAR * NewDebugData,
  472. ULONG * NewDebugSize
  473. );
  474. BOOL
  475. IMAGEAPI
  476. RemovePrivateCvSymbolicEx(
  477. PCHAR DebugData,
  478. ULONG DebugSize,
  479. PCHAR * NewDebugData,
  480. ULONG * NewDebugSize
  481. );
  482. #define NO_PE64_IMAGES 0x01000
  483. #define IMGHLP_FREE_ALL 0xffffffff
  484. #define IMGHLP_FREE_FPO 0x00000001
  485. #define IMGHLP_FREE_PDATA 0x00000002
  486. #define IMGHLP_FREE_OMAPT 0x00000004
  487. #define IMGHLP_FREE_OMAPF 0x00000008
  488. #define IMGHLP_FREE_PDB 0x00000010
  489. #define IMGHLP_FREE_SYMPATH 0x00000020
  490. #define IMGHLP_FREE_OSECT 0x00000040
  491. #define IMGHLP_FREE_CSECT 0x00000080
  492. #define IMGHLP_FREE_XDATA 0x00000100
  493. PIMGHLP_DEBUG_DATA
  494. InitDebugData(
  495. VOID
  496. );
  497. void
  498. ReleaseDebugData(
  499. PIMGHLP_DEBUG_DATA,
  500. DWORD
  501. );
  502. ULONG
  503. ReadImageData(
  504. IN HANDLE hprocess,
  505. IN ULONG64 ul,
  506. IN ULONG64 addr,
  507. OUT LPVOID buffer,
  508. IN ULONG size
  509. );
  510. #if DBG
  511. VOID
  512. __cdecl
  513. dbPrint(
  514. LPCSTR fmt,
  515. ...
  516. );
  517. #else
  518. #define dbPrint
  519. #endif
  520. __inline
  521. BOOL
  522. IsPE64(PVOID OptHeader)
  523. {
  524. return ((PIMAGE_OPTIONAL_HEADER) OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC ? TRUE : FALSE;
  525. }
  526. __inline
  527. UCHAR *
  528. OHMajorLinkerVersion(PVOID OptHeader)
  529. {
  530. return &(((PIMAGE_OPTIONAL_HEADER) OptHeader)->MajorLinkerVersion);
  531. }
  532. __inline
  533. UCHAR *
  534. OHMinorLinkerVersion(PVOID OptHeader)
  535. {
  536. return &(((PIMAGE_OPTIONAL_HEADER) OptHeader)->MinorLinkerVersion);
  537. }
  538. __inline
  539. ULONG *
  540. OHSizeOfCode (PVOID OptHeader)
  541. {
  542. return &(((PIMAGE_OPTIONAL_HEADER) OptHeader)->SizeOfCode);
  543. }
  544. __inline
  545. ULONG *
  546. OHSizeOfInitializedData (PVOID OptHeader)
  547. {
  548. return &(((PIMAGE_OPTIONAL_HEADER) OptHeader)->SizeOfInitializedData);
  549. }
  550. __inline
  551. ULONG *
  552. OHSizeOfUninitializedData (PVOID OptHeader)
  553. {
  554. return &(((PIMAGE_OPTIONAL_HEADER) OptHeader)->SizeOfUninitializedData);
  555. }
  556. __inline
  557. ULONG *
  558. OHAddressOfEntryPoint (PVOID OptHeader)
  559. {
  560. return &(((PIMAGE_OPTIONAL_HEADER) OptHeader)->AddressOfEntryPoint);
  561. }
  562. __inline
  563. ULONG *
  564. OHBaseOfCode (PVOID OptHeader)
  565. {
  566. return &(((PIMAGE_OPTIONAL_HEADER) OptHeader)->BaseOfCode);
  567. }
  568. __inline
  569. ULONG *
  570. OHImageBase (PVOID OptHeader)
  571. {
  572. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  573. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->ImageBase) :
  574. (ULONG *)&(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->ImageBase);
  575. }
  576. __inline
  577. ULONG *
  578. OHSectionAlignment (PVOID OptHeader)
  579. {
  580. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  581. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->SectionAlignment) :
  582. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->SectionAlignment);
  583. }
  584. __inline
  585. ULONG *
  586. OHFileAlignment (PVOID OptHeader)
  587. {
  588. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  589. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->FileAlignment) :
  590. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->FileAlignment);
  591. }
  592. __inline
  593. USHORT *
  594. OHMajorOperatingSystemVersion (PVOID OptHeader)
  595. {
  596. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  597. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->MajorOperatingSystemVersion) :
  598. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->MajorOperatingSystemVersion);
  599. }
  600. __inline
  601. USHORT *
  602. OHMinorOperatingSystemVersion (PVOID OptHeader)
  603. {
  604. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  605. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->MinorOperatingSystemVersion) :
  606. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->MinorOperatingSystemVersion);
  607. }
  608. __inline
  609. USHORT *
  610. OHMajorImageVersion (PVOID OptHeader)
  611. {
  612. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  613. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->MajorImageVersion) :
  614. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->MajorImageVersion);
  615. }
  616. __inline
  617. USHORT *
  618. OHMinorImageVersion (PVOID OptHeader)
  619. {
  620. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  621. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->MinorImageVersion) :
  622. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->MinorImageVersion);
  623. }
  624. __inline
  625. USHORT *
  626. OHMajorSubsystemVersion (PVOID OptHeader)
  627. {
  628. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  629. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->MajorSubsystemVersion) :
  630. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->MajorSubsystemVersion);
  631. }
  632. __inline
  633. USHORT *
  634. OHMinorSubsystemVersion (PVOID OptHeader)
  635. {
  636. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  637. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->MinorSubsystemVersion) :
  638. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->MinorSubsystemVersion);
  639. }
  640. __inline
  641. ULONG *
  642. OHWin32VersionValue (PVOID OptHeader)
  643. {
  644. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  645. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->Win32VersionValue) :
  646. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->Win32VersionValue);
  647. }
  648. __inline
  649. ULONG *
  650. OHSizeOfImage (PVOID OptHeader)
  651. {
  652. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  653. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->SizeOfImage) :
  654. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->SizeOfImage);
  655. }
  656. __inline
  657. ULONG *
  658. OHSizeOfHeaders (PVOID OptHeader)
  659. {
  660. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  661. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->SizeOfHeaders) :
  662. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->SizeOfHeaders);
  663. }
  664. __inline
  665. ULONG *
  666. OHCheckSum (PVOID OptHeader)
  667. {
  668. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  669. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->CheckSum) :
  670. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->CheckSum);
  671. }
  672. __inline
  673. USHORT *
  674. OHSubsystem (PVOID OptHeader)
  675. {
  676. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  677. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->Subsystem) :
  678. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->Subsystem);
  679. }
  680. __inline
  681. USHORT *
  682. OHDllCharacteristics (PVOID OptHeader)
  683. {
  684. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  685. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->DllCharacteristics) :
  686. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->DllCharacteristics);
  687. }
  688. __inline
  689. ULONG *
  690. OHSizeOfStackReserve (PVOID OptHeader)
  691. {
  692. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  693. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->SizeOfStackReserve) :
  694. (ULONG *)&(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->SizeOfStackReserve);
  695. }
  696. __inline
  697. ULONG *
  698. OHSizeOfStackCommit (PVOID OptHeader)
  699. {
  700. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  701. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->SizeOfStackCommit) :
  702. (ULONG *)&(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->SizeOfStackCommit);
  703. }
  704. __inline
  705. ULONG *
  706. OHSizeOfHeapReserve (PVOID OptHeader)
  707. {
  708. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  709. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->SizeOfHeapReserve) :
  710. (ULONG *)&(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->SizeOfHeapReserve);
  711. }
  712. __inline
  713. ULONG *
  714. OHSizeOfHeapCommit (PVOID OptHeader)
  715. {
  716. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  717. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->SizeOfHeapCommit) :
  718. (ULONG *)&(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->SizeOfHeapCommit);
  719. }
  720. __inline
  721. ULONG *
  722. OHLoaderFlags (PVOID OptHeader)
  723. {
  724. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  725. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->LoaderFlags) :
  726. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->LoaderFlags);
  727. }
  728. __inline
  729. ULONG *
  730. OHNumberOfRvaAndSizes (PVOID OptHeader)
  731. {
  732. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  733. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->NumberOfRvaAndSizes) :
  734. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->NumberOfRvaAndSizes);
  735. }
  736. __inline
  737. IMAGE_DATA_DIRECTORY *
  738. OHDataDirectory (PVOID OptHeader)
  739. {
  740. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  741. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->DataDirectory[0]) :
  742. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->DataDirectory[0]);
  743. }
  744. PVOID
  745. MapItRO(
  746. HANDLE FileHandle
  747. );
  748. HANDLE
  749. IMAGEAPI
  750. fnFindDebugInfoFileEx(
  751. IN LPSTR FileName,
  752. IN LPSTR SymbolPath,
  753. OUT LPSTR DebugFilePath,
  754. IN PFIND_DEBUG_FILE_CALLBACK Callback,
  755. IN PVOID CallerData,
  756. IN DWORD flag
  757. );
  758. BOOL
  759. GetFileFromSymbolServer(
  760. IN LPCSTR ServerInfo,
  761. IN LPCSTR FileName,
  762. IN GUID *id,
  763. IN DWORD two,
  764. IN DWORD three,
  765. OUT LPSTR FilePath
  766. );
  767. void
  768. CloseSymbolServer(
  769. VOID
  770. );
  771. void
  772. SetSymbolServerOptions(
  773. ULONG_PTR options,
  774. ULONG64 data
  775. );
  776. void
  777. SetSymbolServerCallback(
  778. BOOL state
  779. );
  780. #define fdifRECURSIVE 0x1
  781. #ifdef __cplusplus
  782. }
  783. #endif
  784. #endif