Skip to content

Commit

Permalink
Rework how structs are keyed
Browse files Browse the repository at this point in the history
  • Loading branch information
Flipout50 committed Apr 4, 2024
1 parent 12bdb53 commit a09c1f3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions libbs/decompilers/ghidra/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ def domainObjectChanged(self, ev):
pass
elif changeType in typeEvents:
try:
struct = self._interface.structs['/'+newValue.name]
struct = self._interface.structs[newValue.name]
# TODO: access old name indicate deletion
#self._interface.struct_changed(Struct(None, None, None), deleted=True)
self._interface.struct_changed(struct)
except KeyError:
pass

try:
enum = self._interface.enums['/'+newValue.name]
enum = self._interface.enums[newValue.name]
#self._interface.enum_changed(Enum(None, None), deleted=True)
self._interface.enum_changed(enum)
except KeyError:
Expand Down
6 changes: 3 additions & 3 deletions libbs/decompilers/ghidra/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def _set_function_header(self, fheader: FunctionHeader, decompilation=None, **kw
@ghidra_transaction
def _set_struct(self, struct: Struct, header=True, members=True, **kwargs) -> bool:
struct: Struct = struct
old_ghidra_struct = self._get_struct_by_name('/' + struct.name)
old_ghidra_struct = self._get_struct_by_name(struct.name)
data_manager = self.ghidra.currentProgram.getDataTypeManager()
handler = self.ghidra.import_module_object("ghidra.program.model.data", "DataTypeConflictHandler")
structType = self.ghidra.import_module_object("ghidra.program.model.data", "StructureDataType")
Expand Down Expand Up @@ -428,7 +428,7 @@ def _structs(self) -> Dict[str, Struct]:
"for s in currentProgram.getDataTypeManager().getAllStructures()]"
)
return {
name: Struct(name, size, members=self._struct_members_from_gstruct(name)) for name, size in name_sizes
name[1:]: Struct(name[1:], size, members=self._struct_members_from_gstruct(name[1:])) for name, size in name_sizes
} if name_sizes else {}

@ghidra_transaction
Expand Down Expand Up @@ -637,7 +637,7 @@ def _get_local_variable_symbols(self, func: Function) -> Dict[str, "HighSymbol"]
)

def _get_struct_by_name(self, name: str) -> "GhidraStructure":
return self.ghidra.currentProgram.getDataTypeManager().getDataType(name)
return self.ghidra.currentProgram.getDataTypeManager().getDataType('/' + name)

def _struct_members_from_gstruct(self, name: str) -> Dict[int, StructMember]:
ghidra_struct = self._get_struct_by_name(name)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_decompilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ def func_hit(*args, **kwargs): hits[args[0].__class__].append(args[0])
# main.stack_vars[-12].name = "named_int"
# deci.functions[func_addr] = main

# struct = deci.structs['/eh_frame_hdr']
# struct = deci.structs['eh_frame_hdr']
# struct.name = "my_struct_name"
# deci.structs['/eh_frame_hdr'] = struct
# deci.structs['eh_frame_hdr'] = struct

# TODO: add argument naming
# func_args = main.header.args
Expand Down

0 comments on commit a09c1f3

Please sign in to comment.