From 4fdfcb6d5dcb467afea53d25e51770a2c5fbcad5 Mon Sep 17 00:00:00 2001 From: Zack Orndorff Date: Thu, 9 May 2019 15:38:42 -0400 Subject: [PATCH] Support multi-way And/Or conditions --- decompiler/decompiler/constraint_visitor.py | 40 ++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/decompiler/decompiler/constraint_visitor.py b/decompiler/decompiler/constraint_visitor.py index 77e539b..2c85271 100644 --- a/decompiler/decompiler/constraint_visitor.py +++ b/decompiler/decompiler/constraint_visitor.py @@ -27,7 +27,45 @@ def visit(self, expression): return value def visit_BoolRef(self, expr): - if expr.num_args() == 2: + if expr.num_args() > 2 and expr.decl().name() in ('and', 'or'): + # Not sure if we need to do DeMorgan's or something here, so bail out + if self._in_not: + raise NotImplementedError() + operation = f"{expr.decl()!s}" + visited = [self.visit(expr.arg(i)) for i in range(expr.num_args())] + + tokens = [] + tokens.append( + InstructionTextToken( + InstructionTextTokenType.TextToken, + "(" + ) + ) + for idx, item in enumerate(visited): + if idx != 0: + tokens.append(InstructionTextToken( + InstructionTextTokenType.TextToken, + f" {operation} " + )) + tokens.append(InstructionTextToken( + InstructionTextTokenType.TextToken, + "(" + )) + tokens.extend(item) + tokens.append(InstructionTextToken( + InstructionTextTokenType.TextToken, + ")" + )) + tokens.append( + InstructionTextToken( + InstructionTextTokenType.TextToken, + ")" + ) + ) + + return tokens + + elif expr.num_args() == 2: if self._in_not: operation = negations.get(f"{expr.decl()!s}") if operation is None: