Beispiel #1
0
 static public void PatchToken(List <MSIL.Instruction> opcodes, MSIL.Resolver Resolver)
 {
     foreach (MSIL.Instruction opcode in opcodes)
     {
         if (opcode.OpCode.FlowControl == System.Reflection.Emit.FlowControl.Call)
         {
             object data = Resolver.ResolveMethod((int)((MSIL.MetadataToken)opcode.Data).Token);
             if (data != null)
             {
                 opcode._Data = data;
             }
         }
         if (opcode.OpCode.OperandType == System.Reflection.Emit.OperandType.InlineField)
         {
             object data = Resolver.ResolveField((int)((MSIL.MetadataToken)opcode.Data).Token);
             if (data != null)
             {
                 opcode._Data = data;
             }
         }
         if (opcode.OpCode == System.Reflection.Emit.OpCodes.Ldftn)
         {
             object data = Resolver.ResolveMethod((int)((MSIL.MetadataToken)opcode.Data).Token);
             if (data != null)
             {
                 opcode._Data = data;
             }
         }
         if (opcode.OpCode == System.Reflection.Emit.OpCodes.Ldstr)
         {
             object data = Resolver.ResolveString((int)((MSIL.MetadataToken)opcode.Data).Token);
             if (data != null)
             {
                 opcode._Data = data;
             }
         }
         if (opcode.OpCode == System.Reflection.Emit.OpCodes.Initobj)
         {
             object data = Resolver.ResolveType((int)((MSIL.MetadataToken)opcode.Data).Token);
             if (data != null)
             {
                 opcode._Data = data;
             }
         }
         if (opcode.OpCode == System.Reflection.Emit.OpCodes.Ldtoken)
         {
             // Keep the token
         }
         if (opcode.OpCode == System.Reflection.Emit.OpCodes.Newarr ||
             opcode.OpCode == System.Reflection.Emit.OpCodes.Constrained)
         {
             object data = Resolver.ResolveType((int)((MSIL.MetadataToken)opcode.Data).Token);
             if (data != null)
             {
                 opcode._Data = data;
             }
         }
     }
 }
Beispiel #2
0
 static public void PatchLocals(List <MSIL.Instruction> opcodes, MSIL.Resolver resolver)
 {
     foreach (MSIL.Instruction opcode in opcodes)
     {
         if (opcode.OpCode == System.Reflection.Emit.OpCodes.Ldloc_0)
         {
             object local = resolver.ResolveLocal(0); if (local != null)
             {
                 opcode._Data = local; opcode._OpCode = System.Reflection.Emit.OpCodes.Ldloc;
             }
         }
         else if (opcode.OpCode == System.Reflection.Emit.OpCodes.Ldloc_1)
         {
             object local = resolver.ResolveLocal(1); if (local != null)
             {
                 opcode._Data = local; opcode._OpCode = System.Reflection.Emit.OpCodes.Ldloc;
             }
         }
         else if (opcode.OpCode == System.Reflection.Emit.OpCodes.Ldloc_2)
         {
             object local = resolver.ResolveLocal(2); if (local != null)
             {
                 opcode._Data = local; opcode._OpCode = System.Reflection.Emit.OpCodes.Ldloc;
             }
         }
         else if (opcode.OpCode == System.Reflection.Emit.OpCodes.Ldloc_3)
         {
             object local = resolver.ResolveLocal(3); if (local != null)
             {
                 opcode._Data = local; opcode._OpCode = System.Reflection.Emit.OpCodes.Ldloc;
             }
         }
         else if (opcode.OpCode == System.Reflection.Emit.OpCodes.Ldloc)
         {
             object local = resolver.ResolveLocal((int)opcode._Data); if (local != null)
             {
                 opcode._Data = local;
             }
         }
         else if (opcode.OpCode == System.Reflection.Emit.OpCodes.Ldloc_S)
         {
             object local = resolver.ResolveLocal((byte)opcode._Data); if (local != null)
             {
                 opcode._Data = local; opcode._OpCode = System.Reflection.Emit.OpCodes.Ldloc;
             }
         }
         else if (opcode.OpCode == System.Reflection.Emit.OpCodes.Stloc_0)
         {
             object local = resolver.ResolveLocal(0); if (local != null)
             {
                 opcode._Data = local; opcode._OpCode = System.Reflection.Emit.OpCodes.Stloc;
             }
         }
         else if (opcode.OpCode == System.Reflection.Emit.OpCodes.Stloc_1)
         {
             object local = resolver.ResolveLocal(1); if (local != null)
             {
                 opcode._Data = local; opcode._OpCode = System.Reflection.Emit.OpCodes.Stloc;
             }
         }
         else if (opcode.OpCode == System.Reflection.Emit.OpCodes.Stloc_2)
         {
             object local = resolver.ResolveLocal(2); if (local != null)
             {
                 opcode._Data = local; opcode._OpCode = System.Reflection.Emit.OpCodes.Stloc;
             }
         }
         else if (opcode.OpCode == System.Reflection.Emit.OpCodes.Stloc_3)
         {
             object local = resolver.ResolveLocal(3); if (local != null)
             {
                 opcode._Data = local; opcode._OpCode = System.Reflection.Emit.OpCodes.Stloc;
             }
         }
         else if (opcode.OpCode == System.Reflection.Emit.OpCodes.Stloc)
         {
             object local = resolver.ResolveLocal((int)opcode._Data); if (local != null)
             {
                 opcode._Data = local;
             }
         }
         else if (opcode.OpCode == System.Reflection.Emit.OpCodes.Stloc_S)
         {
             object local = resolver.ResolveLocal((byte)opcode._Data); if (local != null)
             {
                 opcode._Data = local; opcode._OpCode = System.Reflection.Emit.OpCodes.Stloc;
             }
         }
     }
 }