예제 #1
0
 public static void Skip(BlobReader reader)
 {
     var opCode = (OpCode)reader.ReadByte();
     if (opCode == OpCode.Prefix1)
         opCode = (OpCode)((ushort)opCode << 8 | reader.ReadByte());
     switch (opCode)
     {
     case OpCode.Nop:
     case OpCode.Break:
     case OpCode.Ldarg_0:
     case OpCode.Ldarg_1:
     case OpCode.Ldarg_2:
     case OpCode.Ldarg_3:
     case OpCode.Ldloc_0:
     case OpCode.Ldloc_1:
     case OpCode.Ldloc_2:
     case OpCode.Ldloc_3:
     case OpCode.Stloc_0:
     case OpCode.Stloc_1:
     case OpCode.Stloc_2:
     case OpCode.Stloc_3:
     case OpCode.Ldnull:
     case OpCode.Ldc_i4_m1:
     case OpCode.Ldc_i4_0:
     case OpCode.Ldc_i4_1:
     case OpCode.Ldc_i4_2:
     case OpCode.Ldc_i4_3:
     case OpCode.Ldc_i4_4:
     case OpCode.Ldc_i4_5:
     case OpCode.Ldc_i4_6:
     case OpCode.Ldc_i4_7:
     case OpCode.Ldc_i4_8:
     case OpCode.Dup:
     case OpCode.Pop:
     case OpCode.Ret:
     case OpCode.Ldind_i1:
     case OpCode.Ldind_u1:
     case OpCode.Ldind_i2:
     case OpCode.Ldind_u2:
     case OpCode.Ldind_i4:
     case OpCode.Ldind_u4:
     case OpCode.Ldind_i8:
     case OpCode.Ldind_i:
     case OpCode.Ldind_r4:
     case OpCode.Ldind_r8:
     case OpCode.Ldind_ref:
     case OpCode.Stind_ref:
     case OpCode.Stind_i1:
     case OpCode.Stind_i2:
     case OpCode.Stind_i4:
     case OpCode.Stind_i8:
     case OpCode.Stind_r4:
     case OpCode.Stind_r8:
     case OpCode.Add:
     case OpCode.Sub:
     case OpCode.Mul:
     case OpCode.Div:
     case OpCode.Div_un:
     case OpCode.Rem:
     case OpCode.Rem_un:
     case OpCode.And:
     case OpCode.Or:
     case OpCode.Xor:
     case OpCode.Shl:
     case OpCode.Shr:
     case OpCode.Shr_un:
     case OpCode.Neg:
     case OpCode.Not:
     case OpCode.Conv_i1:
     case OpCode.Conv_i2:
     case OpCode.Conv_i4:
     case OpCode.Conv_i8:
     case OpCode.Conv_r4:
     case OpCode.Conv_r8:
     case OpCode.Conv_u4:
     case OpCode.Conv_u8:
     case OpCode.Conv_r_un:
     case OpCode.Throw:
     case OpCode.Conv_ovf_i1_un:
     case OpCode.Conv_ovf_i2_un:
     case OpCode.Conv_ovf_i4_un:
     case OpCode.Conv_ovf_i8_un:
     case OpCode.Conv_ovf_u1_un:
     case OpCode.Conv_ovf_u2_un:
     case OpCode.Conv_ovf_u4_un:
     case OpCode.Conv_ovf_u8_un:
     case OpCode.Conv_ovf_i_un:
     case OpCode.Conv_ovf_u_un:
     case OpCode.Ldlen:
     case OpCode.Ldelem_i1:
     case OpCode.Ldelem_u1:
     case OpCode.Ldelem_i2:
     case OpCode.Ldelem_u2:
     case OpCode.Ldelem_i4:
     case OpCode.Ldelem_u4:
     case OpCode.Ldelem_i8:
     case OpCode.Ldelem_i:
     case OpCode.Ldelem_r4:
     case OpCode.Ldelem_r8:
     case OpCode.Ldelem_ref:
     case OpCode.Stelem_i:
     case OpCode.Stelem_i1:
     case OpCode.Stelem_i2:
     case OpCode.Stelem_i4:
     case OpCode.Stelem_i8:
     case OpCode.Stelem_r4:
     case OpCode.Stelem_r8:
     case OpCode.Stelem_ref:
     case OpCode.Conv_ovf_i1:
     case OpCode.Conv_ovf_u1:
     case OpCode.Conv_ovf_i2:
     case OpCode.Conv_ovf_u2:
     case OpCode.Conv_ovf_i4:
     case OpCode.Conv_ovf_u4:
     case OpCode.Conv_ovf_i8:
     case OpCode.Conv_ovf_u8:
     case OpCode.Ckfinite:
     case OpCode.Conv_u2:
     case OpCode.Conv_u1:
     case OpCode.Conv_i:
     case OpCode.Conv_ovf_i:
     case OpCode.Conv_ovf_u:
     case OpCode.Add_ovf:
     case OpCode.Add_ovf_un:
     case OpCode.Mul_ovf:
     case OpCode.Mul_ovf_un:
     case OpCode.Sub_ovf:
     case OpCode.Sub_ovf_un:
     case OpCode.Endfinally:
     case OpCode.Stind_i:
     case OpCode.Conv_u:
     case OpCode.Prefix7:
     case OpCode.Prefix6:
     case OpCode.Prefix5:
     case OpCode.Prefix4:
     case OpCode.Prefix3:
     case OpCode.Prefix2:
     case OpCode.Prefix1:
     case OpCode.Prefixref:
     case OpCode.Arglist:
     case OpCode.Ceq:
     case OpCode.Cgt:
     case OpCode.Cgt_un:
     case OpCode.Clt:
     case OpCode.Clt_un:
     case OpCode.Localloc:
     case OpCode.Endfilter:
     case OpCode.Volatile:
     case OpCode.Tailcall:
     case OpCode.Cpblk:
     case OpCode.Initblk:
     case OpCode.Rethrow:
     case OpCode.Refanytype:
     case OpCode.Readonly:
         break;
     case OpCode.Br_s:
     case OpCode.Brfalse_s:
     case OpCode.Brtrue_s:
     case OpCode.Beq_s:
     case OpCode.Bge_s:
     case OpCode.Bgt_s:
     case OpCode.Ble_s:
     case OpCode.Blt_s:
     case OpCode.Bne_un_s:
     case OpCode.Bge_un_s:
     case OpCode.Bgt_un_s:
     case OpCode.Ble_un_s:
     case OpCode.Blt_un_s:
     case OpCode.Leave_s:
     case OpCode.Ldc_i4_s:
         reader.ReadSByte();
         break;
     case OpCode.Unaligned:
     case OpCode.Ldarg_s:
     case OpCode.Ldarga_s:
     case OpCode.Starg_s:
     case OpCode.Ldloc_s:
     case OpCode.Ldloca_s:
     case OpCode.Stloc_s:
         reader.ReadByte();
         break;
     case OpCode.Br:
     case OpCode.Brfalse:
     case OpCode.Brtrue:
     case OpCode.Beq:
     case OpCode.Bge:
     case OpCode.Bgt:
     case OpCode.Ble:
     case OpCode.Blt:
     case OpCode.Bne_un:
     case OpCode.Bge_un:
     case OpCode.Bgt_un:
     case OpCode.Ble_un:
     case OpCode.Blt_un:
     case OpCode.Leave:
     case OpCode.Ldc_i4:
         reader.ReadInt32();
         break;
     case OpCode.Ldfld:
     case OpCode.Ldflda:
     case OpCode.Stfld:
     case OpCode.Ldsfld:
     case OpCode.Ldsflda:
     case OpCode.Stsfld:
     case OpCode.Calli:
     case OpCode.Ldstr:
     case OpCode.Ldtoken:
     case OpCode.Cpobj:
     case OpCode.Ldobj:
     case OpCode.Castclass:
     case OpCode.Isinst:
     case OpCode.Unbox:
     case OpCode.Stobj:
     case OpCode.Box:
     case OpCode.Newarr:
     case OpCode.Ldelema:
     case OpCode.Ldelem:
     case OpCode.Stelem:
     case OpCode.Unbox_any:
     case OpCode.Refanyval:
     case OpCode.Mkrefany:
     case OpCode.Initobj:
     case OpCode.Constrained:
     case OpCode.Sizeof:
     case OpCode.Ldarg:
     case OpCode.Ldarga:
     case OpCode.Starg:
     case OpCode.Ldloc:
     case OpCode.Ldloca:
     case OpCode.Stloc:
     case OpCode.Jmp:
     case OpCode.Call:
     case OpCode.Callvirt:
     case OpCode.Newobj:
     case OpCode.Ldftn:
     case OpCode.Ldvirtftn:
         reader.ReadUInt32();
         break;
     case OpCode.Ldc_i8:
         reader.ReadInt64();
         break;
     case OpCode.Ldc_r4:
         reader.ReadSingle();
         break;
     case OpCode.Ldc_r8:
         reader.ReadDouble();
         break;
     case OpCode.Switch:
         {
             var numTargets = (int)reader.ReadUInt32();
             for (var i = 0; i < numTargets; i++)
                 reader.ReadInt32();
             break;
         }
     default:
         throw new PEException("unrecognised opcode");
     }
 }
