0

为什么 CLR 不检查链接到强命名 dll 的网络模块的哈希值?

现在整个故事..

有两个独立的 C# 源文件 simple.cs 和 complex.cs 被编译成两个 netmodules

csc /target:module complex.cs
csc /target:module simple.cs

然后链接到强命名的 math.dll

al /target:library /keyfile:keyfile.snk /out:math.dll /version:0.0.0.0 
complex.netmodule simple.netmodule

keyfile.snk 之前已通过运行创建:

sn /k keyfile.snk

检查 math.dll 清单中对应于 complex.netmodule 和 simple.netmodule 的哈希值:

.file complex.netmodule
.hash = (D2 B4 1D 11 B1 50 C2 29 01 91 49 10 2C 28 91 45   // .....P.)..I.,(.E
         24 44 A3 B5 )                                     // $D..
.file simple.netmodule
.hash = (29 85 33 28 35 94 03 32 68 E4 30 B6 02 42 B2 8F   // ).3(5..2h.0..B..
         E8 0B A8 8F ) 

构建客户端 exe:

csc /target:exe /reference:math.dll mathclient.cs

运行 mathclient.exe 和输出:

2+2=4 3 平方=9

然后修改complex.cs并重新编译。在这里,我了解 complex.netmodule 的哈希值应更改。

再次运行 mathclient 并期望抛出异常,因为新 complex.netmodule 的哈希值与 math.dll 清单中的哈希值不匹配。然而结果是

2+2=2 3 平方=10

因此,使用了新版本的 complex.netmodule。

知道为什么 CLR 没有对包含的网络模块执行哈希验证吗?

4

1 回答 1

0

出于性能原因。如果必须计算所有二进制文件的哈希,加载应用程序将花费太长时间。

于 2013-10-10T20:25:47.093 回答