Beispiel #1
0
        public static DisassembledInstruction DisassembleInstructionAt(byte[] chunks, int byteIndex, uint startOffset)
        {
            if (byteIndex >= chunks.Length)
                return null;

            // NOTE: offset needs to be right for branching to get correct values
            var cur = new DisassembledInstruction { Offset = startOffset, RollingByteIndex = byteIndex };

            // always use opCode.RollingByteIndex, as the functions update how much they moved forward
            if (chunks[cur.RollingByteIndex] > 0xE0)
                ReadPrefix(chunks, cur);

            // single byte instruction
            if (chunks[cur.RollingByteIndex] <= 0xE0)
                ReadSingleByteInstruction(chunks, cur);
            else
                ReadTwoByteInstruction(chunks, cur);

            cur.Size = cur.RollingByteIndex - byteIndex;
            return cur;
        }
Beispiel #2
0
        private static void ReadParameter(DisassembledInstruction dec, byte[] chunks, ArgType type, bool isPrefixVal)
        {
            if (isPrefixVal)
                dec.PrefixType = type;
            else
                dec.ArgType = type;

            if (type == ArgType.None)
                return;

            int curIdx = dec.RollingByteIndex;
            double? parsedVal = null;

            switch (type)
            {
                case ArgType.SmallBranch:
                case ArgType.Byte:
                case ArgType.Char:
                case ArgType.UChar:
                    if (type != ArgType.UChar)
                        parsedVal = chunks[curIdx];
                    else
                        parsedVal = ((sbyte)chunks[curIdx]);
                    ++curIdx;
                    break;
                case ArgType.Short:
                    if (EnsureRoom(chunks, curIdx, 2))
                    {
                        parsedVal = BitConverter.ToInt16(chunks, curIdx);
                        curIdx += 2;
                    }
                    break;
                case ArgType.UShort:
                    if (EnsureRoom(chunks, curIdx, 2))
                    {
                        parsedVal = BitConverter.ToUInt16(chunks, curIdx);
                        curIdx += 2;
                    }
                    break;
                case ArgType.Token:
                case ArgType.UInt:
                case ArgType.Branch:
                case ArgType.Dword:
                    if (EnsureRoom(chunks, curIdx, 4))
                    {
                        parsedVal = BitConverter.ToUInt32(chunks, curIdx);
                        curIdx += 4;
                    }
                    break;
                case ArgType.Int:
                    if (EnsureRoom(chunks, curIdx, 4))
                    {
                        parsedVal = BitConverter.ToInt32(chunks, curIdx);
                        curIdx += 4;
                    }
                    break;
                case ArgType.Qword:
                    if (EnsureRoom(chunks, curIdx, 8))
                    {
                        parsedVal = BitConverter.ToUInt64(chunks, curIdx);
                        curIdx += 8;
                    }
                    break;
                case ArgType.Int64:
                    if (EnsureRoom(chunks, curIdx, 8))
                    {
                        parsedVal = BitConverter.ToInt64(chunks, curIdx);
                        curIdx += 8;
                    }
                    break;
                case ArgType.Switch:
                    // first uint -> # of uints follow it, its an array of switch offsets
                    // [dword #1] ([dword] [dword] .... ) x #1
                    if (EnsureRoom(chunks, curIdx, 4))
                    {
                        int switchOffsetsCount = BitConverter.ToInt32(chunks, curIdx);
                        curIdx += 4;
                        // TODO: does the array of offsets need to be saved?
                        int switchByteSize = 4 * switchOffsetsCount;
                        if (EnsureRoom(chunks, curIdx, switchByteSize))
                            curIdx += switchByteSize;
                    }
                    break;
            }

            if (parsedVal != null)
            {
                if (isPrefixVal)
                    dec.PrefixValue = parsedVal.Value;
                else
                    dec.ArgValue = parsedVal.Value;
            }
            // dont forget to update this, wups
            dec.RollingByteIndex = curIdx;
        }
