Python: Allow creation of typed arrays in IDA and Ghidra
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
from ghidra.app.cmd.function import ApplyFunctionSignatureCmd
|
||||
from ghidra.app.script import GhidraScriptUtil
|
||||
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):
|
||||
@@ -21,6 +22,16 @@ def MakeFunction(start, name=None):
|
||||
if name is not None:
|
||||
setPlateComment(addr, name)
|
||||
|
||||
def MakeArray(addr, numItems, cppType):
|
||||
if cppType.startswith('struct '):
|
||||
cppType = cppType[7:]
|
||||
|
||||
t = getDataTypes(cppType)[0]
|
||||
a = ArrayDataType(t, numItems, t.getLength())
|
||||
addr = toAddr(addr)
|
||||
removeDataAt(addr)
|
||||
createData(addr, a)
|
||||
|
||||
def DefineCode(code):
|
||||
# Code declarations are not supported in Ghidra
|
||||
# This only affects string literals for metadata version < 19
|
||||
@@ -32,11 +43,11 @@ def SetFunctionType(addr, sig):
|
||||
typeSig = CParserUtils.parseSignature(None, currentProgram, sig)
|
||||
ApplyFunctionSignatureCmd(toAddr(addr), typeSig, SourceType.USER_DEFINED, False, True).applyTo(currentProgram)
|
||||
|
||||
def SetType(addr, type):
|
||||
if type.startswith('struct '):
|
||||
type = type[7:]
|
||||
def SetType(addr, cppType):
|
||||
if cppType.startswith('struct '):
|
||||
cppType = cppType[7:]
|
||||
|
||||
t = getDataTypes(type)[0]
|
||||
t = getDataTypes(cppType)[0]
|
||||
addr = toAddr(addr)
|
||||
removeDataAt(addr)
|
||||
createData(addr, t)
|
||||
|
||||
@@ -10,6 +10,10 @@ def SetName(addr, name):
|
||||
def MakeFunction(start):
|
||||
ida_funcs.add_func(start)
|
||||
|
||||
def MakeArray(addr, numItems, cppType):
|
||||
SetType(addr, cppType)
|
||||
idc.make_array(addr, numItems)
|
||||
|
||||
def DefineCode(code):
|
||||
idc.parse_decls(code)
|
||||
|
||||
|
||||
@@ -38,6 +38,11 @@ def DefineField(addr, name, type, ilType = None):
|
||||
if (ilType is not None):
|
||||
SetComment(addr, AsUTF8(ilType))
|
||||
|
||||
def DefineArray(jsonDef):
|
||||
addr = ParseAddress(jsonDef)
|
||||
MakeArray(addr, int(jsonDef['count']), AsUTF8(jsonDef['type']))
|
||||
SetName(addr, AsUTF8(jsonDef['name']))
|
||||
|
||||
# Process JSON
|
||||
def ProcessJSON(jsonData):
|
||||
|
||||
@@ -105,6 +110,11 @@ def ProcessJSON(jsonData):
|
||||
for d in jsonData['functionMetadata']:
|
||||
DefineCppFunction(d)
|
||||
|
||||
# IL2CPP array metadata
|
||||
print('Processing IL2CPP array metadata')
|
||||
for d in jsonData['arrayMetadata']:
|
||||
DefineArray(d)
|
||||
|
||||
# IL2CPP API functions
|
||||
print('Processing IL2CPP API functions')
|
||||
for d in jsonData['apis']:
|
||||
|
||||
Reference in New Issue
Block a user