예제 #2
0
 public void Read(ReaderContext ctxt, BlobReader reader, uint beginOffset, Func<OpCode, Row, object> resolveRow)
 {
     Offset = (int)(reader.Offset - beginOffset);
     OpCode = (OpCode)reader.ReadByte();
     if (OpCode == OpCode.Prefix1)
         OpCode = (OpCode)((ushort)OpCode << 8 | reader.ReadByte());
     Value = default(object);
     switch (OpCode)
     {
     case OpCode.Nop:
     case OpCode.Break:
     case OpCode.Ldarg_0:
     case OpCode.Ldarg_1:
     case OpCode.Ldarg_2:
     case OpCode.Ldarg_3:
     case OpCode.Ldloc_0:
     case OpCode.Ldloc_1:
     case OpCode.Ldloc_2:
     case OpCode.Ldloc_3:
     case OpCode.Stloc_0:
     case OpCode.Stloc_1:
     case OpCode.Stloc_2:
     case OpCode.Stloc_3:
     case OpCode.Ldnull:
     case OpCode.Ldc_i4_m1:
     case OpCode.Ldc_i4_0:
     case OpCode.Ldc_i4_1:
     case OpCode.Ldc_i4_2:
     case OpCode.Ldc_i4_3:
     case OpCode.Ldc_i4_4:
     case OpCode.Ldc_i4_5:
     case OpCode.Ldc_i4_6:
     case OpCode.Ldc_i4_7:
     case OpCode.Ldc_i4_8:
     case OpCode.Dup:
     case OpCode.Pop:
     case OpCode.Ret:
     case OpCode.Ldind_i1:
     case OpCode.Ldind_u1:
     case OpCode.Ldind_i2:
     case OpCode.Ldind_u2:
     case OpCode.Ldind_i4:
     case OpCode.Ldind_u4:
     case OpCode.Ldind_i8:
     case OpCode.Ldind_i:
     case OpCode.Ldind_r4:
     case OpCode.Ldind_r8:
     case OpCode.Ldind_ref:
     case OpCode.Stind_ref:
     case OpCode.Stind_i1:
     case OpCode.Stind_i2:
     case OpCode.Stind_i4:
     case OpCode.Stind_i8:
     case OpCode.Stind_r4:
     case OpCode.Stind_r8:
     case OpCode.Add:
     case OpCode.Sub:
     case OpCode.Mul:
     case OpCode.Div:
     case OpCode.Div_un:
     case OpCode.Rem:
     case OpCode.Rem_un:
     case OpCode.And:
     case OpCode.Or:
     case OpCode.Xor:
     case OpCode.Shl:
     case OpCode.Shr:
     case OpCode.Shr_un:
     case OpCode.Neg:
     case OpCode.Not:
     case OpCode.Conv_i1:
     case OpCode.Conv_i2:
     case OpCode.Conv_i4:
     case OpCode.Conv_i8:
     case OpCode.Conv_r4:
     case OpCode.Conv_r8:
     case OpCode.Conv_u4:
     case OpCode.Conv_u8:
     case OpCode.Conv_r_un:
     case OpCode.Throw:
     case OpCode.Conv_ovf_i1_un:
     case OpCode.Conv_ovf_i2_un:
     case OpCode.Conv_ovf_i4_un:
     case OpCode.Conv_ovf_i8_un:
     case OpCode.Conv_ovf_u1_un:
     case OpCode.Conv_ovf_u2_un:
     case OpCode.Conv_ovf_u4_un:
     case OpCode.Conv_ovf_u8_un:
     case OpCode.Conv_ovf_i_un:
     case OpCode.Conv_ovf_u_un:
     case OpCode.Ldlen:
     case OpCode.Ldelem_i1:
     case OpCode.Ldelem_u1:
     case OpCode.Ldelem_i2:
     case OpCode.Ldelem_u2:
     case OpCode.Ldelem_i4:
     case OpCode.Ldelem_u4:
     case OpCode.Ldelem_i8:
     case OpCode.Ldelem_i:
     case OpCode.Ldelem_r4:
     case OpCode.Ldelem_r8:
     case OpCode.Ldelem_ref:
     case OpCode.Stelem_i:
     case OpCode.Stelem_i1:
     case OpCode.Stelem_i2:
     case OpCode.Stelem_i4:
     case OpCode.Stelem_i8:
     case OpCode.Stelem_r4:
     case OpCode.Stelem_r8:
     case OpCode.Stelem_ref:
     case OpCode.Conv_ovf_i1:
     case OpCode.Conv_ovf_u1:
     case OpCode.Conv_ovf_i2:
     case OpCode.Conv_ovf_u2:
     case OpCode.Conv_ovf_i4:
     case OpCode.Conv_ovf_u4:
     case OpCode.Conv_ovf_i8:
     case OpCode.Conv_ovf_u8:
     case OpCode.Ckfinite:
     case OpCode.Conv_u2:
     case OpCode.Conv_u1:
     case OpCode.Conv_i:
     case OpCode.Conv_ovf_i:
     case OpCode.Conv_ovf_u:
     case OpCode.Add_ovf:
     case OpCode.Add_ovf_un:
     case OpCode.Mul_ovf:
     case OpCode.Mul_ovf_un:
     case OpCode.Sub_ovf:
     case OpCode.Sub_ovf_un:
     case OpCode.Endfinally:
     case OpCode.Stind_i:
     case OpCode.Conv_u:
     case OpCode.Prefix7:
     case OpCode.Prefix6:
     case OpCode.Prefix5:
     case OpCode.Prefix4:
     case OpCode.Prefix3:
     case OpCode.Prefix2:
     case OpCode.Prefix1:
     case OpCode.Prefixref:
     case OpCode.Arglist:
     case OpCode.Ceq:
     case OpCode.Cgt:
     case OpCode.Cgt_un:
     case OpCode.Clt:
     case OpCode.Clt_un:
     case OpCode.Localloc:
     case OpCode.Endfilter:
     case OpCode.Volatile:
     case OpCode.Tailcall:
     case OpCode.Cpblk:
     case OpCode.Initblk:
     case OpCode.Rethrow:
     case OpCode.Refanytype:
     case OpCode.Readonly:
         break;
     case OpCode.Br:
     case OpCode.Brfalse:
     case OpCode.Brtrue:
     case OpCode.Beq:
     case OpCode.Bge:
     case OpCode.Bgt:
     case OpCode.Ble:
     case OpCode.Blt:
     case OpCode.Bne_un:
     case OpCode.Bge_un:
     case OpCode.Bgt_un:
     case OpCode.Ble_un:
     case OpCode.Blt_un:
     case OpCode.Leave:
         {
             // NOTE: Delta is w.r.t. start of next instruction
             var delta = reader.ReadInt32();
             Value = (int)(reader.Offset - beginOffset) + delta;
         }
         break;
     case OpCode.Br_s:
     case OpCode.Brfalse_s:
     case OpCode.Brtrue_s:
     case OpCode.Beq_s:
     case OpCode.Bge_s:
     case OpCode.Bgt_s:
     case OpCode.Ble_s:
     case OpCode.Blt_s:
     case OpCode.Bne_un_s:
     case OpCode.Bge_un_s:
     case OpCode.Bgt_un_s:
     case OpCode.Ble_un_s:
     case OpCode.Blt_un_s:
     case OpCode.Leave_s:
         {
             var delta = reader.ReadSByte();
             Value = (int)(reader.Offset - beginOffset) + delta;
         }
         break;
     case OpCode.Ldc_i4_s:
         Value = (int)reader.ReadSByte();
         break;
     case OpCode.Unaligned:
     case OpCode.Ldarg_s:
     case OpCode.Ldarga_s:
     case OpCode.Starg_s:
     case OpCode.Ldloc_s:
     case OpCode.Ldloca_s:
     case OpCode.Stloc_s:
         Value = (int)reader.ReadByte();
         break;
     case OpCode.Ldc_i4:
         Value = reader.ReadInt32();
         break;
     case OpCode.Ldarg:
     case OpCode.Ldarga:
     case OpCode.Starg:
     case OpCode.Ldloc:
     case OpCode.Ldloca:
     case OpCode.Stloc:
         Value = (int)reader.ReadUInt32();
         break;
     case OpCode.Ldc_i8:
         Value = reader.ReadInt64();
         break;
     case OpCode.Ldc_r4:
         Value = reader.ReadSingle();
         break;
     case OpCode.Ldc_r8:
         Value = reader.ReadDouble();
         break;
     case OpCode.Ldstr:
         Value = ReadUserString(ctxt, reader);
         break;
     case OpCode.Switch:
         {
             var numTargets = (int)reader.ReadUInt32();
             var targets = new Seq<int>(numTargets);
             // Read as offsets from end of switch, then fixup to offsets from start of instructions
             for (var i = 0; i < numTargets; i++)
                 targets.Add(reader.ReadInt32());
             for (var i = 0; i < numTargets; i++)
                 targets[i] = (int)(reader.Offset - beginOffset) + targets[i];
             Value = targets;
         }
         break;
     case OpCode.Calli:
     case OpCode.Ldfld:
     case OpCode.Ldflda:
     case OpCode.Stfld:
     case OpCode.Ldsfld:
     case OpCode.Ldsflda:
     case OpCode.Stsfld:
     case OpCode.Jmp:
     case OpCode.Call:
     case OpCode.Callvirt:
     case OpCode.Newobj:
     case OpCode.Ldftn:
     case OpCode.Ldvirtftn:
     case OpCode.Ldtoken:
     case OpCode.Cpobj:
     case OpCode.Ldobj:
     case OpCode.Castclass:
     case OpCode.Isinst:
     case OpCode.Unbox:
     case OpCode.Stobj:
     case OpCode.Box:
     case OpCode.Newarr:
     case OpCode.Ldelema:
     case OpCode.Ldelem:
     case OpCode.Stelem:
     case OpCode.Unbox_any:
     case OpCode.Refanyval:
     case OpCode.Mkrefany:
     case OpCode.Initobj:
     case OpCode.Constrained:
     case OpCode.Sizeof:
         Value = resolveRow(OpCode, ReadToken(ctxt, reader));
         break;
     default:
         throw new PEException("unrecognised opcode");
     }
 }
