MSIL反汇编程序是MSIL汇编程序(Ilasm.exe)的一个配套工具。 ILDASM.EXE需要一个可移植可执行文件(PE)文件,其中包含Microsoft中间语言(MSIL)代码,并创建一个文本文件,适合作为输入到Ilasm.exe。
自动安装此工具与Visual Studio和Windows SDK中。 要运行该工具,我们建议您使用Visual Studio命令提示符或Windows SDK命令提示符(CMD壳牌), 这些工具可以帮助您运行该工具很容易,无需导航到安装文件夹。 欲了解更多信息,请参见Visual Studio和Windows SDK命令提示。
- 如果您的计算机上安装有Visual Studio:在任务栏上,单击“ 开始“,单击“ 所有程序“,单击“ Visual Studio中,单击“ Visual Studio工具“,然后单击“ Visual Studio命令提示符“。– 或 –如果您有您的计算机上安装的Windows SDK:在任务栏上,单击“ 开始“,单击“ 所有程序“,单击该文件夹的Windows SDK,然后单击“ 命令提示符(CMD Shell)。
- 在命令提示符下,键入以下命令:
ilasm [options] filename [[options]filename...]
Starting with the .NET Framework 4.5, you can attach a custom attribute to an interface implementation by using code similar to the following:
.class interface public abstract auto ansi IMyInterface
{
.method public hidebysig newslot abstract virtual
instance int32 method1() cil managed
{
} // end of method IMyInterface::method1
} // end of class IMyInterface
.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 )
…
Starting with the .NET Framework 4.5, you can specify an arbitrary marshal BLOB (binary large object) by using its raw binary representation, as shown in the following code:
.method public hidebysig abstract virtual
instance void
marshal({ 38 01 02 FF })
Test(object A_1) cil managed
For more information about the grammar of MSIL, see the asmparse.grammar file in the Windows Software Development Kit (SDK).
The following command assembles the MSIL file myTestFile.il and produces the executable myTestFile.exe.
ilasm myTestFile
The following command assembles the MSIL file myTestFile.il and produces the .dll file myTestFile.dll.
ilasm myTestFile /dll
The following command assembles the MSIL file myTestFile.il and produces the .dll file myNewTestFile.dll.
ilasm myTestFile /dll /output:myNewTestFile.dll
The following code example shows an extremely simple application that displays “Hello World!” to the console. You can compile this code and then use the Ildasm.exe tool to generate an MSIL file.
using System;
publicclass Hello
{
publicstaticvoid Main(String[] args)
{
Console.WriteLine("Hello World!");
}
}
The following MSIL code example corresponds to the previous C# code example. You can compile this code into an assembly using the Ilasm.exe (MSIL Assembler) tool. Both MSIL and C# code examples display “Hello World!” to the console.
// Metadata version: v2.0.50215
.assembly extern mscorlib
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 2:0:0:0
}
.assembly sample
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
.hash algorithm 0x00008004
.ver 0:0:0:0
}
.module sample.exe
// MVID: {A224F460-A049-4A03-9E71-80A36DBBBCD3}
.imagebase 0x00400000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY
// Image base: 0x02F20000
// =============== CLASS MEMBERS DECLARATION ===================
.class public auto ansi beforefieldinit Hello
extends [mscorlib]System.Object
{
.method public hidebysig static void Main(string[] args) cil managed
{
.entrypoint
// Code size 13 (0xd)
.maxstack 8
IL_0000: nop
IL_0001: ldstr "Hello World!"
IL_0006: call void [mscorlib]System.Console::WriteLine(string)
IL_000b: nop
IL_000c: ret
} // end of method Hello::Main
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ret
} // end of method Hello::.ctor
} // end of class Hello
转载请注明出处:https://www.onexin.net/ildasm-exe-msil-disassembler-net-framework-4-5/