iPXE
PeImage.h
Go to the documentation of this file.
1/** @file
2 EFI image format for PE32, PE32+ and TE. Please note some data structures are
3 different for PE32 and PE32+. EFI_IMAGE_NT_HEADERS32 is for PE32 and
4 EFI_IMAGE_NT_HEADERS64 is for PE32+.
5
6 This file is coded to the Visual Studio, Microsoft Portable Executable and
7 Common Object File Format Specification, Revision 9.3 - December 29, 2015.
8 This file also includes some definitions in PI Specification, Revision 1.0.
9
10Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
11Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
12Portions Copyright (c) 2016 - 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
13Portions Copyright (c) 2022, Loongson Technology Corporation Limited. All rights reserved.<BR>
14
15SPDX-License-Identifier: BSD-2-Clause-Patent
16
17**/
18
19#pragma once
20
21FILE_LICENCE ( BSD2_PATENT );
22FILE_SECBOOT ( PERMITTED );
23
24//
25// PE32+ Subsystem type for EFI images
26//
27#define EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION 10
28#define EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11
29#define EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12
30
31//
32// PE32+ Machine type for EFI images
33//
34#define IMAGE_FILE_MACHINE_I386 0x014c
35#define IMAGE_FILE_MACHINE_IA64 0x0200
36#define IMAGE_FILE_MACHINE_EBC 0x0EBC
37#define IMAGE_FILE_MACHINE_X64 0x8664
38#define IMAGE_FILE_MACHINE_ARMTHUMB_MIXED 0x01c2
39#define IMAGE_FILE_MACHINE_ARM64 0xAA64
40#define IMAGE_FILE_MACHINE_RISCV32 0x5032
41#define IMAGE_FILE_MACHINE_RISCV64 0x5064
42#define IMAGE_FILE_MACHINE_RISCV128 0x5128
43#define IMAGE_FILE_MACHINE_LOONGARCH32 0x6232
44#define IMAGE_FILE_MACHINE_LOONGARCH64 0x6264
45
46//
47// EXE file formats
48//
49#define EFI_IMAGE_DOS_SIGNATURE SIGNATURE_16('M', 'Z')
50#define EFI_IMAGE_OS2_SIGNATURE SIGNATURE_16('N', 'E')
51#define EFI_IMAGE_OS2_SIGNATURE_LE SIGNATURE_16('L', 'E')
52#define EFI_IMAGE_NT_SIGNATURE SIGNATURE_32('P', 'E', '\0', '\0')
53
54///
55/// PE images can start with an optional DOS header, so if an image is run
56/// under DOS it can print an error message.
57///
58typedef struct {
59 UINT16 e_magic; ///< Magic number.
60 UINT16 e_cblp; ///< Bytes on last page of file.
61 UINT16 e_cp; ///< Pages in file.
62 UINT16 e_crlc; ///< Relocations.
63 UINT16 e_cparhdr; ///< Size of header in paragraphs.
64 UINT16 e_minalloc; ///< Minimum extra paragraphs needed.
65 UINT16 e_maxalloc; ///< Maximum extra paragraphs needed.
66 UINT16 e_ss; ///< Initial (relative) SS value.
67 UINT16 e_sp; ///< Initial SP value.
68 UINT16 e_csum; ///< Checksum.
69 UINT16 e_ip; ///< Initial IP value.
70 UINT16 e_cs; ///< Initial (relative) CS value.
71 UINT16 e_lfarlc; ///< File address of relocation table.
72 UINT16 e_ovno; ///< Overlay number.
73 UINT16 e_res[4]; ///< Reserved words.
74 UINT16 e_oemid; ///< OEM identifier (for e_oeminfo).
75 UINT16 e_oeminfo; ///< OEM information; e_oemid specific.
76 UINT16 e_res2[10]; ///< Reserved words.
77 UINT32 e_lfanew; ///< File address of new exe header.
79
80///
81/// COFF File Header (Object and Image).
82///
92
93///
94/// Size of EFI_IMAGE_FILE_HEADER.
95///
96#define EFI_IMAGE_SIZEOF_FILE_HEADER 20
97
98//
99// Characteristics
100//
101#define EFI_IMAGE_FILE_RELOCS_STRIPPED BIT0 ///< 0x0001 Relocation info stripped from file.
102#define EFI_IMAGE_FILE_EXECUTABLE_IMAGE BIT1 ///< 0x0002 File is executable (i.e. no unresolved externel references).
103#define EFI_IMAGE_FILE_LINE_NUMS_STRIPPED BIT2 ///< 0x0004 Line numbers stripped from file.
104#define EFI_IMAGE_FILE_LOCAL_SYMS_STRIPPED BIT3 ///< 0x0008 Local symbols stripped from file.
105#define EFI_IMAGE_FILE_LARGE_ADDRESS_AWARE BIT5 ///< 0x0020 Supports addresses > 2-GB
106#define EFI_IMAGE_FILE_BYTES_REVERSED_LO BIT7 ///< 0x0080 Bytes of machine word are reversed.
107#define EFI_IMAGE_FILE_32BIT_MACHINE BIT8 ///< 0x0100 32 bit word machine.
108#define EFI_IMAGE_FILE_DEBUG_STRIPPED BIT9 ///< 0x0200 Debugging info stripped from file in .DBG file.
109#define EFI_IMAGE_FILE_SYSTEM BIT12 ///< 0x1000 System File.
110#define EFI_IMAGE_FILE_DLL BIT13 ///< 0x2000 File is a DLL.
111#define EFI_IMAGE_FILE_BYTES_REVERSED_HI BIT15 ///< 0x8000 Bytes of machine word are reversed.
112
113///
114/// Header Data Directories.
115///
120
121//
122// Directory Entries
123//
124#define EFI_IMAGE_DIRECTORY_ENTRY_EXPORT 0
125#define EFI_IMAGE_DIRECTORY_ENTRY_IMPORT 1
126#define EFI_IMAGE_DIRECTORY_ENTRY_RESOURCE 2
127#define EFI_IMAGE_DIRECTORY_ENTRY_EXCEPTION 3
128#define EFI_IMAGE_DIRECTORY_ENTRY_SECURITY 4
129#define EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC 5
130#define EFI_IMAGE_DIRECTORY_ENTRY_DEBUG 6
131#define EFI_IMAGE_DIRECTORY_ENTRY_COPYRIGHT 7
132#define EFI_IMAGE_DIRECTORY_ENTRY_GLOBALPTR 8
133#define EFI_IMAGE_DIRECTORY_ENTRY_TLS 9
134#define EFI_IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10
135
136#define EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES 16
137
138///
139/// @attention
140/// EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC means PE32 and
141/// EFI_IMAGE_OPTIONAL_HEADER32 must be used. The data structures only vary
142/// after NT additional fields.
143///
144#define EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC 0x10b
145
146///
147/// Optional Header Standard Fields for PE32.
148///
188
189///
190/// @attention
191/// EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC means PE32+ and
192/// EFI_IMAGE_OPTIONAL_HEADER64 must be used. The data structures only vary
193/// after NT additional fields.
194///
195#define EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x20b
196
197///
198/// Optional Header Standard Fields for PE32+.
199///
238
239///
240/// @attention
241/// EFI_IMAGE_NT_HEADERS32 is for use ONLY by tools.
242///
248
249#define EFI_IMAGE_SIZEOF_NT_OPTIONAL32_HEADER sizeof (EFI_IMAGE_NT_HEADERS32)
250
251///
252/// @attention
253/// EFI_IMAGE_HEADERS64 is for use ONLY by tools.
254///
260
261#define EFI_IMAGE_SIZEOF_NT_OPTIONAL64_HEADER sizeof (EFI_IMAGE_NT_HEADERS64)
262
263//
264// Other Windows Subsystem Values
265//
266#define EFI_IMAGE_SUBSYSTEM_UNKNOWN 0
267#define EFI_IMAGE_SUBSYSTEM_NATIVE 1
268#define EFI_IMAGE_SUBSYSTEM_WINDOWS_GUI 2
269#define EFI_IMAGE_SUBSYSTEM_WINDOWS_CUI 3
270#define EFI_IMAGE_SUBSYSTEM_OS2_CUI 5
271#define EFI_IMAGE_SUBSYSTEM_POSIX_CUI 7
272
273//
274// DLL Characteristics
275//
276#define IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA 0x0020
277#define IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE 0x0040
278#define IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY 0x0080
279#define IMAGE_DLLCHARACTERISTICS_NX_COMPAT 0x0100
280#define IMAGE_DLLCHARACTERISTICS_NO_ISOLATION 0x0200
281#define IMAGE_DLLCHARACTERISTICS_NO_SEH 0x0400
282#define IMAGE_DLLCHARACTERISTICS_NO_BIND 0x0800
283#define IMAGE_DLLCHARACTERISTICS_APPCONTAINER 0x1000
284#define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER 0x2000
285#define IMAGE_DLLCHARACTERISTICS_GUARD_CF 0x4000
286#define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE 0x8000
287
288///
289/// Length of ShortName.
290///
291#define EFI_IMAGE_SIZEOF_SHORT_NAME 8
292
293///
294/// Section Table. This table immediately follows the optional header.
295///
311
312///
313/// Size of EFI_IMAGE_SECTION_HEADER.
314///
315#define EFI_IMAGE_SIZEOF_SECTION_HEADER 40
316
317//
318// Section Flags Values
319//
320#define EFI_IMAGE_SCN_TYPE_NO_PAD BIT3 ///< 0x00000008 ///< Reserved.
321#define EFI_IMAGE_SCN_CNT_CODE BIT5 ///< 0x00000020
322#define EFI_IMAGE_SCN_CNT_INITIALIZED_DATA BIT6 ///< 0x00000040
323#define EFI_IMAGE_SCN_CNT_UNINITIALIZED_DATA BIT7 ///< 0x00000080
324
325#define EFI_IMAGE_SCN_LNK_OTHER BIT8 ///< 0x00000100 ///< Reserved.
326#define EFI_IMAGE_SCN_LNK_INFO BIT9 ///< 0x00000200 ///< Section contains comments or some other type of information.
327#define EFI_IMAGE_SCN_LNK_REMOVE BIT11 ///< 0x00000800 ///< Section contents will not become part of image.
328#define EFI_IMAGE_SCN_LNK_COMDAT BIT12 ///< 0x00001000
329
330#define EFI_IMAGE_SCN_ALIGN_1BYTES BIT20 ///< 0x00100000
331#define EFI_IMAGE_SCN_ALIGN_2BYTES BIT21 ///< 0x00200000
332#define EFI_IMAGE_SCN_ALIGN_4BYTES (BIT20|BIT21) ///< 0x00300000
333#define EFI_IMAGE_SCN_ALIGN_8BYTES BIT22 ///< 0x00400000
334#define EFI_IMAGE_SCN_ALIGN_16BYTES (BIT20|BIT22) ///< 0x00500000
335#define EFI_IMAGE_SCN_ALIGN_32BYTES (BIT21|BIT22) ///< 0x00600000
336#define EFI_IMAGE_SCN_ALIGN_64BYTES (BIT20|BIT21|BIT22) ///< 0x00700000
337
338#define EFI_IMAGE_SCN_MEM_DISCARDABLE BIT25 ///< 0x02000000
339#define EFI_IMAGE_SCN_MEM_NOT_CACHED BIT26 ///< 0x04000000
340#define EFI_IMAGE_SCN_MEM_NOT_PAGED BIT27 ///< 0x08000000
341#define EFI_IMAGE_SCN_MEM_SHARED BIT28 ///< 0x10000000
342#define EFI_IMAGE_SCN_MEM_EXECUTE BIT29 ///< 0x20000000
343#define EFI_IMAGE_SCN_MEM_READ BIT30 ///< 0x40000000
344#define EFI_IMAGE_SCN_MEM_WRITE BIT31 ///< 0x80000000
345
346///
347/// Size of a Symbol Table Record.
348///
349#define EFI_IMAGE_SIZEOF_SYMBOL 18
350
351//
352// Symbols have a section number of the section in which they are
353// defined. Otherwise, section numbers have the following meanings:
354//
355#define EFI_IMAGE_SYM_UNDEFINED (UINT16) 0 ///< Symbol is undefined or is common.
356#define EFI_IMAGE_SYM_ABSOLUTE (UINT16) -1 ///< Symbol is an absolute value.
357#define EFI_IMAGE_SYM_DEBUG (UINT16) -2 ///< Symbol is a special debug item.
358
359//
360// Symbol Type (fundamental) values.
361//
362#define EFI_IMAGE_SYM_TYPE_NULL 0 ///< no type.
363#define EFI_IMAGE_SYM_TYPE_VOID 1 ///< no valid type.
364#define EFI_IMAGE_SYM_TYPE_CHAR 2 ///< type character.
365#define EFI_IMAGE_SYM_TYPE_SHORT 3 ///< type short integer.
366#define EFI_IMAGE_SYM_TYPE_INT 4
367#define EFI_IMAGE_SYM_TYPE_LONG 5
368#define EFI_IMAGE_SYM_TYPE_FLOAT 6
369#define EFI_IMAGE_SYM_TYPE_DOUBLE 7
370#define EFI_IMAGE_SYM_TYPE_STRUCT 8
371#define EFI_IMAGE_SYM_TYPE_UNION 9
372#define EFI_IMAGE_SYM_TYPE_ENUM 10 ///< enumeration.
373#define EFI_IMAGE_SYM_TYPE_MOE 11 ///< member of enumeration.
374#define EFI_IMAGE_SYM_TYPE_BYTE 12
375#define EFI_IMAGE_SYM_TYPE_WORD 13
376#define EFI_IMAGE_SYM_TYPE_UINT 14
377#define EFI_IMAGE_SYM_TYPE_DWORD 15
378
379//
380// Symbol Type (derived) values.
381//
382#define EFI_IMAGE_SYM_DTYPE_NULL 0 ///< no derived type.
383#define EFI_IMAGE_SYM_DTYPE_POINTER 1
384#define EFI_IMAGE_SYM_DTYPE_FUNCTION 2
385#define EFI_IMAGE_SYM_DTYPE_ARRAY 3
386
387//
388// Storage classes.
389//
390#define EFI_IMAGE_SYM_CLASS_END_OF_FUNCTION ((UINT8) -1)
391#define EFI_IMAGE_SYM_CLASS_NULL 0
392#define EFI_IMAGE_SYM_CLASS_AUTOMATIC 1
393#define EFI_IMAGE_SYM_CLASS_EXTERNAL 2
394#define EFI_IMAGE_SYM_CLASS_STATIC 3
395#define EFI_IMAGE_SYM_CLASS_REGISTER 4
396#define EFI_IMAGE_SYM_CLASS_EXTERNAL_DEF 5
397#define EFI_IMAGE_SYM_CLASS_LABEL 6
398#define EFI_IMAGE_SYM_CLASS_UNDEFINED_LABEL 7
399#define EFI_IMAGE_SYM_CLASS_MEMBER_OF_STRUCT 8
400#define EFI_IMAGE_SYM_CLASS_ARGUMENT 9
401#define EFI_IMAGE_SYM_CLASS_STRUCT_TAG 10
402#define EFI_IMAGE_SYM_CLASS_MEMBER_OF_UNION 11
403#define EFI_IMAGE_SYM_CLASS_UNION_TAG 12
404#define EFI_IMAGE_SYM_CLASS_TYPE_DEFINITION 13
405#define EFI_IMAGE_SYM_CLASS_UNDEFINED_STATIC 14
406#define EFI_IMAGE_SYM_CLASS_ENUM_TAG 15
407#define EFI_IMAGE_SYM_CLASS_MEMBER_OF_ENUM 16
408#define EFI_IMAGE_SYM_CLASS_REGISTER_PARAM 17
409#define EFI_IMAGE_SYM_CLASS_BIT_FIELD 18
410#define EFI_IMAGE_SYM_CLASS_BLOCK 100
411#define EFI_IMAGE_SYM_CLASS_FUNCTION 101
412#define EFI_IMAGE_SYM_CLASS_END_OF_STRUCT 102
413#define EFI_IMAGE_SYM_CLASS_FILE 103
414#define EFI_IMAGE_SYM_CLASS_SECTION 104
415#define EFI_IMAGE_SYM_CLASS_WEAK_EXTERNAL 105
416
417//
418// type packing constants
419//
420#define EFI_IMAGE_N_BTMASK 017
421#define EFI_IMAGE_N_TMASK 060
422#define EFI_IMAGE_N_TMASK1 0300
423#define EFI_IMAGE_N_TMASK2 0360
424#define EFI_IMAGE_N_BTSHFT 4
425#define EFI_IMAGE_N_TSHIFT 2
426
427//
428// Communal selection types.
429//
430#define EFI_IMAGE_COMDAT_SELECT_NODUPLICATES 1
431#define EFI_IMAGE_COMDAT_SELECT_ANY 2
432#define EFI_IMAGE_COMDAT_SELECT_SAME_SIZE 3
433#define EFI_IMAGE_COMDAT_SELECT_EXACT_MATCH 4
434#define EFI_IMAGE_COMDAT_SELECT_ASSOCIATIVE 5
435
436//
437// the following values only be referred in PeCoff, not defined in PECOFF.
438//
439#define EFI_IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY 1
440#define EFI_IMAGE_WEAK_EXTERN_SEARCH_LIBRARY 2
441#define EFI_IMAGE_WEAK_EXTERN_SEARCH_ALIAS 3
442
443///
444/// Relocation format.
445///
451
452///
453/// Size of EFI_IMAGE_RELOCATION
454///
455#define EFI_IMAGE_SIZEOF_RELOCATION 10
456
457//
458// I386 relocation types.
459//
460#define EFI_IMAGE_REL_I386_ABSOLUTE 0x0000 ///< Reference is absolute, no relocation is necessary.
461#define EFI_IMAGE_REL_I386_DIR16 0x0001 ///< Direct 16-bit reference to the symbols virtual address.
462#define EFI_IMAGE_REL_I386_REL16 0x0002 ///< PC-relative 16-bit reference to the symbols virtual address.
463#define EFI_IMAGE_REL_I386_DIR32 0x0006 ///< Direct 32-bit reference to the symbols virtual address.
464#define EFI_IMAGE_REL_I386_DIR32NB 0x0007 ///< Direct 32-bit reference to the symbols virtual address, base not included.
465#define EFI_IMAGE_REL_I386_SEG12 0x0009 ///< Direct 16-bit reference to the segment-selector bits of a 32-bit virtual address.
466#define EFI_IMAGE_REL_I386_SECTION 0x000A
467#define EFI_IMAGE_REL_I386_SECREL 0x000B
468#define EFI_IMAGE_REL_I386_REL32 0x0014 ///< PC-relative 32-bit reference to the symbols virtual address.
469
470//
471// x64 processor relocation types.
472//
473#define IMAGE_REL_AMD64_ABSOLUTE 0x0000
474#define IMAGE_REL_AMD64_ADDR64 0x0001
475#define IMAGE_REL_AMD64_ADDR32 0x0002
476#define IMAGE_REL_AMD64_ADDR32NB 0x0003
477#define IMAGE_REL_AMD64_REL32 0x0004
478#define IMAGE_REL_AMD64_REL32_1 0x0005
479#define IMAGE_REL_AMD64_REL32_2 0x0006
480#define IMAGE_REL_AMD64_REL32_3 0x0007
481#define IMAGE_REL_AMD64_REL32_4 0x0008
482#define IMAGE_REL_AMD64_REL32_5 0x0009
483#define IMAGE_REL_AMD64_SECTION 0x000A
484#define IMAGE_REL_AMD64_SECREL 0x000B
485#define IMAGE_REL_AMD64_SECREL7 0x000C
486#define IMAGE_REL_AMD64_TOKEN 0x000D
487#define IMAGE_REL_AMD64_SREL32 0x000E
488#define IMAGE_REL_AMD64_PAIR 0x000F
489#define IMAGE_REL_AMD64_SSPAN32 0x0010
490
491///
492/// Based relocation format.
493///
498
499///
500/// Size of EFI_IMAGE_BASE_RELOCATION.
501///
502#define EFI_IMAGE_SIZEOF_BASE_RELOCATION 8
503
504//
505// Based relocation types.
506//
507#define EFI_IMAGE_REL_BASED_ABSOLUTE 0
508#define EFI_IMAGE_REL_BASED_HIGH 1
509#define EFI_IMAGE_REL_BASED_LOW 2
510#define EFI_IMAGE_REL_BASED_HIGHLOW 3
511#define EFI_IMAGE_REL_BASED_HIGHADJ 4
512#define EFI_IMAGE_REL_BASED_MIPS_JMPADDR 5
513#define EFI_IMAGE_REL_BASED_ARM_MOV32A 5
514#define EFI_IMAGE_REL_BASED_ARM_MOV32T 7
515#define EFI_IMAGE_REL_BASED_IA64_IMM64 9
516#define EFI_IMAGE_REL_BASED_MIPS_JMPADDR16 9
517#define EFI_IMAGE_REL_BASED_DIR64 10
518
519///
520/// Relocation types of RISC-V processor.
521///
522#define EFI_IMAGE_REL_BASED_RISCV_HI20 5
523#define EFI_IMAGE_REL_BASED_RISCV_LOW12I 7
524#define EFI_IMAGE_REL_BASED_RISCV_LOW12S 8
525
526//
527// Relocation types of LoongArch processor.
528//
529#define EFI_IMAGE_REL_BASED_LOONGARCH32_MARK_LA 8
530#define EFI_IMAGE_REL_BASED_LOONGARCH64_MARK_LA 8
531
532///
533/// Line number format.
534///
535typedef struct {
536 union {
537 UINT32 SymbolTableIndex; ///< Symbol table index of function name if Linenumber is 0.
538 UINT32 VirtualAddress; ///< Virtual address of line number.
540 UINT16 Linenumber; ///< Line number.
542
543///
544/// Size of EFI_IMAGE_LINENUMBER.
545///
546#define EFI_IMAGE_SIZEOF_LINENUMBER 6
547
548//
549// Archive format.
550//
551#define EFI_IMAGE_ARCHIVE_START_SIZE 8
552#define EFI_IMAGE_ARCHIVE_START "!<arch>\n"
553#define EFI_IMAGE_ARCHIVE_END "`\n"
554#define EFI_IMAGE_ARCHIVE_PAD "\n"
555#define EFI_IMAGE_ARCHIVE_LINKER_MEMBER "/ "
556#define EFI_IMAGE_ARCHIVE_LONGNAMES_MEMBER "// "
557
558///
559/// Archive Member Headers
560///
561typedef struct {
562 UINT8 Name[16]; ///< File member name - `/' terminated.
563 UINT8 Date[12]; ///< File member date - decimal.
564 UINT8 UserID[6]; ///< File member user id - decimal.
565 UINT8 GroupID[6]; ///< File member group id - decimal.
566 UINT8 Mode[8]; ///< File member mode - octal.
567 UINT8 Size[10]; ///< File member size - decimal.
568 UINT8 EndHeader[2]; ///< String to end header. (0x60 0x0A).
570
571///
572/// Size of EFI_IMAGE_ARCHIVE_MEMBER_HEADER.
573///
574#define EFI_IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR 60
575
576//
577// DLL Support
578//
579
580///
581/// Export Directory Table.
582///
596
597//
598// Based export types.
599//
600#define EFI_IMAGE_EXPORT_ORDINAL_BASE 1
601#define EFI_IMAGE_EXPORT_ADDR_SIZE 4
602#define EFI_IMAGE_EXPORT_ORDINAL_SIZE 2
603
604///
605/// Hint/Name Table.
606///
611
612///
613/// Import Address Table RVA (Thunk Table).
614///
622
623#define EFI_IMAGE_ORDINAL_FLAG BIT31 ///< Flag for PE32.
624#define EFI_IMAGE_SNAP_BY_ORDINAL(Ordinal) ((Ordinal & EFI_IMAGE_ORDINAL_FLAG) != 0)
625#define EFI_IMAGE_ORDINAL(Ordinal) (Ordinal & 0xffff)
626
627///
628/// Import Directory Table
629///
637
638///
639/// Debug Directory Format.
640///
641typedef struct {
648 UINT32 RVA; ///< The address of the debug data when loaded, relative to the image base.
649 UINT32 FileOffset; ///< The file pointer to the debug data.
651
652#define EFI_IMAGE_DEBUG_TYPE_CODEVIEW 2 ///< The Visual C++ debug information.
653#define EFI_IMAGE_DEBUG_TYPE_EX_DLLCHARACTERISTICS 20
654
655///
656/// Debug Data Structure defined in Microsoft C++.
657///
658#define CODEVIEW_SIGNATURE_NB10 SIGNATURE_32('N', 'B', '1', '0')
659typedef struct {
660 UINT32 Signature; ///< "NB10"
664 //
665 // Filename of .PDB goes here
666 //
668
669///
670/// Debug Data Structure defined in Microsoft C++.
671///
672#define CODEVIEW_SIGNATURE_RSDS SIGNATURE_32('R', 'S', 'D', 'S')
673typedef struct {
674 UINT32 Signature; ///< "RSDS".
680 //
681 // Filename of .PDB goes here
682 //
684
685///
686/// Debug Data Structure defined by Apple Mach-O to Coff utility.
687///
688#define CODEVIEW_SIGNATURE_MTOC SIGNATURE_32('M', 'T', 'O', 'C')
689typedef struct {
690 UINT32 Signature; ///< "MTOC".
692 //
693 // Filename of .DLL (Mach-O with debug info) goes here
694 //
696
697//
698// .pdata entries for X64
699//
705
714
715///
716/// Extended DLL Characteristics
717///
718#define EFI_IMAGE_DLLCHARACTERISTICS_EX_CET_COMPAT 0x0001
719#define EFI_IMAGE_DLLCHARACTERISTICS_EX_FORWARD_CFI_COMPAT 0x0040
720
724
725///
726/// Resource format.
727///
728typedef struct {
735 //
736 // Array of EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY entries goes here.
737 //
739
740///
741/// Resource directory entry format.
742///
743typedef struct {
744 union {
745 struct {
748 } s;
750 } u1;
751 union {
753 struct {
756 } s;
757 } u2;
759
760///
761/// Resource directory entry for string.
762///
767
768///
769/// Resource directory entry for data array.
770///
777
778///
779/// Header format for TE images, defined in the PI Specification, 1.0.
780///
781typedef struct {
782 UINT16 Signature; ///< The signature for TE format = "VZ".
783 UINT16 Machine; ///< From the original file header.
784 UINT8 NumberOfSections; ///< From the original file header.
785 UINT8 Subsystem; ///< From original optional header.
786 UINT16 StrippedSize; ///< Number of bytes we removed from the header.
787 UINT32 AddressOfEntryPoint; ///< Offset to entry point -- from original optional header.
788 UINT32 BaseOfCode; ///< From original image -- required for ITP debug.
789 UINT64 ImageBase; ///< From original file header.
790 EFI_IMAGE_DATA_DIRECTORY DataDirectory[2]; ///< Only base relocation and debug directory.
792
793#define EFI_TE_IMAGE_HEADER_SIGNATURE SIGNATURE_16('V', 'Z')
794
795//
796// Data directory indexes in our TE image header
797//
798#define EFI_TE_IMAGE_DIRECTORY_ENTRY_BASERELOC 0
799#define EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG 1
800
801///
802/// Union of PE32, PE32+, and TE headers.
803///
809
unsigned short UINT16
2-byte unsigned value.
unsigned long long UINT64
8-byte unsigned value.
unsigned short CHAR16
2-byte Character.
unsigned char UINT8
1-byte unsigned value.
unsigned int UINT32
4-byte unsigned value.
UINT8 Type
Definition Acpi10.h:136
#define EFI_IMAGE_SIZEOF_SHORT_NAME
Length of ShortName.
Definition PeImage.h:291
#define EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES
Definition PeImage.h:136
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:921
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:951
Archive Member Headers.
Definition PeImage.h:561
UINT8 Size[10]
File member size - decimal.
Definition PeImage.h:567
UINT8 GroupID[6]
File member group id - decimal.
Definition PeImage.h:565
UINT8 Name[16]
File member name - ‘/’ terminated.
Definition PeImage.h:562
UINT8 Mode[8]
File member mode - octal.
Definition PeImage.h:566
UINT8 UserID[6]
File member user id - decimal.
Definition PeImage.h:564
UINT8 Date[12]
File member date - decimal.
Definition PeImage.h:563
UINT8 EndHeader[2]
String to end header. (0x60 0x0A).
Definition PeImage.h:568
Based relocation format.
Definition PeImage.h:494
Header Data Directories.
Definition PeImage.h:116
Definition PeImage.h:689
GUID MachOUuid
Definition PeImage.h:691
UINT32 Signature
"MTOC".
Definition PeImage.h:690
Definition PeImage.h:659
UINT32 Unknown3
Definition PeImage.h:663
UINT32 Unknown
Definition PeImage.h:661
UINT32 Signature
"NB10"
Definition PeImage.h:660
UINT32 Unknown2
Definition PeImage.h:662
Definition PeImage.h:673
UINT32 Unknown2
Definition PeImage.h:676
UINT32 Unknown4
Definition PeImage.h:678
UINT32 Signature
"RSDS".
Definition PeImage.h:674
UINT32 Unknown3
Definition PeImage.h:677
UINT32 Unknown
Definition PeImage.h:675
UINT32 Unknown5
Definition PeImage.h:679
Debug Directory Format.
Definition PeImage.h:641
UINT32 Type
Definition PeImage.h:646
UINT32 Characteristics
Definition PeImage.h:642
UINT16 MajorVersion
Definition PeImage.h:644
UINT32 SizeOfData
Definition PeImage.h:647
UINT32 TimeDateStamp
Definition PeImage.h:643
UINT16 MinorVersion
Definition PeImage.h:645
UINT32 FileOffset
The file pointer to the debug data.
Definition PeImage.h:649
UINT32 RVA
The address of the debug data when loaded, relative to the image base.
Definition PeImage.h:648
Definition PeImage.h:721
UINT32 DllCharacteristicsEx
Definition PeImage.h:722
PE images can start with an optional DOS header, so if an image is run under DOS it can print an erro...
Definition PeImage.h:58
UINT16 e_oemid
OEM identifier (for e_oeminfo).
Definition PeImage.h:74
UINT16 e_oeminfo
OEM information; e_oemid specific.
Definition PeImage.h:75
UINT16 e_maxalloc
Maximum extra paragraphs needed.
Definition PeImage.h:65
UINT32 e_lfanew
File address of new exe header.
Definition PeImage.h:77
UINT16 e_crlc
Relocations.
Definition PeImage.h:62
UINT16 e_ip
Initial IP value.
Definition PeImage.h:69
UINT16 e_cparhdr
Size of header in paragraphs.
Definition PeImage.h:63
UINT16 e_magic
Magic number.
Definition PeImage.h:59
UINT16 e_minalloc
Minimum extra paragraphs needed.
Definition PeImage.h:64
UINT16 e_csum
Checksum.
Definition PeImage.h:68
UINT16 e_sp
Initial SP value.
Definition PeImage.h:67
UINT16 e_cblp
Bytes on last page of file.
Definition PeImage.h:60
UINT16 e_res[4]
Reserved words.
Definition PeImage.h:73
UINT16 e_ss
Initial (relative) SS value.
Definition PeImage.h:66
UINT16 e_ovno
Overlay number.
Definition PeImage.h:72
UINT16 e_cp
Pages in file.
Definition PeImage.h:61
UINT16 e_lfarlc
File address of relocation table.
Definition PeImage.h:71
UINT16 e_cs
Initial (relative) CS value.
Definition PeImage.h:70
UINT16 e_res2[10]
Reserved words.
Definition PeImage.h:76
Export Directory Table.
Definition PeImage.h:583
COFF File Header (Object and Image).
Definition PeImage.h:83
UINT32 PointerToSymbolTable
Definition PeImage.h:87
UINT16 SizeOfOptionalHeader
Definition PeImage.h:89
UINT16 NumberOfSections
Definition PeImage.h:85
Hint/Name Table.
Definition PeImage.h:607
Import Directory Table.
Definition PeImage.h:630
EFI_IMAGE_THUNK_DATA * FirstThunk
Definition PeImage.h:635
Line number format.
Definition PeImage.h:535
UINT32 SymbolTableIndex
Symbol table index of function name if Linenumber is 0.
Definition PeImage.h:537
UINT32 VirtualAddress
Virtual address of line number.
Definition PeImage.h:538
UINT16 Linenumber
Line number.
Definition PeImage.h:540
EFI_IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition PeImage.h:246
EFI_IMAGE_FILE_HEADER FileHeader
Definition PeImage.h:245
EFI_IMAGE_FILE_HEADER FileHeader
Definition PeImage.h:257
EFI_IMAGE_OPTIONAL_HEADER64 OptionalHeader
Definition PeImage.h:258
Optional Header Standard Fields for PE32.
Definition PeImage.h:149
UINT32 BaseOfData
PE32 contains this additional field, which is absent in PE32+.
Definition PeImage.h:161
EFI_IMAGE_DATA_DIRECTORY DataDirectory[EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES]
Definition PeImage.h:186
UINT32 ImageBase
Optional Header Windows-Specific Fields.
Definition PeImage.h:165
UINT16 Magic
Standard fields.
Definition PeImage.h:153
Optional Header Standard Fields for PE32+.
Definition PeImage.h:200
UINT64 ImageBase
Optional Header Windows-Specific Fields.
Definition PeImage.h:215
UINT16 Magic
Standard fields.
Definition PeImage.h:204
EFI_IMAGE_DATA_DIRECTORY DataDirectory[EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES]
Definition PeImage.h:236
Relocation format.
Definition PeImage.h:446
UINT32 SymbolTableIndex
Definition PeImage.h:448
Resource directory entry for data array.
Definition PeImage.h:771
UINT32 CodePage
Definition PeImage.h:774
UINT32 Reserved
Definition PeImage.h:775
UINT32 Size
Definition PeImage.h:773
UINT32 OffsetToData
Definition PeImage.h:772
Resource directory entry format.
Definition PeImage.h:743
UINT32 DataIsDirectory
Definition PeImage.h:755
UINT32 OffsetToDirectory
Definition PeImage.h:754
UINT32 NameIsString
Definition PeImage.h:747
UINT32 NameOffset
Definition PeImage.h:746
UINT32 OffsetToData
Definition PeImage.h:752
UINT32 Id
Definition PeImage.h:749
Resource directory entry for string.
Definition PeImage.h:763
Section Table.
Definition PeImage.h:296
UINT8 Name[EFI_IMAGE_SIZEOF_SHORT_NAME]
Definition PeImage.h:297
Import Address Table RVA (Thunk Table).
Definition PeImage.h:615
EFI_IMAGE_IMPORT_BY_NAME * AddressOfData
Definition PeImage.h:619
Header format for TE images, defined in the PI Specification, 1.0.
Definition PeImage.h:781
UINT32 AddressOfEntryPoint
Offset to entry point – from original optional header.
Definition PeImage.h:787
UINT16 Signature
The signature for TE format = "VZ".
Definition PeImage.h:782
UINT8 Subsystem
From original optional header.
Definition PeImage.h:785
UINT64 ImageBase
From original file header.
Definition PeImage.h:789
UINT32 BaseOfCode
From original image – required for ITP debug.
Definition PeImage.h:788
EFI_IMAGE_DATA_DIRECTORY DataDirectory[2]
Only base relocation and debug directory.
Definition PeImage.h:790
UINT16 StrippedSize
Number of bytes we removed from the header.
Definition PeImage.h:786
UINT8 NumberOfSections
From the original file header.
Definition PeImage.h:784
UINT16 Machine
From the original file header.
Definition PeImage.h:783
128 bit buffer containing a unique identifier value.
Definition Base.h:215
UINT32 UnwindInfoAddress
Definition PeImage.h:703
UINT32 FunctionStartAddress
Definition PeImage.h:701
UINT32 FunctionEndAddress
Definition PeImage.h:702
UINT8 FrameRegister
Definition PeImage.h:711
UINT8 SizeOfProlog
Definition PeImage.h:709
UINT8 Flags
Definition PeImage.h:708
UINT8 Version
Definition PeImage.h:707
UINT8 CountOfUnwindCodes
Definition PeImage.h:710
UINT8 FrameRegisterOffset
Definition PeImage.h:712
EFI_TE_IMAGE_HEADER * Te
Definition PeImage.h:813
EFI_IMAGE_OPTIONAL_HEADER_UNION * Union
Definition PeImage.h:814
EFI_IMAGE_NT_HEADERS32 * Pe32
Definition PeImage.h:811
EFI_IMAGE_NT_HEADERS64 * Pe32Plus
Definition PeImage.h:812
Union of PE32, PE32+, and TE headers.
Definition PeImage.h:804
EFI_IMAGE_NT_HEADERS64 Pe32Plus
Definition PeImage.h:806
EFI_TE_IMAGE_HEADER Te
Definition PeImage.h:807
EFI_IMAGE_NT_HEADERS32 Pe32
Definition PeImage.h:805