-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync some updates from the main project
- Loading branch information
1 parent
01ec5a6
commit 731c402
Showing
11 changed files
with
201 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters