.Net compiles to (and always has compiled to) an intermediate language (IL). This isn’t machine code, and this gets interpreted when it runs. There are a few decompilers out there (dotPeek being one of the more popular). However, .Net actually ships with its own decompiler: ILDasm.
In this post, I’ll run through how to use ILDasm. It’s not as graphically pleasing as some of the competition, but it is free, and it does ship with .Net.
New Console App
To start off with, create a new console app, and compile it to to a release exe:
You’ll now need to run the developer command prompt (this is installed with VS) - in newer versions, it’s Powershell. If you now just type ildasm, you’ll get the following window:
You can simply open the relevant compiled file here; however, you can also pass that into the command like:
Let’s have a look at the program itself and see what it tells us about this one line application:
We can now click into one of those aspects of the program and see the specific IL code:
I won’t go into the IL code - it’s very unlikely you’ll ever actually need to read it, although it does have some commonality with assembler.
There’s also the functionality to dump the whole IL to a file.
ILDasm is one of those tools with an enormously long shelf life. Admittedly, you won’t be using it daily, but it’s worth knowing where it is and how to use it.