CLI: Add C++ header output support

This commit is contained in:
Katy Coe
2020-07-02 14:24:20 +02:00
parent 25d19457a9
commit 01519c4c29

View File

@@ -29,6 +29,9 @@ namespace Il2CppInspector.CLI
[Option('p', "py-out", Required = false, HelpText = "IDA Python script output file", Default = "ida.py")] [Option('p', "py-out", Required = false, HelpText = "IDA Python script output file", Default = "ida.py")]
public string PythonOutFile { get; set; } public string PythonOutFile { get; set; }
[Option('h', "cpp-out", Required = false, HelpText = "C++ header output file", Default = "il2cpp-types.h")]
public string CppOutFile { get; set; }
[Option('e', "exclude-namespaces", Required = false, Separator = ',', HelpText = "Comma-separated list of namespaces to suppress in C# output, or 'none' to include all namespaces", [Option('e', "exclude-namespaces", Required = false, Separator = ',', HelpText = "Comma-separated list of namespaces to suppress in C# output, or 'none' to include all namespaces",
Default = new [] { Default = new [] {
"System", "System",
@@ -72,7 +75,7 @@ namespace Il2CppInspector.CLI
[Option("unity-assemblies", Required = false, HelpText = "Path to Unity script assemblies (when using --project). Wildcards select last matching folder in alphanumeric order", Default = @"C:\Program Files\Unity\Hub\Editor\*\Editor\Data\Resources\PackageManager\ProjectTemplates\libcache\com.unity.template.3d-*\ScriptAssemblies")] [Option("unity-assemblies", Required = false, HelpText = "Path to Unity script assemblies (when using --project). Wildcards select last matching folder in alphanumeric order", Default = @"C:\Program Files\Unity\Hub\Editor\*\Editor\Data\Resources\PackageManager\ProjectTemplates\libcache\com.unity.template.3d-*\ScriptAssemblies")]
public string UnityAssembliesPath { get; set; } public string UnityAssembliesPath { get; set; }
[Option("unity-version", Required = false, HelpText = "Version of Unity used to create the input files, if known. Used to enhance IDA Python script output. If not specified, a close match will be inferred automatically.", Default = null)] [Option("unity-version", Required = false, HelpText = "Version of Unity used to create the input files, if known. Used to enhance IDAPython and C++ output. If not specified, a close match will be inferred automatically.", Default = null)]
public UnityVersion UnityVersion { get; set; } public UnityVersion UnityVersion { get; set; }
} }
@@ -143,7 +146,7 @@ namespace Il2CppInspector.CLI
// Check files exist and determine whether they're archives or not // Check files exist and determine whether they're archives or not
List<Il2CppInspector> il2cppInspectors; List<Il2CppInspector> il2cppInspectors;
using (var il2cppTimer = new Benchmark("Analyze IL2CPP data")) { using (new Benchmark("Analyze IL2CPP data")) {
if (!File.Exists(options.BinaryFile)) { if (!File.Exists(options.BinaryFile)) {
Console.Error.WriteLine($"File {options.BinaryFile} does not exist"); Console.Error.WriteLine($"File {options.BinaryFile} does not exist");
@@ -176,11 +179,11 @@ namespace Il2CppInspector.CLI
foreach (var il2cpp in il2cppInspectors) { foreach (var il2cpp in il2cppInspectors) {
// Create model // Create model
Il2CppModel model; Il2CppModel model;
using (var modelTimer = new Benchmark("Create type model")) using (new Benchmark("Create type model"))
model = new Il2CppModel(il2cpp); model = new Il2CppModel(il2cpp);
// C# signatures output // C# signatures output
using (var signaturesDumperTimer = new Benchmark("Generate C# code")) { using (new Benchmark("Generate C# code")) {
var writer = new CSharpCodeStubs(model) { var writer = new CSharpCodeStubs(model) {
ExcludedNamespaces = options.ExcludedNamespaces.ToList(), ExcludedNamespaces = options.ExcludedNamespaces.ToList(),
SuppressMetadata = options.SuppressMetadata, SuppressMetadata = options.SuppressMetadata,
@@ -235,12 +238,20 @@ namespace Il2CppInspector.CLI
} }
// IDA Python script output // IDA Python script output
using (var scriptDumperTimer = new Benchmark("IDA Python Script Dumper")) { using (new Benchmark("Generate IDAPython script")) {
var idaWriter = new IDAPythonScript(model) { var idaWriter = new IDAPythonScript(model) {
UnityVersion = options.UnityVersion, UnityVersion = options.UnityVersion
}; };
idaWriter.WriteScriptToFile(options.PythonOutFile); idaWriter.WriteScriptToFile(options.PythonOutFile);
} }
// C++ output
using (new Benchmark("Generate C++ code")) {
var cppWriter = new CppScaffolding(model) {
UnityVersion = options.UnityVersion
};
cppWriter.WriteCppToFile(options.CppOutFile);
}
} }
// Success exit code // Success exit code