diff --git a/libbs/decompilers/ghidra/hooks.py b/libbs/decompilers/ghidra/hooks.py index 12b2a7ff..3f6668d9 100644 --- a/libbs/decompilers/ghidra/hooks.py +++ b/libbs/decompilers/ghidra/hooks.py @@ -54,7 +54,7 @@ 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) @@ -62,7 +62,7 @@ def domainObjectChanged(self, ev): 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: diff --git a/libbs/decompilers/ghidra/interface.py b/libbs/decompilers/ghidra/interface.py index c1ed1903..2d40efe7 100644 --- a/libbs/decompilers/ghidra/interface.py +++ b/libbs/decompilers/ghidra/interface.py @@ -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") @@ -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 @@ -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) diff --git a/tests/test_decompilers.py b/tests/test_decompilers.py index be182530..cc50d911 100644 --- a/tests/test_decompilers.py +++ b/tests/test_decompilers.py @@ -54,12 +54,12 @@ def test_ghidra(self): deci.functions[func_addr] = main assert deci.functions[func_addr].header.args == func_args - struct = deci.structs['/eh_frame_hdr'] + struct = deci.structs['eh_frame_hdr'] struct.name = "my_struct_name" struct.members[0].type = 'undefined' struct.members[1].type = 'undefined' - deci.structs['/eh_frame_hdr'] = struct - updated = deci.structs['/' + struct.name] + deci.structs['eh_frame_hdr'] = struct + updated = deci.structs[struct.name] assert updated.name == struct.name assert updated.members[0].type == 'undefined' assert updated.members[1].type == 'undefined' @@ -110,9 +110,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