Using ildasm to view IL code

February 06, 2024

.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:

Console App

ILDasm

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:

ILDasm

You can simply open the relevant compiled file here; however, you can also pass that into the command like:

ildasm C:\source\repos\ConsoleApp23\ConsoleApp23\bin\Release\net8.0\ConsoleApp23.dll

Let’s have a look at the program itself and see what it tells us about this one line application:

ILDasm

We can now click into one of those aspects of the program and see the specific IL code:

ILDasm

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.

Summary

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.



Profile picture

A blog about one man's journey through code… and some pictures of the Peak District
Twitter

© Paul Michaels 2024