Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing definitions with global variables #402

Merged
merged 2 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions decompiler/pipeline/preprocessing/missing_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ def _memory_instruction_changes_variable(self, memory_instruction: Instruction,
return False
if self._is_assignment_of_variable_address(memory_instruction):
return False
if isinstance(variable, GlobalVariable): # Global variables could always change in memory instructions
return True
return self._uses_variable_related_to_aliased_variable(memory_instruction, variable)

def _uses_variable_related_to_aliased_variable(self, memory_instruction: Instruction, variable: Variable) -> bool:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ def test_missing_definitions_for_global_variables_are_correct():
+--------------------+ +--------------------+
| 0. | | 0. |
| rand() | | rand() |
| var#0 = g#1 | | g#1 = g#0 |
| var#0 = g#1 | | g#1 -> g#0 |
| if(var#0 < 0xa) | -+ | var#0 = g#1 |
+--------------------+ | | if(var#0 < 0xa) | -+
| | +--------------------+ |
Expand Down Expand Up @@ -1055,7 +1055,7 @@ def test_missing_definitions_for_global_variables_are_correct():
cfg.add_edges_from([UnconditionalEdge(n0, n1), UnconditionalEdge(n0, n2), UnconditionalEdge(n1, n2)])
task = DecompilerTask("test", cfg)
InsertMissingDefinitions().run(task)
expected_inserted_definition = Assignment(globals[1], globals[0])
expected_inserted_definition = Relation(globals[1], globals[0])
inserted_definition: Assignment = n0.instructions[1]
assert inserted_definition == expected_inserted_definition
assert inserted_definition.writes_memory == 1
Expand Down
Loading