Skip to content

Commit

Permalink
[Parser] Lift undetermined jumps as comment (#336)
Browse files Browse the repository at this point in the history
* Create draft PR for #335

* If we encounter a basic-block ending in a jump instruction and having no
outgoing edges, insert a comment.

Note: We do not resolve jump variable

---------

Co-authored-by: mm4rks <[email protected]>
Co-authored-by: Marvin Marks <[email protected]>
Co-authored-by: Niklas Bergmann <[email protected]>
  • Loading branch information
4 people authored Sep 28, 2023
1 parent f673c3e commit 1e818ad
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions decompiler/frontend/binaryninja/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
MediumLevelILBasicBlock,
MediumLevelILConstPtr,
MediumLevelILInstruction,
MediumLevelILJump,
MediumLevelILJumpTo,
MediumLevelILTailcallSsa,
RegisterValueType,
Expand All @@ -18,6 +19,7 @@
from decompiler.structures.graphs.cfg import BasicBlock, ControlFlowGraph, FalseCase, IndirectEdge, SwitchCase, TrueCase, UnconditionalEdge
from decompiler.structures.pseudo import Constant, Instruction
from decompiler.structures.pseudo.complextypes import ComplexTypeMap
from decompiler.structures.pseudo.instructions import Comment


class BinaryninjaParser(Parser):
Expand Down Expand Up @@ -135,6 +137,10 @@ def _get_lookup_table(self, block: MediumLevelILBasicBlock) -> Dict[int, List[Co
lookup[target] += [Constant(value)]
return lookup

def _has_undetermined_jump(self, basic_block: MediumLevelILBasicBlock) -> bool:
"""Return True if basic-block is ending in a jump and has no outgoing edges"""
return bool(len(basic_block) and isinstance(basic_block[-1], MediumLevelILJump) and not basic_block.outgoing_edges)

def _lift_instructions(self, basic_block: MediumLevelILBasicBlock) -> Iterator[Instruction]:
"""Yield the lifted versions of all instructions in the given basic block."""
for instruction in basic_block:
Expand All @@ -144,6 +150,8 @@ def _lift_instructions(self, basic_block: MediumLevelILBasicBlock) -> Iterator[I
self._unlifted_instructions.append(instruction)
continue
yield lifted_instruction
if self._has_undetermined_jump(basic_block):
yield Comment("jump -> undetermined")

def _report_lifter_errors(self):
"""Report instructions which could not be lifted and reset their counter."""
Expand Down

0 comments on commit 1e818ad

Please sign in to comment.