예제 #3
0
        public void Read(ReaderContext ctxt, BlobReader reader, uint beginOffset, Func <OpCode, Row, object> resolveRow)
        {
            Offset = (int)(reader.Offset - beginOffset);
            OpCode = (OpCode)reader.ReadByte();
            if (OpCode == OpCode.Prefix1)
            {
                OpCode = (OpCode)((ushort)OpCode << 8 | reader.ReadByte());
            }
            Value = default(object);
            switch (OpCode)
            {
            case OpCode.Nop:
            case OpCode.Break:
            case OpCode.Ldarg_0:
            case OpCode.Ldarg_1:
            case OpCode.Ldarg_2:
            case OpCode.Ldarg_3:
            case OpCode.Ldloc_0:
            case OpCode.Ldloc_1:
            case OpCode.Ldloc_2:
            case OpCode.Ldloc_3:
            case OpCode.Stloc_0:
            case OpCode.Stloc_1:
            case OpCode.Stloc_2:
            case OpCode.Stloc_3:
            case OpCode.Ldnull:
            case OpCode.Ldc_i4_m1:
            case OpCode.Ldc_i4_0:
            case OpCode.Ldc_i4_1:
            case OpCode.Ldc_i4_2:
            case OpCode.Ldc_i4_3:
            case OpCode.Ldc_i4_4:
            case OpCode.Ldc_i4_5:
            case OpCode.Ldc_i4_6:
            case OpCode.Ldc_i4_7:
            case OpCode.Ldc_i4_8:
            case OpCode.Dup:
            case OpCode.Pop:
            case OpCode.Ret:
            case OpCode.Ldind_i1:
            case OpCode.Ldind_u1:
            case OpCode.Ldind_i2:
            case OpCode.Ldind_u2:
            case OpCode.Ldind_i4:
            case OpCode.Ldind_u4:
            case OpCode.Ldind_i8:
            case OpCode.Ldind_i:
            case OpCode.Ldind_r4:
            case OpCode.Ldind_r8:
            case OpCode.Ldind_ref:
            case OpCode.Stind_ref:
            case OpCode.Stind_i1:
            case OpCode.Stind_i2:
            case OpCode.Stind_i4:
            case OpCode.Stind_i8:
            case OpCode.Stind_r4:
            case OpCode.Stind_r8:
            case OpCode.Add:
            case OpCode.Sub:
            case OpCode.Mul:
            case OpCode.Div:
            case OpCode.Div_un:
            case OpCode.Rem:
            case OpCode.Rem_un:
            case OpCode.And:
            case OpCode.Or:
            case OpCode.Xor:
            case OpCode.Shl:
            case OpCode.Shr:
            case OpCode.Shr_un:
            case OpCode.Neg:
            case OpCode.Not:
            case OpCode.Conv_i1:
            case OpCode.Conv_i2:
            case OpCode.Conv_i4:
            case OpCode.Conv_i8:
            case OpCode.Conv_r4:
            case OpCode.Conv_r8:
            case OpCode.Conv_u4:
            case OpCode.Conv_u8:
            case OpCode.Conv_r_un:
            case OpCode.Throw:
            case OpCode.Conv_ovf_i1_un:
            case OpCode.Conv_ovf_i2_un:
            case OpCode.Conv_ovf_i4_un:
            case OpCode.Conv_ovf_i8_un:
            case OpCode.Conv_ovf_u1_un:
            case OpCode.Conv_ovf_u2_un:
            case OpCode.Conv_ovf_u4_un:
            case OpCode.Conv_ovf_u8_un:
            case OpCode.Conv_ovf_i_un:
            case OpCode.Conv_ovf_u_un:
            case OpCode.Ldlen:
            case OpCode.Ldelem_i1:
            case OpCode.Ldelem_u1:
            case OpCode.Ldelem_i2:
            case OpCode.Ldelem_u2:
            case OpCode.Ldelem_i4:
            case OpCode.Ldelem_u4:
            case OpCode.Ldelem_i8:
            case OpCode.Ldelem_i:
            case OpCode.Ldelem_r4:
            case OpCode.Ldelem_r8:
            case OpCode.Ldelem_ref:
            case OpCode.Stelem_i:
            case OpCode.Stelem_i1:
            case OpCode.Stelem_i2:
            case OpCode.Stelem_i4:
            case OpCode.Stelem_i8:
            case OpCode.Stelem_r4:
            case OpCode.Stelem_r8:
            case OpCode.Stelem_ref:
            case OpCode.Conv_ovf_i1:
            case OpCode.Conv_ovf_u1:
            case OpCode.Conv_ovf_i2:
            case OpCode.Conv_ovf_u2:
            case OpCode.Conv_ovf_i4:
            case OpCode.Conv_ovf_u4:
            case OpCode.Conv_ovf_i8:
            case OpCode.Conv_ovf_u8:
            case OpCode.Ckfinite:
            case OpCode.Conv_u2:
            case OpCode.Conv_u1:
            case OpCode.Conv_i:
            case OpCode.Conv_ovf_i:
            case OpCode.Conv_ovf_u:
            case OpCode.Add_ovf:
            case OpCode.Add_ovf_un:
            case OpCode.Mul_ovf:
            case OpCode.Mul_ovf_un:
            case OpCode.Sub_ovf:
            case OpCode.Sub_ovf_un:
            case OpCode.Endfinally:
            case OpCode.Stind_i:
            case OpCode.Conv_u:
            case OpCode.Prefix7:
            case OpCode.Prefix6:
            case OpCode.Prefix5:
            case OpCode.Prefix4:
            case OpCode.Prefix3:
            case OpCode.Prefix2:
            case OpCode.Prefix1:
            case OpCode.Prefixref:
            case OpCode.Arglist:
            case OpCode.Ceq:
            case OpCode.Cgt:
            case OpCode.Cgt_un:
            case OpCode.Clt:
            case OpCode.Clt_un:
            case OpCode.Localloc:
            case OpCode.Endfilter:
            case OpCode.Volatile:
            case OpCode.Tailcall:
            case OpCode.Cpblk:
            case OpCode.Initblk:
            case OpCode.Rethrow:
            case OpCode.Refanytype:
            case OpCode.Readonly:
                break;

            case OpCode.Br:
            case OpCode.Brfalse:
            case OpCode.Brtrue:
            case OpCode.Beq:
            case OpCode.Bge:
            case OpCode.Bgt:
            case OpCode.Ble:
            case OpCode.Blt:
            case OpCode.Bne_un:
            case OpCode.Bge_un:
            case OpCode.Bgt_un:
            case OpCode.Ble_un:
            case OpCode.Blt_un:
            case OpCode.Leave:
            {
                // NOTE: Delta is w.r.t. start of next instruction
                var delta = reader.ReadInt32();
                Value = (int)(reader.Offset - beginOffset) + delta;
            }
            break;

            case OpCode.Br_s:
            case OpCode.Brfalse_s:
            case OpCode.Brtrue_s:
            case OpCode.Beq_s:
            case OpCode.Bge_s:
            case OpCode.Bgt_s:
            case OpCode.Ble_s:
            case OpCode.Blt_s:
            case OpCode.Bne_un_s:
            case OpCode.Bge_un_s:
            case OpCode.Bgt_un_s:
            case OpCode.Ble_un_s:
            case OpCode.Blt_un_s:
            case OpCode.Leave_s:
            {
                var delta = reader.ReadSByte();
                Value = (int)(reader.Offset - beginOffset) + delta;
            }
            break;

            case OpCode.Ldc_i4_s:
                Value = (int)reader.ReadSByte();
                break;

            case OpCode.Unaligned:
            case OpCode.Ldarg_s:
            case OpCode.Ldarga_s:
            case OpCode.Starg_s:
            case OpCode.Ldloc_s:
            case OpCode.Ldloca_s:
            case OpCode.Stloc_s:
                Value = (int)reader.ReadByte();
                break;

            case OpCode.Ldc_i4:
                Value = reader.ReadInt32();
                break;

            case OpCode.Ldarg:
            case OpCode.Ldarga:
            case OpCode.Starg:
            case OpCode.Ldloc:
            case OpCode.Ldloca:
            case OpCode.Stloc:
                Value = (int)reader.ReadUInt32();
                break;

            case OpCode.Ldc_i8:
                Value = reader.ReadInt64();
                break;

            case OpCode.Ldc_r4:
                Value = reader.ReadSingle();
                break;

            case OpCode.Ldc_r8:
                Value = reader.ReadDouble();
                break;

            case OpCode.Ldstr:
                Value = ReadUserString(ctxt, reader);
                break;

            case OpCode.Switch:
            {
                var numTargets = (int)reader.ReadUInt32();
                var targets    = new Seq <int>(numTargets);
                // Read as offsets from end of switch, then fixup to offsets from start of instructions
                for (var i = 0; i < numTargets; i++)
                {
                    targets.Add(reader.ReadInt32());
                }
                for (var i = 0; i < numTargets; i++)
                {
                    targets[i] = (int)(reader.Offset - beginOffset) + targets[i];
                }
                Value = targets;
            }
            break;

            case OpCode.Calli:
            case OpCode.Ldfld:
            case OpCode.Ldflda:
            case OpCode.Stfld:
            case OpCode.Ldsfld:
            case OpCode.Ldsflda:
            case OpCode.Stsfld:
            case OpCode.Jmp:
            case OpCode.Call:
            case OpCode.Callvirt:
            case OpCode.Newobj:
            case OpCode.Ldftn:
            case OpCode.Ldvirtftn:
            case OpCode.Ldtoken:
            case OpCode.Cpobj:
            case OpCode.Ldobj:
            case OpCode.Castclass:
            case OpCode.Isinst:
            case OpCode.Unbox:
            case OpCode.Stobj:
            case OpCode.Box:
            case OpCode.Newarr:
            case OpCode.Ldelema:
            case OpCode.Ldelem:
            case OpCode.Stelem:
            case OpCode.Unbox_any:
            case OpCode.Refanyval:
            case OpCode.Mkrefany:
            case OpCode.Initobj:
            case OpCode.Constrained:
            case OpCode.Sizeof:
                Value = resolveRow(OpCode, ReadToken(ctxt, reader));
                break;

            default:
                throw new PEException("unrecognised opcode");
            }
        }
