mono.cecil

Unable to load file or assembly 'Mono.Cecil.Pdb' VS17

巧了我就是萌 提交于 2021-01-28 06:36:34
问题 I'm developing a xamarin.forms project using VS17. I have a build faild with this error: 1>System.IO.FileLoadException: Unable to load file or assembly 'Mono.Cecil.Pdb, Version = 0.10.0.0, PublicKeyToken = 50cebf1cceb9d05e' or one of its dependencies. Invalid parameter (Exception from HRESULT: 0x80070057 (E_INVALIDARG)) 1>File name: 'Mono.Cecil.Pdb, Version=0.10.0.0, PublicKeyToken=50cebf1cceb9d05e' ---> System.ArgumentException: Paramètre incorrect. (Exception de HRESULT : 0x80070057 (E

Mono.Cecil - simple example how to get method body

爱⌒轻易说出口 提交于 2020-08-05 06:36:29
问题 I have been searching for a newbie question, but can't find a simple example. Can anyone give me a simple example how to get MethodBody into most available string result? Like: using Mono.Cecil; using Mono.Cecil.Cil; namespace my { public class Main { public Main() { // phseudo code, but doesnt work Console.Write( getMethod("HelloWorld").GetMethodBody().ToString() ); } public void HelloWorld(){ MessageBox.Show("Hiiiiiiiiii"); } } } 回答1: Start with reading your assembly: var path = "... path

How to detect source code changes in async method body

丶灬走出姿态 提交于 2020-06-18 11:56:10
问题 I'm trying to detect during runtime if the source code of a method of a class has been changed. Basically I retrieve the method body (IL), hash it with md5 and store it in the database. Next time I check the method, I can compare the hashes. public class Changed { public string SomeValue { get; set; } public string GetSomeValue() { return SomeValue + "add something"; } public async Task<string> GetSomeValueAsync() { return await Task.FromResult(SomeValue + "add something"); } } I'm using Mono

Emitting delegate function call

♀尐吖头ヾ 提交于 2020-02-20 07:39:21
问题 I have the following C# code: public static double f2(Func<double, double> f, double x) { return f(x); } And here it's IL code: .method public hidebysig static float64 f2 ( class [mscorlib]System.Func`2<float64, float64> f, float64 x ) cil managed { // Method begins at RVA 0x20bd // Code size 8 (0x8) .maxstack 8 IL_0000: ldarg.0 IL_0001: ldarg.1 IL_0002: callvirt instance !1 class [mscorlib]System.Func`2<float64, float64>::Invoke(!0) IL_0007: ret } How can I to emit callvirt instance !1 class

ICSharpCode.Decompiler + Mono.Cecil -> How to generate code for a single method?

∥☆過路亽.° 提交于 2020-01-12 09:15:16
问题 I'm able to use Mono.Cecil and ICSharpCode.Decompiler to generate the code for a type or an assembly. But if I try to generate the code for a single method I'll get an error "Object reference not set to an instance of an object." Can you guys give me any hints about this? Thanks ahead for all the help. Code to generate code for all the types inside an assembly: DirectoryInfo di = new DirectoryInfo(appPath); FileInfo[] allAssemblies = di.GetFiles("*.dll"); foreach (var assemblyFile in

How to inject call to System.Object.Equals with Mono.Cecil?

…衆ロ難τιáo~ 提交于 2020-01-01 15:52:55
问题 Using Mono.Cecil I want to rewrite the following property: public string FirstName { get { return _FirstName; } set { _FirstName = value; } } to this: public string FirstName { get { return _FirstName; } set { if (System.Object.Equals(_FirstName, value)) { return; } _FirstName = value; } } This is just a snippet of what the rewrite will be but it is where I'm having a problem. Using Reflector I can see the following code rewrites the property as required except the call to System.Object

How to inject call to System.Object.Equals with Mono.Cecil?

这一生的挚爱 提交于 2020-01-01 15:52:05
问题 Using Mono.Cecil I want to rewrite the following property: public string FirstName { get { return _FirstName; } set { _FirstName = value; } } to this: public string FirstName { get { return _FirstName; } set { if (System.Object.Equals(_FirstName, value)) { return; } _FirstName = value; } } This is just a snippet of what the rewrite will be but it is where I'm having a problem. Using Reflector I can see the following code rewrites the property as required except the call to System.Object

cecil: Instruction.Operand types corresponding to Instruction.OpCode.Code value

最后都变了- 提交于 2019-12-31 22:40:14
问题 Is there any documentation or is there a part of the cecil source code that I can consult to get a comprehensive view of which Operand types cecil will use for a given Code value? Eg: I can glean from MethodBodyRocks that Ldloc takes an Operand of type VariableDefinition , but I haven't been able to track down this down for some of the other instruction codes. 回答1: You can look at the definition of every OpCode in the OpCodes.cs file. E.g. for Ldloc you would see OperandType.InlineVar 回答2: To

Add a try-catch with Mono Cecil

痞子三分冷 提交于 2019-12-31 21:37:28
问题 I am using Mono Cecil to inject Code in another Method. I want to add a Try-Catch block around my code. So i wrote a HelloWorld.exe with a try catch block and decompiled it. It looks like this in Reflector for the Try-Catch: .try L_0001 to L_0036 catch [mscorlib]System.Exception handler L_0036 to L_003b How can i inject a try catch like this via mono cecil? 回答1: Adding exception handlers with Mono.Cecil is not difficult, it just requires you to know how exception handlers are laid out in the

Add a try-catch with Mono Cecil

自作多情 提交于 2019-12-31 21:37:27
问题 I am using Mono Cecil to inject Code in another Method. I want to add a Try-Catch block around my code. So i wrote a HelloWorld.exe with a try catch block and decompiled it. It looks like this in Reflector for the Try-Catch: .try L_0001 to L_0036 catch [mscorlib]System.Exception handler L_0036 to L_003b How can i inject a try catch like this via mono cecil? 回答1: Adding exception handlers with Mono.Cecil is not difficult, it just requires you to know how exception handlers are laid out in the