Home | History | Annotate | Line # | Download | only in x86_64
      1 /*	$NetBSD: pe.h,v 1.1.1.1 2014/04/01 16:16:07 jakllsch Exp $	*/
      2 
      3 /*
      4     PE32+ header file
      5  */
      6 #ifndef _PE_H
      7 #define _PE_H
      8 
      9 #define IMAGE_DOS_SIGNATURE                 0x5A4D      // MZ
     10 #define IMAGE_OS2_SIGNATURE                 0x454E      // NE
     11 #define IMAGE_OS2_SIGNATURE_LE              0x454C      // LE
     12 #define IMAGE_NT_SIGNATURE                  0x00004550  // PE00
     13 #define IMAGE_EDOS_SIGNATURE                0x44454550  // PEED
     14 
     15 
     16 typedef struct _IMAGE_DOS_HEADER {      // DOS .EXE header
     17     UINT16   e_magic;                     // Magic number
     18     UINT16   e_cblp;                      // Bytes on last page of file
     19     UINT16   e_cp;                        // Pages in file
     20     UINT16   e_crlc;                      // Relocations
     21     UINT16   e_cparhdr;                   // Size of header in paragraphs
     22     UINT16   e_minalloc;                  // Minimum extra paragraphs needed
     23     UINT16   e_maxalloc;                  // Maximum extra paragraphs needed
     24     UINT16   e_ss;                        // Initial (relative) SS value
     25     UINT16   e_sp;                        // Initial SP value
     26     UINT16   e_csum;                      // Checksum
     27     UINT16   e_ip;                        // Initial IP value
     28     UINT16   e_cs;                        // Initial (relative) CS value
     29     UINT16   e_lfarlc;                    // File address of relocation table
     30     UINT16   e_ovno;                      // Overlay number
     31     UINT16   e_res[4];                    // Reserved words
     32     UINT16   e_oemid;                     // OEM identifier (for e_oeminfo)
     33     UINT16   e_oeminfo;                   // OEM information; e_oemid specific
     34     UINT16   e_res2[10];                  // Reserved words
     35     UINT32   e_lfanew;                    // File address of new exe header
     36   } IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;
     37 
     38 typedef struct _IMAGE_OS2_HEADER {      // OS/2 .EXE header
     39     UINT16   ne_magic;                    // Magic number
     40     UINT8    ne_ver;                      // Version number
     41     UINT8    ne_rev;                      // Revision number
     42     UINT16   ne_enttab;                   // Offset of Entry Table
     43     UINT16   ne_cbenttab;                 // Number of bytes in Entry Table
     44     UINT32   ne_crc;                      // Checksum of whole file
     45     UINT16   ne_flags;                    // Flag UINT16
     46     UINT16   ne_autodata;                 // Automatic data segment number
     47     UINT16   ne_heap;                     // Initial heap allocation
     48     UINT16   ne_stack;                    // Initial stack allocation
     49     UINT32   ne_csip;                     // Initial CS:IP setting
     50     UINT32   ne_sssp;                     // Initial SS:SP setting
     51     UINT16   ne_cseg;                     // Count of file segments
     52     UINT16   ne_cmod;                     // Entries in Module Reference Table
     53     UINT16   ne_cbnrestab;                // Size of non-resident name table
     54     UINT16   ne_segtab;                   // Offset of Segment Table
     55     UINT16   ne_rsrctab;                  // Offset of Resource Table
     56     UINT16   ne_restab;                   // Offset of resident name table
     57     UINT16   ne_modtab;                   // Offset of Module Reference Table
     58     UINT16   ne_imptab;                   // Offset of Imported Names Table
     59     UINT32   ne_nrestab;                  // Offset of Non-resident Names Table
     60     UINT16   ne_cmovent;                  // Count of movable entries
     61     UINT16   ne_align;                    // Segment alignment shift count
     62     UINT16   ne_cres;                     // Count of resource segments
     63     UINT8    ne_exetyp;                   // Target Operating system
     64     UINT8    ne_flagsothers;              // Other .EXE flags
     65     UINT16   ne_pretthunks;               // offset to return thunks
     66     UINT16   ne_psegrefbytes;             // offset to segment ref. bytes
     67     UINT16   ne_swaparea;                 // Minimum code swap area size
     68     UINT16   ne_expver;                   // Expected Windows version number
     69   } IMAGE_OS2_HEADER, *PIMAGE_OS2_HEADER;
     70 
     71 //
     72 // File header format.
     73 //
     74 
     75 typedef struct _IMAGE_FILE_HEADER {
     76     UINT16   Machine;
     77     UINT16   NumberOfSections;
     78     UINT32   TimeDateStamp;
     79     UINT32   PointerToSymbolTable;
     80     UINT32   NumberOfSymbols;
     81     UINT16   SizeOfOptionalHeader;
     82     UINT16   Characteristics;
     83 } IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER;
     84 
     85 #define IMAGE_SIZEOF_FILE_HEADER             20
     86 
     87 #define IMAGE_FILE_RELOCS_STRIPPED           0x0001  // Relocation info stripped from file.
     88 #define IMAGE_FILE_EXECUTABLE_IMAGE          0x0002  // File is executable  (i.e. no unresolved externel references).
     89 #define IMAGE_FILE_LINE_NUMS_STRIPPED        0x0004  // Line nunbers stripped from file.
     90 #define IMAGE_FILE_LOCAL_SYMS_STRIPPED       0x0008  // Local symbols stripped from file.
     91 #define IMAGE_FILE_BYTES_REVERSED_LO         0x0080  // Bytes of machine word are reversed.
     92 #define IMAGE_FILE_32BIT_MACHINE             0x0100  // 32 bit word machine.
     93 #define IMAGE_FILE_DEBUG_STRIPPED            0x0200  // Debugging info stripped from file in .DBG file
     94 #define IMAGE_FILE_SYSTEM                    0x1000  // System File.
     95 #define IMAGE_FILE_DLL                       0x2000  // File is a DLL.
     96 #define IMAGE_FILE_BYTES_REVERSED_HI         0x8000  // Bytes of machine word are reversed.
     97 
     98 #define IMAGE_FILE_MACHINE_UNKNOWN           0
     99 #define IMAGE_FILE_MACHINE_I386              0x14c   // Intel 386.
    100 #define IMAGE_FILE_MACHINE_R3000             0x162   // MIPS little-endian, 0540 big-endian
    101 #define IMAGE_FILE_MACHINE_R4000             0x166   // MIPS little-endian
    102 #define IMAGE_FILE_MACHINE_ALPHA             0x184   // Alpha_AXP
    103 #define IMAGE_FILE_MACHINE_ARMTHUMB_MIXED    0x1c2   // Arm/Thumb
    104 #define IMAGE_FILE_MACHINE_POWERPC           0x1F0   // IBM PowerPC Little-Endian
    105 #define IMAGE_FILE_MACHINE_IA64              0x200   // IA-64
    106 #define IMAGE_FILE_MACHINE_TAHOE             0x7cc   // Intel EM machine
    107 #define IMAGE_FILE_MACHINE_EBC               0xebc   // EFI Byte Code
    108 #define IMAGE_FILE_MACHINE_X64               0x8664  // x86_64
    109 //
    110 // Directory format.
    111 //
    112 
    113 typedef struct _IMAGE_DATA_DIRECTORY {
    114     UINT32   VirtualAddress;
    115     UINT32   Size;
    116 } IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY;
    117 
    118 #define IMAGE_NUMBEROF_DIRECTORY_ENTRIES    16
    119 
    120 //
    121 // Optional header format.
    122 //
    123 
    124 typedef struct _IMAGE_OPTIONAL_HEADER {
    125     //
    126     // Standard fields.
    127     //
    128 
    129     UINT16    Magic;
    130     UINT8     MajorLinkerVersion;
    131     UINT8     MinorLinkerVersion;
    132     UINT32    SizeOfCode;
    133     UINT32    SizeOfInitializedData;
    134     UINT32    SizeOfUninitializedData;
    135     UINT32    AddressOfEntryPoint;
    136     UINT32    BaseOfCode;
    137     UINT32    BaseOfData;
    138 
    139     //
    140     // NT additional fields.
    141     //
    142 
    143     UINT32   ImageBase;
    144     UINT32   SectionAlignment;
    145     UINT32   FileAlignment;
    146     UINT16   MajorOperatingSystemVersion;
    147     UINT16   MinorOperatingSystemVersion;
    148     UINT16   MajorImageVersion;
    149     UINT16   MinorImageVersion;
    150     UINT16   MajorSubsystemVersion;
    151     UINT16   MinorSubsystemVersion;
    152     UINT32   Reserved1;
    153     UINT32   SizeOfImage;
    154     UINT32   SizeOfHeaders;
    155     UINT32   CheckSum;
    156     UINT16   Subsystem;
    157     UINT16   DllCharacteristics;
    158     UINT32   SizeOfStackReserve;
    159     UINT32   SizeOfStackCommit;
    160     UINT32   SizeOfHeapReserve;
    161     UINT32   SizeOfHeapCommit;
    162     UINT32   LoaderFlags;
    163     UINT32   NumberOfRvaAndSizes;
    164     IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
    165 } IMAGE_OPTIONAL_HEADER, *PIMAGE_OPTIONAL_HEADER;
    166 
    167 typedef struct _IMAGE_ROM_OPTIONAL_HEADER {
    168     UINT16  Magic;
    169     UINT8   MajorLinkerVersion;
    170     UINT8   MinorLinkerVersion;
    171     UINT32  SizeOfCode;
    172     UINT32  SizeOfInitializedData;
    173     UINT32  SizeOfUninitializedData;
    174     UINT32  AddressOfEntryPoint;
    175     UINT32  BaseOfCode;
    176     UINT32  BaseOfData;
    177     UINT32  BaseOfBss;
    178     UINT32  GprMask;
    179     UINT32  CprMask[4];
    180     UINT32  GpValue;
    181 } IMAGE_ROM_OPTIONAL_HEADER, *PIMAGE_ROM_OPTIONAL_HEADER;
    182 
    183 #define IMAGE_SIZEOF_ROM_OPTIONAL_HEADER      56
    184 #define IMAGE_SIZEOF_STD_OPTIONAL_HEADER      28
    185 #define IMAGE_SIZEOF_NT_OPTIONAL_HEADER      224
    186 
    187 #define IMAGE_NT_OPTIONAL_HDR_MAGIC        0x10b
    188 #define IMAGE_ROM_OPTIONAL_HDR_MAGIC       0x107
    189 
    190 typedef struct _IMAGE_NT_HEADERS {
    191     UINT32 Signature;
    192     IMAGE_FILE_HEADER FileHeader;
    193     IMAGE_OPTIONAL_HEADER OptionalHeader;
    194 } IMAGE_NT_HEADERS, *PIMAGE_NT_HEADERS;
    195 
    196 typedef struct _IMAGE_ROM_HEADERS {
    197     IMAGE_FILE_HEADER FileHeader;
    198     IMAGE_ROM_OPTIONAL_HEADER OptionalHeader;
    199 } IMAGE_ROM_HEADERS, *PIMAGE_ROM_HEADERS;
    200 
    201 #define IMAGE_FIRST_SECTION( ntheader ) ((PIMAGE_SECTION_HEADER)        \
    202     ((UINT32)ntheader +                                                  \
    203      FIELD_OFFSET( IMAGE_NT_HEADERS, OptionalHeader ) +                 \
    204      ((PIMAGE_NT_HEADERS)(ntheader))->FileHeader.SizeOfOptionalHeader   \
    205     ))
    206 
    207 
    208 // Subsystem Values
    209 
    210 #define IMAGE_SUBSYSTEM_UNKNOWN              0   // Unknown subsystem.
    211 #define IMAGE_SUBSYSTEM_NATIVE               1   // Image doesn't require a subsystem.
    212 #define IMAGE_SUBSYSTEM_WINDOWS_GUI          2   // Image runs in the Windows GUI subsystem.
    213 #define IMAGE_SUBSYSTEM_WINDOWS_CUI          3   // Image runs in the Windows character subsystem.
    214 #define IMAGE_SUBSYSTEM_OS2_CUI              5   // image runs in the OS/2 character subsystem.
    215 #define IMAGE_SUBSYSTEM_POSIX_CUI            7   // image run  in the Posix character subsystem.
    216 
    217 
    218 // Directory Entries
    219 
    220 #define IMAGE_DIRECTORY_ENTRY_EXPORT         0   // Export Directory
    221 #define IMAGE_DIRECTORY_ENTRY_IMPORT         1   // Import Directory
    222 #define IMAGE_DIRECTORY_ENTRY_RESOURCE       2   // Resource Directory
    223 #define IMAGE_DIRECTORY_ENTRY_EXCEPTION      3   // Exception Directory
    224 #define IMAGE_DIRECTORY_ENTRY_SECURITY       4   // Security Directory
    225 #define IMAGE_DIRECTORY_ENTRY_BASERELOC      5   // Base Relocation Table
    226 #define IMAGE_DIRECTORY_ENTRY_DEBUG          6   // Debug Directory
    227 #define IMAGE_DIRECTORY_ENTRY_COPYRIGHT      7   // Description String
    228 #define IMAGE_DIRECTORY_ENTRY_GLOBALPTR      8   // Machine Value (MIPS GP)
    229 #define IMAGE_DIRECTORY_ENTRY_TLS            9   // TLS Directory
    230 #define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG   10   // Load Configuration Directory
    231 
    232 //
    233 // Section header format.
    234 //
    235 
    236 #define IMAGE_SIZEOF_SHORT_NAME              8
    237 
    238 typedef struct _IMAGE_SECTION_HEADER {
    239     UINT8   Name[IMAGE_SIZEOF_SHORT_NAME];
    240     union {
    241             UINT32   PhysicalAddress;
    242             UINT32   VirtualSize;
    243     } Misc;
    244     UINT32   VirtualAddress;
    245     UINT32   SizeOfRawData;
    246     UINT32   PointerToRawData;
    247     UINT32   PointerToRelocations;
    248     UINT32   PointerToLinenumbers;
    249     UINT16   NumberOfRelocations;
    250     UINT16   NumberOfLinenumbers;
    251     UINT32   Characteristics;
    252 } IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER;
    253 
    254 #define IMAGE_SIZEOF_SECTION_HEADER          40
    255 
    256 #define IMAGE_SCN_TYPE_NO_PAD                0x00000008  // Reserved.
    257 
    258 #define IMAGE_SCN_CNT_CODE                   0x00000020  // Section contains code.
    259 #define IMAGE_SCN_CNT_INITIALIZED_DATA       0x00000040  // Section contains initialized data.
    260 #define IMAGE_SCN_CNT_UNINITIALIZED_DATA     0x00000080  // Section contains uninitialized data.
    261 
    262 #define IMAGE_SCN_LNK_OTHER                  0x00000100  // Reserved.
    263 #define IMAGE_SCN_LNK_INFO                   0x00000200  // Section contains comments or some other type of information.
    264 #define IMAGE_SCN_LNK_REMOVE                 0x00000800  // Section contents will not become part of image.
    265 #define IMAGE_SCN_LNK_COMDAT                 0x00001000  // Section contents comdat.
    266 
    267 #define IMAGE_SCN_ALIGN_1BYTES               0x00100000  //
    268 #define IMAGE_SCN_ALIGN_2BYTES               0x00200000  //
    269 #define IMAGE_SCN_ALIGN_4BYTES               0x00300000  //
    270 #define IMAGE_SCN_ALIGN_8BYTES               0x00400000  //
    271 #define IMAGE_SCN_ALIGN_16BYTES              0x00500000  // Default alignment if no others are specified.
    272 #define IMAGE_SCN_ALIGN_32BYTES              0x00600000  //
    273 #define IMAGE_SCN_ALIGN_64BYTES              0x00700000  //
    274 
    275 #define IMAGE_SCN_MEM_DISCARDABLE            0x02000000  // Section can be discarded.
    276 #define IMAGE_SCN_MEM_NOT_CACHED             0x04000000  // Section is not cachable.
    277 #define IMAGE_SCN_MEM_NOT_PAGED              0x08000000  // Section is not pageable.
    278 #define IMAGE_SCN_MEM_SHARED                 0x10000000  // Section is shareable.
    279 #define IMAGE_SCN_MEM_EXECUTE                0x20000000  // Section is executable.
    280 #define IMAGE_SCN_MEM_READ                   0x40000000  // Section is readable.
    281 #define IMAGE_SCN_MEM_WRITE                  0x80000000  // Section is writeable.
    282 
    283 //
    284 // Symbol format.
    285 //
    286 
    287 
    288 #define IMAGE_SIZEOF_SYMBOL                  18
    289 
    290 //
    291 // Section values.
    292 //
    293 // Symbols have a section number of the section in which they are
    294 // defined. Otherwise, section numbers have the following meanings:
    295 //
    296 
    297 #define IMAGE_SYM_UNDEFINED           (UINT16)0           // Symbol is undefined or is common.
    298 #define IMAGE_SYM_ABSOLUTE            (UINT16)-1          // Symbol is an absolute value.
    299 #define IMAGE_SYM_DEBUG               (UINT16)-2          // Symbol is a special debug item.
    300 
    301 //
    302 // Type (fundamental) values.
    303 //
    304 
    305 #define IMAGE_SYM_TYPE_NULL                  0           // no type.
    306 #define IMAGE_SYM_TYPE_VOID                  1           //
    307 #define IMAGE_SYM_TYPE_CHAR                  2           // type character.
    308 #define IMAGE_SYM_TYPE_SHORT                 3           // type short integer.
    309 #define IMAGE_SYM_TYPE_INT                   4           //
    310 #define IMAGE_SYM_TYPE_LONG                  5           //
    311 #define IMAGE_SYM_TYPE_FLOAT                 6           //
    312 #define IMAGE_SYM_TYPE_DOUBLE                7           //
    313 #define IMAGE_SYM_TYPE_STRUCT                8           //
    314 #define IMAGE_SYM_TYPE_UNION                 9           //
    315 #define IMAGE_SYM_TYPE_ENUM                  10          // enumeration.
    316 #define IMAGE_SYM_TYPE_MOE                   11          // member of enumeration.
    317 #define IMAGE_SYM_TYPE_BYTE                  12          //
    318 #define IMAGE_SYM_TYPE_WORD                  13          //
    319 #define IMAGE_SYM_TYPE_UINT                  14          //
    320 #define IMAGE_SYM_TYPE_DWORD                 15          //
    321 
    322 //
    323 // Type (derived) values.
    324 //
    325 
    326 #define IMAGE_SYM_DTYPE_NULL                 0           // no derived type.
    327 #define IMAGE_SYM_DTYPE_POINTER              1           // pointer.
    328 #define IMAGE_SYM_DTYPE_FUNCTION             2           // function.
    329 #define IMAGE_SYM_DTYPE_ARRAY                3           // array.
    330 
    331 //
    332 // Storage classes.
    333 //
    334 
    335 #define IMAGE_SYM_CLASS_END_OF_FUNCTION      (BYTE )-1
    336 #define IMAGE_SYM_CLASS_NULL                 0
    337 #define IMAGE_SYM_CLASS_AUTOMATIC            1
    338 #define IMAGE_SYM_CLASS_EXTERNAL             2
    339 #define IMAGE_SYM_CLASS_STATIC               3
    340 #define IMAGE_SYM_CLASS_REGISTER             4
    341 #define IMAGE_SYM_CLASS_EXTERNAL_DEF         5
    342 #define IMAGE_SYM_CLASS_LABEL                6
    343 #define IMAGE_SYM_CLASS_UNDEFINED_LABEL      7
    344 #define IMAGE_SYM_CLASS_MEMBER_OF_STRUCT     8
    345 #define IMAGE_SYM_CLASS_ARGUMENT             9
    346 #define IMAGE_SYM_CLASS_STRUCT_TAG           10
    347 #define IMAGE_SYM_CLASS_MEMBER_OF_UNION      11
    348 #define IMAGE_SYM_CLASS_UNION_TAG            12
    349 #define IMAGE_SYM_CLASS_TYPE_DEFINITION      13
    350 #define IMAGE_SYM_CLASS_UNDEFINED_STATIC     14
    351 #define IMAGE_SYM_CLASS_ENUM_TAG             15
    352 #define IMAGE_SYM_CLASS_MEMBER_OF_ENUM       16
    353 #define IMAGE_SYM_CLASS_REGISTER_PARAM       17
    354 #define IMAGE_SYM_CLASS_BIT_FIELD            18
    355 #define IMAGE_SYM_CLASS_BLOCK                100
    356 #define IMAGE_SYM_CLASS_FUNCTION             101
    357 #define IMAGE_SYM_CLASS_END_OF_STRUCT        102
    358 #define IMAGE_SYM_CLASS_FILE                 103
    359 // new
    360 #define IMAGE_SYM_CLASS_SECTION              104
    361 #define IMAGE_SYM_CLASS_WEAK_EXTERNAL        105
    362 
    363 // type packing constants
    364 
    365 #define N_BTMASK                            017
    366 #define N_TMASK                             060
    367 #define N_TMASK1                            0300
    368 #define N_TMASK2                            0360
    369 #define N_BTSHFT                            4
    370 #define N_TSHIFT                            2
    371 
    372 // MACROS
    373 
    374 //
    375 // Communal selection types.
    376 //
    377 
    378 #define IMAGE_COMDAT_SELECT_NODUPLICATES   1
    379 #define IMAGE_COMDAT_SELECT_ANY            2
    380 #define IMAGE_COMDAT_SELECT_SAME_SIZE      3
    381 #define IMAGE_COMDAT_SELECT_EXACT_MATCH    4
    382 #define IMAGE_COMDAT_SELECT_ASSOCIATIVE    5
    383 
    384 #define IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY 1
    385 #define IMAGE_WEAK_EXTERN_SEARCH_LIBRARY   2
    386 #define IMAGE_WEAK_EXTERN_SEARCH_ALIAS     3
    387 
    388 
    389 //
    390 // Relocation format.
    391 //
    392 
    393 typedef struct _IMAGE_RELOCATION {
    394     UINT32   VirtualAddress;
    395     UINT32   SymbolTableIndex;
    396     UINT16    Type;
    397 } IMAGE_RELOCATION;
    398 
    399 #define IMAGE_SIZEOF_RELOCATION              10
    400 
    401 //
    402 // I386 relocation types.
    403 //
    404 
    405 #define IMAGE_REL_I386_ABSOLUTE              0           // Reference is absolute, no relocation is necessary
    406 #define IMAGE_REL_I386_DIR16                 01          // Direct 16-bit reference to the symbols virtual address
    407 #define IMAGE_REL_I386_REL16                 02          // PC-relative 16-bit reference to the symbols virtual address
    408 #define IMAGE_REL_I386_DIR32                 06          // Direct 32-bit reference to the symbols virtual address
    409 #define IMAGE_REL_I386_DIR32NB               07          // Direct 32-bit reference to the symbols virtual address, base not included
    410 #define IMAGE_REL_I386_SEG12                 011         // Direct 16-bit reference to the segment-selector bits of a 32-bit virtual address
    411 #define IMAGE_REL_I386_SECTION               012
    412 #define IMAGE_REL_I386_SECREL                013
    413 #define IMAGE_REL_I386_REL32                 024         // PC-relative 32-bit reference to the symbols virtual address
    414 
    415 //
    416 // MIPS relocation types.
    417 //
    418 
    419 #define IMAGE_REL_MIPS_ABSOLUTE              0           // Reference is absolute, no relocation is necessary
    420 #define IMAGE_REL_MIPS_REFHALF               01
    421 #define IMAGE_REL_MIPS_REFWORD               02
    422 #define IMAGE_REL_MIPS_JMPADDR               03
    423 #define IMAGE_REL_MIPS_REFHI                 04
    424 #define IMAGE_REL_MIPS_REFLO                 05
    425 #define IMAGE_REL_MIPS_GPREL                 06
    426 #define IMAGE_REL_MIPS_LITERAL               07
    427 #define IMAGE_REL_MIPS_SECTION               012
    428 #define IMAGE_REL_MIPS_SECREL                013
    429 #define IMAGE_REL_MIPS_REFWORDNB             042
    430 #define IMAGE_REL_MIPS_PAIR                  045
    431 
    432 //
    433 // Alpha Relocation types.
    434 //
    435 
    436 #define IMAGE_REL_ALPHA_ABSOLUTE             0x0
    437 #define IMAGE_REL_ALPHA_REFLONG              0x1
    438 #define IMAGE_REL_ALPHA_REFQUAD              0x2
    439 #define IMAGE_REL_ALPHA_GPREL32              0x3
    440 #define IMAGE_REL_ALPHA_LITERAL              0x4
    441 #define IMAGE_REL_ALPHA_LITUSE               0x5
    442 #define IMAGE_REL_ALPHA_GPDISP               0x6
    443 #define IMAGE_REL_ALPHA_BRADDR               0x7
    444 #define IMAGE_REL_ALPHA_HINT                 0x8
    445 #define IMAGE_REL_ALPHA_INLINE_REFLONG       0x9
    446 #define IMAGE_REL_ALPHA_REFHI                0xA
    447 #define IMAGE_REL_ALPHA_REFLO                0xB
    448 #define IMAGE_REL_ALPHA_PAIR                 0xC
    449 #define IMAGE_REL_ALPHA_MATCH                0xD
    450 #define IMAGE_REL_ALPHA_SECTION              0xE
    451 #define IMAGE_REL_ALPHA_SECREL               0xF
    452 #define IMAGE_REL_ALPHA_REFLONGNB            0x10
    453 
    454 //
    455 // IBM PowerPC relocation types.
    456 //
    457 
    458 #define IMAGE_REL_PPC_ABSOLUTE 0x0000  // NOP
    459 #define IMAGE_REL_PPC_ADDR64   0x0001  // 64-bit address
    460 #define IMAGE_REL_PPC_ADDR32   0x0002  // 32-bit address
    461 #define IMAGE_REL_PPC_ADDR24   0x0003  // 26-bit address, shifted left 2 (branch absolute)
    462 #define IMAGE_REL_PPC_ADDR16   0x0004  // 16-bit address
    463 #define IMAGE_REL_PPC_ADDR14   0x0005  // 16-bit address, shifted left 2 (load doubleword)
    464 #define IMAGE_REL_PPC_REL24    0x0006  // 26-bit PC-relative offset, shifted left 2 (branch relative)
    465 #define IMAGE_REL_PPC_REL14    0x0007  // 16-bit PC-relative offset, shifted left 2 (br cond relative)
    466 #define IMAGE_REL_PPC_TOCREL16 0x0008  // 16-bit offset from TOC base
    467 #define IMAGE_REL_PPC_TOCREL14 0x0009  // 16-bit offset from TOC base, shifted left 2 (load doubleword)
    468 
    469 #define IMAGE_REL_PPC_ADDR32NB 0x000A  // 32-bit addr w/o image base
    470 #define IMAGE_REL_PPC_SECREL   0x000B  // va of containing section (as in an image sectionhdr)
    471 #define IMAGE_REL_PPC_SECTION  0x000C  // sectionheader number
    472 #define IMAGE_REL_PPC_IFGLUE   0x000D  // substitute TOC restore instruction iff symbol is glue code
    473 #define IMAGE_REL_PPC_IMGLUE   0x000E  // symbol is glue code; virtual address is TOC restore instruction
    474 
    475 #define IMAGE_REL_PPC_TYPEMASK 0x00FF  // mask to isolate above values in IMAGE_RELOCATION.Type
    476 
    477 // Flag bits in IMAGE_RELOCATION.TYPE
    478 
    479 #define IMAGE_REL_PPC_NEG      0x0100  // subtract reloc value rather than adding it
    480 #define IMAGE_REL_PPC_BRTAKEN  0x0200  // fix branch prediction bit to predict branch taken
    481 #define IMAGE_REL_PPC_BRNTAKEN 0x0400  // fix branch prediction bit to predict branch not taken
    482 #define IMAGE_REL_PPC_TOCDEFN  0x0800  // toc slot defined in file (or, data in toc)
    483 
    484 //
    485 // Based relocation format.
    486 //
    487 
    488 typedef struct _IMAGE_BASE_RELOCATION {
    489     UINT32   VirtualAddress;
    490     UINT32   SizeOfBlock;
    491 //  UINT16    TypeOffset[1];
    492 } IMAGE_BASE_RELOCATION, *PIMAGE_BASE_RELOCATION;
    493 
    494 #define IMAGE_SIZEOF_BASE_RELOCATION         8
    495 
    496 //
    497 // Based relocation types.
    498 //
    499 
    500 #define IMAGE_REL_BASED_ABSOLUTE              0
    501 #define IMAGE_REL_BASED_HIGH                  1
    502 #define IMAGE_REL_BASED_LOW                   2
    503 #define IMAGE_REL_BASED_HIGHLOW               3
    504 #define IMAGE_REL_BASED_HIGHADJ               4
    505 #define IMAGE_REL_BASED_MIPS_JMPADDR          5
    506 #define IMAGE_REL_BASED_IA64_IMM64            9
    507 #define IMAGE_REL_BASED_DIR64                 10
    508 
    509 //
    510 // Line number format.
    511 //
    512 
    513 typedef struct _IMAGE_LINENUMBER {
    514     union {
    515         UINT32   SymbolTableIndex;               // Symbol table index of function name if Linenumber is 0.
    516         UINT32   VirtualAddress;                 // Virtual address of line number.
    517     } Type;
    518     UINT16    Linenumber;                         // Line number.
    519 } IMAGE_LINENUMBER;
    520 
    521 #define IMAGE_SIZEOF_LINENUMBER              6
    522 
    523 //
    524 // Archive format.
    525 //
    526 
    527 #define IMAGE_ARCHIVE_START_SIZE             8
    528 #define IMAGE_ARCHIVE_START                  "!<arch>\n"
    529 #define IMAGE_ARCHIVE_END                    "`\n"
    530 #define IMAGE_ARCHIVE_PAD                    "\n"
    531 #define IMAGE_ARCHIVE_LINKER_MEMBER          "/               "
    532 #define IMAGE_ARCHIVE_LONGNAMES_MEMBER       "//              "
    533 
    534 typedef struct _IMAGE_ARCHIVE_MEMBER_HEADER {
    535     UINT8     Name[16];                          // File member name - `/' terminated.
    536     UINT8     Date[12];                          // File member date - decimal.
    537     UINT8     UserID[6];                         // File member user id - decimal.
    538     UINT8     GroupID[6];                        // File member group id - decimal.
    539     UINT8     Mode[8];                           // File member mode - octal.
    540     UINT8     Size[10];                          // File member size - decimal.
    541     UINT8     EndHeader[2];                      // String to end header.
    542 } IMAGE_ARCHIVE_MEMBER_HEADER, *PIMAGE_ARCHIVE_MEMBER_HEADER;
    543 
    544 #define IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR      60
    545 
    546 //
    547 // DLL support.
    548 //
    549 
    550 //
    551 // Export Format
    552 //
    553 
    554 typedef struct _IMAGE_EXPORT_DIRECTORY {
    555     UINT32   Characteristics;
    556     UINT32   TimeDateStamp;
    557     UINT16   MajorVersion;
    558     UINT16   MinorVersion;
    559     UINT32   Name;
    560     UINT32   Base;
    561     UINT32   NumberOfFunctions;
    562     UINT32   NumberOfNames;
    563     UINT32   *AddressOfFunctions;
    564     UINT32   *AddressOfNames;
    565     UINT32   *AddressOfNameOrdinals;
    566 } IMAGE_EXPORT_DIRECTORY, *PIMAGE_EXPORT_DIRECTORY;
    567 
    568 //
    569 // Import Format
    570 //
    571 
    572 typedef struct _IMAGE_IMPORT_BY_NAME {
    573     UINT16    Hint;
    574     UINT8     Name[1];
    575 } IMAGE_IMPORT_BY_NAME, *PIMAGE_IMPORT_BY_NAME;
    576 
    577 typedef struct _IMAGE_THUNK_DATA {
    578     union {
    579         UINT32 Function;
    580         UINT32 Ordinal;
    581         PIMAGE_IMPORT_BY_NAME AddressOfData;
    582     } u1;
    583 } IMAGE_THUNK_DATA, *PIMAGE_THUNK_DATA;
    584 
    585 #define IMAGE_ORDINAL_FLAG 0x80000000
    586 #define IMAGE_SNAP_BY_ORDINAL(Ordinal) ((Ordinal & IMAGE_ORDINAL_FLAG) != 0)
    587 #define IMAGE_ORDINAL(Ordinal) (Ordinal & 0xffff)
    588 
    589 typedef struct _IMAGE_IMPORT_DESCRIPTOR {
    590     UINT32   Characteristics;
    591     UINT32   TimeDateStamp;
    592     UINT32   ForwarderChain;
    593     UINT32   Name;
    594     PIMAGE_THUNK_DATA FirstThunk;
    595 } IMAGE_IMPORT_DESCRIPTOR, *PIMAGE_IMPORT_DESCRIPTOR;
    596 
    597 #endif
    598