-
Notifications
You must be signed in to change notification settings - Fork 10
/
SymbolMemberInfo.cs
153 lines (144 loc) · 4.54 KB
/
SymbolMemberInfo.cs
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
using Dia2Lib;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace CruncherSharp
{
public class SymbolMemberInfo
{
public enum MemberCategory
{
VTable = 0,
Base = 1,
Member = 2,
UDT = 3,
Pointer = 4
}
public MemberCategory Category { get; set; }
public string Name { get; set; }
public string DisplayName
{
get
{
switch (Category)
{
case MemberCategory.VTable:
return "vtable";
case MemberCategory.Base:
return $"Base: {Name}";
default:
return Name;
}
}
}
public string TypeName { get; set; }
public ulong Size { get; set; }
public ulong BitSize { get; set; }
public ulong Offset { get; set; }
public uint BitPosition { get; set; }
public ulong PaddingBefore { get; set; }
public ulong BitPaddingAfter { get; set; }
public bool AlignWithPrevious { get; set; }
public bool BitField { get; set; }
public bool Volatile { get; set; }
public bool Expanded { get; set; }
public SymbolMemberInfo(MemberCategory category, string name, string typeName, ulong size, ulong bitSize, ulong offset, uint bitPosition)
{
Category = category;
Name = name;
TypeName = typeName;
Size = size;
BitSize = bitSize;
Offset = offset;
BitPosition = bitPosition;
AlignWithPrevious = false;
PaddingBefore = 0;
BitPaddingAfter = 0;
BitField = false;
Volatile = false;
Expanded = false;
}
public bool IsBase => Category == MemberCategory.Base;
public bool IsExapandable => (Category == MemberCategory.Base || Category == MemberCategory.UDT);
public static int CompareOffsets(SymbolMemberInfo a, SymbolMemberInfo b)
{
if (a.Offset != b.Offset)
{
return a.Offset < b.Offset ? -1 : 1;
}
if (a.IsBase != b.IsBase)
{
return a.IsBase ? -1 : 1;
}
if (a.BitPosition != b.BitPosition)
{
return a.BitPosition < b.BitPosition ? -1 : 1;
}
if (a.Size != b.Size)
{
return a.Size > b.Size ? -1 : 1;
}
return 0;
}
public static string GetBaseType(IDiaSymbol typeSymbol)
{
//cf. https://msdn.microsoft.com/en-us/library/4szdtzc3.aspx
switch (typeSymbol.baseType)
{
case 0:
return string.Empty;
case 1:
return "void";
case 2:
return "char";
case 3:
return "wchar";
case 6:
{
switch (typeSymbol.length)
{
case 1:
return "int8";
case 2:
return "int16";
case 4:
return "int32";
case 8:
return "int64";
default:
return "int";
}
}
case 7:
switch (typeSymbol.length)
{
case 1:
return "uint8";
case 2:
return "uint16";
case 4:
return "uint32";
case 8:
return "uint64";
default:
return "uint";
}
case 8:
return "float";
case 9:
return "BCS";
case 10:
return "bool";
case 13:
return "int32";
case 14:
return "uint32";
case 29:
return "bit";
default:
return $"Unhandled: {typeSymbol.baseType}";
}
}
}
}