コード例 #1
0
        static InstrInfo[] ReadInfos()
        {
            var reader  = new DataReader(GetSerializedInstrInfos());
            var infos   = new InstrInfo[IcedConstants.CodeEnumCount];
            var strings = FormatterStringsTable.GetStringsTable();

            var    ca = new char[1];
            string s, s2, s3, s4, s5, s6;
            uint   v, v2, v3;
            int    prevIndex = -1;

            for (int i = 0; i < infos.Length; i++)
            {
                byte f        = reader.ReadByte();
                var  ctorKind = (CtorKind)(f & 0x7F);
                int  currentIndex;
                if (ctorKind == CtorKind.Previous)
                {
                    currentIndex = reader.Index;
                    reader.Index = prevIndex;
                    ctorKind     = (CtorKind)(reader.ReadByte() & 0x7F);
                }
                else
                {
                    currentIndex = -1;
                    prevIndex    = reader.Index - 1;
                }
                s = strings[reader.ReadCompressedUInt32()];
                if ((f & 0x80) != 0)
                {
                    ca[0] = 'v';
                    s     = AddPrefix(s, ca);
                }
                InstrInfo instrInfo;
                switch (ctorKind)
                {
                case CtorKind.Normal_1:
                    instrInfo = new SimpleInstrInfo(s);
                    break;

                case CtorKind.Normal_2a:
                    ca[0]     = (char)reader.ReadByte();
                    s2        = AddSuffix(s, ca);
                    instrInfo = new SimpleInstrInfo(s, s2);
                    break;

                case CtorKind.Normal_2b:
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo(s, (InstrOpInfoFlags)v);
                    break;

                case CtorKind.Normal_2c:
                    ca[0]     = (char)reader.ReadByte();
                    s         = AddSuffix(s, ca);
                    instrInfo = new SimpleInstrInfo(s);
                    break;

                case CtorKind.Normal_3:
                    ca[0]     = (char)reader.ReadByte();
                    s2        = AddSuffix(s, ca);
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo(s, s2, (InstrOpInfoFlags)v);
                    break;

                case CtorKind.AamAad:
                    instrInfo = new SimpleInstrInfo_AamAad(s);
                    break;

                case CtorKind.asz:
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_as((int)v, s);
                    break;

                case CtorKind.bnd:
                    ca[0]     = (char)reader.ReadByte();
                    s2        = AddSuffix(s, ca);
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_bnd(s, s2, (InstrOpInfoFlags)v);
                    break;

                case CtorKind.DeclareData:
                    instrInfo = new SimpleInstrInfo_DeclareData((Code)i, s);
                    break;

                case CtorKind.er_2:
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_er((int)v, s);
                    break;

                case CtorKind.er_4:
                    ca[0]     = (char)reader.ReadByte();
                    s2        = AddSuffix(s, ca);
                    v         = reader.ReadCompressedUInt32();
                    v2        = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_er((int)v, s, s2, (InstrOpInfoFlags)v2);
                    break;

                case CtorKind.far:
                    ca[0]     = (char)reader.ReadByte();
                    s2        = AddSuffix(s, ca);
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_far((int)v, s, s2);
                    break;

                case CtorKind.imul:
                    ca[0]     = (char)reader.ReadByte();
                    s2        = AddSuffix(s, ca);
                    instrInfo = new SimpleInstrInfo_imul(s, s2);
                    break;

                case CtorKind.maskmovq:
                    instrInfo = new SimpleInstrInfo_maskmovq(s);
                    break;

                case CtorKind.movabs:
                    ca[0]     = (char)reader.ReadByte();
                    s2        = AddSuffix(s, ca);
                    s3        = strings[reader.ReadCompressedUInt32()];
                    s4        = AddSuffix(s3, ca);
                    instrInfo = new SimpleInstrInfo_movabs(s, s2, s3, s4);
                    break;

                case CtorKind.nop:
                    v         = reader.ReadCompressedUInt32();
                    v2        = reader.ReadByte();
                    instrInfo = new SimpleInstrInfo_nop((int)v, s, (Register)v2);
                    break;

                case CtorKind.OpSize:
                    v         = reader.ReadByte();
                    s2        = string.Intern(s + "w");
                    s3        = string.Intern(s + "l");
                    s4        = string.Intern(s + "q");
                    instrInfo = new SimpleInstrInfo_OpSize((CodeSize)v, s, s2, s3, s4);
                    break;

                case CtorKind.OpSize2_bnd:
                    s2        = strings[reader.ReadCompressedUInt32()];
                    s3        = strings[reader.ReadCompressedUInt32()];
                    s4        = strings[reader.ReadCompressedUInt32()];
                    instrInfo = new SimpleInstrInfo_OpSize2_bnd(s, s2, s3, s4);
                    break;

                case CtorKind.OpSize3:
                    ca[0]     = (char)reader.ReadByte();
                    s2        = AddSuffix(s, ca);
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_OpSize3((int)v, s, s2);
                    break;

                case CtorKind.os:
                    v  = reader.ReadCompressedUInt32();
                    v2 = reader.ReadByte();
                    if (v2 > 1)
                    {
                        throw new InvalidOperationException();
                    }
                    v3        = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_os((int)v, s, v2 != 0, (InstrOpInfoFlags)v3);
                    break;

                case CtorKind.CC_1:
                    ca[0]     = (char)reader.ReadByte();
                    s2        = AddSuffix(s, ca);
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_cc((int)v, new[] { s }, new[] { s2 });
                    break;

                case CtorKind.CC_2:
                    s2        = strings[reader.ReadCompressedUInt32()];
                    ca[0]     = (char)reader.ReadByte();
                    v         = reader.ReadCompressedUInt32();
                    s3        = AddSuffix(s, ca);
                    s4        = AddSuffix(s2, ca);
                    instrInfo = new SimpleInstrInfo_cc((int)v, new[] { s, s2 }, new[] { s3, s4 });
                    break;

                case CtorKind.CC_3:
                    s2        = strings[reader.ReadCompressedUInt32()];
                    s3        = strings[reader.ReadCompressedUInt32()];
                    ca[0]     = (char)reader.ReadByte();
                    v         = reader.ReadCompressedUInt32();
                    s4        = AddSuffix(s, ca);
                    s5        = AddSuffix(s2, ca);
                    s6        = AddSuffix(s3, ca);
                    instrInfo = new SimpleInstrInfo_cc((int)v, new[] { s, s2, s3 }, new[] { s4, s5, s6 });
                    break;

                case CtorKind.os_jcc_1:
                    v2        = reader.ReadCompressedUInt32();
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_os_jcc((int)v, (int)v2, new[] { s });
                    break;

                case CtorKind.os_jcc_2:
                    s2        = strings[reader.ReadCompressedUInt32()];
                    v2        = reader.ReadCompressedUInt32();
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_os_jcc((int)v, (int)v2, new[] { s, s2 });
                    break;

                case CtorKind.os_jcc_3:
                    s2        = strings[reader.ReadCompressedUInt32()];
                    s3        = strings[reader.ReadCompressedUInt32()];
                    v2        = reader.ReadCompressedUInt32();
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_os_jcc((int)v, (int)v2, new[] { s, s2, s3 });
                    break;

                case CtorKind.os_loopcc:
                    s2        = strings[reader.ReadCompressedUInt32()];
                    ca[0]     = (char)reader.ReadByte();
                    s3        = AddSuffix(s, ca);
                    s4        = AddSuffix(s2, ca);
                    v3        = reader.ReadCompressedUInt32();
                    v         = reader.ReadCompressedUInt32();
                    v2        = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_os_loop((int)v, (int)v2, (int)v3, new[] { s, s2 }, new[] { s3, s4 });
                    break;

                case CtorKind.os_loop:
                    ca[0]     = (char)reader.ReadByte();
                    s2        = AddSuffix(s, ca);
                    v         = reader.ReadCompressedUInt32();
                    v2        = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_os_loop((int)v, (int)v2, -1, new[] { s }, new[] { s2 });
                    break;

                case CtorKind.os_mem:
                    ca[0]     = (char)reader.ReadByte();
                    s2        = AddSuffix(s, ca);
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_os_mem((int)v, s, s2);
                    break;

                case CtorKind.Reg16:
                    ca[0]     = 'w';
                    s2        = AddSuffix(s, ca);
                    instrInfo = new SimpleInstrInfo_Reg16(s, s2);
                    break;

                case CtorKind.os_mem2:
                    ca[0]     = (char)reader.ReadByte();
                    s2        = AddSuffix(s, ca);
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_os_mem2((int)v, s, s2);
                    break;

                case CtorKind.os2_3:
                    ca[0] = (char)reader.ReadByte();
                    s2    = AddSuffix(s, ca);
                    v     = reader.ReadCompressedUInt32();
                    v2    = reader.ReadByte();
                    if (v2 > 1)
                    {
                        throw new InvalidOperationException();
                    }
                    instrInfo = new SimpleInstrInfo_os2((int)v, s, s2, v2 != 0, InstrOpInfoFlags.None);
                    break;

                case CtorKind.os2_4:
                    ca[0] = (char)reader.ReadByte();
                    s2    = AddSuffix(s, ca);
                    v     = reader.ReadCompressedUInt32();
                    v2    = reader.ReadByte();
                    if (v2 > 1)
                    {
                        throw new InvalidOperationException();
                    }
                    v3        = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_os2((int)v, s, s2, v2 != 0, (InstrOpInfoFlags)v3);
                    break;

                case CtorKind.pblendvb:
                    instrInfo = new SimpleInstrInfo_pblendvb(s);
                    break;

                case CtorKind.pclmulqdq:
                    v         = reader.ReadByte();
                    instrInfo = new SimpleInstrInfo_pclmulqdq(s, FormatterConstants.GetPseudoOps((PseudoOpsKind)v));
                    break;

                case CtorKind.pops:
                    v  = reader.ReadByte();
                    v2 = reader.ReadByte();
                    if (v2 > 1)
                    {
                        throw new InvalidOperationException();
                    }
                    instrInfo = new SimpleInstrInfo_pops(s, FormatterConstants.GetPseudoOps((PseudoOpsKind)v), v2 != 0);
                    break;

                case CtorKind.mem16:
                    ca[0]     = (char)reader.ReadByte();
                    s2        = AddSuffix(s, ca);
                    ca[0]     = 'w';
                    s3        = AddSuffix(s, ca);
                    instrInfo = new SimpleInstrInfo_mem16(s, s2, s3);
                    break;

                case CtorKind.Reg32:
                    instrInfo = new SimpleInstrInfo_Reg32(s);
                    break;

                case CtorKind.sae:
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_sae((int)v, s);
                    break;

                case CtorKind.ST_STi:
                    instrInfo = new SimpleInstrInfo_ST_STi(s);
                    break;

                case CtorKind.STi_ST:
                    v = reader.ReadByte();
                    if (v > 1)
                    {
                        throw new InvalidOperationException();
                    }
                    instrInfo = new SimpleInstrInfo_STi_ST(s, v != 0);
                    break;

                case CtorKind.STIG1:
                    v = reader.ReadByte();
                    if (v > 1)
                    {
                        throw new InvalidOperationException();
                    }
                    instrInfo = new SimpleInstrInfo_STIG1(s, v != 0);
                    break;

                default:
                    throw new InvalidOperationException();
                }
                infos[i] = instrInfo;
                if (currentIndex >= 0)
                {
                    reader.Index = currentIndex;
                }
            }
            if (reader.CanRead)
            {
                throw new InvalidOperationException();
            }

            return(infos);
        }
