From 65060ed05d633044fcd53c92bd53723242a18ddb Mon Sep 17 00:00:00 2001 From: Zack Orndorff Date: Thu, 9 May 2019 00:21:20 -0400 Subject: [PATCH 1/2] Add more ConditionVisitor visit methods Added are MLIL_CMP_SLT, MLIL_CMP_UGE, MLIL_CMP_ULT --- decompiler/decompiler/condition_visitor.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/decompiler/decompiler/condition_visitor.py b/decompiler/decompiler/condition_visitor.py index 4b2b9df..6c02c5d 100644 --- a/decompiler/decompiler/condition_visitor.py +++ b/decompiler/decompiler/condition_visitor.py @@ -2,7 +2,7 @@ from binaryninja import (Variable, VariableSourceType) -from z3 import (BitVec, And, Or, Not, Solver, simplify, Extract, UGT, ULE, Array, BitVecSort, Concat, Bool) +from z3 import (BitVec, And, Or, Not, Solver, simplify, Extract, UGT, ULE, UGE, ULT, Array, BitVecSort, Concat, Bool) def make_variable(var: Variable): if var.name == '': @@ -45,6 +45,11 @@ def visit_MLIL_CMP_SGT(self, expr): return left > right + def visit_MLIL_CMP_SLT(self, expr): + left, right = self.visit_both_sides(expr) + + return left < right + def visit_MLIL_CMP_SGE(self, expr): left, right = self.visit_both_sides(expr) @@ -60,6 +65,16 @@ def visit_MLIL_CMP_ULE(self, expr): return ULE(left, right) + def visit_MLIL_CMP_UGE(self, expr): + left, right = self.visit_both_sides(expr) + + return UGE(left, right) + + def visit_MLIL_CMP_ULT(self, expr): + left, right = self.visit_both_sides(expr) + + return ULT(left, right) + def visit_MLIL_LOAD(self, expr): src = self.visit(expr.src) return make_load(src, expr.size) @@ -102,4 +117,4 @@ def visit_MLIL_LSL(self, expr): def visit_both_sides(self, expr): return self.visit(expr.left), self.visit(expr.right) - visit_MLIL_CONST_PTR = visit_MLIL_CONST \ No newline at end of file + visit_MLIL_CONST_PTR = visit_MLIL_CONST From 0e6f4b08ce5645cc05e5b9b0cbf783e011ce7417 Mon Sep 17 00:00:00 2001 From: Zack Orndorff Date: Thu, 9 May 2019 01:04:25 -0400 Subject: [PATCH 2/2] Fix typing error in calculation of to_visit Tuple was being used as basic block, led to no .start attribute error. Fixed by looking at index 0 instead, which seems to be the index that holds the bb. --- decompiler/decompiler/linear_mlil.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/decompiler/decompiler/linear_mlil.py b/decompiler/decompiler/linear_mlil.py index 3349d46..f5dc245 100644 --- a/decompiler/decompiler/linear_mlil.py +++ b/decompiler/decompiler/linear_mlil.py @@ -128,7 +128,7 @@ def generateLines(self): to_visit = [ (n, 0) for header, n in sorted( - ast._regions.items(), key=cmp_to_key(lambda i, j: 1 if ast.reaching_conditions.get((i[0], j[0])) is None else 1 if i.start > j.start else -1), reverse=True + ast._regions.items(), key=cmp_to_key(lambda i, j: 1 if ast.reaching_conditions.get((i[0], j[0])) is None else 1 if i[0].start > j[0].start else -1), reverse=True ) ]