Implement new GUI and CLI, fix misc. smaller issues (#22)
* Initial commit of new UI c# component * Initial commit of new UI frontend component * target WinExe to hide console window in release mode, move ui exe into resources * force single file publishing and add initial gh workflow for publishing ui * fix workflow errors * update dependencies and remove cxxdemangler, as it was outdated * fix c# single file output due to invalid output path * smaller tweaks, hack around loops in cpp type layouting * process other queued exports even if one fails and show error message * add basic support for processing LC_DYLD_CHAINED_FIXUPS * ELF loading should not use the file offset for loading the dynamic section * fix symbol table loading in some modified elfs * add "start export" button on format selection screen, clear all toasts after selecting an export format * embed ui executable directly into c# assembly * only build tauri component in c# release builds * add il2cpp file (binary, metadata) export to advanced tab * fix and enable binary ninja fake string segment support * add support for metadata * unify logic for getting element type index * fix new ui not allowing script exports other than ida * new ui: clear out loaded binary if no IL2CPP images could be loaded * fix toAddr calls in ghidra script target * remove dependency on a section being named .text in loaded pe files * tweak symbol reading a bit and remove sht relocation reading * add initial support for required forward references in il2cpp types, also fix issues with type names clashing with il2cpp api types * reduce clang errors for header file, fix better array size struct, emit required forward definitions in header * expose forward definitions in AppModel, fix issue with method-only used types not being emitted * remove debug log line * fix spelling mistakes in gui outputs * fix il2cpp_array_size_t not being an actual type for later method definitions * change the default port for new ui dev to 5000 * show current version and hash in new ui footer * seperate redux ui impl into FrontendCore project * make inspector version a server api, split up output subtypes and tweak some option names * add redux CLI based on redux GUI output formats * replace all Console.WriteLine calls in core inspector with AnsiConsole calls * add workflow for new cli and add back old gui workflow * disable aot publish and enable single file for redux cli
This commit is contained in:
10
Il2CppInspector.Redux.FrontendCore/Outputs/CSharpLayout.cs
Normal file
10
Il2CppInspector.Redux.FrontendCore/Outputs/CSharpLayout.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Il2CppInspector.Redux.FrontendCore.Outputs;
|
||||
|
||||
public enum CSharpLayout
|
||||
{
|
||||
SingleFile,
|
||||
Namespace,
|
||||
Assembly,
|
||||
Class,
|
||||
Tree
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
using Il2CppInspector.Model;
|
||||
using Il2CppInspector.Outputs;
|
||||
|
||||
namespace Il2CppInspector.Redux.FrontendCore.Outputs;
|
||||
|
||||
public class CSharpStubOutput : IOutputFormatProvider
|
||||
{
|
||||
public static string Id => "cs";
|
||||
|
||||
private class Settings(Dictionary<string, string> settings)
|
||||
{
|
||||
public readonly CSharpLayout Layout = settings.GetAsEnumOrDefault("layout", CSharpLayout.SingleFile);
|
||||
public readonly bool FlattenHierarchy = settings.GetAsBooleanOrDefault("flattenhierarchy", false);
|
||||
public readonly TypeSortingMode SortingMode = settings.GetAsEnumOrDefault("sortingmode", TypeSortingMode.Alphabetical);
|
||||
public readonly bool SuppressMetadata = settings.GetAsBooleanOrDefault("suppressmetadata", false);
|
||||
public readonly bool MustCompile = settings.GetAsBooleanOrDefault("mustcompile", false);
|
||||
public readonly bool SeperateAssemblyAttributes = settings.GetAsBooleanOrDefault("seperateassemblyattributes", true);
|
||||
}
|
||||
|
||||
public async Task Export(AppModel model, UiClient client, string outputPath, Dictionary<string, string> settingsDict)
|
||||
{
|
||||
var settings = new Settings(settingsDict);
|
||||
|
||||
var writer = new CSharpCodeStubs(model.TypeModel)
|
||||
{
|
||||
SuppressMetadata = settings.SuppressMetadata,
|
||||
MustCompile = settings.MustCompile
|
||||
};
|
||||
|
||||
await client.ShowLogMessage("Writing C# type definitions");
|
||||
|
||||
var outputPathFile = Path.Join(outputPath, "il2cpp.cs");
|
||||
|
||||
switch (settings.Layout, settings.SortingMode)
|
||||
{
|
||||
case (CSharpLayout.SingleFile, TypeSortingMode.TypeDefinitionIndex):
|
||||
writer.WriteSingleFile(outputPathFile, info => info.Index);
|
||||
break;
|
||||
case (CSharpLayout.SingleFile, TypeSortingMode.Alphabetical):
|
||||
writer.WriteSingleFile(outputPathFile, info => info.Name);
|
||||
break;
|
||||
|
||||
case (CSharpLayout.Namespace, TypeSortingMode.TypeDefinitionIndex):
|
||||
writer.WriteFilesByNamespace(outputPath, info => info.Index, settings.FlattenHierarchy);
|
||||
break;
|
||||
case (CSharpLayout.Namespace, TypeSortingMode.Alphabetical):
|
||||
writer.WriteFilesByNamespace(outputPath, info => info.Name, settings.FlattenHierarchy);
|
||||
break;
|
||||
|
||||
case (CSharpLayout.Assembly, TypeSortingMode.TypeDefinitionIndex):
|
||||
writer.WriteFilesByAssembly(outputPath, info => info.Index, settings.SeperateAssemblyAttributes);
|
||||
break;
|
||||
case (CSharpLayout.Assembly, TypeSortingMode.Alphabetical):
|
||||
writer.WriteFilesByAssembly(outputPath, info => info.Name, settings.SeperateAssemblyAttributes);
|
||||
break;
|
||||
|
||||
case (CSharpLayout.Class, _):
|
||||
writer.WriteFilesByClass(outputPath, settings.FlattenHierarchy);
|
||||
break;
|
||||
|
||||
case (CSharpLayout.Tree, _):
|
||||
writer.WriteFilesByClassTree(outputPath, settings.SeperateAssemblyAttributes);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using Il2CppInspector.Cpp;
|
||||
using Il2CppInspector.Cpp.UnityHeaders;
|
||||
using Il2CppInspector.Model;
|
||||
using Il2CppInspector.Outputs;
|
||||
|
||||
namespace Il2CppInspector.Redux.FrontendCore.Outputs;
|
||||
|
||||
public class CppScaffoldingOutput : IOutputFormatProvider
|
||||
{
|
||||
public static string Id => "cppscaffolding";
|
||||
|
||||
private class Settings(Dictionary<string, string> settings)
|
||||
{
|
||||
public readonly string UnityVersion = settings.GetValueOrDefault("unityversion", "");
|
||||
public readonly CppCompilerType Compiler = settings.GetAsEnumOrDefault("compiler", CppCompilerType.GCC);
|
||||
}
|
||||
|
||||
public async Task Export(AppModel model, UiClient client, string outputPath, Dictionary<string, string> settingsDict)
|
||||
{
|
||||
var settings = new Settings(settingsDict);
|
||||
|
||||
await client.ShowLogMessage($"Building application model for Unity {settings.UnityVersion}/{settings.Compiler}");
|
||||
model.Build(new UnityVersion(settings.UnityVersion), settings.Compiler);
|
||||
|
||||
await client.ShowLogMessage("Generating C++ scaffolding");
|
||||
var scaffolding = new CppScaffolding(model);
|
||||
|
||||
await client.ShowLogMessage("Writing C++ scaffolding");
|
||||
scaffolding.Write(outputPath);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using Il2CppInspector.Cpp;
|
||||
using Il2CppInspector.Cpp.UnityHeaders;
|
||||
using Il2CppInspector.Model;
|
||||
using Il2CppInspector.Outputs;
|
||||
|
||||
namespace Il2CppInspector.Redux.FrontendCore.Outputs;
|
||||
|
||||
public class DisassemblerMetadataOutput : IOutputFormatProvider
|
||||
{
|
||||
public static string Id => "disassemblermetadata";
|
||||
|
||||
private class Settings(Dictionary<string, string> dict)
|
||||
{
|
||||
public readonly DisassemblerType Disassembler = dict.GetAsEnumOrDefault("disassembler", DisassemblerType.IDA);
|
||||
public readonly string UnityVersion = dict.GetValueOrDefault("unityversion", "");
|
||||
}
|
||||
|
||||
public async Task Export(AppModel model, UiClient client, string outputPath, Dictionary<string, string> settingsDict)
|
||||
{
|
||||
var settings = new Settings(settingsDict);
|
||||
|
||||
await client.ShowLogMessage($"Building application model for Unity {settings.UnityVersion}/{CppCompilerType.GCC}");
|
||||
model.Build(new UnityVersion(settings.UnityVersion), CppCompilerType.GCC);
|
||||
|
||||
var headerPath = Path.Join(outputPath, "il2cpp.h");
|
||||
{
|
||||
await client.ShowLogMessage("Generating C++ types");
|
||||
var cppScaffolding = new CppScaffolding(model, useBetterArraySize: true);
|
||||
|
||||
await client.ShowLogMessage("Writing C++ types");
|
||||
cppScaffolding.WriteTypes(headerPath);
|
||||
}
|
||||
|
||||
var metadataPath = Path.Join(outputPath, "il2cpp.json");
|
||||
{
|
||||
await client.ShowLogMessage("Generating disassembler metadata");
|
||||
var jsonMetadata = new JSONMetadata(model);
|
||||
|
||||
await client.ShowLogMessage("Writing disassembler metadata");
|
||||
jsonMetadata.Write(metadataPath);
|
||||
}
|
||||
|
||||
if (settings.Disassembler != DisassemblerType.None)
|
||||
{
|
||||
var scriptPath = Path.Join(outputPath, "il2cpp.py");
|
||||
await client.ShowLogMessage($"Generating python script for {settings.Disassembler}");
|
||||
var script = new PythonScript(model);
|
||||
|
||||
await client.ShowLogMessage($"Writing python script for {settings.Disassembler}");
|
||||
script.WriteScriptToFile(scriptPath, settings.Disassembler.ToString(), headerPath, metadataPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Il2CppInspector.Redux.FrontendCore.Outputs;
|
||||
|
||||
public enum DisassemblerType
|
||||
{
|
||||
IDA,
|
||||
Ghidra,
|
||||
BinaryNinja,
|
||||
None
|
||||
}
|
||||
27
Il2CppInspector.Redux.FrontendCore/Outputs/DummyDllOutput.cs
Normal file
27
Il2CppInspector.Redux.FrontendCore/Outputs/DummyDllOutput.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using Il2CppInspector.Model;
|
||||
using Il2CppInspector.Outputs;
|
||||
|
||||
namespace Il2CppInspector.Redux.FrontendCore.Outputs;
|
||||
|
||||
public class DummyDllOutput : IOutputFormatProvider
|
||||
{
|
||||
public static string Id => "dummydlls";
|
||||
|
||||
private class Settings(Dictionary<string, string> dict)
|
||||
{
|
||||
public readonly bool SuppressMetadata = dict.GetAsBooleanOrDefault("suppressmetadata", false);
|
||||
}
|
||||
|
||||
public async Task Export(AppModel model, UiClient client, string outputPath, Dictionary<string, string> settingsDict)
|
||||
{
|
||||
var outputSettings = new Settings(settingsDict);
|
||||
|
||||
await client.ShowLogMessage("Generating .NET dummy assemblies");
|
||||
var shims = new AssemblyShims(model.TypeModel)
|
||||
{
|
||||
SuppressMetadata = outputSettings.SuppressMetadata
|
||||
};
|
||||
|
||||
shims.Write(outputPath, client.EventHandler);
|
||||
}
|
||||
}
|
||||
14
Il2CppInspector.Redux.FrontendCore/Outputs/IOutputFormat.cs
Normal file
14
Il2CppInspector.Redux.FrontendCore/Outputs/IOutputFormat.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Il2CppInspector.Model;
|
||||
|
||||
namespace Il2CppInspector.Redux.FrontendCore.Outputs;
|
||||
|
||||
public interface IOutputFormat
|
||||
{
|
||||
public Task Export(AppModel model, UiClient client, string outputPath,
|
||||
Dictionary<string, string> settingsDict);
|
||||
}
|
||||
|
||||
public interface IOutputFormatProvider : IOutputFormat
|
||||
{
|
||||
public static abstract string Id { get; }
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
namespace Il2CppInspector.Redux.FrontendCore.Outputs;
|
||||
|
||||
public static class OutputFormatRegistry
|
||||
{
|
||||
public static IEnumerable<string> AvailableOutputFormats => OutputFormats.Keys;
|
||||
|
||||
private static readonly Dictionary<string, IOutputFormat> OutputFormats = [];
|
||||
|
||||
public static void RegisterOutputFormat<T>() where T : IOutputFormatProvider, new()
|
||||
{
|
||||
if (OutputFormats.ContainsKey(T.Id))
|
||||
throw new InvalidOperationException("An output format with this id was already registered.");
|
||||
|
||||
OutputFormats[T.Id] = new T();
|
||||
}
|
||||
|
||||
public static IOutputFormat GetOutputFormat(string id)
|
||||
{
|
||||
if (!OutputFormats.TryGetValue(id, out var format))
|
||||
throw new ArgumentException($"Failed to find output format for id {id}", nameof(id));
|
||||
|
||||
return format;
|
||||
}
|
||||
|
||||
private static void RegisterBuiltinOutputFormats()
|
||||
{
|
||||
RegisterOutputFormat<CSharpStubOutput>();
|
||||
RegisterOutputFormat<VsSolutionOutput>();
|
||||
RegisterOutputFormat<DummyDllOutput>();
|
||||
RegisterOutputFormat<DisassemblerMetadataOutput>();
|
||||
RegisterOutputFormat<CppScaffoldingOutput>();
|
||||
}
|
||||
|
||||
static OutputFormatRegistry()
|
||||
{
|
||||
RegisterBuiltinOutputFormats();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Il2CppInspector.Redux.FrontendCore.Outputs;
|
||||
|
||||
public enum TypeSortingMode
|
||||
{
|
||||
Alphabetical,
|
||||
TypeDefinitionIndex
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using Il2CppInspector.Model;
|
||||
using Il2CppInspector.Outputs;
|
||||
|
||||
namespace Il2CppInspector.Redux.FrontendCore.Outputs;
|
||||
|
||||
public class VsSolutionOutput : IOutputFormatProvider
|
||||
{
|
||||
public static string Id => "vssolution";
|
||||
|
||||
private class Settings(Dictionary<string, string> settings)
|
||||
{
|
||||
public readonly string UnityPath = settings.GetValueOrDefault("unitypath", "");
|
||||
public readonly string UnityAssembliesPath = settings.GetValueOrDefault("unityassembliespath", "");
|
||||
}
|
||||
|
||||
public async Task Export(AppModel model, UiClient client, string outputPath, Dictionary<string, string> settingsDict)
|
||||
{
|
||||
var settings = new Settings(settingsDict);
|
||||
|
||||
var writer = new CSharpCodeStubs(model.TypeModel)
|
||||
{
|
||||
MustCompile = true,
|
||||
SuppressMetadata = true
|
||||
};
|
||||
|
||||
await client.ShowLogMessage("Writing Visual Studio solution");
|
||||
writer.WriteSolution(outputPath, settings.UnityPath, settings.UnityAssembliesPath);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user