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
|
// Convert DMD CodeView debug information to PDB files
// Copyright (c) 2009-2010 by Rainer Schuetze, All Rights Reserved
//
// License for redistribution is given by the Artistic License 2.0
// see file LICENSE for further details
#ifndef __CV2PDB_H__
#define __CV2PDB_H__
#include "LastError.h"
#include "mspdb.h"
#include <windows.h>
extern "C" {
#include "mscvpdb.h"
}
class PEImage;
class CV2PDB : public LastError
{
public:
CV2PDB(PEImage& image);
~CV2PDB();
bool cleanup(bool commit);
bool openPDB(const char* pdbname);
bool setError(const char* msg);
bool createModules();
bool initLibraries();
const BYTE* getLibrary(int i);
bool initSegMap();
enum
{
kCmdAdd,
kCmdCount,
kCmdNestedTypes,
kCmdOffsetFirstVirtualMethod,
kCmdHasClassTypeEnum,
kCmdCountBaseClasses
};
int _doFields(int cmd, codeview_reftype* dfieldlist, const codeview_reftype* fieldlist, int arg);
int addFields(codeview_reftype* dfieldlist, const codeview_reftype* fieldlist, int maxdlen);
int countFields(const codeview_reftype* fieldlist);
int countNestedTypes(const codeview_reftype* fieldlist, int type);
int addAggregate(codeview_type* dtype, bool clss, int n_element, int fieldlist, int property,
int derived, int vshape, int structlen, const char*name);
int addClass(codeview_type* dtype, int n_element, int fieldlist, int property,
int derived, int vshape, int structlen, const char*name);
int addStruct(codeview_type* dtype, int n_element, int fieldlist, int property,
int derived, int vshape, int structlen, const char*name);
int addEnum(codeview_type* dtype, int count, int fieldlist, int property,
int type, const char*name);
int addPointerType(codeview_type* dtype, int type, int attr = 0x800A);
int addPointerType(unsigned char* dtype, int type, int attr = 0x800A);
int addFieldMember(codeview_fieldtype* dfieldtype, int attr, int offset, int type, const char* name);
int addFieldStaticMember(codeview_fieldtype* dfieldtype, int attr, int type, const char* name);
int addFieldNestedType(codeview_fieldtype* dfieldtype, int type, const char* name);
int addFieldEnumerate(codeview_fieldtype* dfieldtype, const char* name, int val);
void checkUserTypeAlloc(int size = 1000, int add = 10000);
void checkGlobalTypeAlloc(int size, int add = 1000);
void writeUserTypeLen(codeview_type* type, int len);
const codeview_type* getTypeData(int type);
const codeview_type* getUserTypeData(int type);
const codeview_type* getConvertedTypeData(int type);
const codeview_type* findCompleteClassType(const codeview_type* cvtype, int* ptype = 0);
int findMemberFunctionType(codeview_symbol* lastGProcSym, int thisPtrType);
int fixProperty(int type, int prop, int fieldType);
bool derivesFromObject(const codeview_type* cvtype);
bool isCppInterface(const codeview_type* cvtype);
int sizeofClassType(const codeview_type* cvtype);
int sizeofBasicType(int type);
int sizeofType(int type);
// to be used when writing new type only to avoid double translation
int translateType(int type);
int getBaseClass(const codeview_type* cvtype);
int countBaseClasses(const codeview_type* cvtype);
bool nameOfBasicType(int type, char* name, int maxlen);
bool nameOfType(int type, char* name, int maxlen);
bool nameOfDynamicArray(int indexType, int elemType, char* name, int maxlen);
bool nameOfAssocArray(int indexType, int elemType, char* name, int maxlen);
bool nameOfDelegate(int thisType, int funcType, char* name, int maxlen);
bool nameOfOEMType(codeview_oem_type* oem, char* name, int maxlen);
bool nameOfModifierType(int type, int mod, char* name, int maxlen);
int numeric_leaf(int* value, const void* leaf);
int copy_leaf(unsigned char* dp, int& dpos, const unsigned char* p, int& pos);
const char* appendDynamicArray(int indexType, int elemType);
const char* appendAssocArray(int keyType, int elemType);
const char* appendDelegate(int thisType, int funcType);
int appendObjectType (int object_derived_type, int enumType, const char* classSymbol);
int appendPointerType(int pointedType, int attr);
int appendTypedef(int type, const char* name);
int appendComplex(int cplxtype, int basetype, int elemsize, const char* name);
void appendTypedefs();
int appendEnumerator(const char* typeName, const char* enumName, int enumValue, int prop);
int appendClassTypeEnum(const codeview_type* fieldlist, int type, const char* name);
bool hasClassTypeEnum(const codeview_type* fieldlist);
bool insertClassTypeEnums();
int insertBaseClass(const codeview_type* fieldlist, int type);
bool initGlobalTypes();
bool initGlobalSymbols();
bool addTypes();
bool addSrcLines();
bool addPublics();
codeview_symbol* findUdtSymbol(int type);
bool addUdtSymbol(int type, const char* name);
void ensureUDT(int type, const codeview_type* cvtype);
// returns new destSize
int copySymbols(BYTE* srcSymbols, int srcSize, BYTE* destSymbols, int destSize);
bool writeSymbols(mspdb::Mod* mod, DWORD* data, int databytes, int prefix, bool addGlobals);
bool addSymbols(mspdb::Mod* mod, BYTE* symbols, int cb, bool addGlobals);
bool addSymbols(int iMod, BYTE* symbols, int cb, bool addGlobals);
bool addSymbols();
bool markSrcLineInBitmap(int segIndex, int adr);
bool createSrcLineBitmap();
int getNextSrcLine(int seg, unsigned int off);
bool writeImage(const char* opath);
mspdb::Mod* globalMod();
// private:
BYTE* libraries;
PEImage& img;
mspdb::PDB* pdb;
mspdb::DBI *dbi;
mspdb::TPI *tpi;
mspdb::Mod** modules;
mspdb::Mod* globmod;
int countEntries;
OMFSignatureRSDS* rsds;
OMFSegMap* segMap;
OMFSegMapDesc* segMapDesc;
int* segFrame2Index;
OMFGlobalTypes* globalTypeHeader;
unsigned char* globalTypes;
int cbGlobalTypes;
int allocGlobalTypes;
unsigned char* userTypes;
int* pointerTypes;
int cbUserTypes;
int allocUserTypes;
unsigned char* globalSymbols;
int cbGlobalSymbols;
unsigned char* staticSymbols;
int cbStaticSymbols;
unsigned char* udtSymbols;
int cbUdtSymbols;
int allocUdtSymbols;
int nextUserType;
int objectType;
int classEnumType;
int ifaceEnumType;
int cppIfaceEnumType;
int structEnumType;
int classBaseType;
int ifaceBaseType;
int cppIfaceBaseType;
int structBaseType;
// D named types
int typedefs[20];
int translatedTypedefs[20];
int cntTypedefs;
bool addClassTypeEnum;
bool useGlobalMod;
bool thisIsNotRef;
bool v3;
const char* lastError;
int srcLineSections;
char** srcLineStart; // array of bitmaps per segment, indicating whether src line start is available for corresponding address
double Dversion;
};
#endif //__CV2PDB_H__
|