From 7b9c28fdf30c7379f910498049ad896c63413f14 Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Tue, 28 Jul 2020 19:23:53 +0200 Subject: [PATCH] IDA: Don't produce C type header file if it's already available --- Il2CppInspector.CLI/Program.cs | 2 +- .../Outputs/IDAPythonScript.cs | 17 +++++++++++++---- Il2CppTests/TestRunner.cs | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Il2CppInspector.CLI/Program.cs b/Il2CppInspector.CLI/Program.cs index a1b9ff6..4727494 100644 --- a/Il2CppInspector.CLI/Program.cs +++ b/Il2CppInspector.CLI/Program.cs @@ -258,7 +258,7 @@ namespace Il2CppInspector.CLI // IDA Python script output using (new Benchmark("Generate IDAPython script")) { - new IDAPythonScript(appModel).WriteScriptToFile(options.PythonOutFile); + new IDAPythonScript(appModel).WriteScriptToFile(options.PythonOutFile, options.CppOutPath + Path.DirectorySeparatorChar + "il2cpp-types.h"); } // C++ output diff --git a/Il2CppInspector.Common/Outputs/IDAPythonScript.cs b/Il2CppInspector.Common/Outputs/IDAPythonScript.cs index 039128e..ebb559e 100755 --- a/Il2CppInspector.Common/Outputs/IDAPythonScript.cs +++ b/Il2CppInspector.Common/Outputs/IDAPythonScript.cs @@ -21,11 +21,20 @@ namespace Il2CppInspector.Outputs public IDAPythonScript(AppModel model) => this.model = model; - public void WriteScriptToFile(string outputFile) { + public void WriteScriptToFile(string outputFile, string existingTypeHeaderFIle = null) { - // Write types file first + // Write types file first if it hasn't been specified var typeHeaderFile = Path.Combine(Path.GetDirectoryName(outputFile), Path.GetFileNameWithoutExtension(outputFile) + ".h"); - writeTypes(typeHeaderFile); + + if (string.IsNullOrEmpty(existingTypeHeaderFIle)) + writeTypes(typeHeaderFile); + else + typeHeaderFile = existingTypeHeaderFIle; + + var typeHeaderRelativePath = Path.GetRelativePath(Path.GetDirectoryName(Path.GetFullPath(outputFile)), + Path.GetDirectoryName(Path.GetFullPath(typeHeaderFile))) + + Path.DirectorySeparatorChar + + Path.GetFileName(typeHeaderFile); using var fs = new FileStream(outputFile, FileMode.Create); writer = new StreamWriter(fs, Encoding.ASCII); @@ -40,7 +49,7 @@ namespace Il2CppInspector.Outputs writeLine( @"original_macros = ida_typeinf.get_c_macros() ida_typeinf.set_c_macros(original_macros + "";_IDA_=1"") -idc.parse_decls(""" + Path.GetFileName(typeHeaderFile) + @""", idc.PT_FILE) +idc.parse_decls(""" + typeHeaderRelativePath + @""", idc.PT_FILE) ida_typeinf.set_c_macros(original_macros)"); writeMethods(); diff --git a/Il2CppTests/TestRunner.cs b/Il2CppTests/TestRunner.cs index b3494fe..827c95b 100644 --- a/Il2CppTests/TestRunner.cs +++ b/Il2CppTests/TestRunner.cs @@ -55,7 +55,7 @@ namespace Il2CppInspector }.WriteSingleFile(testPath + $@"\test-result{nameSuffix}.cs"); new IDAPythonScript(appModel) - .WriteScriptToFile(testPath + $@"\test-ida-result{nameSuffix}.py"); + .WriteScriptToFile(testPath + $@"\test-ida-result{nameSuffix}.py", testPath + $@"\test-cpp-result{nameSuffix}\il2cpp-types.h"); new CppScaffolding(appModel) .Write(testPath + $@"\test-cpp-result{nameSuffix}");