Whilst using monomerge.exe I found a case where MethodBody.Clone
didn't decode an instruction.
The method was like below:
.method assembly specialname rtspecialname instance void .ctor() cil
managed
{
.maxstack 4
L_0000: ldarg 0
L_0004: call instance void [mscorlib]System.Object::.ctor()
While processing "ldarg 0" the routine couldn't find a method
parameter to match the operand.
I have limited CIL knowledge, but I believe "ldarg 0" references the
"this" pointer.
I changed my code to recognise and clone the "this" operand.
diff -u3 -r org\Mono.Cecil/Mono.Cecil.Cil/MethodBody.cs Mono.Cecil/
Mono.Cecil.Cil/MethodBody.cs
--- org\Mono.Cecil/Mono.Cecil.Cil/MethodBody.cs 2007-07-13
08:28:50.000000000 +1000
+++ Mono.Cecil/Mono.Cecil.Cil/MethodBody.cs 2007-09-18
16:25:09.445511600 +1000
@@ -130,7 +130,7 @@
case OperandType.InlineParam :
case OperandType.ShortInlineParam :
int param =
body.Method.Parameters.IndexOf
((ParameterDefinition) instr.Operand);
- ni.Operand = parent.Parameters [param];
+ ni.Operand = instr.Operand ==
body.Method.This ?
nb.Method.This : parent.Parameters[param];
break;
case OperandType.InlineVar :
case OperandType.ShortInlineVar :
--~--~---------~--~----~------------~-------~--~----~
--
mono-cecil
-~----------~----~----~----~------~----~------~--~---