سؤال

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