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.

966 lines
35 KiB

  1. /*++ BUILD Version: 0004 // Increment this if a change has global effects
  2. Copyright (c) 1989-1993 Microsoft Corporation
  3. Module Name:
  4. ntimage.h
  5. Abstract:
  6. This is the include file that describes all image structures.
  7. Author:
  8. Mike O'Leary (mikeol) 21-Mar-1991
  9. Revision History:
  10. --*/
  11. #ifndef _NTIMAGE_
  12. #define _NTIMAGE_
  13. //
  14. // Define the linker version number. This is temporary to aid
  15. // in debugging with people trying to load images built with
  16. // an older linker. This is not required in the final product.
  17. //
  18. #define IMAGE_MAJOR_LINKER_VERSION 2
  19. // begin_winnt
  20. //
  21. // Image Format
  22. //
  23. #ifndef RC_INVOKED
  24. #pragma pack (1)
  25. #endif // !RC_INVOKED
  26. #define IMAGE_DOS_SIGNATURE 0x5A4D // MZ
  27. #define IMAGE_OS2_SIGNATURE 0x454E // NE
  28. #define IMAGE_OS2_SIGNATURE_LE 0x454C // LE
  29. #define IMAGE_NT_SIGNATURE 0x00004550 // PE00
  30. typedef struct _IMAGE_DOS_HEADER { // DOS .EXE header
  31. USHORT e_magic; // Magic number
  32. USHORT e_cblp; // Bytes on last page of file
  33. USHORT e_cp; // Pages in file
  34. USHORT e_crlc; // Relocations
  35. USHORT e_cparhdr; // Size of header in paragraphs
  36. USHORT e_minalloc; // Minimum extra paragraphs needed
  37. USHORT e_maxalloc; // Maximum extra paragraphs needed
  38. USHORT e_ss; // Initial (relative) SS value
  39. USHORT e_sp; // Initial SP value
  40. USHORT e_csum; // Checksum
  41. USHORT e_ip; // Initial IP value
  42. USHORT e_cs; // Initial (relative) CS value
  43. USHORT e_lfarlc; // File address of relocation table
  44. USHORT e_ovno; // Overlay number
  45. USHORT e_res[4]; // Reserved words
  46. USHORT e_oemid; // OEM identifier (for e_oeminfo)
  47. USHORT e_oeminfo; // OEM information; e_oemid specific
  48. USHORT e_res2[10]; // Reserved words
  49. LONG e_lfanew; // File address of new exe header
  50. } IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;
  51. typedef struct _IMAGE_OS2_HEADER { // OS/2 .EXE header
  52. USHORT ne_magic; // Magic number
  53. CHAR ne_ver; // Version number
  54. CHAR ne_rev; // Revision number
  55. USHORT ne_enttab; // Offset of Entry Table
  56. USHORT ne_cbenttab; // Number of bytes in Entry Table
  57. LONG ne_crc; // Checksum of whole file
  58. USHORT ne_flags; // Flag word
  59. USHORT ne_autodata; // Automatic data segment number
  60. USHORT ne_heap; // Initial heap allocation
  61. USHORT ne_stack; // Initial stack allocation
  62. LONG ne_csip; // Initial CS:IP setting
  63. LONG ne_sssp; // Initial SS:SP setting
  64. USHORT ne_cseg; // Count of file segments
  65. USHORT ne_cmod; // Entries in Module Reference Table
  66. USHORT ne_cbnrestab; // Size of non-resident name table
  67. USHORT ne_segtab; // Offset of Segment Table
  68. USHORT ne_rsrctab; // Offset of Resource Table
  69. USHORT ne_restab; // Offset of resident name table
  70. USHORT ne_modtab; // Offset of Module Reference Table
  71. USHORT ne_imptab; // Offset of Imported Names Table
  72. LONG ne_nrestab; // Offset of Non-resident Names Table
  73. USHORT ne_cmovent; // Count of movable entries
  74. USHORT ne_align; // Segment alignment shift count
  75. USHORT ne_cres; // Count of resource segments
  76. UCHAR ne_exetyp; // Target Operating system
  77. UCHAR ne_flagsothers; // Other .EXE flags
  78. USHORT ne_pretthunks; // offset to return thunks
  79. USHORT ne_psegrefbytes; // offset to segment ref. bytes
  80. USHORT ne_swaparea; // Minimum code swap area size
  81. USHORT ne_expver; // Expected Windows version number
  82. } IMAGE_OS2_HEADER, *PIMAGE_OS2_HEADER;
  83. //
  84. // File header format.
  85. //
  86. typedef struct _IMAGE_FILE_HEADER {
  87. USHORT Machine;
  88. USHORT NumberOfSections;
  89. ULONG TimeDateStamp;
  90. ULONG PointerToSymbolTable;
  91. ULONG NumberOfSymbols;
  92. USHORT SizeOfOptionalHeader;
  93. USHORT Characteristics;
  94. } IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER;
  95. #define IMAGE_SIZEOF_FILE_HEADER 20
  96. #define IMAGE_FILE_RELOCS_STRIPPED 0x0001 // Relocation info stripped from file.
  97. #define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002 // File is executable (i.e. no unresolved externel references).
  98. #define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004 // Line nunbers stripped from file.
  99. #define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008 // Local symbols stripped from file.
  100. #define IMAGE_FILE_MINIMAL_OBJECT 0x0010 // Reserved.
  101. #define IMAGE_FILE_UPDATE_OBJECT 0x0020 // Reserved.
  102. #define IMAGE_FILE_16BIT_MACHINE 0x0040 // 16 bit word machine.
  103. #define IMAGE_FILE_BYTES_REVERSED_LO 0x0080 // Bytes of machine word are reversed.
  104. #define IMAGE_FILE_32BIT_MACHINE 0x0100 // 32 bit word machine.
  105. #define IMAGE_FILE_DEBUG_STRIPPED 0x0200 // Debugging info stripped from file in .DBG file
  106. #define IMAGE_FILE_PATCH 0x0400 // Reserved.
  107. #define IMAGE_FILE_SYSTEM 0x1000 // System File.
  108. #define IMAGE_FILE_DLL 0x2000 // File is a DLL.
  109. #define IMAGE_FILE_BYTES_REVERSED_HI 0x8000 // Bytes of machine word are reversed.
  110. #define IMAGE_FILE_MACHINE_UNKNOWN 0
  111. #define IMAGE_FILE_MACHINE_I386 0x14c // Intel 386.
  112. #define IMAGE_FILE_MACHINE_R3000 0x162 // MIPS little-endian, 0540 big-endian
  113. #define IMAGE_FILE_MACHINE_R4000 0x166 // MIPS little-endian
  114. #define IMAGE_FILE_MACHINE_ALPHA 0x184 // Alpha_AXP
  115. //
  116. // Directory format.
  117. //
  118. typedef struct _IMAGE_DATA_DIRECTORY {
  119. ULONG VirtualAddress;
  120. ULONG Size;
  121. } IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY;
  122. #define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
  123. //
  124. // Optional header format.
  125. //
  126. typedef struct _IMAGE_OPTIONAL_HEADER {
  127. //
  128. // Standard fields.
  129. //
  130. USHORT Magic;
  131. UCHAR MajorLinkerVersion;
  132. UCHAR MinorLinkerVersion;
  133. ULONG SizeOfCode;
  134. ULONG SizeOfInitializedData;
  135. ULONG SizeOfUninitializedData;
  136. ULONG AddressOfEntryPoint;
  137. ULONG BaseOfCode;
  138. ULONG BaseOfData;
  139. //
  140. // NT additional fields.
  141. //
  142. ULONG ImageBase;
  143. ULONG SectionAlignment;
  144. ULONG FileAlignment;
  145. USHORT MajorOperatingSystemVersion;
  146. USHORT MinorOperatingSystemVersion;
  147. USHORT MajorImageVersion;
  148. USHORT MinorImageVersion;
  149. USHORT MajorSubsystemVersion;
  150. USHORT MinorSubsystemVersion;
  151. ULONG Reserved1;
  152. ULONG SizeOfImage;
  153. ULONG SizeOfHeaders;
  154. ULONG CheckSum;
  155. USHORT Subsystem;
  156. USHORT DllCharacteristics;
  157. ULONG SizeOfStackReserve;
  158. ULONG SizeOfStackCommit;
  159. ULONG SizeOfHeapReserve;
  160. ULONG SizeOfHeapCommit;
  161. ULONG LoaderFlags;
  162. ULONG NumberOfRvaAndSizes;
  163. IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
  164. } IMAGE_OPTIONAL_HEADER, *PIMAGE_OPTIONAL_HEADER;
  165. typedef struct _IMAGE_ROM_OPTIONAL_HEADER {
  166. USHORT Magic;
  167. UCHAR MajorLinkerVersion;
  168. UCHAR MinorLinkerVersion;
  169. ULONG SizeOfCode;
  170. ULONG SizeOfInitializedData;
  171. ULONG SizeOfUninitializedData;
  172. ULONG AddressOfEntryPoint;
  173. ULONG BaseOfCode;
  174. ULONG BaseOfData;
  175. ULONG BaseOfBss;
  176. ULONG GprMask;
  177. ULONG CprMask[4];
  178. ULONG GpValue;
  179. } IMAGE_ROM_OPTIONAL_HEADER, *PIMAGE_ROM_OPTIONAL_HEADER;
  180. #define IMAGE_SIZEOF_ROM_OPTIONAL_HEADER 56
  181. #define IMAGE_SIZEOF_STD_OPTIONAL_HEADER 28
  182. #define IMAGE_SIZEOF_NT_OPTIONAL_HEADER 224
  183. #define IMAGE_NT_OPTIONAL_HDR_MAGIC 0x10b
  184. #define IMAGE_ROM_OPTIONAL_HDR_MAGIC 0x107
  185. typedef struct _IMAGE_NT_HEADERS {
  186. ULONG Signature;
  187. IMAGE_FILE_HEADER FileHeader;
  188. IMAGE_OPTIONAL_HEADER OptionalHeader;
  189. } IMAGE_NT_HEADERS, *PIMAGE_NT_HEADERS;
  190. typedef struct _IMAGE_ROM_HEADERS {
  191. IMAGE_FILE_HEADER FileHeader;
  192. IMAGE_ROM_OPTIONAL_HEADER OptionalHeader;
  193. } IMAGE_ROM_HEADERS, *PIMAGE_ROM_HEADERS;
  194. #define IMAGE_FIRST_SECTION( ntheader ) ((PIMAGE_SECTION_HEADER) \
  195. ((ULONG)ntheader + \
  196. FIELD_OFFSET( IMAGE_NT_HEADERS, OptionalHeader ) + \
  197. ((PIMAGE_NT_HEADERS)(ntheader))->FileHeader.SizeOfOptionalHeader \
  198. ))
  199. // Subsystem Values
  200. #define IMAGE_SUBSYSTEM_UNKNOWN 0 // Unknown subsystem.
  201. #define IMAGE_SUBSYSTEM_NATIVE 1 // Image doesn't require a subsystem.
  202. #define IMAGE_SUBSYSTEM_WINDOWS_GUI 2 // Image runs in the Windows GUI subsystem.
  203. #define IMAGE_SUBSYSTEM_WINDOWS_CUI 3 // Image runs in the Windows character subsystem.
  204. #define IMAGE_SUBSYSTEM_OS2_CUI 5 // image runs in the OS/2 character subsystem.
  205. #define IMAGE_SUBSYSTEM_POSIX_CUI 7 // image run in the Posix character subsystem.
  206. // Dll Characteristics
  207. #define IMAGE_LIBRARY_PROCESS_INIT 1 // Dll has a process initialization routine.
  208. #define IMAGE_LIBRARY_PROCESS_TERM 2 // Dll has a thread termination routine.
  209. #define IMAGE_LIBRARY_THREAD_INIT 4 // Dll has a thread initialization routine.
  210. #define IMAGE_LIBRARY_THREAD_TERM 8 // Dll has a thread termination routine.
  211. //
  212. // Loader Flags
  213. //
  214. #define IMAGE_LOADER_FLAGS_BREAK_ON_LOAD 0x00000001
  215. #define IMAGE_LOADER_FLAGS_DEBUG_ON_LOAD 0x00000002
  216. // Directory Entries
  217. #define IMAGE_DIRECTORY_ENTRY_EXPORT 0 // Export Directory
  218. #define IMAGE_DIRECTORY_ENTRY_IMPORT 1 // Import Directory
  219. #define IMAGE_DIRECTORY_ENTRY_RESOURCE 2 // Resource Directory
  220. #define IMAGE_DIRECTORY_ENTRY_EXCEPTION 3 // Exception Directory
  221. #define IMAGE_DIRECTORY_ENTRY_SECURITY 4 // Security Directory
  222. #define IMAGE_DIRECTORY_ENTRY_BASERELOC 5 // Base Relocation Table
  223. #define IMAGE_DIRECTORY_ENTRY_DEBUG 6 // Debug Directory
  224. #define IMAGE_DIRECTORY_ENTRY_COPYRIGHT 7 // Description String
  225. #define IMAGE_DIRECTORY_ENTRY_GLOBALPTR 8 // Machine Value (MIPS GP)
  226. #define IMAGE_DIRECTORY_ENTRY_TLS 9 // TLS Directory
  227. #define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10 // Load Configuration Directory
  228. //
  229. // Section header format.
  230. //
  231. #define IMAGE_SIZEOF_SHORT_NAME 8
  232. typedef struct _IMAGE_SECTION_HEADER {
  233. UCHAR Name[IMAGE_SIZEOF_SHORT_NAME];
  234. union {
  235. ULONG PhysicalAddress;
  236. ULONG VirtualSize;
  237. } Misc;
  238. ULONG VirtualAddress;
  239. ULONG SizeOfRawData;
  240. ULONG PointerToRawData;
  241. ULONG PointerToRelocations;
  242. ULONG PointerToLinenumbers;
  243. USHORT NumberOfRelocations;
  244. USHORT NumberOfLinenumbers;
  245. ULONG Characteristics;
  246. } IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER;
  247. #define IMAGE_SIZEOF_SECTION_HEADER 40
  248. #define IMAGE_SCN_TYPE_REGULAR 0x00000000 //
  249. #define IMAGE_SCN_TYPE_DUMMY 0x00000001 // Reserved.
  250. #define IMAGE_SCN_TYPE_NO_LOAD 0x00000002 // Reserved.
  251. #define IMAGE_SCN_TYPE_GROUPED 0x00000004 // Used for 16-bit offset code.
  252. #define IMAGE_SCN_TYPE_NO_PAD 0x00000008 // Reserved.
  253. #define IMAGE_SCN_TYPE_COPY 0x00000010 // Reserved.
  254. #define IMAGE_SCN_CNT_CODE 0x00000020 // Section contains code.
  255. #define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 // Section contains initialized data.
  256. #define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 // Section contains uninitialized data.
  257. #define IMAGE_SCN_LNK_OTHER 0x00000100 // Reserved.
  258. #define IMAGE_SCN_LNK_INFO 0x00000200 // Section contains comments or some other type of information.
  259. #define IMAGE_SCN_LNK_OVERLAY 0x00000400 // Section contains an overlay.
  260. #define IMAGE_SCN_LNK_REMOVE 0x00000800 // Section contents will not become part of image.
  261. #define IMAGE_SCN_LNK_COMDAT 0x00001000 // Section contents comdat.
  262. #define IMAGE_SCN_ALIGN_1BYTES 0x00100000 //
  263. #define IMAGE_SCN_ALIGN_2BYTES 0x00200000 //
  264. #define IMAGE_SCN_ALIGN_4BYTES 0x00300000 //
  265. #define IMAGE_SCN_ALIGN_8BYTES 0x00400000 //
  266. #define IMAGE_SCN_ALIGN_16BYTES 0x00500000 // Default alignment if no others are specified.
  267. #define IMAGE_SCN_ALIGN_32BYTES 0x00600000 //
  268. #define IMAGE_SCN_ALIGN_64BYTES 0x00700000 //
  269. #define IMAGE_SCN_MEM_DISCARDABLE 0x02000000 // Section can be discarded.
  270. #define IMAGE_SCN_MEM_NOT_CACHED 0x04000000 // Section is not cachable.
  271. #define IMAGE_SCN_MEM_NOT_PAGED 0x08000000 // Section is not pageable.
  272. #define IMAGE_SCN_MEM_SHARED 0x10000000 // Section is shareable.
  273. #define IMAGE_SCN_MEM_EXECUTE 0x20000000 // Section is executable.
  274. #define IMAGE_SCN_MEM_READ 0x40000000 // Section is readable.
  275. #define IMAGE_SCN_MEM_WRITE 0x80000000 // Section is writeable.
  276. //
  277. // Symbol format.
  278. //
  279. typedef struct _IMAGE_SYMBOL {
  280. union {
  281. UCHAR ShortName[8];
  282. struct {
  283. ULONG Short; // if 0, use LongName
  284. ULONG Long; // offset into string table
  285. } Name;
  286. PUCHAR LongName[2];
  287. } N;
  288. ULONG Value;
  289. SHORT SectionNumber;
  290. USHORT Type;
  291. UCHAR StorageClass;
  292. UCHAR NumberOfAuxSymbols;
  293. } IMAGE_SYMBOL;
  294. typedef IMAGE_SYMBOL UNALIGNED *PIMAGE_SYMBOL;
  295. #define IMAGE_SIZEOF_SYMBOL 18
  296. //
  297. // Section values.
  298. //
  299. // Symbols have a section number of the section in which they are
  300. // defined. Otherwise, section numbers have the following meanings:
  301. //
  302. #define IMAGE_SYM_UNDEFINED (SHORT)0 // Symbol is undefined or is common.
  303. #define IMAGE_SYM_ABSOLUTE (SHORT)-1 // Symbol is an absolute value.
  304. #define IMAGE_SYM_DEBUG (SHORT)-2 // Symbol is a special debug item.
  305. //
  306. // Type (fundamental) values.
  307. //
  308. #define IMAGE_SYM_TYPE_NULL 0 // no type.
  309. #define IMAGE_SYM_TYPE_VOID 1 //
  310. #define IMAGE_SYM_TYPE_CHAR 2 // type character.
  311. #define IMAGE_SYM_TYPE_SHORT 3 // type short integer.
  312. #define IMAGE_SYM_TYPE_INT 4 //
  313. #define IMAGE_SYM_TYPE_LONG 5 //
  314. #define IMAGE_SYM_TYPE_FLOAT 6 //
  315. #define IMAGE_SYM_TYPE_DOUBLE 7 //
  316. #define IMAGE_SYM_TYPE_STRUCT 8 //
  317. #define IMAGE_SYM_TYPE_UNION 9 //
  318. #define IMAGE_SYM_TYPE_ENUM 10 // enumeration.
  319. #define IMAGE_SYM_TYPE_MOE 11 // member of enumeration.
  320. #define IMAGE_SYM_TYPE_UCHAR 12 //
  321. #define IMAGE_SYM_TYPE_USHORT 13 //
  322. #define IMAGE_SYM_TYPE_UINT 14 //
  323. #define IMAGE_SYM_TYPE_ULONG 15 //
  324. //
  325. // Type (derived) values.
  326. //
  327. #define IMAGE_SYM_DTYPE_NULL 0 // no derived type.
  328. #define IMAGE_SYM_DTYPE_POINTER 1 // pointer.
  329. #define IMAGE_SYM_DTYPE_FUNCTION 2 // function.
  330. #define IMAGE_SYM_DTYPE_ARRAY 3 // array.
  331. //
  332. // Storage classes.
  333. //
  334. #define IMAGE_SYM_CLASS_END_OF_FUNCTION (UCHAR)-1
  335. #define IMAGE_SYM_CLASS_NULL 0
  336. #define IMAGE_SYM_CLASS_AUTOMATIC 1
  337. #define IMAGE_SYM_CLASS_EXTERNAL 2
  338. #define IMAGE_SYM_CLASS_STATIC 3
  339. #define IMAGE_SYM_CLASS_REGISTER 4
  340. #define IMAGE_SYM_CLASS_EXTERNAL_DEF 5
  341. #define IMAGE_SYM_CLASS_LABEL 6
  342. #define IMAGE_SYM_CLASS_UNDEFINED_LABEL 7
  343. #define IMAGE_SYM_CLASS_MEMBER_OF_STRUCT 8
  344. #define IMAGE_SYM_CLASS_ARGUMENT 9
  345. #define IMAGE_SYM_CLASS_STRUCT_TAG 10
  346. #define IMAGE_SYM_CLASS_MEMBER_OF_UNION 11
  347. #define IMAGE_SYM_CLASS_UNION_TAG 12
  348. #define IMAGE_SYM_CLASS_TYPE_DEFINITION 13
  349. #define IMAGE_SYM_CLASS_UNDEFINED_STATIC 14
  350. #define IMAGE_SYM_CLASS_ENUM_TAG 15
  351. #define IMAGE_SYM_CLASS_MEMBER_OF_ENUM 16
  352. #define IMAGE_SYM_CLASS_REGISTER_PARAM 17
  353. #define IMAGE_SYM_CLASS_BIT_FIELD 18
  354. #define IMAGE_SYM_CLASS_BLOCK 100
  355. #define IMAGE_SYM_CLASS_FUNCTION 101
  356. #define IMAGE_SYM_CLASS_END_OF_STRUCT 102
  357. #define IMAGE_SYM_CLASS_FILE 103
  358. // new
  359. #define IMAGE_SYM_CLASS_SECTION 104
  360. #define IMAGE_SYM_CLASS_WEAK_EXTERNAL 105
  361. // type packing constants
  362. #define N_BTMASK 017
  363. #define N_TMASK 060
  364. #define N_TMASK1 0300
  365. #define N_TMASK2 0360
  366. #define N_BTSHFT 4
  367. #define N_TSHIFT 2
  368. // MACROS
  369. // Basic Type of x
  370. #define BTYPE(x) ((x) & N_BTMASK)
  371. // Is x a pointer?
  372. #ifndef ISPTR
  373. #define ISPTR(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_POINTER << N_BTSHFT))
  374. #endif
  375. // Is x a function?
  376. #ifndef ISFCN
  377. #define ISFCN(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_FUNCTION << N_BTSHFT))
  378. #endif
  379. // Is x an array?
  380. #ifndef ISARY
  381. #define ISARY(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_ARRAY << N_BTSHFT))
  382. #endif
  383. // Is x a structure, union, or enumeration TAG?
  384. #ifndef ISTAG
  385. #define ISTAG(x) ((x)==IMAGE_SYM_CLASS_STRUCT_TAG || (x)==IMAGE_SYM_CLASS_UNION_TAG || (x)==IMAGE_SYM_CLASS_ENUM_TAG)
  386. #endif
  387. #ifndef INCREF
  388. #define INCREF(x) ((((x)&~N_BTMASK)<<N_TSHIFT)|(IMAGE_SYM_DTYPE_POINTER<<N_BTSHFT)|((x)&N_BTMASK))
  389. #endif
  390. #ifndef DECREF
  391. #define DECREF(x) ((((x)>>N_TSHIFT)&~N_BTMASK)|((x)&N_BTMASK))
  392. #endif
  393. //
  394. // Auxiliary entry format.
  395. //
  396. typedef union _IMAGE_AUX_SYMBOL {
  397. struct {
  398. ULONG TagIndex; // struct, union, or enum tag index
  399. union {
  400. struct {
  401. USHORT Linenumber; // declaration line number
  402. USHORT Size; // size of struct, union, or enum
  403. } LnSz;
  404. ULONG TotalSize;
  405. } Misc;
  406. union {
  407. struct { // if ISFCN, tag, or .bb
  408. ULONG PointerToLinenumber;
  409. ULONG PointerToNextFunction;
  410. } Function;
  411. struct { // if ISARY, up to 4 dimen.
  412. USHORT Dimension[4];
  413. } Array;
  414. } FcnAry;
  415. USHORT TvIndex; // tv index
  416. } Sym;
  417. struct {
  418. UCHAR Name[IMAGE_SIZEOF_SYMBOL];
  419. } File;
  420. struct {
  421. ULONG Length; // section length
  422. USHORT NumberOfRelocations; // number of relocation entries
  423. USHORT NumberOfLinenumbers; // number of line numbers
  424. ULONG CheckSum; // checksum for communal
  425. SHORT Number; // section number to associate with
  426. UCHAR Selection; // communal selection type
  427. } Section;
  428. } IMAGE_AUX_SYMBOL;
  429. typedef IMAGE_AUX_SYMBOL UNALIGNED *PIMAGE_AUX_SYMBOL;
  430. #define IMAGE_SIZEOF_AUX_SYMBOL 18
  431. //
  432. // Communal selection types.
  433. //
  434. #define IMAGE_COMDAT_SELECT_UNKNOWN 0
  435. #define IMAGE_COMDAT_SELECT_NODUPLICATES 1
  436. #define IMAGE_COMDAT_SELECT_ANY 2
  437. #define IMAGE_COMDAT_SELECT_SAME_SIZE 3
  438. #define IMAGE_COMDAT_SELECT_EXACT_MATCH 4
  439. #define IMAGE_COMDAT_SELECT_ASSOCIATIVE 5
  440. #define IMAGE_WEAK_EXTERN_SEARCH_UNKNOWN 0
  441. #define IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY 1
  442. #define IMAGE_WEAK_EXTERN_SEARCH_LIBRARY 2
  443. //
  444. // Relocation format.
  445. //
  446. typedef struct _IMAGE_RELOCATION {
  447. ULONG VirtualAddress;
  448. ULONG SymbolTableIndex;
  449. USHORT Type;
  450. } IMAGE_RELOCATION;
  451. typedef IMAGE_RELOCATION UNALIGNED *PIMAGE_RELOCATION;
  452. #define IMAGE_SIZEOF_RELOCATION 10
  453. //
  454. // I386 relocation types.
  455. //
  456. #define IMAGE_REL_I386_ABSOLUTE 0 // Reference is absolute, no relocation is necessary
  457. #define IMAGE_REL_I386_DIR16 01 // Direct 16-bit reference to the symbols virtual address
  458. #define IMAGE_REL_I386_REL16 02 // PC-relative 16-bit reference to the symbols virtual address
  459. #define IMAGE_REL_I386_DIR32 06 // Direct 32-bit reference to the symbols virtual address
  460. #define IMAGE_REL_I386_DIR32NB 07 // Direct 32-bit reference to the symbols virtual address, base not included
  461. #define IMAGE_REL_I386_SEG12 011 // Direct 16-bit reference to the segment-selector bits of a 32-bit virtual address
  462. #define IMAGE_REL_I386_SECTION 012
  463. #define IMAGE_REL_I386_SECREL 013
  464. #define IMAGE_REL_I386_REL32 024 // PC-relative 32-bit reference to the symbols virtual address
  465. //
  466. // MIPS relocation types.
  467. //
  468. #define IMAGE_REL_MIPS_ABSOLUTE 0 // Reference is absolute, no relocation is necessary
  469. #define IMAGE_REL_MIPS_REFHALF 01
  470. #define IMAGE_REL_MIPS_REFWORD 02
  471. #define IMAGE_REL_MIPS_JMPADDR 03
  472. #define IMAGE_REL_MIPS_REFHI 04
  473. #define IMAGE_REL_MIPS_REFLO 05
  474. #define IMAGE_REL_MIPS_GPREL 06
  475. #define IMAGE_REL_MIPS_LITERAL 07
  476. #define IMAGE_REL_MIPS_SECTION 012
  477. #define IMAGE_REL_MIPS_SECREL 013
  478. #define IMAGE_REL_MIPS_REFWORDNB 042
  479. #define IMAGE_REL_MIPS_PAIR 045
  480. //
  481. // Alpha Relocation types.
  482. //
  483. #define IMAGE_REL_ALPHA_ABSOLUTE 0x0
  484. #define IMAGE_REL_ALPHA_REFLONG 0x1
  485. #define IMAGE_REL_ALPHA_REFQUAD 0x2
  486. #define IMAGE_REL_ALPHA_GPREL32 0x3
  487. #define IMAGE_REL_ALPHA_LITERAL 0x4
  488. #define IMAGE_REL_ALPHA_LITUSE 0x5
  489. #define IMAGE_REL_ALPHA_GPDISP 0x6
  490. #define IMAGE_REL_ALPHA_BRADDR 0x7
  491. #define IMAGE_REL_ALPHA_HINT 0x8
  492. #define IMAGE_REL_ALPHA_INLINE_REFLONG 0x9
  493. #define IMAGE_REL_ALPHA_REFHI 0xA
  494. #define IMAGE_REL_ALPHA_REFLO 0xB
  495. #define IMAGE_REL_ALPHA_PAIR 0xC
  496. #define IMAGE_REL_ALPHA_MATCH 0xD
  497. #define IMAGE_REL_ALPHA_SECTION 0xE
  498. #define IMAGE_REL_ALPHA_SECREL 0xF
  499. #define IMAGE_REL_ALPHA_REFLONGNB 0x10
  500. //
  501. // Based relocation format.
  502. //
  503. typedef struct _IMAGE_BASE_RELOCATION {
  504. ULONG VirtualAddress;
  505. ULONG SizeOfBlock;
  506. // USHORT TypeOffset[1];
  507. } IMAGE_BASE_RELOCATION, *PIMAGE_BASE_RELOCATION;
  508. #define IMAGE_SIZEOF_BASE_RELOCATION 8
  509. //
  510. // Based relocation types.
  511. //
  512. #define IMAGE_REL_BASED_ABSOLUTE 0
  513. #define IMAGE_REL_BASED_HIGH 1
  514. #define IMAGE_REL_BASED_LOW 2
  515. #define IMAGE_REL_BASED_HIGHLOW 3
  516. #define IMAGE_REL_BASED_HIGHADJ 4
  517. #define IMAGE_REL_BASED_MIPS_JMPADDR 5
  518. //
  519. // Line number format.
  520. //
  521. typedef struct _IMAGE_LINENUMBER {
  522. union {
  523. ULONG SymbolTableIndex; // Symbol table index of function name if Linenumber is 0.
  524. ULONG VirtualAddress; // Virtual address of line number.
  525. } Type;
  526. USHORT Linenumber; // Line number.
  527. } IMAGE_LINENUMBER;
  528. typedef IMAGE_LINENUMBER UNALIGNED *PIMAGE_LINENUMBER;
  529. #define IMAGE_SIZEOF_LINENUMBER 6
  530. //
  531. // Archive format.
  532. //
  533. #define IMAGE_ARCHIVE_START_SIZE 8
  534. #define IMAGE_ARCHIVE_START "!<arch>\n"
  535. #define IMAGE_ARCHIVE_END "`\n"
  536. #define IMAGE_ARCHIVE_PAD "\n"
  537. #define IMAGE_ARCHIVE_LINKER_MEMBER "/ "
  538. #define IMAGE_ARCHIVE_LONGNAMES_MEMBER "// "
  539. typedef struct _IMAGE_ARCHIVE_MEMBER_HEADER {
  540. UCHAR Name[16]; // File member name - `/' terminated.
  541. UCHAR Date[12]; // File member date - decimal.
  542. UCHAR UserID[6]; // File member user id - decimal.
  543. UCHAR GroupID[6]; // File member group id - decimal.
  544. UCHAR Mode[8]; // File member mode - octal.
  545. UCHAR Size[10]; // File member size - decimal.
  546. UCHAR EndHeader[2]; // String to end header.
  547. } IMAGE_ARCHIVE_MEMBER_HEADER, *PIMAGE_ARCHIVE_MEMBER_HEADER;
  548. #define IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR 60
  549. //
  550. // DLL support.
  551. //
  552. //
  553. // Export Format
  554. //
  555. typedef struct _IMAGE_EXPORT_DIRECTORY {
  556. ULONG Characteristics;
  557. ULONG TimeDateStamp;
  558. USHORT MajorVersion;
  559. USHORT MinorVersion;
  560. ULONG Name;
  561. ULONG Base;
  562. ULONG NumberOfFunctions;
  563. ULONG NumberOfNames;
  564. PULONG *AddressOfFunctions;
  565. PULONG *AddressOfNames;
  566. PUSHORT *AddressOfNameOrdinals;
  567. } IMAGE_EXPORT_DIRECTORY, *PIMAGE_EXPORT_DIRECTORY;
  568. //
  569. // Import Format
  570. //
  571. typedef struct _IMAGE_IMPORT_BY_NAME {
  572. USHORT Hint;
  573. UCHAR Name[1];
  574. } IMAGE_IMPORT_BY_NAME, *PIMAGE_IMPORT_BY_NAME;
  575. typedef struct _IMAGE_THUNK_DATA {
  576. union {
  577. PULONG Function;
  578. ULONG Ordinal;
  579. PIMAGE_IMPORT_BY_NAME AddressOfData;
  580. } u1;
  581. } IMAGE_THUNK_DATA, *PIMAGE_THUNK_DATA;
  582. #define IMAGE_ORDINAL_FLAG 0x80000000
  583. #define IMAGE_SNAP_BY_ORDINAL(Ordinal) ((Ordinal & IMAGE_ORDINAL_FLAG) != 0)
  584. #define IMAGE_ORDINAL(Ordinal) (Ordinal & 0xffff)
  585. typedef struct _IMAGE_IMPORT_DESCRIPTOR {
  586. ULONG Characteristics;
  587. ULONG TimeDateStamp;
  588. ULONG ForwarderChain;
  589. ULONG Name;
  590. PIMAGE_THUNK_DATA FirstThunk;
  591. } IMAGE_IMPORT_DESCRIPTOR, *PIMAGE_IMPORT_DESCRIPTOR;
  592. //
  593. // Thread Local Storage
  594. //
  595. typedef VOID
  596. (NTAPI *PIMAGE_TLS_CALLBACK) (
  597. PVOID DllHandle,
  598. ULONG Reason,
  599. PVOID Reserved
  600. );
  601. typedef struct _IMAGE_TLS_DIRECTORY {
  602. ULONG StartAddressOfRawData;
  603. ULONG EndAddressOfRawData;
  604. PULONG AddressOfIndex;
  605. PIMAGE_TLS_CALLBACK *AddressOfCallBacks;
  606. ULONG SizeOfZeroFill;
  607. ULONG Characteristics;
  608. } IMAGE_TLS_DIRECTORY, *PIMAGE_TLS_DIRECTORY;
  609. //
  610. // Resource Format.
  611. //
  612. //
  613. // Resource directory consists of two counts, following by a variable length
  614. // array of directory entries. The first count is the number of entries at
  615. // beginning of the array that have actual names associated with each entry.
  616. // The entries are in ascending order, case insensitive strings. The second
  617. // count is the number of entries that immediately follow the named entries.
  618. // This second count identifies the number of entries that have 31-bit integer
  619. // Ids as their name. These entries are also sorted in ascending order.
  620. //
  621. // This structure allows fast lookup by either name or number, but for any
  622. // given resource entry only one form of lookup is supported, not both.
  623. // This is consistant with the syntax of the .RC file and the .RES file.
  624. //
  625. typedef struct _IMAGE_RESOURCE_DIRECTORY {
  626. ULONG Characteristics;
  627. ULONG TimeDateStamp;
  628. USHORT MajorVersion;
  629. USHORT MinorVersion;
  630. USHORT NumberOfNamedEntries;
  631. USHORT NumberOfIdEntries;
  632. // IMAGE_RESOURCE_DIRECTORY_ENTRY DirectoryEntries[];
  633. } IMAGE_RESOURCE_DIRECTORY, *PIMAGE_RESOURCE_DIRECTORY;
  634. #define IMAGE_RESOURCE_NAME_IS_STRING 0x80000000
  635. #define IMAGE_RESOURCE_DATA_IS_DIRECTORY 0x80000000
  636. //
  637. // Each directory contains the 32-bit Name of the entry and an offset,
  638. // relative to the beginning of the resource directory of the data associated
  639. // with this directory entry. If the name of the entry is an actual text
  640. // string instead of an integer Id, then the high order bit of the name field
  641. // is set to one and the low order 31-bits are an offset, relative to the
  642. // beginning of the resource directory of the string, which is of type
  643. // IMAGE_RESOURCE_DIRECTORY_STRING. Otherwise the high bit is clear and the
  644. // low-order 31-bits are the integer Id that identify this resource directory
  645. // entry. If the directory entry is yet another resource directory (i.e. a
  646. // subdirectory), then the high order bit of the offset field will be
  647. // set to indicate this. Otherwise the high bit is clear and the offset
  648. // field points to a resource data entry.
  649. //
  650. typedef struct _IMAGE_RESOURCE_DIRECTORY_ENTRY {
  651. ULONG Name;
  652. ULONG OffsetToData;
  653. } IMAGE_RESOURCE_DIRECTORY_ENTRY, *PIMAGE_RESOURCE_DIRECTORY_ENTRY;
  654. //
  655. // For resource directory entries that have actual string names, the Name
  656. // field of the directory entry points to an object of the following type.
  657. // All of these string objects are stored together after the last resource
  658. // directory entry and before the first resource data object. This minimizes
  659. // the impact of these variable length objects on the alignment of the fixed
  660. // size directory entry objects.
  661. //
  662. typedef struct _IMAGE_RESOURCE_DIRECTORY_STRING {
  663. USHORT Length;
  664. CHAR NameString[ 1 ];
  665. } IMAGE_RESOURCE_DIRECTORY_STRING, *PIMAGE_RESOURCE_DIRECTORY_STRING;
  666. typedef struct _IMAGE_RESOURCE_DIR_STRING_U {
  667. USHORT Length;
  668. WCHAR NameString[ 1 ];
  669. } IMAGE_RESOURCE_DIR_STRING_U, *PIMAGE_RESOURCE_DIR_STRING_U;
  670. //
  671. // Each resource data entry describes a leaf node in the resource directory
  672. // tree. It contains an offset, relative to the beginning of the resource
  673. // directory of the data for the resource, a size field that gives the number
  674. // of bytes of data at that offset, a CodePage that should be used when
  675. // decoding code point values within the resource data. Typically for new
  676. // applications the code page would be the unicode code page.
  677. //
  678. typedef struct _IMAGE_RESOURCE_DATA_ENTRY {
  679. ULONG OffsetToData;
  680. ULONG Size;
  681. ULONG CodePage;
  682. ULONG Reserved;
  683. } IMAGE_RESOURCE_DATA_ENTRY, *PIMAGE_RESOURCE_DATA_ENTRY;
  684. //
  685. // Load Configuration Directory Entry
  686. //
  687. typedef struct _IMAGE_LOAD_CONFIG_DIRECTORY {
  688. ULONG Characteristics;
  689. ULONG TimeDateStamp;
  690. USHORT MajorVersion;
  691. USHORT MinorVersion;
  692. ULONG GlobalFlagsClear;
  693. ULONG GlobalFlagsSet;
  694. ULONG CriticalSectionDefaultTimeout;
  695. ULONG DeCommitFreeBlockThreshold;
  696. ULONG DeCommitTotalFreeThreshold;
  697. PVOID LockPrefixTable;
  698. ULONG MaximumAllocationSize;
  699. ULONG VirtualMemoryThreshold;
  700. ULONG Reserved[ 5 ];
  701. } IMAGE_LOAD_CONFIG_DIRECTORY, *PIMAGE_LOAD_CONFIG_DIRECTORY;
  702. //
  703. // Function table entry format for MIPS/ALPHA images. Function table is
  704. // pointed to by the IMAGE_DIRECTORY_ENTRY_EXCEPTION directory entry.
  705. // This definition duplicates ones in ntmips.h and ntalpha.h for use
  706. // by portable image file mungers.
  707. //
  708. typedef struct _IMAGE_RUNTIME_FUNCTION_ENTRY {
  709. ULONG BeginAddress;
  710. ULONG EndAddress;
  711. PVOID ExceptionHandler;
  712. PVOID HandlerData;
  713. ULONG PrologEndAddress;
  714. } IMAGE_RUNTIME_FUNCTION_ENTRY, *PIMAGE_RUNTIME_FUNCTION_ENTRY;
  715. //
  716. // Debug Format
  717. //
  718. typedef struct _IMAGE_DEBUG_DIRECTORY {
  719. ULONG Characteristics;
  720. ULONG TimeDateStamp;
  721. USHORT MajorVersion;
  722. USHORT MinorVersion;
  723. ULONG Type;
  724. ULONG SizeOfData;
  725. ULONG AddressOfRawData;
  726. ULONG PointerToRawData;
  727. } IMAGE_DEBUG_DIRECTORY, *PIMAGE_DEBUG_DIRECTORY;
  728. #define IMAGE_DEBUG_TYPE_UNKNOWN 0
  729. #define IMAGE_DEBUG_TYPE_COFF 1
  730. #define IMAGE_DEBUG_TYPE_CODEVIEW 2
  731. #define IMAGE_DEBUG_TYPE_FPO 3
  732. #define IMAGE_DEBUG_TYPE_MISC 4
  733. #define IMAGE_DEBUG_TYPE_EXCEPTION 5
  734. #define IMAGE_DEBUG_TYPE_FIXUP 6
  735. #define IMAGE_DEBUG_TYPE_OMAP_TO_SRC 7
  736. #define IMAGE_DEBUG_TYPE_OMAP_FROM_SRC 8
  737. typedef struct _IMAGE_COFF_SYMBOLS_HEADER {
  738. ULONG NumberOfSymbols;
  739. ULONG LvaToFirstSymbol;
  740. ULONG NumberOfLinenumbers;
  741. ULONG LvaToFirstLinenumber;
  742. ULONG RvaToFirstByteOfCode;
  743. ULONG RvaToLastByteOfCode;
  744. ULONG RvaToFirstByteOfData;
  745. ULONG RvaToLastByteOfData;
  746. } IMAGE_COFF_SYMBOLS_HEADER, *PIMAGE_COFF_SYMBOLS_HEADER;
  747. #define FRAME_FPO 0
  748. #define FRAME_TRAP 1
  749. #define FRAME_TSS 2
  750. typedef struct _FPO_DATA {
  751. ULONG ulOffStart; // offset 1st byte of function code
  752. ULONG cbProcSize; // # bytes in function
  753. ULONG cdwLocals; // # bytes in locals/4
  754. USHORT cdwParams; // # bytes in params/4
  755. USHORT cbProlog : 8; // # bytes in prolog
  756. USHORT cbRegs : 3; // # regs saved
  757. USHORT fHasSEH : 1; // TRUE if SEH in func
  758. USHORT fUseBP : 1; // TRUE if EBP has been allocated
  759. USHORT reserved : 1; // reserved for future use
  760. USHORT cbFrame : 2; // frame type
  761. } FPO_DATA, *PFPO_DATA;
  762. #define SIZEOF_RFPO_DATA 16
  763. #define IMAGE_DEBUG_MISC_EXENAME 1
  764. typedef struct _IMAGE_DEBUG_MISC {
  765. ULONG DataType; // type of misc data, see defines
  766. ULONG Length; // total length of record, rounded to four
  767. // byte multiple.
  768. BOOLEAN Unicode; // TRUE if data is unicode string
  769. UCHAR Reserved[ 3 ];
  770. UCHAR Data[ 1 ]; // Actual data
  771. } IMAGE_DEBUG_MISC, *PIMAGE_DEBUG_MISC;
  772. //
  773. // Debugging information can be stripped from an image file and placed
  774. // in a separate .DBG file, whose file name part is the same as the
  775. // image file name part (e.g. symbols for CMD.EXE could be stripped
  776. // and placed in CMD.DBG). This is indicated by the IMAGE_FILE_DEBUG_STRIPPED
  777. // flag in the Characteristics field of the file header. The beginning of
  778. // the .DBG file contains the following structure which captures certain
  779. // information from the image file. This allows a debug to proceed even if
  780. // the original image file is not accessable. This header is followed by
  781. // zero of more IMAGE_SECTION_HEADER structures, followed by zero or more
  782. // IMAGE_DEBUG_DIRECTORY structures. The latter structures and those in
  783. // the image file contain file offsets relative to the beginning of the
  784. // .DBG file.
  785. //
  786. // If symbols have been stripped from an image, the IMAGE_DEBUG_MISC structure
  787. // is left in the image file, but not mapped. This allows a debugger to
  788. // compute the name of the .DBG file, from the name of the image in the
  789. // IMAGE_DEBUG_MISC structure.
  790. //
  791. typedef struct _IMAGE_SEPARATE_DEBUG_HEADER {
  792. USHORT Signature;
  793. USHORT Flags;
  794. USHORT Machine;
  795. USHORT Characteristics;
  796. ULONG TimeDateStamp;
  797. ULONG CheckSum;
  798. ULONG ImageBase;
  799. ULONG SizeOfImage;
  800. ULONG NumberOfSections;
  801. ULONG ExportedNamesSize;
  802. ULONG DebugDirectorySize;
  803. ULONG Reserved[ 3 ];
  804. } IMAGE_SEPARATE_DEBUG_HEADER, *PIMAGE_SEPARATE_DEBUG_HEADER;
  805. #define IMAGE_SEPARATE_DEBUG_SIGNATURE 0x4944
  806. #ifndef RC_INVOKED
  807. #pragma pack ()
  808. #endif // !RC_INVOKED
  809. //
  810. // End Image Format
  811. //
  812. // end_winnt
  813. #endif // _NTIMAGE_