Overhaul IDA script output and add progress waitbox
This commit is contained in:
@@ -5,24 +5,18 @@ from ghidra.app.util.cparser.C import CParserUtils
|
||||
from ghidra.program.model.data import ArrayDataType
|
||||
from ghidra.program.model.symbol import SourceType
|
||||
|
||||
def SetName(addr, name):
|
||||
def set_name(addr, name):
|
||||
createLabel(toAddr(addr), name, True)
|
||||
|
||||
def MakeFunction(start, name=None, addrMax=None):
|
||||
def make_function(start, end = None):
|
||||
addr = toAddr(start)
|
||||
# Don't override existing functions
|
||||
fn = getFunctionAt(addr)
|
||||
if fn is not None and name is not None:
|
||||
# Set existing function name if name available
|
||||
fn.setName(name, SourceType.USER_DEFINED)
|
||||
elif fn is None:
|
||||
if fn is None:
|
||||
# Create new function if none exists
|
||||
createFunction(addr, name)
|
||||
# Set header comment if name available
|
||||
if name is not None:
|
||||
setPlateComment(addr, name)
|
||||
createFunction(addr, None)
|
||||
|
||||
def MakeArray(addr, numItems, cppType):
|
||||
def make_array(addr, numItems, cppType):
|
||||
if cppType.startswith('struct '):
|
||||
cppType = cppType[7:]
|
||||
|
||||
@@ -32,18 +26,18 @@ def MakeArray(addr, numItems, cppType):
|
||||
removeDataAt(addr)
|
||||
createData(addr, a)
|
||||
|
||||
def DefineCode(code):
|
||||
def define_code(code):
|
||||
# Code declarations are not supported in Ghidra
|
||||
# This only affects string literals for metadata version < 19
|
||||
# TODO: Replace with creating a DataType for enums
|
||||
pass
|
||||
|
||||
def SetFunctionType(addr, sig):
|
||||
MakeFunction(addr)
|
||||
def set_function_type(addr, sig):
|
||||
make_function(addr)
|
||||
typeSig = CParserUtils.parseSignature(None, currentProgram, sig)
|
||||
ApplyFunctionSignatureCmd(toAddr(addr), typeSig, SourceType.USER_DEFINED, False, True).applyTo(currentProgram)
|
||||
|
||||
def SetType(addr, cppType):
|
||||
def set_type(addr, cppType):
|
||||
if cppType.startswith('struct '):
|
||||
cppType = cppType[7:]
|
||||
|
||||
@@ -52,13 +46,13 @@ def SetType(addr, cppType):
|
||||
removeDataAt(addr)
|
||||
createData(addr, t)
|
||||
|
||||
def SetComment(addr, text):
|
||||
def set_comment(addr, text):
|
||||
setEOLComment(toAddr(addr), text)
|
||||
|
||||
def SetHeaderComment(addr, text):
|
||||
def set_header_comment(addr, text):
|
||||
setPlateComment(toAddr(addr), text)
|
||||
|
||||
def CustomInitializer():
|
||||
def script_prologue(status):
|
||||
# Check that the user has parsed the C headers first
|
||||
if len(getDataTypes('Il2CppObject')) == 0:
|
||||
print('STOP! You must import the generated C header file (%TYPE_HEADER_RELATIVE_PATH%) before running this script.')
|
||||
@@ -70,5 +64,10 @@ def CustomInitializer():
|
||||
if currentProgram.getExecutableFormat().endswith('(ELF)'):
|
||||
currentProgram.setImageBase(toAddr(%IMAGE_BASE%), True)
|
||||
|
||||
def GetScriptDirectory():
|
||||
def script_epilogue(status):
|
||||
pass
|
||||
|
||||
def get_script_directory():
|
||||
return getSourceFile().getParentFile().toString()
|
||||
|
||||
class StatusWrapper(BaseStatusHandler): pass
|
||||
Reference in New Issue
Block a user