1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4//
5// ZapHeaders.h
6//
7
8//
9// Zapping of headers (IMAGE_COR20_HEADER, CORCOMPILE_HEADER, etc.)
10//
11// ======================================================================================
12
13#ifndef __ZAPHEADERS_H__
14#define __ZAPHEADERS_H__
15
16//
17// IMAGE_COR20_HEADER
18//
19
20class ZapCorHeader : public ZapNode
21{
22public:
23 ZapCorHeader(ZapImage * pImage)
24 {
25 }
26
27 virtual DWORD GetSize()
28 {
29 return sizeof(IMAGE_COR20_HEADER);
30 }
31
32 virtual UINT GetAlignment()
33 {
34 return sizeof(DWORD);
35 }
36
37 virtual ZapNodeType GetType()
38 {
39 return ZapNodeType_CorHeader;
40 }
41
42 virtual void Save(ZapWriter * pZapWriter)
43 {
44 ZapImage::GetImage(pZapWriter)->SaveCorHeader();
45 }
46};
47
48//
49// CORCOMPILE_HEADER
50//
51
52class ZapNativeHeader : public ZapNode
53{
54public:
55 ZapNativeHeader(ZapImage * pImage)
56 {
57 }
58
59 virtual DWORD GetSize()
60 {
61 return sizeof(CORCOMPILE_HEADER);
62 }
63
64 virtual UINT GetAlignment()
65 {
66 return sizeof(DWORD);
67 }
68
69 virtual ZapNodeType GetType()
70 {
71 return ZapNodeType_NativeHeader;
72 }
73
74 virtual void Save(ZapWriter * pZapWriter)
75 {
76 ZapImage::GetImage(pZapWriter)->SaveNativeHeader();
77 }
78};
79
80//
81// CORCOMPILE_VERSION_INFO
82//
83class ZapVersionInfo : public ZapNode
84{
85 CORCOMPILE_VERSION_INFO m_versionInfo;
86
87public:
88 ZapVersionInfo(CORCOMPILE_VERSION_INFO * pVersionInfo)
89 {
90 memcpy(&m_versionInfo, pVersionInfo, sizeof(m_versionInfo));
91 }
92
93 CORCOMPILE_VERSION_INFO * GetData()
94 {
95 return &m_versionInfo;
96 }
97
98 virtual DWORD GetSize()
99 {
100 return sizeof(CORCOMPILE_VERSION_INFO);
101 }
102
103 virtual UINT GetAlignment()
104 {
105 return sizeof(DWORD);
106 }
107
108 virtual ZapNodeType GetType()
109 {
110 return ZapNodeType_VersionInfo;
111 }
112
113 virtual void Save(ZapWriter * pZapWriter)
114 {
115 pZapWriter->Write(&m_versionInfo, sizeof(m_versionInfo));
116 }
117};
118
119//
120// CORCOMPILE_CORCOMPILE_DEPENDENCY
121//
122class ZapDependencies : public ZapNode
123{
124 DWORD m_cDependencies;
125 CORCOMPILE_DEPENDENCY * m_pDependencies;
126
127public:
128 ZapDependencies(CORCOMPILE_DEPENDENCY * pDependencies, DWORD cDependencies)
129 : m_cDependencies(cDependencies), m_pDependencies(pDependencies)
130 {
131 }
132
133 virtual DWORD GetSize()
134 {
135 return sizeof(CORCOMPILE_DEPENDENCY) * m_cDependencies;
136 }
137
138 virtual UINT GetAlignment()
139 {
140 return sizeof(ULARGE_INTEGER);
141 }
142
143 virtual ZapNodeType GetType()
144 {
145 return ZapNodeType_Dependencies;
146 }
147
148 virtual void Save(ZapWriter * pZapWriter)
149 {
150 pZapWriter->Write(m_pDependencies, sizeof(CORCOMPILE_DEPENDENCY) * m_cDependencies);
151 }
152};
153
154//
155// CORCOMPILE_CODE_MANAGER_ENTRY
156//
157
158class ZapCodeManagerEntry : public ZapNode
159{
160public:
161 ZapCodeManagerEntry(ZapImage * pImage)
162 {
163 }
164
165 virtual DWORD GetSize()
166 {
167 return sizeof(CORCOMPILE_CODE_MANAGER_ENTRY);
168 }
169
170 virtual UINT GetAlignment()
171 {
172 return sizeof(DWORD);
173 }
174
175 virtual ZapNodeType GetType()
176 {
177 return ZapNodeType_CodeManagerEntry;
178 }
179
180 virtual void Save(ZapWriter * pZapWriter)
181 {
182 ZapImage::GetImage(pZapWriter)->SaveCodeManagerEntry();
183 }
184};
185
186//
187// Version Resource
188//
189
190class ZapVersionResource : public ZapNode
191{
192 ZapNode * m_pVersionData;
193
194public:
195 ZapVersionResource(ZapNode * pVersionData)
196 : m_pVersionData(pVersionData)
197 {
198 }
199
200 struct VersionResourceHeader {
201 IMAGE_RESOURCE_DIRECTORY TypeDir;
202 IMAGE_RESOURCE_DIRECTORY_ENTRY TypeEntry;
203 IMAGE_RESOURCE_DIRECTORY NameDir;
204 IMAGE_RESOURCE_DIRECTORY_ENTRY NameEntry;
205 IMAGE_RESOURCE_DIRECTORY LangDir;
206 IMAGE_RESOURCE_DIRECTORY_ENTRY LangEntry;
207 IMAGE_RESOURCE_DATA_ENTRY DataEntry;
208 CHAR Data[0];
209 };
210
211 virtual DWORD GetSize()
212 {
213 return sizeof(VersionResourceHeader);
214 }
215
216 virtual UINT GetAlignment()
217 {
218 return sizeof(DWORD);
219 }
220
221 virtual ZapNodeType GetType()
222 {
223 return ZapNodeType_VersionResource;
224 }
225
226 virtual void Save(ZapWriter * pZapWriter);
227};
228
229
230//
231// Debug Directory
232//
233
234class ZapDebugDirectory : public ZapNode
235{
236 ZapNode * m_pNGenPdbDebugData;
237 DWORD m_nDebugDirectory;
238 IMAGE_DEBUG_DIRECTORY * m_pDebugDirectory;
239 ZapNode ** m_ppDebugData;
240
241public:
242 ZapDebugDirectory(ZapNode *pNGenPdbDebugData, DWORD nDebugDirectory, PIMAGE_DEBUG_DIRECTORY pDebugDirectory, ZapNode ** ppDebugData)
243 : m_pNGenPdbDebugData(pNGenPdbDebugData),
244 m_nDebugDirectory(nDebugDirectory),
245 m_pDebugDirectory(pDebugDirectory),
246 m_ppDebugData(ppDebugData)
247 {
248 }
249
250 virtual DWORD GetSize()
251 {
252#if defined(NO_NGENPDB)
253 return sizeof(IMAGE_DEBUG_DIRECTORY) * m_nDebugDirectory;
254#else
255 // Add one for NGen PDB debug directory entry
256 return sizeof(IMAGE_DEBUG_DIRECTORY) * (m_nDebugDirectory + 1);
257#endif // NO_NGENPDB
258 }
259
260 virtual UINT GetAlignment()
261 {
262 return sizeof(DWORD);
263 }
264
265 virtual ZapNodeType GetType()
266 {
267 return ZapNodeType_DebugDirectory;
268 }
269
270 void SaveOriginalDebugDirectoryEntry(ZapWriter *pZapWriter);
271 void SaveNGenDebugDirectoryEntry(ZapWriter *pZapWriter);
272 virtual void Save(ZapWriter * pZapWriter);
273};
274
275//
276// PE Style exports. Currently can only save an empty list of exports
277// but this is useful because it avoids the DLL being seen as Resource Only
278// (which then causes SymServer to avoid copying its PDB to the cloud).
279//
280
281class ZapPEExports : public ZapNode
282{
283 LPCWSTR m_dllFileName; // Just he DLL name without the path.
284
285public:
286 ZapPEExports(LPCWSTR dllPath);
287 virtual DWORD GetSize();
288 virtual UINT GetAlignment() { return sizeof(DWORD); }
289 virtual void Save(ZapWriter * pZapWriter);
290};
291
292//
293// List of all sections for diagnostic purposes
294
295class ZapVirtualSectionsTable : public ZapNode
296{
297 ZapImage * m_pImage;
298
299public:
300
301 ZapVirtualSectionsTable(ZapImage * pImage)
302 : m_pImage(pImage)
303 {
304 }
305
306 virtual DWORD GetSize();
307
308 virtual ZapNodeType GetType()
309 {
310 return ZapNodeType_VirtualSectionsTable;
311 }
312
313 virtual void Save(ZapWriter * pZapWriter);
314};
315
316#endif // __ZAPHEADERS_H__
317