mirror of
https://github.com/Perfare/Il2CppDumper.git
synced 2025-01-10 03:27:28 -03:00
Fixed #106
This commit is contained in:
parent
8a1e42e726
commit
68fdf9e330
3 changed files with 64 additions and 4 deletions
|
@ -89,6 +89,9 @@
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<None Include="ghidra.py">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
|
|
@ -11,24 +11,23 @@ namespace Il2CppDumper
|
||||||
{
|
{
|
||||||
private Metadata metadata;
|
private Metadata metadata;
|
||||||
private Il2Cpp il2Cpp;
|
private Il2Cpp il2Cpp;
|
||||||
private StreamWriter writer;
|
|
||||||
private Dictionary<Il2CppTypeDefinition, int> typeDefImageIndices = new Dictionary<Il2CppTypeDefinition, int>();
|
private Dictionary<Il2CppTypeDefinition, int> typeDefImageIndices = new Dictionary<Il2CppTypeDefinition, int>();
|
||||||
|
|
||||||
public ScriptGenerator(Metadata metadata, Il2Cpp il2Cpp)
|
public ScriptGenerator(Metadata metadata, Il2Cpp il2Cpp)
|
||||||
{
|
{
|
||||||
writer = new StreamWriter(new FileStream("ida.py", FileMode.Create), new UTF8Encoding(false));
|
|
||||||
this.metadata = metadata;
|
this.metadata = metadata;
|
||||||
this.il2Cpp = il2Cpp;
|
this.il2Cpp = il2Cpp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WriteScript(Config config)
|
public void WriteScript(Config config)
|
||||||
{
|
{
|
||||||
writer.WriteLine("#encoding: utf-8");
|
var writer = new StreamWriter(new FileStream("ida.py", FileMode.Create), new UTF8Encoding(false));
|
||||||
|
writer.WriteLine("# -*- coding: utf-8 -*-");
|
||||||
writer.WriteLine("import idaapi");
|
writer.WriteLine("import idaapi");
|
||||||
writer.WriteLine();
|
writer.WriteLine();
|
||||||
writer.WriteLine("def SetString(addr, comm):");
|
writer.WriteLine("def SetString(addr, comm):");
|
||||||
writer.WriteLine("\tglobal index");
|
writer.WriteLine("\tglobal index");
|
||||||
writer.WriteLine("\tname = \"StringLiteral_\" + str(index);");
|
writer.WriteLine("\tname = \"StringLiteral_\" + str(index)");
|
||||||
writer.WriteLine("\tret = idc.set_name(addr, name, SN_NOWARN)");
|
writer.WriteLine("\tret = idc.set_name(addr, name, SN_NOWARN)");
|
||||||
writer.WriteLine("\tidc.set_cmt(addr, comm, 1)");
|
writer.WriteLine("\tidc.set_cmt(addr, comm, 1)");
|
||||||
writer.WriteLine("\tindex += 1");
|
writer.WriteLine("\tindex += 1");
|
||||||
|
|
58
Il2CppDumper/ghidra.py
Normal file
58
Il2CppDumper/ghidra.py
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
import ghidra.program.model.symbol.SourceType
|
||||||
|
import re
|
||||||
|
|
||||||
|
functionManager = currentProgram.getFunctionManager()
|
||||||
|
baseAddress = currentProgram.getImageBase()
|
||||||
|
USER_DEFINED = ghidra.program.model.symbol.SourceType.USER_DEFINED
|
||||||
|
index = 1
|
||||||
|
|
||||||
|
def _convert_arg_addr(arg):
|
||||||
|
return baseAddress.add(int(arg, 0))
|
||||||
|
|
||||||
|
def _convert_arg_string(arg):
|
||||||
|
if arg.startswith('r'):
|
||||||
|
return arg[2:-1]
|
||||||
|
return arg[1:-1]
|
||||||
|
|
||||||
|
def do_idc_set_cmt(arg1, arg2):
|
||||||
|
addr = _convert_arg_addr(arg1)
|
||||||
|
text = _convert_arg_string(arg2)
|
||||||
|
setEOLComment(addr, text)
|
||||||
|
|
||||||
|
def do_SetName(arg1, arg2):
|
||||||
|
addr = _convert_arg_addr(arg1)
|
||||||
|
name = _convert_arg_string(arg2)
|
||||||
|
createLabel(addr, name, True, USER_DEFINED)
|
||||||
|
|
||||||
|
def do_SetString(arg1, arg2):
|
||||||
|
addr = _convert_arg_addr(arg1)
|
||||||
|
text = _convert_arg_string(arg2)
|
||||||
|
|
||||||
|
global index
|
||||||
|
name = "StringLiteral_" + str(index);
|
||||||
|
createLabel(addr, name, True, USER_DEFINED)
|
||||||
|
setEOLComment(addr, text)
|
||||||
|
index += 1
|
||||||
|
|
||||||
|
def do_MakeFunction(arg1, arg2):
|
||||||
|
start = _convert_arg_addr(arg1)
|
||||||
|
end = _convert_arg_addr(arg2)
|
||||||
|
next_func_start = getFunctionAfter(start).getEntryPoint()
|
||||||
|
if next_func_start < end:
|
||||||
|
end = next_func_start
|
||||||
|
body = createAddressSet()
|
||||||
|
body.addRange(start, end.subtract(1))
|
||||||
|
functionManager.deleteAddressRange(start, end.subtract(1), getMonitor())
|
||||||
|
func = getFunctionAt(start)
|
||||||
|
if func is None:
|
||||||
|
functionManager.createFunction(None, start, body, USER_DEFINED)
|
||||||
|
else:
|
||||||
|
func.setBody(body)
|
||||||
|
|
||||||
|
f = askFile("ida.py from Il2cppdumper", "Open")
|
||||||
|
for line in file(f.absolutePath):
|
||||||
|
match = re.search(r"^([\w+\.]+)\((\w+),\s*(.*)\)$", line)
|
||||||
|
if match:
|
||||||
|
name, arg1, arg2 = match.groups()
|
||||||
|
res = globals()['do_'+name.replace('.', '_')](arg1, arg2.replace(' ', '-'))
|
Loading…
Reference in a new issue