Programmatically compare IL of two methods
I have a compiled assembly. I want to programmatically compare the method implementation of one of the methods in that assembly with something I expect.
Is there a way I can compare their ILs? Even if I 开发者_如何学JAVAcan get a byte array representation of any instruction set, I'll be in a good place.
Help appreciated.
You could try using Reflection and compare the IL using byte arrays.
Take a look at this method: http://msdn.microsoft.com/en-us/library/system.reflection.methodbody.getilasbytearray.aspx
Using Mono.Cecil might be a good place to start. Cecil is a library used to read and modify CLR assemblies, and will do all the file parsing for you as far as grabbing the CIL bytecode.
Another potential library you might be able to use is Boogie
You can dump the assemblies using ildasm and diff the two versions like this:
ildasm /ALL /TEXT assembly1.dll > dump1.txt
ildasm /ALL /TEXT assembly2.dll > dump2.txt
fc dump1.txt dump2.txt
you can use ildasm.exe from a visual studio command prompt and do something like ildasm.exe dll name
You can use ildasm or reflector to extract IL from assembly
精彩评论