DLL: Allow suppression of metadata attributes

This commit is contained in:
Katy Coe
2021-01-12 02:17:23 +01:00
parent 59c095f794
commit fca91ff556
4 changed files with 27 additions and 6 deletions

View File

@@ -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")]
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.")]
public bool MustCompile { get; set; }
@@ -427,7 +430,10 @@ namespace Il2CppInspector.CLI
// DLL output
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++;
}

View File

@@ -36,6 +36,11 @@ namespace Il2CppInspector.Outputs
// 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
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 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
public class AssemblyShims
{
// Suppress informational attributes
public bool SuppressMetadata { get; set; }
// .NET type model
private readonly TypeModel model;
@@ -502,10 +510,12 @@ namespace Il2CppInspector.Outputs
}
// Generate our custom types assembly (relies on mscorlib.dll being added above)
var baseDll = CreateBaseAssembly();
if (!SuppressMetadata) {
var baseDll = CreateBaseAssembly();
// Write base assembly to disk
baseDll.Write(Path.Combine(outputPath, baseDll.Name));
// Write base assembly to disk
baseDll.Write(Path.Combine(outputPath, baseDll.Name));
}
// Add assembly custom attribute attributes (must do this after all assemblies are created due to type referencing)
foreach (var asm in model.Assemblies) {

View File

@@ -350,7 +350,8 @@
<!-- Assembly shim DLLs -->
<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"/>

View File

@@ -612,11 +612,15 @@ namespace Il2CppInspectorGUI
return;
var dllOutPath = dllSaveFolderDialog.SelectedPath;
var suppressMetadata = cbSuppressDllMetadata.IsChecked == true;
areaBusyIndicator.Visibility = Visibility.Visible;
await Task.Run(() => {
OnStatusUpdate(this, "Generating .NET assembly shim DLLs");
new AssemblyShims(model.TypeModel).Write(dllOutPath, OnStatusUpdate);
new AssemblyShims(model.TypeModel) {
SuppressMetadata = suppressMetadata
}
.Write(dllOutPath, OnStatusUpdate);
});
break;
}