1 /* 2 * Copyright 2013-2014, Haiku, Inc. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Alexander von Gluck IV, <kallisti5@unixzen.com> 7 */ 8 #ifndef _PE_COMMON_H 9 #define _PE_COMMON_H 10 11 12 #include <SupportDefs.h> 13 #include <ByteOrder.h> 14 15 16 // Magic strings 17 #define MZ_MAGIC "MZ" 18 #define PE_MAGIC "PE" 19 #define PE_OPTIONAL_MAGIC_PE32 0x010b 20 #define PE_OPTIONAL_MAGIC_PE32P 0x020b 21 22 23 typedef struct { 24 uint16 magic; /* == MZ_MAGIC */ 25 uint16 bytesInLastBlock; 26 uint16 blocksInFile; 27 uint16 numRelocations; 28 uint16 headerParagraphs; 29 uint16 minExtraParagraphs; 30 uint16 maxExtraParagraphs; 31 uint16 ss; 32 uint16 sp; 33 uint16 checksum; 34 uint16 ip; 35 uint16 cs; 36 uint16 relocationTableOffset; 37 uint16 overlayNumber; 38 uint16 reserved[4]; 39 uint16 oemID; 40 uint16 oemInfo; 41 uint16 reserved2[10]; 42 uint32 lfaNew; // PE Header start addr 43 } MzHeader; 44 45 typedef struct { 46 uint32 magic; // == PE_MAGIC */ 47 uint16 machine; 48 uint16 numberOfSections; 49 uint32 timeDateStamp; 50 uint32 pointerToSymbolTable; 51 uint32 numberOfSymbols; 52 uint16 sizeOfOptionalHeader; 53 uint16 characteristics; 54 } PeHeader; 55 56 typedef struct { 57 uint16 magic; // == 0x010b - PE32, 0x020b - PE32+ (64 bit) 58 uint8 majorLinkerVersion; 59 uint8 minorLinkerVersion; 60 uint32 sizeOfCode; 61 uint32 sizeOfInitializedData; 62 uint32 sizeOfUninitializedData; 63 uint32 addressOfEntryPoint; 64 uint32 baseOfCode; 65 uint32 baseOfData; 66 uint32 imageBase; 67 uint32 sectionAlignment; 68 uint32 fileAlignment; 69 uint16 majorOperatingSystemVersion; 70 uint16 minorOperatingSystemVersion; 71 uint16 majorImageVersion; 72 uint16 minorImageVersion; 73 uint16 majorSubsystemVersion; 74 uint16 minorSubsystemVersion; 75 uint32 win32VersionValue; 76 uint32 sizeOfImage; 77 uint32 sizeOfHeaders; 78 uint32 checksum; 79 uint16 subsystem; 80 uint16 llCharacteristics; 81 uint32 sizeOfStackReserve; 82 uint32 sizeOfStackCommit; 83 uint32 sizeOfHeapReserve; 84 uint32 sizeOfHeapCommit; 85 uint32 loaderFlags; 86 uint32 numberOfRvaAndSizes; 87 } Pe32OptionalHeader; 88 89 #endif /* _PE_COMMON_H */ 90