Friday, April 18, 2008

De-assemble and Re-assemble a .Net assembly

Friday, April 18, 2008 Posted by Andre Broers , 9 comments
A .Net assembly can be de-assembled pretty easy. In this blog I create an assembly and will de-assemble, alter and re-assemble the assembly.

Let's start with the famous Hello.cs:

[sourcecode language="CSharp"]

using System;

public class Hello
{
    [STAThread]
    static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
}
[/sourcecode]
build it:

csc /target:exe Hello.cs

de-assemble:

ildasm /out:Hello.il Hello.exe

edit the string "Hello World!" in the Hello.il file to something like "Hello Andre Broers!"

assemble:

ilasm /out:Hello2.exe /res:Hello.res Hello.il

Now we have the altered assembly.

By signing the assembly we can get sure the assembly isn't tampered with. I will explain this in a next blog.

9 comments: