-
Notifications
You must be signed in to change notification settings - Fork 4
/
constants.py
124 lines (120 loc) · 4.91 KB
/
constants.py
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
from binaryninja import Architecture, Type
from enum import IntEnum
class VMTOffsets(object):
def __init__(self, delphi_version: int):
if delphi_version == 2:
self.cVmtSelfPtr = -0x34
self.cVmtInitTable = -0x30
self.cVmtTypeInfo = -0x2C
self.cVmtFieldTable = -0x28
self.cVmtMethodTable = -0x24
self.cVmtDynamicTable = -0x20
self.cVmtClassName = -0x1C
self.cVmtInstanceSize = -0x18
self.cVmtParent = -0x14
self.cVmtDefaultHandler = -0x10
self.cVmtNewInstance = -0xC
self.cVmtFreeInstance = -8
self.cVmtDestroy = -4
elif delphi_version == 3:
self.cVmtSelfPtr = -0x40
self.cVmtIntfTable = -0x3C
self.cVmtAutoTable = -0x38
self.cVmtInitTable = -0x34
self.cVmtTypeInfo = -0x30
self.cVmtFieldTable = -0x2C
self.cVmtMethodTable = -0x28
self.cVmtDynamicTable = -0x24
self.cVmtClassName = -0x20
self.cVmtInstanceSize = -0x1C
self.cVmtParent = -0x18
self.cVmtSafeCallException = -0x14
self.cVmtDefaultHandler = -0x10
self.cVmtNewInstance = -0xC
self.cVmtFreeInstance = -8
self.cVmtDestroy = -4
elif delphi_version in [4, 5, 6, 7, 2005, 2006, 2007]:
self.cVmtSelfPtr = -0x4C
self.cVmtIntfTable = -0x48
self.cVmtAutoTable = -0x44
self.cVmtInitTable = -0x40
self.cVmtTypeInfo = -0x3C
self.cVmtFieldTable = -0x38
self.cVmtMethodTable = -0x34
self.cVmtDynamicTable = -0x30
self.cVmtClassName = -0x2C
self.cVmtInstanceSize = -0x28
self.cVmtParent = -0x24
self.cVmtSafeCallException = -0x20
self.cVmtAfterConstruction = -0x1C
self.cVmtBeforeDestruction = -0x18
self.cVmtDispatch = -0x14
self.cVmtDefaultHandler = -0x10
self.cVmtNewInstance = -0xC
self.cVmtFreeInstance = -8
self.cVmtDestroy = -4
elif delphi_version in [2009, 2010]:
self.cVmtSelfPtr = -0x58
self.cVmtIntfTable = -0x54
self.cVmtAutoTable = -0x50
self.cVmtInitTable = -0x4C
self.cVmtTypeInfo = -0x48
self.cVmtFieldTable = -0x44
self.cVmtMethodTable = -0x40
self.cVmtDynamicTable = -0x3C
self.cVmtClassName = -0x38
self.cVmtInstanceSize = -0x34
self.cVmtParent = -0x30
self.cVmtEquals = -0x2C
self.cVmtGetHashCode = -0x28
self.cVmtToString = -0x24
self.cVmtSafeCallException = -0x20
self.cVmtAfterConstruction = -0x1C
self.cVmtBeforeDestruction = -0x18
self.cVmtDispatch = -0x14
self.cVmtDefaultHandler = -0x10
self.cVmtNewInstance = -0xC
self.cVmtFreeInstance = -8
self.cVmtDestroy = -4
elif delphi_version in [2011, 2012, 2013, 2014]:
self.cVmtSelfPtr = -0x58
self.cVmtIntfTable = -0x54
self.cVmtAutoTable = -0x50
self.cVmtInitTable = -0x4C
self.cVmtTypeInfo = -0x48
self.cVmtFieldTable = -0x44
self.cVmtMethodTable = -0x40
self.cVmtDynamicTable = -0x3C
self.cVmtClassName = -0x38
self.cVmtInstanceSize = -0x34
self.cVmtParent = -0x30
self.cVmtEquals = -0x2C
self.cVmtGetHashCode = -0x28
self.cVmtToString = -0x24
self.cVmtSafeCallException = -0x20
self.cVmtAfterConstruction = -0x1C
self.cVmtBeforeDestruction = -0x18
self.cVmtDispatch = -0x14
self.cVmtDefaultHandler = -0x10
self.cVmtNewInstance = -0xC
self.cVmtFreeInstance = -8
self.cVmtDestroy = -4
# self.cVmtQueryInterface = 0
# self.cVmtAddRef = 4
# self.cVmtRelease = 8
# self.cVmtCreateObject = 0xC
else:
raise RuntimeError(f'Unsuported Delphi version {delphi_version}')
class VMTFieldTypes(object):
def __init__(self, arch: Architecture):
self.cVmtSelfPtr = Type.pointer(arch, Type.void())
self.cVmtIntfTable = Type.pointer(arch, Type.void())
self.cVmtAutoTable = Type.pointer(arch, Type.void())
self.cVmtInitTable = Type.pointer(arch, Type.void())
self.cVmtTypeInfo = Type.pointer(arch, Type.void())
self.cVmtFieldTable = Type.pointer(arch, Type.void())
self.cVmtMethodTable = Type.pointer(arch, Type.void())
self.cVmtDynamicTable = Type.pointer(arch, Type.void())
self.cVmtClassName = Type.pointer(arch, Type.void())
self.cVmtInstanceSize = Type.int(4)
self.cVmtParent = Type.pointer(arch, Type.void())