CLI: Switch from Microsoft CommandLine to CommandLineParser
This commit is contained in:
@@ -7,6 +7,13 @@
|
|||||||
<PublishSingleFile>true</PublishSingleFile>
|
<PublishSingleFile>true</PublishSingleFile>
|
||||||
<PublishTrimmed>true</PublishTrimmed>
|
<PublishTrimmed>true</PublishTrimmed>
|
||||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||||
|
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
|
||||||
|
<Version>2.0</Version>
|
||||||
|
<Company>Noisy Cow Studios</Company>
|
||||||
|
<Product>Il2CppInspector</Product>
|
||||||
|
<Copyright>(c) 2017-2019 Katy Coe - www.djkaty.com</Copyright>
|
||||||
|
<PackageId>Il2CppDumper</PackageId>
|
||||||
|
<Authors>Katy Coe</Authors>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -16,7 +23,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="3.0.0" />
|
<PackageReference Include="CommandLineParser" Version="2.6.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -5,57 +5,64 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using CommandLine;
|
||||||
using Il2CppInspector.Reflection;
|
using Il2CppInspector.Reflection;
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
|
|
||||||
namespace Il2CppInspector
|
namespace Il2CppInspector
|
||||||
{
|
{
|
||||||
public class App
|
public class App
|
||||||
{
|
{
|
||||||
static void Main(string[] args) {
|
private class Options
|
||||||
|
{
|
||||||
|
[Option('i', "bin", Required = true, HelpText = "IL2CPP binary file input", Default = "libil2cpp.so")]
|
||||||
|
public string BinaryFile { get; set; }
|
||||||
|
|
||||||
// Banner
|
[Option('m', "metadata", Required = true, HelpText = "IL2CPP metadata file input", Default = "global-metadata.data")]
|
||||||
Console.WriteLine("Il2CppDumper");
|
public string MetadataFile { get; set; }
|
||||||
Console.WriteLine("(c) 2017-2019 Katy Coe - www.djkaty.com");
|
|
||||||
Console.WriteLine("");
|
|
||||||
|
|
||||||
// Command-line usage: dotnet run [--bin=<binary-file>] [--metadata=<metadata-file>] [--cs-out=<output-file>] [--py-out=<output-file>] [--exclude-namespaces=<ns1,n2,...>|none] [--suppress-compiler-generated=false]
|
[Option('c', "cs-out", Required = false, HelpText = "C# output file or path", Default = "types.cs")]
|
||||||
// Defaults to libil2cpp.so or GameAssembly.dll if binary file not specified
|
public string CSharpOutPath { get; set; }
|
||||||
IConfiguration config = new ConfigurationBuilder().AddCommandLine(args).Build();
|
|
||||||
|
|
||||||
string imageFile = config["bin"] ?? "libil2cpp.so";
|
[Option('p', "py-out", Required = false, Hidden = true, HelpText = "IDA Python script output file", Default = "ida.py")]
|
||||||
string metaFile = config["metadata"] ?? "global-metadata.dat";
|
public string PythonOutFile { get; set; }
|
||||||
string outCsFile = config["cs-out"] ?? "types.cs";
|
|
||||||
string outPythonFile = config["py-out"] ?? "ida.py";
|
|
||||||
if (!bool.TryParse(config["suppress-compiler-generated"], out var suppressGenerated))
|
|
||||||
suppressGenerated = true;
|
|
||||||
|
|
||||||
// Exclusions
|
[Option("exclude-namespaces", Required = false, Separator = ',', HelpText = "Comma-separated list of namespaces to suppress in C# output, or 'none' to include all namespaces",
|
||||||
var excludedNamespaces = config["exclude-namespaces"]?.Split(',').ToList() ??
|
Default = new [] {
|
||||||
new List<string> {
|
"System",
|
||||||
"System",
|
"Unity",
|
||||||
"Unity",
|
"UnityEngine",
|
||||||
"UnityEngine",
|
"UnityEngineInternal",
|
||||||
"UnityEngineInternal",
|
"Mono",
|
||||||
"Mono",
|
"Microsoft.Win32",
|
||||||
"Microsoft.Win32",
|
})]
|
||||||
};
|
public IEnumerable<string> ExcludedNamespaces { get; set; }
|
||||||
|
|
||||||
if (excludedNamespaces.Count == 1 && excludedNamespaces[0].ToLower() == "none")
|
[Option("no-suppress-cg", Required = false, HelpText = "Don't suppress C# generation of items with CompilerGenerated attribute", Default = false)]
|
||||||
excludedNamespaces = null;
|
public bool DontSuppressCompilerGenerated { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int Main(string[] args) =>
|
||||||
|
Parser.Default.ParseArguments<Options>(args).MapResult(
|
||||||
|
options => Run(options),
|
||||||
|
_ => 1);
|
||||||
|
|
||||||
|
private static int Run(Options options) {
|
||||||
|
// Check excluded namespaces
|
||||||
|
if (options.ExcludedNamespaces.Count() == 1 && options.ExcludedNamespaces.First().ToLower() == "none")
|
||||||
|
options.ExcludedNamespaces = new List<string>();
|
||||||
|
|
||||||
// Check files
|
// Check files
|
||||||
if (!File.Exists(imageFile)) {
|
if (!File.Exists(options.BinaryFile)) {
|
||||||
Console.Error.WriteLine($"File {imageFile} does not exist");
|
Console.Error.WriteLine($"File {options.BinaryFile} does not exist");
|
||||||
Environment.Exit(1);
|
return 1;
|
||||||
}
|
}
|
||||||
if (!File.Exists(metaFile)) {
|
if (!File.Exists(options.MetadataFile)) {
|
||||||
Console.Error.WriteLine($"File {metaFile} does not exist");
|
Console.Error.WriteLine($"File {options.MetadataFile} does not exist");
|
||||||
Environment.Exit(1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Analyze data
|
// Analyze data
|
||||||
var il2cppInspectors = Il2CppInspector.LoadFromFile(imageFile, metaFile);
|
var il2cppInspectors = Il2CppInspector.LoadFromFile(options.BinaryFile, options.MetadataFile);
|
||||||
if (il2cppInspectors == null)
|
if (il2cppInspectors == null)
|
||||||
Environment.Exit(1);
|
Environment.Exit(1);
|
||||||
|
|
||||||
@@ -66,12 +73,15 @@ namespace Il2CppInspector
|
|||||||
var model = new Il2CppModel(il2cpp);
|
var model = new Il2CppModel(il2cpp);
|
||||||
|
|
||||||
// C# signatures output
|
// C# signatures output
|
||||||
new Il2CppCSharpDumper(model) {ExcludedNamespaces = excludedNamespaces, SuppressGenerated = suppressGenerated}
|
new Il2CppCSharpDumper(model) {ExcludedNamespaces = options.ExcludedNamespaces.ToList(), SuppressGenerated = !options.DontSuppressCompilerGenerated}
|
||||||
.WriteSingleFile(outCsFile + (i++ > 0 ? "-" + (i-1) : ""));
|
.WriteSingleFile(options.CSharpOutPath + (i++ > 0 ? "-" + (i-1) : ""));
|
||||||
|
|
||||||
// IDA Python script output
|
// IDA Python script output
|
||||||
// TODO: IDA Python script output
|
// TODO: IDA Python script output
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Success exit code
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user