xref: /aosp_15_r20/external/google-breakpad/src/client/linux/minidump_writer/pe_structs.h (revision 9712c20fc9bbfbac4935993a2ca0b3958c5adad2)
1 // Copyright 2022 Google LLC
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 //     * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 //     * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 //     * Neither the name of Google LLC nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 #ifndef CLIENT_LINUX_MINIDUMP_WRITER_PE_STRUCTS_H_
30 #define CLIENT_LINUX_MINIDUMP_WRITER_PE_STRUCTS_H_
31 
32 #include <cstdint>
33 
34 namespace google_breakpad {
35 
36 typedef uint8_t BYTE;
37 typedef uint16_t WORD;
38 typedef uint32_t DWORD;
39 typedef uint64_t ULONGLONG;
40 
41 #define IMAGE_NT_OPTIONAL_HDR32_MAGIC 0x10b
42 #define IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x20b
43 
44 #define IMAGE_DEBUG_TYPE_CODEVIEW 2
45 
46 #define IMAGE_DOS_SIGNATURE 0x5A4D     // MZ
47 #define IMAGE_NT_SIGNATURE 0x00004550  // PE00
48 
49 #define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
50 #define IMAGE_DIRECTORY_ENTRY_DEBUG 6
51 
52 typedef struct _IMAGE_DOS_HEADER {  // DOS .EXE header
53   WORD e_magic;                     // Magic number
54   WORD e_cblp;                      // Bytes on last page of file
55   WORD e_cp;                        // Pages in file
56   WORD e_crlc;                      // Relocations
57   WORD e_cparhdr;                   // Size of header in paragraphs
58   WORD e_minalloc;                  // Minimum extra paragraphs needed
59   WORD e_maxalloc;                  // Maximum extra paragraphs needed
60   WORD e_ss;                        // Initial (relative) SS value
61   WORD e_sp;                        // Initial SP value
62   WORD e_csum;                      // Checksum
63   WORD e_ip;                        // Initial IP value
64   WORD e_cs;                        // Initial (relative) CS value
65   WORD e_lfarlc;                    // File address of relocation table
66   WORD e_ovno;                      // Overlay number
67   WORD e_res[4];                    // Reserved words
68   WORD e_oemid;                     // OEM identifier (for e_oeminfo)
69   WORD e_oeminfo;                   // OEM information; e_oemid specific
70   WORD e_res2[10];                  // Reserved words
71   DWORD e_lfanew;                   // File address of new exe header
72 } IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;
73 
74 typedef struct _IMAGE_FILE_HEADER {
75   WORD Machine;
76   WORD NumberOfSections;
77   DWORD TimeDateStamp;
78   DWORD PointerToSymbolTable;
79   DWORD NumberOfSymbols;
80   WORD SizeOfOptionalHeader;
81   WORD Characteristics;
82 } IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER;
83 
84 typedef struct _IMAGE_DATA_DIRECTORY {
85   DWORD VirtualAddress;
86   DWORD Size;
87 } IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY;
88 
89 
90 typedef struct _IMAGE_DEBUG_DIRECTORY {
91   DWORD Characteristics;
92   DWORD TimeDateStamp;
93   WORD MajorVersion;
94   WORD MinorVersion;
95   DWORD Type;
96   DWORD SizeOfData;
97   DWORD AddressOfRawData;
98   DWORD PointerToRawData;
99 } IMAGE_DEBUG_DIRECTORY, *PIMAGE_DEBUG_DIRECTORY;
100 
101 typedef struct _IMAGE_OPTIONAL_HEADER64 {
102   //
103   // Standard fields - Magic.
104   //
105   WORD Magic;
106   BYTE MajorLinkerVersion;
107   BYTE MinorLinkerVersion;
108   DWORD SizeOfCode;
109   DWORD SizeOfInitializedData;
110   DWORD SizeOfUninitializedData;
111   DWORD AddressOfEntryPoint;
112   DWORD BaseOfCode;
113   //
114   // NT additional fields.
115   //
116   ULONGLONG ImageBase;
117   DWORD SectionAlignment;
118   DWORD FileAlignment;
119   WORD MajorOperatingSystemVersion;
120   WORD MinorOperatingSystemVersion;
121   WORD MajorImageVersion;
122   WORD MinorImageVersion;
123   WORD MajorSubsystemVersion;
124   WORD MinorSubsystemVersion;
125   DWORD Win32VersionValue;
126   DWORD SizeOfImage;
127   DWORD SizeOfHeaders;
128   DWORD CheckSum;
129   WORD Subsystem;
130   WORD DllCharacteristics;
131   ULONGLONG SizeOfStackReserve;
132   ULONGLONG SizeOfStackCommit;
133   ULONGLONG SizeOfHeapReserve;
134   ULONGLONG SizeOfHeapCommit;
135   DWORD LoaderFlags;
136   DWORD NumberOfRvaAndSizes;
137   IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
138 } IMAGE_OPTIONAL_HEADER64, *PIMAGE_OPTIONAL_HEADER64;
139 
140 typedef struct _IMAGE_OPTIONAL_HEADER {
141   //
142   // Standard fields.
143   //
144   WORD Magic;
145   BYTE MajorLinkerVersion;
146   BYTE MinorLinkerVersion;
147   DWORD SizeOfCode;
148   DWORD SizeOfInitializedData;
149   DWORD SizeOfUninitializedData;
150   DWORD AddressOfEntryPoint;
151   DWORD BaseOfCode;
152   DWORD BaseOfData;
153   //
154   // NT additional fields.
155   //
156   DWORD ImageBase;
157   DWORD SectionAlignment;
158   DWORD FileAlignment;
159   WORD MajorOperatingSystemVersion;
160   WORD MinorOperatingSystemVersion;
161   WORD MajorImageVersion;
162   WORD MinorImageVersion;
163   WORD MajorSubsystemVersion;
164   WORD MinorSubsystemVersion;
165   DWORD Win32VersionValue;
166   DWORD SizeOfImage;
167   DWORD SizeOfHeaders;
168   DWORD CheckSum;
169   WORD Subsystem;
170   WORD DllCharacteristics;
171   DWORD SizeOfStackReserve;
172   DWORD SizeOfStackCommit;
173   DWORD SizeOfHeapReserve;
174   DWORD SizeOfHeapCommit;
175   DWORD LoaderFlags;
176   DWORD NumberOfRvaAndSizes;
177   IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
178 } IMAGE_OPTIONAL_HEADER32, *PIMAGE_OPTIONAL_HEADER32;
179 
180 typedef struct _IMAGE_NT_HEADERS64 {
181   DWORD Signature;
182   IMAGE_FILE_HEADER FileHeader;
183   IMAGE_OPTIONAL_HEADER64 OptionalHeader;
184 } IMAGE_NT_HEADERS64, *PIMAGE_NT_HEADERS64;
185 
186 typedef struct _IMAGE_NT_HEADERS32 {
187   DWORD Signature;
188   IMAGE_FILE_HEADER FileHeader;
189   IMAGE_OPTIONAL_HEADER32 OptionalHeader;
190 } IMAGE_NT_HEADERS32, *PIMAGE_NT_HEADERS32;
191 
192 typedef struct _IMAGE_NT_HEADERS {
193   DWORD Signature;
194   IMAGE_FILE_HEADER FileHeader;
195   IMAGE_OPTIONAL_HEADER32 OptionalHeader;
196 } IMAGE_NT_HEADERS, *PIMAGE_NT_HEADERS;
197 
198 #define IMAGE_SIZEOF_SHORT_NAME 8
199 
200 typedef struct _IMAGE_SECTION_HEADER {
201   BYTE Name[IMAGE_SIZEOF_SHORT_NAME];
202   union {
203     DWORD PhysicalAddress;
204     DWORD VirtualSize;
205   } Misc;
206   DWORD VirtualAddress;
207   DWORD SizeOfRawData;
208   DWORD PointerToRawData;
209   DWORD PointerToRelocations;
210   DWORD PointerToLinenumbers;
211   WORD NumberOfRelocations;
212   WORD NumberOfLinenumbers;
213   DWORD Characteristics;
214 } IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER;
215 
216 typedef struct _RSDS_DEBUG_FORMAT {
217   DWORD signature;
218   BYTE guid[16];
219   BYTE age[4];
220   char pdbpath[1];
221 } RSDS_DEBUG_FORMAT, *PRSDS_DEBUG_FORMAT;
222 
223 }  // namespace google_breakpad
224 
225 #endif  // CLIENT_LINUX_MINIDUMP_WRITER_PE_STRUCTS_H_