Self-modifying C# (MSIL) code?
Asked Answered
U

1

6

How can I dynamically modify MSIL code in-memory with C#/.NET?

And yes, I'm really looking to replace existing code that's already in memory on the fly.
Specifically, I'm not:

  • Looking to only generate new code (via expression templates, ILGenerator, etc.)
  • Trying to emit a new binary module in the hopes of loading it into memory later
Unnecessarily answered 1/7, 2013 at 23:16 Comment(4)
As far as I am aware, this is not supported in .net IL. Why is this specific scenario required?Bourg
Why do you need this?Quantize
@newStackExchangeInstance: I can't really discuss the project I'm working on, all I can say is that having this capability would help a lot.Unnecessarily
@sheldo Given that Mehrdad is talking about a Virtual Machine Runtime, whose premise of an easily modifiable IL comes with the .NET territory, it is definitely possible. Additionally with unsafe and/or Marshalled invocations there is little one can not do.Aussie
O
2

.Net Profiling API seems promising.

Otherwise, I'm stumped.

Olivaolivaceous answered 1/7, 2013 at 23:27 Comment(1)
It seems to require native code... is there no way to do it from managed code?Unnecessarily

© 2022 - 2024 — McMap. All rights reserved.