Output: Option to suppress constructs with [CompilerGeneratedAttribute]
This commit is contained in:
@@ -17,6 +17,11 @@ namespace Il2CppInspector
|
||||
// Namespace prefixes whose contents should be skipped
|
||||
public List<string> ExcludedNamespaces { get; set; }
|
||||
|
||||
// Suppress types, fields and methods with the CompilerGenerated attribute; suppress the attribute itself from property getters and setters
|
||||
public bool SuppressGenerated { get; set; }
|
||||
|
||||
private const string CGAttribute = "System.Runtime.CompilerServices.CompilerGeneratedAttribute";
|
||||
|
||||
public Il2CppCSharpDumper(Il2CppModel model) => this.model = model;
|
||||
|
||||
private StreamWriter writer;
|
||||
@@ -49,6 +54,9 @@ namespace Il2CppInspector
|
||||
}
|
||||
|
||||
private void writeType(TypeInfo type, string prefix = "") {
|
||||
// Don't output compiler-generated types if desired
|
||||
if (SuppressGenerated && type.GetCustomAttributes(CGAttribute).Any())
|
||||
return;
|
||||
|
||||
// Only print namespace if we're not nested
|
||||
if (!type.IsNested)
|
||||
@@ -132,6 +140,9 @@ namespace Il2CppInspector
|
||||
writer.Write(prefix + "\t// Fields\n");
|
||||
|
||||
foreach (var field in type.DeclaredFields) {
|
||||
if (SuppressGenerated && field.GetCustomAttributes(CGAttribute).Any())
|
||||
continue;
|
||||
|
||||
if (field.IsNotSerialized)
|
||||
writer.Write(prefix + "\t[NonSerialized]\n");
|
||||
|
||||
@@ -191,8 +202,8 @@ namespace Il2CppInspector
|
||||
|
||||
string modifiers = prop.GetMethod?.GetModifierString() ?? prop.SetMethod.GetModifierString();
|
||||
writer.Write($"{prefix}\t{modifiers}{prop.PropertyType.CSharpName} {prop.Name} {{ ");
|
||||
writer.Write((prop.GetMethod != null ? prop.GetMethod.CustomAttributes.ToString(inline: true) + "get; " : "")
|
||||
+ (prop.SetMethod != null ? prop.SetMethod.CustomAttributes.ToString(inline: true) + "set; " : "") + "}");
|
||||
writer.Write((prop.GetMethod != null ? prop.GetMethod.CustomAttributes.Where(a => !SuppressGenerated || a.AttributeType.FullName != CGAttribute).ToString(inline: true) + "get; " : "")
|
||||
+ (prop.SetMethod != null ? prop.SetMethod.CustomAttributes.Where(a => !SuppressGenerated || a.AttributeType.FullName != CGAttribute).ToString(inline: true) + "set; " : "") + "}");
|
||||
if ((prop.GetMethod != null && prop.GetMethod.VirtualAddress != 0) || (prop.SetMethod != null && prop.SetMethod.VirtualAddress != 0))
|
||||
writer.Write(" // ");
|
||||
writer.Write((prop.GetMethod != null && prop.GetMethod.VirtualAddress != 0 ? Il2CppModel.FormatAddress(prop.GetMethod.VirtualAddress) + " " : "")
|
||||
@@ -255,6 +266,9 @@ namespace Il2CppInspector
|
||||
|
||||
// Don't re-output methods for constructors, properties, events etc.
|
||||
foreach (var method in type.DeclaredMethods.Except(usedMethods)) {
|
||||
if (SuppressGenerated && method.GetCustomAttributes(CGAttribute).Any())
|
||||
continue;
|
||||
|
||||
// Attributes
|
||||
writer.Write(method.CustomAttributes.ToString(prefix + "\t"));
|
||||
// IL2CPP doesn't seem to retain return type attributes
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Il2CppInspector
|
||||
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]
|
||||
// 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]
|
||||
// Defaults to libil2cpp.so or GameAssembly.dll if binary file not specified
|
||||
IConfiguration config = new ConfigurationBuilder().AddCommandLine(args).Build();
|
||||
|
||||
@@ -27,6 +27,8 @@ namespace Il2CppInspector
|
||||
string metaFile = config["metadata"] ?? "global-metadata.dat";
|
||||
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
|
||||
var excludedNamespaces = config["exclude-namespaces"]?.Split(',').ToList() ??
|
||||
@@ -63,7 +65,8 @@ namespace Il2CppInspector
|
||||
var model = new Il2CppModel(il2cpp);
|
||||
|
||||
// C# signatures output
|
||||
new Il2CppCSharpDumper(model) {ExcludedNamespaces = excludedNamespaces}.WriteFile(outCsFile + (i++ > 0 ? "-" + (i-1) : ""));
|
||||
new Il2CppCSharpDumper(model) {ExcludedNamespaces = excludedNamespaces, SuppressGenerated = suppressGenerated}
|
||||
.WriteFile(outCsFile + (i++ > 0 ? "-" + (i-1) : ""));
|
||||
|
||||
// IDA Python script output
|
||||
// TODO: IDA Python script output
|
||||
|
||||
Reference in New Issue
Block a user