199767f8919635c4928607450d9e0abb932109ceToomas Soome/* $FreeBSD$ */
199767f8919635c4928607450d9e0abb932109ceToomas Soome PE32+ header file
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct _IMAGE_DOS_HEADER { // DOS .EXE header
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINT16 e_cparhdr; // Size of header in paragraphs
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINT16 e_minalloc; // Minimum extra paragraphs needed
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINT16 e_maxalloc; // Maximum extra paragraphs needed
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINT16 e_lfarlc; // File address of relocation table
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINT16 e_oemid; // OEM identifier (for e_oeminfo)
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINT16 e_oeminfo; // OEM information; e_oemid specific
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINT32 e_lfanew; // File address of new exe header
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct _IMAGE_OS2_HEADER { // OS/2 .EXE header
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINT16 ne_cbenttab; // Number of bytes in Entry Table
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINT16 ne_autodata; // Automatic data segment number
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINT16 ne_cmod; // Entries in Module Reference Table
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINT16 ne_cbnrestab; // Size of non-resident name table
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINT16 ne_restab; // Offset of resident name table
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINT16 ne_modtab; // Offset of Module Reference Table
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINT16 ne_imptab; // Offset of Imported Names Table
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINT32 ne_nrestab; // Offset of Non-resident Names Table
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINT16 ne_align; // Segment alignment shift count
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINT16 ne_pretthunks; // offset to return thunks
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINT16 ne_psegrefbytes; // offset to segment ref. bytes
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINT16 ne_swaparea; // Minimum code swap area size
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINT16 ne_expver; // Expected Windows version number
199767f8919635c4928607450d9e0abb932109ceToomas Soome// File header format.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_FILE_RELOCS_STRIPPED 0x0001 // Relocation info stripped from file.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002 // File is executable (i.e. no unresolved externel references).
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004 // Line nunbers stripped from file.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008 // Local symbols stripped from file.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_FILE_BYTES_REVERSED_LO 0x0080 // Bytes of machine word are reversed.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_FILE_32BIT_MACHINE 0x0100 // 32 bit word machine.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_FILE_DEBUG_STRIPPED 0x0200 // Debugging info stripped from file in .DBG file
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_FILE_SYSTEM 0x1000 // System File.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_FILE_BYTES_REVERSED_HI 0x8000 // Bytes of machine word are reversed.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_FILE_MACHINE_I386 0x14c // Intel 386.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_FILE_MACHINE_R3000 0x162 // MIPS little-endian, 0540 big-endian
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_FILE_MACHINE_R4000 0x166 // MIPS little-endian
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_FILE_MACHINE_ALPHA 0x184 // Alpha_AXP
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_FILE_MACHINE_POWERPC 0x1F0 // IBM PowerPC Little-Endian
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_FILE_MACHINE_TAHOE 0x7cc // Intel EM machine
199767f8919635c4928607450d9e0abb932109ceToomas Soome// Directory format.
199767f8919635c4928607450d9e0abb932109ceToomas Soome// Optional header format.
199767f8919635c4928607450d9e0abb932109ceToomas Soome // Standard fields.
199767f8919635c4928607450d9e0abb932109ceToomas Soome // NT additional fields.
199767f8919635c4928607450d9e0abb932109ceToomas Soome IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
199767f8919635c4928607450d9e0abb932109ceToomas Soome} IMAGE_OPTIONAL_HEADER, *PIMAGE_OPTIONAL_HEADER;
199767f8919635c4928607450d9e0abb932109ceToomas Soome} IMAGE_ROM_OPTIONAL_HEADER, *PIMAGE_ROM_OPTIONAL_HEADER;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_FIRST_SECTION( ntheader ) ((PIMAGE_SECTION_HEADER) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome FIELD_OFFSET( IMAGE_NT_HEADERS, OptionalHeader ) + \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((PIMAGE_NT_HEADERS)(ntheader))->FileHeader.SizeOfOptionalHeader \
199767f8919635c4928607450d9e0abb932109ceToomas Soome// Subsystem Values
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_SUBSYSTEM_UNKNOWN 0 // Unknown subsystem.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_SUBSYSTEM_NATIVE 1 // Image doesn't require a subsystem.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_SUBSYSTEM_WINDOWS_GUI 2 // Image runs in the Windows GUI subsystem.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_SUBSYSTEM_WINDOWS_CUI 3 // Image runs in the Windows character subsystem.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_SUBSYSTEM_OS2_CUI 5 // image runs in the OS/2 character subsystem.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_SUBSYSTEM_POSIX_CUI 7 // image run in the Posix character subsystem.
199767f8919635c4928607450d9e0abb932109ceToomas Soome// Directory Entries
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_DIRECTORY_ENTRY_EXPORT 0 // Export Directory
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_DIRECTORY_ENTRY_IMPORT 1 // Import Directory
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_DIRECTORY_ENTRY_RESOURCE 2 // Resource Directory
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_DIRECTORY_ENTRY_EXCEPTION 3 // Exception Directory
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_DIRECTORY_ENTRY_SECURITY 4 // Security Directory
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_DIRECTORY_ENTRY_BASERELOC 5 // Base Relocation Table
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_DIRECTORY_ENTRY_DEBUG 6 // Debug Directory
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_DIRECTORY_ENTRY_COPYRIGHT 7 // Description String
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_DIRECTORY_ENTRY_GLOBALPTR 8 // Machine Value (MIPS GP)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_DIRECTORY_ENTRY_TLS 9 // TLS Directory
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10 // Load Configuration Directory
199767f8919635c4928607450d9e0abb932109ceToomas Soome// Section header format.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_SCN_TYPE_NO_PAD 0x00000008 // Reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_SCN_CNT_CODE 0x00000020 // Section contains code.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 // Section contains initialized data.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 // Section contains uninitialized data.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_SCN_LNK_OTHER 0x00000100 // Reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_SCN_LNK_INFO 0x00000200 // Section contains comments or some other type of information.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_SCN_LNK_REMOVE 0x00000800 // Section contents will not become part of image.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_SCN_LNK_COMDAT 0x00001000 // Section contents comdat.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_SCN_ALIGN_16BYTES 0x00500000 // Default alignment if no others are specified.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_SCN_MEM_DISCARDABLE 0x02000000 // Section can be discarded.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_SCN_MEM_NOT_CACHED 0x04000000 // Section is not cachable.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_SCN_MEM_NOT_PAGED 0x08000000 // Section is not pageable.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_SCN_MEM_SHARED 0x10000000 // Section is shareable.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_SCN_MEM_EXECUTE 0x20000000 // Section is executable.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_SCN_MEM_READ 0x40000000 // Section is readable.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_SCN_MEM_WRITE 0x80000000 // Section is writeable.
199767f8919635c4928607450d9e0abb932109ceToomas Soome// Symbol format.
199767f8919635c4928607450d9e0abb932109ceToomas Soome// Section values.
199767f8919635c4928607450d9e0abb932109ceToomas Soome// Symbols have a section number of the section in which they are
199767f8919635c4928607450d9e0abb932109ceToomas Soome// defined. Otherwise, section numbers have the following meanings:
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_SYM_UNDEFINED (UINT16)0 // Symbol is undefined or is common.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_SYM_ABSOLUTE (UINT16)-1 // Symbol is an absolute value.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_SYM_DEBUG (UINT16)-2 // Symbol is a special debug item.
199767f8919635c4928607450d9e0abb932109ceToomas Soome// Type (fundamental) values.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_SYM_TYPE_CHAR 2 // type character.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_SYM_TYPE_SHORT 3 // type short integer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_SYM_TYPE_MOE 11 // member of enumeration.
199767f8919635c4928607450d9e0abb932109ceToomas Soome// Type (derived) values.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_SYM_DTYPE_NULL 0 // no derived type.
199767f8919635c4928607450d9e0abb932109ceToomas Soome// Storage classes.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_SYM_CLASS_END_OF_FUNCTION (BYTE )-1
199767f8919635c4928607450d9e0abb932109ceToomas Soome// type packing constants
199767f8919635c4928607450d9e0abb932109ceToomas Soome// Communal selection types.
199767f8919635c4928607450d9e0abb932109ceToomas Soome// Relocation format.
199767f8919635c4928607450d9e0abb932109ceToomas Soome// I386 relocation types.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_REL_I386_ABSOLUTE 0 // Reference is absolute, no relocation is necessary
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_REL_I386_DIR16 01 // Direct 16-bit reference to the symbols virtual address
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_REL_I386_REL16 02 // PC-relative 16-bit reference to the symbols virtual address
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_REL_I386_DIR32 06 // Direct 32-bit reference to the symbols virtual address
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_REL_I386_DIR32NB 07 // Direct 32-bit reference to the symbols virtual address, base not included
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_REL_I386_SEG12 011 // Direct 16-bit reference to the segment-selector bits of a 32-bit virtual address
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_REL_I386_REL32 024 // PC-relative 32-bit reference to the symbols virtual address
199767f8919635c4928607450d9e0abb932109ceToomas Soome// MIPS relocation types.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_REL_MIPS_ABSOLUTE 0 // Reference is absolute, no relocation is necessary
199767f8919635c4928607450d9e0abb932109ceToomas Soome// Alpha Relocation types.
199767f8919635c4928607450d9e0abb932109ceToomas Soome// IBM PowerPC relocation types.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_REL_PPC_ADDR64 0x0001 // 64-bit address
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_REL_PPC_ADDR32 0x0002 // 32-bit address
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_REL_PPC_ADDR24 0x0003 // 26-bit address, shifted left 2 (branch absolute)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_REL_PPC_ADDR16 0x0004 // 16-bit address
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_REL_PPC_ADDR14 0x0005 // 16-bit address, shifted left 2 (load doubleword)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_REL_PPC_REL24 0x0006 // 26-bit PC-relative offset, shifted left 2 (branch relative)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_REL_PPC_REL14 0x0007 // 16-bit PC-relative offset, shifted left 2 (br cond relative)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_REL_PPC_TOCREL16 0x0008 // 16-bit offset from TOC base
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_REL_PPC_TOCREL14 0x0009 // 16-bit offset from TOC base, shifted left 2 (load doubleword)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_REL_PPC_ADDR32NB 0x000A // 32-bit addr w/o image base
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_REL_PPC_SECREL 0x000B // va of containing section (as in an image sectionhdr)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_REL_PPC_SECTION 0x000C // sectionheader number
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_REL_PPC_IFGLUE 0x000D // substitute TOC restore instruction iff symbol is glue code
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_REL_PPC_IMGLUE 0x000E // symbol is glue code; virtual address is TOC restore instruction
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_REL_PPC_TYPEMASK 0x00FF // mask to isolate above values in IMAGE_RELOCATION.Type
199767f8919635c4928607450d9e0abb932109ceToomas Soome// Flag bits in IMAGE_RELOCATION.TYPE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_REL_PPC_NEG 0x0100 // subtract reloc value rather than adding it
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_REL_PPC_BRTAKEN 0x0200 // fix branch prediction bit to predict branch taken
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_REL_PPC_BRNTAKEN 0x0400 // fix branch prediction bit to predict branch not taken
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_REL_PPC_TOCDEFN 0x0800 // toc slot defined in file (or, data in toc)
199767f8919635c4928607450d9e0abb932109ceToomas Soome// Based relocation format.
199767f8919635c4928607450d9e0abb932109ceToomas Soome// UINT16 TypeOffset[1];
199767f8919635c4928607450d9e0abb932109ceToomas Soome} IMAGE_BASE_RELOCATION, *PIMAGE_BASE_RELOCATION;
199767f8919635c4928607450d9e0abb932109ceToomas Soome// Based relocation types.
199767f8919635c4928607450d9e0abb932109ceToomas Soome// Line number format.
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINT32 SymbolTableIndex; // Symbol table index of function name if Linenumber is 0.
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINT32 VirtualAddress; // Virtual address of line number.
199767f8919635c4928607450d9e0abb932109ceToomas Soome// Archive format.
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINT8 Name[16]; // File member name - `/' terminated.
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINT8 UserID[6]; // File member user id - decimal.
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINT8 GroupID[6]; // File member group id - decimal.
199767f8919635c4928607450d9e0abb932109ceToomas Soome} IMAGE_ARCHIVE_MEMBER_HEADER, *PIMAGE_ARCHIVE_MEMBER_HEADER;
199767f8919635c4928607450d9e0abb932109ceToomas Soome// DLL support.
199767f8919635c4928607450d9e0abb932109ceToomas Soome// Export Format
199767f8919635c4928607450d9e0abb932109ceToomas Soome} IMAGE_EXPORT_DIRECTORY, *PIMAGE_EXPORT_DIRECTORY;
199767f8919635c4928607450d9e0abb932109ceToomas Soome// Import Format
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_SNAP_BY_ORDINAL(Ordinal) ((Ordinal & IMAGE_ORDINAL_FLAG) != 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IMAGE_ORDINAL(Ordinal) (Ordinal & 0xffff)
199767f8919635c4928607450d9e0abb932109ceToomas Soome} IMAGE_IMPORT_DESCRIPTOR, *PIMAGE_IMPORT_DESCRIPTOR;
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define CODEVIEW_SIGNATURE_NB10 0x3031424E // "NB10"
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome // Filename of .PDB goes here
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define CODEVIEW_SIGNATURE_RSDS 0x53445352 // "RSDS"
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome // Filename of .PDB goes here