ILDasm和ILAsm简单使用

1.       新建ILDasmAndILAsmConApp控制台程序。

static void Main(string[] args)

        {

            string msg = "use ILDasm to ILFile";

            Console.WriteLine(msg);

        }

2.       使用VS命令提示打开exe,并保存为ILDasmAndILAsmConApp.il

 

.method private hidebysig static void  Main(string[] args) cil managed

  {

    .entrypoint

    // 代码大小       15 (0xf)

    .maxstack  1

    .locals init (string V_0)

    IL_0000:  nop

    IL_0001:  ldstr      "use ILDasm to ILFile"

    IL_0006:  stloc.0

    IL_0007:  ldloc.0

    IL_0008:  call       void [mscorlib]System.Console::WriteLine(string)

    IL_000d:  nop

    IL_000e:  ret

  } // end of method Program::Main

3.       ILDasmAndILAsmConApp.il 新增Console.ReadLine()方法。

.method private hidebysig static void  Main(string[] args) cil managed

  {

    .entrypoint

    // 代码大小       15 (0xf)

    .maxstack  1

    .locals init (string V_0)

    IL_0000:  nop

    IL_0001:  ldstr      "use ILDasm to ILFile"

    IL_0006:  stloc.0

    IL_0007:  ldloc.0

    IL_0008:  call       void [mscorlib]System.Console::WriteLine(string)

    IL_000d:  nop

    IL_000e:  call       string [mscorlib]System.Console::ReadLine()

    IL_0013:  pop

    IL_0014:  ret

  } // end of method Program::Main

4.       通过ILAsm,将ILDasmAndILAsmConApp.il生成新的exe

ilasm d:\users\hexe\桌面\ILDasmAndILAsmConApp.il /output=d:\users\hexe\桌面\ILDasmAndILAsmConApp.exe  /exe

 

 

结果:

 

 

发布了79 篇原创文章 · 获赞 8 · 访问量 22万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章