From f26d2c317e28164a1726e64450d294c0beeaea44 Mon Sep 17 00:00:00 2001 From: NeoQuix Date: Wed, 23 Aug 2023 09:19:18 +0000 Subject: [PATCH 1/3] Create draft PR for #308 From b40e57fcab00b318ae9c770498c59e3cc7062cee Mon Sep 17 00:00:00 2001 From: Spartak Ehrlich Date: Wed, 23 Aug 2023 11:33:16 +0200 Subject: [PATCH 2/3] ignore branch --- .../preprocessing/compiler_idiom_handling.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/decompiler/pipeline/preprocessing/compiler_idiom_handling.py b/decompiler/pipeline/preprocessing/compiler_idiom_handling.py index 640e91d69..b393a8f36 100644 --- a/decompiler/pipeline/preprocessing/compiler_idiom_handling.py +++ b/decompiler/pipeline/preprocessing/compiler_idiom_handling.py @@ -1,11 +1,11 @@ """Module for handling compiler idioms that have already been marked in BinaryNinja""" import logging from dataclasses import dataclass -from typing import Iterable, List, Optional +from typing import List, Optional from decompiler.pipeline.stage import PipelineStage from decompiler.structures.pseudo.expressions import Constant, Tag, Variable -from decompiler.structures.pseudo.instructions import Assignment, Instruction +from decompiler.structures.pseudo.instructions import Assignment, Instruction, Branch from decompiler.structures.pseudo.operations import BinaryOperation, OperationType from decompiler.structures.pseudo.typing import Integer from decompiler.task import DecompilerTask @@ -23,10 +23,10 @@ class TaggedIdiom: class CompilerIdiomHandling(PipelineStage): """ The CompilerIdiomHandling replaces instructions that have been marked as compiler idioms in BinaryNinja by the respective high level instruction. - Basically, for a consecutive sequence of instructions with the identical tag (starting with "compiler_idiom: "), the last intruction will be replaced. + Basically, for a consecutive sequence of instructions with the identical tag (starting with "compiler_idiom: "), the last instruction will be replaced. This stage itself does not recognize nor tag instructions as compiler idiom. - See https://gitlab.fkie.fraunhofer.de/mariia.rybalka/compiler-idioms-paper for more details. + See https://github.com/fkie-cad/dewolf-idioms for more details. """ name = "compiler-idiom-handling" @@ -82,11 +82,11 @@ def _get_replacement_instruction( ) -> Optional[Assignment]: """ Create the assignment instruction to replace the compiler idiom with. - Return None if no constant could be extracted from tag or unable to find dividend variable + Return None if no constant could be extracted from tag or unable to find dividend variable or last instruction is branch """ var = self._get_variable_from_first_instruction(instructions[first_index], tag) const = self._get_constant_from_tag(tag) - if not var or not const: + if not var or not const or isinstance(instructions[last_index], Branch): return None operation_type = self._get_operation_type_from_tag(tag) return Assignment(instructions[last_index].destination, BinaryOperation(operation_type, [var, const])) From dc5878f04ad7590cc935b71a43d6e6f1f0434f1c Mon Sep 17 00:00:00 2001 From: Spartak Ehrlich Date: Wed, 23 Aug 2023 11:38:39 +0200 Subject: [PATCH 3/3] isort --- decompiler/pipeline/preprocessing/compiler_idiom_handling.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/decompiler/pipeline/preprocessing/compiler_idiom_handling.py b/decompiler/pipeline/preprocessing/compiler_idiom_handling.py index b393a8f36..1cf599a8f 100644 --- a/decompiler/pipeline/preprocessing/compiler_idiom_handling.py +++ b/decompiler/pipeline/preprocessing/compiler_idiom_handling.py @@ -5,7 +5,7 @@ from decompiler.pipeline.stage import PipelineStage from decompiler.structures.pseudo.expressions import Constant, Tag, Variable -from decompiler.structures.pseudo.instructions import Assignment, Instruction, Branch +from decompiler.structures.pseudo.instructions import Assignment, Branch, Instruction from decompiler.structures.pseudo.operations import BinaryOperation, OperationType from decompiler.structures.pseudo.typing import Integer from decompiler.task import DecompilerTask