Peverify.exe (PEVerify 工具)Peverify.exe (PEVerify Tool)

PEVerify 工具可以協助像是編譯器撰寫者、指令碼引擎開發人員等產生 Microsoft Intermediate Language (MSIL) 的開發人員,判斷其 MSIL 程式碼和相關聯的中繼資料是否符合類型安全需求。The PEVerify tool helps developers who generate Microsoft intermediate language (MSIL) (such as compiler writers, script engine developers, and so on) to determine whether their MSIL code and associated metadata meet type safety requirements. 只有在避免使用某些語言建構時,某些編譯器才會產生可驗證的類型安全程式碼。Some compilers generate verifiably type-safe code only if you avoid using certain language constructs. 如果您是使用這類編譯器的開發人員,可能會想要驗證您並未損及程式碼的類型安全。If, as a developer, you are using such a compiler, you may want to verify that you have not compromised the type safety of your code. 在這種情況下,您可以在檔案上執行 PEVerify 工具來檢查 MSIL 和中繼資料。In this situation, you can run the PEVerify tool on your files to check the MSIL and metadata.

此工具會自動與 Visual Studio 一起安裝。This tool is automatically installed with Visual Studio. 若要執行這項工具,請使用 [Visual Studio 開發人員命令提示字元] (或 Windows 7 中的 [Visual Studio 命令提示字元])。To run the tool, use the Developer Command Prompt for Visual Studio (or the Visual Studio Command Prompt in Windows 7). 如需詳細資訊,請參閱命令提示字元For more information, see Command Prompts.

在命令提示字元下輸入下列命令:At the command prompt, type the following:

語法Syntax

peverify filename [options]  

參數Parameters

引數Argument 說明Description
filenamefilename 要檢查其 MSIL 和中繼資料的可攜式執行檔 (PE)。The portable executable (PE) file for which to check the MSIL and metadata.
選項Option 描述Description
/break= maxErrorCount/break= maxErrorCount 發生 maxErrorCount 錯誤之後中止驗證。Aborts verification after maxErrorCount errors.

.NET Framework 2.0 (含) 以後版本不支援此參數。This parameter is not supported in .NET Framework version 2.0 or later.
/clock/clock 以毫秒為單位測量並報告下列驗證時間:Measures and reports the following verification times in milliseconds:

MD Val. cycleMD Val. cycle
中繼資料驗證週期Metadata validation cycle

MD Val. pureMD Val. pure
單純中繼資料驗證Metadata validation pure

IL Ver. cycleIL Ver. cycle
Microsoft Intermediate Language (MSIL) 驗證週期Microsoft intermediate language (MSIL) verification cycle

IL Ver pureIL Ver pure
單純 MSIL 驗證MSIL verification pure

MD Val. cycleIL Ver. cycle 時間包括了執行必要的啟始和關閉程序所需的時間。The MD Val. cycle and IL Ver. cycle times include the time required to perform necessary startup and shutdown procedures. MD Val. pureIL Ver pure 時間則是反映純粹執行驗證所需的時間。The MD Val. pure and IL Ver pure times reflect the time required to perform the validation or verification only.
/help/help 顯示工具的命令語法和選項。Displays command syntax and options for the tool.
/hresult/hresult 以十六進位格式顯示錯誤碼。Displays error codes in hexadecimal format.
/ignore= hex.code [, hex.code]/ignore= hex.code [, hex.code] 忽略指定的錯誤碼。Ignores the specified error codes.
/ignore=@ responseFile/ignore=@ responseFile 忽略指定的回應檔中列出的錯誤碼。Ignores the error codes listed in the specified response file.
/il/il 針對 filename 所指定組件中實作的方法,執行 MSIL 型別安全驗證檢查。Performs MSIL type safety verification checks for methods implemented in the assembly specified by filename. 除非您指定 /quiet 選項,否則此工具會針對每個找到的問題傳回詳細描述。The tool returns detailed descriptions for each problem found unless you specify the /quiet option.
/md/md filename 所指定的組件上,執行中繼資料驗證檢查。Performs metadata validation checks on the assembly specified by filename. 這會逐步檢查檔案內的所有中繼資料結構,並報告遇到的所有驗證問題。This walks the full metadata structure within the file and reports all validation problems encountered.
/nologo/nologo 不顯示產品版本和著作權資訊。Suppresses the display of product version and copyright information.
/nosymbols/nosymbols 在 .NET Framework 2.0 版中,隱藏回溯相容性的行號。In the .NET Framework version 2.0, suppresses line numbers for backward compatibility.
/quiet/quiet 指定無訊息模式,隱藏驗證問題報告的輸出。Specifies quiet mode; suppresses output of the verification problem reports. Peverify.exe 仍會報告檔案是否為類型安全,但不會報告阻礙類型安全驗證之問題的資訊。Peverify.exe still reports whether the file is type safe, but does not report information on problems preventing type safety verification.
/transparent 只驗證透明方法。Verify only the transparent methods.
/unique/unique 忽略重複的錯誤碼。Ignores repeating error codes.
/verbose/verbose 在 .NET Framework 2.0 版中,使用 MSIL 驗證訊息顯示其他資訊。In the .NET Framework version 2.0, displays additional information in MSIL verification messages.
/?/? 顯示工具的命令語法和選項。Displays command syntax and options for the tool.

