Rev 5191 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6324 | serge | 1 | /* pe.h - PE COFF header information |
5191 | serge | 2 | |
6324 | serge | 3 | Copyright (C) 1999-2015 Free Software Foundation, Inc. |
5191 | serge | 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 3 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, |
||
19 | Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ |
||
20 | #ifndef _PE_H |
||
21 | #define _PE_H |
||
22 | |||
23 | /* NT specific file attributes. */ |
||
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 |
||
28 | #define IMAGE_FILE_AGGRESSIVE_WS_TRIM 0x0010 |
||
29 | #define IMAGE_FILE_LARGE_ADDRESS_AWARE 0x0020 |
||
30 | #define IMAGE_FILE_16BIT_MACHINE 0x0040 |
||
31 | #define IMAGE_FILE_BYTES_REVERSED_LO 0x0080 |
||
32 | #define IMAGE_FILE_32BIT_MACHINE 0x0100 |
||
33 | #define IMAGE_FILE_DEBUG_STRIPPED 0x0200 |
||
34 | #define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400 |
||
35 | #define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800 |
||
36 | #define IMAGE_FILE_SYSTEM 0x1000 |
||
37 | #define IMAGE_FILE_DLL 0x2000 |
||
38 | #define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000 |
||
39 | #define IMAGE_FILE_BYTES_REVERSED_HI 0x8000 |
||
40 | |||
41 | /* DllCharacteristics flag bits. The inconsistent naming may seem |
||
42 | odd, but that is how they are defined in the PE specification. */ |
||
6324 | serge | 43 | #define IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA 0x0020 |
5191 | serge | 44 | #define IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE 0x0040 |
45 | #define IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY 0x0080 |
||
46 | #define IMAGE_DLL_CHARACTERISTICS_NX_COMPAT 0x0100 |
||
47 | #define IMAGE_DLLCHARACTERISTICS_NO_ISOLATION 0x0200 |
||
48 | #define IMAGE_DLLCHARACTERISTICS_NO_SEH 0x0400 |
||
49 | #define IMAGE_DLLCHARACTERISTICS_NO_BIND 0x0800 |
||
50 | #define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER 0x2000 |
||
51 | #define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE 0x8000 |
||
52 | |||
53 | /* Additional flags to be set for section headers to allow the NT loader to |
||
54 | read and write to the section data (to replace the addresses of data in |
||
55 | dlls for one thing); also to execute the section in .text's case. */ |
||
56 | #define IMAGE_SCN_MEM_DISCARDABLE 0x02000000 |
||
57 | #define IMAGE_SCN_MEM_EXECUTE 0x20000000 |
||
58 | #define IMAGE_SCN_MEM_READ 0x40000000 |
||
59 | #define IMAGE_SCN_MEM_WRITE 0x80000000 |
||
60 | |||
61 | /* Section characteristics added for ppc-nt. */ |
||
62 | |||
6324 | serge | 63 | #define IMAGE_SCN_TYPE_NO_PAD 0x00000008 /* Reserved. */ |
5191 | serge | 64 | |
6324 | serge | 65 | #define IMAGE_SCN_CNT_CODE 0x00000020 /* Section contains code. */ |
66 | #define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 /* Section contains initialized data. */ |
||
67 | #define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 /* Section contains uninitialized data. */ |
||
5191 | serge | 68 | |
6324 | serge | 69 | #define IMAGE_SCN_LNK_OTHER 0x00000100 /* Reserved. */ |
70 | #define IMAGE_SCN_LNK_INFO 0x00000200 /* Section contains comments or some other type of information. */ |
||
71 | #define IMAGE_SCN_LNK_REMOVE 0x00000800 /* Section contents will not become part of image. */ |
||
72 | #define IMAGE_SCN_LNK_COMDAT 0x00001000 /* Section contents comdat. */ |
||
5191 | serge | 73 | |
74 | #define IMAGE_SCN_MEM_FARDATA 0x00008000 |
||
75 | |||
76 | #define IMAGE_SCN_MEM_PURGEABLE 0x00020000 |
||
77 | #define IMAGE_SCN_MEM_16BIT 0x00020000 |
||
78 | #define IMAGE_SCN_MEM_LOCKED 0x00040000 |
||
79 | #define IMAGE_SCN_MEM_PRELOAD 0x00080000 |
||
80 | |||
6324 | serge | 81 | /* Bit position in the s_flags field where the alignment values start. */ |
5191 | serge | 82 | #define IMAGE_SCN_ALIGN_POWER_BIT_POS 20 |
83 | #define IMAGE_SCN_ALIGN_POWER_BIT_MASK 0x00f00000 |
||
84 | #define IMAGE_SCN_ALIGN_POWER_NUM(val) \ |
||
85 | (((val) >> IMAGE_SCN_ALIGN_POWER_BIT_POS) - 1) |
||
86 | #define IMAGE_SCN_ALIGN_POWER_CONST(val) \ |
||
87 | (((val) + 1) << IMAGE_SCN_ALIGN_POWER_BIT_POS) |
||
88 | |||
89 | #define IMAGE_SCN_ALIGN_1BYTES IMAGE_SCN_ALIGN_POWER_CONST (0) |
||
90 | #define IMAGE_SCN_ALIGN_2BYTES IMAGE_SCN_ALIGN_POWER_CONST (1) |
||
91 | #define IMAGE_SCN_ALIGN_4BYTES IMAGE_SCN_ALIGN_POWER_CONST (2) |
||
92 | #define IMAGE_SCN_ALIGN_8BYTES IMAGE_SCN_ALIGN_POWER_CONST (3) |
||
6324 | serge | 93 | /* Default alignment if no others are specified. */ |
5191 | serge | 94 | #define IMAGE_SCN_ALIGN_16BYTES IMAGE_SCN_ALIGN_POWER_CONST (4) |
95 | #define IMAGE_SCN_ALIGN_32BYTES IMAGE_SCN_ALIGN_POWER_CONST (5) |
||
96 | #define IMAGE_SCN_ALIGN_64BYTES IMAGE_SCN_ALIGN_POWER_CONST (6) |
||
97 | #define IMAGE_SCN_ALIGN_128BYTES IMAGE_SCN_ALIGN_POWER_CONST (7) |
||
98 | #define IMAGE_SCN_ALIGN_256BYTES IMAGE_SCN_ALIGN_POWER_CONST (8) |
||
99 | #define IMAGE_SCN_ALIGN_512BYTES IMAGE_SCN_ALIGN_POWER_CONST (9) |
||
100 | #define IMAGE_SCN_ALIGN_1024BYTES IMAGE_SCN_ALIGN_POWER_CONST (10) |
||
101 | #define IMAGE_SCN_ALIGN_2048BYTES IMAGE_SCN_ALIGN_POWER_CONST (11) |
||
102 | #define IMAGE_SCN_ALIGN_4096BYTES IMAGE_SCN_ALIGN_POWER_CONST (12) |
||
103 | #define IMAGE_SCN_ALIGN_8192BYTES IMAGE_SCN_ALIGN_POWER_CONST (13) |
||
104 | |||
6324 | serge | 105 | /* Encode alignment power into IMAGE_SCN_ALIGN bits of s_flags. */ |
5191 | serge | 106 | #define COFF_ENCODE_ALIGNMENT(SECTION, ALIGNMENT_POWER) \ |
107 | ((SECTION).s_flags |= IMAGE_SCN_ALIGN_POWER_CONST ((ALIGNMENT_POWER))) |
||
108 | |||
109 | #define IMAGE_SCN_LNK_NRELOC_OVFL 0x01000000 /* Section contains extended relocations. */ |
||
110 | #define IMAGE_SCN_MEM_NOT_CACHED 0x04000000 /* Section is not cachable. */ |
||
111 | #define IMAGE_SCN_MEM_NOT_PAGED 0x08000000 /* Section is not pageable. */ |
||
112 | #define IMAGE_SCN_MEM_SHARED 0x10000000 /* Section is shareable. */ |
||
113 | |||
114 | /* COMDAT selection codes. */ |
||
115 | |||
116 | #define IMAGE_COMDAT_SELECT_NODUPLICATES (1) /* Warn if duplicates. */ |
||
117 | #define IMAGE_COMDAT_SELECT_ANY (2) /* No warning. */ |
||
118 | #define IMAGE_COMDAT_SELECT_SAME_SIZE (3) /* Warn if different size. */ |
||
119 | #define IMAGE_COMDAT_SELECT_EXACT_MATCH (4) /* Warn if different. */ |
||
120 | #define IMAGE_COMDAT_SELECT_ASSOCIATIVE (5) /* Base on other section. */ |
||
121 | |||
122 | /* Machine numbers. */ |
||
123 | |||
124 | #define IMAGE_FILE_MACHINE_UNKNOWN 0x0000 |
||
125 | #define IMAGE_FILE_MACHINE_ALPHA 0x0184 |
||
126 | #define IMAGE_FILE_MACHINE_ALPHA64 0x0284 |
||
127 | #define IMAGE_FILE_MACHINE_AM33 0x01d3 |
||
128 | #define IMAGE_FILE_MACHINE_AMD64 0x8664 |
||
129 | #define IMAGE_FILE_MACHINE_ARM 0x01c0 |
||
130 | #define IMAGE_FILE_MACHINE_AXP64 IMAGE_FILE_MACHINE_ALPHA64 |
||
131 | #define IMAGE_FILE_MACHINE_CEE 0xc0ee |
||
132 | #define IMAGE_FILE_MACHINE_CEF 0x0cef |
||
133 | #define IMAGE_FILE_MACHINE_EBC 0x0ebc |
||
134 | #define IMAGE_FILE_MACHINE_I386 0x014c |
||
135 | #define IMAGE_FILE_MACHINE_IA64 0x0200 |
||
136 | #define IMAGE_FILE_MACHINE_M32R 0x9041 |
||
137 | #define IMAGE_FILE_MACHINE_M68K 0x0268 |
||
138 | #define IMAGE_FILE_MACHINE_MIPS16 0x0266 |
||
139 | #define IMAGE_FILE_MACHINE_MIPSFPU 0x0366 |
||
140 | #define IMAGE_FILE_MACHINE_MIPSFPU16 0x0466 |
||
141 | #define IMAGE_FILE_MACHINE_POWERPC 0x01f0 |
||
142 | #define IMAGE_FILE_MACHINE_POWERPCFP 0x01f1 |
||
143 | #define IMAGE_FILE_MACHINE_R10000 0x0168 |
||
144 | #define IMAGE_FILE_MACHINE_R3000 0x0162 |
||
145 | #define IMAGE_FILE_MACHINE_R4000 0x0166 |
||
146 | #define IMAGE_FILE_MACHINE_SH3 0x01a2 |
||
147 | #define IMAGE_FILE_MACHINE_SH3DSP 0x01a3 |
||
148 | #define IMAGE_FILE_MACHINE_SH3E 0x01a4 |
||
149 | #define IMAGE_FILE_MACHINE_SH4 0x01a6 |
||
150 | #define IMAGE_FILE_MACHINE_SH5 0x01a8 |
||
151 | #define IMAGE_FILE_MACHINE_THUMB 0x01c2 |
||
152 | #define IMAGE_FILE_MACHINE_TRICORE 0x0520 |
||
153 | #define IMAGE_FILE_MACHINE_WCEMIPSV2 0x0169 |
||
154 | #define IMAGE_FILE_MACHINE_AMD64 0x8664 |
||
155 | |||
156 | #define IMAGE_SUBSYSTEM_UNKNOWN 0 |
||
157 | #define IMAGE_SUBSYSTEM_NATIVE 1 |
||
158 | #define IMAGE_SUBSYSTEM_WINDOWS_GUI 2 |
||
159 | #define IMAGE_SUBSYSTEM_WINDOWS_CUI 3 |
||
160 | #define IMAGE_SUBSYSTEM_POSIX_CUI 7 |
||
161 | #define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI 9 |
||
162 | #define IMAGE_SUBSYSTEM_EFI_APPLICATION 10 |
||
163 | #define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11 |
||
164 | #define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12 |
||
165 | #define IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER 13 |
||
166 | #define IMAGE_SUBSYSTEM_XBOX 14 |
||
6324 | serge | 167 | |
5191 | serge | 168 | /* Magic values that are true for all dos/nt implementations. */ |
6324 | serge | 169 | #define DOSMAGIC 0x5a4d |
5191 | serge | 170 | #define NT_SIGNATURE 0x00004550 |
171 | |||
172 | /* NT allows long filenames, we want to accommodate this. |
||
173 | This may break some of the bfd functions. */ |
||
174 | #undef FILNMLEN |
||
175 | #define FILNMLEN 18 /* # characters in a file name. */ |
||
176 | |||
177 | struct external_PEI_DOS_hdr |
||
178 | { |
||
179 | /* DOS header fields - always at offset zero in the EXE file. */ |
||
180 | char e_magic[2]; /* Magic number, 0x5a4d. */ |
||
181 | char e_cblp[2]; /* Bytes on last page of file, 0x90. */ |
||
182 | char e_cp[2]; /* Pages in file, 0x3. */ |
||
183 | char e_crlc[2]; /* Relocations, 0x0. */ |
||
184 | char e_cparhdr[2]; /* Size of header in paragraphs, 0x4. */ |
||
185 | char e_minalloc[2]; /* Minimum extra paragraphs needed, 0x0. */ |
||
186 | char e_maxalloc[2]; /* Maximum extra paragraphs needed, 0xFFFF. */ |
||
187 | char e_ss[2]; /* Initial (relative) SS value, 0x0. */ |
||
188 | char e_sp[2]; /* Initial SP value, 0xb8. */ |
||
189 | char e_csum[2]; /* Checksum, 0x0. */ |
||
190 | char e_ip[2]; /* Initial IP value, 0x0. */ |
||
191 | char e_cs[2]; /* Initial (relative) CS value, 0x0. */ |
||
192 | char e_lfarlc[2]; /* File address of relocation table, 0x40. */ |
||
193 | char e_ovno[2]; /* Overlay number, 0x0. */ |
||
194 | char e_res[4][2]; /* Reserved words, all 0x0. */ |
||
195 | char e_oemid[2]; /* OEM identifier (for e_oeminfo), 0x0. */ |
||
196 | char e_oeminfo[2]; /* OEM information; e_oemid specific, 0x0. */ |
||
197 | char e_res2[10][2]; /* Reserved words, all 0x0. */ |
||
198 | char e_lfanew[4]; /* File address of new exe header, usually 0x80. */ |
||
199 | char dos_message[16][4]; /* Other stuff, always follow DOS header. */ |
||
200 | }; |
||
201 | |||
202 | struct external_PEI_IMAGE_hdr |
||
203 | { |
||
6324 | serge | 204 | char nt_signature[4]; /* Required NT signature, 0x4550. */ |
5191 | serge | 205 | |
206 | /* From standard header. */ |
||
207 | char f_magic[2]; /* Magic number. */ |
||
208 | char f_nscns[2]; /* Number of sections. */ |
||
209 | char f_timdat[4]; /* Time & date stamp. */ |
||
210 | char f_symptr[4]; /* File pointer to symtab. */ |
||
211 | char f_nsyms[4]; /* Number of symtab entries. */ |
||
212 | char f_opthdr[2]; /* Sizeof(optional hdr). */ |
||
213 | char f_flags[2]; /* Flags. */ |
||
214 | }; |
||
215 | |||
216 | struct external_PEI_filehdr |
||
217 | { |
||
218 | /* DOS header fields - always at offset zero in the EXE file. */ |
||
219 | char e_magic[2]; /* Magic number, 0x5a4d. */ |
||
220 | char e_cblp[2]; /* Bytes on last page of file, 0x90. */ |
||
221 | char e_cp[2]; /* Pages in file, 0x3. */ |
||
222 | char e_crlc[2]; /* Relocations, 0x0. */ |
||
223 | char e_cparhdr[2]; /* Size of header in paragraphs, 0x4. */ |
||
224 | char e_minalloc[2]; /* Minimum extra paragraphs needed, 0x0. */ |
||
225 | char e_maxalloc[2]; /* Maximum extra paragraphs needed, 0xFFFF. */ |
||
226 | char e_ss[2]; /* Initial (relative) SS value, 0x0. */ |
||
227 | char e_sp[2]; /* Initial SP value, 0xb8. */ |
||
228 | char e_csum[2]; /* Checksum, 0x0. */ |
||
229 | char e_ip[2]; /* Initial IP value, 0x0. */ |
||
230 | char e_cs[2]; /* Initial (relative) CS value, 0x0. */ |
||
231 | char e_lfarlc[2]; /* File address of relocation table, 0x40. */ |
||
232 | char e_ovno[2]; /* Overlay number, 0x0. */ |
||
233 | char e_res[4][2]; /* Reserved words, all 0x0. */ |
||
234 | char e_oemid[2]; /* OEM identifier (for e_oeminfo), 0x0. */ |
||
235 | char e_oeminfo[2]; /* OEM information; e_oemid specific, 0x0. */ |
||
236 | char e_res2[10][2]; /* Reserved words, all 0x0. */ |
||
237 | char e_lfanew[4]; /* File address of new exe header, usually 0x80. */ |
||
238 | char dos_message[16][4]; /* Other stuff, always follow DOS header. */ |
||
239 | |||
240 | /* Note: additional bytes may be inserted before the signature. Use |
||
241 | the e_lfanew field to find the actual location of the NT signature. */ |
||
242 | |||
6324 | serge | 243 | char nt_signature[4]; /* Required NT signature, 0x4550. */ |
5191 | serge | 244 | |
245 | /* From standard header. */ |
||
246 | char f_magic[2]; /* Magic number. */ |
||
247 | char f_nscns[2]; /* Number of sections. */ |
||
248 | char f_timdat[4]; /* Time & date stamp. */ |
||
249 | char f_symptr[4]; /* File pointer to symtab. */ |
||
250 | char f_nsyms[4]; /* Number of symtab entries. */ |
||
251 | char f_opthdr[2]; /* Sizeof(optional hdr). */ |
||
252 | char f_flags[2]; /* Flags. */ |
||
253 | }; |
||
254 | |||
255 | #ifdef COFF_IMAGE_WITH_PE |
||
256 | |||
257 | /* The filehdr is only weird in images. */ |
||
258 | |||
259 | #undef FILHDR |
||
260 | #define FILHDR struct external_PEI_filehdr |
||
261 | #undef FILHSZ |
||
262 | #define FILHSZ 152 |
||
263 | |||
264 | #endif /* COFF_IMAGE_WITH_PE */ |
||
265 | |||
6324 | serge | 266 | /* 32-bit PE a.out header: */ |
5191 | serge | 267 | |
6324 | serge | 268 | typedef struct |
5191 | serge | 269 | { |
270 | AOUTHDR standard; |
||
271 | |||
272 | /* NT extra fields; see internal.h for descriptions. */ |
||
273 | char ImageBase[4]; |
||
274 | char SectionAlignment[4]; |
||
275 | char FileAlignment[4]; |
||
276 | char MajorOperatingSystemVersion[2]; |
||
277 | char MinorOperatingSystemVersion[2]; |
||
278 | char MajorImageVersion[2]; |
||
279 | char MinorImageVersion[2]; |
||
280 | char MajorSubsystemVersion[2]; |
||
281 | char MinorSubsystemVersion[2]; |
||
282 | char Reserved1[4]; |
||
283 | char SizeOfImage[4]; |
||
284 | char SizeOfHeaders[4]; |
||
285 | char CheckSum[4]; |
||
286 | char Subsystem[2]; |
||
287 | char DllCharacteristics[2]; |
||
288 | char SizeOfStackReserve[4]; |
||
289 | char SizeOfStackCommit[4]; |
||
290 | char SizeOfHeapReserve[4]; |
||
291 | char SizeOfHeapCommit[4]; |
||
292 | char LoaderFlags[4]; |
||
293 | char NumberOfRvaAndSizes[4]; |
||
294 | /* IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; */ |
||
295 | char DataDirectory[16][2][4]; /* 16 entries, 2 elements/entry, 4 chars. */ |
||
296 | } PEAOUTHDR; |
||
297 | |||
298 | #undef AOUTSZ |
||
299 | #define AOUTSZ (AOUTHDRSZ + 196) |
||
300 | |||
301 | /* Like PEAOUTHDR, except that the "standard" member has no BaseOfData |
||
302 | (aka data_start) member and that some of the members are 8 instead |
||
303 | of just 4 bytes long. */ |
||
6324 | serge | 304 | typedef struct |
5191 | serge | 305 | { |
306 | #ifdef AOUTHDRSZ64 |
||
307 | AOUTHDR64 standard; |
||
308 | #else |
||
309 | AOUTHDR standard; |
||
310 | #endif |
||
311 | /* NT extra fields; see internal.h for descriptions. */ |
||
312 | char ImageBase[8]; |
||
313 | char SectionAlignment[4]; |
||
314 | char FileAlignment[4]; |
||
315 | char MajorOperatingSystemVersion[2]; |
||
316 | char MinorOperatingSystemVersion[2]; |
||
317 | char MajorImageVersion[2]; |
||
318 | char MinorImageVersion[2]; |
||
319 | char MajorSubsystemVersion[2]; |
||
320 | char MinorSubsystemVersion[2]; |
||
321 | char Reserved1[4]; |
||
322 | char SizeOfImage[4]; |
||
323 | char SizeOfHeaders[4]; |
||
324 | char CheckSum[4]; |
||
325 | char Subsystem[2]; |
||
326 | char DllCharacteristics[2]; |
||
327 | char SizeOfStackReserve[8]; |
||
328 | char SizeOfStackCommit[8]; |
||
329 | char SizeOfHeapReserve[8]; |
||
330 | char SizeOfHeapCommit[8]; |
||
331 | char LoaderFlags[4]; |
||
332 | char NumberOfRvaAndSizes[4]; |
||
333 | /* IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; */ |
||
334 | char DataDirectory[16][2][4]; /* 16 entries, 2 elements/entry, 4 chars. */ |
||
335 | } PEPAOUTHDR; |
||
336 | |||
337 | #ifdef AOUTHDRSZ64 |
||
338 | #define PEPAOUTSZ (AOUTHDRSZ64 + 196 + 5 * 4) /* = 240 */ |
||
339 | #else |
||
340 | #define PEPAOUTSZ 240 |
||
341 | #endif |
||
6324 | serge | 342 | |
5191 | serge | 343 | #undef E_FILNMLEN |
344 | #define E_FILNMLEN 18 /* # characters in a file name. */ |
||
345 | |||
346 | /* Import Tyoes fot ILF format object files.. */ |
||
347 | #define IMPORT_CODE 0 |
||
348 | #define IMPORT_DATA 1 |
||
349 | #define IMPORT_CONST 2 |
||
350 | |||
351 | /* Import Name Tyoes for ILF format object files. */ |
||
352 | #define IMPORT_ORDINAL 0 |
||
353 | #define IMPORT_NAME 1 |
||
354 | #define IMPORT_NAME_NOPREFIX 2 |
||
355 | #define IMPORT_NAME_UNDECORATE 3 |
||
356 | |||
357 | /* Weak external characteristics. */ |
||
358 | #define IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY 1 |
||
359 | #define IMAGE_WEAK_EXTERN_SEARCH_LIBRARY 2 |
||
360 | #define IMAGE_WEAK_EXTERN_SEARCH_ALIAS 3 |
||
361 | |||
6324 | serge | 362 | /* Bigobj header. */ |
363 | struct external_ANON_OBJECT_HEADER_BIGOBJ |
||
364 | { |
||
365 | /* ANON_OBJECT_HEADER_V2 header. */ |
||
366 | char Sig1[2]; |
||
367 | char Sig2[2]; |
||
368 | char Version[2]; |
||
369 | char Machine[2]; |
||
370 | char TimeDateStamp[4]; |
||
371 | char ClassID[16]; |
||
372 | char SizeOfData[4]; |
||
373 | char Flags[4]; |
||
374 | char MetaDataSize[4]; |
||
375 | char MetaDataOffset[4]; |
||
376 | |||
377 | /* BIGOBJ specific. */ |
||
378 | char NumberOfSections[4]; |
||
379 | char PointerToSymbolTable[4]; |
||
380 | char NumberOfSymbols[4]; |
||
381 | }; |
||
382 | |||
383 | #define FILHSZ_BIGOBJ (14 * 4) |
||
384 | |||
385 | struct external_SYMBOL_EX |
||
386 | { |
||
387 | union |
||
388 | { |
||
389 | char e_name[E_SYMNMLEN]; |
||
390 | |||
391 | struct |
||
392 | { |
||
393 | char e_zeroes[4]; |
||
394 | char e_offset[4]; |
||
395 | } e; |
||
396 | } e; |
||
397 | |||
398 | char e_value[4]; |
||
399 | char e_scnum[4]; |
||
400 | char e_type[2]; |
||
401 | char e_sclass[1]; |
||
402 | char e_numaux[1]; |
||
403 | } ATTRIBUTE_PACKED ; |
||
404 | |||
405 | #define SYMENT_BIGOBJ struct external_SYMBOL_EX |
||
406 | #define SYMESZ_BIGOBJ 20 |
||
407 | |||
408 | #define FILNMLEN_BIGOBJ 20 |
||
409 | |||
410 | union external_AUX_SYMBOL_EX |
||
411 | { |
||
412 | struct |
||
413 | { |
||
414 | char WeakDefaultSymIndex[4]; |
||
415 | char WeakSearchType[4]; |
||
416 | char rgbReserved[12]; |
||
417 | } Sym; |
||
418 | |||
419 | struct |
||
420 | { |
||
421 | char Name[FILNMLEN_BIGOBJ]; |
||
422 | } File; |
||
423 | |||
424 | struct |
||
425 | { |
||
426 | char Length[4]; /* Section length. */ |
||
427 | char NumberOfRelocations[2];/* # relocation entries. */ |
||
428 | char NumberOfLinenumbers[2];/* # line numbers. */ |
||
429 | char Checksum[4]; /* Section COMDAT checksum. */ |
||
430 | char Number[2]; /* COMDAT associated section index. */ |
||
431 | char Selection[1]; /* COMDAT selection number. */ |
||
432 | char bReserved[1]; |
||
433 | char HighNumber[2]; /* High bits of COMDAT associated sec. */ |
||
434 | char rgbReserved[2]; |
||
435 | } Section; |
||
436 | } ATTRIBUTE_PACKED; |
||
437 | |||
438 | #define AUXENT_BIGOBJ union external_AUX_SYMBOL_EX |
||
439 | #define AUXESZ_BIGOBJ 20 |
||
440 | |||
5191 | serge | 441 | /* .pdata/.xdata defines and structures for x64 PE+ for exception handling. */ |
442 | |||
443 | /* .pdata in exception directory. */ |
||
444 | |||
445 | struct pex64_runtime_function |
||
446 | { |
||
447 | bfd_vma rva_BeginAddress; |
||
448 | bfd_vma rva_EndAddress; |
||
449 | bfd_vma rva_UnwindData; |
||
450 | }; |
||
451 | |||
452 | struct external_pex64_runtime_function |
||
453 | { |
||
454 | bfd_byte rva_BeginAddress[4]; |
||
455 | bfd_byte rva_EndAddress[4]; |
||
456 | bfd_byte rva_UnwindData[4]; |
||
457 | }; |
||
458 | |||
459 | /* If the lowest significant bit is set for rva_UnwindData RVA, it |
||
460 | means that the unified RVA points to another pex64_runtime_function |
||
461 | that this entry shares the unwind_info block with. */ |
||
462 | #define PEX64_IS_RUNTIME_FUNCTION_CHAINED(PTR_RTF) \ |
||
463 | (((PTR_RTF)->rva_UnwindData & 1) != 0) |
||
464 | #define PEX64_GET_UNWINDDATA_UNIFIED_RVA(PTR_RTF) \ |
||
465 | ((PTR_RTF)->rva_UnwindData & ~1) |
||
466 | |||
467 | /* The unwind codes. */ |
||
468 | #define UWOP_PUSH_NONVOL 0 |
||
469 | #define UWOP_ALLOC_LARGE 1 |
||
470 | #define UWOP_ALLOC_SMALL 2 |
||
471 | #define UWOP_SET_FPREG 3 |
||
472 | #define UWOP_SAVE_NONVOL 4 |
||
473 | #define UWOP_SAVE_NONVOL_FAR 5 |
||
6324 | serge | 474 | #define UWOP_SAVE_XMM 6 /* For version 1. */ |
475 | #define UWOP_EPILOG 6 /* For version 2. */ |
||
476 | #define UWOP_SAVE_XMM_FAR 7 /* For version 1 (deprecated). */ |
||
477 | #define UWOP_SPARE 7 /* For version 2. */ |
||
5191 | serge | 478 | #define UWOP_SAVE_XMM128 8 |
479 | #define UWOP_SAVE_XMM128_FAR 9 |
||
480 | #define UWOP_PUSH_MACHFRAME 10 |
||
481 | |||
482 | struct pex64_unwind_code |
||
483 | { |
||
484 | bfd_vma prologue_offset; |
||
485 | /* Contains Frame offset, or frame allocation size. */ |
||
486 | bfd_vma frame_addr; |
||
487 | unsigned int uwop_code : 4; |
||
488 | /* xmm, mm, or standard register from 0 - 15. */ |
||
489 | unsigned int reg : 4; |
||
490 | /* Used for UWOP_PUSH_MACHFRAME to indicate optional errorcode stack |
||
491 | argument. */ |
||
492 | unsigned int has_errorcode : 1; |
||
493 | }; |
||
494 | |||
495 | struct external_pex64_unwind_code |
||
496 | { |
||
497 | bfd_byte dta[2]; |
||
498 | }; |
||
499 | |||
500 | #define PEX64_UNWCODE_CODE(VAL) ((VAL) & 0xf) |
||
501 | #define PEX64_UNWCODE_INFO(VAL) (((VAL) >> 4) & 0xf) |
||
502 | |||
503 | /* The unwind info. */ |
||
504 | #define UNW_FLAG_NHANDLER 0 |
||
505 | #define UNW_FLAG_EHANDLER 1 |
||
506 | #define UNW_FLAG_UHANDLER 2 |
||
507 | #define UNW_FLAG_FHANDLER 3 |
||
508 | #define UNW_FLAG_CHAININFO 4 |
||
509 | |||
510 | #define UNW_FLAG_MASK 0x1f |
||
511 | |||
512 | struct pex64_unwind_info |
||
513 | { |
||
514 | bfd_vma SizeOfBlock; |
||
515 | bfd_byte Version; /* Values from 0 up to 7 are possible. */ |
||
516 | bfd_byte Flags; /* Values from 0 up to 31 are possible. */ |
||
517 | bfd_vma SizeOfPrologue; |
||
518 | bfd_vma CountOfCodes; /* Amount of pex64_unwind_code elements. */ |
||
519 | /* 0 = CFA, 1..15 are index of integer registers. */ |
||
520 | unsigned int FrameRegister : 4; |
||
521 | bfd_vma FrameOffset; |
||
522 | bfd_vma sizeofUnwindCodes; |
||
523 | bfd_byte *rawUnwindCodes; |
||
6324 | serge | 524 | bfd_vma rva_ExceptionHandler; /* UNW_EHANDLER or UNW_FLAG_UHANDLER. */ |
525 | bfd_vma rva_BeginAddress; /* UNW_FLAG_CHAININFO. */ |
||
526 | bfd_vma rva_EndAddress; /* UNW_FLAG_CHAININFO. */ |
||
527 | bfd_vma rva_UnwindData; /* UNW_FLAG_CHAININFO. */ |
||
5191 | serge | 528 | }; |
529 | |||
530 | struct external_pex64_unwind_info |
||
531 | { |
||
532 | bfd_byte Version_Flags; |
||
533 | bfd_byte SizeOfPrologue; |
||
534 | bfd_byte CountOfCodes; |
||
535 | bfd_byte FrameRegisterOffset; |
||
536 | /* external_pex64_unwind_code array. */ |
||
537 | /* bfd_byte handler[4]; */ |
||
538 | /* Optional language specific data. */ |
||
539 | }; |
||
540 | |||
541 | struct external_pex64_scope |
||
542 | { |
||
543 | bfd_vma Count; |
||
544 | }; |
||
545 | |||
546 | struct pex64_scope |
||
547 | { |
||
548 | bfd_byte Count[4]; |
||
549 | }; |
||
550 | |||
551 | struct pex64_scope_entry |
||
552 | { |
||
553 | bfd_vma rva_BeginAddress; |
||
554 | bfd_vma rva_EndAddress; |
||
555 | bfd_vma rva_HandlerAddress; |
||
556 | bfd_vma rva_JumpAddress; |
||
557 | }; |
||
558 | #define PEX64_SCOPE_ENTRY_SIZE 16 |
||
559 | |||
560 | struct external_pex64_scope_entry |
||
561 | { |
||
562 | bfd_byte rva_BeginAddress[4]; |
||
563 | bfd_byte rva_EndAddress[4]; |
||
564 | bfd_byte rva_HandlerAddress[4]; |
||
565 | bfd_byte rva_JumpAddress[4]; |
||
566 | }; |
||
567 | |||
568 | #define PEX64_UWI_VERSION(VAL) ((VAL) & 7) |
||
569 | #define PEX64_UWI_FLAGS(VAL) (((VAL) >> 3) & 0x1f) |
||
570 | #define PEX64_UWI_FRAMEREG(VAL) ((VAL) & 0xf) |
||
571 | #define PEX64_UWI_FRAMEOFF(VAL) (((VAL) >> 4) & 0xf) |
||
572 | #define PEX64_UWI_SIZEOF_UWCODE_ARRAY(VAL) \ |
||
573 | ((((VAL) + 1) & ~1) * 2) |
||
574 | |||
575 | #define PEX64_OFFSET_TO_UNWIND_CODE 0x4 |
||
576 | |||
577 | #define PEX64_OFFSET_TO_HANDLER_RVA (COUNTOFUNWINDCODES) \ |
||
578 | (PEX64_OFFSET_TO_UNWIND_CODE + \ |
||
579 | PEX64_UWI_SIZEOF_UWCODE_ARRAY(COUNTOFUNWINDCODES)) |
||
580 | |||
581 | #define PEX64_OFFSET_TO_SCOPE_COUNT(COUNTOFUNWINDCODES) \ |
||
582 | (PEX64_OFFSET_TO_HANDLER_RVA(COUNTOFUNWINDCODES) + 4) |
||
583 | |||
584 | #define PEX64_SCOPE_ENTRY(COUNTOFUNWINDCODES, IDX) \ |
||
585 | (PEX64_OFFSET_TO_SCOPE_COUNT(COUNTOFUNWINDCODES) + \ |
||
586 | PEX64_SCOPE_ENTRY_SIZE * (IDX)) |
||
587 | |||
6324 | serge | 588 | /* Extra structure used in debug directory. */ |
589 | struct external_IMAGE_DEBUG_DIRECTORY |
||
590 | { |
||
591 | char Characteristics[4]; |
||
592 | char TimeDateStamp[4]; |
||
593 | char MajorVersion[2]; |
||
594 | char MinorVersion[2]; |
||
595 | char Type[4]; |
||
596 | char SizeOfData[4]; |
||
597 | char AddressOfRawData[4]; |
||
598 | char PointerToRawData[4]; |
||
599 | }; |
||
600 | |||
601 | /* Extra structures used in codeview debug record. */ |
||
602 | /* This is not part of the PE specification. */ |
||
603 | |||
604 | #define CVINFO_PDB70_CVSIGNATURE 0x53445352 // "RSDS" |
||
605 | #define CVINFO_PDB20_CVSIGNATURE 0x3031424e // "NB10" |
||
606 | #define CVINFO_CV50_CVSIGNATURE 0x3131424e // "NB11" |
||
607 | #define CVINFO_CV41_CVSIGNATURE 0x3930424e // âNB09" |
||
608 | |||
609 | typedef struct _CV_INFO_PDB70 |
||
610 | { |
||
611 | char CvSignature[4]; |
||
612 | char Signature[16]; |
||
613 | char Age[4]; |
||
614 | char PdbFileName[]; |
||
615 | } CV_INFO_PDB70; |
||
616 | |||
617 | typedef struct _CV_INFO_PDB20 |
||
618 | { |
||
619 | char CvHeader[4]; |
||
620 | char Offset[4]; |
||
621 | char Signature[4]; |
||
622 | char Age[4]; |
||
623 | char PdbFileName[]; |
||
624 | } CV_INFO_PDB20; |
||
625 | |||
5191 | serge | 626 | #endif /* _PE_H */><> |