Questions tagged [mono.cecil]

Mono.Cecil is a library to generate and inspect programs and libraries in the ECMA CIL form.

Mono.Cecil is a cross platform library, working equally well on .net and Mono, used to analyze, modify and write .net assemblies.

It is used in a variety of open source projects and commercial products.

Links

390 questions
4
votes
0 answers

Weave third party dll with fody

I would like to write a Fody plugin that will allow me to weave a third party dll. Is it possible? Reading the documentation and the source code from different plugins, I haven't found any way to do so. It appears that fody only enables to weave the…
4
votes
1 answer

Mono Cecil Add Class with Method into Assembly

I am trying to add a new class into an assembly with 1 method call that I am trying to call from elsewhere in this assembly. Currently I have the following: ParameterDefinition param = new ParameterDefinition("Param", ParameterAttributes.None,…
user3412625
  • 99
  • 1
  • 8
4
votes
1 answer

C# Intercept/change/redirect a method

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…
user3150838
  • 61
  • 1
  • 5
4
votes
0 answers

How do I change all references from one type to another using Mono.Cecil?

I need to replace all references to a particular type, and replace them with references to another type. I remember Mono.Cecil had a ReferenceVisitor class some time ago, but it seems to be gone. How can I solve my task with current version of…
krint
  • 41
  • 2
4
votes
0 answers

Mono Cecil error generating PDB

The code below allows me to change methods body and save back the assembly. // Recreate PDB var assemblyResolver = new DefaultAssemblyResolver(); var assemblyLocation = Path.GetDirectoryName(pathBin); …
GBrian
  • 1,031
  • 11
  • 28
4
votes
1 answer

How to use Mono.Cecil to parse IL Instructions from byte array

I am dynamically compiling source code using CodeDOM, now i want to work with the generated IL code of a particular method using Cecil, CodeDOM provides me with the IL code of the method as a byte array, is there any way to create a MethodBody, (or…
Robert J.
  • 645
  • 5
  • 13
4
votes
1 answer

Mono.Cecil How to define an output parameter

I want to add a new method via Mono.Cecil which has an output parameter, like: private static bool XXXXX(out Int32 a) I tried the following codes to add this parameter TypeReference typeInt32 =…
Mr.Wang from Next Door
  • 13,670
  • 12
  • 64
  • 97
4
votes
1 answer

Mono cecil SaveSymbols(); in ver- 0.9.5.0

There was a AssemblyDefinition.MainModule.SaveSymbols(); But in version 0.9.5.0, how we can save a .pdb file before saving an AssemblyDefinition. //Here to add the command for save the .pdb file AssemblyDefinition.Write(_);
Jaish Mathews
  • 766
  • 1
  • 9
  • 25
4
votes
2 answers

Mono.Cecil: injecting try/finally?

Good overview of implementing try/catch in Mono.Cecil was answered here, but he stops just short of a full try/catch/finally. So how do you implement try/finally using Mono.Cecil?
naasking
  • 2,514
  • 1
  • 27
  • 32
4
votes
2 answers

Mono.Cecil - How to get custom attributes

I am trying to use Cecil to inspect the attributes associated with a given method. It seems to find it, but I cannot get its name using the following code: AssemblyDefinition assembly =…
devoured elysium
  • 101,373
  • 131
  • 340
  • 557
4
votes
1 answer

How to make a dynamic method which uses static variables from the same assembly?

I created a dynamic method, but when I try to access outside resources, it gives me an exception TargetInvocationException: Exception has been thrown by the target of an invocation. Basically I want to write a method to byte array, then load it…
blez
  • 4,939
  • 5
  • 50
  • 82
4
votes
4 answers

How to run method from byte array (in memory)?

I have a dynamic method and I have the byte[] from the real method (using Cecil). Now how to assign this byte array to the dynamic method and execute it? I'm sure it's not only one way thing, there must be a way to invoke byte arrays.
blez
  • 4,939
  • 5
  • 50
  • 82
4
votes
1 answer

Creating an IL instruction with an inline argument using Mono.Cecil

I'm playing with mutation testing at the moment. One of the mutations I'm looking at involves swapping parameters, for which I may need to swap, for example Ldarg.0 and Ldarg_S with an operand indicating the index. The operand type for this is an…
David M
  • 71,481
  • 13
  • 158
  • 186
3
votes
1 answer

Mono.Cecil fails to process a Silverlight 5 assembly

When I am trying to read a Silverlight 5 assembly via Mono.Cecil version 0.9.3.0, I am getting the following exception: System.NotSupportedException: Version not supported: 5.0.5.0 ------ at…
VitalyB
  • 12,397
  • 9
  • 72
  • 94
3
votes
0 answers

MissingMethodException when applied generic type parameters to method that returns generic parameter

I have a method called DynamicInvoke that is as follows: public static object InvokeDynamic(Delegate d, object[] args) { Type[] tparams = d.Method.DeclaringType.GetGenericArguments() …
June Rhodes
  • 3,047
  • 4
  • 23
  • 29