Skip to content

Commit

Permalink
[Lifter] Represent BNinja void correctly (#415)
Browse files Browse the repository at this point in the history
* Create draft PR for #405

* Add: uchar8 for void

* Remove void* hack

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Spartak Ehrlich <neoquix@posteo.de>
Co-authored-by: Manuel Blatt <45859907+blattm@users.noreply.github.com>
  • Loading branch information
3 people authored Jun 24, 2024
1 parent 68d1d13 commit 2bd0591
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
3 changes: 3 additions & 0 deletions decompiler/backend/cexpressiongenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ def visit_constant_composition(self, expr: expressions.ConstantComposition):
case CustomType(text="wchar16") | CustomType(text="wchar32"):
val = "".join([x.value for x in expr.value])
return f'L"{val}"' if len(val) <= MAX_GLOBAL_INIT_LENGTH else f'L"{val[:MAX_GLOBAL_INIT_LENGTH]}..."'
case Integer(size=8, signed=False):
val = "".join([f"\\x{x.value:02X}" for x in expr.value][:MAX_GLOBAL_INIT_LENGTH])
return f'"{val}"' if len(val) <= MAX_GLOBAL_INIT_LENGTH else f'"{val[:MAX_GLOBAL_INIT_LENGTH]}..."'
case Integer(8):
val = "".join([x.value for x in expr.value][:MAX_GLOBAL_INIT_LENGTH])
return f'"{val}"' if len(val) <= MAX_GLOBAL_INIT_LENGTH else f'"{val[:MAX_GLOBAL_INIT_LENGTH]}..."'
Expand Down
2 changes: 1 addition & 1 deletion decompiler/backend/variabledeclarations.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def _generate_definitions(global_variables: set[GlobalVariable]) -> Iterator[str
match variable.type:
case ArrayType():
br, bl = "", ""
if not variable.type.type in [Integer.char(), CustomType.wchar16(), CustomType.wchar32()]:
if not variable.type.type in [Integer.char(), Integer.uint8_t(), CustomType.wchar16(), CustomType.wchar32()]:
br, bl = "{", "}"
yield f"{base}{variable.type.type} {variable.name}[{hex(variable.type.elements)}] = {br}{CExpressionGenerator().visit(variable.initial_value)}{bl};"
case _:
Expand Down
3 changes: 0 additions & 3 deletions decompiler/frontend/binaryninja/handlers/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ def lift_constant_pointer(self, pointer: mediumlevelil.MediumLevelILConstPtr, **
if isinstance(res, Constant): # BNinja Error case handling
return res

if isinstance(res.type, Pointer) and res.type.type == CustomType.void():
return res

if isinstance(pointer, mediumlevelil.MediumLevelILImport): # Temp fix for '&'
return res

Expand Down
4 changes: 3 additions & 1 deletion decompiler/frontend/binaryninja/handlers/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ def _get_unknown_value(self, variable: DataVariable):
type = PseudoArrayType(self._lifter.lift(data[1]), len(data[0]))
data = ConstantComposition([Constant(x, type.type) for x in data[0]], type)
else:
data, type = get_raw_bytes(variable.address, self._view), Pointer(CustomType.void(), self._view.address_size * BYTE_SIZE)
rbytes = get_raw_bytes(variable.address, self._view)
type = PseudoArrayType(Integer.uint8_t(), len(rbytes))
data = ConstantComposition([Constant(b, type.type) for b in rbytes], type)
return data, type

def _get_unknown_pointer_value(self, variable: DataVariable, callers: list[int] = None):
Expand Down

0 comments on commit 2bd0591

Please sign in to comment.