xref: /openbmc/qemu/contrib/elf2dmp/pe.h (revision a68694cd)
1 /*
2  * Copyright (c) 2018 Virtuozzo International GmbH
3  *
4  * This work is licensed under the terms of the GNU GPL, version 2 or later.
5  *
6  */
7 
8 #ifndef PE_H
9 #define PE_H
10 
11 
12 #ifndef _WIN32
13 typedef struct IMAGE_DOS_HEADER {
14     uint16_t  e_magic;      /* 0x00: MZ Header signature */
15     uint16_t  e_cblp;       /* 0x02: Bytes on last page of file */
16     uint16_t  e_cp;         /* 0x04: Pages in file */
17     uint16_t  e_crlc;       /* 0x06: Relocations */
18     uint16_t  e_cparhdr;    /* 0x08: Size of header in paragraphs */
19     uint16_t  e_minalloc;   /* 0x0a: Minimum extra paragraphs needed */
20     uint16_t  e_maxalloc;   /* 0x0c: Maximum extra paragraphs needed */
21     uint16_t  e_ss;         /* 0x0e: Initial (relative) SS value */
22     uint16_t  e_sp;         /* 0x10: Initial SP value */
23     uint16_t  e_csum;       /* 0x12: Checksum */
24     uint16_t  e_ip;         /* 0x14: Initial IP value */
25     uint16_t  e_cs;         /* 0x16: Initial (relative) CS value */
26     uint16_t  e_lfarlc;     /* 0x18: File address of relocation table */
27     uint16_t  e_ovno;       /* 0x1a: Overlay number */
28     uint16_t  e_res[4];     /* 0x1c: Reserved words */
29     uint16_t  e_oemid;      /* 0x24: OEM identifier (for e_oeminfo) */
30     uint16_t  e_oeminfo;    /* 0x26: OEM information; e_oemid specific */
31     uint16_t  e_res2[10];   /* 0x28: Reserved words */
32     uint32_t  e_lfanew;     /* 0x3c: Offset to extended header */
33 } __attribute__ ((packed)) IMAGE_DOS_HEADER;
34 
35 typedef struct IMAGE_FILE_HEADER {
36   uint16_t  Machine;
37   uint16_t  NumberOfSections;
38   uint32_t  TimeDateStamp;
39   uint32_t  PointerToSymbolTable;
40   uint32_t  NumberOfSymbols;
41   uint16_t  SizeOfOptionalHeader;
42   uint16_t  Characteristics;
43 } __attribute__ ((packed)) IMAGE_FILE_HEADER;
44 
45 typedef struct IMAGE_DATA_DIRECTORY {
46   uint32_t VirtualAddress;
47   uint32_t Size;
48 } __attribute__ ((packed)) IMAGE_DATA_DIRECTORY;
49 
50 #define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
51 
52 typedef struct IMAGE_OPTIONAL_HEADER64 {
53   uint16_t  Magic; /* 0x20b */
54   uint8_t   MajorLinkerVersion;
55   uint8_t   MinorLinkerVersion;
56   uint32_t  SizeOfCode;
57   uint32_t  SizeOfInitializedData;
58   uint32_t  SizeOfUninitializedData;
59   uint32_t  AddressOfEntryPoint;
60   uint32_t  BaseOfCode;
61   uint64_t  ImageBase;
62   uint32_t  SectionAlignment;
63   uint32_t  FileAlignment;
64   uint16_t  MajorOperatingSystemVersion;
65   uint16_t  MinorOperatingSystemVersion;
66   uint16_t  MajorImageVersion;
67   uint16_t  MinorImageVersion;
68   uint16_t  MajorSubsystemVersion;
69   uint16_t  MinorSubsystemVersion;
70   uint32_t  Win32VersionValue;
71   uint32_t  SizeOfImage;
72   uint32_t  SizeOfHeaders;
73   uint32_t  CheckSum;
74   uint16_t  Subsystem;
75   uint16_t  DllCharacteristics;
76   uint64_t  SizeOfStackReserve;
77   uint64_t  SizeOfStackCommit;
78   uint64_t  SizeOfHeapReserve;
79   uint64_t  SizeOfHeapCommit;
80   uint32_t  LoaderFlags;
81   uint32_t  NumberOfRvaAndSizes;
82   IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
83 } __attribute__ ((packed)) IMAGE_OPTIONAL_HEADER64;
84 
85 typedef struct IMAGE_NT_HEADERS64 {
86   uint32_t Signature;
87   IMAGE_FILE_HEADER FileHeader;
88   IMAGE_OPTIONAL_HEADER64 OptionalHeader;
89 } __attribute__ ((packed)) IMAGE_NT_HEADERS64;
90 
91 typedef struct IMAGE_DEBUG_DIRECTORY {
92   uint32_t Characteristics;
93   uint32_t TimeDateStamp;
94   uint16_t MajorVersion;
95   uint16_t MinorVersion;
96   uint32_t Type;
97   uint32_t SizeOfData;
98   uint32_t AddressOfRawData;
99   uint32_t PointerToRawData;
100 } __attribute__ ((packed)) IMAGE_DEBUG_DIRECTORY;
101 
102 #define IMAGE_DEBUG_TYPE_CODEVIEW   2
103 #endif
104 
105 #define IMAGE_FILE_DEBUG_DIRECTORY  6
106 
107 typedef struct guid_t {
108     uint32_t a;
109     uint16_t b;
110     uint16_t c;
111     uint8_t d[2];
112     uint8_t  e[6];
113 } __attribute__ ((packed)) guid_t;
114 
115 typedef struct OMFSignatureRSDS {
116     char        Signature[4];
117     guid_t      guid;
118     uint32_t    age;
119     char        name[];
120 } __attribute__ ((packed)) OMFSignatureRSDS;
121 
122 #endif /* PE_H */
123