views:

63

answers:

5

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 can get a byte array representation of any instruction set, I'll be in a good place.

Help appreciated.

A: 

you can use ildasm.exe from a visual studio command prompt and do something like ildasm.exe dll name

PaulStack
I meant I need to do it programmatically.
Water Cooler v2
this article may help then - http://support.microsoft.com/kb/304655
PaulStack
A: 

You can use ildasm or reflector to extract IL from assembly

Alex Reitbort
+2  A: 

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       
0xA3
That's nice. However, I only need to compare the implementation for a single method in the two assemblies. There may be many differences in the two assemblies.
Water Cooler v2
+4  A: 

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

Mark H
+1 for Cecil. That library is awesome.
Bobby
+2  A: 

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

Jan
You're the man! That's precisely what I was looking for. And I'd been looking at that method just about an hour ago, and have used it many times earlier. Never thought of it when I needed it. Thanks again.
Water Cooler v2