Exploring IL Assembler
One of colleague once asked a question to me, like what is the risk by distributing the windows application without obfuscating it. The only problem I found is user can use some tools like .Net Reflector and explore our assemblies. But few days before I found some nice .Net Framework tools, ildasm.exe and ilasm.exe, IL Disassembler and IL Assembler respectively. These tools are available with .Net Framework SDKs. These tools can used to generate IL code for .Net assemblies and re-create assemblies from IL code. You can achieve it in code via .Net Reflection.Emit namespace. (In Community Techdays @ Cochin, one session is on Reflection.Emit. Don’t miss it.) As it is a vast topic I am only explaining basics
Generate IL code using ILDASM.exe
- First create a HelloWorld.cs and compile it to HelloWorld.exe
- Use
csc.exeto compile the cs file to exe. –csc HelloWorld.cs - Use
ildasm.exe HelloWorld.Exeto view the IL Code. You can find ILDASM in the Microsoft .Net SDK Path - To generate the IL code use Select Dump option from File Menu or Press Ctrl+D. It will asks for a location to save the IL code.
- Use any Editor to modify the IL code. You can find all the string values ( “Hello World” in this example ) as it is in the IL code. Modify it.( I am modifying it as “Hello World from IL Code”).
using System;
public class HelloWorld
{
static int Main(string[] args)
{
Console.WriteLine("Hello World");
return(0);
}
}
So we created the IL code and modified.
Generate Assembly from IL code using ILASM.exe
- Invoke the ILASM.exe with IL file as the parameter.
ilasm helloworld_il.il - It will show some details about assembling the IL code to assembly. And if the operation is successful you will get an exe in the location with HelloWorld_IL.exe.
- If you invoke the exe from command prompt it will display the modified string instead of Hello World.(In this example “Hello World from IL Code”).
You can do more if you know how IL works. Happy IL Programming




