You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When removing a typedef from this particular assembly and using the PreserveAll flags it will throw a bunch of MemberNotImportedException exceptions but if that flag is not used it will work as expected and the modified assembly will have the typedef removed
How To Reproduce
To reproduce it, I've managed to create this minimal example for .NET 8.0 console project on windows
staticvoidMain(string[]args){varmodule=ModuleDefinition.FromFile(args[0]);ManagedPEImageBuilderbuilder=new();DotNetDirectoryFactoryfactory=new();builder.DotNetDirectoryFactory=factory;//factory.MetadataBuilderFlags = MetadataBuilderFlags.None; // uncomment this to have it working as expectedfactory.MetadataBuilderFlags=MetadataBuilderFlags.PreserveAll;// uncomment this to trigger the issuevara=module.TopLevelTypes.First(x =>x.Name=="CopyPasteEntityInfo");module.TopLevelTypes.Remove(a);module.Write("out_Rust.Data.dll",builder);}
After building the app drag & drop this provided dll onto the .exe or pass it as the first argument if invoking from a console or a debugger.
For completeness sake, I will provide a working compiled example: CompiledExample.zip (needs .NET 8.0 runtime to run)
Expected Behavior
Save the module without issues
Actual Behavior
Throws:
Unhandledexception. System.AggregateException: Construction of the PE image failed with one or more errors.(MemberProtoBuf.CopyPasteEntityInfo (0x020000E3) was not imported into the module.)(MemberProtoBuf.CopyPasteEntityInfo (0x020000E3) was not imported into the module.)(MemberProtoBuf.CopyPasteEntityInfo (0x020000E3) was not imported into the module.)(MemberProtoBuf.CopyPasteEntityInfo (0x020000E3) was not imported into the module.)---> AsmResolver.DotNet.Builder.Metadata.MemberNotImportedException: Member ProtoBuf.CopyPasteEntityInfo(0x020000E3)wasnotimportedinto the module.---End of inner exception stack trace ---atAsmResolver.DotNet.ModuleDefinition.ToPEImage(IPEImageBuilderimageBuilder,BooleanthrowOnNonFatalError)
at AsmResolver.DotNet.ModuleDefinition.ToPEImage(IPEImageBuilderimageBuilder)
at AsmResolver.DotNet.ModuleDefinition.Write(BinaryStreamWriterwriter,IPEImageBuilderimageBuilder,IPEFileBuilderfileBuilder)
at AsmResolver.DotNet.ModuleDefinition.Write(StreamoutputStream,IPEImageBuilderimageBuilder,IPEFileBuilderfileBuilder)
at AsmResolver.DotNet.ModuleDefinition.Write(StringfilePath,IPEImageBuilderimageBuilder,IPEFileBuilderfileBuilder)
at AsmResolver.DotNet.ModuleDefinition.Write(StringfilePath,IPEImageBuilderimageBuilder)
at Rust.Data_Processor.src.Program.Main(String[]args) in C:\Users\xxtur\Desktop\UKNDev\ukn-anticheat-tools\Rust.Data-Processor\src\Program.cs:line 36---> (Inner Exception #1) AsmResolver.DotNet.Builder.Metadata.MemberNotImportedException:Member ProtoBuf.CopyPasteEntityInfo(0x020000E3)was not imported into the module.<------> (InnerException #2) AsmResolver.DotNet.Builder.Metadata.MemberNotImportedException:Member ProtoBuf.CopyPasteEntityInfo(0x020000E3)was not imported into the module.<------> (InnerException #3) AsmResolver.DotNet.Builder.Metadata.MemberNotImportedException:Member ProtoBuf.CopyPasteEntityInfo(0x020000E3)was not imported into the module.<---
Additional Context
No response
The text was updated successfully, but these errors were encountered:
This is an interesting edge-case that can be reduced to preserving StandAloneSignatures with local variable signatures referencing the removed type.
Removing a type results in this type becoming "unimported" because it is no longer present in the module. However, preserving a standalone signature that still references this type will therefore mean preserving a signature with an invalid reference to a non-existing metadata member:
This issue highlights the asymmetry that exists within what it means to "preserve indices" for different metadata tables. Preserving TypeDef indices preserves RIDs by replacing removed types with inaccessible empty dummy types. Preserving standalone signatures does not replace removed signatures with dummy metadata, but preserves the unreferenced signature as a whole including its contents. This was a conscious decision to make it easier to add "floating" signatures to modules that are not directly referenced by metadata but by code (e.g., using Module::ResolveSignature).
Since we are preserving invalid signatures, should we consider this an error? If so, how should a user deal with this (other than simply ignoring the error)? We also want the user to create invalid .NET modules. Should there be an extra builder flag for this? Should the signature keep referencing the original metadata token (and thus reference the new placeholder type), even if the target type is removed?
AsmResolver Version
6.0.0-beta.1
.NET Version
.NET 8.0
Operating System
Windows
Describe the Bug
When removing a typedef from this particular assembly and using the PreserveAll flags it will throw a bunch of
MemberNotImportedException
exceptions but if that flag is not used it will work as expected and the modified assembly will have the typedef removedHow To Reproduce
To reproduce it, I've managed to create this minimal example for .NET 8.0 console project on windows
After building the app drag & drop this provided dll onto the .exe or pass it as the first argument if invoking from a console or a debugger.
For completeness sake, I will provide a working compiled example:
CompiledExample.zip (needs .NET 8.0 runtime to run)
Expected Behavior
Save the module without issues
Actual Behavior
Throws:
Additional Context
No response
The text was updated successfully, but these errors were encountered: