Skip to content

Commit

Permalink
Fix access to private property of task object
Browse files Browse the repository at this point in the history
  • Loading branch information
rihi committed Feb 28, 2024
1 parent ace3ab5 commit da6510c
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def run(self, task: DecompilerTask):
for_loop_names: List[str] = task.options.getlist("loop-name-generator.for_loop_variable_names", fallback=[])

if rename_while_loops:
WhileLoopVariableRenamer(task._ast).rename()
WhileLoopVariableRenamer(task.ast).rename()

if for_loop_names:
ForLoopVariableRenamer(task._ast, for_loop_names).rename()
ForLoopVariableRenamer(task.ast, for_loop_names).rename()
4 changes: 2 additions & 2 deletions decompiler/pipeline/controlflowanalysis/restructuring.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def run(self, task: DecompilerTask):
assert len(self.t_cfg) == 1, f"The Transition Graph can only have one node after the restructuring."
self.asforest.set_current_root(self.t_cfg.root.ast)
assert (roots := len(self.asforest.get_roots)) == 1, f"After the restructuring the forest should have one root, but it has {roots}!"
task._ast = AbstractSyntaxTree.from_asforest(self.asforest, self.asforest.current_root)
task._cfg = None
task.ast = AbstractSyntaxTree.from_asforest(self.asforest, self.asforest.current_root)
task.cfg = None

def restructure_cfg(self) -> None:
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
from abc import ABC, abstractmethod
from enum import Enum
from typing import Dict, List, Optional, Set
from typing import Dict, List, Optional

from decompiler.pipeline.stage import PipelineStage
from decompiler.structures.ast.ast_nodes import ConditionNode, LoopNode
Expand Down Expand Up @@ -75,9 +75,9 @@ class RenamingScheme(ABC):

def __init__(self, task: DecompilerTask) -> None:
"""Collets all needed variables for renaming + filters already renamed + function arguments out"""
collector = VariableCollector(task._ast.condition_map)
collector.visit_ast(task._ast)
self._params: List[Variable] = task._function_parameters
collector = VariableCollector(task.ast.condition_map)
collector.visit_ast(task.ast)
self._params: List[Variable] = task.function_parameters
self._loop_vars: List[Variable] = collector.get_loop_variables()
self._variables: List[Variable] = list(filter(self._filter_variables, collector.get_variables()))

Expand Down
5 changes: 0 additions & 5 deletions decompiler/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ class DecompilerTask:
graph = property(lambda self: self.cfg, lambda self, v: setattr(self, "cfg", v))
syntax_tree = property(lambda self: self.ast, lambda self, v: setattr(self, "ast", v))

# Properties for backwards compatibility. For some reason some code directly accessed these private fields.
_cfg = property(lambda self: self.cfg, lambda self, v: setattr(self, "cfg", v))
_ast = property(lambda self: self.ast, lambda self, v: setattr(self, "ast", v))
_function_parameters = property(lambda self: self.function_parameters, lambda self, v: setattr(self, "function_parameters", v))

def fail(self, origin: str = ""):
"""Sets the task to be failed by setting the failure origin."""
if self.failure_origin is not None:
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@
from decompiler.structures.ast.ast_nodes import ConditionNode, SeqNode, SwitchNode
from decompiler.structures.ast.condition_symbol import ConditionHandler
from decompiler.structures.ast.reachability_graph import SiblingReachabilityGraph
from decompiler.structures.ast.switch_node_handler import ExpressionUsages
from decompiler.structures.ast.syntaxforest import AbstractSyntaxForest
from decompiler.structures.graphs.cfg import BasicBlock, ControlFlowGraph, FalseCase, TrueCase, UnconditionalEdge
from decompiler.structures.pseudo.expressions import Constant, ImportedFunctionSymbol, Variable
from decompiler.structures.pseudo.expressions import Constant, Variable
from decompiler.structures.pseudo.instructions import Assignment, Branch, Return
from decompiler.structures.pseudo.operations import BinaryOperation, Condition, OperationType
from decompiler.structures.pseudo.typing import CustomType, Integer
from decompiler.task import DecompilerTask
from decompiler.util.decoration import DecoratedCFG

var_b = Variable("b", Integer.int32_t())
var_c = Variable("c", Integer.int32_t())
Expand All @@ -46,7 +44,7 @@ def test_no_crash_missing_case_finder(task):
var_4 = Variable("var_4", Integer(32, False), ssa_name=Variable("rbx_2", Integer(32, False), 2))
var_5 = Variable("var_5", Integer(32, False), ssa_name=Variable("rax_1", Integer(32, False), 2))
var_6 = Variable("var_6", Integer(32, False), ssa_name=Variable("rax_2", Integer(32, False), 2))
task._cfg.add_nodes_from(
task.cfg.add_nodes_from(
[
b0 := BasicBlock(
0,
Expand Down Expand Up @@ -77,7 +75,7 @@ def test_no_crash_missing_case_finder(task):
),
]
)
task._cfg.add_edges_from(
task.cfg.add_edges_from(
[
TrueCase(b0, b1),
FalseCase(b0, b3),
Expand Down

0 comments on commit da6510c

Please sign in to comment.