peData.ml 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. (*
  2. * This file is part of ilLib
  3. * Copyright (c)2004-2013 Haxe Foundation
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  18. *)
  19. (*
  20. This data is based on the
  21. Microsoft Portable Executable and Common Object File Format Specification
  22. Revision 8.3
  23. *)
  24. type machine_type =
  25. | TUnknown (* 0 - unmanaged PE files only *)
  26. | Ti386 (* 0x014c - i386 *)
  27. | TR3000 (* 0x0162 - R3000 MIPS Little Endian *)
  28. | TR4000 (* 0x0166 - R4000 MIPS Little Endian *)
  29. | TR10000 (* 0x0168 - R10000 MIPS Little Endian *)
  30. | TWCeMipsV2 (* 0x0169 - MIPS Little Endian running MS Windows CE 2 *)
  31. | TAlpha (* 0x0184 - Alpha AXP *)
  32. | TSh3 (* 0x01a2 - SH3 Little Endian *)
  33. | TSh3Dsp (* 0x01a3 SH3DSP Little Endian *)
  34. | TSh3e (* 0x01a4 SH3E Little Endian *)
  35. | TSh4 (* 0x01a6 SH4 Little Endian *)
  36. | TSh5 (* 0x01a8 SH5 *)
  37. | TArm (* 0x1c0 ARM Little Endian *)
  38. | TArmN (* 0x1c4 ARMv7 (or higher) Thumb mode only Little Endian *)
  39. | TArm64 (* 0xaa64 - ARMv8 in 64-bit mode *)
  40. | TEbc (* 0xebc - EFI byte code *)
  41. | TThumb (* 0x1c2 ARM processor with Thumb decompressor *)
  42. | TAm33 (* 0x1d3 AM33 processor *)
  43. | TPowerPC (* 0x01f0 IBM PowerPC Little Endian *)
  44. | TPowerPCFP (* 0x01f1 IBM PowerPC with FPU *)
  45. | TItanium64 (* 0x0200 Intel IA64 (Itanium) *)
  46. | TMips16 (* 0x0266 MIPS *)
  47. | TAlpha64 (* 0x0284 Alpha AXP64 *)
  48. | TMipsFpu (* 0x0366 MIPS with FPU *)
  49. | TMipsFpu16 (* 0x0466 MIPS16 with FPU *)
  50. | TTriCore (* 0x0520 Infineon *)
  51. | TAmd64 (* 0x8664 AMD x64 and Intel E64T *)
  52. | TM32R (* 0x9041 M32R *)
  53. | TOSXAmd64 (* 0xC020 = 0x8664 xor 0x4644 OSX AMD x64 *)
  54. | TLinuxAmd64 (* 0xFD1D = 0x8664 xor 0x7B79 Linux AMD x64 *)
  55. type coff_prop =
  56. | RelocsStripped (* 0x1 *)
  57. (* image file only. Indicates the file contains no base relocations and *)
  58. (* must be loaded at its preferred base address. Should not be set for MPE files *)
  59. | ExecutableImage (* 0x2 *)
  60. (* Indicates that the file is an image file (EXE or DLL). Should be set for MPE files *)
  61. | LineNumsStripped (* 0x4 *)
  62. (* COFF line numbers have been removed. This flag should not be set for MPE files *)
  63. (* because they do not use the debug info embedded in the PE file itself. They are saved on PDB files *)
  64. | LocalSymsStripped (* 0x8 *)
  65. (* COFF symbol table entries for local symbols have been removed. It should be set for MPE files *)
  66. | AgressiveWsTrim (* 0x10 *)
  67. (* Agressively trim the working set. This flag should not be set for pure-IL MPE files *)
  68. | LargeAddressAware (* 0x20 *)
  69. (* Application can handle addresses beyond the 2GB range. This flag should not be set for *)
  70. (* pure-IL MPE files of versions 1 and 1.1, but can be set for v2.0 files *)
  71. | BytesReversedLO (* 0x80 *)
  72. (* Little endian. This flag should not be set for pure-IL MPE files *)
  73. | Machine32Bit (* 0x100 *)
  74. (* Machine is based on 32-bit architecture. This flag is usually set by the current *)
  75. (* versions of code generators producing PE files. V2.0+ can produce 64-bit specific images *)
  76. (* which don't have this flag set *)
  77. | DebugStripped (* 0x200 *)
  78. (* Debug information has been removed from the image file *)
  79. | RemovableRunFromSwap (* 0x400 *)
  80. (* If the image file is on removable media, copy and run it from swap file. *)
  81. (* This flag should no be set for pure-IL MPE files *)
  82. | NetRunFromSwap (* 0x800 *)
  83. (* If the image file is on a network, copy and run it from the swap file. *)
  84. (* This flag should no be set for pure-IL MPE files *)
  85. | FileSystem (* 0x1000 *)
  86. (* The image file is a system file (for example, a device driver) *)
  87. (* This flag should not be set for pure-IL MPE files *)
  88. | FileDll (* 0x2000 *)
  89. (* This image file is a DLL rather than an EXE. It cannot be directly run. *)
  90. | UpSystemOnly (* 0x4000 *)
  91. (* The image file should be run on an uniprocessor machine only. *)
  92. (* This flag should not be set for pure-IL MPE files *)
  93. | BytesReversedHI (* 0x8000 *)
  94. (* Big endian *)
  95. (* This flag should not be set for pure-IL MPE files *)
  96. (* represents a virtual address pointer. It's 64-bit on 64-bit executables, and 32-bit otherwise *)
  97. type pointer = int64
  98. (* represents a memory index address on the target architecture. It's 64-bit on 64-bit executables, and 32-bit otherwise *)
  99. type size_t = pointer
  100. (* relative virtual address. *)
  101. (* it's always 32-bit - which means that PE/COFF files are still limited to the 4GB size *)
  102. type rva = int32
  103. (* represents a PE file-bound memory index *)
  104. type size_t_file = int32
  105. (* represents a file offset *)
  106. (* there's no point in defining it as int32, as file seek operations need an int *)
  107. type pointer_file = int
  108. type coff_header = {
  109. coff_machine : machine_type; (* offset 0 - size 2 . *)
  110. (* If the managed PE file is intended for various machine types (AnyCPU), it should be Ti386 *)
  111. coff_nsections : int; (* O2S2 *)
  112. coff_timestamp : int32; (* O4S4 *)
  113. coff_symbol_table_pointer : rva; (* O8S4 *)
  114. (* File pointer of the COFF symbol table. In managed PE files, it is 0 *)
  115. coff_nsymbols : int; (* O12S4 *)
  116. (* Number of entries in the COFF symbol table. Should be 0 in managed PE files *)
  117. coff_optheader_size: int; (* O16S2 *)
  118. (* Size of the PE header *)
  119. coff_props : coff_prop list;
  120. }
  121. let coff_default_exe_props = [ ExecutableImage; LineNumsStripped; LocalSymsStripped; (* Machine32Bit; *) ]
  122. let coff_default_dll_props = [ ExecutableImage; LineNumsStripped; LocalSymsStripped; (* Machine32Bit; *) FileDll ]
  123. type pe_magic =
  124. | P32 (* 0x10b *)
  125. | PRom (* 0x107 *)
  126. | P64 (* 0x20b - called PE32+ on the docs *)
  127. (* allows 64-bit address space while limiting the image size to 2 gb *)
  128. type subsystem =
  129. | SUnknown (* 0 *)
  130. | SNative (* 1 *)
  131. (* Device drivers and native windows processes *)
  132. | SWGui (* 2 *)
  133. (* Windows GUI subsystem *)
  134. | SWCui (* 3 *)
  135. (* Windows character subsystem *)
  136. | SPCui (* 7 *)
  137. (* Posix character subsystem *)
  138. | SWCeGui (* 9 *)
  139. (* Windows CE subsystem *)
  140. | SEfi (* 10 *)
  141. (* EFI application *)
  142. | SEfiBoot (* 11 *)
  143. (* EFI driver with boot services *)
  144. | SEfiRuntime (* 12 *)
  145. (* EFI driver with run-time services *)
  146. | SEfiRom (* 13 *)
  147. (* EFI ROM Image *)
  148. | SXbox (* 14 *)
  149. type dll_prop =
  150. | DDynamicBase (* 0x0040 *)
  151. (* DLL can be relocated at load time *)
  152. | DForceIntegrity (* 0x0080 *)
  153. (* Code integrity checks are enforced *)
  154. | DNxCompat (* 0x0100 *)
  155. (* Image is NX compatible *)
  156. | DNoIsolation (* 0x0200 *)
  157. (* Isolation-aware, but do not isolate the image *)
  158. | DNoSeh (* 0x0400 *)
  159. (* No structured exception handling *)
  160. | DNoBind (* 0x0800 *)
  161. (* Do not bind the image *)
  162. | DWdmDriver (* 0x2000 *)
  163. (* A WDM driver *)
  164. | DTerminalServer (* 0x8000 *)
  165. (* Terminal server aware *)
  166. type directory_type =
  167. | ExportTable (* .edata *)
  168. (* contains information about four other tables, which hold data describing *)
  169. (* unmanaged exports of the PE file. ILAsm and VC++ linker are capable of exposing *)
  170. (* the managed PE file as unmanaged exports *)
  171. | ImportTable (* .idata *)
  172. (* data on unmanaged imports consumed by the PE file. Only the VC++ linker makes *)
  173. (* use of this table, by marking the imported unmanaged external functions used by *)
  174. (* the unmanaged native code embedded in the same assembly. Other compilers only *)
  175. (* contain a single entry - that of the CLR entry function *)
  176. | ResourceTable (* .rsrc *)
  177. (* unmanaged resources embedded in the PE file. Managed resources don't use this *)
  178. | ExceptionTable (* .pdata *)
  179. (* unmanaged exceptions only *)
  180. | CertificateTable
  181. (* points to a table of attribute certificates, used for file authentication *)
  182. (* the first field of this entry is a file pointer rather than an RVA *)
  183. | RelocTable (* .reloc *)
  184. (* relocation table. We need to be aware of it if we use native TLS. *)
  185. (* only the VC++ linker uses native TLS' *)
  186. | DebugTable
  187. (* unmanaged debug data starting address and size. A managed PE file doesn't carry *)
  188. (* embedded debug data, so this data is either all zero or points to a 30-byte debug dir entry *)
  189. (* of type 2 (IMAGE_DEBUG_TYPE_CODEVIEW), which in turn points to a CodeView-style header, containing *)
  190. (* the path to the PDB debug file. *)
  191. | ArchitectureTable
  192. (* for i386, Itanium64 or AMD64, this data is set to all zeros *)
  193. | GlobalPointer
  194. (* the RVA of the value to be stored in the global pointer register. Size must be 0. *)
  195. (* if the target architecture (e.g. i386 or AMD64) don't use the concept of a global pointer, *)
  196. (* it is set to all zeros *)
  197. | TlsTable (* .tls *)
  198. (* The thread-local storage data. Only the VC++ linker and IL assembler produce code that use it *)
  199. | LoadConfigTable
  200. (* data specific to Windows NT OS *)
  201. | BoundImportTable
  202. (* array of bound import descriptors, each of which describes a DLL this image was bound *)
  203. (* at link-time, along with time stamps of the bindings. Iff they are up-to-date, the OS loader *)
  204. (* uses these bindings as a "shortcut" for API import *)
  205. | ImportAddressTable
  206. (* referenced from the Import Directory table (data directory 1) *)
  207. | DelayImport
  208. (* delay-load imports are DLLs described as implicit imports but loaded as explicit imports *)
  209. (* (via calls to the LoadLibrary API) *)
  210. | ClrRuntimeHeader (* .cormeta *)
  211. (* pointer to the clr_runtime_header *)
  212. | Reserved
  213. (* must be zero *)
  214. | Custom of int
  215. let directory_type_info = function
  216. | ExportTable -> 0, "ExportTable"
  217. | ImportTable -> 1, "ImportTable"
  218. | ResourceTable -> 2, "ResourceTable"
  219. | ExceptionTable -> 3, "ExceptionTable"
  220. | CertificateTable -> 4, "CertificateTable"
  221. | RelocTable -> 5, "RelocTable"
  222. | DebugTable -> 6, "DebugTable"
  223. | ArchitectureTable -> 7, "ArchTable"
  224. | GlobalPointer -> 8, "GlobalPointer"
  225. | TlsTable -> 9, "TlsTable"
  226. | LoadConfigTable -> 10, "LoadConfigTable"
  227. | BoundImportTable -> 11, "BuildImportTable"
  228. | ImportAddressTable -> 12, "ImportAddressTable"
  229. | DelayImport -> 13, "DelayImport"
  230. | ClrRuntimeHeader -> 14, "ClrRuntimeHeader"
  231. | Reserved -> 15, "Reserved"
  232. | Custom i -> i, "Custom" ^ (string_of_int i)
  233. let directory_type_of_int = function
  234. | 0 -> ExportTable
  235. | 1 -> ImportTable
  236. | 2 -> ResourceTable
  237. | 3 -> ExceptionTable
  238. | 4 -> CertificateTable
  239. | 5 -> RelocTable
  240. | 6 -> DebugTable
  241. | 7 -> ArchitectureTable
  242. | 8 -> GlobalPointer
  243. | 9 -> TlsTable
  244. | 10 -> LoadConfigTable
  245. | 11 -> BoundImportTable
  246. | 12 -> ImportAddressTable
  247. | 13 -> DelayImport
  248. | 14 -> ClrRuntimeHeader
  249. | 15 -> Reserved
  250. | i -> Custom i
  251. type section_prop =
  252. | SNoPad (* 0x8 *)
  253. (* the section should not be padded to the next boundary. *)
  254. (* OBSOLETE - replaced by SAlign1Bytes *)
  255. | SHasCode (* 0x20 *)
  256. (* the section contains executable code *)
  257. | SHasIData (* 0x40 *)
  258. (* contains initialized data *)
  259. | SHasData (* 0x80 *)
  260. (* contains uninitialized data *)
  261. | SHasLinkInfo (* 0x200 *)
  262. (* contains comments or other information. only valid for object files *)
  263. | SLinkRemove (* 0x1000 *)
  264. (* this will not become part of the image. only valid for object files *)
  265. | SGlobalRel (* 0x8000 *)
  266. (* contains data referenced through the global pointer (GP) *)
  267. | SHas16BitMem (* 0x20000 *)
  268. (* for ARM architecture. The section contains Thumb code *)
  269. | SAlign1Bytes (* 0x100000 *)
  270. (* align data on a 1-byte boundary. valid only for object files *)
  271. | SAlign2Bytes (* 0x200000 *)
  272. | SAlign4Bytes (* 0x300000 *)
  273. | SAlign8Bytes (* 0x400000 *)
  274. | SAlign16Bytes (* 0x500000 *)
  275. | SAlign32Bytes (* 0x600000 *)
  276. | SAlign64Bytes (* 0x700000 *)
  277. | SAlign128Bytes (* 0x800000 *)
  278. | SAlign256Bytes (* 0x900000 *)
  279. | SAlign512Bytes (* 0xA00000 *)
  280. | SAlign1024Bytes (* 0xB00000 *)
  281. | SAlign2048Bytes (* 0xC00000 *)
  282. | SAlign4096Bytes (* 0xD00000 *)
  283. | SAlign8192Bytes (* 0xE00000 *)
  284. | SHasExtRelocs (* 0x1000000 *)
  285. (* section contains extended relocations *)
  286. | SCanDiscard (* 0x02000000 *)
  287. (* section can be discarded as needed *)
  288. | SNotCached (* 0x04000000 *)
  289. (* section cannot be cached *)
  290. | SNotPaged (* 0x08000000 *)
  291. (* section is not pageable *)
  292. | SShared (* 0x10000000 *)
  293. (* section can be shared in memory *)
  294. | SExec (* 0x20000000 *)
  295. (* section can be executed as code *)
  296. | SRead (* 0x40000000 *)
  297. (* section can be read *)
  298. | SWrite (* 0x80000000 *)
  299. (* section can be written to *)
  300. type pe_section = {
  301. s_name : string;
  302. (* an 8-byte, null-padded UTF-8 encoded string *)
  303. s_vsize : size_t_file;
  304. (* the total size of the section when loaded into memory. *)
  305. (* if less than s_rawsize, the section is zero-padded *)
  306. (* should be set to 0 on object files *)
  307. s_vaddr : rva;
  308. (* the RVA of the beginning of the section *)
  309. s_raw_size : size_t_file;
  310. (* the size of the initialized data on disk, rounded up to a multiple *)
  311. (* of the file alignment value. If it's less than s_vsize, it should be *)
  312. (* zero filled. It may happen that rawsize is greater than vsize. *)
  313. s_raw_pointer : pointer_file;
  314. (* the file pointer to the first page of the section within the COFF file *)
  315. (* on executable images, this must be a multiple of file aignment value. *)
  316. (* for object files, it should be aligned on a 4byte boundary *)
  317. s_reloc_pointer : pointer_file;
  318. (* the file pointer to the beginning of relocation entries for this section *)
  319. (* this is set to zero for executable images or if there are no relocations *)
  320. s_line_num_pointer : pointer_file;
  321. (* the file pointer to the beginning of line-number entries for this section *)
  322. (* must be 0 : COFF debugging image is deprecated *)
  323. s_nrelocs : int;
  324. (* number of relocation entries *)
  325. s_nline_nums : int;
  326. (* number of line number entries *)
  327. s_props : section_prop list;
  328. (* properties of the section *)
  329. }
  330. (* The size of the PE header is not fixed. It depends on the number of data directories defined in the header *)
  331. (* and is specified in the optheader_size in the COFF header *)
  332. (* object files don't have this; but it's required for image files *)
  333. type pe_header = {
  334. pe_coff_header : coff_header;
  335. (* Standard fields *)
  336. pe_magic : pe_magic;
  337. pe_major : int;
  338. pe_minor : int;
  339. pe_code_size : int;
  340. (* size of the code section (.text) or the sum of all code sections, *)
  341. (* if multiple sections exist. The IL assembler always emits a single code section *)
  342. pe_init_size : int;
  343. pe_uinit_size : int;
  344. pe_entry_addr : rva;
  345. (* RVA of the beginning of the entry point function. For unmanaged DLLs, this can be 0 *)
  346. (* For managed PE files, this always points to the CLR invocation stub *)
  347. pe_base_code : rva;
  348. (* The address that is relative to the image base of the beginning-of-code section *)
  349. (* when it's loaded into memory *)
  350. pe_base_data : rva;
  351. (* The address that is relative to the image base of the beginning-of-data section *)
  352. (* when it's loaded into memory *)
  353. (* COFF Windows extension *)
  354. pe_image_base : pointer;
  355. (* The preferred address of the first byte of image when loaded into memory. *)
  356. (* Should be a multiple of 64K *)
  357. pe_section_alignment : int;
  358. (* The alignment in bytes of sections when they are loaded into memory *)
  359. (* It must be greater than or equal to FileAlignment. The default is the page size *)
  360. (* for the architecture *)
  361. (* x86 MPE files should have an alignment of 8KB, even though only 4KB would be needed *)
  362. (* for compatibility with 64-bits *)
  363. pe_file_alignment : int;
  364. (* The alignment factor in bytes that is used to align the raw data of sections *)
  365. (* in the image file. The value should be a POT between 512 and 64K. *)
  366. (* If secion_alignment is less than architecture's page size, file_alignment must match *)
  367. (* secion_alignment *)
  368. pe_major_osver : int;
  369. pe_minor_osver : int;
  370. pe_major_imgver : int;
  371. pe_minor_imgver : int;
  372. pe_major_subsysver : int;
  373. pe_minor_subsysver : int;
  374. pe_image_size : int;
  375. (* the size of the image in bytes, as the image is loaded into memory *)
  376. (* must be a multiple of section_alignment *)
  377. pe_headers_size : int;
  378. (* the combined size of an MSDOS stub, PE header, and section headers *)
  379. (* rounded up to a multiple of FileAlignment *)
  380. pe_checksum : int32;
  381. pe_subsystem : subsystem;
  382. pe_dll_props : dll_prop list;
  383. (* in MPE files of v1.0, always set to 0; In MPE of v1.1 and later, *)
  384. (* always set to 0x400 (DNoSeh) *)
  385. pe_stack_reserve : size_t;
  386. (* the size of the stack to reserve. Only pe_stack_commit is committed *)
  387. pe_stack_commit : size_t;
  388. (* the size of the stack to commit *)
  389. pe_heap_reserve : size_t;
  390. (* the size of the local heap space to reserve. Only pe_heap_commit is committed *)
  391. pe_heap_commit : size_t;
  392. (* the size of the heap to commit *)
  393. pe_ndata_dir : int;
  394. (* the number of data-directory entries in the remainder of the optional header *)
  395. (* should be at least 16. Although is possible to emit more than 16 data directories, *)
  396. (* all existing managed compilers emit exactly 16 data directories, with the last never *)
  397. (* used (reserved) *)
  398. pe_data_dirs : (rva * size_t_file) array;
  399. (* data directories are RVA's that point to sections on the PE that have special significance *)
  400. (* see directory_type docs *)
  401. (* sections *)
  402. pe_sections : pe_section array;
  403. }
  404. (* raw .idata table *)
  405. (* not used : only here for documentation purposes *)
  406. type idata_table_raw = {
  407. impr_lookup_table : rva;
  408. (* the RVA of the lookup table *)
  409. impr_timestamp : int32;
  410. (* on bound images, it's set to the timestamp of the DLL *)
  411. impr_fchain : int32;
  412. (* the index of the first forwarder reference - which are references *)
  413. (* that are both imported and exported *)
  414. impr_name : rva;
  415. (* the RVA to an ASCII string that contains the name of the DLL *)
  416. impr_address_table : rva;
  417. (* RVA of the import address table. The contents are identical to the imp_lookup_table *)
  418. (* until the image is bound *)
  419. }
  420. (* a symbol lookup can happen either by name, or by ordinal. *)
  421. (* lookup by name happens to be an extra indirection, as the loader *)
  422. (* uses the name to look up the export ordinal anyway. *)
  423. (* Most (if not all) MPE will do a lookup by name, though *)
  424. type symbol_lookup =
  425. | SName of int * string
  426. | SOrdinal of int
  427. type idata_table = {
  428. imp_name : string;
  429. (* ASCII string that contains the name of the DLL *)
  430. imp_imports : symbol_lookup list;
  431. }
  432. type clr_flag =
  433. | FIlOnly (* 0x1 *)
  434. (* the image file contains IL code only, with no embedded native unmanaged code *)
  435. (* this can cause some problems on WXP+, because the .reloc section is ignored when this flag is set *)
  436. (* e.g. if native TLS support is used. In this case the VC++ compiler unsets this flag *)
  437. | F32BitRequired (* 0x2 *)
  438. (* the file can be only loaded into a 32-bit process *)
  439. | FIlLibrary (* 0x4 *)
  440. (* obsolete *)
  441. | FSigned (* 0x8 *)
  442. (* the image file is protected with a strong name signature *)
  443. | FNativeEntry (* 0x10 *)
  444. (* the executable's entry point is an unmanaged method. *)
  445. (* the EntryPointToken / EntryPointRVA field of the CLR header *)
  446. (* contains the RVA of this native method *)
  447. | FTrackDebug (* 0x10000 *)
  448. (* the CLR loader is required to track debug information about the methods. This flag is not used *)
  449. type clr_header = {
  450. clr_cb : int;
  451. (* size of header *)
  452. clr_major : int;
  453. clr_minor : int;
  454. (* symbol table and startup information *)
  455. clr_meta : rva * size_t_file;
  456. clr_flags : clr_flag list;
  457. clr_entry_point : rva;
  458. (* metadata identifier (token) of the entry point for the image file *)
  459. (* can be 0 for DLL images. This field identifies a method belonging to this module *)
  460. (* or a module containing the entry point method. This field may contain RVA of the *)
  461. (* embedded native entry point method, if FNativeEntry flag is set *)
  462. (* binding information *)
  463. clr_res : rva * size_t_file;
  464. (* RVA of managed resources *)
  465. clr_sig : rva * size_t_file;
  466. (* RVA of the hash data for this PE file, used by the loader for binding and versioning *)
  467. (* regular fixup and binding information *)
  468. clr_codeman : rva * size_t_file;
  469. (* code manager table - RESERVED and should be 0 *)
  470. clr_vtable_fix : rva * size_t_file;
  471. (* RVA of an array of vtable fixups. Only VC++ linker and IL assembler produce data in this array *)
  472. clr_export_address : rva * size_t_file;
  473. (* rva of addresses of jump thunks. obsolete and should be set to 0 *)
  474. }
  475. (* unused structure: documentation purposes only *)
  476. type clr_stream_header = {
  477. str_offset : pointer_file;
  478. (* the (relative to the start of metadata) offset in the file for this stream *)
  479. str_size : size_t_file;
  480. (* the size of the stream in bytes *)
  481. str_name : string;
  482. (* name of the stream - a zero-terminated ASCII string no longer than 31 characters (plus 0 terminator) *)
  483. (* if the stream name is smaller, it can be reduced - but must be padded to the 4-byte boundary *)
  484. }
  485. (* unused structure: documentation purposes only *)
  486. type clr_meta_table = {
  487. (* storage signature *)
  488. meta_magic : string;
  489. (* always BSJB *)
  490. meta_major : int;
  491. meta_minor : int;
  492. (* meta_extra : int; *)
  493. (* reserved; always 0 *)
  494. meta_ver : string;
  495. (* encoded by first passing its length *)
  496. (* storage header *)
  497. (* meta_flags : int; *)
  498. (* reserved; always 0 *)
  499. meta_nstreams : int;
  500. (* number of streams *)
  501. meta_strings_stream : clr_stream_header;
  502. (* #Strings: a string heap containing the names of metadata items *)
  503. meta_blob_stream : clr_stream_header;
  504. (* #Blob: blob heap containing internal metadata binary object, such as default values, signatures, etc *)
  505. meta_guid_stream : clr_stream_header;
  506. (* #GUID: a GUID heap *)
  507. meta_us_stream : clr_stream_header;
  508. (* #US: user-defined strings *)
  509. meta_meta_stream : clr_stream_header;
  510. (* may be either: *)
  511. (* #~: compressed (optimized) metadata stream *)
  512. (* #-: uncompressed (unoptimized) metadata stream *)
  513. meta_streams : clr_stream_header list;
  514. (* custom streams *)
  515. }