Quantcast
Channel: Common Language Runtime Internals and Architecture forum
Viewing all articles
Browse latest Browse all 1710

How to rewrite and check IL code more easy?

$
0
0

Hi!

I instrument method System.Web.Mvc.ControllerActionInvoker.InvokeAction instrument [System.Web.Mvc.dll] which version is 3.0.0.0, but I got a VerificationException: Operation could destabilize the runtime.

I test the same profiler to instrument same method but in System.Web.Mvc.dll version 2.0.0.0, it works normally.

I test newrelic profiler to  instrument same method in version 3.0.0.0, it works normally.

I think that my rewriting IL code is invalid, but I don't know how to verify it. 

Here is the hex I get from GetILFunctionBody

[1B300500E80000007B000011032D0B721D000070732B00000A7A04282E00000A2C1028630B000672D9080070732F00000A7A02036F620200060A020306046F630200060B0739A80000000203076F640200060C0203086F040A0006076F700200060D096F190400062C0F0203096F190400066F6D0200062B44036FEA0100066FD30200062C060328720200060203076F6702000613040203086F030A00060711046F6C02000613050203086F060A000611056FFF0100066F6F02000626DE3126FE1A13060203086F050A000611066F71020006130711076FE60500062D02FE1A020311076FE80500066F6D020006DE00172A162A011C0000000047006CB300031E010001000047006CB6002E84000001]=272 

And here is the hex I use SetILFunctionBody to  
[1B306A004D010000E50100111F028D02000001251F000E01A2251F010E02A21308724C4B00702000800000723F02007072BE4B007072DC4B0070722A4C007072444C0070021108283606000A130A032D0B721D000070732B00000A7A04282E00000A2C1028630B000672D9080070732F00000A7A02036F620200060A020306046F630200060B0739AC0000000203076F640200060C0203086F040A0006076F700200060D096F190400062C0F0203096F190400066F6D0200062B44036FEA0100066FD30200062C060328720200060203076F6702000613040203086F030A00060711046F6C02000613050203086F060A000611056FFF0100066F6F02000626DE3126FE1A13060203086F050A000611066F71020006130711076FE60500062D02FE1A020311076FE80500066F6D020006DE001700130BDE141600130BDE0E1309110A141109283706000AFE1A110A110B14283706000A110B2A000000414C000000000000890000006C000000F5000000030000001E01000100000000890000006C000000F80000002E000000840000010000000042000000F0000000320100000E00000084000001]=424

ps: I wrapper the method a try/catch structure.  In try branch I replace all the ret opcode into save return value the leave.s opcode. In catch  branch I call a static method with exception and then rethrow exception.
I just want to record the return value and exception(if throw) for each method which being instrumented.

1.How can I to solve VerificationException?  I'm not sure that my IL code is invalid or not, but I think I should debug from it. 

2.My way to warp the method is dirty, I break up the old IL code to a double linked list, then insert some instruction, then generates the IL code from double linked list.  Are there any library to do this?
3.Are there any tool or way to verify the IL code to help debug?

Thank you! 

 

Viewing all articles
Browse latest Browse all 1710

Trending Articles