1b55d4692Sfgsch /* pe.h - PE COFF header information 22159047fSniklas 3007c2a45Smiod Copyright 2000, 2001, 2003 Free Software Foundation, Inc. 4b55d4692Sfgsch 5b55d4692Sfgsch This file is part of BFD, the Binary File Descriptor library. 6b55d4692Sfgsch 7b55d4692Sfgsch This program is free software; you can redistribute it and/or modify 8b55d4692Sfgsch it under the terms of the GNU General Public License as published by 9b55d4692Sfgsch the Free Software Foundation; either version 2 of the License, or 10b55d4692Sfgsch (at your option) any later version. 11b55d4692Sfgsch 12b55d4692Sfgsch This program is distributed in the hope that it will be useful, 13b55d4692Sfgsch but WITHOUT ANY WARRANTY; without even the implied warranty of 14b55d4692Sfgsch MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15b55d4692Sfgsch GNU General Public License for more details. 16b55d4692Sfgsch 17b55d4692Sfgsch You should have received a copy of the GNU General Public License 18b55d4692Sfgsch along with this program; if not, write to the Free Software Foundation, 19b55d4692Sfgsch Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 202159047fSniklas #ifndef _PE_H 212159047fSniklas #define _PE_H 222159047fSniklas 23b305b0f1Sespie /* NT specific file attributes. */ 242159047fSniklas #define IMAGE_FILE_RELOCS_STRIPPED 0x0001 252159047fSniklas #define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002 262159047fSniklas #define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004 272159047fSniklas #define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008 28b305b0f1Sespie #define IMAGE_FILE_AGGRESSIVE_WS_TRIM 0x0010 29b305b0f1Sespie #define IMAGE_FILE_LARGE_ADDRESS_AWARE 0x0020 30b305b0f1Sespie #define IMAGE_FILE_16BIT_MACHINE 0x0040 312159047fSniklas #define IMAGE_FILE_BYTES_REVERSED_LO 0x0080 322159047fSniklas #define IMAGE_FILE_32BIT_MACHINE 0x0100 332159047fSniklas #define IMAGE_FILE_DEBUG_STRIPPED 0x0200 34b305b0f1Sespie #define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400 35007c2a45Smiod #define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800 362159047fSniklas #define IMAGE_FILE_SYSTEM 0x1000 372159047fSniklas #define IMAGE_FILE_DLL 0x2000 38b305b0f1Sespie #define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000 392159047fSniklas #define IMAGE_FILE_BYTES_REVERSED_HI 0x8000 402159047fSniklas 41b305b0f1Sespie /* Additional flags to be set for section headers to allow the NT loader to 422159047fSniklas read and write to the section data (to replace the addresses of data in 43b305b0f1Sespie dlls for one thing); also to execute the section in .text's case. */ 442159047fSniklas #define IMAGE_SCN_MEM_DISCARDABLE 0x02000000 452159047fSniklas #define IMAGE_SCN_MEM_EXECUTE 0x20000000 462159047fSniklas #define IMAGE_SCN_MEM_READ 0x40000000 472159047fSniklas #define IMAGE_SCN_MEM_WRITE 0x80000000 482159047fSniklas 49b305b0f1Sespie /* Section characteristics added for ppc-nt. */ 502159047fSniklas 512159047fSniklas #define IMAGE_SCN_TYPE_NO_PAD 0x00000008 /* Reserved. */ 522159047fSniklas 532159047fSniklas #define IMAGE_SCN_CNT_CODE 0x00000020 /* Section contains code. */ 542159047fSniklas #define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 /* Section contains initialized data. */ 552159047fSniklas #define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 /* Section contains uninitialized data. */ 562159047fSniklas 572159047fSniklas #define IMAGE_SCN_LNK_OTHER 0x00000100 /* Reserved. */ 582159047fSniklas #define IMAGE_SCN_LNK_INFO 0x00000200 /* Section contains comments or some other type of information. */ 592159047fSniklas #define IMAGE_SCN_LNK_REMOVE 0x00000800 /* Section contents will not become part of image. */ 602159047fSniklas #define IMAGE_SCN_LNK_COMDAT 0x00001000 /* Section contents comdat. */ 612159047fSniklas 622159047fSniklas #define IMAGE_SCN_MEM_FARDATA 0x00008000 632159047fSniklas 642159047fSniklas #define IMAGE_SCN_MEM_PURGEABLE 0x00020000 652159047fSniklas #define IMAGE_SCN_MEM_16BIT 0x00020000 662159047fSniklas #define IMAGE_SCN_MEM_LOCKED 0x00040000 672159047fSniklas #define IMAGE_SCN_MEM_PRELOAD 0x00080000 682159047fSniklas 692159047fSniklas #define IMAGE_SCN_ALIGN_1BYTES 0x00100000 702159047fSniklas #define IMAGE_SCN_ALIGN_2BYTES 0x00200000 712159047fSniklas #define IMAGE_SCN_ALIGN_4BYTES 0x00300000 722159047fSniklas #define IMAGE_SCN_ALIGN_8BYTES 0x00400000 732159047fSniklas #define IMAGE_SCN_ALIGN_16BYTES 0x00500000 /* Default alignment if no others are specified. */ 742159047fSniklas #define IMAGE_SCN_ALIGN_32BYTES 0x00600000 752159047fSniklas #define IMAGE_SCN_ALIGN_64BYTES 0x00700000 762159047fSniklas 772159047fSniklas #define IMAGE_SCN_LNK_NRELOC_OVFL 0x01000000 /* Section contains extended relocations. */ 782159047fSniklas #define IMAGE_SCN_MEM_NOT_CACHED 0x04000000 /* Section is not cachable. */ 792159047fSniklas #define IMAGE_SCN_MEM_NOT_PAGED 0x08000000 /* Section is not pageable. */ 802159047fSniklas #define IMAGE_SCN_MEM_SHARED 0x10000000 /* Section is shareable. */ 812159047fSniklas 82c88b1d6cSniklas /* COMDAT selection codes. */ 83c88b1d6cSniklas 84c88b1d6cSniklas #define IMAGE_COMDAT_SELECT_NODUPLICATES (1) /* Warn if duplicates. */ 85c88b1d6cSniklas #define IMAGE_COMDAT_SELECT_ANY (2) /* No warning. */ 86c88b1d6cSniklas #define IMAGE_COMDAT_SELECT_SAME_SIZE (3) /* Warn if different size. */ 87c88b1d6cSniklas #define IMAGE_COMDAT_SELECT_EXACT_MATCH (4) /* Warn if different. */ 88c88b1d6cSniklas #define IMAGE_COMDAT_SELECT_ASSOCIATIVE (5) /* Base on other section. */ 892159047fSniklas 90b305b0f1Sespie /* Machine numbers. */ 91b305b0f1Sespie 92007c2a45Smiod #define IMAGE_FILE_MACHINE_UNKNOWN 0x0000 93007c2a45Smiod #define IMAGE_FILE_MACHINE_ALPHA 0x0184 94007c2a45Smiod #define IMAGE_FILE_MACHINE_ALPHA64 0x0284 95007c2a45Smiod #define IMAGE_FILE_MACHINE_AM33 0x01d3 96007c2a45Smiod #define IMAGE_FILE_MACHINE_AMD64 0x8664 97007c2a45Smiod #define IMAGE_FILE_MACHINE_ARM 0x01c0 98007c2a45Smiod #define IMAGE_FILE_MACHINE_AXP64 IMAGE_FILE_MACHINE_ALPHA64 99007c2a45Smiod #define IMAGE_FILE_MACHINE_CEE 0xc0ee 100007c2a45Smiod #define IMAGE_FILE_MACHINE_CEF 0x0cef 101007c2a45Smiod #define IMAGE_FILE_MACHINE_EBC 0x0ebc 102007c2a45Smiod #define IMAGE_FILE_MACHINE_I386 0x014c 103007c2a45Smiod #define IMAGE_FILE_MACHINE_IA64 0x0200 104007c2a45Smiod #define IMAGE_FILE_MACHINE_M32R 0x9041 105007c2a45Smiod #define IMAGE_FILE_MACHINE_M68K 0x0268 106007c2a45Smiod #define IMAGE_FILE_MACHINE_MIPS16 0x0266 107007c2a45Smiod #define IMAGE_FILE_MACHINE_MIPSFPU 0x0366 108007c2a45Smiod #define IMAGE_FILE_MACHINE_MIPSFPU16 0x0466 109007c2a45Smiod #define IMAGE_FILE_MACHINE_POWERPC 0x01f0 110007c2a45Smiod #define IMAGE_FILE_MACHINE_POWERPCFP 0x01f1 111007c2a45Smiod #define IMAGE_FILE_MACHINE_R10000 0x0168 112007c2a45Smiod #define IMAGE_FILE_MACHINE_R3000 0x0162 113007c2a45Smiod #define IMAGE_FILE_MACHINE_R4000 0x0166 114007c2a45Smiod #define IMAGE_FILE_MACHINE_SH3 0x01a2 115007c2a45Smiod #define IMAGE_FILE_MACHINE_SH3DSP 0x01a3 116007c2a45Smiod #define IMAGE_FILE_MACHINE_SH3E 0x01a4 117007c2a45Smiod #define IMAGE_FILE_MACHINE_SH4 0x01a6 118007c2a45Smiod #define IMAGE_FILE_MACHINE_SH5 0x01a8 119007c2a45Smiod #define IMAGE_FILE_MACHINE_THUMB 0x01c2 120007c2a45Smiod #define IMAGE_FILE_MACHINE_TRICORE 0x0520 121007c2a45Smiod #define IMAGE_FILE_MACHINE_WCEMIPSV2 0x0169 122b305b0f1Sespie 123b55d4692Sfgsch #define IMAGE_SUBSYSTEM_UNKNOWN 0 124b55d4692Sfgsch #define IMAGE_SUBSYSTEM_NATIVE 1 125b55d4692Sfgsch #define IMAGE_SUBSYSTEM_WINDOWS_GUI 2 126b55d4692Sfgsch #define IMAGE_SUBSYSTEM_WINDOWS_CUI 3 127b55d4692Sfgsch #define IMAGE_SUBSYSTEM_POSIX_CUI 7 128b55d4692Sfgsch #define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI 9 129b55d4692Sfgsch #define IMAGE_SUBSYSTEM_EFI_APPLICATION 10 130b55d4692Sfgsch #define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11 131b55d4692Sfgsch #define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12 132b55d4692Sfgsch 133b55d4692Sfgsch /* Magic values that are true for all dos/nt implementations. */ 1342159047fSniklas #define DOSMAGIC 0x5a4d 1352159047fSniklas #define NT_SIGNATURE 0x00004550 1362159047fSniklas 137b55d4692Sfgsch /* NT allows long filenames, we want to accommodate this. 138b55d4692Sfgsch This may break some of the bfd functions. */ 1392159047fSniklas #undef FILNMLEN 140b55d4692Sfgsch #define FILNMLEN 18 /* # characters in a file name. */ 141b55d4692Sfgsch 142b55d4692Sfgsch struct external_PEI_DOS_hdr 143b55d4692Sfgsch { 144b55d4692Sfgsch /* DOS header fields - always at offset zero in the EXE file. */ 145b55d4692Sfgsch char e_magic[2]; /* Magic number, 0x5a4d. */ 146b55d4692Sfgsch char e_cblp[2]; /* Bytes on last page of file, 0x90. */ 147b55d4692Sfgsch char e_cp[2]; /* Pages in file, 0x3. */ 148b55d4692Sfgsch char e_crlc[2]; /* Relocations, 0x0. */ 149b55d4692Sfgsch char e_cparhdr[2]; /* Size of header in paragraphs, 0x4. */ 150b55d4692Sfgsch char e_minalloc[2]; /* Minimum extra paragraphs needed, 0x0. */ 151b55d4692Sfgsch char e_maxalloc[2]; /* Maximum extra paragraphs needed, 0xFFFF. */ 152b55d4692Sfgsch char e_ss[2]; /* Initial (relative) SS value, 0x0. */ 153b55d4692Sfgsch char e_sp[2]; /* Initial SP value, 0xb8. */ 154b55d4692Sfgsch char e_csum[2]; /* Checksum, 0x0. */ 155b55d4692Sfgsch char e_ip[2]; /* Initial IP value, 0x0. */ 156b55d4692Sfgsch char e_cs[2]; /* Initial (relative) CS value, 0x0. */ 157b55d4692Sfgsch char e_lfarlc[2]; /* File address of relocation table, 0x40. */ 158b55d4692Sfgsch char e_ovno[2]; /* Overlay number, 0x0. */ 159b55d4692Sfgsch char e_res[4][2]; /* Reserved words, all 0x0. */ 160b55d4692Sfgsch char e_oemid[2]; /* OEM identifier (for e_oeminfo), 0x0. */ 161b55d4692Sfgsch char e_oeminfo[2]; /* OEM information; e_oemid specific, 0x0. */ 162b55d4692Sfgsch char e_res2[10][2]; /* Reserved words, all 0x0. */ 163b55d4692Sfgsch char e_lfanew[4]; /* File address of new exe header, usually 0x80. */ 164b55d4692Sfgsch char dos_message[16][4]; /* Other stuff, always follow DOS header. */ 165b55d4692Sfgsch }; 166b55d4692Sfgsch 167b55d4692Sfgsch struct external_PEI_IMAGE_hdr 168b55d4692Sfgsch { 169b55d4692Sfgsch char nt_signature[4]; /* required NT signature, 0x4550. */ 170b55d4692Sfgsch 171b55d4692Sfgsch /* From standard header. */ 172b55d4692Sfgsch char f_magic[2]; /* Magic number. */ 173b55d4692Sfgsch char f_nscns[2]; /* Number of sections. */ 174b55d4692Sfgsch char f_timdat[4]; /* Time & date stamp. */ 175b55d4692Sfgsch char f_symptr[4]; /* File pointer to symtab. */ 176b55d4692Sfgsch char f_nsyms[4]; /* Number of symtab entries. */ 177b55d4692Sfgsch char f_opthdr[2]; /* Sizeof(optional hdr). */ 178b55d4692Sfgsch char f_flags[2]; /* Flags. */ 179b55d4692Sfgsch }; 1802159047fSniklas 181b305b0f1Sespie struct external_PEI_filehdr 1822159047fSniklas { 183b55d4692Sfgsch /* DOS header fields - always at offset zero in the EXE file. */ 184b55d4692Sfgsch char e_magic[2]; /* Magic number, 0x5a4d. */ 185b55d4692Sfgsch char e_cblp[2]; /* Bytes on last page of file, 0x90. */ 186b55d4692Sfgsch char e_cp[2]; /* Pages in file, 0x3. */ 187b55d4692Sfgsch char e_crlc[2]; /* Relocations, 0x0. */ 188b55d4692Sfgsch char e_cparhdr[2]; /* Size of header in paragraphs, 0x4. */ 189b55d4692Sfgsch char e_minalloc[2]; /* Minimum extra paragraphs needed, 0x0. */ 190b55d4692Sfgsch char e_maxalloc[2]; /* Maximum extra paragraphs needed, 0xFFFF. */ 191b55d4692Sfgsch char e_ss[2]; /* Initial (relative) SS value, 0x0. */ 192b55d4692Sfgsch char e_sp[2]; /* Initial SP value, 0xb8. */ 193b55d4692Sfgsch char e_csum[2]; /* Checksum, 0x0. */ 194b55d4692Sfgsch char e_ip[2]; /* Initial IP value, 0x0. */ 195b55d4692Sfgsch char e_cs[2]; /* Initial (relative) CS value, 0x0. */ 196b55d4692Sfgsch char e_lfarlc[2]; /* File address of relocation table, 0x40. */ 197b55d4692Sfgsch char e_ovno[2]; /* Overlay number, 0x0. */ 198b55d4692Sfgsch char e_res[4][2]; /* Reserved words, all 0x0. */ 199b55d4692Sfgsch char e_oemid[2]; /* OEM identifier (for e_oeminfo), 0x0. */ 200b55d4692Sfgsch char e_oeminfo[2]; /* OEM information; e_oemid specific, 0x0. */ 201b55d4692Sfgsch char e_res2[10][2]; /* Reserved words, all 0x0. */ 202b55d4692Sfgsch char e_lfanew[4]; /* File address of new exe header, usually 0x80. */ 203b55d4692Sfgsch char dos_message[16][4]; /* Other stuff, always follow DOS header. */ 2042159047fSniklas 205b55d4692Sfgsch /* Note: additional bytes may be inserted before the signature. Use 206b55d4692Sfgsch the e_lfanew field to find the actual location of the NT signature. */ 2072159047fSniklas 208b55d4692Sfgsch char nt_signature[4]; /* required NT signature, 0x4550. */ 2092159047fSniklas 210b55d4692Sfgsch /* From standard header. */ 211b55d4692Sfgsch char f_magic[2]; /* Magic number. */ 212b55d4692Sfgsch char f_nscns[2]; /* Number of sections. */ 213b55d4692Sfgsch char f_timdat[4]; /* Time & date stamp. */ 214b55d4692Sfgsch char f_symptr[4]; /* File pointer to symtab. */ 215b55d4692Sfgsch char f_nsyms[4]; /* Number of symtab entries. */ 216b55d4692Sfgsch char f_opthdr[2]; /* Sizeof(optional hdr). */ 217b55d4692Sfgsch char f_flags[2]; /* Flags. */ 2182159047fSniklas }; 2192159047fSniklas 220b305b0f1Sespie #ifdef COFF_IMAGE_WITH_PE 2212159047fSniklas 222b305b0f1Sespie /* The filehdr is only weird in images. */ 223b305b0f1Sespie 224b305b0f1Sespie #undef FILHDR 225b305b0f1Sespie #define FILHDR struct external_PEI_filehdr 2260c6d0228Sniklas #undef FILHSZ 2270c6d0228Sniklas #define FILHSZ 152 2282159047fSniklas 229b305b0f1Sespie #endif /* COFF_IMAGE_WITH_PE */ 2302159047fSniklas 231b55d4692Sfgsch /* 32-bit PE a.out header: */ 232b55d4692Sfgsch 2332159047fSniklas typedef struct 2342159047fSniklas { 2352159047fSniklas AOUTHDR standard; 2362159047fSniklas 237b55d4692Sfgsch /* NT extra fields; see internal.h for descriptions. */ 2382159047fSniklas char ImageBase[4]; 2392159047fSniklas char SectionAlignment[4]; 2402159047fSniklas char FileAlignment[4]; 2412159047fSniklas char MajorOperatingSystemVersion[2]; 2422159047fSniklas char MinorOperatingSystemVersion[2]; 2432159047fSniklas char MajorImageVersion[2]; 2442159047fSniklas char MinorImageVersion[2]; 2452159047fSniklas char MajorSubsystemVersion[2]; 2462159047fSniklas char MinorSubsystemVersion[2]; 2472159047fSniklas char Reserved1[4]; 2482159047fSniklas char SizeOfImage[4]; 2492159047fSniklas char SizeOfHeaders[4]; 2502159047fSniklas char CheckSum[4]; 2512159047fSniklas char Subsystem[2]; 2522159047fSniklas char DllCharacteristics[2]; 2532159047fSniklas char SizeOfStackReserve[4]; 2542159047fSniklas char SizeOfStackCommit[4]; 2552159047fSniklas char SizeOfHeapReserve[4]; 2562159047fSniklas char SizeOfHeapCommit[4]; 2572159047fSniklas char LoaderFlags[4]; 2582159047fSniklas char NumberOfRvaAndSizes[4]; 2592159047fSniklas /* IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; */ 260b55d4692Sfgsch char DataDirectory[16][2][4]; /* 16 entries, 2 elements/entry, 4 chars. */ 2612159047fSniklas } PEAOUTHDR; 2622159047fSniklas #undef AOUTSZ 2630c6d0228Sniklas #define AOUTSZ (AOUTHDRSZ + 196) 2642159047fSniklas 265b55d4692Sfgsch /* Like PEAOUTHDR, except that the "standard" member has no BaseOfData 266b55d4692Sfgsch (aka data_start) member and that some of the members are 8 instead 267b55d4692Sfgsch of just 4 bytes long. */ 268b55d4692Sfgsch typedef struct 269b55d4692Sfgsch { 270*272a140bSkettenis #ifdef AOUTHDRSZ64 271*272a140bSkettenis AOUTHDR64 standard; 272*272a140bSkettenis #else 273b55d4692Sfgsch AOUTHDR standard; 274*272a140bSkettenis #endif 275b55d4692Sfgsch /* NT extra fields; see internal.h for descriptions. */ 276b55d4692Sfgsch char ImageBase[8]; 277b55d4692Sfgsch char SectionAlignment[4]; 278b55d4692Sfgsch char FileAlignment[4]; 279b55d4692Sfgsch char MajorOperatingSystemVersion[2]; 280b55d4692Sfgsch char MinorOperatingSystemVersion[2]; 281b55d4692Sfgsch char MajorImageVersion[2]; 282b55d4692Sfgsch char MinorImageVersion[2]; 283b55d4692Sfgsch char MajorSubsystemVersion[2]; 284b55d4692Sfgsch char MinorSubsystemVersion[2]; 285b55d4692Sfgsch char Reserved1[4]; 286b55d4692Sfgsch char SizeOfImage[4]; 287b55d4692Sfgsch char SizeOfHeaders[4]; 288b55d4692Sfgsch char CheckSum[4]; 289b55d4692Sfgsch char Subsystem[2]; 290b55d4692Sfgsch char DllCharacteristics[2]; 291b55d4692Sfgsch char SizeOfStackReserve[8]; 292b55d4692Sfgsch char SizeOfStackCommit[8]; 293b55d4692Sfgsch char SizeOfHeapReserve[8]; 294b55d4692Sfgsch char SizeOfHeapCommit[8]; 295b55d4692Sfgsch char LoaderFlags[4]; 296b55d4692Sfgsch char NumberOfRvaAndSizes[4]; 297b55d4692Sfgsch /* IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; */ 298b55d4692Sfgsch char DataDirectory[16][2][4]; /* 16 entries, 2 elements/entry, 4 chars. */ 299b55d4692Sfgsch } PEPAOUTHDR; 300*272a140bSkettenis 301*272a140bSkettenis #ifdef AOUTHDRSZ64 302*272a140bSkettenis #define PEPAOUTSZ (AOUTHDRSZ64 + 196 + 5 * 4) /* = 240 */ 303*272a140bSkettenis #else 304b55d4692Sfgsch #define PEPAOUTSZ 240 305*272a140bSkettenis #endif 306b55d4692Sfgsch 3072159047fSniklas #undef E_FILNMLEN 308b55d4692Sfgsch #define E_FILNMLEN 18 /* # characters in a file name. */ 3092159047fSniklas 310b305b0f1Sespie /* Import Tyoes fot ILF format object files.. */ 311b305b0f1Sespie #define IMPORT_CODE 0 312b305b0f1Sespie #define IMPORT_DATA 1 313b305b0f1Sespie #define IMPORT_CONST 2 3142159047fSniklas 315b305b0f1Sespie /* Import Name Tyoes for ILF format object files. */ 316b305b0f1Sespie #define IMPORT_ORDINAL 0 317b305b0f1Sespie #define IMPORT_NAME 1 318b305b0f1Sespie #define IMPORT_NAME_NOPREFIX 2 319b305b0f1Sespie #define IMPORT_NAME_UNDECORATE 3 3202159047fSniklas 321b305b0f1Sespie #endif /* _PE_H */ 322