PeNet
PeNet copied to clipboard
TypeRefHash Questions/Inconsistencies
While attempting to review and leverage the TypeRefHash, we came across a few issues we would like to bring up and hopefully resolve through discussion/implementation:
- Could you explicitly state the sort order in the definition of
TypeRefHash? It seems the sort order is the default C# sort order, which may cause some problems as stated in subsequent bullets: - Since the C# default sort order is leveraged, the generated
TypeRefHashmay change based upon locality/language. For example, if the default language setting for a user is French, the generatedTypeRefHashmay be different than if the default language setting is English. - The C# default sort order treats some characters differently than, say, Python. Having a sorter which is language agnostic will better enable portability and implementation in other languages/environments.
- The sort order is case-insensitive, while the hash is case-sensitive. The
TypeRefHashcan be defeated by altering the case of some of the strings. In comparison, anImportHashconverts all names to lower-case before both comparing and hashing.
Hi @ddash-ct the topic came up a few times already. It is definitely a design flaw that we haven't on our minds when we created the TRH.
As far as I can see, the best would be to bring out a TRH 2.0, with a defined sort order that is easy to port to other languages.
For the case argument, I'm not sure if that is an issue, as .NET TypeRefs are case-sensitive as well, e.g. System.Text.Json is not the same as system.Text.Json. In that case it differs from the PE import table. If I'm wrong on that, please let me know.
I'll discuss the problem with the co-creators of the hash. As it is a breaking change, we need some time to figure out how to do it without creating too much friction.