예제 #1
0
        /// <summary>
        /// Makes a copy of the instruction with a new opcode.
        /// </summary>
        /// <param name="newOpcode">The new opcode</param>
        /// <returns>The copy</returns>
        public MsilInstruction CopyWith(OpCode newOpcode)
        {
            var result = new MsilInstruction(newOpcode);

            Operand?.CopyTo(result.Operand);
            foreach (MsilLabel x in Labels)
            {
                result.Labels.Add(x);
            }
            result.TryCatchOperation = TryCatchOperation;
            return(result);
        }
예제 #2
0
 /// <summary>
 /// Gets the constant int this instruction pushes onto the stack.
 /// </summary>
 /// <param name="m">Instruction</param>
 /// <returns>The constant int</returns>
 public static int GetConstInt(this MsilInstruction m)
 {
     if (m.OpCode == OpCodes.Ldc_I4_0)
     {
         return(0);
     }
     if (m.OpCode == OpCodes.Ldc_I4_1)
     {
         return(1);
     }
     if (m.OpCode == OpCodes.Ldc_I4_2)
     {
         return(2);
     }
     if (m.OpCode == OpCodes.Ldc_I4_3)
     {
         return(3);
     }
     if (m.OpCode == OpCodes.Ldc_I4_4)
     {
         return(4);
     }
     if (m.OpCode == OpCodes.Ldc_I4_5)
     {
         return(5);
     }
     if (m.OpCode == OpCodes.Ldc_I4_6)
     {
         return(6);
     }
     if (m.OpCode == OpCodes.Ldc_I4_7)
     {
         return(7);
     }
     if (m.OpCode == OpCodes.Ldc_I4_8)
     {
         return(8);
     }
     if (m.OpCode == OpCodes.Ldc_I4_M1)
     {
         return(-1);
     }
     if (m.OpCode == OpCodes.Ldc_I4)
     {
         return(((MsilOperandInline <int>)m.Operand).Value);
     }
     if (m.OpCode == OpCodes.Ldc_I4_S)
     {
         return(((MsilOperandInline <byte>)m.Operand).Value);
     }
     throw new ArgumentException($"Can't get constant int from instruction {m}");
 }
예제 #3
0
 /// <summary>
 /// Determines if this instruction is a constant int load instruction.
 /// </summary>
 /// <param name="m">Instruction</param>
 /// <returns>True if this instruction pushes a constant int onto the stack</returns>
 public static bool IsConstIntLoad(this MsilInstruction m)
 {
     if (m.OpCode == OpCodes.Ldc_I4_0)
     {
         return(true);
     }
     if (m.OpCode == OpCodes.Ldc_I4_1)
     {
         return(true);
     }
     if (m.OpCode == OpCodes.Ldc_I4_2)
     {
         return(true);
     }
     if (m.OpCode == OpCodes.Ldc_I4_3)
     {
         return(true);
     }
     if (m.OpCode == OpCodes.Ldc_I4_4)
     {
         return(true);
     }
     if (m.OpCode == OpCodes.Ldc_I4_5)
     {
         return(true);
     }
     if (m.OpCode == OpCodes.Ldc_I4_6)
     {
         return(true);
     }
     if (m.OpCode == OpCodes.Ldc_I4_7)
     {
         return(true);
     }
     if (m.OpCode == OpCodes.Ldc_I4_8)
     {
         return(true);
     }
     if (m.OpCode == OpCodes.Ldc_I4_M1)
     {
         return(true);
     }
     if (m.OpCode == OpCodes.Ldc_I4)
     {
         return(true);
     }
     return(m.OpCode == OpCodes.Ldc_I4_S);
 }
예제 #4
0
 /// <summary>
 /// For a local referencing opcode, get the local it is referencing.
 /// </summary>
 public static MsilLocal GetReferencedLocal(this MsilInstruction me)
 {
     if (me.Operand is MsilOperandInline.MsilOperandLocal mol)
     {
         return(mol.Value);
     }
     if (me.OpCode == OpCodes.Stloc_0 || me.OpCode == OpCodes.Ldloc_0)
     {
         return(new MsilLocal(0));
     }
     if (me.OpCode == OpCodes.Stloc_1 || me.OpCode == OpCodes.Ldloc_1)
     {
         return(new MsilLocal(1));
     }
     if (me.OpCode == OpCodes.Stloc_2 || me.OpCode == OpCodes.Ldloc_2)
     {
         return(new MsilLocal(2));
     }
     if (me.OpCode == OpCodes.Stloc_3 || me.OpCode == OpCodes.Ldloc_3)
     {
         return(new MsilLocal(3));
     }
     throw new ArgumentException($"Can't get referenced local in instruction {me}");
 }
