Can I programmatically calculate a hash of "public" parts of the dll? #2937
-
Hi, I would like to calculate an assembly's footprint - a hash that changes only if "significant" parts of the assembly change, which is mostly when its Reference assemblies would be different. Some assemblies produce Reference assemblies already, so for those I can just check the hash of the ref dll. Can I use
Is there an alternative programmatic tool I could use? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
ILSpy uses System.Reflection.Metadata as the low-level assembly loader. This provides a read-only view into the .dll, no way to modify it. If you want to modify a .dll, remove all method bodies and maybe the private methods, save it to a MemoryStream, and then hash it; then I would recommend using the Mono.Cecil library. If you want the fastest assembly-API-hashing tool possible, and have some flexibility in what exactly you are hashing, then I would recommend using System.Reflection.Metadata with a custom "signature decoder" that directly adds to a hasher. Then, for public classes and methods, write the relevant fields from the SRM structs to your hasher; while "decoding" signature blobs (you can't hash signature blobs directly as they contain metadata tokens which contain row numbers that might get re-numbered whenever another private method/class is added). But this will be significantly more work than the Mono.Cecil solution. |
Beta Was this translation helpful? Give feedback.
ILSpy uses System.Reflection.Metadata as the low-level assembly loader. This provides a read-only view into the .dll, no way to modify it.
At a higher level, ILSpy has its own type system (ICSharpCode.Decompiler.TypeSystem). This again is read-only.
If you want to modify a .dll, remove all method bodies and maybe the private methods, save it to a MemoryStream, and then hash it; then I would recommend using the Mono.Cecil library.
If you want the fastest assembly-API-hashing tool possible, and have some flexibility in what exactly you are hashing, then I would recommend using System.Reflection.Metadata with a custom "signature decoder" that directly adds to a hasher. Then, for public class…