備註Remarks

通用語言執行平台透過以類型安全的方式執行應用程式程式碼,協助強制執行安全性和隔離機制。The common language runtime relies on the type-safe execution of application code to help enforce security and isolation mechanisms. 正常情況下,不是可驗證型別安全的程式碼無法執行,但是您可以設定安全性原則,讓受信任但無法驗證的程式碼執行。Normally, code that is not verifiably type safe cannot run, although you can set security policy to allow the execution of trusted but unverifiable code.

如果 /md/il 兩個選項都未指定,則 Peverify.exe 會執行這兩種檢查。If neither the /md nor /il options are specified, Peverify.exe performs both types of checks. Peverify.exe 會先執行 /md 檢查。Peverify.exe performs /md checks first. 如果沒有任何錯誤,則會執行 /il 檢查。If there are no errors, /il checks are made. 如果您同時指定 /md/il,則即使中繼資料有錯誤,還是會執行 /il 檢查。If you specify both /md and /il, /il checks are made even if there are errors in the metadata. 因此,如果中繼資料沒有錯誤,peverify filename 就相當於 peverify filename /md /ilThus, if there are no metadata errors, peverify filename is equivalent to peverify filename /md /il.

Peverify.exe 會依據資料流分析加上有效的中繼資料上數百項規則的清單,執行全面性的 MSIL 驗證檢查。Peverify.exe performs comprehensive MSIL verification checks based on dataflow analysis plus a list of several hundred rules on valid metadata. 如需 Peverify.exe 所執行檢查的詳細資訊,請參閱 Windows SDK 的 [Tools Developers Guide] 資料夾中的「中繼資料驗證規格」與「MSIL 指令集規格」。For detailed information on the checks Peverify.exe performs, see the "Metadata Validation Specification" and the "MSIL Instruction Set Specification" in the Tools Developers Guide folder in the Windows SDK.

請注意,.NET Framework 2.0 版 (含) 以後版本支援傳回使用下列 MSIL 指令指定的可驗證 byrefdupldsfldaldfldaldelemacallunboxNote that the .NET Framework version 2.0 or later supports verifiable byref returns specified using the following MSIL instructions: dup, ldsflda, ldflda, ldelema, call and unbox.

範例Examples

下列命令會對 myAssembly.exe 組件中實作的方法,執行中繼資料驗證檢查和 MSIL 類型安全驗證檢查。The following command performs metadata validation checks and MSIL type safety verification checks for methods implemented in the assembly myAssembly.exe.

peverify myAssembly.exe /md /il  

成功完成上述要求之後,Peverify.exe 會顯示下列訊息。Upon successful completion of the above request, Peverify.exe displays the following message.

All classes and methods in myAssembly.exe Verified  

下列命令會對 myAssembly.exe 組件中實作的方法,執行中繼資料驗證檢查和 MSIL 類型安全驗證檢查。The following command performs metadata validation checks and MSIL type safety verification checks for methods implemented in the assembly myAssembly.exe. 工具會顯示執行這些檢查所需的時間。The tool displays the time required to perform these checks.

peverify myAssembly.exe /md /il /clock  

成功完成上述要求之後,Peverify.exe 會顯示下列訊息。Upon successful completion of the above request, Peverify.exe displays the following message.

All classes and methods in myAssembly.exe Verified  
Timing: Total run     320 msec  
        MD Val.cycle  40 msec  
        MD Val.pure   10 msec  
        IL Ver.cycle  270 msec  
        IL Ver.pure   230 msec  

下列命令會對 myAssembly.exe 組件中實作的方法,執行中繼資料驗證檢查和 MSIL 類型安全驗證檢查。The following command performs metadata validation checks and MSIL type safety verification checks for methods implemented in the assembly myAssembly.exe. 不過,Peverify.exe 會在達到最大錯誤計數 100 時停止。Peverify.exe stops, however, when it reaches the maximum error count of 100. 工具也會忽略指定的錯誤碼。The tool also ignores the specified error codes.

peverify myAssembly.exe /break=100 /ignore=0x12345678,0xABCD1234  

下列命令會產生與上面的前一個範例相同的結果,但是會指定回應檔 ignoreErrors.rsp 中要忽略的錯誤碼。The following command produces the same result as the above previous example, but specifies the error codes to ignore in the response file ignoreErrors.rsp.

peverify myAssembly.exe /break=100 /ignore@ignoreErrors.rsp  

回應檔可包含逗號分隔的錯誤碼清單。The response file can contain a comma-separated list of error codes.

0x12345678, 0xABCD1234  

或者,回應檔可以透過每行一個錯誤碼的方式格式化。Alternatively, the response file can be formatted with one error code per line.

0x12345678  
0xABCD1234  

另請參閱See also