Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Help appreciated.

like image 549
Water Cooler v2 Avatar asked Dec 22 '22 23:12

Water Cooler v2


2 Answers

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

like image 175
Jan Avatar answered Jan 07 '23 14:01

Jan


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

like image 35
Mark H Avatar answered Jan 07 '23 15:01

Mark H