Skip to content

Commit

Permalink
False control structure for structs (#342)
Browse files Browse the repository at this point in the history
Co-authored-by: rihi <[email protected]>
Co-authored-by: rihi <[email protected]>
Co-authored-by: Steffen Enders <[email protected]>
  • Loading branch information
4 people authored Oct 9, 2023
1 parent 83b07e6 commit 9663023
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions decompiler/frontend/binaryninja/handlers/assignments.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,21 @@ def lift_get_field(self, instruction: mediumlevelil.MediumLevelILVarField, is_al
case 1: struct member read access e.g. (x = )book.title
lift as (x = ) struct_member(book, title)
case 2: accessing register portion e.g. (x = )eax.ah
lift as (x = ) eax & 0x0000ff00
lift as (x = ) (uint8_t)(eax >> 8)
(x = ) <- for the sake of example, only rhs expression is lifted here.
"""
source = self._lifter.lift(instruction.src, is_aliased=is_aliased, parent=instruction)
if isinstance(source.type, Struct) or isinstance(source.type, Union):
return self._get_field_as_member_access(instruction, source, **kwargs)
cast_type = source.type.resize(instruction.size * self.BYTE_SIZE)
if instruction.offset:
return BinaryOperation(
OperationType.bitwise_and,
[source, Constant(self._get_all_ones_mask_for_type(instruction.size) << instruction.offset)],
vartype=cast_type,
return UnaryOperation(
OperationType.cast,
[BinaryOperation(
OperationType.right_shift_us,
[source, Constant(instruction.offset, Integer.int32_t())]
)],
cast_type
)
return UnaryOperation(OperationType.cast, [source], vartype=cast_type, contraction=True)

Expand Down

0 comments on commit 9663023

Please sign in to comment.