Skip to content

Commit

Permalink
[[email protected]:141] TypeError: Type violation: 'unknown type' (#…
Browse files Browse the repository at this point in the history
…443)

* Create draft PR for #442

* Add: Ptr in section check

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Spartak Ehrlich <[email protected]>
Co-authored-by: Niklas Bergmann <[email protected]>
  • Loading branch information
3 people authored Nov 22, 2024
1 parent 54a3ed8 commit 8637644
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions decompiler/frontend/binaryninja/handlers/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ def _lift_pointer_type(
1. Function pointer: If Bninja already knows it's a function pointer.
2. Type pointer: As normal type pointer (there _should_ be a datavariable at the pointers dest.)
3. Void pointer: Try to extract a datavariable (recover type of void* directly), string (char*) or raw bytes (void*) at the given address
Caution: A pointer can point at a constant instead of a variable (e.g. stdout/stderr)
=> 2/3 catch this error with a value in section check
"""
match variable.type.target:
case FunctionType(): # BNinja knows it's a imported function pointer
Expand All @@ -241,19 +243,23 @@ def _lift_pointer_type(
)
case VoidType(): # BNinja knows it's a pointer pointing at something
# Extract the initial_value and type from the location where the pointer is pointing to
init_value, type = self._get_unknown_pointer_value(variable, callers)
init_value, vtype = self._get_unknown_pointer_value(variable, callers)
case _:
if callers:
callers.append(variable.address)
else:
callers = [variable.address]
init_value, type = (
self._lifter.lift(self._view.get_data_var_at(variable.value), view=self._view, callers=callers),
self._lifter.lift(variable.type),
)

vtype = self._lifter.lift(variable.type)
# BNinja error case: Pointer does not point at variable in view
if not addr_in_section(self._view, variable.value):
init_value = Constant(variable.value, vartype=Integer(self._view.address_size * BYTE_SIZE, False))
else:
self._lifter.lift(self._view.get_data_var_at(variable.value), view=self._view, callers=callers)

return self._build_global_variable(
name=self._lifter.lift(variable.symbol).name if variable.symbol else None,
type=type,
type=vtype,
addr=variable.address,
init_value=init_value,
ssa_label=parent.ssa_memory_version if parent else 0,
Expand Down

0 comments on commit 8637644

Please sign in to comment.