|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +import json |
| 3 | + |
| 4 | +processFields = [ |
| 5 | + "ScriptMethod", |
| 6 | + "ScriptString", |
| 7 | + "ScriptMetadata", |
| 8 | + "ScriptMetadataMethod", |
| 9 | + "Addresses", |
| 10 | +] |
| 11 | + |
| 12 | +imageBase = idaapi.get_imagebase() |
| 13 | + |
| 14 | +def get_addr(addr): |
| 15 | + return imageBase + addr |
| 16 | + |
| 17 | +def set_name(addr, name): |
| 18 | + ret = idc.set_name(addr, name, SN_NOWARN | SN_NOCHECK) |
| 19 | + if ret == 0: |
| 20 | + new_name = name + '_' + str(addr) |
| 21 | + ret = idc.set_name(addr, new_name, SN_NOWARN | SN_NOCHECK) |
| 22 | + |
| 23 | +def make_function(start, end): |
| 24 | + next_func = idc.get_next_func(start) |
| 25 | + if next_func < end: |
| 26 | + end = next_func |
| 27 | + if idc.get_func_attr(start, FUNCATTR_START) == start: |
| 28 | + ida_funcs.del_func(start) |
| 29 | + ida_funcs.add_func(start, end) |
| 30 | + |
| 31 | +path = idaapi.ask_file(False, '*.json', 'script.json from Il2cppdumper') |
| 32 | +hpath = idaapi.ask_file(False, '*.h', 'il2cpp.h from Il2cppdumper') |
| 33 | +parse_decls(open(hpath, 'r').read(), 0) |
| 34 | +data = json.loads(open(path, 'rb').read().decode('utf-8')) |
| 35 | + |
| 36 | +if "Addresses" in data and "Addresses" in processFields: |
| 37 | + addresses = data["Addresses"] |
| 38 | + for index in range(len(addresses) - 1): |
| 39 | + start = get_addr(addresses[index]) |
| 40 | + end = get_addr(addresses[index + 1]) |
| 41 | + make_function(start, end) |
| 42 | + |
| 43 | +if "ScriptMethod" in data and "ScriptMethod" in processFields: |
| 44 | + scriptMethods = data["ScriptMethod"] |
| 45 | + for scriptMethod in scriptMethods: |
| 46 | + addr = get_addr(scriptMethod["Address"]) |
| 47 | + name = scriptMethod["Name"] |
| 48 | + set_name(addr, name) |
| 49 | + signature = scriptMethod["Signature"] |
| 50 | + if apply_type(addr, parse_decl(signature, 0), 1) == False: |
| 51 | + print("apply_type failed:", hex(addr), signature) |
| 52 | + |
| 53 | +if "ScriptString" in data and "ScriptString" in processFields: |
| 54 | + index = 1 |
| 55 | + scriptStrings = data["ScriptString"] |
| 56 | + for scriptString in scriptStrings: |
| 57 | + addr = get_addr(scriptString["Address"]) |
| 58 | + value = scriptString["Value"] |
| 59 | + name = "StringLiteral_" + str(index) |
| 60 | + idc.set_name(addr, name, SN_NOWARN) |
| 61 | + idc.set_cmt(addr, value, 1) |
| 62 | + index += 1 |
| 63 | + |
| 64 | +if "ScriptMetadata" in data and "ScriptMetadata" in processFields: |
| 65 | + scriptMetadatas = data["ScriptMetadata"] |
| 66 | + for scriptMetadata in scriptMetadatas: |
| 67 | + addr = get_addr(scriptMetadata["Address"]) |
| 68 | + name = scriptMetadata["Name"] |
| 69 | + set_name(addr, name) |
| 70 | + idc.set_cmt(addr, name, 1) |
| 71 | + if scriptMetadata["Signature"] is not None: |
| 72 | + signature = scriptMetadata["Signature"] |
| 73 | + if apply_type(addr, parse_decl(signature, 0), 1) == False: |
| 74 | + print("apply_type failed:", hex(addr), signature) |
| 75 | + |
| 76 | +if "ScriptMetadataMethod" in data and "ScriptMetadataMethod" in processFields: |
| 77 | + scriptMetadataMethods = data["ScriptMetadataMethod"] |
| 78 | + for scriptMetadataMethod in scriptMetadataMethods: |
| 79 | + addr = get_addr(scriptMetadataMethod["Address"]) |
| 80 | + name = scriptMetadataMethod["Name"] |
| 81 | + methodAddr = get_addr(scriptMetadataMethod["MethodAddress"]) |
| 82 | + set_name(addr, name) |
| 83 | + idc.set_cmt(addr, name, 1) |
| 84 | + idc.set_cmt(addr, '{0:X}'.format(methodAddr), 0) |
| 85 | + |
| 86 | +print('Script finished!') |
| 87 | + |
0 commit comments