mono.cecil

How to use Mono.Cecil to create HelloWorld.exe

别来无恙 提交于 2019-11-30 13:07:34
How do you use Mono.Cecil to create a simple program from scratch? All the examples and tutorials I've been able to find so far, assume you are working with an existing assembly, reading or making small changes. See the following code to get you started: var myHelloWorldApp = AssemblyDefinition.CreateAssembly( new AssemblyNameDefinition("HelloWorld", new Version(1, 0, 0, 0)), "HelloWorld", ModuleKind.Console); var module = myHelloWorldApp.MainModule; // create the program type and add it to the module var programType = new TypeDefinition("HelloWorld", "Program", Mono.Cecil.TypeAttributes.Class

Does Mono.Cecil take care of branches etc location?

半世苍凉 提交于 2019-11-30 12:43:25
Well this question may seem odd but it's simple - my point is if i have a "goto" (brtrue etc) in the decompiled code like example br IL_0003 call ***** IL_0003: ret and I add a command after that **** call will the br at the top point to ret like it should or to that code. does Cecil do it by itself or I have to take care of all those branches ? :/ it wouldn't be very hard to fix them but if Cecil doesn't then I simply won't start this project, I've no time (or knowledge) for advanced IL magic :P (yes I know it won't be IL_0003 it's just for example) Yes, Cecil will update the branch for you.

How to determine which methods are called in a method?

空扰寡人 提交于 2019-11-30 09:38:21
I'd like to list all the methods that are called from a specific method. E.g. if I have the following code: public void test1() { test2(); test3(); } The list should contain test2() and test3(). It would be great if methods of the same class but also methods of another class could be listed. Additionaly I'd like to find a way to detect which fields are used of a method: public class A { private String test1 = ""; private String test2 = ""; public void test() { Console.WriteLine(test1); } } Should therefore list test1. I tried this using Mono.Cecil, but unfortunately I couldn't find lot of

How to create an override method using Mono.Cecil?

…衆ロ難τιáo~ 提交于 2019-11-30 02:47:18
问题 I'm using Mono.Cecil to generate an assembly that contains a derived class that overrides a specific method in an imported base class. The override method is an 'implicit' override. The problem is that I cannot figure out how to designate it as an override. I'm using the following code to create the override method. void CreateMethodOverride(TypeDefinition targetType, TypeDefinition baseClass, string methodName, MethodInfo methodInfo) { // locate the matching base class method, which may //

How to use Mono.Cecil to create HelloWorld.exe

百般思念 提交于 2019-11-29 18:36:06
问题 How do you use Mono.Cecil to create a simple program from scratch? All the examples and tutorials I've been able to find so far, assume you are working with an existing assembly, reading or making small changes. 回答1: See the following code to get you started: var myHelloWorldApp = AssemblyDefinition.CreateAssembly( new AssemblyNameDefinition("HelloWorld", new Version(1, 0, 0, 0)), "HelloWorld", ModuleKind.Console); var module = myHelloWorldApp.MainModule; // create the program type and add it

Mono.Cecil: call GENERIC base class' method from other assembly

最后都变了- 提交于 2019-11-29 14:46:57
问题 I'm following up on my earlier question: Mono.Cecil: call base class' method from other assembly. I'm doing the same thing, but if my base class is generic it doesn't work. //in Assembly A class BaseVM<T> {} //in Assembly B class MyVM : Base<SomeModel> { [NotifyProperty] public string Something {get;set;} } It weaves the following code: L_000e: call instance void [AssemblyA]Base`1::RaisePropertyChanged(string) instead of L_000e: call instance void [AssemblyA]Base`1<class SomeModel>:

How to determine which methods are called in a method?

半世苍凉 提交于 2019-11-29 14:17:29
问题 I'd like to list all the methods that are called from a specific method. E.g. if I have the following code: public void test1() { test2(); test3(); } The list should contain test2() and test3(). It would be great if methods of the same class but also methods of another class could be listed. Additionaly I'd like to find a way to detect which fields are used of a method: public class A { private String test1 = ""; private String test2 = ""; public void test() { Console.WriteLine(test1); } }

C# Intercept/change/redirect a method

巧了我就是萌 提交于 2019-11-29 05:08:29
Let's say I have a private, "instance," non-static, bool method in a third-party dll. All this method does is return a value. Nothing else. How would I go about intercepting calls to this method, changing it's IL OpCodes/method body, or redirecting it to an extra, overridden or derived method. I do not want to decompile the third-party dll, manually change the source, and recompile it. I also would rather not to save the assembly to disk as this would also involve using a "recompiled" assembly instead of the original. I basically want to be able to use the original dll - no replacements or