0xd4d / dnlib

Reads and writes .NET assemblies and modules
MIT License
2.16k stars 584 forks source link

Support for writing `StandAloneSig` custom attributes and custom debug info. #432

Open ElektroKill opened 2 years ago

ElektroKill commented 2 years ago

Currently when reading an assembly dnlib reads a StandAloneSig into its respective class which implements IHasCustomAttribute and IHasCustomDebugInformation. However, when dnlib creates a CallingConventionSig from the StandAloneSig the custom attribute and custom debug info information is not passed over and therefore not available in the highest level model. dnlib is also unable to write custom attributes and custom debug info of StandAloneSig as seen here: https://github.com/0xd4d/dnlib/blob/086cda2c737f34b3085f1d30a970e4adfb421ae3/src/DotNet/Writer/Metadata.cs#L2144-L2152 https://github.com/0xd4d/dnlib/blob/086cda2c737f34b3085f1d30a970e4adfb421ae3/src/DotNet/Writer/Metadata.cs#L2161-L2172 https://github.com/0xd4d/dnlib/blob/086cda2c737f34b3085f1d30a970e4adfb421ae3/src/DotNet/Writer/Metadata.cs#L2180-L2191

wtfsck commented 2 years ago

Does any compiler (or other tool) attach CAs or CDIs to StandAloneSig rows?

ElektroKill commented 2 years ago

Hi, To my knowledge Roslyn or other compilers do not emit custom attributes on StandAloneSig (I don’t know about custom debug infos but most likely they aren’t emitted for this table too). However, in theory these attributes could be used to detect tampering of a file by a obfuscator since dnlib would not rewrite them but this is purely hypothetical and I’m yet to see something like this in practice. I haven’t looked much at the signature code but I think this could be achieved in a similar way to how I handled custom attributes and custom debug infos in https://github.com/0xd4d/dnlib/pull/418 except for LocalSig for which the Metadata class accepts a List<Local> instead of LocalSig.