Ildasm.exe (IL 反組譯工具)Ildasm.exe (IL Disassembler)

IL 反組譯工具是 IL 組譯工具 (Ilasm.exe) 的附屬工具。The IL Disassembler is a companion tool to the IL Assembler (Ilasm.exe). Ildasm.exe 採用包含中繼語言 (IL) 程式碼的可攜式執行檔 (PE),並建立適合用作 Ilasm.exe 輸入的文字檔。Ildasm.exe takes a portable executable (PE) file that contains intermediate language (IL) code and creates a text file suitable as input to Ilasm.exe.

此工具會自動與 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:


ildasm [options] [PEfilename] [options]


下列選項可用於 .exe.dll.obj.lib.winmd 檔案。The following options are available for .exe, .dll, .obj, .lib, and .winmd files.

選項Option 描述Description
/out= filename/out= filename 建立具有指定 filename 的輸出檔案,而不是在圖形化使用者介面中顯示結果。Creates an output file with the specified filename, rather than displaying the results in a graphical user interface.
/rtf/rtf 產生 Rich Text Format (RTF) 格式的輸出。Produces output in rich text format. 使用 /text 選項時無效。Invalid with the /text option.
/text/text 在主控台視窗中顯示結果,而不是在圖形化使用者介面中顯示或做為輸出檔。Displays the results to the console window, rather than in a graphical user interface or as an output file.
/html/html 產生 HTML 格式的輸出。Produces output in HTML format. 使用 /output 選項時才有效。Valid with the /output option only.
/?/? 顯示工具的命令語法和選項。Displays the command syntax and options for the tool.

下列其他選項可用於 .exe.dll.winmd 檔案。The following additional options are available for .exe, .dll, and .winmd files.

選項Option 描述Description
/bytes/bytes 顯示十六進位格式的實際位元組做為指令註解。Shows actual bytes, in hexadecimal format, as instruction comments.
/caverbal/caverbal 以動詞化格式產生自訂屬性 BLOB。Produces custom attribute blobs in verbal form. 預設為二進位格式。The default is binary form.
/linenum/linenum 包含原始程式行的參考。Includes references to original source lines.
/nobar/nobar 隱藏反組譯碼進度指示器快顯視窗。Suppresses the disassembly progress indicator pop-up window.
/noca/noca 隱藏自訂屬性的輸出。Suppresses the output of custom attributes.
/project/project 以對受控程式碼顯示的方式顯示中繼資料,而不採用在原生 Windows 執行階段中顯示的方式。Displays metadata the way it appears to managed code, instead of the way it appears in the native Windows Runtime. 如果 PEfilename 不是 Windows 中繼資料 ( .winmd) 檔案,這個選項就沒有任何作用。If PEfilename is not a Windows metadata (.winmd) file, this option has no effect. 請參閱適用於 Windows 市集應用程式和 Windows 執行階段的 .NET Framework 支援See .NET Framework Support for Windows Store Apps and Windows Runtime.
/pubonly/pubonly 僅反組譯公用類型和成員。Disassembles only public types and members. 相當於 /visibility:PUBEquivalent to /visibility:PUB.
/quoteallnames/quoteallnames 將所有名稱包含在單引號內。Includes all names in single quotes.
/raweh/raweh 以未經處理格式顯示例外狀況處理子句。Shows exception handling clauses in raw form.
/source/source 將原來的原始程式行顯示成註解。Shows original source lines as comments.
/tokens/tokens 顯示類別和成員的中繼資料語彙基元。Shows metadata tokens of classes and members.
/visibility: vis[+vis...]/visibility: vis[+vis...] 僅反組譯具有所指定可視性的類型或成員。Disassembles only types or members with the specified visibility. 以下是 vis 的有效值:The following are valid values for vis:

PUB:公開PUB — Public

PRI:私用PRI — Private

FAM:家族FAM — Family

ASM:組件ASM — Assembly

FAA:家族和組件FAA — Family and Assembly

FOA:家族或組件FOA — Family or Assembly

PSC:私用範圍PSC — Private Scope

如需這些可視性修飾詞的定義,請參閱 MethodAttributesTypeAttributesFor definitions of these visibility modifiers, see MethodAttributes and TypeAttributes.

下列選項只對檔案或主控台輸出的 .exe.dll.winmd 檔案有效。The following options are valid for .exe, .dll, and .winmd files for file or console output only.

