Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

776 lines
20 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 <io.h>
  18. #include <fcntl.h>
  19. #include <sys\types.h>
  20. #include <sys\stat.h>
  21. #include <time.h>
  22. #include <ctype.h>
  23. #include <memory.h>
  24. #include <malloc.h>
  25. #include <dbgeng.h>
  26. #if DBG
  27. // disable the -DNDEBUG set by oak\bin\makefile.def
  28. #undef NDEBUG
  29. #endif // DBG
  30. #include <assert.h>
  31. #include <string.h>
  32. #include <time.h>
  33. #include <ntverp.h>
  34. #include <cvexefmt.h>
  35. #define PDB_LIBRARY
  36. #include <pdb.h>
  37. #include "pdbp.h"
  38. #include "util.h"
  39. #include "srcsrv.h"
  40. #include "dbgimage.h"
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44. // used for delayloading the pdb handler
  45. #define REGKEY_DBGHELP "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\dbgHelp"
  46. #define REGVAL_PDBHANDLER "PDBHandler"
  47. // define the module
  48. #ifdef BUILD_DBGHELP
  49. #define MOD_FILENAME "dbghelp.dll"
  50. #define MOD_NAME "dbghelp"
  51. #else
  52. #define MOD_FILENAME "imagehlp.dll"
  53. #define MOD_NAME "imagehlp"
  54. #endif
  55. #ifndef DIMA
  56. #define DIMAT(Array, EltType) (sizeof(Array) / sizeof(EltType))
  57. #define DIMA(Array) DIMAT(Array, (Array)[0])
  58. #endif
  59. /******************************************************************************
  60. On a Hydra System, we don't want imaghlp.dll to load user32.dll since it
  61. prevents CSRSS from exiting when running a under a debugger.
  62. The following two functions have been copied from user32.dll so that we don't
  63. link to user32.dll.
  64. ******************************************************************************/
  65. #undef CharNext
  66. #undef CharPrev
  67. LPSTR CharNext(
  68. LPCSTR lpCurrentChar);
  69. LPSTR CharPrev(
  70. LPCSTR lpStart,
  71. LPCSTR lpCurrentChar);
  72. // Define some list prototypes
  73. #define InitializeListHead(ListHead) (\
  74. (ListHead)->Flink = (ListHead)->Blink = (ListHead))
  75. #define IsListEmpty(ListHead) \
  76. ((ListHead)->Flink == (ListHead))
  77. #define InsertTailList(ListHead,Entry) {\
  78. PLIST_ENTRY _EX_Blink;\
  79. PLIST_ENTRY _EX_ListHead;\
  80. _EX_ListHead = (ListHead);\
  81. _EX_Blink = _EX_ListHead->Blink;\
  82. (Entry)->Flink = _EX_ListHead;\
  83. (Entry)->Blink = _EX_Blink;\
  84. _EX_Blink->Flink = (Entry);\
  85. _EX_ListHead->Blink = (Entry);\
  86. }
  87. #define RemoveEntryList(Entry) {\
  88. PLIST_ENTRY _EX_Blink;\
  89. PLIST_ENTRY _EX_Flink;\
  90. _EX_Flink = (Entry)->Flink;\
  91. _EX_Blink = (Entry)->Blink;\
  92. _EX_Blink->Flink = _EX_Flink;\
  93. _EX_Flink->Blink = _EX_Blink;\
  94. }
  95. //
  96. // some helpers for PE32/PE64 issues
  97. //
  98. #define OPTIONALHEADER(field) (OptionalHeader32 ? (OptionalHeader32->field) : (OptionalHeader64 ? OptionalHeader64->field : 0))
  99. #define OPTIONALHEADER_LV(field) (*(OptionalHeader32 ? &(OptionalHeader32->field) : &(OptionalHeader64->field)))
  100. #define OPTIONALHEADER_ASSIGN(field,value) (OptionalHeader32 ? (OptionalHeader32->field=(value)) : (OptionalHeader64->field=(value)))
  101. #define OPTIONALHEADER_SET_FLAG(field,flag) (OptionalHeader32 ? (OptionalHeader32->field |=(flag)) : (OptionalHeader64->field|=(flag)))
  102. #define OPTIONALHEADER_CLEAR_FLAG(field,flag) (OptionalHeader32 ? (OptionalHeader32->field &=(~flag)) : (OptionalHeader64->field&=(~flag)))
  103. // IA64 unwind specific structures
  104. #define VWNDIA64_FIXUP_TABLE_SIZE 5
  105. #define VWNDIA64_UNWIND_CONTEXT_TABLE_SIZE 5
  106. typedef struct _VWNDIA64_FUXUP_REGION {
  107. ULONGLONG Ip;
  108. ULONGLONG Begin;
  109. ULONGLONG End;
  110. ULONGLONG Fixup;
  111. } VWNDIA64_FUXUP_REGION, *PVWNDIA64_FUXUP_REGION;
  112. typedef struct _VWNDIA64_UNWIND_CONTEXT {
  113. BOOL bFailureReported;
  114. VWNDIA64_FUXUP_REGION FixupTable[VWNDIA64_FIXUP_TABLE_SIZE];
  115. } VWNDIA64_UNWIND_CONTEXT, *PVWNDIA64_UNWIND_CONTEXT;
  116. // stackwalk operation flags
  117. #define WALK_FIX_FPO_EBP 0x1
  118. __inline
  119. void
  120. OptionalHeadersFromNtHeaders(
  121. PIMAGE_NT_HEADERS32 NtHeaders,
  122. PIMAGE_OPTIONAL_HEADER32 *OptionalHeader32,
  123. PIMAGE_OPTIONAL_HEADER64 *OptionalHeader64
  124. )
  125. {
  126. if (NtHeaders->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
  127. if ( OptionalHeader32 ) {
  128. *OptionalHeader32 = (PIMAGE_OPTIONAL_HEADER32)&NtHeaders->OptionalHeader;
  129. }
  130. if ( OptionalHeader64 ) {
  131. *OptionalHeader64 = NULL;
  132. }
  133. } else
  134. if (NtHeaders->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
  135. if ( OptionalHeader64 ) {
  136. *OptionalHeader64 = (PIMAGE_OPTIONAL_HEADER64)&NtHeaders->OptionalHeader;
  137. }
  138. if ( OptionalHeader32 ) {
  139. *OptionalHeader32 = NULL;
  140. }
  141. }
  142. }
  143. #define DebugDirectoryIsUseful(Pointer, Size) ( \
  144. (Pointer != NULL) && \
  145. (Size >= sizeof(IMAGE_DEBUG_DIRECTORY)) && \
  146. ((Size % sizeof(IMAGE_DEBUG_DIRECTORY)) == 0) \
  147. )
  148. ULONG
  149. IMAGEAPI
  150. SymGetFileLineOffsets64(
  151. IN HANDLE hProcess,
  152. IN LPSTR ModuleName,
  153. IN LPSTR FileName,
  154. OUT PDWORD64 Buffer,
  155. IN ULONG BufferLines
  156. );
  157. BOOL
  158. CalculateImagePtrs(
  159. PLOADED_IMAGE LoadedImage
  160. );
  161. typedef void * ( __cdecl * Alloc_t )( unsigned int );
  162. typedef void ( __cdecl * Free_t )( void * );
  163. typedef BOOL (__stdcall *PGET_MODULE)(HANDLE,LPSTR,DWORD64,DWORD,PVOID);
  164. typedef PCHAR (__cdecl *PUNDNAME)( char *, const char *, int, Alloc_t, Free_t, unsigned short);
  165. #ifdef IMAGEHLP_HEAP_DEBUG
  166. #define HEAP_SIG 0x69696969
  167. typedef struct _HEAP_BLOCK {
  168. LIST_ENTRY ListEntry;
  169. ULONG Signature;
  170. ULONG_PTR Size;
  171. ULONG Line;
  172. CHAR File[16];
  173. } HEAP_BLOCK, *PHEAP_BLOCK;
  174. #define MemAlloc(s) pMemAlloc(s,__LINE__,__FILE__)
  175. #define MemReAlloc(s,n) pMemReAlloc(s,n,__LINE__,__FILE__)
  176. #define MemFree(p) pMemFree(p,__LINE__,__FILE__)
  177. #define CheckHeap(p) pCheckHeap(p,__LINE__,__FILE__)
  178. #define HeapDump(s) pHeapDump(s,__LINE__,__FILE__)
  179. #define MemSize(p) pMemSize(p)
  180. #define HeapInitList(p) InitializeListHead(p);
  181. #else
  182. #define MemAlloc(s) pMemAlloc(s)
  183. #define MemReAlloc(s,n) pMemReAlloc(s,n)
  184. #define MemFree(p) pMemFree(p)
  185. #define CheckHeap(p)
  186. #define HeapDump(s)
  187. #define MemSize(p) pMemSize(p)
  188. #define HeapInitList(p)
  189. #endif
  190. #ifdef IMAGEHLP_HEAP_DEBUG
  191. BOOL
  192. pCheckHeap(
  193. PVOID MemPtr,
  194. ULONG Line,
  195. LPSTR File
  196. );
  197. BOOL
  198. pHeapDump(
  199. LPSTR sz,
  200. ULONG line,
  201. LPSTR file
  202. );
  203. VOID PrintAllocations(VOID);
  204. #endif
  205. PVOID
  206. pMemAlloc(
  207. ULONG_PTR AllocSize
  208. #ifdef IMAGEHLP_HEAP_DEBUG
  209. ,ULONG Line
  210. ,LPSTR File
  211. #endif
  212. );
  213. PVOID
  214. pMemReAlloc(
  215. PVOID OldAlloc,
  216. ULONG_PTR AllocSize
  217. #ifdef IMAGEHLP_HEAP_DEBUG
  218. ,ULONG Line
  219. ,LPSTR File
  220. #endif
  221. );
  222. VOID
  223. pMemFree(
  224. PVOID MemPtr
  225. #ifdef IMAGEHLP_HEAP_DEBUG
  226. ,ULONG Line
  227. ,LPSTR File
  228. #endif
  229. );
  230. ULONG_PTR
  231. pMemSize(
  232. PVOID MemPtr
  233. );
  234. #define MAP_READONLY TRUE
  235. #define MAP_READWRITE FALSE
  236. BOOL
  237. MapIt(
  238. HANDLE FileHandle,
  239. PLOADED_IMAGE LoadedImage,
  240. BOOL ReadOnly
  241. );
  242. VOID
  243. UnMapIt(
  244. PLOADED_IMAGE LoadedImage
  245. );
  246. BOOL
  247. GrowMap(
  248. PLOADED_IMAGE LoadedImage,
  249. LONG lSizeOfDelta
  250. );
  251. DWORD
  252. ImagepSetLastErrorFromStatus(
  253. IN DWORD Status
  254. );
  255. BOOL
  256. UnloadAllImages(
  257. void
  258. );
  259. #define CALLBACK_STACK(f) (f->KdHelp.ThCallbackStack)
  260. #define CALLBACK_BSTORE(f) (f->KdHelp.ThCallbackBStore)
  261. #define CALLBACK_NEXT(f) (f->KdHelp.NextCallback)
  262. #define CALLBACK_FUNC(f) (f->KdHelp.KiCallUserMode)
  263. #define CALLBACK_THREAD(f) (f->KdHelp.Thread)
  264. #define CALLBACK_FP(f) (f->KdHelp.FramePointer)
  265. #define CALLBACK_DISPATCHER(f) (f->KdHelp.KeUserCallbackDispatcher)
  266. #define SYSTEM_RANGE_START(f) (f->KdHelp.SystemRangeStart)
  267. // These modifications of the RF_ macros are required because of the need
  268. // for an explicit ULONG64 result
  269. #define ALPHA_RF_FIXED_RETURN64(RF) (((ULONG64)(RF)->ExceptionHandler) & (~3))
  270. #define ALPHA_RF_ALT_PROLOG64(RF) (((ULONG64)(RF)->ExceptionHandler) & (~3))
  271. extern ULONG g_vc7fpo;
  272. enum
  273. {
  274. SDB_DEBUG_OUT,
  275. SDB_CALLBACK_OUT,
  276. };
  277. #define SDB_NO_PREFIX 0x80000000
  278. extern ULONG g_StackDebugMask;
  279. extern ULONG g_StackDebugIo;
  280. void __cdecl
  281. SdbOut(
  282. ULONG Mask,
  283. PSTR Format,
  284. ...
  285. );
  286. BOOL
  287. WalkX86(
  288. HANDLE hProcess,
  289. HANDLE hThread,
  290. LPSTACKFRAME64 StackFrame,
  291. PVOID ContextRecord,
  292. PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine,
  293. PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine,
  294. PGET_MODULE_BASE_ROUTINE64 GetModuleBase,
  295. PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress,
  296. DWORD flags
  297. );
  298. BOOL
  299. WalkIa64(
  300. HANDLE hProcess,
  301. LPSTACKFRAME64 StackFrame,
  302. PVOID ContextRecord,
  303. PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine,
  304. PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine,
  305. PGET_MODULE_BASE_ROUTINE64 GetModuleBase
  306. );
  307. BOOL
  308. WalkAlpha(
  309. HANDLE hProcess,
  310. LPSTACKFRAME64 StackFrame,
  311. PVOID ContextRecord,
  312. PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine,
  313. PGET_MODULE_BASE_ROUTINE64 GetModuleBase,
  314. PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine,
  315. BOOL Use64
  316. );
  317. BOOL
  318. WalkAmd64(
  319. HANDLE hProcess,
  320. LPSTACKFRAME64 StackFrame,
  321. PVOID ContextRecord,
  322. PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine,
  323. PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine,
  324. PGET_MODULE_BASE_ROUTINE64 GetModuleBase
  325. );
  326. BOOL
  327. WalkArm(
  328. HANDLE hProcess,
  329. HANDLE hThread,
  330. LPSTACKFRAME64 StackFrame,
  331. PVOID ContextRecord,
  332. PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine,
  333. PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine,
  334. PGET_MODULE_BASE_ROUTINE64 GetModuleBase
  335. );
  336. void
  337. ConvertAlphaRf32To64(
  338. PIMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY rf32,
  339. PIMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY rf64
  340. );
  341. void
  342. SymParseArgs(
  343. LPCSTR args
  344. );
  345. VOID
  346. EnsureTrailingBackslash(
  347. LPSTR sz
  348. );
  349. enum {
  350. dsNone = 0,
  351. dsInProc,
  352. dsImage,
  353. dsDbg,
  354. dsPdb,
  355. dsDia,
  356. dsCallerData,
  357. dsVirtual
  358. };
  359. typedef struct _OMAP {
  360. ULONG rva;
  361. ULONG rvaTo;
  362. } OMAP, *POMAP;
  363. typedef struct _OMAPLIST {
  364. struct _OMAPLIST *next;
  365. OMAP omap;
  366. ULONG cb;
  367. } OMAPLIST, *POMAPLIST;
  368. enum {
  369. mdHeader = 100,
  370. mdSecHdrs,
  371. mdNum
  372. };
  373. #define NUM_MODULE_DATA_ENTRIES 14
  374. typedef BOOL (*PGETINFOPROC)(struct _IMGHLP_DEBUG_DATA *);
  375. typedef struct _MODULE_DATA {
  376. DWORD id;
  377. DWORD hint;
  378. DWORD src;
  379. BOOL required;
  380. PGETINFOPROC fn;
  381. } MODULE_DATA, *PMODULE_DATA;
  382. BOOL
  383. CopyPdb(
  384. CHAR const * SrcPdb,
  385. CHAR const * DestPdb,
  386. BOOL StripPrivate
  387. );
  388. BOOL
  389. IMAGEAPI
  390. RemovePrivateCvSymbolic(
  391. PCHAR DebugData,
  392. PCHAR * NewDebugData,
  393. ULONG * NewDebugSize
  394. );
  395. BOOL
  396. IMAGEAPI
  397. RemovePrivateCvSymbolicEx(
  398. PCHAR DebugData,
  399. ULONG DebugSize,
  400. PCHAR * NewDebugData,
  401. ULONG * NewDebugSize
  402. );
  403. #define NO_PE64_IMAGES 0x01000
  404. #define IMGHLP_FREE_ALL 0xffffffff
  405. #define IMGHLP_FREE_FPO 0x00000001
  406. #define IMGHLP_FREE_PDATA 0x00000002
  407. #define IMGHLP_FREE_OMAPT 0x00000004
  408. #define IMGHLP_FREE_OMAPF 0x00000008
  409. #define IMGHLP_FREE_PDB 0x00000010
  410. #define IMGHLP_FREE_SYMPATH 0x00000020
  411. #define IMGHLP_FREE_OSECT 0x00000040
  412. #define IMGHLP_FREE_CSECT 0x00000080
  413. #define IMGHLP_FREE_XDATA 0x00000100
  414. #define IMGHLP_FREE_STANDARD (IMGHLP_FREE_FPO | IMGHLP_FREE_SYMPATH | IMGHLP_FREE_PDATA | IMGHLP_FREE_XDATA) // | IMGHLP_FREE_OMAPT | IMGHLP_FREE_OMAPF)
  415. #if DBG
  416. VOID
  417. __cdecl
  418. dbPrint(
  419. LPCSTR fmt,
  420. ...
  421. );
  422. #else
  423. #define dbPrint
  424. #endif
  425. __inline
  426. BOOL
  427. IsPE64(PVOID OptHeader)
  428. {
  429. return ((PIMAGE_OPTIONAL_HEADER) OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC ? TRUE : FALSE;
  430. }
  431. __inline
  432. UCHAR *
  433. OHMajorLinkerVersion(PVOID OptHeader)
  434. {
  435. return &(((PIMAGE_OPTIONAL_HEADER) OptHeader)->MajorLinkerVersion);
  436. }
  437. __inline
  438. UCHAR *
  439. OHMinorLinkerVersion(PVOID OptHeader)
  440. {
  441. return &(((PIMAGE_OPTIONAL_HEADER) OptHeader)->MinorLinkerVersion);
  442. }
  443. __inline
  444. ULONG *
  445. OHSizeOfCode (PVOID OptHeader)
  446. {
  447. return &(((PIMAGE_OPTIONAL_HEADER) OptHeader)->SizeOfCode);
  448. }
  449. __inline
  450. ULONG *
  451. OHSizeOfInitializedData (PVOID OptHeader)
  452. {
  453. return &(((PIMAGE_OPTIONAL_HEADER) OptHeader)->SizeOfInitializedData);
  454. }
  455. __inline
  456. ULONG *
  457. OHSizeOfUninitializedData (PVOID OptHeader)
  458. {
  459. return &(((PIMAGE_OPTIONAL_HEADER) OptHeader)->SizeOfUninitializedData);
  460. }
  461. __inline
  462. ULONG *
  463. OHAddressOfEntryPoint (PVOID OptHeader)
  464. {
  465. return &(((PIMAGE_OPTIONAL_HEADER) OptHeader)->AddressOfEntryPoint);
  466. }
  467. __inline
  468. ULONG *
  469. OHBaseOfCode (PVOID OptHeader)
  470. {
  471. return &(((PIMAGE_OPTIONAL_HEADER) OptHeader)->BaseOfCode);
  472. }
  473. __inline
  474. ULONG *
  475. OHImageBase (PVOID OptHeader)
  476. {
  477. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  478. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->ImageBase) :
  479. (ULONG *)&(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->ImageBase);
  480. }
  481. __inline
  482. ULONG *
  483. OHSectionAlignment (PVOID OptHeader)
  484. {
  485. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  486. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->SectionAlignment) :
  487. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->SectionAlignment);
  488. }
  489. __inline
  490. ULONG *
  491. OHFileAlignment (PVOID OptHeader)
  492. {
  493. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  494. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->FileAlignment) :
  495. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->FileAlignment);
  496. }
  497. __inline
  498. USHORT *
  499. OHMajorOperatingSystemVersion (PVOID OptHeader)
  500. {
  501. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  502. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->MajorOperatingSystemVersion) :
  503. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->MajorOperatingSystemVersion);
  504. }
  505. __inline
  506. USHORT *
  507. OHMinorOperatingSystemVersion (PVOID OptHeader)
  508. {
  509. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  510. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->MinorOperatingSystemVersion) :
  511. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->MinorOperatingSystemVersion);
  512. }
  513. __inline
  514. USHORT *
  515. OHMajorImageVersion (PVOID OptHeader)
  516. {
  517. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  518. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->MajorImageVersion) :
  519. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->MajorImageVersion);
  520. }
  521. __inline
  522. USHORT *
  523. OHMinorImageVersion (PVOID OptHeader)
  524. {
  525. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  526. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->MinorImageVersion) :
  527. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->MinorImageVersion);
  528. }
  529. __inline
  530. USHORT *
  531. OHMajorSubsystemVersion (PVOID OptHeader)
  532. {
  533. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  534. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->MajorSubsystemVersion) :
  535. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->MajorSubsystemVersion);
  536. }
  537. __inline
  538. USHORT *
  539. OHMinorSubsystemVersion (PVOID OptHeader)
  540. {
  541. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  542. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->MinorSubsystemVersion) :
  543. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->MinorSubsystemVersion);
  544. }
  545. __inline
  546. ULONG *
  547. OHWin32VersionValue (PVOID OptHeader)
  548. {
  549. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  550. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->Win32VersionValue) :
  551. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->Win32VersionValue);
  552. }
  553. __inline
  554. ULONG *
  555. OHSizeOfImage (PVOID OptHeader)
  556. {
  557. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  558. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->SizeOfImage) :
  559. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->SizeOfImage);
  560. }
  561. __inline
  562. ULONG *
  563. OHSizeOfHeaders (PVOID OptHeader)
  564. {
  565. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  566. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->SizeOfHeaders) :
  567. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->SizeOfHeaders);
  568. }
  569. __inline
  570. ULONG *
  571. OHCheckSum (PVOID OptHeader)
  572. {
  573. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  574. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->CheckSum) :
  575. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->CheckSum);
  576. }
  577. __inline
  578. USHORT *
  579. OHSubsystem (PVOID OptHeader)
  580. {
  581. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  582. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->Subsystem) :
  583. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->Subsystem);
  584. }
  585. __inline
  586. USHORT *
  587. OHDllCharacteristics (PVOID OptHeader)
  588. {
  589. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  590. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->DllCharacteristics) :
  591. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->DllCharacteristics);
  592. }
  593. __inline
  594. ULONG *
  595. OHSizeOfStackReserve (PVOID OptHeader)
  596. {
  597. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  598. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->SizeOfStackReserve) :
  599. (ULONG *)&(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->SizeOfStackReserve);
  600. }
  601. __inline
  602. ULONG *
  603. OHSizeOfStackCommit (PVOID OptHeader)
  604. {
  605. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  606. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->SizeOfStackCommit) :
  607. (ULONG *)&(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->SizeOfStackCommit);
  608. }
  609. __inline
  610. ULONG *
  611. OHSizeOfHeapReserve (PVOID OptHeader)
  612. {
  613. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  614. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->SizeOfHeapReserve) :
  615. (ULONG *)&(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->SizeOfHeapReserve);
  616. }
  617. __inline
  618. ULONG *
  619. OHSizeOfHeapCommit (PVOID OptHeader)
  620. {
  621. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  622. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->SizeOfHeapCommit) :
  623. (ULONG *)&(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->SizeOfHeapCommit);
  624. }
  625. __inline
  626. ULONG *
  627. OHLoaderFlags (PVOID OptHeader)
  628. {
  629. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  630. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->LoaderFlags) :
  631. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->LoaderFlags);
  632. }
  633. __inline
  634. ULONG *
  635. OHNumberOfRvaAndSizes (PVOID OptHeader)
  636. {
  637. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  638. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->NumberOfRvaAndSizes) :
  639. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->NumberOfRvaAndSizes);
  640. }
  641. __inline
  642. IMAGE_DATA_DIRECTORY *
  643. OHDataDirectory (PVOID OptHeader)
  644. {
  645. return ((PIMAGE_OPTIONAL_HEADER)OptHeader)->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ?
  646. &(((PIMAGE_OPTIONAL_HEADER32) OptHeader)->DataDirectory[0]) :
  647. &(((PIMAGE_OPTIONAL_HEADER64) OptHeader)->DataDirectory[0]);
  648. }
  649. BOOL IsRegularExpression(const char *sz);
  650. #ifdef __cplusplus
  651. }
  652. #endif
  653. #endif