예제 #4
0
        public static void Skip(BlobReader reader)
        {
            var opCode = (OpCode)reader.ReadByte();

            if (opCode == OpCode.Prefix1)
            {
                opCode = (OpCode)((ushort)opCode << 8 | reader.ReadByte());
            }
            switch (opCode)
            {
            case OpCode.Nop:
            case OpCode.Break:
            case OpCode.Ldarg_0:
            case OpCode.Ldarg_1:
            case OpCode.Ldarg_2:
            case OpCode.Ldarg_3:
            case OpCode.Ldloc_0:
            case OpCode.Ldloc_1:
            case OpCode.Ldloc_2:
            case OpCode.Ldloc_3:
            case OpCode.Stloc_0:
            case OpCode.Stloc_1:
            case OpCode.Stloc_2:
            case OpCode.Stloc_3:
            case OpCode.Ldnull:
            case OpCode.Ldc_i4_m1:
            case OpCode.Ldc_i4_0:
            case OpCode.Ldc_i4_1:
            case OpCode.Ldc_i4_2:
            case OpCode.Ldc_i4_3:
            case OpCode.Ldc_i4_4:
            case OpCode.Ldc_i4_5:
            case OpCode.Ldc_i4_6:
            case OpCode.Ldc_i4_7:
            case OpCode.Ldc_i4_8:
            case OpCode.Dup:
            case OpCode.Pop:
            case OpCode.Ret:
            case OpCode.Ldind_i1:
            case OpCode.Ldind_u1:
            case OpCode.Ldind_i2:
            case OpCode.Ldind_u2:
            case OpCode.Ldind_i4:
            case OpCode.Ldind_u4:
            case OpCode.Ldind_i8:
            case OpCode.Ldind_i:
            case OpCode.Ldind_r4:
            case OpCode.Ldind_r8:
            case OpCode.Ldind_ref:
            case OpCode.Stind_ref:
            case OpCode.Stind_i1:
            case OpCode.Stind_i2:
            case OpCode.Stind_i4:
            case OpCode.Stind_i8:
            case OpCode.Stind_r4:
            case OpCode.Stind_r8:
            case OpCode.Add:
            case OpCode.Sub:
            case OpCode.Mul:
            case OpCode.Div:
            case OpCode.Div_un:
            case OpCode.Rem:
            case OpCode.Rem_un:
            case OpCode.And:
            case OpCode.Or:
            case OpCode.Xor:
            case OpCode.Shl:
            case OpCode.Shr:
            case OpCode.Shr_un:
            case OpCode.Neg:
            case OpCode.Not:
            case OpCode.Conv_i1:
            case OpCode.Conv_i2:
            case OpCode.Conv_i4:
            case OpCode.Conv_i8:
            case OpCode.Conv_r4:
            case OpCode.Conv_r8:
            case OpCode.Conv_u4:
            case OpCode.Conv_u8:
            case OpCode.Conv_r_un:
            case OpCode.Throw:
            case OpCode.Conv_ovf_i1_un:
            case OpCode.Conv_ovf_i2_un:
            case OpCode.Conv_ovf_i4_un:
            case OpCode.Conv_ovf_i8_un:
            case OpCode.Conv_ovf_u1_un:
            case OpCode.Conv_ovf_u2_un:
            case OpCode.Conv_ovf_u4_un:
            case OpCode.Conv_ovf_u8_un:
            case OpCode.Conv_ovf_i_un:
            case OpCode.Conv_ovf_u_un:
            case OpCode.Ldlen:
            case OpCode.Ldelem_i1:
            case OpCode.Ldelem_u1:
            case OpCode.Ldelem_i2:
            case OpCode.Ldelem_u2:
            case OpCode.Ldelem_i4:
            case OpCode.Ldelem_u4:
            case OpCode.Ldelem_i8:
            case OpCode.Ldelem_i:
            case OpCode.Ldelem_r4:
            case OpCode.Ldelem_r8:
            case OpCode.Ldelem_ref:
            case OpCode.Stelem_i:
            case OpCode.Stelem_i1:
            case OpCode.Stelem_i2:
            case OpCode.Stelem_i4:
            case OpCode.Stelem_i8:
            case OpCode.Stelem_r4:
            case OpCode.Stelem_r8:
            case OpCode.Stelem_ref:
            case OpCode.Conv_ovf_i1:
            case OpCode.Conv_ovf_u1:
            case OpCode.Conv_ovf_i2:
            case OpCode.Conv_ovf_u2:
            case OpCode.Conv_ovf_i4:
            case OpCode.Conv_ovf_u4:
            case OpCode.Conv_ovf_i8:
            case OpCode.Conv_ovf_u8:
            case OpCode.Ckfinite:
            case OpCode.Conv_u2:
            case OpCode.Conv_u1:
            case OpCode.Conv_i:
            case OpCode.Conv_ovf_i:
            case OpCode.Conv_ovf_u:
            case OpCode.Add_ovf:
            case OpCode.Add_ovf_un:
            case OpCode.Mul_ovf:
            case OpCode.Mul_ovf_un:
            case OpCode.Sub_ovf:
            case OpCode.Sub_ovf_un:
            case OpCode.Endfinally:
            case OpCode.Stind_i:
            case OpCode.Conv_u:
            case OpCode.Prefix7:
            case OpCode.Prefix6:
            case OpCode.Prefix5:
            case OpCode.Prefix4:
            case OpCode.Prefix3:
            case OpCode.Prefix2:
            case OpCode.Prefix1:
            case OpCode.Prefixref:
            case OpCode.Arglist:
            case OpCode.Ceq:
            case OpCode.Cgt:
            case OpCode.Cgt_un:
            case OpCode.Clt:
            case OpCode.Clt_un:
            case OpCode.Localloc:
            case OpCode.Endfilter:
            case OpCode.Volatile:
            case OpCode.Tailcall:
            case OpCode.Cpblk:
            case OpCode.Initblk:
            case OpCode.Rethrow:
            case OpCode.Refanytype:
            case OpCode.Readonly:
                break;

            case OpCode.Br_s:
            case OpCode.Brfalse_s:
            case OpCode.Brtrue_s:
            case OpCode.Beq_s:
            case OpCode.Bge_s:
            case OpCode.Bgt_s:
            case OpCode.Ble_s:
            case OpCode.Blt_s:
            case OpCode.Bne_un_s:
            case OpCode.Bge_un_s:
            case OpCode.Bgt_un_s:
            case OpCode.Ble_un_s:
            case OpCode.Blt_un_s:
            case OpCode.Leave_s:
            case OpCode.Ldc_i4_s:
                reader.ReadSByte();
                break;

            case OpCode.Unaligned:
            case OpCode.Ldarg_s:
            case OpCode.Ldarga_s:
            case OpCode.Starg_s:
            case OpCode.Ldloc_s:
            case OpCode.Ldloca_s:
            case OpCode.Stloc_s:
                reader.ReadByte();
                break;

            case OpCode.Br:
            case OpCode.Brfalse:
            case OpCode.Brtrue:
            case OpCode.Beq:
            case OpCode.Bge:
            case OpCode.Bgt:
            case OpCode.Ble:
            case OpCode.Blt:
            case OpCode.Bne_un:
            case OpCode.Bge_un:
            case OpCode.Bgt_un:
            case OpCode.Ble_un:
            case OpCode.Blt_un:
            case OpCode.Leave:
            case OpCode.Ldc_i4:
                reader.ReadInt32();
                break;

            case OpCode.Ldfld:
            case OpCode.Ldflda:
            case OpCode.Stfld:
            case OpCode.Ldsfld:
            case OpCode.Ldsflda:
            case OpCode.Stsfld:
            case OpCode.Calli:
            case OpCode.Ldstr:
            case OpCode.Ldtoken:
            case OpCode.Cpobj:
            case OpCode.Ldobj:
            case OpCode.Castclass:
            case OpCode.Isinst:
            case OpCode.Unbox:
            case OpCode.Stobj:
            case OpCode.Box:
            case OpCode.Newarr:
            case OpCode.Ldelema:
            case OpCode.Ldelem:
            case OpCode.Stelem:
            case OpCode.Unbox_any:
            case OpCode.Refanyval:
            case OpCode.Mkrefany:
            case OpCode.Initobj:
            case OpCode.Constrained:
            case OpCode.Sizeof:
            case OpCode.Ldarg:
            case OpCode.Ldarga:
            case OpCode.Starg:
            case OpCode.Ldloc:
            case OpCode.Ldloca:
            case OpCode.Stloc:
            case OpCode.Jmp:
            case OpCode.Call:
            case OpCode.Callvirt:
            case OpCode.Newobj:
            case OpCode.Ldftn:
            case OpCode.Ldvirtftn:
                reader.ReadUInt32();
                break;

            case OpCode.Ldc_i8:
                reader.ReadInt64();
                break;

            case OpCode.Ldc_r4:
                reader.ReadSingle();
                break;

            case OpCode.Ldc_r8:
                reader.ReadDouble();
                break;

            case OpCode.Switch:
            {
                var numTargets = (int)reader.ReadUInt32();
                for (var i = 0; i < numTargets; i++)
                {
                    reader.ReadInt32();
                }
                break;
            }

            default:
                throw new PEException("unrecognised opcode");
            }
        }
