Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ElektroKill opened this issue Dec 10, 2021 · 2 comments
Milestone

Comments

@ElektroKill
Copy link
Contributor

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:

public virtual MDToken GetToken(IList<TypeSig> locals, uint origToken) {
if (locals is null || locals.Count == 0)
return new MDToken((Table)0, 0);
var row = new RawStandAloneSigRow(GetSignature(new LocalSig(locals, false)));
uint rid = tablesHeap.StandAloneSigTable.Add(row);
//TODO: Add custom attributes
//TODO: Add custom debug infos
return new MDToken(Table.StandAloneSig, rid);

protected virtual uint AddStandAloneSig(MethodSig methodSig, uint origToken) {
if (methodSig is null) {
Error("StandAloneSig: MethodSig is null");
return 0;
}
var row = new RawStandAloneSigRow(GetSignature(methodSig));
uint rid = tablesHeap.StandAloneSigTable.Add(row);
//TODO: Add custom attributes
//TODO: Add custom debug infos
return rid;
}

protected virtual uint AddStandAloneSig(FieldSig fieldSig, uint origToken) {
if (fieldSig is null) {
Error("StandAloneSig: FieldSig is null");
return 0;
}
var row = new RawStandAloneSigRow(GetSignature(fieldSig));
uint rid = tablesHeap.StandAloneSigTable.Add(row);
//TODO: Add custom attributes
//TODO: Add custom debug infos
return rid;
}

@wtfsck
Copy link
Contributor

wtfsck commented Dec 11, 2021

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

@ElektroKill
Copy link
Contributor Author

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 #418 except for LocalSig for which the Metadata class accepts a List<Local> instead of LocalSig.

@wtfsck wtfsck added this to the v4 milestone Dec 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants