Skip to content

Commit

Permalink
dont assume added as function if no exception was thrown in decl case
Browse files Browse the repository at this point in the history
  • Loading branch information
2over12 committed Sep 22, 2022
1 parent 14807fa commit 55d47e9
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions python/anvill/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def add_symbol(self, ea: int, name: str):
self._symbols[ea].add(name)

def add_variable_declaration(self, ea: int, add_refs_as_defs=False) -> bool:
DEBUG(f"Adding variable decl at {ea:x}")
var: Optional[Variable] = self.get_variable(ea)
if var is not None and isinstance(var, Variable):
ea = var.address() # Argument `ea` might be inside the variable.
Expand Down Expand Up @@ -184,32 +185,39 @@ def set_control_flow_targets(
self._control_flow_targets[entry.source] = entry
return True

def try_add_function_definition(self, ea: int, add_refs_as_defs: bool) -> bool:
try:
return self.add_function_definition(ea, add_refs_as_defs)
except InvalidFunctionException:
return False

def try_add_function_declaration(self, ea: int, add_refs_as_defs: bool) -> bool:
try:
return self.add_function_declaration(ea, add_refs_as_defs)
except InvalidFunctionException:
return False

def try_add_referenced_entity(self, ea: int, add_refs_as_defs=False) -> bool:
DEBUG(f"Attempting to add ref entity: {ea:x} {add_refs_as_defs}")
DEBUG(f"Attempting to add ref entity: {ea:x} with refs as defs: {add_refs_as_defs}")
if add_refs_as_defs:
try:
DEBUG(f"Adding ref as function {ea:x}")
if self.add_function_definition(ea, add_refs_as_defs):
DEBUG(f"Added function {ea:x}")
return True
except InvalidFunctionException as e1:
pass
DEBUG(f"Adding ref as function {ea:x}")
if self.try_add_function_definition(ea, add_refs_as_defs):
DEBUG(f"Added function {ea:x}")
return True
try:
DEBUG(f"Adding ref as variable {ea:x}")
if self.add_variable_definition(ea, add_refs_as_defs):
DEBUG(f"Variable added {ea:x}")
return True
except InvalidVariableException as e2:
except InvalidVariableException:
pass
try:
self.add_function_declaration(ea, False)

if self.try_add_function_declaration(ea, False):
return True
except InvalidFunctionException as e1:
try:
self.add_variable_declaration(ea, False)
return True
except InvalidVariableException as e2:
return False
try:
return self.add_variable_declaration(ea, False)
except InvalidVariableException:
return False

@property
def memory(self) -> Memory:
Expand Down

0 comments on commit 55d47e9

Please sign in to comment.