コード例 #1
0
        public static Instruction FromReader(DisReader reader)
        {
            Instruction result = new Instruction();

            result.Opcode         = reader.ReadByte();
            result.AddressingMode = reader.ReadByte();

            int srcAddr    = result.AddressingMode & AddrMode.SOURCE_MASK;
            int destAddr   = result.AddressingMode & AddrMode.DESTINATION_MASK;
            int middleAddr = result.AddressingMode & AddrMode.MIDDLE_MASK;

            if (middleAddr == AddrMode.MIDDLE_NONE)
            {
                result.Middle = result.Destination;
            }
            else
            {
                result.Middle = reader.ReadOP();
            }

            if ((srcAddr == AddrMode.SOURCE_MPDOUBLEINDIRECT) ||
                (srcAddr == AddrMode.SOURCE_FPDOUBLEINDIRECT))
            {
                result.Source = (reader.ReadOP() << 16) | reader.ReadOP();
            }
            else if (srcAddr != AddrMode.SOURCE_NONE)
            {
                result.Source = reader.ReadOP();
            }

            if ((destAddr == AddrMode.DESTINATION_MPDOUBLEINDIRECT) ||
                (destAddr == AddrMode.DESTINATION_FPDOUBLEINDIRECT))
            {
                result.Destination = (reader.ReadOP() << 16) | reader.ReadOP();
            }
            else if (destAddr != AddrMode.DESTINATION_NONE)
            {
                result.Destination = reader.ReadOP();
            }

            return(result);
        }
コード例 #2
0
        public static DataDescriptor FromReader(DisReader reader)
        {
            DataDescriptor result = new DataDescriptor {
                Code = 0
            };

            int code = reader.ReadByte();

            if (code == 0)
            {
                return(result);
            }

            int count = code & 0x0f;

            if (count == 0)
            {
                count = reader.ReadOP();
            }

            result.Code   = (code & 0xf0) >> 4;
            result.Count  = count;
            result.Offset = reader.ReadOP();

            int dataSize = 0;

            if (result.Code == INT8)
            {
                dataSize = 1;
            }
            else if (result.Code == INT32)
            {
                dataSize = 4;
            }
            else if (result.Code == FLOAT)
            {
                dataSize = 8;
            }
            else if (result.Code == STRING)
            {
                result.Data = Encoding.UTF8.GetBytes(reader.ReadString(count));
            }

            if (dataSize != 0 && count != 0)
            {
                result.Data = reader.ReadBytes(count * dataSize);

                // big endian to little endian
                result.Data = result.Data.Reverse().ToArray();
            }
            return(result);
        }