Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top