diff options
| -rw-r--r-- | miasm2/core/sembuilder.py | 10 | ||||
| -rw-r--r-- | test/core/sembuilder.py | 3 |
2 files changed, 13 insertions, 0 deletions
diff --git a/miasm2/core/sembuilder.py b/miasm2/core/sembuilder.py index 65e951bd..34271960 100644 --- a/miasm2/core/sembuilder.py +++ b/miasm2/core/sembuilder.py @@ -90,6 +90,7 @@ class SemBuilder(object): # Get the function AST parsed = ast.parse(inspect.getsource(func)) fc_ast = parsed.body[0] + argument_names = [name.id for name in fc_ast.args.args] body = [] # AffBlock of the current instruction @@ -99,6 +100,15 @@ class SemBuilder(object): if isinstance(statement, ast.Assign): src = self.transformer.visit(statement.value) dst = self.transformer.visit(statement.targets[0]) + + if (isinstance(dst, ast.Name) and + dst.id not in argument_names and + dst.id not in self.ctx): + # Real variable declaration + statement.value = src + body.append(statement) + continue + dst.ctx = ast.Load() res = ast.Call(func=ast.Name(id='ExprAff', diff --git a/test/core/sembuilder.py b/test/core/sembuilder.py index 1854fc58..3c1b7d3f 100644 --- a/test/core/sembuilder.py +++ b/test/core/sembuilder.py @@ -1,4 +1,5 @@ import inspect +from pdb import pm from miasm2.core.sembuilder import SemBuilder import miasm2.expression.expression as m2_expr @@ -12,6 +13,8 @@ def test(Arg1, Arg2, Arg3): mem32[Arg1] = Arg2 mem32[Arg2] = Arg3 + i32(4) - mem32[Arg1] Arg3 = Arg3 if Arg2 else i32(0) + tmpvar = i32(2) + Arg2 = tmpvar a = m2_expr.ExprId('A') b = m2_expr.ExprId('B') |