コード例 #2
0
ファイル: InstrInfos.cs プロジェクト: jangocheng/iced
        static InstrInfo[] ReadInfos()
        {
            var reader  = new DataReader(GetSerializedInstrInfos());
            var infos   = new InstrInfo[IcedConstants.NumberOfCodeValues];
            var strings = FormatterStringsTable.GetStringsTable();

            var    ca = new char[1];
            string s, s2, s3, s4;
            uint   v, v2, v3, v4;
            int    prevIndex = -1;

            for (int i = 0; i < infos.Length; i++)
            {
                byte f        = reader.ReadByte();
                var  ctorKind = (CtorKind)(f & 0x7F);
                int  currentIndex;
                if (ctorKind == CtorKind.Previous)
                {
                    currentIndex = reader.Index;
                    reader.Index = prevIndex;
                    ctorKind     = (CtorKind)(reader.ReadByte() & 0x7F);
                }
                else
                {
                    currentIndex = -1;
                    prevIndex    = reader.Index - 1;
                }
                s = strings[reader.ReadCompressedUInt32()];
                if ((f & 0x80) != 0)
                {
                    ca[0] = 'v';
                    s     = AddPrefix(s, ca);
                }
                InstrInfo instrInfo;
                switch (ctorKind)
                {
                case CtorKind.Normal_1:
                    instrInfo = new SimpleInstrInfo(s);
                    break;

                case CtorKind.Normal_2:
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo(s, (InstrOpInfoFlags)v);
                    break;

                case CtorKind.AamAad:
                    instrInfo = new SimpleInstrInfo_AamAad(s);
                    break;

                case CtorKind.asz:
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_as((int)v, s);
                    break;

                case CtorKind.AX:
                    instrInfo = new SimpleInstrInfo_AX(s);
                    break;

                case CtorKind.AY:
                    instrInfo = new SimpleInstrInfo_AY(s);
                    break;

                case CtorKind.bcst:
                    v         = reader.ReadCompressedUInt32();
                    v2        = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_bcst(s, (InstrOpInfoFlags)v, (InstrOpInfoFlags)v2);
                    break;

                case CtorKind.bnd_1:
                    instrInfo = new SimpleInstrInfo_bnd(s);
                    break;

                case CtorKind.bnd_2:
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_bnd(s, (InstrOpInfoFlags)v);
                    break;

                case CtorKind.DeclareData:
                    instrInfo = new SimpleInstrInfo_DeclareData((Code)i, s);
                    break;

                case CtorKind.DX:
                    instrInfo = new SimpleInstrInfo_DX(s);
                    break;

                case CtorKind.er_2:
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_er((int)v, s);
                    break;

                case CtorKind.er_3:
                    v         = reader.ReadCompressedUInt32();
                    v2        = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_er((int)v, s, (InstrOpInfoFlags)v2);
                    break;

                case CtorKind.far:
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_far((int)v, s);
                    break;

                case CtorKind.far_mem:
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_far_mem((int)v, s);
                    break;

                case CtorKind.invlpga:
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_invlpga((int)v, s);
                    break;

                case CtorKind.maskmovq:
                    instrInfo = new SimpleInstrInfo_maskmovq(s);
                    break;

                case CtorKind.mmxmem_1:
                    instrInfo = new SimpleInstrInfo_mmxmem(s);
                    break;

                case CtorKind.mmxmem_2:
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_mmxmem(s, (InstrOpInfoFlags)v);
                    break;

                case CtorKind.mmxmem_3:
                    v         = reader.ReadCompressedUInt32();
                    v2        = reader.ReadByte();
                    instrInfo = new SimpleInstrInfo_mmxmem(s, (InstrOpInfoFlags)v, (MemorySize)v2);
                    break;

                case CtorKind.movabs:
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_movabs((int)v, s);
                    break;

                case CtorKind.ms_pops:
                    v2        = reader.ReadByte();
                    v3        = reader.ReadCompressedUInt32();
                    v4        = reader.ReadByte();
                    instrInfo = new SimpleInstrInfo_ms_pops(s, FormatterConstants.GetPseudoOps((PseudoOpsKind)v2), (InstrOpInfoFlags)v3, (MemorySize)v4);
                    break;

                case CtorKind.nop:
                    v         = reader.ReadCompressedUInt32();
                    v2        = reader.ReadByte();
                    instrInfo = new SimpleInstrInfo_nop((int)v, s, (Register)v2);
                    break;

                case CtorKind.OpSize:
                    v         = reader.ReadByte();
                    ca[0]     = 'w';
                    s2        = AddSuffix(s, ca);
                    ca[0]     = 'd';
                    s3        = AddSuffix(s, ca);
                    ca[0]     = 'q';
                    s4        = AddSuffix(s, ca);
                    instrInfo = new SimpleInstrInfo_OpSize((CodeSize)v, s, s2, s3, s4);
                    break;

                case CtorKind.OpSize2_bnd:
                    s2        = strings[reader.ReadCompressedUInt32()];
                    s3        = strings[reader.ReadCompressedUInt32()];
                    s4        = strings[reader.ReadCompressedUInt32()];
                    instrInfo = new SimpleInstrInfo_OpSize2_bnd(s, s2, s3, s4);
                    break;

                case CtorKind.OpSize3:
                    ca[0]     = (char)reader.ReadByte();
                    s2        = AddSuffix(s, ca);
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_OpSize3((int)v, s, s2);
                    break;

                case CtorKind.os_2:
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_os((int)v, s);
                    break;

                case CtorKind.os_3:
                    v         = reader.ReadCompressedUInt32();
                    v2        = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_os((int)v, s, (InstrOpInfoFlags)v2);
                    break;

                case CtorKind.os_call_2:
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_os_call((int)v, s);
                    break;

                case CtorKind.os_call_3:
                    v  = reader.ReadCompressedUInt32();
                    v2 = reader.ReadByte();
                    if (v2 > 1)
                    {
                        throw new InvalidOperationException();
                    }
                    instrInfo = new SimpleInstrInfo_os_call((int)v, s, v2 != 0);
                    break;

                case CtorKind.CC_1:
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_cc((int)v, new[] { s });
                    break;

                case CtorKind.CC_2:
                    s2        = strings[reader.ReadCompressedUInt32()];
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_cc((int)v, new[] { s, s2 });
                    break;

                case CtorKind.CC_3:
                    s2        = strings[reader.ReadCompressedUInt32()];
                    s3        = strings[reader.ReadCompressedUInt32()];
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_cc((int)v, new[] { s, s2, s3 });
                    break;

                case CtorKind.os_jcc_a_1:
                    v2        = reader.ReadCompressedUInt32();
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_os_jcc((int)v, (int)v2, new[] { s });
                    break;

                case CtorKind.os_jcc_a_2:
                    s2        = strings[reader.ReadCompressedUInt32()];
                    v2        = reader.ReadCompressedUInt32();
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_os_jcc((int)v, (int)v2, new[] { s, s2 });
                    break;

                case CtorKind.os_jcc_a_3:
                    s2        = strings[reader.ReadCompressedUInt32()];
                    s3        = strings[reader.ReadCompressedUInt32()];
                    v2        = reader.ReadCompressedUInt32();
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_os_jcc((int)v, (int)v2, new[] { s, s2, s3 });
                    break;

                case CtorKind.os_jcc_b_1:
                    v3        = reader.ReadCompressedUInt32();
                    v         = reader.ReadCompressedUInt32();
                    v2        = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_os_jcc((int)v, (int)v3, new[] { s }, (InstrOpInfoFlags)v2);
                    break;

                case CtorKind.os_jcc_b_2:
                    s2        = strings[reader.ReadCompressedUInt32()];
                    v3        = reader.ReadCompressedUInt32();
                    v         = reader.ReadCompressedUInt32();
                    v2        = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_os_jcc((int)v, (int)v3, new[] { s, s2 }, (InstrOpInfoFlags)v2);
                    break;

                case CtorKind.os_jcc_b_3:
                    s2        = strings[reader.ReadCompressedUInt32()];
                    s3        = strings[reader.ReadCompressedUInt32()];
                    v3        = reader.ReadCompressedUInt32();
                    v         = reader.ReadCompressedUInt32();
                    v2        = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_os_jcc((int)v, (int)v3, new[] { s, s2, s3 }, (InstrOpInfoFlags)v2);
                    break;

                case CtorKind.os_loopcc:
                    s2        = strings[reader.ReadCompressedUInt32()];
                    v3        = reader.ReadCompressedUInt32();
                    v         = reader.ReadCompressedUInt32();
                    v2        = reader.ReadByte();
                    instrInfo = new SimpleInstrInfo_os_loop((int)v, (int)v3, (Register)v2, new[] { s, s2 });
                    break;

                case CtorKind.os_loop:
                    v         = reader.ReadCompressedUInt32();
                    v2        = reader.ReadByte();
                    instrInfo = new SimpleInstrInfo_os_loop((int)v, -1, (Register)v2, new[] { s });
                    break;

                case CtorKind.os_mem:
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_os_mem((int)v, s);
                    break;

                case CtorKind.os_mem_reg16:
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_os_mem_reg16((int)v, s);
                    break;

                case CtorKind.os_mem2:
                    v         = reader.ReadCompressedUInt32();
                    v2        = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_os_mem2((int)v, s, (InstrOpInfoFlags)v2);
                    break;

                case CtorKind.pblendvb_1:
                    instrInfo = new SimpleInstrInfo_pblendvb(s);
                    break;

                case CtorKind.pblendvb_2:
                    v         = reader.ReadByte();
                    instrInfo = new SimpleInstrInfo_pblendvb(s, (MemorySize)v);
                    break;

                case CtorKind.pclmulqdq:
                    v         = reader.ReadByte();
                    instrInfo = new SimpleInstrInfo_pclmulqdq(s, FormatterConstants.GetPseudoOps((PseudoOpsKind)v));
                    break;

                case CtorKind.pops_2:
                    v         = reader.ReadByte();
                    instrInfo = new SimpleInstrInfo_pops(s, FormatterConstants.GetPseudoOps((PseudoOpsKind)v));
                    break;

                case CtorKind.pops_3:
                    v         = reader.ReadByte();
                    v2        = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_pops(s, FormatterConstants.GetPseudoOps((PseudoOpsKind)v), (InstrOpInfoFlags)v2);
                    break;

                case CtorKind.Reg16:
                    instrInfo = new SimpleInstrInfo_Reg16(s);
                    break;

                case CtorKind.reverse2:
                    instrInfo = new SimpleInstrInfo_reverse2(s);
                    break;

                case CtorKind.sae:
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_sae((int)v, s);
                    break;

                case CtorKind.sae_pops:
                    v         = reader.ReadCompressedUInt32();
                    v2        = reader.ReadByte();
                    instrInfo = new SimpleInstrInfo_sae_pops((int)v, s, FormatterConstants.GetPseudoOps((PseudoOpsKind)v2));
                    break;

                case CtorKind.SEX1:
                    v         = reader.ReadCompressedUInt32();
                    v2        = reader.ReadByte();
                    instrInfo = new SimpleInstrInfo_SEX1((int)v, (SignExtendInfo)v2, s);
                    break;

                case CtorKind.SEX1a:
                    v         = reader.ReadCompressedUInt32();
                    v2        = reader.ReadByte();
                    instrInfo = new SimpleInstrInfo_SEX1a((int)v, (SignExtendInfo)v2, s);
                    break;

                case CtorKind.SEX2_2:
                    v         = reader.ReadByte();
                    instrInfo = new SimpleInstrInfo_SEX2((SignExtendInfo)v, s);
                    break;

                case CtorKind.SEX2_3:
                    v         = reader.ReadByte();
                    v2        = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_SEX2((SignExtendInfo)v, s, (InstrOpInfoFlags)v2);
                    break;

                case CtorKind.SEX2_4:
                    v         = reader.ReadByte();
                    v2        = reader.ReadByte();
                    v3        = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_SEX2((SignExtendInfo)v, (SignExtendInfo)v2, s, (InstrOpInfoFlags)v3);
                    break;

                case CtorKind.SEX3:
                    v         = reader.ReadByte();
                    instrInfo = new SimpleInstrInfo_SEX3((SignExtendInfo)v, s);
                    break;

                case CtorKind.STIG1_1:
                    instrInfo = new SimpleInstrInfo_STIG1(s);
                    break;

                case CtorKind.STIG1_2:
                    v = reader.ReadByte();
                    if (v > 1)
                    {
                        throw new InvalidOperationException();
                    }
                    instrInfo = new SimpleInstrInfo_STIG1(s, v != 0);
                    break;

                case CtorKind.STIG2_2a:
                    v = reader.ReadByte();
                    if (v > 1)
                    {
                        throw new InvalidOperationException();
                    }
                    instrInfo = new SimpleInstrInfo_STIG2(s, v != 0);
                    break;

                case CtorKind.STIG2_2b:
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_STIG2(s, (InstrOpInfoFlags)v);
                    break;

                case CtorKind.xbegin:
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_xbegin((int)v, s);
                    break;

                case CtorKind.XLAT:
                    instrInfo = new SimpleInstrInfo_XLAT(s);
                    break;

                case CtorKind.XY:
                    instrInfo = new SimpleInstrInfo_XY(s);
                    break;

                case CtorKind.YA:
                    instrInfo = new SimpleInstrInfo_YA(s);
                    break;

                case CtorKind.YD:
                    instrInfo = new SimpleInstrInfo_YD(s);
                    break;

                case CtorKind.YX:
                    instrInfo = new SimpleInstrInfo_YX(s);
                    break;

                default:
                    throw new InvalidOperationException();
                }
                infos[i] = instrInfo;
                if (currentIndex >= 0)
                {
                    reader.Index = currentIndex;
                }
            }
            if (reader.CanRead)
            {
                throw new InvalidOperationException();
            }

            return(infos);
        }