예제 #5
0
 /// <summary>
 /// For an argument referencing opcode, get the index of the local it is referencing.
 /// </summary>
 public static MsilArgument GetReferencedArgument(this MsilInstruction me)
 {
     if (me.Operand is MsilOperandInline.MsilOperandArgument mol)
     {
         return(mol.Value);
     }
     if (me.OpCode == OpCodes.Ldarg_0)
     {
         return(new MsilArgument(0));
     }
     if (me.OpCode == OpCodes.Ldarg_1)
     {
         return(new MsilArgument(1));
     }
     if (me.OpCode == OpCodes.Ldarg_2)
     {
         return(new MsilArgument(2));
     }
     if (me.OpCode == OpCodes.Ldarg_3)
     {
         return(new MsilArgument(3));
     }
     throw new ArgumentException($"Can't get referenced argument in instruction {me}");
 }
예제 #6
0
 internal MsilOperandLocal(MsilInstruction instruction) : base(instruction)
 {
 }
예제 #7
0
 internal MsilOperandArgument(MsilInstruction instruction) : base(instruction)
 {
 }
예제 #8
0
 internal MsilOperandSignature(MsilInstruction instruction) : base(instruction)
 {
 }
예제 #9
0
 internal MsilOperandString(MsilInstruction instruction) : base(instruction)
 {
 }
예제 #10
0
 internal MsilOperandDouble(MsilInstruction instruction) : base(instruction)
 {
 }
예제 #11
0
 internal MsilOperandSingle(MsilInstruction instruction) : base(instruction)
 {
 }
예제 #12
0
 internal MsilOperandSwitch(MsilInstruction instruction) : base(instruction)
 {
 }
예제 #13
0
 /// <summary>
 /// Is this instruction a local store instruction.
 /// </summary>
 public static bool IsLocalStore(this MsilInstruction me)
 {
     return(me.OpCode.IsLocalStore());
 }
예제 #14
0
 internal MsilOperandBrTarget(MsilInstruction instruction) : base(instruction)
 {
 }
예제 #15
0
 /// <summary>
 /// Is this instruction an argument load-by-value instruction.
 /// </summary>
 public static bool IsArgumentLoad(this MsilInstruction me)
 {
     return(me.OpCode == OpCodes.Ldarg || me.OpCode == OpCodes.Ldarg_S || me.OpCode == OpCodes.Ldarg_0 ||
            me.OpCode == OpCodes.Ldarg_1 || me.OpCode == OpCodes.Ldarg_2 || me.OpCode == OpCodes.Ldarg_3);
 }
예제 #16
0
 /// <summary>
 /// Is this instruction a local load-by-reference instruction.
 /// </summary>
 public static bool IsLocalLoadByRef(this MsilInstruction me)
 {
     return(me.OpCode.IsLocalLoadByRef());
 }
예제 #17
0
 /// <summary>
 /// Is this instruction an argument load-by-reference instruction.
 /// </summary>
 public static bool IsArgumentLoadByRef(this MsilInstruction me)
 {
     return(me.OpCode == OpCodes.Ldarga || me.OpCode == OpCodes.Ldarga_S);
 }
예제 #18
0
 internal MsilOperandReflected(MsilInstruction instruction) : base(instruction)
 {
 }
예제 #19
0
파일: MsilOperand.cs 프로젝트: thakyZ/Torch
 protected MsilOperand(MsilInstruction instruction)
 {
     Instruction = instruction;
 }
예제 #20
0
 internal MsilOperandInt32(MsilInstruction instruction) : base(instruction)
 {
 }
예제 #21
0
 /// <summary>
 /// Is this instruction an argument store instruction.
 /// </summary>
 public static bool IsArgumentStore(this MsilInstruction me)
 {
     return(me.OpCode == OpCodes.Starg || me.OpCode == OpCodes.Starg_S);
 }