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