Sunday, November 26, 2006

Decompiling .Net Code with .Net Reflector

I'm always suprised to hear that a lot of developers that do not know that .Net code can be decompiled into source code. .Net code is compiled into an Itermediate Lanuage, other languages such as C++ compile code into Machine Code. Machine code is not encrypted, but it is not in a format that a human being can easily understand. Reverse engineering apps from machine code is inherently diificult. Intermediate Language code, though is somewhere between source code and machine code and are much easier to reverse engineer.

From the Wikipedia Entry on the .Net Framework:

Programming languages on the .NET Framework compile into an intermediate
language known as the Common Intermediate Language, or CIL; Microsoft's
implementation of CIL is known as Microsoft Intermediate Language, or MSIL. In
Microsoft's implementation, this intermediate language is not interpreted, but
rather compiled in a manner known as just-in-time compilation (JIT) into native
code. The combination of these concepts is called the Common Language
Infrastructure (CLI), a specification; Microsoft's implementation of the CLI is
known as the Common Language Runtime (CLR).


Since all .Net languages compile into the Common Intermediate Language (CIL), it makes sense that you can take the Common Intermediate Language and decompile that into any .Net language.

Lucky for us, Lutz Roeder has put together a great tool for decompiling CIL code called .Net Reflector.
Reflector is the class browser, explorer, analyzer and documentation viewer for
.NET. Reflector allows to easily view, navigate, search, decompile and analyze
.NET assemblies in C#, Visual Basic and IL.

I've used .Net Reflector to recover lost source code, translate VB.Net to C#, and also just to analyze code from assemblies I've downloaded on the internet.

For those of you who don't want to expose your source code to the masses, don't fret, you can always obfuscate your code. More on that in the coming days...

No comments: