我有一点自定义IL我写,它不会通过PEVerify。我得到的错误是为什么.Net IL无法验证?
$ peverify foo.exe Microsoft (R) .NET Framework PE Verifier. Version 4.0.30319.17929 Copyright (c) Microsoft Corporation. All rights reserved. [IL]: Error: [Z:\virtualbox_shared\foo.exe : HelloWorld.Program::Main][offset 0x00000021] Stack height at all points must be determinable in a single forward scan of IL. 1 Error(s) Verifying foo.exe
该程序将运行良好,没有任何例外。下面是相关方法的IL:
.method private static hidebysig
default void Main (string[] args) cil managed
{
// Method begins at RVA 0x2050
.entrypoint
// Code size 54 (0x36)
.maxstack 2
//custom IL
ldc.i4 1
ldc.i4 1
ceq
switch(first, second)
first:
ldc.i4 1
br.s temp
popit: pop
br.s second
temp: ldc.i4 1
brfalse temp2
temp2: br.s popit
second:
ldc.i4 2
pop
ret
} // end of method Program::Main
完整的源代码在pastebin
为什么会出现这个错误?
我不完全理解其中的逻辑,但看起来涉及到1.7.5反向分支约束上(http://books.google.com/books?id=50PhgS8vjhwC&pg=PA500&lpg=PA500&dq=1.7.5+Backward+ Branch + Constraints&source = bl&ots = vZJvWiy5mP&sig = SGz2IS1A4ynarLdB5aMg2ZGQ16g&hl = en&sa = X&ei = b5KaUOzZNuHWiwK87IGgCw&ved = 0CFYQ6AEwBQ#v = onepage&q&f = false) – Prescott
@Prescott我真的没有把这看作是在这里应用。查看通过验证的[this](http://pastebin.com/YSPY5szf)代码(特别是IL_0018标签) – Earlz