ILDASM and ILASM, how use them?

橙三吉。 提交于 2019-12-12 09:08:16

问题


I'm having a hard time trying to (Dis)assemble a dll using the Visual Studio command prompt, don't look that simple as I see in the microsoft page.

I'm using the ildasm for these way:

ildasm myLibrary.dll output:MyLibrary.il

And I get: Unable to open 'MyLibrary.il' for output.

I also tried the full path:

ildasm directory\myLibrary.dll output:directory\MyLibrary.il

And I get: MULTIPLE INPUT FILES SPECIFIED

Using the ildasm GUI actually works, but when I use the ilasm:

ilasm myLibrary.il /dll

I get: Could not open 'myLibrary.il', when I use the full path I get the same error.

What's wrong here?


回答1:


simple, let's take this line of code:

using System;      
public class sample  
{
    static void Main(string[] args)
    {
        Console.WriteLine("Inside main ...");
    }
}

Let us compile App.cs to App.exe. This executable now prints Inside main … when we run it.

Now let us attempt to change the output of this executable without touching its source files.

You run ildasm App.exe /out:App.il to generate the IL code corresponding to the executable. You can now edit this il code in notepad and change the ldstr from “Inside main …” to “Inside main changed …” as shown below:

IL_0000: nop

IL_0001: ldstr "Inside main ..."

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

IL_000b: nop

IL_000c: ret

To

IL_0000: nop

IL_0001: ldstr "Inside main changed ..."

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

IL_000b: nop

IL_000c: ret

Now let us rebuild the executable from this il file by running ilasm App.il. This generates a new App.exe. If you run App.exe you will get the following output “Inside main changed …”

There are useful posts in social.msdn and in c-sharpcorner as well guiding through the use of ILDASM and ILASM.



来源:https://stackoverflow.com/questions/52023353/ildasm-and-ilasm-how-use-them

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!