1 |
578 |
markom |
/* pe.h - PE COFF header information
|
2 |
|
|
|
3 |
|
|
Copyright 2000, 2001 Free Software Foundation, Inc.
|
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,
|
19 |
|
|
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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_SYSTEM 0x1000
|
36 |
|
|
#define IMAGE_FILE_DLL 0x2000
|
37 |
|
|
#define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000
|
38 |
|
|
#define IMAGE_FILE_BYTES_REVERSED_HI 0x8000
|
39 |
|
|
|
40 |
|
|
/* Additional flags to be set for section headers to allow the NT loader to
|
41 |
|
|
read and write to the section data (to replace the addresses of data in
|
42 |
|
|
dlls for one thing); also to execute the section in .text's case. */
|
43 |
|
|
#define IMAGE_SCN_MEM_DISCARDABLE 0x02000000
|
44 |
|
|
#define IMAGE_SCN_MEM_EXECUTE 0x20000000
|
45 |
|
|
#define IMAGE_SCN_MEM_READ 0x40000000
|
46 |
|
|
#define IMAGE_SCN_MEM_WRITE 0x80000000
|
47 |
|
|
|
48 |
|
|
/* Section characteristics added for ppc-nt. */
|
49 |
|
|
|
50 |
|
|
#define IMAGE_SCN_TYPE_NO_PAD 0x00000008 /* Reserved. */
|
51 |
|
|
|
52 |
|
|
#define IMAGE_SCN_CNT_CODE 0x00000020 /* Section contains code. */
|
53 |
|
|
#define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 /* Section contains initialized data. */
|
54 |
|
|
#define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 /* Section contains uninitialized data. */
|
55 |
|
|
|
56 |
|
|
#define IMAGE_SCN_LNK_OTHER 0x00000100 /* Reserved. */
|
57 |
|
|
#define IMAGE_SCN_LNK_INFO 0x00000200 /* Section contains comments or some other type of information. */
|
58 |
|
|
#define IMAGE_SCN_LNK_REMOVE 0x00000800 /* Section contents will not become part of image. */
|
59 |
|
|
#define IMAGE_SCN_LNK_COMDAT 0x00001000 /* Section contents comdat. */
|
60 |
|
|
|
61 |
|
|
#define IMAGE_SCN_MEM_FARDATA 0x00008000
|
62 |
|
|
|
63 |
|
|
#define IMAGE_SCN_MEM_PURGEABLE 0x00020000
|
64 |
|
|
#define IMAGE_SCN_MEM_16BIT 0x00020000
|
65 |
|
|
#define IMAGE_SCN_MEM_LOCKED 0x00040000
|
66 |
|
|
#define IMAGE_SCN_MEM_PRELOAD 0x00080000
|
67 |
|
|
|
68 |
|
|
#define IMAGE_SCN_ALIGN_1BYTES 0x00100000
|
69 |
|
|
#define IMAGE_SCN_ALIGN_2BYTES 0x00200000
|
70 |
|
|
#define IMAGE_SCN_ALIGN_4BYTES 0x00300000
|
71 |
|
|
#define IMAGE_SCN_ALIGN_8BYTES 0x00400000
|
72 |
|
|
#define IMAGE_SCN_ALIGN_16BYTES 0x00500000 /* Default alignment if no others are specified. */
|
73 |
|
|
#define IMAGE_SCN_ALIGN_32BYTES 0x00600000
|
74 |
|
|
#define IMAGE_SCN_ALIGN_64BYTES 0x00700000
|
75 |
|
|
|
76 |
|
|
#define IMAGE_SCN_LNK_NRELOC_OVFL 0x01000000 /* Section contains extended relocations. */
|
77 |
|
|
#define IMAGE_SCN_MEM_NOT_CACHED 0x04000000 /* Section is not cachable. */
|
78 |
|
|
#define IMAGE_SCN_MEM_NOT_PAGED 0x08000000 /* Section is not pageable. */
|
79 |
|
|
#define IMAGE_SCN_MEM_SHARED 0x10000000 /* Section is shareable. */
|
80 |
|
|
|
81 |
|
|
/* COMDAT selection codes. */
|
82 |
|
|
|
83 |
|
|
#define IMAGE_COMDAT_SELECT_NODUPLICATES (1) /* Warn if duplicates. */
|
84 |
|
|
#define IMAGE_COMDAT_SELECT_ANY (2) /* No warning. */
|
85 |
|
|
#define IMAGE_COMDAT_SELECT_SAME_SIZE (3) /* Warn if different size. */
|
86 |
|
|
#define IMAGE_COMDAT_SELECT_EXACT_MATCH (4) /* Warn if different. */
|
87 |
|
|
#define IMAGE_COMDAT_SELECT_ASSOCIATIVE (5) /* Base on other section. */
|
88 |
|
|
|
89 |
|
|
/* Machine numbers. */
|
90 |
|
|
|
91 |
|
|
#define IMAGE_FILE_MACHINE_UNKNOWN 0x0
|
92 |
|
|
#define IMAGE_FILE_MACHINE_ALPHA 0x184
|
93 |
|
|
#define IMAGE_FILE_MACHINE_ARM 0x1c0
|
94 |
|
|
#define IMAGE_FILE_MACHINE_ALPHA64 0x284
|
95 |
|
|
#define IMAGE_FILE_MACHINE_I386 0x14c
|
96 |
|
|
#define IMAGE_FILE_MACHINE_IA64 0x200
|
97 |
|
|
#define IMAGE_FILE_MACHINE_M68K 0x268
|
98 |
|
|
#define IMAGE_FILE_MACHINE_MIPS16 0x266
|
99 |
|
|
#define IMAGE_FILE_MACHINE_MIPSFPU 0x366
|
100 |
|
|
#define IMAGE_FILE_MACHINE_MIPSFPU16 0x466
|
101 |
|
|
#define IMAGE_FILE_MACHINE_POWERPC 0x1f0
|
102 |
|
|
#define IMAGE_FILE_MACHINE_R3000 0x162
|
103 |
|
|
#define IMAGE_FILE_MACHINE_R4000 0x166
|
104 |
|
|
#define IMAGE_FILE_MACHINE_R10000 0x168
|
105 |
|
|
#define IMAGE_FILE_MACHINE_SH3 0x1a2
|
106 |
|
|
#define IMAGE_FILE_MACHINE_SH4 0x1a6
|
107 |
|
|
#define IMAGE_FILE_MACHINE_THUMB 0x1c2
|
108 |
|
|
|
109 |
|
|
#define IMAGE_SUBSYSTEM_UNKNOWN 0
|
110 |
|
|
#define IMAGE_SUBSYSTEM_NATIVE 1
|
111 |
|
|
#define IMAGE_SUBSYSTEM_WINDOWS_GUI 2
|
112 |
|
|
#define IMAGE_SUBSYSTEM_WINDOWS_CUI 3
|
113 |
|
|
#define IMAGE_SUBSYSTEM_POSIX_CUI 7
|
114 |
|
|
#define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI 9
|
115 |
|
|
#define IMAGE_SUBSYSTEM_EFI_APPLICATION 10
|
116 |
|
|
#define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11
|
117 |
|
|
#define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12
|
118 |
|
|
|
119 |
|
|
/* Magic values that are true for all dos/nt implementations. */
|
120 |
|
|
#define DOSMAGIC 0x5a4d
|
121 |
|
|
#define NT_SIGNATURE 0x00004550
|
122 |
|
|
|
123 |
|
|
/* NT allows long filenames, we want to accommodate this.
|
124 |
|
|
This may break some of the bfd functions. */
|
125 |
|
|
#undef FILNMLEN
|
126 |
|
|
#define FILNMLEN 18 /* # characters in a file name. */
|
127 |
|
|
|
128 |
|
|
struct external_PEI_DOS_hdr
|
129 |
|
|
{
|
130 |
|
|
/* DOS header fields - always at offset zero in the EXE file. */
|
131 |
|
|
char e_magic[2]; /* Magic number, 0x5a4d. */
|
132 |
|
|
char e_cblp[2]; /* Bytes on last page of file, 0x90. */
|
133 |
|
|
char e_cp[2]; /* Pages in file, 0x3. */
|
134 |
|
|
char e_crlc[2]; /* Relocations, 0x0. */
|
135 |
|
|
char e_cparhdr[2]; /* Size of header in paragraphs, 0x4. */
|
136 |
|
|
char e_minalloc[2]; /* Minimum extra paragraphs needed, 0x0. */
|
137 |
|
|
char e_maxalloc[2]; /* Maximum extra paragraphs needed, 0xFFFF. */
|
138 |
|
|
char e_ss[2]; /* Initial (relative) SS value, 0x0. */
|
139 |
|
|
char e_sp[2]; /* Initial SP value, 0xb8. */
|
140 |
|
|
char e_csum[2]; /* Checksum, 0x0. */
|
141 |
|
|
char e_ip[2]; /* Initial IP value, 0x0. */
|
142 |
|
|
char e_cs[2]; /* Initial (relative) CS value, 0x0. */
|
143 |
|
|
char e_lfarlc[2]; /* File address of relocation table, 0x40. */
|
144 |
|
|
char e_ovno[2]; /* Overlay number, 0x0. */
|
145 |
|
|
char e_res[4][2]; /* Reserved words, all 0x0. */
|
146 |
|
|
char e_oemid[2]; /* OEM identifier (for e_oeminfo), 0x0. */
|
147 |
|
|
char e_oeminfo[2]; /* OEM information; e_oemid specific, 0x0. */
|
148 |
|
|
char e_res2[10][2]; /* Reserved words, all 0x0. */
|
149 |
|
|
char e_lfanew[4]; /* File address of new exe header, usually 0x80. */
|
150 |
|
|
char dos_message[16][4]; /* Other stuff, always follow DOS header. */
|
151 |
|
|
};
|
152 |
|
|
|
153 |
|
|
struct external_PEI_IMAGE_hdr
|
154 |
|
|
{
|
155 |
|
|
char nt_signature[4]; /* required NT signature, 0x4550. */
|
156 |
|
|
|
157 |
|
|
/* From standard header. */
|
158 |
|
|
char f_magic[2]; /* Magic number. */
|
159 |
|
|
char f_nscns[2]; /* Number of sections. */
|
160 |
|
|
char f_timdat[4]; /* Time & date stamp. */
|
161 |
|
|
char f_symptr[4]; /* File pointer to symtab. */
|
162 |
|
|
char f_nsyms[4]; /* Number of symtab entries. */
|
163 |
|
|
char f_opthdr[2]; /* Sizeof(optional hdr). */
|
164 |
|
|
char f_flags[2]; /* Flags. */
|
165 |
|
|
};
|
166 |
|
|
|
167 |
|
|
struct external_PEI_filehdr
|
168 |
|
|
{
|
169 |
|
|
/* DOS header fields - always at offset zero in the EXE file. */
|
170 |
|
|
char e_magic[2]; /* Magic number, 0x5a4d. */
|
171 |
|
|
char e_cblp[2]; /* Bytes on last page of file, 0x90. */
|
172 |
|
|
char e_cp[2]; /* Pages in file, 0x3. */
|
173 |
|
|
char e_crlc[2]; /* Relocations, 0x0. */
|
174 |
|
|
char e_cparhdr[2]; /* Size of header in paragraphs, 0x4. */
|
175 |
|
|
char e_minalloc[2]; /* Minimum extra paragraphs needed, 0x0. */
|
176 |
|
|
char e_maxalloc[2]; /* Maximum extra paragraphs needed, 0xFFFF. */
|
177 |
|
|
char e_ss[2]; /* Initial (relative) SS value, 0x0. */
|
178 |
|
|
char e_sp[2]; /* Initial SP value, 0xb8. */
|
179 |
|
|
char e_csum[2]; /* Checksum, 0x0. */
|
180 |
|
|
char e_ip[2]; /* Initial IP value, 0x0. */
|
181 |
|
|
char e_cs[2]; /* Initial (relative) CS value, 0x0. */
|
182 |
|
|
char e_lfarlc[2]; /* File address of relocation table, 0x40. */
|
183 |
|
|
char e_ovno[2]; /* Overlay number, 0x0. */
|
184 |
|
|
char e_res[4][2]; /* Reserved words, all 0x0. */
|
185 |
|
|
char e_oemid[2]; /* OEM identifier (for e_oeminfo), 0x0. */
|
186 |
|
|
char e_oeminfo[2]; /* OEM information; e_oemid specific, 0x0. */
|
187 |
|
|
char e_res2[10][2]; /* Reserved words, all 0x0. */
|
188 |
|
|
char e_lfanew[4]; /* File address of new exe header, usually 0x80. */
|
189 |
|
|
char dos_message[16][4]; /* Other stuff, always follow DOS header. */
|
190 |
|
|
|
191 |
|
|
/* Note: additional bytes may be inserted before the signature. Use
|
192 |
|
|
the e_lfanew field to find the actual location of the NT signature. */
|
193 |
|
|
|
194 |
|
|
char nt_signature[4]; /* required NT signature, 0x4550. */
|
195 |
|
|
|
196 |
|
|
/* From standard header. */
|
197 |
|
|
char f_magic[2]; /* Magic number. */
|
198 |
|
|
char f_nscns[2]; /* Number of sections. */
|
199 |
|
|
char f_timdat[4]; /* Time & date stamp. */
|
200 |
|
|
char f_symptr[4]; /* File pointer to symtab. */
|
201 |
|
|
char f_nsyms[4]; /* Number of symtab entries. */
|
202 |
|
|
char f_opthdr[2]; /* Sizeof(optional hdr). */
|
203 |
|
|
char f_flags[2]; /* Flags. */
|
204 |
|
|
};
|
205 |
|
|
|
206 |
|
|
#ifdef COFF_IMAGE_WITH_PE
|
207 |
|
|
|
208 |
|
|
/* The filehdr is only weird in images. */
|
209 |
|
|
|
210 |
|
|
#undef FILHDR
|
211 |
|
|
#define FILHDR struct external_PEI_filehdr
|
212 |
|
|
#undef FILHSZ
|
213 |
|
|
#define FILHSZ 152
|
214 |
|
|
|
215 |
|
|
#endif /* COFF_IMAGE_WITH_PE */
|
216 |
|
|
|
217 |
|
|
/* 32-bit PE a.out header: */
|
218 |
|
|
|
219 |
|
|
typedef struct
|
220 |
|
|
{
|
221 |
|
|
AOUTHDR standard;
|
222 |
|
|
|
223 |
|
|
/* NT extra fields; see internal.h for descriptions. */
|
224 |
|
|
char ImageBase[4];
|
225 |
|
|
char SectionAlignment[4];
|
226 |
|
|
char FileAlignment[4];
|
227 |
|
|
char MajorOperatingSystemVersion[2];
|
228 |
|
|
char MinorOperatingSystemVersion[2];
|
229 |
|
|
char MajorImageVersion[2];
|
230 |
|
|
char MinorImageVersion[2];
|
231 |
|
|
char MajorSubsystemVersion[2];
|
232 |
|
|
char MinorSubsystemVersion[2];
|
233 |
|
|
char Reserved1[4];
|
234 |
|
|
char SizeOfImage[4];
|
235 |
|
|
char SizeOfHeaders[4];
|
236 |
|
|
char CheckSum[4];
|
237 |
|
|
char Subsystem[2];
|
238 |
|
|
char DllCharacteristics[2];
|
239 |
|
|
char SizeOfStackReserve[4];
|
240 |
|
|
char SizeOfStackCommit[4];
|
241 |
|
|
char SizeOfHeapReserve[4];
|
242 |
|
|
char SizeOfHeapCommit[4];
|
243 |
|
|
char LoaderFlags[4];
|
244 |
|
|
char NumberOfRvaAndSizes[4];
|
245 |
|
|
/* IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; */
|
246 |
|
|
char DataDirectory[16][2][4]; /* 16 entries, 2 elements/entry, 4 chars. */
|
247 |
|
|
} PEAOUTHDR;
|
248 |
|
|
#undef AOUTSZ
|
249 |
|
|
#define AOUTSZ (AOUTHDRSZ + 196)
|
250 |
|
|
|
251 |
|
|
/* Like PEAOUTHDR, except that the "standard" member has no BaseOfData
|
252 |
|
|
(aka data_start) member and that some of the members are 8 instead
|
253 |
|
|
of just 4 bytes long. */
|
254 |
|
|
typedef struct
|
255 |
|
|
{
|
256 |
|
|
AOUTHDR standard;
|
257 |
|
|
|
258 |
|
|
/* NT extra fields; see internal.h for descriptions. */
|
259 |
|
|
char ImageBase[8];
|
260 |
|
|
char SectionAlignment[4];
|
261 |
|
|
char FileAlignment[4];
|
262 |
|
|
char MajorOperatingSystemVersion[2];
|
263 |
|
|
char MinorOperatingSystemVersion[2];
|
264 |
|
|
char MajorImageVersion[2];
|
265 |
|
|
char MinorImageVersion[2];
|
266 |
|
|
char MajorSubsystemVersion[2];
|
267 |
|
|
char MinorSubsystemVersion[2];
|
268 |
|
|
char Reserved1[4];
|
269 |
|
|
char SizeOfImage[4];
|
270 |
|
|
char SizeOfHeaders[4];
|
271 |
|
|
char CheckSum[4];
|
272 |
|
|
char Subsystem[2];
|
273 |
|
|
char DllCharacteristics[2];
|
274 |
|
|
char SizeOfStackReserve[8];
|
275 |
|
|
char SizeOfStackCommit[8];
|
276 |
|
|
char SizeOfHeapReserve[8];
|
277 |
|
|
char SizeOfHeapCommit[8];
|
278 |
|
|
char LoaderFlags[4];
|
279 |
|
|
char NumberOfRvaAndSizes[4];
|
280 |
|
|
/* IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; */
|
281 |
|
|
char DataDirectory[16][2][4]; /* 16 entries, 2 elements/entry, 4 chars. */
|
282 |
|
|
} PEPAOUTHDR;
|
283 |
|
|
#define PEPAOUTSZ 240
|
284 |
|
|
|
285 |
|
|
#undef E_FILNMLEN
|
286 |
|
|
#define E_FILNMLEN 18 /* # characters in a file name. */
|
287 |
|
|
|
288 |
|
|
/* Import Tyoes fot ILF format object files.. */
|
289 |
|
|
#define IMPORT_CODE 0
|
290 |
|
|
#define IMPORT_DATA 1
|
291 |
|
|
#define IMPORT_CONST 2
|
292 |
|
|
|
293 |
|
|
/* Import Name Tyoes for ILF format object files. */
|
294 |
|
|
#define IMPORT_ORDINAL 0
|
295 |
|
|
#define IMPORT_NAME 1
|
296 |
|
|
#define IMPORT_NAME_NOPREFIX 2
|
297 |
|
|
#define IMPORT_NAME_UNDECORATE 3
|
298 |
|
|
|
299 |
|
|
#endif /* _PE_H */
|