Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

API for getting IL from byte array

Tags:

cil

There is a GetILAsByteArray method in MethodBody class which gives body of a method. I am looking for converting this byte array into more understandable IL instructions (into a List or something like that). What resources, open source code or api available are there to help me understand and convert this byte array (or do it for me)?

I found this but it does not work with generics. I am pretty much looking for guidance to convert understand these bytes in all framework versions.

CLI Documentation is also helpful for learning IL instructions but I cannot see how to use it to make these bytes make sense.

like image 999
Serhat Ozgel Avatar asked Jan 06 '09 12:01

Serhat Ozgel


3 Answers

I just wrote an extension method to get a more understandable list of instructions using GetILAsByteArray. It's quite simple, the API is like:

public static IList<Instruction> GetInstructions (this MethodBase self);

You can read more about the implementation in my blog post. Or you can go take the implementation and start using it.

like image 143
Jb Evain Avatar answered Nov 02 '22 18:11

Jb Evain


Have a look at the Mono.Cecil library.

like image 41
Anton Tykhyy Avatar answered Nov 02 '22 19:11

Anton Tykhyy


It is a huge undertaking. I wrote the starts of an IL reader and it had a pretty good amount of opcodes implemented: but you will need to finish it.

http://svn.ensemble-os.org/tags/OldOCJ/CIL/

There is also MONO Cecil, which is feature-complete.

like image 44
Jonathan C Dickinson Avatar answered Nov 02 '22 20:11

Jonathan C Dickinson