11using System ;
22using System . Buffers . Binary ;
33using System . Collections . Generic ;
4- using System . Collections . Immutable ;
54using System . Linq ;
65using System . Reflection ;
76using System . Reflection . Metadata ;
87using System . Reflection . Metadata . Ecma335 ;
9- using System . Reflection . PortableExecutable ;
108using System . Security . Cryptography ;
119using System . Text ;
12- using System . Threading . Tasks ;
1310
1411using ICSharpCode . Decompiler . TypeSystem ;
1512using ICSharpCode . Decompiler . TypeSystem . Implementation ;
@@ -21,33 +18,11 @@ namespace ICSharpCode.Decompiler.Metadata
2118{
2219 public static class MetadataExtensions
2320 {
24- static HashAlgorithm GetHashAlgorithm ( this MetadataReader reader )
25- {
26- switch ( reader . GetAssemblyDefinition ( ) . HashAlgorithm )
27- {
28- case AssemblyHashAlgorithm . None :
29- // only for multi-module assemblies?
30- return SHA1 . Create ( ) ;
31- case AssemblyHashAlgorithm . MD5 :
32- return MD5 . Create ( ) ;
33- case AssemblyHashAlgorithm . Sha1 :
34- return SHA1 . Create ( ) ;
35- case AssemblyHashAlgorithm . Sha256 :
36- return SHA256 . Create ( ) ;
37- case AssemblyHashAlgorithm . Sha384 :
38- return SHA384 . Create ( ) ;
39- case AssemblyHashAlgorithm . Sha512 :
40- return SHA512 . Create ( ) ;
41- default :
42- return SHA1 . Create ( ) ; // default?
43- }
44- }
45-
4621 static string CalculatePublicKeyToken ( BlobHandle blob , MetadataReader reader )
4722 {
4823 // Calculate public key token:
49- // 1. hash the public key using the appropriate algorithm .
50- byte [ ] publicKeyTokenBytes = reader . GetHashAlgorithm ( ) . ComputeHash ( reader . GetBlobBytes ( blob ) ) ;
24+ // 1. hash the public key (always use SHA1) .
25+ byte [ ] publicKeyTokenBytes = SHA1 . Create ( ) . ComputeHash ( reader . GetBlobBytes ( blob ) ) ;
5126 // 2. take the last 8 bytes
5227 // 3. according to Cecil we need to reverse them, other sources did not mention this.
5328 return publicKeyTokenBytes . TakeLast ( 8 ) . Reverse ( ) . ToHexString ( 8 ) ;
0 commit comments