From 9b3737338dbdc416a1b2416e141224d1c313f407 Mon Sep 17 00:00:00 2001 From: MJ <32413318+MJx0@users.noreply.github.com> Date: Fri, 10 Nov 2023 06:47:59 -0800 Subject: [PATCH] added IDA & Ghidra scripts --- AndUE4Dumper/scripts/ida_funcs.py | 15 --------------- scripts/ghidra.py | 31 +++++++++++++++++++++++++++++++ scripts/ida.py | 31 +++++++++++++++++++++++++++++++ scripts/ida_py3.py | 31 +++++++++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 15 deletions(-) delete mode 100644 AndUE4Dumper/scripts/ida_funcs.py create mode 100644 scripts/ghidra.py create mode 100644 scripts/ida.py create mode 100644 scripts/ida_py3.py diff --git a/AndUE4Dumper/scripts/ida_funcs.py b/AndUE4Dumper/scripts/ida_funcs.py deleted file mode 100644 index 4e962e9..0000000 --- a/AndUE4Dumper/scripts/ida_funcs.py +++ /dev/null @@ -1,15 +0,0 @@ -# -*- coding: utf-8 -*- -import json - -path = idaapi.ask_file(False, '*.json', 'script.json') -json_data = json.loads(open(path, 'rb').read().decode('utf-8')) - -imageBase = idaapi.get_imagebase() - -for func_entry in json_data['Functions']: - name = func_entry['Name'] - addr = imageBase+func_entry['Address'] - ret = idc.set_name(addr, name, SN_NOWARN | SN_NOCHECK) - if ret == 0: - new_name = name+'_'+str(addr) - ret = idc.set_name(addr, new_name, SN_NOWARN | SN_NOCHECK) \ No newline at end of file diff --git a/scripts/ghidra.py b/scripts/ghidra.py new file mode 100644 index 0000000..08dbce1 --- /dev/null +++ b/scripts/ghidra.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +import json + +functionManager = currentProgram.getFunctionManager() +baseAddress = currentProgram.getImageBase() +USER_DEFINED = ghidra.program.model.symbol.SourceType.USER_DEFINED + +def get_addr(addr): + return baseAddress.add(addr) + +def set_name(addr, name): + name = name.replace(' ', '-') + createLabel(addr, name, True, USER_DEFINED) + +def make_function(start): + func = getFunctionAt(start) + if func is None: + createFunction(start, None) + +f = askFile("script.json from UE4Dumper", "Open") +json_data = json.loads(open(f.absolutePath, 'rb').read().decode('utf-8')) + +monitor.initialize(len(json_data['Functions'])) +monitor.setMessage("Methods") +for func_entry in json_data['Functions']: + addr = get_addr(func_entry["Address"]) + name = func_entry["Name"].encode("utf-8") + set_name(addr, name) + monitor.incrementProgress(1) + +print('Script finished!') diff --git a/scripts/ida.py b/scripts/ida.py new file mode 100644 index 0000000..40cf251 --- /dev/null +++ b/scripts/ida.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +import json + +imageBase = idaapi.get_imagebase() + +def get_addr(addr): + return imageBase + addr + +def set_name(addr, name): + ret = idc.set_name(addr, name, SN_NOWARN | SN_NOCHECK) + if ret == 0: + new_name = name + '_' + str(addr) + ret = idc.set_name(addr, new_name, SN_NOWARN | SN_NOCHECK) + +def make_function(start, end): + next_func = idc.get_next_func(start) + if next_func < end: + end = next_func + if idc.get_func_attr(start, FUNCATTR_START) == start: + ida_funcs.del_func(start) + ida_funcs.add_func(start, end) + +path = idaapi.ask_file(False, '*.json', 'script.json') +json_data = json.loads(open(path, 'rb').read().decode('utf-8')) + +for func_entry in json_data['Functions']: + addr = get_addr(func_entry["Address"]) + name = func_entry["Name"].encode("utf-8") + set_name(addr, name) + +print('Script finished!') \ No newline at end of file diff --git a/scripts/ida_py3.py b/scripts/ida_py3.py new file mode 100644 index 0000000..98a2121 --- /dev/null +++ b/scripts/ida_py3.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +import json + +imageBase = idaapi.get_imagebase() + +def get_addr(addr): + return imageBase + addr + +def set_name(addr, name): + ret = idc.set_name(addr, name, SN_NOWARN | SN_NOCHECK) + if ret == 0: + new_name = name + '_' + str(addr) + ret = idc.set_name(addr, new_name, SN_NOWARN | SN_NOCHECK) + +def make_function(start, end): + next_func = idc.get_next_func(start) + if next_func < end: + end = next_func + if idc.get_func_attr(start, FUNCATTR_START) == start: + ida_funcs.del_func(start) + ida_funcs.add_func(start, end) + +path = idaapi.ask_file(False, '*.json', 'script.json') +json_data = json.loads(open(path, 'rb').read().decode('utf-8')) + +for func_entry in json_data['Functions']: + addr = get_addr(func_entry["Address"]) + name = func_entry["Name"] + set_name(addr, name) + +print('Script finished!') \ No newline at end of file