Skip to content

Commit 965d513

Browse files
committed
🚑 Fix Structure builder type for new API
Fix #1
1 parent 357d2a2 commit 965d513

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

bnhelpers.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,24 @@
33
from .delphi_analyser import DelphiVMT
44
from .constants import VMTFieldTypes
55

6+
## Backwards compatibility for API < 2500
7+
try:
8+
StructureType = types.StructureBuilder
9+
except AttributeError:
10+
StructureType = types.Structure
11+
612

713
class BNHelpers(object):
814
@staticmethod
915
def create_vmt_struct(bv: BinaryView, vmt: DelphiVMT) -> bool:
1016
if not vmt.is_valid:
1117
return False
1218

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()
1424

1525
if not BNHelpers._add_vmt_fields(bv, vmt, vmt_struct):
1626
return False
@@ -31,7 +41,7 @@ def create_vmt_struct(bv: BinaryView, vmt: DelphiVMT) -> bool:
3141
# Protected methods
3242

3343
@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:
3545
address_size = bv.address_size
3646
field_types = VMTFieldTypes(bv.arch)
3747
vmt_offsets = vmt.vmt_offsets
@@ -52,7 +62,7 @@ def _add_vmt_fields(bv: BinaryView, vmt: DelphiVMT, out_struct: types.Structure)
5262

5363

5464
@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:
5666
address_size = bv.address_size
5767

5868
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
105115
# Private methods
106116

107117
@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:
109119
vmt_offsets = vmt.vmt_offsets
110120

111121
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
124134
if class_name_len is None:
125135
return False
126136

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+
128143
class_name_struct.append(Type.int(1, False), 'length')
129144
class_name_struct.append(Type.array(Type.char(), class_name_len), 'value')
130145
struct_type = Type.structure_type(class_name_struct)

0 commit comments

Comments
 (0)