Created
September 10, 2019 16:23
-
-
Save sei0o/d495bd1941e9fec88cc79699cf55b07e to your computer and use it in GitHub Desktop.
Ghidra scripts to load script.py which IL2CppDumper exported (forked from @worawit's one)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#TODO write a description for this script | |
#@author | |
#@category _NEW_ | |
#@keybinding | |
#@menupath | |
#@url | |
#@toolbar | |
# forked from: https://gist.github.com/worawit/c8788723a667f990ba9aebe9d69f2fc4 | |
# see also: https://github.com/ghidraninja/ghidra_scripts/blob/371da70c6589d6c8a689224bf8069a957e4daf8c/golang_renamer.py | |
# -*- coding: utf-8 -*- | |
import ghidra.program.model.symbol.SourceType | |
import re | |
addressFactory = currentProgram.getAddressFactory() | |
functionManager = currentProgram.getFunctionManager() | |
minAddress = currentProgram.getMinAddress() | |
baseAddress = currentProgram.getImageBase() | |
USER_DEFINED = ghidra.program.model.symbol.SourceType.USER_DEFINED | |
index = 1 | |
def addrToInt(addr): | |
return int(addr.toString(), 16) | |
def hexToAddr(hexaddr): | |
return addressFactory.getAddress(hexaddr) | |
def _convert_arg_string(arg): | |
if arg.startswith('r'): | |
return arg[2:-1] # remove prefix 'r' and quote | |
return arg[1:-1] # remove quote | |
def do_SetName(hexaddr, name): | |
print("from %s to %s" % (hexaddr, name)) | |
addr = hexToAddr(hexaddr) | |
name = _convert_arg_string(name) | |
func = functionManager.getFunctionAt(addr) | |
if func != None: | |
func.setName(name, USER_DEFINED) | |
else: | |
createFunction(addr, name) | |
def do_idc_MakeComm(arg1, arg2): | |
addr = hexToAddr(arg1) | |
text = _convert_arg_string(arg2) | |
setEOLComment(addr, text) | |
def do_SetString(arg1, arg2): | |
addr = hexToAddr(arg1) | |
text = _convert_arg_string(arg2) | |
global index | |
name = "StringLiteral_" + str(index); | |
createLabel(addr, name, True, USER_DEFINED) | |
setEOLComment(addr, text) | |
index += 1 | |
def do_MakeFunction(start, end): | |
start_addr = hexToAddr(start) | |
end_addr = hexToAddr(end) | |
func = functionManager.getFunctionAt(start_addr) | |
if func is None: | |
try: | |
func = createFunction(start_addr, None) | |
except: | |
pass | |
f = askFile("script.py from Il2cppdumper", "Open") | |
for line in file(f.absolutePath): | |
match = re.search(r"^([\w+\.]+)\((\w+),\s*(.*)\)$", line) | |
if match: | |
name, arg1, arg2 = match.groups() | |
res = globals()['do_'+name.replace('.', '_')](arg1, arg2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment