Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup ghidra_with_struct.py #811

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions Il2CppDumper/ghidra_with_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ def get_addr(addr):
return baseAddress.add(addr)

def set_name(addr, name):
try:
name = name.replace(' ', '-')
createLabel(addr, name, True, USER_DEFINED)
except:
print("set_name() Failed.")
try:
name = name.replace(' ', '-')
createLabel(addr, name, True, USER_DEFINED)
except:
print("set_name() Failed.")

def set_type(addr, type):
# Requires types (il2cpp.h) to be imported first
Expand All @@ -47,11 +47,10 @@ def set_type(addr, type):
if addrType is None:
print("Could not identify type " + type + "(parsed as '" + newType + "')")
else:
try:
createData(addr, addrType)
except ghidra.program.model.util.CodeUnitInsertionException:
print("Warning: unable to set type (CodeUnitInsertionException)")

try:
createData(addr, addrType)
except ghidra.program.model.util.CodeUnitInsertionException:
print("Warning: unable to set type (CodeUnitInsertionException)")

def make_function(start):
func = getFunctionAt(start)
Expand Down Expand Up @@ -79,8 +78,8 @@ def set_sig(addr, name, sig):
return
if typeSig is not None:
try:
typeSig.setName(name)
ApplyFunctionSignatureCmd(addr, typeSig, USER_DEFINED, False, True).applyTo(currentProgram)
typeSig.setName(name)
ApplyFunctionSignatureCmd(addr, typeSig, USER_DEFINED, False, True).applyTo(currentProgram)
except:
print("Warning: unable to set Signature. ApplyFunctionSignatureCmd() Failed.")

Expand Down Expand Up @@ -120,9 +119,9 @@ def set_sig(addr, name, sig):
name = scriptMetadata["Name"].encode("utf-8")
set_name(addr, name)
setEOLComment(addr, name)
monitor.incrementProgress(1)
if scriptMetadata["Signature"]:
set_type(addr, scriptMetadata["Signature"].encode("utf-8"))
monitor.incrementProgress(1)

if "ScriptMetadataMethod" in data and "ScriptMetadataMethod" in processFields:
scriptMetadataMethods = data["ScriptMetadataMethod"]
Expand All @@ -147,10 +146,13 @@ def set_sig(addr, name, sig):

if "ScriptMethod" in data and "ScriptMethod" in processFields:
scriptMethods = data["ScriptMethod"]
monitor.initialize(len(scriptMethods))
monitor.setMessage("Methods")
for scriptMethod in scriptMethods:
addr = get_addr(scriptMethod["Address"])
sig = scriptMethod["Signature"][:-1].encode("utf-8")
name = scriptMethod["Name"].encode("utf-8")
set_sig(addr, name, sig)
monitor.incrementProgress(1)

print 'Script finished!'