-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathPDBHeaderReconstructor.h
289 lines (242 loc) · 5.58 KB
/
PDBHeaderReconstructor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#pragma once
#include "PDBReconstructorBase.h"
#include <iostream>
#include <numeric> // std::accumulate
#include <string>
#include <map>
#include <set>
#include <cassert>
class PDBHeaderReconstructor
: public PDBReconstructorBase
{
public:
enum class MemberStructExpansionType
{
//
// No expansion of nested UDTs (user defined types).
//
None,
//
// Expand only unnamed UDTs (user defined types).
//
InlineUnnamed,
//
// Expand all referenced UDTs (user defined types).
//
InlineAll,
};
struct Settings
{
Settings()
{
MemberStructExpansion = MemberStructExpansionType::InlineUnnamed;
OutputFile = &std::cout;
TestFile = nullptr;
PaddingMemberPrefix = "Padding_";
BitFieldPaddingMemberPrefix = "";
UnnamedTypePrefix = "TAG_UNNAMED_";
AnonymousStructPrefix = "s"; // DUMMYSTRUCTNAME (up to 6)
AnonymousUnionPrefix = "u"; // DUMMYUNIONNAME (up to 9)
CreatePaddingMembers = true;
ShowOffsets = true;
MicrosoftTypedefs = true;
AllowBitFieldsInUnion = false;
AllowAnonymousDataTypes = true;
}
MemberStructExpansionType MemberStructExpansion;
std::ostream* OutputFile;
std::ostream* TestFile;
std::string PaddingMemberPrefix;
std::string BitFieldPaddingMemberPrefix;
std::string UnnamedTypePrefix;
std::string SymbolPrefix;
std::string SymbolSuffix;
std::string AnonymousStructPrefix;
std::string AnonymousUnionPrefix;
bool CreatePaddingMembers : 1;
bool ShowOffsets : 1;
bool MicrosoftTypedefs : 1;
bool AllowBitFieldsInUnion : 1;
bool AllowAnonymousDataTypes : 1;
};
PDBHeaderReconstructor(
Settings* VisitorSettings = nullptr
);
void
Clear();
const std::string&
GetCorrectedSymbolName(
const SYMBOL* Symbol
) const;
protected:
bool
OnEnumType(
const SYMBOL* Symbol
) override;
void
OnEnumTypeBegin(
const SYMBOL* Symbol
) override;
void
OnEnumTypeEnd(
const SYMBOL* Symbol
) override;
void
OnEnumField(
const SYMBOL_ENUM_FIELD* EnumField
) override;
bool
OnUdt(
const SYMBOL* Symbol
) override;
void
OnUdtBegin(
const SYMBOL* Symbol
) override;
void
OnUdtEnd(
const SYMBOL* Symbol
) override;
void
OnUdtFieldBegin(
const SYMBOL_UDT_FIELD* UdtField
) override;
void
OnUdtFieldEnd(
const SYMBOL_UDT_FIELD* UdtField
) override;
void
OnUdtField(
const SYMBOL_UDT_FIELD* UdtField,
UdtFieldDefinitionBase* MemberDefinition
) override;
void
OnAnonymousUdtBegin(
UdtKind Kind,
const SYMBOL_UDT_FIELD* FirstUdtField
) override;
void
OnAnonymousUdtEnd(
UdtKind Kind,
const SYMBOL_UDT_FIELD* FirstUdtField,
const SYMBOL_UDT_FIELD* LastUdtField,
DWORD Size
) override;
void
OnUdtFieldBitFieldBegin(
const SYMBOL_UDT_FIELD* FirstUdtFieldBitField,
const SYMBOL_UDT_FIELD* LastUdtFieldBitField
) override;
void
OnUdtFieldBitFieldEnd(
const SYMBOL_UDT_FIELD* FirstUdtFieldBitField,
const SYMBOL_UDT_FIELD* LastUdtFieldBitField
) override;
void
OnPaddingMember(
const SYMBOL_UDT_FIELD* UdtField,
BasicType PaddingBasicType,
DWORD PaddingBasicTypeSize,
DWORD PaddingSize
) override;
void
OnPaddingBitFieldField(
const SYMBOL_UDT_FIELD* UdtField,
const SYMBOL_UDT_FIELD* PreviousUdtField
) override;
private:
void
Write(
const char* Format,
...
);
void
WriteIndent();
void
WriteVariant(
const VARIANT* v
);
void
WriteUnnamedDataType(
UdtKind Kind
);
void
WriteTypedefBegin(
const SYMBOL* Symbol
);
void
WriteTypedefEnd(
const SYMBOL* Symbol
);
void
WriteConstAndVolatile(
const SYMBOL* Symbol
);
void
WriteOffset(
const SYMBOL_UDT_FIELD* UdtField,
int PaddingOffset
);
bool
HasBeenVisited(
const SYMBOL* Symbol
) const;
void
MarkAsVisited(
const SYMBOL* Symbol
);
DWORD
GetParentOffset() const;
void
AppendToTest(
const SYMBOL_UDT_FIELD* UdtField
);
bool
ShouldExpand(
const SYMBOL* Symbol
) const;
private:
//
// Settings for this visitor.
//
Settings* m_Settings;
//
// Everytime visitor enters a new member (UDT field),
// it pushes the current offset here.
// In case the current member is a new struct (or any other UDT)
// which will be expanded, this property
// helps to find the offset of the parent member.
//
std::vector<DWORD> m_OffsetStack;
//
// Indentation.
//
DWORD m_Depth = 0;
//
// Counter for anonymous UDTs.
//
DWORD m_AnonymousDataTypeCounter = 0;
//
// Counter of padding members.
//
DWORD m_PaddingMemberCounter = 0;
//
// Collection of unnamed symbols.
//
// Unnamed symbols actually have a special name.
// See PDB::IsUnnamedSymbol() for more information.
//
mutable std::set<const SYMBOL*> m_UnnamedSymbols;
//
// Mapping of symbols to their "corrected" names.
//
mutable std::map<const SYMBOL*, std::string> m_CorrectedSymbolNames;
//
// Collection of symbol names which has already been visited.
// We save names of the symbols here, because some PDBs
// has multiple definition of the same symbol.
//
// See PDBVisitorSorter::HasBeenVisited() for more information.
//
std::set<std::string> m_VisitedSymbols;
};