1
2
3
4
5
6
7
8 #ifndef __LINUX_PE_H
9 #define __LINUX_PE_H
10
11 #include <linux/types.h>
12
13 #define MZ_MAGIC 0x5a4d
14
15 #define PE_MAGIC 0x00004550
16 #define PE_OPT_MAGIC_PE32 0x010b
17 #define PE_OPT_MAGIC_PE32_ROM 0x0107
18 #define PE_OPT_MAGIC_PE32PLUS 0x020b
19
20
21 #define IMAGE_FILE_MACHINE_UNKNOWN 0x0000
22 #define IMAGE_FILE_MACHINE_AM33 0x01d3
23 #define IMAGE_FILE_MACHINE_AMD64 0x8664
24 #define IMAGE_FILE_MACHINE_ARM 0x01c0
25 #define IMAGE_FILE_MACHINE_ARMV7 0x01c4
26 #define IMAGE_FILE_MACHINE_ARM64 0xaa64
27 #define IMAGE_FILE_MACHINE_EBC 0x0ebc
28 #define IMAGE_FILE_MACHINE_I386 0x014c
29 #define IMAGE_FILE_MACHINE_IA64 0x0200
30 #define IMAGE_FILE_MACHINE_M32R 0x9041
31 #define IMAGE_FILE_MACHINE_MIPS16 0x0266
32 #define IMAGE_FILE_MACHINE_MIPSFPU 0x0366
33 #define IMAGE_FILE_MACHINE_MIPSFPU16 0x0466
34 #define IMAGE_FILE_MACHINE_POWERPC 0x01f0
35 #define IMAGE_FILE_MACHINE_POWERPCFP 0x01f1
36 #define IMAGE_FILE_MACHINE_R4000 0x0166
37 #define IMAGE_FILE_MACHINE_SH3 0x01a2
38 #define IMAGE_FILE_MACHINE_SH3DSP 0x01a3
39 #define IMAGE_FILE_MACHINE_SH3E 0x01a4
40 #define IMAGE_FILE_MACHINE_SH4 0x01a6
41 #define IMAGE_FILE_MACHINE_SH5 0x01a8
42 #define IMAGE_FILE_MACHINE_THUMB 0x01c2
43 #define IMAGE_FILE_MACHINE_WCEMIPSV2 0x0169
44
45
46 #define IMAGE_FILE_RELOCS_STRIPPED 0x0001
47 #define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002
48 #define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004
49 #define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008
50 #define IMAGE_FILE_AGGRESSIVE_WS_TRIM 0x0010
51 #define IMAGE_FILE_LARGE_ADDRESS_AWARE 0x0020
52 #define IMAGE_FILE_16BIT_MACHINE 0x0040
53 #define IMAGE_FILE_BYTES_REVERSED_LO 0x0080
54 #define IMAGE_FILE_32BIT_MACHINE 0x0100
55 #define IMAGE_FILE_DEBUG_STRIPPED 0x0200
56 #define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400
57 #define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800
58 #define IMAGE_FILE_SYSTEM 0x1000
59 #define IMAGE_FILE_DLL 0x2000
60 #define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000
61 #define IMAGE_FILE_BYTES_REVERSED_HI 0x8000
62
63 #define IMAGE_FILE_OPT_ROM_MAGIC 0x107
64 #define IMAGE_FILE_OPT_PE32_MAGIC 0x10b
65 #define IMAGE_FILE_OPT_PE32_PLUS_MAGIC 0x20b
66
67 #define IMAGE_SUBSYSTEM_UNKNOWN 0
68 #define IMAGE_SUBSYSTEM_NATIVE 1
69 #define IMAGE_SUBSYSTEM_WINDOWS_GUI 2
70 #define IMAGE_SUBSYSTEM_WINDOWS_CUI 3
71 #define IMAGE_SUBSYSTEM_POSIX_CUI 7
72 #define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI 9
73 #define IMAGE_SUBSYSTEM_EFI_APPLICATION 10
74 #define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11
75 #define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12
76 #define IMAGE_SUBSYSTEM_EFI_ROM_IMAGE 13
77 #define IMAGE_SUBSYSTEM_XBOX 14
78
79 #define IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE 0x0040
80 #define IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY 0x0080
81 #define IMAGE_DLL_CHARACTERISTICS_NX_COMPAT 0x0100
82 #define IMAGE_DLLCHARACTERISTICS_NO_ISOLATION 0x0200
83 #define IMAGE_DLLCHARACTERISTICS_NO_SEH 0x0400
84 #define IMAGE_DLLCHARACTERISTICS_NO_BIND 0x0800
85 #define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER 0x2000
86 #define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE 0x8000
87
88
89 #define IMAGE_SCN_RESERVED_0 0x00000001
90 #define IMAGE_SCN_RESERVED_1 0x00000002
91 #define IMAGE_SCN_RESERVED_2 0x00000004
92 #define IMAGE_SCN_TYPE_NO_PAD 0x00000008
93 #define IMAGE_SCN_RESERVED_3 0x00000010
94 #define IMAGE_SCN_CNT_CODE 0x00000020
95 #define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040
96 #define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080
97 #define IMAGE_SCN_LNK_OTHER 0x00000100
98 #define IMAGE_SCN_LNK_INFO 0x00000200
99 #define IMAGE_SCN_RESERVED_4 0x00000400
100 #define IMAGE_SCN_LNK_REMOVE 0x00000800
101 #define IMAGE_SCN_LNK_COMDAT 0x00001000
102 #define IMAGE_SCN_RESERVED_5 0x00002000
103 #define IMAGE_SCN_RESERVED_6 0x00004000
104 #define IMAGE_SCN_GPREL 0x00008000
105
106 #define IMAGE_SCN_MEM_PURGEABLE 0x00010000
107 #define IMAGE_SCN_16BIT 0x00020000
108 #define IMAGE_SCN_LOCKED 0x00040000
109 #define IMAGE_SCN_PRELOAD 0x00080000
110
111 #define IMAGE_SCN_ALIGN_1BYTES 0x00100000
112 #define IMAGE_SCN_ALIGN_2BYTES 0x00200000
113 #define IMAGE_SCN_ALIGN_4BYTES 0x00300000
114 #define IMAGE_SCN_ALIGN_8BYTES 0x00400000
115 #define IMAGE_SCN_ALIGN_16BYTES 0x00500000
116 #define IMAGE_SCN_ALIGN_32BYTES 0x00600000
117 #define IMAGE_SCN_ALIGN_64BYTES 0x00700000
118 #define IMAGE_SCN_ALIGN_128BYTES 0x00800000
119 #define IMAGE_SCN_ALIGN_256BYTES 0x00900000
120 #define IMAGE_SCN_ALIGN_512BYTES 0x00a00000
121 #define IMAGE_SCN_ALIGN_1024BYTES 0x00b00000
122 #define IMAGE_SCN_ALIGN_2048BYTES 0x00c00000
123 #define IMAGE_SCN_ALIGN_4096BYTES 0x00d00000
124 #define IMAGE_SCN_ALIGN_8192BYTES 0x00e00000
125 #define IMAGE_SCN_LNK_NRELOC_OVFL 0x01000000
126 #define IMAGE_SCN_MEM_DISCARDABLE 0x02000000
127 #define IMAGE_SCN_MEM_NOT_CACHED 0x04000000
128 #define IMAGE_SCN_MEM_NOT_PAGED 0x08000000
129 #define IMAGE_SCN_MEM_SHARED 0x10000000
130 #define IMAGE_SCN_MEM_EXECUTE 0x20000000
131 #define IMAGE_SCN_MEM_READ 0x40000000
132 #define IMAGE_SCN_MEM_WRITE 0x80000000
133
134 #define IMAGE_DEBUG_TYPE_CODEVIEW 2
135
136 #ifndef __ASSEMBLY__
137
138 struct mz_hdr {
139 uint16_t magic;
140 uint16_t lbsize;
141 uint16_t blocks;
142 uint16_t relocs;
143 uint16_t hdrsize;
144 uint16_t min_extra_pps;
145 uint16_t max_extra_pps;
146 uint16_t ss;
147 uint16_t sp;
148 uint16_t checksum;
149 uint16_t ip;
150 uint16_t cs;
151 uint16_t reloc_table_offset;
152 uint16_t overlay_num;
153 uint16_t reserved0[4];
154 uint16_t oem_id;
155 uint16_t oem_info;
156 uint16_t reserved1[10];
157 uint32_t peaddr;
158 char message[];
159 };
160
161 struct mz_reloc {
162 uint16_t offset;
163 uint16_t segment;
164 };
165
166 struct pe_hdr {
167 uint32_t magic;
168 uint16_t machine;
169 uint16_t sections;
170 uint32_t timestamp;
171 uint32_t symbol_table;
172 uint32_t symbols;
173 uint16_t opt_hdr_size;
174 uint16_t flags;
175 };
176
177
178
179 struct pe32_opt_hdr {
180
181 uint16_t magic;
182 uint8_t ld_major;
183 uint8_t ld_minor;
184 uint32_t text_size;
185 uint32_t data_size;
186 uint32_t bss_size;
187 uint32_t entry_point;
188 uint32_t code_base;
189 uint32_t data_base;
190
191 uint32_t image_base;
192 uint32_t section_align;
193 uint32_t file_align;
194 uint16_t os_major;
195 uint16_t os_minor;
196 uint16_t image_major;
197 uint16_t image_minor;
198 uint16_t subsys_major;
199 uint16_t subsys_minor;
200 uint32_t win32_version;
201 uint32_t image_size;
202 uint32_t header_size;
203
204 uint32_t csum;
205 uint16_t subsys;
206 uint16_t dll_flags;
207 uint32_t stack_size_req;
208 uint32_t stack_size;
209 uint32_t heap_size_req;
210 uint32_t heap_size;
211 uint32_t loader_flags;
212 uint32_t data_dirs;
213 };
214
215 struct pe32plus_opt_hdr {
216 uint16_t magic;
217 uint8_t ld_major;
218 uint8_t ld_minor;
219 uint32_t text_size;
220 uint32_t data_size;
221 uint32_t bss_size;
222 uint32_t entry_point;
223 uint32_t code_base;
224
225 uint64_t image_base;
226 uint32_t section_align;
227 uint32_t file_align;
228 uint16_t os_major;
229 uint16_t os_minor;
230 uint16_t image_major;
231 uint16_t image_minor;
232 uint16_t subsys_major;
233 uint16_t subsys_minor;
234 uint32_t win32_version;
235 uint32_t image_size;
236 uint32_t header_size;
237
238 uint32_t csum;
239 uint16_t subsys;
240 uint16_t dll_flags;
241 uint64_t stack_size_req;
242 uint64_t stack_size;
243 uint64_t heap_size_req;
244 uint64_t heap_size;
245 uint32_t loader_flags;
246 uint32_t data_dirs;
247 };
248
249 struct data_dirent {
250 uint32_t virtual_address;
251 uint32_t size;
252 };
253
254 struct data_directory {
255 struct data_dirent exports;
256 struct data_dirent imports;
257 struct data_dirent resources;
258 struct data_dirent exceptions;
259 struct data_dirent certs;
260 struct data_dirent base_relocations;
261 struct data_dirent debug;
262 struct data_dirent arch;
263 struct data_dirent global_ptr;
264 struct data_dirent tls;
265 struct data_dirent load_config;
266 struct data_dirent bound_imports;
267 struct data_dirent import_addrs;
268 struct data_dirent delay_imports;
269 struct data_dirent clr_runtime_hdr;
270 struct data_dirent reserved;
271 };
272
273 struct section_header {
274 char name[8];
275 uint32_t virtual_size;
276 uint32_t virtual_address;
277 uint32_t raw_data_size;
278 uint32_t data_addr;
279 uint32_t relocs;
280 uint32_t line_numbers;
281 uint16_t num_relocs;
282 uint16_t num_lin_numbers;
283 uint32_t flags;
284 };
285
286 enum x64_coff_reloc_type {
287 IMAGE_REL_AMD64_ABSOLUTE = 0,
288 IMAGE_REL_AMD64_ADDR64,
289 IMAGE_REL_AMD64_ADDR32,
290 IMAGE_REL_AMD64_ADDR32N,
291 IMAGE_REL_AMD64_REL32,
292 IMAGE_REL_AMD64_REL32_1,
293 IMAGE_REL_AMD64_REL32_2,
294 IMAGE_REL_AMD64_REL32_3,
295 IMAGE_REL_AMD64_REL32_4,
296 IMAGE_REL_AMD64_REL32_5,
297 IMAGE_REL_AMD64_SECTION,
298 IMAGE_REL_AMD64_SECREL,
299 IMAGE_REL_AMD64_SECREL7,
300 IMAGE_REL_AMD64_TOKEN,
301 IMAGE_REL_AMD64_SREL32,
302 IMAGE_REL_AMD64_PAIR,
303 IMAGE_REL_AMD64_SSPAN32,
304 };
305
306 enum arm_coff_reloc_type {
307 IMAGE_REL_ARM_ABSOLUTE,
308 IMAGE_REL_ARM_ADDR32,
309 IMAGE_REL_ARM_ADDR32N,
310 IMAGE_REL_ARM_BRANCH2,
311 IMAGE_REL_ARM_BRANCH1,
312 IMAGE_REL_ARM_SECTION,
313 IMAGE_REL_ARM_SECREL,
314 };
315
316 enum sh_coff_reloc_type {
317 IMAGE_REL_SH3_ABSOLUTE,
318 IMAGE_REL_SH3_DIRECT16,
319 IMAGE_REL_SH3_DIRECT32,
320 IMAGE_REL_SH3_DIRECT8,
321 IMAGE_REL_SH3_DIRECT8_WORD,
322 IMAGE_REL_SH3_DIRECT8_LONG,
323 IMAGE_REL_SH3_DIRECT4,
324 IMAGE_REL_SH3_DIRECT4_WORD,
325 IMAGE_REL_SH3_DIRECT4_LONG,
326 IMAGE_REL_SH3_PCREL8_WORD,
327 IMAGE_REL_SH3_PCREL8_LONG,
328 IMAGE_REL_SH3_PCREL12_WORD,
329 IMAGE_REL_SH3_STARTOF_SECTION,
330 IMAGE_REL_SH3_SIZEOF_SECTION,
331 IMAGE_REL_SH3_SECTION,
332 IMAGE_REL_SH3_SECREL,
333 IMAGE_REL_SH3_DIRECT32_NB,
334 IMAGE_REL_SH3_GPREL4_LONG,
335 IMAGE_REL_SH3_TOKEN,
336 IMAGE_REL_SHM_PCRELPT,
337 IMAGE_REL_SHM_REFLO,
338 IMAGE_REL_SHM_REFHALF,
339 IMAGE_REL_SHM_RELLO,
340 IMAGE_REL_SHM_RELHALF,
341 IMAGE_REL_SHM_PAIR,
342 IMAGE_REL_SHM_NOMODE,
343 };
344
345 enum ppc_coff_reloc_type {
346 IMAGE_REL_PPC_ABSOLUTE,
347 IMAGE_REL_PPC_ADDR64,
348 IMAGE_REL_PPC_ADDR32,
349 IMAGE_REL_PPC_ADDR24,
350 IMAGE_REL_PPC_ADDR16,
351 IMAGE_REL_PPC_ADDR14,
352 IMAGE_REL_PPC_REL24,
353 IMAGE_REL_PPC_REL14,
354 IMAGE_REL_PPC_ADDR32N,
355 IMAGE_REL_PPC_SECREL,
356 IMAGE_REL_PPC_SECTION,
357 IMAGE_REL_PPC_SECREL16,
358 IMAGE_REL_PPC_REFHI,
359 IMAGE_REL_PPC_REFLO,
360 IMAGE_REL_PPC_PAIR,
361 IMAGE_REL_PPC_SECRELLO,
362 IMAGE_REL_PPC_GPREL,
363 IMAGE_REL_PPC_TOKEN,
364 };
365
366 enum x86_coff_reloc_type {
367 IMAGE_REL_I386_ABSOLUTE,
368 IMAGE_REL_I386_DIR16,
369 IMAGE_REL_I386_REL16,
370 IMAGE_REL_I386_DIR32,
371 IMAGE_REL_I386_DIR32NB,
372 IMAGE_REL_I386_SEG12,
373 IMAGE_REL_I386_SECTION,
374 IMAGE_REL_I386_SECREL,
375 IMAGE_REL_I386_TOKEN,
376 IMAGE_REL_I386_SECREL7,
377 IMAGE_REL_I386_REL32,
378 };
379
380 enum ia64_coff_reloc_type {
381 IMAGE_REL_IA64_ABSOLUTE,
382 IMAGE_REL_IA64_IMM14,
383 IMAGE_REL_IA64_IMM22,
384 IMAGE_REL_IA64_IMM64,
385 IMAGE_REL_IA64_DIR32,
386 IMAGE_REL_IA64_DIR64,
387 IMAGE_REL_IA64_PCREL21B,
388 IMAGE_REL_IA64_PCREL21M,
389 IMAGE_REL_IA64_PCREL21F,
390 IMAGE_REL_IA64_GPREL22,
391 IMAGE_REL_IA64_LTOFF22,
392 IMAGE_REL_IA64_SECTION,
393 IMAGE_REL_IA64_SECREL22,
394 IMAGE_REL_IA64_SECREL64I,
395 IMAGE_REL_IA64_SECREL32,
396 IMAGE_REL_IA64_DIR32NB,
397 IMAGE_REL_IA64_SREL14,
398 IMAGE_REL_IA64_SREL22,
399 IMAGE_REL_IA64_SREL32,
400 IMAGE_REL_IA64_UREL32,
401 IMAGE_REL_IA64_PCREL60X,
402 IMAGE_REL_IA64_PCREL60B,
403 IMAGE_REL_IA64_PCREL60F,
404 IMAGE_REL_IA64_PCREL60I,
405 IMAGE_REL_IA64_PCREL60M,
406 IMAGE_REL_IA64_IMMGPREL6,
407 IMAGE_REL_IA64_TOKEN,
408 IMAGE_REL_IA64_GPREL32,
409 IMAGE_REL_IA64_ADDEND,
410 };
411
412 struct coff_reloc {
413 uint32_t virtual_address;
414 uint32_t symbol_table_index;
415 union {
416 enum x64_coff_reloc_type x64_type;
417 enum arm_coff_reloc_type arm_type;
418 enum sh_coff_reloc_type sh_type;
419 enum ppc_coff_reloc_type ppc_type;
420 enum x86_coff_reloc_type x86_type;
421 enum ia64_coff_reloc_type ia64_type;
422 uint16_t data;
423 };
424 };
425
426
427
428
429 #define WIN_CERT_TYPE_PKCS_SIGNED_DATA 0x0002
430 #define WIN_CERT_TYPE_EFI_OKCS115 0x0EF0
431 #define WIN_CERT_TYPE_EFI_GUID 0x0EF1
432
433 #define WIN_CERT_REVISION_1_0 0x0100
434 #define WIN_CERT_REVISION_2_0 0x0200
435
436 struct win_certificate {
437 uint32_t length;
438 uint16_t revision;
439 uint16_t cert_type;
440 };
441
442 #endif
443
444 #endif