[MSIL] How to replace existing method by MSIL at runtime in CoreClr? #110934
-
Hello all, Harmony package can support this feature, but I no idea to how implement. Ask for your help to tell me which knowledge I need to study, thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Modifying running code is not supported. There is hot patching that can update running code, but it's debug only and has many limitations. Harmony itself doesn't do the patching. It only composes code blocks in to methods, and depends on MonoMod to replace methods. MonoMod's documentation contains some discussion about hooking methods. It requires to update process memory directly. It's generally unsupported, unreliable and can be broken by many factors, including security or anti-malware enhancement, CLR feature update or refactor. |
Beta Was this translation helpful? Give feedback.
-
One supported way of modifying MSIL at runtime is the Profiler API. The docs say:
The profiling API, as the name suggests, is designed for implementing tools like profilers or code coverage tools. It is a bit of an advanced API, so personally I would try to avoid rewriting IL at runtime if possible. Other types of code generation and rewriting are a easier to implement, including:
|
Beta Was this translation helpful? Give feedback.
Modifying running code is not supported. There is hot patching that can update running code, but it's debug only and has many limitations.
Harmony itself doesn't do the patching. It only composes code blocks in to methods, and depends on MonoMod to replace methods.
MonoMod's documentation contains some discussion about hooking methods. It requires to update process memory directly. It's generally unsupported, unreliable and can be broken by many factors, including security or anti-malware enhancement, CLR feature update or refactor.