Skip to content

Commit

Permalink
fix: Check for existence of RustStringSlice type before creating it
Browse files Browse the repository at this point in the history
  • Loading branch information
cxiao committed Dec 25, 2023
1 parent 85cc89b commit 4813149
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions binja_plugin/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ def __repr__(self):
return f"StringSlice(address={self.address:#x}, length={self.length:#x}, data={self.data!r})"

@classmethod
def create_binary_ninja_type(
cls, bv: BinaryView
): # TODO: check for existence of type
def check_binary_ninja_type_exists(cls, bv: BinaryView) -> bool:
return bv.get_type_by_name("RustStringSlice") is not None

@classmethod
def create_binary_ninja_type(cls, bv: BinaryView):
if bv.arch is not None:
rust_string_slice_bn_type_obj = StructureBuilder.create(packed=True)
rust_string_slice_bn_type_obj.append(
Expand Down Expand Up @@ -337,10 +339,12 @@ def run(self):


def action_recover_string_slices_from_code(bv: BinaryView):
RustStringSlice.create_binary_ninja_type(bv)
if not RustStringSlice.check_binary_ninja_type_exists(bv):
RustStringSlice.create_binary_ninja_type(bv)
RecoverStringFromCodeTask(bv=bv).start()


def action_recover_string_slices_from_readonly_data(bv: BinaryView):
RustStringSlice.create_binary_ninja_type(bv)
if not RustStringSlice.check_binary_ninja_type_exists(bv):
RustStringSlice.create_binary_ninja_type(bv)
RecoverStringFromReadOnlyDataTask(bv=bv).start()

0 comments on commit 4813149

Please sign in to comment.