Commit | Line | Data |
---|---|---|
d155c6ea | 1 | /* pe.h - PE COFF header information |
252b5132 | 2 | |
99ad8390 | 3 | Copyright 1999, 2000, 2001, 2003, 2004, 2006 Free Software Foundation, Inc. |
d155c6ea NC |
4 | |
5 | This file is part of BFD, the Binary File Descriptor library. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software Foundation, | |
e172dbf8 | 19 | Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ |
252b5132 RH |
20 | #ifndef _PE_H |
21 | #define _PE_H | |
22 | ||
cbaede9c | 23 | /* NT specific file attributes. */ |
252b5132 RH |
24 | #define IMAGE_FILE_RELOCS_STRIPPED 0x0001 |
25 | #define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002 | |
26 | #define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004 | |
27 | #define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008 | |
cbaede9c NC |
28 | #define IMAGE_FILE_AGGRESSIVE_WS_TRIM 0x0010 |
29 | #define IMAGE_FILE_LARGE_ADDRESS_AWARE 0x0020 | |
30 | #define IMAGE_FILE_16BIT_MACHINE 0x0040 | |
252b5132 RH |
31 | #define IMAGE_FILE_BYTES_REVERSED_LO 0x0080 |
32 | #define IMAGE_FILE_32BIT_MACHINE 0x0100 | |
33 | #define IMAGE_FILE_DEBUG_STRIPPED 0x0200 | |
cbaede9c | 34 | #define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400 |
93e49a47 | 35 | #define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800 |
252b5132 RH |
36 | #define IMAGE_FILE_SYSTEM 0x1000 |
37 | #define IMAGE_FILE_DLL 0x2000 | |
cbaede9c | 38 | #define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000 |
252b5132 RH |
39 | #define IMAGE_FILE_BYTES_REVERSED_HI 0x8000 |
40 | ||
cbaede9c | 41 | /* Additional flags to be set for section headers to allow the NT loader to |
252b5132 | 42 | read and write to the section data (to replace the addresses of data in |
cbaede9c | 43 | dlls for one thing); also to execute the section in .text's case. */ |
252b5132 RH |
44 | #define IMAGE_SCN_MEM_DISCARDABLE 0x02000000 |
45 | #define IMAGE_SCN_MEM_EXECUTE 0x20000000 | |
46 | #define IMAGE_SCN_MEM_READ 0x40000000 | |
47 | #define IMAGE_SCN_MEM_WRITE 0x80000000 | |
48 | ||
cbaede9c | 49 | /* Section characteristics added for ppc-nt. */ |
252b5132 RH |
50 | |
51 | #define IMAGE_SCN_TYPE_NO_PAD 0x00000008 /* Reserved. */ | |
52 | ||
53 | #define IMAGE_SCN_CNT_CODE 0x00000020 /* Section contains code. */ | |
54 | #define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 /* Section contains initialized data. */ | |
55 | #define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 /* Section contains uninitialized data. */ | |
56 | ||
57 | #define IMAGE_SCN_LNK_OTHER 0x00000100 /* Reserved. */ | |
58 | #define IMAGE_SCN_LNK_INFO 0x00000200 /* Section contains comments or some other type of information. */ | |
59 | #define IMAGE_SCN_LNK_REMOVE 0x00000800 /* Section contents will not become part of image. */ | |
60 | #define IMAGE_SCN_LNK_COMDAT 0x00001000 /* Section contents comdat. */ | |
61 | ||
62 | #define IMAGE_SCN_MEM_FARDATA 0x00008000 | |
63 | ||
64 | #define IMAGE_SCN_MEM_PURGEABLE 0x00020000 | |
65 | #define IMAGE_SCN_MEM_16BIT 0x00020000 | |
66 | #define IMAGE_SCN_MEM_LOCKED 0x00040000 | |
67 | #define IMAGE_SCN_MEM_PRELOAD 0x00080000 | |
68 | ||
69 | #define IMAGE_SCN_ALIGN_1BYTES 0x00100000 | |
70 | #define IMAGE_SCN_ALIGN_2BYTES 0x00200000 | |
71 | #define IMAGE_SCN_ALIGN_4BYTES 0x00300000 | |
72 | #define IMAGE_SCN_ALIGN_8BYTES 0x00400000 | |
73 | #define IMAGE_SCN_ALIGN_16BYTES 0x00500000 /* Default alignment if no others are specified. */ | |
74 | #define IMAGE_SCN_ALIGN_32BYTES 0x00600000 | |
75 | #define IMAGE_SCN_ALIGN_64BYTES 0x00700000 | |
76 | ||
252b5132 RH |
77 | #define IMAGE_SCN_LNK_NRELOC_OVFL 0x01000000 /* Section contains extended relocations. */ |
78 | #define IMAGE_SCN_MEM_NOT_CACHED 0x04000000 /* Section is not cachable. */ | |
79 | #define IMAGE_SCN_MEM_NOT_PAGED 0x08000000 /* Section is not pageable. */ | |
80 | #define IMAGE_SCN_MEM_SHARED 0x10000000 /* Section is shareable. */ | |
81 | ||
82 | /* COMDAT selection codes. */ | |
83 | ||
84 | #define IMAGE_COMDAT_SELECT_NODUPLICATES (1) /* Warn if duplicates. */ | |
85 | #define IMAGE_COMDAT_SELECT_ANY (2) /* No warning. */ | |
86 | #define IMAGE_COMDAT_SELECT_SAME_SIZE (3) /* Warn if different size. */ | |
87 | #define IMAGE_COMDAT_SELECT_EXACT_MATCH (4) /* Warn if different. */ | |
88 | #define IMAGE_COMDAT_SELECT_ASSOCIATIVE (5) /* Base on other section. */ | |
89 | ||
cbaede9c NC |
90 | /* Machine numbers. */ |
91 | ||
93e49a47 NC |
92 | #define IMAGE_FILE_MACHINE_UNKNOWN 0x0000 |
93 | #define IMAGE_FILE_MACHINE_ALPHA 0x0184 | |
94 | #define IMAGE_FILE_MACHINE_ALPHA64 0x0284 | |
95 | #define IMAGE_FILE_MACHINE_AM33 0x01d3 | |
96 | #define IMAGE_FILE_MACHINE_AMD64 0x8664 | |
97 | #define IMAGE_FILE_MACHINE_ARM 0x01c0 | |
98 | #define IMAGE_FILE_MACHINE_AXP64 IMAGE_FILE_MACHINE_ALPHA64 | |
99 | #define IMAGE_FILE_MACHINE_CEE 0xc0ee | |
100 | #define IMAGE_FILE_MACHINE_CEF 0x0cef | |
101 | #define IMAGE_FILE_MACHINE_EBC 0x0ebc | |
102 | #define IMAGE_FILE_MACHINE_I386 0x014c | |
103 | #define IMAGE_FILE_MACHINE_IA64 0x0200 | |
104 | #define IMAGE_FILE_MACHINE_M32R 0x9041 | |
105 | #define IMAGE_FILE_MACHINE_M68K 0x0268 | |
106 | #define IMAGE_FILE_MACHINE_MIPS16 0x0266 | |
107 | #define IMAGE_FILE_MACHINE_MIPSFPU 0x0366 | |
108 | #define IMAGE_FILE_MACHINE_MIPSFPU16 0x0466 | |
109 | #define IMAGE_FILE_MACHINE_POWERPC 0x01f0 | |
110 | #define IMAGE_FILE_MACHINE_POWERPCFP 0x01f1 | |
111 | #define IMAGE_FILE_MACHINE_R10000 0x0168 | |
112 | #define IMAGE_FILE_MACHINE_R3000 0x0162 | |
113 | #define IMAGE_FILE_MACHINE_R4000 0x0166 | |
114 | #define IMAGE_FILE_MACHINE_SH3 0x01a2 | |
115 | #define IMAGE_FILE_MACHINE_SH3DSP 0x01a3 | |
116 | #define IMAGE_FILE_MACHINE_SH3E 0x01a4 | |
117 | #define IMAGE_FILE_MACHINE_SH4 0x01a6 | |
118 | #define IMAGE_FILE_MACHINE_SH5 0x01a8 | |
119 | #define IMAGE_FILE_MACHINE_THUMB 0x01c2 | |
120 | #define IMAGE_FILE_MACHINE_TRICORE 0x0520 | |
121 | #define IMAGE_FILE_MACHINE_WCEMIPSV2 0x0169 | |
99ad8390 | 122 | #define IMAGE_FILE_MACHINE_AMD64 0x8664 |
93e49a47 | 123 | |
63fa1674 JW |
124 | #define IMAGE_SUBSYSTEM_UNKNOWN 0 |
125 | #define IMAGE_SUBSYSTEM_NATIVE 1 | |
126 | #define IMAGE_SUBSYSTEM_WINDOWS_GUI 2 | |
127 | #define IMAGE_SUBSYSTEM_WINDOWS_CUI 3 | |
128 | #define IMAGE_SUBSYSTEM_POSIX_CUI 7 | |
129 | #define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI 9 | |
130 | #define IMAGE_SUBSYSTEM_EFI_APPLICATION 10 | |
131 | #define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11 | |
132 | #define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12 | |
6c73cbb1 NC |
133 | #define IMAGE_SUBSYSTEM_EFI_ROM 13 |
134 | #define IMAGE_SUBSYSTEM_XBOX 14 | |
63fa1674 | 135 | |
d155c6ea | 136 | /* Magic values that are true for all dos/nt implementations. */ |
252b5132 RH |
137 | #define DOSMAGIC 0x5a4d |
138 | #define NT_SIGNATURE 0x00004550 | |
139 | ||
d155c6ea NC |
140 | /* NT allows long filenames, we want to accommodate this. |
141 | This may break some of the bfd functions. */ | |
252b5132 | 142 | #undef FILNMLEN |
d155c6ea | 143 | #define FILNMLEN 18 /* # characters in a file name. */ |
252b5132 | 144 | |
98536290 L |
145 | struct external_PEI_DOS_hdr |
146 | { | |
147 | /* DOS header fields - always at offset zero in the EXE file. */ | |
148 | char e_magic[2]; /* Magic number, 0x5a4d. */ | |
149 | char e_cblp[2]; /* Bytes on last page of file, 0x90. */ | |
150 | char e_cp[2]; /* Pages in file, 0x3. */ | |
151 | char e_crlc[2]; /* Relocations, 0x0. */ | |
152 | char e_cparhdr[2]; /* Size of header in paragraphs, 0x4. */ | |
153 | char e_minalloc[2]; /* Minimum extra paragraphs needed, 0x0. */ | |
154 | char e_maxalloc[2]; /* Maximum extra paragraphs needed, 0xFFFF. */ | |
155 | char e_ss[2]; /* Initial (relative) SS value, 0x0. */ | |
156 | char e_sp[2]; /* Initial SP value, 0xb8. */ | |
157 | char e_csum[2]; /* Checksum, 0x0. */ | |
158 | char e_ip[2]; /* Initial IP value, 0x0. */ | |
159 | char e_cs[2]; /* Initial (relative) CS value, 0x0. */ | |
160 | char e_lfarlc[2]; /* File address of relocation table, 0x40. */ | |
161 | char e_ovno[2]; /* Overlay number, 0x0. */ | |
162 | char e_res[4][2]; /* Reserved words, all 0x0. */ | |
163 | char e_oemid[2]; /* OEM identifier (for e_oeminfo), 0x0. */ | |
164 | char e_oeminfo[2]; /* OEM information; e_oemid specific, 0x0. */ | |
165 | char e_res2[10][2]; /* Reserved words, all 0x0. */ | |
166 | char e_lfanew[4]; /* File address of new exe header, usually 0x80. */ | |
167 | char dos_message[16][4]; /* Other stuff, always follow DOS header. */ | |
168 | }; | |
169 | ||
170 | struct external_PEI_IMAGE_hdr | |
171 | { | |
172 | char nt_signature[4]; /* required NT signature, 0x4550. */ | |
173 | ||
174 | /* From standard header. */ | |
175 | char f_magic[2]; /* Magic number. */ | |
176 | char f_nscns[2]; /* Number of sections. */ | |
177 | char f_timdat[4]; /* Time & date stamp. */ | |
178 | char f_symptr[4]; /* File pointer to symtab. */ | |
179 | char f_nsyms[4]; /* Number of symtab entries. */ | |
180 | char f_opthdr[2]; /* Sizeof(optional hdr). */ | |
181 | char f_flags[2]; /* Flags. */ | |
182 | }; | |
183 | ||
25bcc51d | 184 | struct external_PEI_filehdr |
252b5132 | 185 | { |
d155c6ea NC |
186 | /* DOS header fields - always at offset zero in the EXE file. */ |
187 | char e_magic[2]; /* Magic number, 0x5a4d. */ | |
188 | char e_cblp[2]; /* Bytes on last page of file, 0x90. */ | |
189 | char e_cp[2]; /* Pages in file, 0x3. */ | |
190 | char e_crlc[2]; /* Relocations, 0x0. */ | |
191 | char e_cparhdr[2]; /* Size of header in paragraphs, 0x4. */ | |
192 | char e_minalloc[2]; /* Minimum extra paragraphs needed, 0x0. */ | |
193 | char e_maxalloc[2]; /* Maximum extra paragraphs needed, 0xFFFF. */ | |
194 | char e_ss[2]; /* Initial (relative) SS value, 0x0. */ | |
195 | char e_sp[2]; /* Initial SP value, 0xb8. */ | |
196 | char e_csum[2]; /* Checksum, 0x0. */ | |
197 | char e_ip[2]; /* Initial IP value, 0x0. */ | |
198 | char e_cs[2]; /* Initial (relative) CS value, 0x0. */ | |
199 | char e_lfarlc[2]; /* File address of relocation table, 0x40. */ | |
200 | char e_ovno[2]; /* Overlay number, 0x0. */ | |
201 | char e_res[4][2]; /* Reserved words, all 0x0. */ | |
202 | char e_oemid[2]; /* OEM identifier (for e_oeminfo), 0x0. */ | |
203 | char e_oeminfo[2]; /* OEM information; e_oemid specific, 0x0. */ | |
204 | char e_res2[10][2]; /* Reserved words, all 0x0. */ | |
205 | char e_lfanew[4]; /* File address of new exe header, usually 0x80. */ | |
206 | char dos_message[16][4]; /* Other stuff, always follow DOS header. */ | |
c689311b DD |
207 | |
208 | /* Note: additional bytes may be inserted before the signature. Use | |
d155c6ea NC |
209 | the e_lfanew field to find the actual location of the NT signature. */ |
210 | ||
211 | char nt_signature[4]; /* required NT signature, 0x4550. */ | |
212 | ||
213 | /* From standard header. */ | |
214 | char f_magic[2]; /* Magic number. */ | |
215 | char f_nscns[2]; /* Number of sections. */ | |
216 | char f_timdat[4]; /* Time & date stamp. */ | |
217 | char f_symptr[4]; /* File pointer to symtab. */ | |
218 | char f_nsyms[4]; /* Number of symtab entries. */ | |
219 | char f_opthdr[2]; /* Sizeof(optional hdr). */ | |
220 | char f_flags[2]; /* Flags. */ | |
252b5132 RH |
221 | }; |
222 | ||
25bcc51d ILT |
223 | #ifdef COFF_IMAGE_WITH_PE |
224 | ||
cbaede9c | 225 | /* The filehdr is only weird in images. */ |
252b5132 | 226 | |
cbaede9c | 227 | #undef FILHDR |
25bcc51d | 228 | #define FILHDR struct external_PEI_filehdr |
cbaede9c | 229 | #undef FILHSZ |
252b5132 RH |
230 | #define FILHSZ 152 |
231 | ||
25bcc51d | 232 | #endif /* COFF_IMAGE_WITH_PE */ |
252b5132 | 233 | |
63fa1674 JW |
234 | /* 32-bit PE a.out header: */ |
235 | ||
252b5132 RH |
236 | typedef struct |
237 | { | |
238 | AOUTHDR standard; | |
239 | ||
d155c6ea | 240 | /* NT extra fields; see internal.h for descriptions. */ |
252b5132 RH |
241 | char ImageBase[4]; |
242 | char SectionAlignment[4]; | |
243 | char FileAlignment[4]; | |
244 | char MajorOperatingSystemVersion[2]; | |
245 | char MinorOperatingSystemVersion[2]; | |
246 | char MajorImageVersion[2]; | |
247 | char MinorImageVersion[2]; | |
248 | char MajorSubsystemVersion[2]; | |
249 | char MinorSubsystemVersion[2]; | |
250 | char Reserved1[4]; | |
251 | char SizeOfImage[4]; | |
252 | char SizeOfHeaders[4]; | |
253 | char CheckSum[4]; | |
254 | char Subsystem[2]; | |
255 | char DllCharacteristics[2]; | |
256 | char SizeOfStackReserve[4]; | |
257 | char SizeOfStackCommit[4]; | |
258 | char SizeOfHeapReserve[4]; | |
259 | char SizeOfHeapCommit[4]; | |
260 | char LoaderFlags[4]; | |
261 | char NumberOfRvaAndSizes[4]; | |
d155c6ea NC |
262 | /* IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; */ |
263 | char DataDirectory[16][2][4]; /* 16 entries, 2 elements/entry, 4 chars. */ | |
252b5132 | 264 | } PEAOUTHDR; |
99ad8390 | 265 | |
252b5132 RH |
266 | #undef AOUTSZ |
267 | #define AOUTSZ (AOUTHDRSZ + 196) | |
268 | ||
63fa1674 JW |
269 | /* Like PEAOUTHDR, except that the "standard" member has no BaseOfData |
270 | (aka data_start) member and that some of the members are 8 instead | |
271 | of just 4 bytes long. */ | |
272 | typedef struct | |
273 | { | |
99ad8390 NC |
274 | #ifdef AOUTHDRSZ64 |
275 | AOUTHDR64 standard; | |
276 | #else | |
63fa1674 | 277 | AOUTHDR standard; |
99ad8390 | 278 | #endif |
d155c6ea | 279 | /* NT extra fields; see internal.h for descriptions. */ |
63fa1674 JW |
280 | char ImageBase[8]; |
281 | char SectionAlignment[4]; | |
282 | char FileAlignment[4]; | |
283 | char MajorOperatingSystemVersion[2]; | |
284 | char MinorOperatingSystemVersion[2]; | |
285 | char MajorImageVersion[2]; | |
286 | char MinorImageVersion[2]; | |
287 | char MajorSubsystemVersion[2]; | |
288 | char MinorSubsystemVersion[2]; | |
289 | char Reserved1[4]; | |
290 | char SizeOfImage[4]; | |
291 | char SizeOfHeaders[4]; | |
292 | char CheckSum[4]; | |
293 | char Subsystem[2]; | |
294 | char DllCharacteristics[2]; | |
295 | char SizeOfStackReserve[8]; | |
296 | char SizeOfStackCommit[8]; | |
297 | char SizeOfHeapReserve[8]; | |
298 | char SizeOfHeapCommit[8]; | |
299 | char LoaderFlags[4]; | |
300 | char NumberOfRvaAndSizes[4]; | |
d155c6ea NC |
301 | /* IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; */ |
302 | char DataDirectory[16][2][4]; /* 16 entries, 2 elements/entry, 4 chars. */ | |
c9430732 | 303 | } PEPAOUTHDR; |
99ad8390 NC |
304 | |
305 | #ifdef AOUTHDRSZ64 | |
306 | #define PEPAOUTSZ (AOUTHDRSZ64 + 196 + 5 * 4) /* = 240 */ | |
307 | #else | |
c9430732 | 308 | #define PEPAOUTSZ 240 |
99ad8390 | 309 | #endif |
63fa1674 | 310 | |
252b5132 | 311 | #undef E_FILNMLEN |
d155c6ea | 312 | #define E_FILNMLEN 18 /* # characters in a file name. */ |
056350c6 NC |
313 | |
314 | /* Import Tyoes fot ILF format object files.. */ | |
315 | #define IMPORT_CODE 0 | |
316 | #define IMPORT_DATA 1 | |
317 | #define IMPORT_CONST 2 | |
318 | ||
319 | /* Import Name Tyoes for ILF format object files. */ | |
320 | #define IMPORT_ORDINAL 0 | |
321 | #define IMPORT_NAME 1 | |
322 | #define IMPORT_NAME_NOPREFIX 2 | |
323 | #define IMPORT_NAME_UNDECORATE 3 | |
324 | ||
977cdf5a NC |
325 | /* Weak external characteristics. */ |
326 | #define IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY 1 | |
327 | #define IMAGE_WEAK_EXTERN_SEARCH_LIBRARY 2 | |
328 | #define IMAGE_WEAK_EXTERN_SEARCH_ALIAS 3 | |
329 | ||
056350c6 | 330 | #endif /* _PE_H */ |