選項Option 描述Description
/all/all 指定 /header/bytes/stats/classlist/tokens 選項的組合。Specifies a combination of the /header, /bytes, /stats, /classlist, and /tokens options.
/classlist/classlist 包括模組中定義的類別清單。Includes a list of classes defined in the module.
/forward/forward 使用 forward 類別宣告。Uses forward class declaration.
/headers/headers 在輸出中包含檔案標頭資訊。Includes file header information in the output.
/item: class[ :: member[(sig]]/item: class[:: member[(sig]] 根據提供的引數反組譯下列項目:Disassembles the following depending upon the argument supplied:

- 反組譯指定的 class- Disassembles the specified class.
- 反組譯 class 的指定 member- Disassembles the specified member of the class.
- 以指定的簽章 sig 反組譯 classmember- Disassembles the member of the class with the specified signature sig. sig 的格式為:The format of sig is:
[instance] returnType(parameterType1, parameterType2, …, parameterTypeN)[instance] returnType(parameterType1, parameterType2, …, parameterTypeN)
注意:在 .NET Framework 1.0 和 1.1 版中,sig 後面必須接著右括號:(sig)Note In the .NET Framework versions 1.0 and 1.1, sig must be followed by a closing parenthesis: (sig). 從 Net Framework 2.0 開始,必須省略右括號:(sigStarting with the Net Framework 2.0 the closing parenthesis must be omitted: (sig.
/noil/noil 隱藏 IL 組件的程式碼輸出。Suppresses IL assembly code output.
/stats/stats 包含影像中的統計資料。Includes statistics on the image.
/typelist/typelist 產生完整的類型清單,以便在反覆存取時保留類型順序。Produces the full list of types, to preserve type ordering in a round trip.
/unicode/unicode 使用 Unicode 編碼輸出。Uses Unicode encoding for the output.
/utf8/utf8 使用 UTF-8 編碼輸出。Uses UTF-8 encoding for the output. 預設值為 ANSI。ANSI is the default.

下列選項只對檔案或主控台輸出的 .exe.dll.obj.lib.winmd 檔案有效。The following options are valid for .exe, .dll, .obj, .lib, and .winmd files for file or console output only.

選項Option 描述Description
/metadata[=specifier]/metadata[=specifier] 顯示中繼資料,其中 specifier 是:Shows metadata, where specifier is:

MDHEADER:顯示中繼資料的標頭資訊和大小。MDHEADER — Show the metadata header information and sizes.

HEX:使用十六進位和文字顯示資訊。HEX — Show information in hex as well as in words.

CSV:顯示記錄計數和堆積大小。CSV — Show the record counts and heap sizes.

UNREX:顯示無法解析的外部符號。UNREX — Show unresolved externals.

SCHEMA:顯示中繼資料的標頭和結構描述資訊。SCHEMA — Show the metadata header and schema information.

RAW:顯示原始中繼資料表。RAW — Show the raw metadata tables.

HEAPS:顯示原始的堆積。HEAPS — Show the raw heaps.

VALIDATE:驗證中繼資料的一致性。VALIDATE — Validate the consistency of the metadata.

您可以多次指定 /metadata,每次使用不同的 specifier 值。You can specify /metadata multiple times, with different values for specifier.

下列選項只對檔案或主控台輸出的 .lib 檔案有效。The following options are valid for .lib files for file or console output only.

選項Option 描述Description
/objectfile=filename/objectfile=filename 顯示所指定程式庫中單一物件檔案的中繼資料。Shows the metadata of a single object file in the specified library.


Ildasm.exe 的所有選項都不區分大小寫,並以前三個字母來辨識。All options for Ildasm.exe are case-insensitive and recognized by the first three letters. 例如, /quo 相當於 /quoteallnamesFor example, /quo is equivalent to /quoteallnames. 指定引數的選項可以接受冒號 (:) 或等號 (=) 做為選項與引數之間的分隔符號。Options that specify arguments accept either a colon (:) or an equal sign (=) as the separator between the option and the argument. 例如, /output: <檔案名稱> 相當於 /output= <檔案名稱>。For example, /output: filename is equivalent to /output= filename.


Ildasm.exe 只在磁碟上的 PE 檔上作業。Ildasm.exe only operates on PE files on disk. 它無法在安裝於全域組件快取中的檔案上作業。It does not operate on files installed in the global assembly cache.

Ildasm.exe 所產生的文字檔可以用作 IL 組譯工具 (Ilasm.exe) 的輸入。The text file produced by Ildasm.exe can be used as input to the IL Assembler (Ilasm.exe). 這非常有用,例如在不支援所有執行階段中繼資料屬性的程式語言中編譯程式碼時。This is useful, for example, when compiling code in a programming language that does not support all the runtime metadata attributes. 編譯完程式碼並透過 Ildasm.exe 執行其輸出後,可以手動編輯產生的 IL 文字檔來新增遺漏的屬性。After compiling the code and running its output through Ildasm.exe, the resulting IL text file can be hand-edited to add the missing attributes. 然後可以透過 IL 組譯工具執行這個文字檔來產生最後的可執行檔。You can then run this text file through the IL Assembler to produce a final executable file.


目前您無法將這項技術用於包含內嵌機器碼的 PE 檔 (例如,由 Visual C++ 所產生的 PE 檔)。Currently, you cannot use this technique with PE files that contain embedded native code (for example, PE files produced by Visual C++).

您可以使用 IL 反組譯工具中的預設 GUI,檢視階層樹狀檢視中任何現有 PE 檔的中繼資料和反組譯碼。You can use the default GUI in the IL Disassembler to view the metadata and disassembled code of any existing PE file in a hierarchical tree view. 若要使用 GUI,請在命令列鍵入 ildasm,但不提供 PEfilename 引數或任何選項。To use the GUI, type ildasm at the command line without supplying the PEfilename argument or any options. 您可以從 [檔案] 功能表巡覽至要載入 Ildasm.exe 中的 PE 檔。From the File menu, you can navigate to the PE file that you want to load into Ildasm.exe. 若要儲存針對所選取 PE 顯示的中繼資料和反組譯程式碼,請選取 [檔案] 功能表中的 [傾印] 命令。To save the metadata and disassembled code displayed for the selected PE, select the Dump command from the File menu. 若只要儲存階層樹狀檢閱,請從 [檔案] 功能表中選取 [傾印樹狀檢視] 命令。To save the hierarchical tree view only, select the Dump Treeview command from the File menu. 如需將檔案載入 Ildasm.exe 及解譯輸出的詳細指南,請參閱位於 Windows SDK 隨附 [Samples] 資料夾中的 Ildasm.exe 教學課程。For a detailed guide to loading a file into Ildasm.exe and interpreting the output, see the Ildasm.exe Tutorial, located in the Samples folder that ships with the Windows SDK.

如果您將包含內嵌資源的 PEfilename 引數提供給 Ildasm.exe,這個工具就會產生多個輸出檔案:包含 IL 程式碼的文字檔;每個內嵌的 Managed 資源還會各有一個使用來自中繼資料的資源名稱所產生的 .resources 檔案。If you provide Ildasm.exe with a PEfilename argument that contains embedded resources, the tool produces multiple output files: a text file that contains IL code and, for each embedded managed resource, a .resources file produced using the resource's name from metadata. 如果 Unmanaged 資源內嵌於 PEfilename/output 選項就會使用為 IL 指定的檔案名稱來產生 .res 檔案。If an unmanaged resource is embedded in PEfilename, a .res file is produced using the filename specified for IL output by the /output option.


Ildasm.exe 僅會顯示 .obj.lib 輸入檔的中繼資料描述。Ildasm.exe shows only metadata descriptions for .obj and .lib input files. 這些檔案類型的 IL 程式碼不會進行反組譯。IL code for these file types is not disassembled.

您可以對 .exe 或 .dll 檔案執行 Ildasm.exe 來判斷該檔案是否為 Managed。You can run Ildasm.exe over an.exe or .dll file to determine whether the file is managed. 如果檔案不是 Managed,工具便會顯示一則訊息,說明該檔案沒有有效的通用語言執行平台標頭而且無法進行反組譯。If the file is not managed, the tool displays a message stating that the file has no valid common language runtime header and cannot be disassembled. 如果檔案是 Managed,工具就會成功執行。If the file is managed, the tool runs successfully.

版本資訊Version Information

從 .NET Framework 4.5 開始,Ildasm.exe 會藉由顯示原始二進位內容來處理無法辨認的封送處理 BLOB (二進位大型物件)。Starting with the .NET Framework 4.5, Ildasm.exe handles an unrecognized marshal BLOB (binary large object) by displaying the raw binary content. 例如,下列程式碼將示範如何顯示 C# 程式所產生的封送處理 BLOB:For example, the following code shows how a marshal BLOB generated by a C# program is displayed:

public void Test([MarshalAs((short)70)] int test) { }
// IL from Ildasm.exe output
.method public hidebysig instance void Test(int32  marshal({ 46 }) test) cil managed

從 .NET Framework 4.5 開始,Ildasm.exe 會顯示套用至介面實作的屬性,如 Ildasm.exe 輸出的下列摘要所示:Starting with the .NET Framework 4.5, Ildasm.exe displays attributes that are applied to interface implementations, as shown in the following excerpt from Ildasm.exe output:

.class public auto ansi beforefieldinit MyClass
  extends [mscorlib]System.Object
  implements IMyInterface
    .interfaceimpl type IMyInterface
    .custom instance void
      [mscorlib]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 )


下列命令會讓 PE 檔 MyHello.exe 的中繼資料和反組譯程式碼顯示於 Ildasm.exe 的預設 GUI 中。The following command causes the metadata and disassembled code for the PE file MyHello.exe to display in the Ildasm.exe default GUI.

ildasm myHello.exe

下列命令會反組譯 MyFile.exe 檔案,並將產生的 IL 組譯工具文字儲存到 檔案中。The following command disassembles the file MyFile.exe and stores the resulting IL Assembler text in the file

ildasm MyFile.exe /

下列命令會反組譯 MyFile.exe 檔案,並在主控台視窗中顯示產生的 IL 組譯工具文字。The following command disassembles the file MyFile.exe and displays the resulting IL Assembler text to the console window.

ildasm MyFile.exe /text

如果檔案 MyApp.exe 包含內嵌的 Managed 和 Unmanaged 資源,則下列命令會產生四個檔案:MyApp.ilMyApp.resIcons.resourcesMessage.resourcesIf the file MyApp.exe contains embedded managed and unmanaged resources, the following command produces four files:, MyApp.res, Icons.resources, and Message.resources:

ildasm MyApp.exe /

下列命令會反組譯 MyFile.exeMyClass 類別內的 MyMethod 方法,並且在主控台視窗中顯示輸出。The following command disassembles the method MyMethod within the class MyClass in MyFile.exe and displays the output to the console window.

ildasm /item:MyClass::MyMethod MyFile.exe /text

在上述範例中,可能有數個名為 MyMethod 但具有不同簽章的方法。In the previous example, there could be several methods named MyMethod with different signatures. 下列命令會反組譯傳回型別為 void 以及參數類型為 int32string 的執行個體方法 MyMethodThe following command disassembles the instance method MyMethod with the return type of void and the parameter types int32 and string.

ildasm /item:"MyClass::MyMethod(instance void(int32,string)" MyFile.exe /text


在 .NET Framework 1.0 和 1.1 版中,方法名稱後的左括號必須與簽章後的右括號保持對稱:MyMethod(instance void(int32))In the .NET Framework versions 1.0 and 1.1, the left parenthesis that follows the method name must be balanced by a right parenthesis after the signature: MyMethod(instance void(int32)). 從 .NET Framework 2.0 開始,必須省略右括號:MyMethod(instance void(int32)Starting with the .NET Framework 2.0 the closing parenthesis must be omitted: MyMethod(instance void(int32).

若要擷取 static 方法 (在 Visual Basic 中為 Shared 方法),請省略關鍵字 instanceTo retrieve a static method (Shared method in Visual Basic), omit the keyword instance. 不是 int32string 等基本類型 (Primitive Type) 的類別類型,都必須包含命名空間,而且前面必須加上關鍵字 classClass types that are not primitive types like int32 and string must include the namespace and must be preceded by the keyword class. 外部類型的前面必須加上以方括號括住的程式庫名稱。External types must be preceded by the library name in square brackets. 下列命令會反組譯名為 MyMethod 的靜態方法,該靜態方法具有一個 AppDomain 類型的參數,而且傳回類型為 AppDomainThe following command disassembles a static method named MyMethod that has one parameter of type AppDomain and has a return type of AppDomain.

ildasm /item:"MyClass::MyMethod(class [mscorlib]System.AppDomain(class [mscorlib]System.AppDomain)" MyFile.exe /text

巢狀類型的前面必須加上它的包含類別,並以正斜線分隔。A nested type must be preceded by its containing class, delimited by a forward slash. 例如,如果 MyNamespace.MyClass 類別包含名為 NestedClass 的巢狀類別,則該巢狀類別的識別方式如下:class MyNamespace.MyClass/NestedClassFor example, if the MyNamespace.MyClass class contains a nested class named NestedClass, the nested class is identified as follows: class MyNamespace.MyClass/NestedClass.

請參閱See also