コード例 #3
0
        static InstrInfo[] ReadInfos()
        {
            var reader  = new DataReader(GetSerializedInstrInfos());
            var infos   = new InstrInfo[DecoderConstants.NumberOfCodeValues];
            var strings = FormatterStringsTable.GetStringsTable();

            var    ca = new char[1];
            string s, s2, s3, s4;
            uint   v, v2;
            int    prevIndex = -1;

            for (int i = 0; i < infos.Length; i++)
            {
                var  code     = (Code)i;
                byte f        = reader.ReadByte();
                var  ctorKind = (CtorKind)(f & 0x7F);
                int  currentIndex;
                if (ctorKind == CtorKind.Previous)
                {
                    currentIndex = reader.Index;
                    reader.Index = prevIndex;
                    ctorKind     = (CtorKind)(reader.ReadByte() & 0x7F);
                }
                else
                {
                    currentIndex = -1;
                    prevIndex    = reader.Index - 1;
                }
                s = strings[reader.ReadCompressedUInt32()];
                if ((f & 0x80) != 0)
                {
                    ca[0] = 'v';
                    s     = AddPrefix(s, ca);
                }
                InstrInfo instrInfo;
                switch (ctorKind)
                {
                case CtorKind.Normal_1:
                    instrInfo = new SimpleInstrInfo(code, s);
                    break;

                case CtorKind.Normal_2a:
                    ca[0]     = (char)reader.ReadByte();
                    s2        = AddSuffix(s, ca);
                    instrInfo = new SimpleInstrInfo(code, s, s2);
                    break;

                case CtorKind.Normal_2b:
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo(code, s, (InstrOpInfoFlags)v);
                    break;

                case CtorKind.Normal_2c:
                    ca[0]     = (char)reader.ReadByte();
                    s         = AddSuffix(s, ca);
                    instrInfo = new SimpleInstrInfo(code, s);
                    break;

                case CtorKind.Normal_3:
                    ca[0]     = (char)reader.ReadByte();
                    s2        = AddSuffix(s, ca);
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo(code, s, s2, (InstrOpInfoFlags)v);
                    break;

                case CtorKind.AamAad:
                    instrInfo = new SimpleInstrInfo_AamAad(code, s);
                    break;

                case CtorKind.asz:
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_as(code, (int)v, s);
                    break;

                case CtorKind.bnd2_2:
                    ca[0]     = (char)reader.ReadByte();
                    s2        = AddSuffix(s, ca);
                    instrInfo = new SimpleInstrInfo_bnd2(code, s, s2);
                    break;

                case CtorKind.bnd2_3:
                    ca[0]     = (char)reader.ReadByte();
                    s2        = AddSuffix(s, ca);
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_bnd2(code, s, s2, (InstrOpInfoFlags)v);
                    break;

                case CtorKind.DeclareData:
                    instrInfo = new SimpleInstrInfo_DeclareData(code, s);
                    break;

                case CtorKind.er_2:
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_er(code, (int)v, s);
                    break;

                case CtorKind.er_4:
                    ca[0]     = (char)reader.ReadByte();
                    s2        = AddSuffix(s, ca);
                    v         = reader.ReadCompressedUInt32();
                    v2        = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_er(code, (int)v, s, s2, (InstrOpInfoFlags)v2);
                    break;

                case CtorKind.far:
                    ca[0]     = (char)reader.ReadByte();
                    s2        = AddSuffix(s, ca);
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_far(code, (int)v, s, s2);
                    break;

                case CtorKind.imul:
                    ca[0]     = (char)reader.ReadByte();
                    s2        = AddSuffix(s, ca);
                    instrInfo = new SimpleInstrInfo_imul(code, s, s2);
                    break;

                case CtorKind.maskmovq:
                    instrInfo = new SimpleInstrInfo_maskmovq(code, s);
                    break;

                case CtorKind.movabs:
                    ca[0]     = (char)reader.ReadByte();
                    s2        = AddSuffix(s, ca);
                    v         = reader.ReadCompressedUInt32();
                    s3        = strings[reader.ReadCompressedUInt32()];
                    ca[0]     = (char)reader.ReadByte();
                    s4        = AddSuffix(s3, ca);
                    instrInfo = new SimpleInstrInfo_movabs(code, (int)v, s, s2, s3, s4);
                    break;

                case CtorKind.nop:
                    v         = reader.ReadCompressedUInt32();
                    v2        = reader.ReadByte();
                    instrInfo = new SimpleInstrInfo_nop(code, (int)v, s, (Register)v2);
                    break;

                case CtorKind.OpSize:
                    v         = reader.ReadByte();
                    s2        = string.Intern(s + "w");
                    s3        = string.Intern(s + "l");
                    s4        = string.Intern(s + "q");
                    instrInfo = new SimpleInstrInfo_OpSize(code, (CodeSize)v, s, s2, s3, s4);
                    break;

                case CtorKind.OpSize2_bnd:
                    s2        = strings[reader.ReadCompressedUInt32()];
                    s3        = strings[reader.ReadCompressedUInt32()];
                    s4        = strings[reader.ReadCompressedUInt32()];
                    instrInfo = new SimpleInstrInfo_OpSize2_bnd(code, s, s2, s3, s4);
                    break;

                case CtorKind.OpSize3:
                    ca[0]     = (char)reader.ReadByte();
                    s2        = AddSuffix(s, ca);
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_OpSize3(code, (int)v, s, s2);
                    break;

                case CtorKind.os_A:
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_os(code, (int)v, s);
                    break;

                case CtorKind.os_B:
                    v         = reader.ReadCompressedUInt32();
                    v2        = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_os(code, (int)v, s, (InstrOpInfoFlags)v2);
                    break;

                case CtorKind.os_bnd:
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_os_bnd(code, (int)v, s);
                    break;

                case CtorKind.os_jcc:
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_os_jcc(code, (int)v, s);
                    break;

                case CtorKind.os_loop:
                    ca[0]     = (char)reader.ReadByte();
                    s2        = AddSuffix(s, ca);
                    v         = reader.ReadCompressedUInt32();
                    v2        = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_os_loop(code, (int)v, (int)v2, s, s2);
                    break;

                case CtorKind.os_mem:
                    ca[0]     = (char)reader.ReadByte();
                    s2        = AddSuffix(s, ca);
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_os_mem(code, (int)v, s, s2);
                    break;

                case CtorKind.os_mem_reg16:
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_os_mem_reg16(code, (int)v, s);
                    break;

                case CtorKind.os_mem2:
                    ca[0]     = (char)reader.ReadByte();
                    s2        = AddSuffix(s, ca);
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_os_mem2(code, (int)v, s, s2);
                    break;

                case CtorKind.os2_3:
                    ca[0]     = (char)reader.ReadByte();
                    s2        = AddSuffix(s, ca);
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_os2(code, (int)v, s, s2);
                    break;

                case CtorKind.os2_4:
                    ca[0]     = (char)reader.ReadByte();
                    s2        = AddSuffix(s, ca);
                    v         = reader.ReadCompressedUInt32();
                    v2        = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_os2(code, (int)v, s, s2, (InstrOpInfoFlags)v2);
                    break;

                case CtorKind.os2_bnd:
                    ca[0]     = (char)reader.ReadByte();
                    s2        = AddSuffix(s, ca);
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_os2_bnd(code, (int)v, s, s2);
                    break;

                case CtorKind.pblendvb:
                    instrInfo = new SimpleInstrInfo_pblendvb(code, s);
                    break;

                case CtorKind.pclmulqdq:
                    v         = reader.ReadByte();
                    instrInfo = new SimpleInstrInfo_pclmulqdq(code, s, FormatterConstants.GetPseudoOps((PseudoOpsKind)v));
                    break;

                case CtorKind.pops:
                    v         = reader.ReadByte();
                    instrInfo = new SimpleInstrInfo_pops(code, s, FormatterConstants.GetPseudoOps((PseudoOpsKind)v));
                    break;

                case CtorKind.Reg16:
                    instrInfo = new SimpleInstrInfo_Reg16(code, s);
                    break;

                case CtorKind.sae:
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_sae(code, (int)v, s);
                    break;

                case CtorKind.sae_pops:
                    v         = reader.ReadCompressedUInt32();
                    v2        = reader.ReadByte();
                    instrInfo = new SimpleInstrInfo_sae_pops(code, (int)v, s, FormatterConstants.GetPseudoOps((PseudoOpsKind)v2));
                    break;

                case CtorKind.ST_STi:
                    instrInfo = new SimpleInstrInfo_ST_STi(code, s);
                    break;

                case CtorKind.STi_ST:
                    instrInfo = new SimpleInstrInfo_STi_ST(code, s);
                    break;

                case CtorKind.STi_ST2:
                    instrInfo = new SimpleInstrInfo_STi_ST2(code, s);
                    break;

                case CtorKind.STIG_1a:
                    instrInfo = new SimpleInstrInfo_STIG1(code, s);
                    break;

                case CtorKind.STIG_1b:
                    v = reader.ReadByte();
                    if (v > 1)
                    {
                        throw new InvalidOperationException();
                    }
                    instrInfo = new SimpleInstrInfo_STIG1(code, s, v != 0);
                    break;

                case CtorKind.xbegin:
                    v         = reader.ReadCompressedUInt32();
                    instrInfo = new SimpleInstrInfo_xbegin(code, (int)v, s);
                    break;

                default:
                    throw new InvalidOperationException();
                }
                infos[i] = instrInfo;
                if (currentIndex >= 0)
                {
                    reader.Index = currentIndex;
                }
            }
            if (reader.CanRead)
            {
                throw new InvalidOperationException();
            }

            return(infos);
        }