3
3
from .delphi_analyser import DelphiVMT
4
4
from .constants import VMTFieldTypes
5
5
6
+ ## Backwards compatibility for API < 2500
7
+ try :
8
+ StructureType = types .StructureBuilder
9
+ except AttributeError :
10
+ StructureType = types .Structure
11
+
6
12
7
13
class BNHelpers (object ):
8
14
@staticmethod
9
15
def create_vmt_struct (bv : BinaryView , vmt : DelphiVMT ) -> bool :
10
16
if not vmt .is_valid :
11
17
return False
12
18
13
- vmt_struct = types .Structure ()
19
+ ## Backwards compatibility for API < 2500
20
+ try :
21
+ vmt_struct = types .StructureBuilder .create ()
22
+ except AttributeError :
23
+ vmt_struct = types .Structure ()
14
24
15
25
if not BNHelpers ._add_vmt_fields (bv , vmt , vmt_struct ):
16
26
return False
@@ -31,7 +41,7 @@ def create_vmt_struct(bv: BinaryView, vmt: DelphiVMT) -> bool:
31
41
# Protected methods
32
42
33
43
@staticmethod
34
- def _add_vmt_fields (bv : BinaryView , vmt : DelphiVMT , out_struct : types . Structure ) -> bool :
44
+ def _add_vmt_fields (bv : BinaryView , vmt : DelphiVMT , out_struct : StructureType ) -> bool :
35
45
address_size = bv .address_size
36
46
field_types = VMTFieldTypes (bv .arch )
37
47
vmt_offsets = vmt .vmt_offsets
@@ -52,7 +62,7 @@ def _add_vmt_fields(bv: BinaryView, vmt: DelphiVMT, out_struct: types.Structure)
52
62
53
63
54
64
@staticmethod
55
- def _add_vmt_methods (bv : BinaryView , vmt : DelphiVMT , out_struct : types . Structure ) -> bool :
65
+ def _add_vmt_methods (bv : BinaryView , vmt : DelphiVMT , out_struct : StructureType ) -> bool :
56
66
address_size = bv .address_size
57
67
58
68
if not vmt .seek_to_vmt_offset (vmt .vmt_offsets .cVmtParent + address_size ):
@@ -105,7 +115,7 @@ def _add_vmt_methods(bv: BinaryView, vmt: DelphiVMT, out_struct: types.Structure
105
115
# Private methods
106
116
107
117
@staticmethod
108
- def __create_class_name_type (bv : BinaryView , vmt : DelphiVMT , out_struct : types . Structure ) -> bool :
118
+ def __create_class_name_type (bv : BinaryView , vmt : DelphiVMT , out_struct : StructureType ) -> bool :
109
119
vmt_offsets = vmt .vmt_offsets
110
120
111
121
if not vmt .seek_to_vmt_offset (vmt_offsets .cVmtClassName ):
@@ -124,7 +134,12 @@ def __create_class_name_type(bv: BinaryView, vmt: DelphiVMT, out_struct: types.S
124
134
if class_name_len is None :
125
135
return False
126
136
127
- class_name_struct = types .Structure ()
137
+ ## Backwards compatibility for API < 2500
138
+ try :
139
+ class_name_struct = types .StructureBuilder .create ()
140
+ except AttributeError :
141
+ class_name_struct = types .Structure ()
142
+
128
143
class_name_struct .append (Type .int (1 , False ), 'length' )
129
144
class_name_struct .append (Type .array (Type .char (), class_name_len ), 'value' )
130
145
struct_type = Type .structure_type (class_name_struct )
0 commit comments