예제 #5
0
 public override object ReadValue(BlobReader reader, Func<string, CustomAttributePropertyType> resolveType)
 {
     switch (Type)
     {
     case PrimitiveType.Boolean:
         return reader.ReadByte() == 0 ? false : true;
     case PrimitiveType.Char:
         return (char)reader.ReadUInt16();
     case PrimitiveType.Int8:
         return reader.ReadSByte();
     case PrimitiveType.Int16:
         return reader.ReadInt16();
     case PrimitiveType.Int32:
         return reader.ReadInt32();
     case PrimitiveType.Int64:
         return reader.ReadInt64();
     case PrimitiveType.UInt8:
         return reader.ReadByte();
     case PrimitiveType.UInt16:
         return reader.ReadUInt16();
     case PrimitiveType.UInt32:
         return reader.ReadUInt32();
     case PrimitiveType.UInt64:
         return reader.ReadUInt64();
     case PrimitiveType.IntNative:
     case PrimitiveType.UIntNative:
         throw new PEException("cannot read native integers");
     case PrimitiveType.Single:
         return reader.ReadSingle();
     case PrimitiveType.Double:
         return reader.ReadDouble();
     case PrimitiveType.String:
         return reader.ReadUTF8SizedString();
     case PrimitiveType.Type:
         return new TypeCustomAttributePropertyValue { Name = reader.ReadUTF8SizedString() };
     case PrimitiveType.Object:
     case PrimitiveType.TypedRef:
     case PrimitiveType.Void:
         throw new PEException("invalid type tag in custom attribute");
     default:
         throw new ArgumentOutOfRangeException();
     }
 }