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