dnlib icon indicating copy to clipboard operation
dnlib copied to clipboard

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

Open ElektroKill opened this issue 4 years ago • 2 comments

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

ElektroKill avatar Dec 10 '21 21:12 ElektroKill

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

wtfsck avatar Dec 11 '21 21:12 wtfsck

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.

ElektroKill avatar Dec 11 '21 21:12 ElektroKill