dnlib icon indicating copy to clipboard operation
dnlib copied to clipboard

Why does dnlib compare two MemberDef by name?

Open CreateAndInject opened this issue 3 years ago • 2 comments

Why a == b is not enough? image

class Program
{
    int a;
    int b;
}

Rename b to a by dnSpy, then SigCompare will think it's the same field, but it's not in fact.

CreateAndInject avatar Jan 17 '22 18:01 CreateAndInject

It's useful when you open the same assembly but two different versions and need to compare defs. Reference equality is not what you want when comparing types A from both assemblies since they should be considered equal.

However it causes problems like you mentioned above.

This is a breaking change so we could change the default in v4 and add an option to use the old behavior if needed.

wtfsck avatar Jan 18 '22 18:01 wtfsck

SigComparer could also be updated to check if they're in the same module and if so, use reference equality in that case.

wtfsck avatar Jan 18 '22 18:01 wtfsck

@wtfsck This one should be marked as v4, it's important for dnSpy analyzer, since many obfuscators will generate duplicate names.

CreateAndInject avatar Jul 09 '23 21:07 CreateAndInject

PRs welcome!

wtfsck avatar Jul 15 '23 16:07 wtfsck