From b5a70d94fd346ddcbed052baac799fae34a9f66c Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Thu, 6 Aug 2020 05:20:20 +0200 Subject: [PATCH] Script: Allow script target API to be passed as argument --- Il2CppInspector.CLI/Program.cs | 2 +- Il2CppInspector.Common/Outputs/IDAPythonScript.cs | 12 +++++++----- Il2CppInspector.GUI/MainWindow.xaml.cs | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Il2CppInspector.CLI/Program.cs b/Il2CppInspector.CLI/Program.cs index ac1dbf1..30fed2e 100644 --- a/Il2CppInspector.CLI/Program.cs +++ b/Il2CppInspector.CLI/Program.cs @@ -271,7 +271,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, "IDA", Path.Combine(options.CppOutPath, "appdata/il2cpp-types.h"), options.JsonOutPath); } diff --git a/Il2CppInspector.Common/Outputs/IDAPythonScript.cs b/Il2CppInspector.Common/Outputs/IDAPythonScript.cs index df51314..8a36451 100755 --- a/Il2CppInspector.Common/Outputs/IDAPythonScript.cs +++ b/Il2CppInspector.Common/Outputs/IDAPythonScript.cs @@ -8,6 +8,7 @@ using System.IO; using Il2CppInspector.Reflection; using Il2CppInspector.Model; using System.Collections.Generic; +using System; namespace Il2CppInspector.Outputs { @@ -25,7 +26,11 @@ namespace Il2CppInspector.Outputs } // Output script file - public void WriteScriptToFile(string outputFile, string existingTypeHeaderFIle = null, string existingJsonMetadataFile = null) { + public void WriteScriptToFile(string outputFile, string target, string existingTypeHeaderFIle = null, string existingJsonMetadataFile = null) { + + // Check that target script API is valid + if (!GetAvailableTargets().Contains(target)) + throw new InvalidOperationException("Unknown script API target: " + target); // Write types file first if it hasn't been specified var typeHeaderFile = Path.Combine(Path.GetDirectoryName(outputFile), Path.GetFileNameWithoutExtension(outputFile) + ".h"); @@ -47,13 +52,10 @@ namespace Il2CppInspector.Outputs var jsonMetadataRelativePath = getRelativePath(outputFile, jsonMetadataFile); - // TODO: Replace with target selector - var targetApi = "IDA"; - var ns = typeof(IDAPythonScript).Namespace + ".ScriptResources"; var preamble = ResourceHelper.GetText(ns + ".shared-preamble.py"); var main = ResourceHelper.GetText(ns + ".shared-main.py"); - var api = ResourceHelper.GetText($"{ns}.Targets.{targetApi}.py"); + var api = ResourceHelper.GetText($"{ns}.Targets.{target}.py"); var script = string.Join("\n", new [] { preamble, api, main }) .Replace("%SCRIPTFILENAME%", Path.GetFileName(outputFile)) diff --git a/Il2CppInspector.GUI/MainWindow.xaml.cs b/Il2CppInspector.GUI/MainWindow.xaml.cs index 3f9979f..c68fd90 100644 --- a/Il2CppInspector.GUI/MainWindow.xaml.cs +++ b/Il2CppInspector.GUI/MainWindow.xaml.cs @@ -431,7 +431,7 @@ namespace Il2CppInspectorGUI model.Build(selectedIdaUnityVersion, CppCompilerType.GCC); OnStatusUpdate(this, "Generating IDAPython script"); - new IDAPythonScript(model).WriteScriptToFile(idaOutFile); + new IDAPythonScript(model).WriteScriptToFile(idaOutFile, "IDA"); }); break;