Skip to content

Commit

Permalink
added IDA & Ghidra scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
MJx0 committed Nov 10, 2023
1 parent 5c53c8f commit 9b37373
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 15 deletions.
15 changes: 0 additions & 15 deletions AndUE4Dumper/scripts/ida_funcs.py

This file was deleted.

31 changes: 31 additions & 0 deletions scripts/ghidra.py
Original file line number Diff line number Diff line change
@@ -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!')
31 changes: 31 additions & 0 deletions scripts/ida.py
Original file line number Diff line number Diff line change
@@ -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!')
31 changes: 31 additions & 0 deletions scripts/ida_py3.py
Original file line number Diff line number Diff line change
@@ -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!')

0 comments on commit 9b37373

Please sign in to comment.