Is there a way in .NET to access the bytecode/IL/CLR that is currently running?

Posted by Alix on Stack Overflow See other posts from Stack Overflow or by Alix
Published on 2010-04-13T15:35:56Z Indexed on 2010/04/13 15:43 UTC
Read the original article Hit count: 392

Filed under:
|
|
|
|

Hi.

I'd like to have access to the bytecode that is currently running or about to run in order to detect certain instructions and take specific actions (depending the instructions). In short, I'd like to monitor the bytecode in order to add safety control.

Is this possible? I know there are some AOP frameworks that notify you of specific events, like an access to a field or the invocation of a method, but I'd like to skip that extra layer and just look at all the bytecode myself, throughout the entire execution of the application.

I've already looked at the following questions (...among many many others ;) ):
    Preprocessing C# - Detecting Methods
    What CLR/.NET bytecode tools exist?
as well as several AOP frameworks (although not in great detail, since they don't seem to do quite what I need) and I'm familiar with Mono.Cecil.

I appreciate alternative suggestions, but I don't want to introduce the overhead of an AOP framework when what I actually need is access to the bytecode, without all the stuff they add on top to make it more user-friendly (... admittedly very useful stuff when you don't want to go low-level).

Thanks :)

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET