mirror of
https://github.com/Perfare/Il2CppDumper.git
synced 2025-01-09 11:17:35 -03:00
Update Binary Ninja script (#624)
* Update Binary Ninja script * More correct header convertation
This commit is contained in:
parent
bf36e1d5cc
commit
f4f630c768
6 changed files with 176 additions and 33 deletions
96
Il2CppDumper/Il2CppBinaryNinja/__init__.py
Normal file
96
Il2CppDumper/Il2CppBinaryNinja/__init__.py
Normal file
|
@ -0,0 +1,96 @@
|
|||
from binaryninja import *
|
||||
from os.path import exists
|
||||
|
||||
def get_addr(bv: BinaryView, addr: int):
|
||||
imageBase = bv.start
|
||||
return imageBase + addr
|
||||
|
||||
class Il2CppProcessTask(BackgroundTaskThread):
|
||||
def __init__(self, bv: BinaryView, script_path: str,
|
||||
header_path: str):
|
||||
BackgroundTaskThread.__init__(self, "Il2Cpp start", True)
|
||||
self.bv = bv
|
||||
self.script_path = script_path
|
||||
self.header_path = header_path
|
||||
self.has_types = False
|
||||
|
||||
def process_header(self):
|
||||
self.progress = "Il2Cpp types (1/3)"
|
||||
with open(self.header_path) as f:
|
||||
result = self.bv.parse_types_from_string(f.read())
|
||||
length = len(result.types)
|
||||
i = 0
|
||||
for name in result.types:
|
||||
i += 1
|
||||
if i % 100 == 0:
|
||||
percent = i / length * 100
|
||||
self.progress = f"Il2Cpp types: {percent:.2f}%"
|
||||
if self.bv.get_type_by_name(name):
|
||||
continue
|
||||
self.bv.define_user_type(name, result.types[name])
|
||||
|
||||
def process_methods(self, data: dict):
|
||||
self.progress = f"Il2Cpp methods (2/3)"
|
||||
scriptMethods = data["ScriptMethod"]
|
||||
length = len(scriptMethods)
|
||||
i = 0
|
||||
for scriptMethod in scriptMethods:
|
||||
if self.cancelled:
|
||||
self.progress = "Il2Cpp cancelled, aborting"
|
||||
return
|
||||
i += 1
|
||||
if i % 100 == 0:
|
||||
percent = i / length * 100
|
||||
self.progress = f"Il2Cpp methods: {percent:.2f}%"
|
||||
addr = get_addr(self.bv, scriptMethod["Address"])
|
||||
name = scriptMethod["Name"].replace("$", "_").replace(".", "_")
|
||||
signature = scriptMethod["Signature"]
|
||||
func = self.bv.get_function_at(addr)
|
||||
if func != None:
|
||||
if func.name == name:
|
||||
continue
|
||||
if self.has_types:
|
||||
func.function_type = signature
|
||||
else:
|
||||
func.name = scriptMethod["Name"]
|
||||
|
||||
def process_strings(self, data: dict):
|
||||
self.progress = "Il2Cpp strings (3/3)"
|
||||
scriptStrings = data["ScriptString"]
|
||||
i = 0
|
||||
for scriptString in scriptStrings:
|
||||
i += 1
|
||||
if self.cancelled:
|
||||
self.progress = "Il2Cpp cancelled, aborting"
|
||||
return
|
||||
addr = get_addr(self.bv, scriptString["Address"])
|
||||
value = scriptString["Value"]
|
||||
var = self.bv.get_data_var_at(addr)
|
||||
if var != None:
|
||||
var.name = f"StringLiteral_{i}"
|
||||
self.bv.set_comment_at(addr, value)
|
||||
|
||||
def run(self):
|
||||
if exists(self.header_path):
|
||||
self.process_header()
|
||||
else:
|
||||
log_warn("Header file not found")
|
||||
if self.bv.get_type_by_name("Il2CppClass"):
|
||||
self.has_types = True
|
||||
data = json.loads(open(self.script_path, 'rb').read().decode('utf-8'))
|
||||
if "ScriptMethod" in data:
|
||||
self.process_methods(data)
|
||||
if "ScriptString" in data:
|
||||
self.process_strings(data)
|
||||
|
||||
def process(bv: BinaryView):
|
||||
scriptDialog = OpenFileNameField("Select script.json", "script.json", "script.json")
|
||||
headerDialog = OpenFileNameField("Select il2cpp_binja.h", "il2cpp_binja.h", "il2cpp_binja.h")
|
||||
if not get_form_input([scriptDialog, headerDialog], "script.json from Il2CppDumper"):
|
||||
return log_error("File not selected, try again!")
|
||||
if not exists(scriptDialog.result):
|
||||
return log_error("File not found, try again!")
|
||||
task = Il2CppProcessTask(bv, scriptDialog.result, headerDialog.result)
|
||||
task.start()
|
||||
|
||||
PluginCommand.register("Il2CppDumper", "Process file", process)
|
33
Il2CppDumper/Il2CppBinaryNinja/plugin.json
Normal file
33
Il2CppDumper/Il2CppBinaryNinja/plugin.json
Normal file
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
"pluginmetadataversion": 2,
|
||||
"name": "Il2CppDumper",
|
||||
"type": [
|
||||
"core",
|
||||
"ui",
|
||||
"binaryview"
|
||||
],
|
||||
"api": [
|
||||
"python3"
|
||||
],
|
||||
"description": "Add Il2Cpp structs and method signatures",
|
||||
"longdescription": "",
|
||||
"license": {
|
||||
"name": "MIT",
|
||||
"text": "Copyright (c) 2022 Il2CppDumper contributors\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."
|
||||
},
|
||||
"platforms": [
|
||||
"Darwin",
|
||||
"Linux",
|
||||
"Windows"
|
||||
],
|
||||
"installinstructions": {
|
||||
"Darwin": "Install Il2CppDumper",
|
||||
"Linux": "Install Il2CppDumper",
|
||||
"Windows": "Install Il2CppDumper"
|
||||
},
|
||||
"dependencies": {
|
||||
},
|
||||
"version": "1.0.0",
|
||||
"author": "Il2CppDumper contributors",
|
||||
"minimumbinaryninjaversion": 3164
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
import binaryninja
|
||||
from os.path import exists
|
||||
|
||||
imageBase = bv.start
|
||||
|
||||
def get_addr(addr):
|
||||
return imageBase + addr
|
||||
|
||||
fileDialog = OpenFileNameField("Select script.json", "script.json", "script.json")
|
||||
|
||||
if get_form_input([fileDialog], "script.json from Il2CppDumper") != 1:
|
||||
print("File not selected, try again!")
|
||||
else:
|
||||
if exists(fileDialog.result) == True:
|
||||
data = json.loads(open(fileDialog.result, 'rb').read().decode('utf-8'))
|
||||
data["Addresses"] = None
|
||||
if "ScriptMethod" in data:
|
||||
scriptMethods = data["ScriptMethod"]
|
||||
for scriptMethod in scriptMethods:
|
||||
addr = get_addr(scriptMethod["Address"])
|
||||
name = scriptMethod["Name"]
|
||||
func = bv.get_function_at(addr)
|
||||
if func != None:
|
||||
bv.get_function_at(addr).name = name
|
||||
print("Done")
|
||||
else:
|
||||
print("File not found")
|
41
Il2CppDumper/il2cpp_header_to_binja.py
Normal file
41
Il2CppDumper/il2cpp_header_to_binja.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
import re
|
||||
|
||||
data = open("./il2cpp.h").read()
|
||||
|
||||
builtin = ["void", "intptr_t", "uint32_t", "uint16_t", "int32_t", "uint8_t", "bool",
|
||||
"int64_t", "uint64_t", "double", "int16_t", "int8_t", "float", "uintptr_t",
|
||||
"const", "union", "{", "};", "il2cpp_array_size_t", "il2cpp_array_lower_bound_t",
|
||||
"struct", "Il2CppMethodPointer"]
|
||||
structs = []
|
||||
notfound = []
|
||||
header = ""
|
||||
|
||||
for line in data.splitlines():
|
||||
if line.startswith("struct") or line.startswith("union"):
|
||||
struct = line.split()[1]
|
||||
if struct.endswith(";"):
|
||||
struct = struct[:-1]
|
||||
structs.append(struct)
|
||||
if line.startswith("\t"):
|
||||
struct = line[1:].split()[0]
|
||||
if struct == "struct":
|
||||
struct = line[1:].split()[1]
|
||||
if struct.endswith("*"):
|
||||
struct = struct[:-1]
|
||||
if struct.endswith("*"):
|
||||
struct = struct[:-1]
|
||||
if struct in builtin:
|
||||
continue
|
||||
if struct not in structs and struct not in notfound:
|
||||
notfound.append(struct)
|
||||
for struct in notfound:
|
||||
header += f"struct {struct};" + "\n"
|
||||
to_replace = re.findall("struct (.*) {\n};", data)
|
||||
for item in to_replace:
|
||||
data = data.replace("struct "+item+" {\n};", "")
|
||||
data = data.replace("\t"+item.split()[0]+" ", "\tvoid *")
|
||||
data = data.replace("\t struct "+item.split()[0]+" ", "\t void *")
|
||||
data = re.sub(r": (\w+) {", r"{\n\t\1 super;", data)
|
||||
with open("./il2cpp_binja.h", "w") as f:
|
||||
f.write(header)
|
||||
f.write(data)
|
|
@ -11,7 +11,7 @@ Unity il2cpp reverse engineer
|
|||
* Complete DLL restore (except code), can be used to extract `MonoBehaviour` and `MonoScript`
|
||||
* Supports ELF, ELF64, Mach-O, PE, NSO and WASM format
|
||||
* Supports Unity 5.3 - 2021.3
|
||||
* Supports generate IDA and Ghidra scripts to help IDA and Ghidra better analyze il2cpp files
|
||||
* Supports generate IDA, Ghidra and Binary Ninja scripts to help them better analyze il2cpp files
|
||||
* Supports generate structures header file
|
||||
* Supports Android memory dumped `libil2cpp.so` file to bypass protection
|
||||
* Support bypassing simple PE protection
|
||||
|
@ -54,7 +54,7 @@ structure information header file
|
|||
|
||||
For Ghidra
|
||||
|
||||
#### binaryninja3_py3.py
|
||||
#### Il2CppBinaryNinja
|
||||
|
||||
For BinaryNinja
|
||||
|
||||
|
@ -64,7 +64,7 @@ For Ghidra, work with [ghidra-wasm-plugin](https://github.com/nneonneo/ghidra-wa
|
|||
|
||||
#### script.json
|
||||
|
||||
For ida.py and ghidra.py
|
||||
For ida.py, ghidra.py and Il2CppBinaryNinja
|
||||
|
||||
#### stringliteral.json
|
||||
|
||||
|
@ -119,4 +119,4 @@ If you have a rooted Android phone, you can try my other project [Zygisk-Il2CppD
|
|||
|
||||
## Credits
|
||||
|
||||
- Jumboperson - [Il2CppDumper](https://github.com/Jumboperson/Il2CppDumper)
|
||||
- Jumboperson - [Il2CppDumper](https://github.com/Jumboperson/Il2CppDumper)
|
||||
|
|
|
@ -52,7 +52,7 @@ Il2CppDumper.exe <executable-file> <global-metadata> <output-directory>
|
|||
|
||||
用于Ghidra
|
||||
|
||||
#### binaryninja3_py3.py
|
||||
#### Il2CppBinaryNinja
|
||||
|
||||
用于BinaryNinja
|
||||
|
||||
|
@ -113,4 +113,4 @@ Il2CppDumper检测到可执行文件已被保护,使用`GameGuardian`从游戏
|
|||
|
||||
## 感谢
|
||||
|
||||
- Jumboperson - [Il2CppDumper](https://github.com/Jumboperson/Il2CppDumper)
|
||||
- Jumboperson - [Il2CppDumper](https://github.com/Jumboperson/Il2CppDumper)
|
||||
|
|
Loading…
Reference in a new issue