DLL: Allow suppression of metadata attributes
This commit is contained in:
@@ -85,6 +85,9 @@ namespace Il2CppInspector.CLI
|
|||||||
[Option('n', "suppress-metadata", Required = false, HelpText = "Diff tidying: suppress method pointers, field offsets and type indices from C# output. Useful for comparing two versions of a binary for changes with a diff tool")]
|
[Option('n', "suppress-metadata", Required = false, HelpText = "Diff tidying: suppress method pointers, field offsets and type indices from C# output. Useful for comparing two versions of a binary for changes with a diff tool")]
|
||||||
public bool SuppressMetadata { get; set; }
|
public bool SuppressMetadata { get; set; }
|
||||||
|
|
||||||
|
[Option("suppress-dll-metadata", Required = false, HelpText = "Diff tidying: suppress method pointers, field offsets and type indices attributes from DLL output. Useful for comparing two versions of a binary for changes")]
|
||||||
|
public bool SuppressDllMetadata { get; set; }
|
||||||
|
|
||||||
[Option('k', "must-compile", Required = false, HelpText = "Compilation tidying: try really hard to make code that compiles. Suppress generation of code for items with CompilerGenerated attribute. Comment out attributes without parameterless constructors or all-optional constructor arguments. Don't emit add/remove/raise on events. Specify AttributeTargets.All on classes with AttributeUsage attribute. Force auto-properties to have get accessors. Force regular properties to have bodies. Suppress global::Locale classes. Generate dummy parameterless base constructors and ref return fields.")]
|
[Option('k', "must-compile", Required = false, HelpText = "Compilation tidying: try really hard to make code that compiles. Suppress generation of code for items with CompilerGenerated attribute. Comment out attributes without parameterless constructors or all-optional constructor arguments. Don't emit add/remove/raise on events. Specify AttributeTargets.All on classes with AttributeUsage attribute. Force auto-properties to have get accessors. Force regular properties to have bodies. Suppress global::Locale classes. Generate dummy parameterless base constructors and ref return fields.")]
|
||||||
public bool MustCompile { get; set; }
|
public bool MustCompile { get; set; }
|
||||||
|
|
||||||
@@ -427,7 +430,10 @@ namespace Il2CppInspector.CLI
|
|||||||
|
|
||||||
// DLL output
|
// DLL output
|
||||||
using (new Benchmark("Generate .NET assembly shim DLLs"))
|
using (new Benchmark("Generate .NET assembly shim DLLs"))
|
||||||
new AssemblyShims(model).Write(getOutputPath(options.DllOutPath, "", imageIndex));
|
new AssemblyShims(model) {
|
||||||
|
SuppressMetadata = options.SuppressDllMetadata
|
||||||
|
}
|
||||||
|
.Write(getOutputPath(options.DllOutPath, "", imageIndex));
|
||||||
|
|
||||||
imageIndex++;
|
imageIndex++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,11 @@ namespace Il2CppInspector.Outputs
|
|||||||
// Add custom attribute to item with named property arguments
|
// Add custom attribute to item with named property arguments
|
||||||
// 'module' is the module that owns 'type'; type.Module may still be null when this is called
|
// 'module' is the module that owns 'type'; type.Module may still be null when this is called
|
||||||
public static CustomAttribute AddAttribute(this IHasCustomAttribute def, ModuleDef module, TypeDef attrTypeDef, params (string prop, object value)[] args) {
|
public static CustomAttribute AddAttribute(this IHasCustomAttribute def, ModuleDef module, TypeDef attrTypeDef, params (string prop, object value)[] args) {
|
||||||
|
|
||||||
|
// If SuppressMetadata is set, our own attributes will never be generated so attrTypeDef will be null
|
||||||
|
if (attrTypeDef == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
var attRef = module.Import(attrTypeDef);
|
var attRef = module.Import(attrTypeDef);
|
||||||
var attCtorRef = new MemberRefUser(attrTypeDef.Module, ".ctor", MethodSig.CreateInstance(module.CorLibTypes.Void), attRef);
|
var attCtorRef = new MemberRefUser(attrTypeDef.Module, ".ctor", MethodSig.CreateInstance(module.CorLibTypes.Void), attRef);
|
||||||
|
|
||||||
@@ -53,6 +58,9 @@ namespace Il2CppInspector.Outputs
|
|||||||
// Output module to create .NET DLLs containing type definitions
|
// Output module to create .NET DLLs containing type definitions
|
||||||
public class AssemblyShims
|
public class AssemblyShims
|
||||||
{
|
{
|
||||||
|
// Suppress informational attributes
|
||||||
|
public bool SuppressMetadata { get; set; }
|
||||||
|
|
||||||
// .NET type model
|
// .NET type model
|
||||||
private readonly TypeModel model;
|
private readonly TypeModel model;
|
||||||
|
|
||||||
@@ -502,10 +510,12 @@ namespace Il2CppInspector.Outputs
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate our custom types assembly (relies on mscorlib.dll being added above)
|
// Generate our custom types assembly (relies on mscorlib.dll being added above)
|
||||||
|
if (!SuppressMetadata) {
|
||||||
var baseDll = CreateBaseAssembly();
|
var baseDll = CreateBaseAssembly();
|
||||||
|
|
||||||
// Write base assembly to disk
|
// Write base assembly to disk
|
||||||
baseDll.Write(Path.Combine(outputPath, baseDll.Name));
|
baseDll.Write(Path.Combine(outputPath, baseDll.Name));
|
||||||
|
}
|
||||||
|
|
||||||
// Add assembly custom attribute attributes (must do this after all assemblies are created due to type referencing)
|
// Add assembly custom attribute attributes (must do this after all assemblies are created due to type referencing)
|
||||||
foreach (var asm in model.Assemblies) {
|
foreach (var asm in model.Assemblies) {
|
||||||
|
|||||||
@@ -350,7 +350,8 @@
|
|||||||
|
|
||||||
<!-- Assembly shim DLLs -->
|
<!-- Assembly shim DLLs -->
|
||||||
<RadioButton GroupName="grpOutputType" Name="rdoOutputDll" VerticalContentAlignment="Center" FontSize="18" Foreground="{StaticResource MicrosoftGreen}">.NET assembly shim DLLs</RadioButton>
|
<RadioButton GroupName="grpOutputType" Name="rdoOutputDll" VerticalContentAlignment="Center" FontSize="18" Foreground="{StaticResource MicrosoftGreen}">.NET assembly shim DLLs</RadioButton>
|
||||||
<TextBlock TextWrapping="WrapWithOverflow">No configuration required for assembly shims</TextBlock>
|
|
||||||
|
<CheckBox Name="cbSuppressDllMetadata" Margin="2,10,2,2">Suppress output of all metadata attributes</CheckBox>
|
||||||
|
|
||||||
<Separator Margin="5,15,5,15"/>
|
<Separator Margin="5,15,5,15"/>
|
||||||
|
|
||||||
|
|||||||
@@ -612,11 +612,15 @@ namespace Il2CppInspectorGUI
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var dllOutPath = dllSaveFolderDialog.SelectedPath;
|
var dllOutPath = dllSaveFolderDialog.SelectedPath;
|
||||||
|
var suppressMetadata = cbSuppressDllMetadata.IsChecked == true;
|
||||||
|
|
||||||
areaBusyIndicator.Visibility = Visibility.Visible;
|
areaBusyIndicator.Visibility = Visibility.Visible;
|
||||||
await Task.Run(() => {
|
await Task.Run(() => {
|
||||||
OnStatusUpdate(this, "Generating .NET assembly shim DLLs");
|
OnStatusUpdate(this, "Generating .NET assembly shim DLLs");
|
||||||
new AssemblyShims(model.TypeModel).Write(dllOutPath, OnStatusUpdate);
|
new AssemblyShims(model.TypeModel) {
|
||||||
|
SuppressMetadata = suppressMetadata
|
||||||
|
}
|
||||||
|
.Write(dllOutPath, OnStatusUpdate);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user