Skip to content

Commit 4813149

Browse files
committed
fix: Check for existence of RustStringSlice type before creating it
1 parent 85cc89b commit 4813149

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

binja_plugin/actions.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ def __repr__(self):
2727
return f"StringSlice(address={self.address:#x}, length={self.length:#x}, data={self.data!r})"
2828

2929
@classmethod
30-
def create_binary_ninja_type(
31-
cls, bv: BinaryView
32-
): # TODO: check for existence of type
30+
def check_binary_ninja_type_exists(cls, bv: BinaryView) -> bool:
31+
return bv.get_type_by_name("RustStringSlice") is not None
32+
33+
@classmethod
34+
def create_binary_ninja_type(cls, bv: BinaryView):
3335
if bv.arch is not None:
3436
rust_string_slice_bn_type_obj = StructureBuilder.create(packed=True)
3537
rust_string_slice_bn_type_obj.append(
@@ -337,10 +339,12 @@ def run(self):
337339

338340

339341
def action_recover_string_slices_from_code(bv: BinaryView):
340-
RustStringSlice.create_binary_ninja_type(bv)
342+
if not RustStringSlice.check_binary_ninja_type_exists(bv):
343+
RustStringSlice.create_binary_ninja_type(bv)
341344
RecoverStringFromCodeTask(bv=bv).start()
342345

343346

344347
def action_recover_string_slices_from_readonly_data(bv: BinaryView):
345-
RustStringSlice.create_binary_ninja_type(bv)
348+
if not RustStringSlice.check_binary_ninja_type_exists(bv):
349+
RustStringSlice.create_binary_ninja_type(bv)
346350
RecoverStringFromReadOnlyDataTask(bv=bv).start()

0 commit comments

Comments
 (0)