2
0

peData.ml 22 KB

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