Beispiel #3
0
 private static void SetPrefix(DisassembledInstruction dec, Prefix prefix, byte[] chunks, ArgType type)
 {
     dec.PrefixType  = type;
     dec.Prefix      = prefix;
     ReadParameter(dec, chunks, type, true);
 }
Beispiel #4
0
 private static void SetInstruction(DisassembledInstruction dec, Instruction instr, byte[] chunks, ArgType type)
 {
     dec.Instruction = instr;
     ReadParameter(dec, chunks, type, false);
 }
Beispiel #5
0
 // for instructions with no parameters (which i incorrectly call args ;)
 private static void SetInstruction(DisassembledInstruction dec, Instruction instr)
 {
     dec.Instruction     = instr;
     dec.ArgType         = ArgType.None;
 }
Beispiel #6
0
 private static bool ReadTwoByteInstruction(byte[] chunks, DisassembledInstruction dec)
 {
     ushort opChunk = BitConverter.ToUInt16(chunks, dec.RollingByteIndex);
     dec.RollingByteIndex += 2; // opcode size
     switch ((OpCode)opChunk)
     {
         case OpCode.ARGLIST:        SetInstruction(dec, Instruction.Arglist);                         break;
         case OpCode.CEQ:            SetInstruction(dec, Instruction.Ceq);                             break;
         case OpCode.CGT:            SetInstruction(dec, Instruction.Cgt);                             break;
         case OpCode.CGT_UN:         SetInstruction(dec, Instruction.Cgt_un);                          break;
         case OpCode.CLT:            SetInstruction(dec, Instruction.Clt);                             break;
         case OpCode.CLT_UN:         SetInstruction(dec, Instruction.Clt);                             break;
         case OpCode.LDFTN:          SetInstruction(dec, Instruction.Ldftn, chunks, ArgType.Token);    break;
         case OpCode.LDVIRTFTN:      SetInstruction(dec, Instruction.Ldvirtftn, chunks, ArgType.Token); break;
         case OpCode.LDARG:          SetInstruction(dec, Instruction.Ldarg, chunks, ArgType.UShort);   break;
         case OpCode.LDARGA:         SetInstruction(dec, Instruction.Ldarga, chunks, ArgType.UShort);  break;
         case OpCode.STARG:          SetInstruction(dec, Instruction.Starg, chunks, ArgType.UShort);   break;
         case OpCode.LDLOC:          SetInstruction(dec, Instruction.Ldloc, chunks, ArgType.UShort);   break;
         case OpCode.LDLOCA:         SetInstruction(dec, Instruction.Ldloca, chunks, ArgType.UShort);  break;
         case OpCode.STLOC:          SetInstruction(dec, Instruction.Stloc, chunks, ArgType.UShort);   break;
         case OpCode.LOCALLOC:       SetInstruction(dec, Instruction.Localloc);                        break;
         case OpCode.ENDFILTER:      SetInstruction(dec, Instruction.Endfilter);                       break;
         case OpCode.INITOBJ:        SetInstruction(dec, Instruction.Initobj, chunks, ArgType.Token);  break;
         case OpCode.CPBLK:          SetInstruction(dec, Instruction.Cpblk);                           break;
         case OpCode.RETHROW:        SetInstruction(dec, Instruction.Rethrow);                         break;
         case OpCode.SIZEOF:         SetInstruction(dec, Instruction.Sizeof, chunks, ArgType.Token);   break;
         case OpCode.REFANYTYPE_V2:  SetInstruction(dec, Instruction.Refanytype_v2);                   break;
         default: return false;
     }
     return true;
 }
