I have a question about Mono.Cecil. I have method m in class C in namespace NS. The method returns String. I need to inject IL code into another method in other class that will call m method. How to do this?

有帮助吗?

解决方案

You can use MethodDefinition.Body.GetILProcessor() to receive an ILProcessor object. That allows you to further modify the method body and inject whatever IL code you want to add.

You might get some basic ideas from Obfuscar.HideStrings where new classes and methods are created from scratch,

https://github.com/lextm/obfuscar/blob/master/Obfuscar/Obfuscator.cs

There are other open source projects based on Cecil, too.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top