ILdasm 的使用方法

Ildasm.exe下載地址:http://www.dbjr.com.cn/softs/73291.html
下邊我們來(lái)看看怎么使用:
1.在VS2008中新建一個(gè)Windows窗體應(yīng)用程序,輸入如下代碼后生成解決方案:
private void Form1_Load(object sender, EventArgs e)
{
int i = 0;
i = i++;
MessageBox.Show(i.ToString());
}
2.運(yùn)行ildasm,打開(kāi)剛生成的exe文件,可以看到如下內(nèi)容:
3.在ildasm中雙擊"Form1_Load: void(object,class [mscorlib]System.EventArgs)"即可看到上邊代碼的MSIL代碼:
.method private hidebysig instance void Form1_Load(object sender,
class [mscorlib]System.EventArgs e) cil managed
{
// 代碼大小 22 (0x16)
.maxstack 3
.locals init ([0] int32 i)
IL_0000: ldc.i4.0
IL_0001: stloc.0
IL_0002: ldloc.0
IL_0003: dup
IL_0004: ldc.i4.1
IL_0005: add
IL_0006: stloc.0
IL_0007: stloc.0
IL_0008: ldloca.s i
IL_000a: call instance string [mscorlib]System.Int32::ToString()
IL_000f: call valuetype [System.Windows.Forms]System.Windows.Forms.DialogResult [System.Windows.Forms]System.Windows.Forms.MessageBox::Show(string)
IL_0014: pop
IL_0015: ret
} // end of method Form1::Form1_Load
附:將ildasm集成到VS2008中的方法:
在VS2008菜單中選擇"工具→外部工具",點(diǎn)擊添加按鈕,在標(biāo)題中輸入ILdasm,命令中輸入C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\ildasm.exe,確定后在工具菜單中就能找到ILdasm了,以后只要選擇它就能運(yùn)行ILdasm。
MSIL匯編程序(Ilasm.exe)和MSIL反匯編程序(Ildasm.exe)
先來(lái)解釋下文要提到的幾個(gè)名詞:
PE文件:可移植可執(zhí)行文件。當(dāng)為公共語(yǔ)言運(yùn)行庫(kù)編譯程序時(shí),該程序轉(zhuǎn)換為由三部分組成的 PE 文件,PE 標(biāo)頭、MSIL 指令、元數(shù)據(jù)。
MSIL: Microsoft 中間語(yǔ)言。這是一組可以有效地轉(zhuǎn)換為本機(jī)代碼且獨(dú)立于 CPU 的指令。MSIL 包括用于加載、存儲(chǔ)和初始化對(duì)象以及對(duì)對(duì)象調(diào)用方法的指令,還包括用于算術(shù)和邏輯運(yùn)算、控制流、直接內(nèi)存訪問(wèn)、異常處理和其他操作的指令。
MSIL 反匯編程序是 MSIL 匯編程序 (Ilasm.exe) 的伙伴工具。Ildasm.exe 采用包含 Microsoft 中間語(yǔ)言 (MSIL) 代碼的可移植可執(zhí)行 (PE) 文件,并創(chuàng)建相應(yīng)的文本文件作為 Ilasm.exe 的輸入。
還是以SampleClass為例來(lái)解釋它們的用法。
MSIL反匯編程序(Ildasm.exe)
下面的命令使 PE 文件 SampleClass.exe 的元數(shù)據(jù)和反匯編代碼顯示在 Ildasm.exe 的默認(rèn) GUI 中。
ildasm SampleClass.exe
下面的命令對(duì) SampleClass.exe 文件進(jìn)行反匯編,并將結(jié)果 MSIL 匯編程程序文本存儲(chǔ)在 SampleClass.il 文件中。
E:\test>ildasm SampleClass.exe /output:SampleClass.il
// WARNING: Created Win32 resource file SampleClass.res
下面的命令對(duì) SampleClass.exe 文件進(jìn)行反匯編,并將結(jié)果 MSIL 匯編程序文本顯示到控制臺(tái)窗口中。
E:\test>ildasm SampleClass.exe /text
如果文件 SampleClass.exe 包含嵌入的托管和非托管資源,則下面的命令將產(chǎn)生以下 4 個(gè)文件:SampleClass.il、SampleClass.res、Icons.resources 和 Message.resources:
ildasm SampleClass.exe /output:SampleClass.il
下面的命令對(duì) SampleClass.exe 的 SampleClass 類中的 DataClass 方法進(jìn)行反匯編,并將輸出顯示到控制臺(tái)窗口中。
ildasm /item:SampleClass::DataClass SampleClass.exe /text
參數(shù)列表:
下列選項(xiàng)可用于 .exe、.dll、.obj 和 .lib 文件。
/output:filename | 創(chuàng)建具有指定 filename 的輸出文件,而不是在對(duì)話框中顯示結(jié)果。 |
/text | 將結(jié)果顯示到控制臺(tái)窗口,而不是顯示在對(duì)話框中或顯示為輸出文件。 |
/? | 顯示此工具的命令語(yǔ)法和選項(xiàng)。 |
下列附加選項(xiàng)可用于 .exe 和 .dll 文件。
/bytes | 以十六進(jìn)制格式顯示作為指令注釋的實(shí)際字節(jié)。 |
/linenum | 包含對(duì)原始源行的引用。 |
/nobar | 取消反匯編進(jìn)度指示器彈出窗口的顯示。 |
/pubonly | 只反匯編公共類型和公共成員。等效于 /visibility:PUB。 |
/quoteallnames | 在單引號(hào)中包含所有名稱。 |
/raweh | 以原始格式顯示異常處理子句。 |
/source | 顯示作為注釋的原始源行。 |
/tokens | 顯示類和成員的元數(shù)據(jù)標(biāo)記。 |
/visibility:vis [+vis ...] | 只反匯編具有指定可見(jiàn)性的類型或成員。以下是 vis 的有效值。 PUB Public PRI Private FAM Family ASM Assembly FAA Family 和 Assembly FOA Family 或 Assembly PSC Private Scope |
下列選項(xiàng)僅對(duì)用于文件或控制臺(tái)輸出的 .exe 和 .dll 文件有效。
/all | 指定 /header、/bytes 和 /tokens 選項(xiàng)的組合。 |
/header | 在輸出中包含文件頭信息。 |
/noil | 取消 MSIL 程序集代碼輸出。 |
/unicode | 對(duì)輸出使用 Unicode 編碼。 |
/utf8 | 對(duì)輸出使用 UTF-8 編碼。默認(rèn)值是 ANSI。 |
下列選項(xiàng)僅對(duì)用于文件或控制臺(tái)輸出的 .exe、.dll、.obj 和 .lib 文件有效。
/item:class[::method [(sig)]] | 根據(jù)所提供的參數(shù)反匯編下列內(nèi)容:
|
MSIL匯編程序(Ilasm.exe)
下面的命令對(duì) MSIL 文件 SampleClass.il 進(jìn)行匯編并產(chǎn)生可執(zhí)行文件 SampleClass.exe。
E:\test>ilasm SampleClass
Microsoft (R) .NET Framework IL Assembler. Version 1.1.4322.2032
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.
Assembling 'SampleClass.IL' , no listing file, to EXE --> 'SampleClass.EX
Source file is ANSI
Assembled method DataClass::.ctor
Assembled method DataClass::addem
Assembled method SampleClass::.ctor
Assembled method SampleClass::Main
Creating PE file
Emitting members:
Global
Class 1 Fields: 2; Methods: 2;
Class 2 Fields: 2; Methods: 2;
Resolving member refs: 11 -> 11 defs, 0 refs
Writing PE file
Operation completed successfully
下面的命令對(duì) MSIL 文件 SampleClass.il 進(jìn)行匯編并產(chǎn)生 .dll 文件 SampleClass.dll。
E:\test>ilasm SampleClass /dll
Microsoft (R) .NET Framework IL Assembler. Version 1.1.4322.2032
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.
Assembling 'SampleClass.IL' , no listing file, to DLL --> 'SampleClass.DLL'
Source file is ANSI
Assembled method DataClass::.ctor
Assembled method DataClass::addem
Assembled method SampleClass::.ctor
Assembled method SampleClass::Main
Creating PE file
Emitting members:
Global
Class 1 Fields: 2; Methods: 2;
Class 2 Fields: 2; Methods: 2;
Resolving member refs: 11 -> 11 defs, 0 refs
Writing PE file
Operation completed successfully
下面的命令對(duì) MSIL 文件 SampleClass.il 進(jìn)行匯編并產(chǎn)生 .dll 文件 SampleClass.dll。
ilasm SampleClass /dll /output:newSampleClass.dll
參數(shù)列表:
/alignment=integer | 將 FileAlignment 設(shè)置為由 NT Optional 標(biāo)題中的 integer 指定的值。如果在文件中指定了 .alignment IL 指令,則此選項(xiàng)將重寫它。 |
/base=integer | 將 ImageBase 設(shè)置為由 NT Optional 標(biāo)題中的 integer 指定的值。如果在文件指定了 .imagebase IL 指令,則此選項(xiàng)將重寫它。 |
/clock | 為指定的 .il 源文件測(cè)量并報(bào)告下列編譯時(shí)間(以毫秒為單位): 總運(yùn)行時(shí)間 執(zhí)行后面的所有特定操作所花費(fèi)的總時(shí)間。 啟動(dòng) 加載并打開(kāi)文件。
分析 發(fā)出 MD 發(fā)出元數(shù)據(jù)。 定義引用解析 解析對(duì)文件中的定義的引用。修正和鏈接 CEE 文件生成 在內(nèi)存中生成文件映像。 PE 文件寫入 將映像寫入 PE 文件。 |
/debug | 包括調(diào)試信息(局部變量名和參數(shù)名以及行號(hào))。 |
/dll | 生成 .dll 文件作為輸出。 |
/exe | 生成可執(zhí)行文件作為輸出。這是默認(rèn)值。 |
/flags=integer | 將 ImageFlags 設(shè)置為由公共語(yǔ)言運(yùn)行庫(kù)標(biāo)題中的 integer 指定的值。如果在文件中指定了 .corflags IL 指令,則此選項(xiàng)將重寫它。有關(guān) integer 的有效值的列表,請(qǐng)參見(jiàn) CorHdr.h 中的 COMIMAGE_FLAGS。 |
/key:keyFile | 使用 keyFile 中包含的私鑰編譯具有強(qiáng)簽名的 filename。 |
/key:@keySource | 使用在 keySource 中生成的私鑰編譯具有強(qiáng)簽名的 filename。 |
/listing | 在標(biāo)準(zhǔn)輸出上生成列表文件。如果省略此選項(xiàng),則不生成列表文件。 |
/nologo | 取消顯示 Microsoft 啟動(dòng)標(biāo)題。 |
/output:file.ext | 指定輸出文件名和擴(kuò)展名。默認(rèn)情況下,輸出文件名與第一個(gè)源文件名相同。默認(rèn)擴(kuò)展名為 .exe。如果指定 /dll 選項(xiàng),則默認(rèn)擴(kuò)展名為 .dll。 注意 指定 /output:myfile.dll 并不會(huì)設(shè)置 /dll 選項(xiàng)。如果不指定 /dll,則會(huì)生成名為 myfile.dll 的可執(zhí)行文件。 |
/quiet | 指定安靜模式;不報(bào)告程序集進(jìn)度。 |
/resource:file.res | 在生成的 .exe 或 .dll 文件中包括 *.res 格式的指定資源文件。使用 /resource 選項(xiàng)只能指定一個(gè) .res 文件。 |
/subsystem=integer | 將 subsystem 設(shè)置為由 NT Optional 標(biāo)題中的 integer 指定的值。如果在文件中指定了 .subsystem IL 指令,則此命令將重寫它。有關(guān) integer 的有效值的列表,請(qǐng)參見(jiàn) winnt.h 中的 IMAGE_SUBSYSTEM。 |
/? | 顯示此工具的命令語(yǔ)法和選項(xiàng)。 |
相關(guān)文章
c#反編譯工具(Ildasm.exe)2.0 中文綠色版(MSIL 反匯編程序)
MSIL 反匯編程序是 MSIL 匯編程序 (Ilasm.exe) 的伙伴工具。 Ildasm.exe 采用包含 Microsoft 中間語(yǔ)言 (MSIL) 代碼的可遷移可執(zhí)行 (PE) 文件,并創(chuàng)建相應(yīng)的文本文件作為 Il2013-02-17