9

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?

svick
  • 236,525
  • 50
  • 385
  • 514
Freddx L.
  • 455
  • 2
  • 7
  • 16

2 Answers2

8

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.

Ender Look
  • 2,303
  • 2
  • 17
  • 41
Barr J
  • 10,636
  • 1
  • 28
  • 46
  • 2
    It's kinda frustracting, I try a new project and I get: `c:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools>ildasm ConsoleApp1.exe /out:ConsoleApp.il Unable to open 'ConsoleApp.il' for output.` – Freddx L. Aug 26 '18 at 05:30
  • because your .il is probably read only or your don't have enough permissions, try removing the read only or working with administrator privilages – Barr J Aug 26 '18 at 05:36
  • Open the CMD with elevated privileges – developer learn999 Jan 24 '20 at 15:31
  • @FreddxL. change to a folder where you have write permissions – StayOnTarget May 21 '21 at 14:31
0

ildasm myLibrary.dll -output=MyLibrary.il

DO NOT USE OPTION KEY "/" ON LINUX OR OSX.

'/' is system path separator.