views:

424

answers:

2

Hi Fellows,

I am studding IL.

I like .Net Reflector tool from RedGate (Lutz initially). I already have Serge Lidin’s and Ecma-335 books. It looks like these things are all we have to work with IL (except ILAsm and ILDasm, of course).

My task is to parse assembly binary file and get IL code. It is obvious that the assembly is a binary file; hence, it is just a chain of bytes. To do what I want I need to know the assembly structure: which headers exist, how much bytes they occupy, offsets in bytes to read it byte after byte, etc.

Lidin’s book describes it, but it is not 100% clear for me. Did anyone try to parse DLL as byte stream? To have metadata and IL code as byte streams, then parse the IL byte stream to get IL source? I do not want to use reflection here; I’d want to work just with the binary file, rather.

Does the mono Cecil do the same? Even if so, I’d want to know how to do it.

And yes, I am trying to create another wheel like that of .NET Reflector and I want to know how it's made. Like someone said: “Lutz shouldn't necessarily be the only man in the world who knows how to make it”.

BTW, how does ISDasm work? Was it coded in .net?

Any thoughts, resources, examples?

Thank you.

A: 

You could use ildasm directly:

ildasm.exe MyFile.dll /output:MyFile.il

It can be automated from within your program.

Darin Dimitrov
Imagine that I want to write my own ildasm.exe. Just to understand IL and DLL structure better.
Antipod
+2  A: 

Mono.Cecil does exactly what you want to do. So, you may want to have a look at the source code.

In fact, there is an on going project named Cecil.Decompiler, from Jb Evain, based on top of Cecil, which is an open source .NET decompiler.

Romain Verdier
Do you know where can I download the sources? The following URL http://anonsvn.mono-project.com/source/trunk/cecil/decompiler does not work for me.Thank you.
Antipod
Well, it seems to work. May I ask you to retry?
Romain Verdier
Yes, it works now. Thank you.
Antipod