xref: /openbmc/qemu/contrib/elf2dmp/pe.h (revision 438c78da)
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 #include <stdint.h>
12 
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 #define IMAGE_FILE_DEBUG_DIRECTORY  6
92 
93 typedef struct IMAGE_DEBUG_DIRECTORY {
94   uint32_t Characteristics;
95   uint32_t TimeDateStamp;
96   uint16_t MajorVersion;
97   uint16_t MinorVersion;
98   uint32_t Type;
99   uint32_t SizeOfData;
100   uint32_t AddressOfRawData;
101   uint32_t PointerToRawData;
102 } __attribute__ ((packed)) IMAGE_DEBUG_DIRECTORY;
103 
104 #define IMAGE_DEBUG_TYPE_CODEVIEW   2
105 
106 typedef struct guid_t {
107     uint32_t a;
108     uint16_t b;
109     uint16_t c;
110     uint8_t d[2];
111     uint8_t  e[6];
112 } __attribute__ ((packed)) guid_t;
113 
114 typedef struct OMFSignatureRSDS {
115     char        Signature[4];
116     guid_t      guid;
117     uint32_t    age;
118     char        name[];
119 } __attribute__ ((packed)) OMFSignatureRSDS;
120 
121 #endif /* PE_H */
122