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
|
// 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
#include "cvutil.h"
bool isStruct(const codeview_type* cvtype)
{
switch(cvtype->common.id)
{
case LF_STRUCTURE_V1:
case LF_CLASS_V1:
case LF_STRUCTURE_V2:
case LF_CLASS_V2:
case LF_STRUCTURE_V3:
case LF_CLASS_V3:
return true;
}
return false;
}
bool isClass(const codeview_type* cvtype)
{
switch(cvtype->common.id)
{
case LF_CLASS_V1:
case LF_CLASS_V2:
case LF_CLASS_V3:
return true;
}
return false;
}
int getStructProperty(const codeview_type* cvtype)
{
switch(cvtype->common.id)
{
case LF_STRUCTURE_V1:
case LF_CLASS_V1:
return cvtype->struct_v1.property;
case LF_STRUCTURE_V2:
case LF_CLASS_V2:
return cvtype->struct_v2.property;
case LF_STRUCTURE_V3:
case LF_CLASS_V3:
return cvtype->struct_v3.property;
}
return 0;
}
int getStructFieldlist(const codeview_type* cvtype)
{
switch(cvtype->common.id)
{
case LF_STRUCTURE_V1:
case LF_CLASS_V1:
return cvtype->struct_v1.fieldlist;
case LF_STRUCTURE_V2:
case LF_CLASS_V2:
return cvtype->struct_v2.fieldlist;
case LF_STRUCTURE_V3:
case LF_CLASS_V3:
return cvtype->struct_v3.fieldlist;
}
return 0;
}
const BYTE* getStructName(const codeview_type* cvtype, bool &cstr)
{
int value, leaf_len;
switch(cvtype->common.id)
{
case LF_STRUCTURE_V1:
case LF_CLASS_V1:
cstr = false;
leaf_len = numeric_leaf(&value, &cvtype->struct_v1.structlen);
return (const BYTE*) &cvtype->struct_v1.structlen + leaf_len;
case LF_STRUCTURE_V2:
case LF_CLASS_V2:
cstr = false;
leaf_len = numeric_leaf(&value, &cvtype->struct_v2.structlen);
return (const BYTE*) &cvtype->struct_v2.structlen + leaf_len;
case LF_STRUCTURE_V3:
case LF_CLASS_V3:
cstr = true;
leaf_len = numeric_leaf(&value, &cvtype->struct_v3.structlen);
return (const BYTE*) &cvtype->struct_v3.structlen + leaf_len;
}
return 0;
}
bool cmpStructName(const codeview_type* cvtype, const BYTE* name, bool cstr)
{
bool cstr2;
const BYTE* name2 = getStructName(cvtype, cstr2);
if(!name || !name2)
return name == name2;
return dstrcmp(name, cstr, name2, cstr2);
}
bool isCompleteStruct(const codeview_type* type, const BYTE* name, bool cstr)
{
return isStruct(type)
&& !(getStructProperty(type) & kPropIncomplete)
&& cmpStructName(type, name, cstr);
}
int numeric_leaf(int* value, const void* leaf)
{
unsigned short int type = *(const unsigned short int*) leaf;
leaf = (const unsigned short int*) leaf + 1;
int length = 2;
*value = 0;
switch (type)
{
case LF_CHAR:
length += 1;
*value = *(const char*)leaf;
break;
case LF_SHORT:
length += 2;
*value = *(const short*)leaf;
break;
case LF_USHORT:
length += 2;
*value = *(const unsigned short*)leaf;
break;
case LF_LONG:
case LF_ULONG:
length += 4;
*value = *(const int*)leaf;
break;
case LF_COMPLEX64:
case LF_QUADWORD:
case LF_UQUADWORD:
case LF_REAL64:
length += 8;
break;
case LF_COMPLEX32:
case LF_REAL32:
length += 4;
break;
case LF_REAL48:
length += 6;
break;
case LF_COMPLEX80:
case LF_REAL80:
length += 10;
break;
case LF_COMPLEX128:
case LF_REAL128:
length += 16;
break;
case LF_VARSTRING:
length += 2 + *(const unsigned short*)leaf;
break;
default:
if (type < LF_NUMERIC)
*value = type;
else
{
length = 0; // error!
}
break;
}
return length;
}
int write_numeric_leaf(int value, void* leaf)
{
if(value >= 0 && value < LF_NUMERIC)
{
*(unsigned short int*) leaf = (unsigned short) value;
return 2;
}
unsigned short int* type = (unsigned short int*) leaf;
leaf = type + 1;
if (value >= -128 && value <= 127)
{
*type = LF_CHAR;
*(char*) leaf = (char)value;
return 3;
}
if (value >= -32768 && value <= 32767)
{
*type = LF_SHORT;
*(short*) leaf = (short)value;
return 4;
}
if (value >= 0 && value <= 65535)
{
*type = LF_USHORT;
*(unsigned short*) leaf = (unsigned short)value;
return 4;
}
*type = LF_LONG;
*(long*) leaf = (long)value;
return 6;
}
|