Beispiel #7
0
 private static bool ReadSingleByteInstruction(byte[] chunks, DisassembledInstruction dec)
 {
     byte opChunk = chunks[dec.RollingByteIndex];
     ++dec.RollingByteIndex;
     // yep. nothing clever here, sorry
     switch ((OpCode)opChunk)
     {
         case OpCode.NOP:                SetInstruction(dec, Instruction.Nop);                                     break;
         case OpCode.BREAK:              SetInstruction(dec, Instruction.Break);                                   break;
         case OpCode.LDARG_0:            SetInstruction(dec, Instruction.Ldarg_0);                                 break;
         case OpCode.LDARG_1:            SetInstruction(dec, Instruction.Ldarg_1);                                 break;
         case OpCode.LDARG_2:            SetInstruction(dec, Instruction.Ldarg_2);                                 break;
         case OpCode.LDARG_3:            SetInstruction(dec, Instruction.Ldarg_3);                                 break;
         case OpCode.LDLOC_0:            SetInstruction(dec, Instruction.Ldloc_0);                                 break;
         case OpCode.LDLOC_1:            SetInstruction(dec, Instruction.Ldloc_1);                                 break;
         case OpCode.LDLOC_2:            SetInstruction(dec, Instruction.Ldloc_2);                                 break;
         case OpCode.LDLOC_3:            SetInstruction(dec, Instruction.Ldloc_3);                                 break;
         case OpCode.STLOC_0:            SetInstruction(dec, Instruction.Stloc_0);                                 break;
         case OpCode.STLOC_1:            SetInstruction(dec, Instruction.Stloc_1);                                 break;
         case OpCode.STLOC_2:            SetInstruction(dec, Instruction.Stloc_1);                                 break;
         case OpCode.STLOC_3:            SetInstruction(dec, Instruction.Stloc_1);                                 break;
         case OpCode.LDARG_S:            SetInstruction(dec, Instruction.Ldarg_s, chunks, ArgType.UChar);          break;
         case OpCode.LDARGA_S:           SetInstruction(dec, Instruction.Ldarga_s, chunks, ArgType.UChar);         break;
         case OpCode.STARG_S:            SetInstruction(dec, Instruction.Starg_s, chunks, ArgType.UChar);          break;
         case OpCode.LDLOC_S:            SetInstruction(dec, Instruction.Ldloc_s, chunks, ArgType.UChar);          break;
         case OpCode.LDLOCA_S:           SetInstruction(dec, Instruction.Ldloca_s, chunks, ArgType.UChar);         break;
         case OpCode.STLOC_S:            SetInstruction(dec, Instruction.Stloc_s, chunks, ArgType.UChar);          break;
         case OpCode.LDNULL:             SetInstruction(dec, Instruction.Ldnull);                                  break;
         case OpCode.LDC_I4_M1:          SetInstruction(dec, Instruction.Ldc_i4_m1);                               break;
         case OpCode.LDC_I4_0:           SetInstruction(dec, Instruction.Ldc_i4_0);                                break;
         case OpCode.LDC_I4_1:           SetInstruction(dec, Instruction.Ldc_i4_1);                                break;
         case OpCode.LDC_I4_2:           SetInstruction(dec, Instruction.Ldc_i4_2);                                break;
         case OpCode.LDC_I4_3:           SetInstruction(dec, Instruction.Ldc_i4_3);                                break;
         case OpCode.LDC_I4_4:           SetInstruction(dec, Instruction.Ldc_i4_4);                                break;
         case OpCode.LDC_I4_5:           SetInstruction(dec, Instruction.Ldc_i4_5);                                break;
         case OpCode.LDC_I4_6:           SetInstruction(dec, Instruction.Ldc_i4_6);                                break;
         case OpCode.LDC_I4_7:           SetInstruction(dec, Instruction.Ldc_i4_7);                                break;
         case OpCode.LDC_I4_8:           SetInstruction(dec, Instruction.Ldc_i4_8);                                break;
         case OpCode.LDC_I4_S:           SetInstruction(dec, Instruction.Ldc_i4_s, chunks, ArgType.Char);          break;
         case OpCode.LDC_I4:             SetInstruction(dec, Instruction.Ldc_i4, chunks, ArgType.Int);             break;
         case OpCode.LDC_I8:             SetInstruction(dec, Instruction.Ldc_i8, chunks, ArgType.Int64);           break;
         case OpCode.LDC_R4:             SetInstruction(dec, Instruction.Ldc_r4, chunks, ArgType.Dword);           break;
         case OpCode.LDC_R8:             SetInstruction(dec, Instruction.Ldc_r8, chunks, ArgType.Qword);           break;
         case OpCode.DUP:                SetInstruction(dec, Instruction.Dup);                                     break;
         case OpCode.POP:                SetInstruction(dec, Instruction.Pop);                                     break;
         case OpCode.JMP:                SetInstruction(dec, Instruction.Jmp, chunks, ArgType.Dword);              break;
         case OpCode.CALL:               SetInstruction(dec, Instruction.Call, chunks, ArgType.Dword);             break;
         case OpCode.CALLI:              SetInstruction(dec, Instruction.Calli, chunks, ArgType.Dword);            break;
         case OpCode.RET:                SetInstruction(dec, Instruction.Ret);                                     break;
         case OpCode.BR_S:               SetInstruction(dec, Instruction.Br_s, chunks, ArgType.SmallBranch);       break;
         case OpCode.BRFALSE_S:          SetInstruction(dec, Instruction.Brfalse_s, chunks, ArgType.SmallBranch);  break;
         case OpCode.BRTRUE_S:           SetInstruction(dec, Instruction.Brtrue_s, chunks, ArgType.SmallBranch);   break;
         case OpCode.BEQ_S:              SetInstruction(dec, Instruction.Beq_s, chunks, ArgType.SmallBranch);      break;
         case OpCode.BGE_S:              SetInstruction(dec, Instruction.Bge_s, chunks, ArgType.SmallBranch);      break;
         case OpCode.BGT_S:              SetInstruction(dec, Instruction.Bgt_s, chunks, ArgType.SmallBranch);      break;
         case OpCode.BLE_S:              SetInstruction(dec, Instruction.Ble_s, chunks, ArgType.SmallBranch);      break;
         case OpCode.BLT_S:              SetInstruction(dec, Instruction.Blt_s, chunks, ArgType.SmallBranch);      break;
         case OpCode.BNE_UN_S:           SetInstruction(dec, Instruction.Bne_un_s, chunks, ArgType.SmallBranch);   break;
         case OpCode.BGE_UN_S:           SetInstruction(dec, Instruction.Bge_un_s, chunks, ArgType.SmallBranch);   break;
         case OpCode.BGT_UN_S:           SetInstruction(dec, Instruction.Bgt_un_s, chunks, ArgType.SmallBranch);   break;
         case OpCode.BLE_UN_S:           SetInstruction(dec, Instruction.Ble_un_s, chunks, ArgType.SmallBranch);   break;
         case OpCode.BLT_UN_S:           SetInstruction(dec, Instruction.Blt_un_s, chunks, ArgType.SmallBranch);   break;
         case OpCode.BR:                 SetInstruction(dec, Instruction.Br, chunks, ArgType.Branch);              break;
         case OpCode.BRFALSE:            SetInstruction(dec, Instruction.Brfalse, chunks, ArgType.Branch);         break;
         case OpCode.BRTRUE:             SetInstruction(dec, Instruction.Brtrue, chunks, ArgType.Branch);          break;
         case OpCode.BEQ:                SetInstruction(dec, Instruction.Beq, chunks, ArgType.Branch);             break;
         case OpCode.BGE:                SetInstruction(dec, Instruction.Bge, chunks, ArgType.Branch);             break;
         case OpCode.BGT:                SetInstruction(dec, Instruction.Bgt, chunks, ArgType.Branch);             break;
         case OpCode.BLE:                SetInstruction(dec, Instruction.Ble, chunks, ArgType.Branch);             break;
         case OpCode.BLT:                SetInstruction(dec, Instruction.Blt, chunks, ArgType.Branch);             break;
         case OpCode.BNE_UN:             SetInstruction(dec, Instruction.Bne_un, chunks, ArgType.Branch);          break;
         case OpCode.BGE_UN:             SetInstruction(dec, Instruction.Bge_un, chunks, ArgType.Branch);          break;
         case OpCode.BGT_UN:             SetInstruction(dec, Instruction.Bgt_un, chunks, ArgType.Branch);          break;
         case OpCode.BLE_UN:             SetInstruction(dec, Instruction.Ble_un, chunks, ArgType.Branch);          break;
         case OpCode.BLT_UN:             SetInstruction(dec, Instruction.Blt_un, chunks, ArgType.Branch);          break;
         case OpCode.SWITCH:             SetInstruction(dec, Instruction.Switch, chunks, ArgType.Switch);          break;
         case OpCode.LDIND_I1:           SetInstruction(dec, Instruction.Ldind_i1);                                break;
         case OpCode.LDIND_I2:           SetInstruction(dec, Instruction.Ldind_i2);                                break;
         case OpCode.LDIND_I4:           SetInstruction(dec, Instruction.Ldind_i4);                                break;
         case OpCode.LDIND_I8:           SetInstruction(dec, Instruction.Ldind_i8);                                break;
         case OpCode.LDIND_U1:           SetInstruction(dec, Instruction.Ldind_u1);                                break;
         case OpCode.LDIND_U2:           SetInstruction(dec, Instruction.Ldind_u2);                                break;
         case OpCode.LDIND_U4:           SetInstruction(dec, Instruction.Ldind_u4);                                break;
         case OpCode.LDIND_I:            SetInstruction(dec, Instruction.Ldind_i);                                 break;
         case OpCode.LDIND_R4:           SetInstruction(dec, Instruction.Ldind_r4);                                break;
         case OpCode.LDIND_R8:           SetInstruction(dec, Instruction.Ldind_r8);                                break;
         case OpCode.LDIND_REF:          SetInstruction(dec, Instruction.Ldind_ref);                               break;
         case OpCode.STIND_REF:          SetInstruction(dec, Instruction.Stind_ref);                               break;
         case OpCode.STIND_I1:           SetInstruction(dec, Instruction.Stind_i1);                                break;
         case OpCode.STIND_I2:           SetInstruction(dec, Instruction.Stind_i2);                                break;
         case OpCode.STIND_I4:           SetInstruction(dec, Instruction.Stind_i4);                                break;
         case OpCode.STIND_I8:           SetInstruction(dec, Instruction.Stind_i8);                                break;
         case OpCode.STIND_R4:           SetInstruction(dec, Instruction.Stind_r4);                                break;
         case OpCode.STIND_R8:           SetInstruction(dec, Instruction.Stind_r8);                                break;
         case OpCode.ADD:                SetInstruction(dec, Instruction.Add);                                     break;
         case OpCode.SUB:                SetInstruction(dec, Instruction.Sub);                                     break;
         case OpCode.MUL:                SetInstruction(dec, Instruction.Mul);                                     break;
         case OpCode.DIV:                SetInstruction(dec, Instruction.Div);                                     break;
         case OpCode.DIV_UN:             SetInstruction(dec, Instruction.Div_un);                                  break;
         case OpCode.REM:                SetInstruction(dec, Instruction.Rem);                                     break;
         case OpCode.REM_UN:             SetInstruction(dec, Instruction.Rem_un);                                  break;
         case OpCode.AND:                SetInstruction(dec, Instruction.And);                                     break;
         case OpCode.OR:                 SetInstruction(dec, Instruction.Or);                                      break;
         case OpCode.XOR:                SetInstruction(dec, Instruction.Xor);                                     break;
         case OpCode.SHL:                SetInstruction(dec, Instruction.Shl);                                     break;
         case OpCode.SHR:                SetInstruction(dec, Instruction.Shr);                                     break;
         case OpCode.SHR_UN:             SetInstruction(dec, Instruction.Shr_un);                                  break;
         case OpCode.NEG:                SetInstruction(dec, Instruction.Neg);                                     break;
         case OpCode.NOT:                SetInstruction(dec, Instruction.Not);                                     break;
         case OpCode.CONV_I1:            SetInstruction(dec, Instruction.Conv_i1);                                 break;
         case OpCode.CONV_I2:            SetInstruction(dec, Instruction.Conv_i2);                                 break;
         case OpCode.CONV_I4:            SetInstruction(dec, Instruction.Conv_i4);                                 break;
         case OpCode.CONV_I8:            SetInstruction(dec, Instruction.Conv_i8);                                 break;
         case OpCode.CONV_R4:            SetInstruction(dec, Instruction.Conv_r4);                                 break;
         case OpCode.CONV_R8:            SetInstruction(dec, Instruction.Conv_r8);                                 break;
         case OpCode.CONV_U4:            SetInstruction(dec, Instruction.Conv_u4);                                 break;
         case OpCode.CONV_U8:            SetInstruction(dec, Instruction.Conv_u8);                                 break;
         case OpCode.CALLVIRT:           SetInstruction(dec, Instruction.Callvirt, chunks, ArgType.Token);         break;
         case OpCode.CPOBJ:              SetInstruction(dec, Instruction.Cpobj, chunks, ArgType.Token);            break;
         case OpCode.LDOBJ:              SetInstruction(dec, Instruction.Ldobj, chunks, ArgType.Token);            break;
         case OpCode.LDSTR:              SetInstruction(dec, Instruction.Ldstr, chunks, ArgType.Token);            break;
         case OpCode.NEWOBJ:             SetInstruction(dec, Instruction.Newobj, chunks, ArgType.Token);           break;
         case OpCode.CASTCLASS:          SetInstruction(dec, Instruction.Castclass, chunks, ArgType.Token);        break;
         case OpCode.ISINST:             SetInstruction(dec, Instruction.Isinst, chunks, ArgType.Token);           break;
         case OpCode.CONV_R_UN:          SetInstruction(dec, Instruction.Conv_r_un);                               break;
         case OpCode.UNBOX:              SetInstruction(dec, Instruction.Unbox, chunks, ArgType.Token);            break;
         case OpCode.THROW:              SetInstruction(dec, Instruction.Throw);                                   break;
         case OpCode.LDFLD:              SetInstruction(dec, Instruction.Ldfld, chunks, ArgType.Token);            break;
         case OpCode.LDFLDA:             SetInstruction(dec, Instruction.Ldflda, chunks, ArgType.Token);           break;
         case OpCode.STFLD:              SetInstruction(dec, Instruction.Stfld, chunks, ArgType.Token);            break;
         case OpCode.LDSFLD:             SetInstruction(dec, Instruction.Ldsfld, chunks, ArgType.Token);           break;
         case OpCode.LDSFLDA:            SetInstruction(dec, Instruction.Ldsflda, chunks, ArgType.Token);          break;
         case OpCode.STSFLD:             SetInstruction(dec, Instruction.Stsfld, chunks, ArgType.Token);           break;
         case OpCode.STOBJ:              SetInstruction(dec, Instruction.Stobj, chunks, ArgType.Token);            break;
         case OpCode.CONV_OVF_I1_UN:     SetInstruction(dec, Instruction.Conv_ovf_i1_un);                          break;
         case OpCode.CONV_OVF_I2_UN:     SetInstruction(dec, Instruction.Conv_ovf_i2_un);                          break;
         case OpCode.CONV_OVF_I4_UN:     SetInstruction(dec, Instruction.Conv_ovf_i4_un);                          break;
         case OpCode.CONV_OVF_I8_UN:     SetInstruction(dec, Instruction.Conv_ovf_i8_un);                          break;
         case OpCode.CONV_OVF_U1_UN:     SetInstruction(dec, Instruction.Conv_ovf_u1_un);                          break;
         case OpCode.CONV_OVF_U2_UN:     SetInstruction(dec, Instruction.Conv_ovf_u2_un);                          break;
         case OpCode.CONV_OVF_U4_UN:     SetInstruction(dec, Instruction.Conv_ovf_u4_un);                          break;
         case OpCode.CONV_OVF_U8_UN:     SetInstruction(dec, Instruction.Conv_ovf_u8_un);                          break;
         case OpCode.CONV_OVF_U_UN:      SetInstruction(dec, Instruction.Conv_ovf_u_un);                           break;
         case OpCode.CONV_OVF_I_UN:      SetInstruction(dec, Instruction.Conv_ovf_i_un);                           break;
         case OpCode.BOX:                SetInstruction(dec, Instruction.Box, chunks, ArgType.Token);              break;
         case OpCode.NEWARR:             SetInstruction(dec, Instruction.Newarr, chunks, ArgType.Token);           break;
         case OpCode.LDLEN:              SetInstruction(dec, Instruction.Ldlen);                                   break;
         case OpCode.LDELEMA:            SetInstruction(dec, Instruction.Ldelema, chunks, ArgType.Token);          break;
         case OpCode.LDELEM_I1:          SetInstruction(dec, Instruction.Ldelem_i1);                               break;
         case OpCode.LDELEM_I2:          SetInstruction(dec, Instruction.Ldelem_i2);                               break;
         case OpCode.LDELEM_I4:          SetInstruction(dec, Instruction.Ldelem_i4);                               break;
         case OpCode.LDELEM_I8:          SetInstruction(dec, Instruction.Ldelem_i8);                               break;
         case OpCode.LDELEM_U1:          SetInstruction(dec, Instruction.Ldelem_u1);                               break;
         case OpCode.LDELEM_U2:          SetInstruction(dec, Instruction.Ldelem_u2);                               break;
         case OpCode.LDELEM_U4:          SetInstruction(dec, Instruction.Ldelem_u4);                               break;
         case OpCode.LDELEM_I:           SetInstruction(dec, Instruction.Ldelem_i);                                break;
         case OpCode.LDELEM_R4:          SetInstruction(dec, Instruction.Ldelem_r4);                               break;
         case OpCode.LDELEM_R8:          SetInstruction(dec, Instruction.Ldelem_r8);                               break;
         case OpCode.LDELEM_REF:         SetInstruction(dec, Instruction.Ldelem_ref);                              break;
         case OpCode.STELEM_I:           SetInstruction(dec, Instruction.Stelem_i);                                break;
         case OpCode.STELEM_I1:          SetInstruction(dec, Instruction.Stelem_i1);                               break;
         case OpCode.STELEM_I2:          SetInstruction(dec, Instruction.Stelem_i2);                               break;
         case OpCode.STELEM_I4:          SetInstruction(dec, Instruction.Stelem_i4);                               break;
         case OpCode.STELEM_I8:          SetInstruction(dec, Instruction.Stelem_i8);                               break;
         case OpCode.STELEM_R4:          SetInstruction(dec, Instruction.Stelem_r4);                               break;
         case OpCode.STELEM_R8:          SetInstruction(dec, Instruction.Stelem_r8);                               break;
         case OpCode.LDELEM:             SetInstruction(dec, Instruction.Ldelem, chunks, ArgType.Token);           break;
         case OpCode.STELEM:             SetInstruction(dec, Instruction.Stelem, chunks, ArgType.Token);           break;
         case OpCode.UNBOX_ANY:          SetInstruction(dec, Instruction.Unbox_any, chunks, ArgType.Token);        break;
         case OpCode.CONV_OVF_I1:        SetInstruction(dec, Instruction.Conv_ovf_i1);                             break;
         case OpCode.CONV_OVF_I2:        SetInstruction(dec, Instruction.Conv_ovf_i2);                             break;
         case OpCode.CONV_OVF_I4:        SetInstruction(dec, Instruction.Conv_ovf_i4);                             break;
         case OpCode.CONV_OVF_I8:        SetInstruction(dec, Instruction.Conv_ovf_i8);                             break;
         case OpCode.CONV_OVF_U1:        SetInstruction(dec, Instruction.Conv_ovf_u1);                             break;
         case OpCode.CONV_OVF_U2:        SetInstruction(dec, Instruction.Conv_ovf_u2);                             break;
         case OpCode.CONV_OVF_U4:        SetInstruction(dec, Instruction.Conv_ovf_u4);                             break;
         case OpCode.CONV_OVF_U8:        SetInstruction(dec, Instruction.Conv_ovf_u8);                             break;
         case OpCode.REFANYVAL:          SetInstruction(dec, Instruction.Refanyval, chunks, ArgType.Token);        break;
         case OpCode.CKFINITE:           SetInstruction(dec, Instruction.Ckfinite);                                break;
         case OpCode.MKREFANY:           SetInstruction(dec, Instruction.Mkrefany, chunks, ArgType.Token);         break;
         case OpCode.LDTOKEN:            SetInstruction(dec, Instruction.Ldtoken, chunks, ArgType.Token);          break;
         case OpCode.CONV_U:             SetInstruction(dec, Instruction.Conv_u);                                  break;
         case OpCode.CONV_U1:            SetInstruction(dec, Instruction.Conv_u1);                                 break;
         case OpCode.CONV_U2:            SetInstruction(dec, Instruction.Conv_u2);                                 break;
         case OpCode.CONV_I:             SetInstruction(dec, Instruction.Conv_i);                                  break;
         case OpCode.CONV_OVF_I:         SetInstruction(dec, Instruction.Conv_ovf_i);                              break;
         case OpCode.CONV_OVF_U:         SetInstruction(dec, Instruction.Conv_ovf_u);                              break;
         case OpCode.ADD_OVF:            SetInstruction(dec, Instruction.Add_ovf);                                 break;
         case OpCode.ADD_OVF_UN:         SetInstruction(dec, Instruction.Add_ovf_un);                              break;
         case OpCode.MUL_OVF:            SetInstruction(dec, Instruction.Mul_ovf);                                 break;
         case OpCode.MUL_OVF_UN:         SetInstruction(dec, Instruction.Mul_ovf_un);                              break;
         case OpCode.SUB_OVF:            SetInstruction(dec, Instruction.Sub_ovf);                                 break;
         case OpCode.SUB_OVF_UN:         SetInstruction(dec, Instruction.Sub_ovf_un);                              break;
         case OpCode.ENDFINALLY:         SetInstruction(dec, Instruction.Endfinally);                              break;
         case OpCode.LEAVE:              SetInstruction(dec, Instruction.Leave, chunks, ArgType.Branch);           break;
         case OpCode.LEAVE_S:            SetInstruction(dec, Instruction.Leave_s, chunks, ArgType.SmallBranch);    break;
         case OpCode.STIND_I:            SetInstruction(dec, Instruction.Stind_i);                                 break;
         default: return false;
     }
     return true;
 }
Beispiel #8
0
 private static void ReadPrefix(byte[] chunks, DisassembledInstruction dec)
 {
     ushort opChunk = BitConverter.ToUInt16(chunks, dec.RollingByteIndex);
     dec.RollingByteIndex += 2; // opcode size
     switch ((OpCode)opChunk)
     {
         case OpCode.CONSTRAINED_PREFIX: SetPrefix(dec, Prefix.Constrained, chunks, ArgType.None);   break;
         case OpCode.UNALIGNED_PREFIX:   SetPrefix(dec, Prefix.Unaligned, chunks, ArgType.UChar);    break;
         case OpCode.NO_PREFIX:          SetPrefix(dec, Prefix.No, chunks, ArgType.UChar);           break;
         case OpCode.TAIL_PREFIX:        SetPrefix(dec, Prefix.Tail, chunks, ArgType.None);          break;
         case OpCode.VOLATILE_PREFIX:    SetPrefix(dec, Prefix.Volatile, chunks, ArgType.None);      break;
         case OpCode.READONLY_PREFIX:    SetPrefix(dec, Prefix.Readonly, chunks, ArgType.None);      break;
     }
 }