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萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章