Skip to content

Commit

Permalink
Add Ghidra header
Browse files Browse the repository at this point in the history
  • Loading branch information
mahaloz committed Nov 3, 2023
1 parent 06f8605 commit ba93860
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions yodalib/decompilers/ghidra/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,47 +136,47 @@ def _functions(self) -> Dict[int, Function]:
}
return funcs


#
# TODO: REMOVE ME THIS IS THE BINSYNC CODE
# Filler/Setter API
#

def fill_function(self, func_addr, user=None, artifact=None, **kwargs):
decompilation = self._ghidra_decompile(self._get_nearest_function(func_addr))
changes = super().fill_function(
func_addr, user=user, artifact=artifact, decompilation=decompilation, **kwargs
)

return changes

@ghidra_transaction
def fill_function_header(self, func_addr, user=None, artifact=None, decompilation=None, **kwargs):
def _set_function_header(self, fheader: FunctionHeader, decompilation=None, **kwargs) -> bool:
changes = False
func_header: FunctionHeader = artifact
func_addr = fheader.addr
ghidra_func = decompilation.getFunction() if decompilation else self._get_nearest_function(func_addr)
src_type = self.ghidra.import_module_object("ghidra.program.model.symbol", "SourceType")

# func name
if func_header.name and func_header.name != ghidra_func.getName():
ghidra_func.setName(func_header.name, src_type.USER_DEFINED)
if fheader.name and fheader.name != ghidra_func.getName():
ghidra_func.setName(fheader.name, src_type.USER_DEFINED)
changes = True

# return type
if func_header.type and decompilation is not None:
parsed_type = self.typestr_to_gtype(func_header.type)
if fheader.type and decompilation is not None:
parsed_type = self.typestr_to_gtype(fheader.type)
if parsed_type is not None and \
parsed_type != str(decompilation.highFunction.getFunctionPrototype().getReturnType()):
ghidra_func.setReturnType(parsed_type, src_type.USER_DEFINED)
changes = True

# args
if func_header.args and decompilation is not None:
if fheader.args and decompilation is not None:
# TODO: do arg names and types
pass

return changes


#
# TODO: REMOVE ME THIS IS THE BINSYNC CODE
# Filler/Setter API
#

def fill_function(self, func_addr, user=None, artifact=None, **kwargs):
decompilation = self._ghidra_decompile(self._get_nearest_function(func_addr))
changes = super().fill_function(
func_addr, user=user, artifact=artifact, decompilation=decompilation, **kwargs
)

return changes

@ghidra_transaction
def fill_struct(self, struct_name, header=True, members=True, artifact=None, **kwargs):
struct: Struct = artifact;
Expand Down

0 comments on commit ba93860

Please sign in to comment.