Skip to content

Commit

Permalink
Fix a bug in None named binja vars (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
mahaloz authored Oct 14, 2024
1 parent 075fcb3 commit 060a20f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion libbs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "2.2.0"
__version__ = "2.2.1"


import logging
Expand Down
21 changes: 16 additions & 5 deletions libbs/decompilers/binja/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,13 @@ def _set_function_header(self, fheader: FunctionHeader, bn_func=None, **kwargs)

return updates

def _valid_var_for_bn_set(self, bs_var: StackVariable):
# a stopgap for issue reported in:
# https://github.com/binsync/libbs/issues/128
#
# the real fix is likely on the binja side.
return bs_var.offset is not None and bs_var.name is not None

# stack vars
def _set_stack_variable(self, svar: StackVariable, bn_func=None, **kwargs) -> bool:
updates = False
Expand All @@ -415,11 +422,15 @@ def _set_stack_variable(self, svar: StackVariable, bn_func=None, **kwargs) -> bo
if bs_svar_type is not None:
if self.art_lifter.lift_type(str(current_bn_vars[bn_offset].type)) != bs_svar_type:
current_bn_vars[bn_offset].type = bs_svar_type
try:
bn_func.create_user_stack_var(bn_offset, bs_svar_type, svar.name)
bn_func.create_auto_stack_var(bn_offset, bs_svar_type, svar.name)
except Exception as e:
l.warning(f"BinSync could not sync stack variable at offset {bn_offset}: {e}")

# this can cause a binja segfault, so we need to check if the var is valid before doing
# normal python try/except
if self._valid_var_for_bn_set(svar):
try:
bn_func.create_user_stack_var(bn_offset, bs_svar_type, svar.name)
bn_func.create_auto_stack_var(bn_offset, bs_svar_type, svar.name)
except Exception as e:
l.warning(f"BinSync could not sync stack variable at offset {bn_offset}: {e}")

updates |= True

Expand Down

0 comments on commit 060a20f

Please sign in to comment.