Python: Support Python 3 (for IDA 7.4+) (#57)

This commit is contained in:
Katy Coe
2020-09-02 09:10:02 +02:00
parent dde0b74831
commit 1368d06170
2 changed files with 17 additions and 13 deletions

View File

@@ -1,39 +1,42 @@
# Shared interface
def AsUTF8(s):
return s if sys.version_info[0] > 2 else s.encode('utf-8')
def ParseAddress(d):
return int(d['virtualAddress'], 0)
def DefineILMethod(jsonDef):
addr = ParseAddress(jsonDef)
SetName(addr, jsonDef['name'].encode('utf-8'))
SetFunctionType(addr, jsonDef['signature'].encode('utf-8'))
SetHeaderComment(addr, jsonDef['dotNetSignature'].encode('utf-8'))
SetName(addr, AsUTF8(jsonDef['name']))
SetFunctionType(addr, AsUTF8(jsonDef['signature']))
SetHeaderComment(addr, AsUTF8(jsonDef['dotNetSignature']))
def DefineILMethodInfo(jsonDef):
addr = ParseAddress(jsonDef)
SetName(addr, jsonDef['name'].encode('utf-8'))
SetName(addr, AsUTF8(jsonDef['name']))
SetType(addr, r'struct MethodInfo *')
SetComment(addr, jsonDef['dotNetSignature'].encode('utf-8'))
SetComment(addr, AsUTF8(jsonDef['dotNetSignature']))
def DefineCppFunction(jsonDef):
addr = ParseAddress(jsonDef)
SetName(addr, jsonDef['name'].encode('utf-8'))
SetFunctionType(addr, jsonDef['signature'].encode('utf-8'))
SetName(addr, AsUTF8(jsonDef['name']))
SetFunctionType(addr, AsUTF8(jsonDef['signature']))
def DefineString(jsonDef):
addr = ParseAddress(jsonDef)
SetName(addr, jsonDef['name'].encode('utf-8'))
SetName(addr, AsUTF8(jsonDef['name']))
SetType(addr, r'struct String *')
SetComment(addr, jsonDef['string'].encode('utf-8'))
SetComment(addr, AsUTF8(jsonDef['string']))
def DefineFieldFromJson(jsonDef):
DefineField(jsonDef['virtualAddress'], jsonDef['name'], jsonDef['type'], jsonDef['dotNetType'])
def DefineField(addr, name, type, ilType = None):
addr = int(addr, 0)
SetName(addr, name.encode('utf-8'))
SetType(addr, type.encode('utf-8'))
SetName(addr, AsUTF8(name))
SetType(addr, AsUTF8(type))
if (ilType is not None):
SetComment(addr, ilType.encode('utf-8'))
SetComment(addr, AsUTF8(ilType))
# Process JSON
def ProcessJSON(jsonData):
@@ -68,7 +71,7 @@ def ProcessJSON(jsonData):
else:
litDecl = 'enum StringLiteralIndex {\n'
for d in jsonData['stringLiterals']:
litDecl += " " + d['name'].encode('utf-8') + ",\n"
litDecl += " " + AsUTF8(d['name']) + ",\n"
litDecl += '};\n'
DefineCode(litDecl)

View File

@@ -3,3 +3,4 @@
import json
import os
import sys