Пример #1
0
        public virtual FDumpInfo Dump(FDumpInfo info)
        {
            RDump.StartDump(info);
            FBytes bytes = Build();

            info.Append("Length:");
            info.AppendLine(bytes.Length);
            info.AppendLine(RDump.LINE_L2);
            string value = Encoding.ASCII.GetString(bytes.Memory, 0, bytes.Length);

            char[] chs   = value.ToCharArray();
            int    count = Math.Min(chs.Length, 2048);

            for (int n = 0; n < count; n++)
            {
                char ch = chs[n];
                if (ch >= ' ')
                {
                    info.Append(ch);
                }
                else if (ch == '\n' || ch == '\r')
                {
                    info.Append(ch);
                }
                else
                {
                    info.Append('.');
                }
            }
            info.AppendLine();
            info.AppendLine(RDump.LINE_L2);
            return(info);
        }
Пример #2
0
        public override bool Parse(FAsmCommand cmd, FBytes memory, int offset)
        {
            byte code = memory[offset];

            if ((code & 0xF8) == 0x40)
            {
                // 01000rrr
                cmd.Attributes = new string[] { RAsm.Reg32Name(code & 0x03) };
                return(true);
            }
            else if ((code & 0xFE) == 0xFE)
            {
                // 1111111woo000mmm
                cmd.Size = 2;
                int    code2 = memory[offset + 1];
                int    w     = code & 0x01;
                int    oo    = (code2 & 0xC0) >> 6;
                int    rrr   = (code2 & 0x38) >> 3;
                int    mmm   = (code2 & 0x07);
                string p1    = RAsm.RegName(w, rrr);
                string p2    = RAsm.FuncName(w, oo, mmm);
                cmd.Attributes = new string[] { p1, p2 };
                return(true);
            }
            return(false);
        }
Пример #3
0
        public override bool Parse(FAsmCommand command, FBytes memory, int offset)
        {
            int code = memory[offset++];

            if (code == 0xFF)
            {
                int code2 = memory[offset++];
                if ((code2 & 0x38) == 0x28)
                {
                    // 1111 1111 oo10 1mmm - MemFar
                    command.Size = 2;
                }
                else if ((code2 & 0x38) == 0x20)
                {
                    // 1111 1111 oo10 0mmm - RegWord / MemNear
                }
                return(true);
            }
            else if (code == 0xEB)
            {
                // 1110 1011 - Short
                return(true);
            }
            else if (code == 0xE9)
            {
                // 1110 1001 - Near
                return(true);
            }
            else if (code == 0xEA)
            {
                // 1110 1010 - Far
                return(true);
            }
            return(false);
        }
Пример #4
0
        public void Send()
        {
            Console.WriteLine(Dump());
            FBytes bytes = Build();

            _connection._socket.Output.Write(bytes.ToArray());
        }
Пример #5
0
        public override bool Parse(FAsmCommand cmd, FBytes memory, int offset)
        {
            int code = memory[offset];

            if ((code & 0xF8) == 0x58)
            {
                // 01011rrr
                cmd.Attributes = new string[] { RAsm.Reg32Name(code & 0x03) };
                return(true);
            }
            else if (code == 0x9C)
            {
                // 10001111oo000mmm
                return(true);
            }
            else if ((code & 0xC7) == 0x07)
            {
                // 00sss111
                cmd.Attributes = new string[] { RAsm.RegSssName((code & 0x38) >> 3) };
                return(true);
            }
            else if (code == 0x0F)
            {
                int code2 = memory[offset + 1];
                if ((code2 & 0xC7) == 0x81)
                {
                    // 0000 1111 10ss s001
                    cmd.Size       = 2;
                    cmd.Attributes = new string[] { RAsm.RegSssName((code2 & 0x38) >> 3) };
                    return(true);
                }
            }
            return(false);
        }
Пример #6
0
        //============================================================
        // <T>从字节流中读取指定长度的数据。</T>
        //
        // @param lenth 读取的字节数
        // @return 保存所有数据的数组
        //============================================================
        public FBytes ReadLength(int length)
        {
            FBytes bytes = new FBytes();

            ReadLength(bytes, length);
            return(bytes);
        }
Пример #7
0
        public static bool ParseOoRrrMmm(FAsmCommand cmd, int w, int code, FBytes memory, int offset)
        {
            int oo  = (code & 0xC0) >> 6;
            int rrr = (code & 0x38) >> 3;
            int mmm = (code & 0x07);

            switch (oo)
            {
            case 0x00:
                if (mmm == 0x06)
                {
                    cmd.Size      += RInt.BYTE_SIZE;
                    cmd.Attributes = new object[] { memory.GetInt32(offset) };
                }
                return(true);

            case 0x01:
                cmd.Size      += RByte.BYTE_SIZE;
                cmd.Attributes = new object[] { RAsm.RegName(w, rrr), memory[offset] };
                return(true);

            case 0x02:
                cmd.Size      += RInt.BYTE_SIZE;
                cmd.Attributes = new object[] { RAsm.RegName(w, rrr), memory.GetInt32(offset) };
                return(true);

            case 0x03:
                string des = RAsm.RegName(w, rrr);
                string src = RAsm.FuncName(w, oo, mmm);
                cmd.Attributes = new object[] { des, src };
                return(true);
            }
            return(false);
        }
Пример #8
0
        public const int REG_EDI = 0x07; // BH, DI, EDI

        public static bool ParseOoMmm(FAsmCommand cmd, int w, int oo, int mmm, FBytes memory, int offset)
        {
            switch (oo)
            {
            case 0x00:
                if (mmm == 0x06)
                {
                    cmd.Size      += RInt.BYTE_SIZE;
                    cmd.Attributes = new object[] { memory.GetInt32(offset) };
                }
                return(true);

            case 0x01:
                cmd.Size      += RByte.BYTE_SIZE;
                cmd.Attributes = new object[] { memory[offset] };
                return(true);

            case 0x02:
                cmd.Size      += RInt.BYTE_SIZE;
                cmd.Attributes = new object[] { memory.GetInt32(offset) };
                return(true);

            case 0x03:
                cmd.Size += RByte.BYTE_SIZE;
                string des = RAsm.RegName(w, mmm);
                cmd.Attributes = new object[] { des, memory[offset] };
                return(true);
            }
            return(false);
        }
Пример #9
0
        public override bool Parse(FAsmCommand command, FBytes memory, int offset)
        {
            int code = memory[offset];

            if ((code & 0xF8) == 0x50)
            {
                // 0101 0rrr - RegWord
                command.Attributes = new string[] { RAsm.Reg32Name(code & 0x07) };
                return(true);
            }
            else if (code == 0xFF)
            {
                int code2 = memory[offset + 1];
                if ((code2 & 0x38) == 0x30)
                {
                    // 1111 1111 oo11 0mmm - MemWord
                    command.Size = 2;
                    int oo = (code2 & 0xC0) >> 6;
                    command.Attributes = new string[] { RAsm.FuncName(1, oo, code2 & 0x07) };
                    return(true);
                }
            }
            else if ((code & 0xC7) == 0x06)
            {
                // 00ss s110 - SegOld
                int sss = (code & 0x38) >> 3;
                command.Attributes = new string[] { RAsm.RegSssName(sss) };
                return(true);
            }
            else if (code == 0x0F)
            {
                int code2 = memory[offset + 1];
                if ((code2 & 0xC7) == 0x80)
                {
                    // 0000 1111 10ss s000 - Seg
                    command.Size = 2;
                    int sss = (code & 0x38) >> 3;
                    command.Attributes = new string[] { RAsm.RegSssName(sss) };
                    return(true);
                }
            }
            else if ((code & 0x6A) == 0x6A)
            {
                // 01101010 - Imm8
                command.Size       = 1 + RAsm.W0_BYTES;
                command.Attributes = new string[] { memory[offset + 1].ToString("X2") };
                return(true);
            }
            else if ((code & 0x68) == 0x68)
            {
                // 01101000 - Imm
                command.Size       = 1 + RAsm.W1_BYTES;
                command.Attributes = new string[] { memory.GetUint32(offset + 1).ToString("X8") };
                return(true);
            }
            return(false);
        }
Пример #10
0
 public override bool Parse(FAsmCommand cmd, FBytes memory, int offset)
 {
     int code = memory[offset++];
      if(code == 0xE3) {
     // 11100011 - Short
     return true;
      }
      return false;
 }
Пример #11
0
        public override bool Parse(FAsmCommand cmd, FBytes memory, int offset)
        {
            byte code = memory[offset++];

            if ((code & 0xFE) == 0x02)
            {
                // 0000 001w oorrrmmm
                cmd.Size       = 2;
                cmd.Attributes = RAsm.OoRrrMmmName(code & 0x01, memory[offset + 1]);
                return(true);
            }
            else if ((code & 0xFE) == 0x00)
            {
                // 0000 000w oorrrmmm
                cmd.Size       = 2;
                cmd.Attributes = RAsm.OoRrrMmmName(code & 0x01, memory[offset + 1]);
                return(true);
            }
            else if ((code & 0xFE) == 0x04)
            {
                // 0000010w
                if ((code & 0x01) == 0x00)
                {
                    cmd.Size       = 1 + RAsm.W0_BYTES;
                    cmd.Attributes = new string[] { memory[offset + 1].ToString("X2") };
                }
                else
                {
                    cmd.Size       = 1 + RAsm.W1_BYTES;
                    cmd.Attributes = new string[] { memory.GetUint32(offset + 1).ToString("X8") };
                }
                return(true);
            }
            else if ((code & 0xFE) == 0x82)
            {
                int code2 = memory[offset++];
                if ((code2 & 0x38) == 0x00)
                {
                    // 1000 001w oo00 0mmm
                    cmd.Size = 2;
                    RAsm.ParseOoMmm(cmd, code & 0x01, (code2 & 0xC0) >> 6, code2 & 0x07, memory, offset);
                    return(true);
                }
            }
            else if ((code & 0xFE) == 0x80)
            {
                int code2 = memory[offset + 1];
                if ((code2 & 0x38) == 0x00)
                {
                    // 1000 000w oo000mmm
                    cmd.Size = 2;
                    return(true);
                }
            }
            return(false);
        }
Пример #12
0
        // <OpCode name="Rep" flag="11110011" regs="" mode="8086" text="Repeat Following String Operation" />
        public override bool Parse(FAsmCommand cmd, FBytes memory, int offset)
        {
            int code = memory[offset];

            if (code == 0xF3)
            {
                int code2 = memory[offset + 1];
                cmd.Size = 2;
            }
            return(true);
        }
Пример #13
0
 public override bool Parse(FAsmCommand cmd, FBytes bytes, int offset, int bits)
 {
     cmd.Code = this;
     cmd.Size = 1;
     if (Parse(cmd, bytes, offset))
     {
         cmd.Memory = bytes.ToArray(offset, cmd.Size);
         return(true);
     }
     return(false);
 }
Пример #14
0
        public override bool Parse(FAsmCommand cmd, FBytes memory, int offset)
        {
            byte code = memory[offset];

            if (code == 0x8D)
            {
                // 1000 1101 oorr rmmm
                cmd.Size = 2;
                return(RAsm.ParseOoRrrMmm(cmd, 1, memory[offset + 1], memory, offset + 2));
            }
            return(false);
        }
Пример #15
0
        public override bool Parse(FAsmCommand cmd, FBytes memory, int offset)
        {
            byte code = memory[offset];

            if (code == 0x63)
            {
                // 0110 0011 oorrrmmm
                cmd.Size       = 2;
                cmd.Attributes = RAsm.OoRrrMmmName(1, memory[offset + 1]);
                return(true);
            }
            return(false);
        }
Пример #16
0
        public override bool Parse(FAsmCommand cmd, FBytes memory, int offset)
        {
            int code = memory[offset];

            if (code == 0x68)
            {
                // 0110 1000 - Imm32
                cmd.Size       = 1 + RAsm.W1_BYTES;
                cmd.Attributes = new string[] { memory.GetUint32(offset + 1).ToString("X8") };
                return(true);
            }
            return(false);
        }
Пример #17
0
        //============================================================
        // <T>从字节流中读取所有数据。</T>
        //
        // @return 保存所有数据的数组
        //============================================================
        public FBytes ReadAll()
        {
            FBytes bytes = new FBytes();
            int    read  = 0;

            do
            {
                bytes.EnsureSize(bytes.Length + RInt.SIZE_1K);
                read = _socket.NativeSocket.Receive(bytes.Memory, bytes.Length, RInt.SIZE_1K, SocketFlags.None);
                //bytes.Length += read;
            } while (read == RInt.SIZE_1K);
            return(bytes);
        }
Пример #18
0
        public override bool Parse(FAsmCommand cmd, FBytes memory, int offset)
        {
            byte code = memory[offset];

            if ((code & 0xFE) == 0x2A)
            {
                // 0010 101w oorr rmmm - Reg,Reg
                cmd.Size       = 2;
                cmd.Attributes = RAsm.OoRrrMmmName(code & 0x01, memory[offset + 1]);
                return(true);
            }
            else if ((code & 0xFE) == 0x28)
            {
                // 0010 100w oorr rmmm - Mem,Reg
                cmd.Size       = 2;
                cmd.Attributes = RAsm.OoRrrMmmName(code & 0x01, memory[offset + 1]);
                return(true);
            }
            else if ((code & 0xFE) == 0x2C)
            {
                // 0010 110w - Acc,Imm
                cmd.Size = 1;
                return(true);
            }
            else if ((code & 0xFE) == 0x82)
            {
                int code2 = memory[offset + 1];
                if ((code2 & 0x38) == 0x28)
                {
                    // 1000 001w oo10 1mmm - Reg,Imm8
                    cmd.Size = 2;
                    return(true);
                }
            }
            else if ((code & 0xFE) == 0x80)
            {
                int code2 = memory[offset + 1];
                if ((code2 & 0x38) == 0x28)
                {
                    // 1000 000w oo10 1mmm - Reg,Imm
                    cmd.Size = 2 + RAsm.GetWordBytes(code & 0x01);
                    int    oo  = (code2 & 0xC0) >> 6;
                    string des = RAsm.FuncName(code & 0x01, oo, code2 & 0x07);
                    cmd.Attributes = new object[] { des, memory.GetUint32(offset + 2) };
                    return(true);
                }
            }
            return(false);
        }
Пример #19
0
        //============================================================
        // <T>从字节流中读取指定长度的数据保存在指定数组中。</T>
        //
        // @param bytes 保存数据的数组
        // @param lenth 读取的字节数
        //============================================================
        public void ReadLength(FBytes bytes, int length)
        {
            int read   = 0;
            int remain = length;
            int block  = RInt.SIZE_4K;

            byte[] memory = new byte[block];
            while (remain > 0)
            {
                block = (remain > block) ? block : remain;
                read  = _socket.NativeSocket.Receive(memory, 0, block, SocketFlags.None);
                bytes.Append(memory, 0, read);
                remain -= read;
            }
        }
Пример #20
0
        public override bool Parse(FAsmCommand cmd, FBytes memory, int offset)
        {
            byte code = memory[offset];

            if ((code & 0xFE) == 0x12)
            {
                // 0001 001w oorr rmmm
                cmd.Size       = 2;
                cmd.Attributes = RAsm.OoRrrMmmName(code & 0x01, memory[offset + 1]);
                return(true);
            }
            else if ((code & 0xFE) == 0x10)
            {
                // 0001 000w oorr rmmm
                cmd.Size       = 2;
                cmd.Attributes = RAsm.OoRrrMmmName(code & 0x01, memory[offset + 1]);
                return(true);
            }
            else if ((code & 0xFE) == 0x14)
            {
                // 0001 010w
                cmd.Size = 1;
                return(true);
            }
            else if ((code & 0xFE) == 0x82)
            {
                int code2 = memory[offset + 1];
                if ((code2 & 0x38) == 0x10)
                {
                    // 1000 001w oo01 0mmm
                    cmd.Size = 2;
                    return(true);
                }
            }
            else if ((code & 0xFE) == 0x80)
            {
                int code2 = memory[offset + 1];
                if ((code2 & 0x38) == 0x10)
                {
                    // 1000 000w oo01 0mmm
                    cmd.Size = 2;
                    return(true);
                }
            }
            return(false);
        }
Пример #21
0
        public void Receive()
        {
            int    nIndex = 0;
            String line   = _connection._socket.Input.ReadLine(Encoding.ASCII);

            String[] lines = RString.Split(line, ' ', 3);
            if (lines.Length != 3)
            {
                throw new FFatalException("Receive: {1}", line);
            }
            _protocol   = lines[0];
            _status     = Int32.Parse(lines[1]);
            _statusNote = lines[2];
            _heads.Clear();
            while (true)
            {
                line = _connection._socket.Input.ReadLine(Encoding.ASCII);
                if (line.Length == 0)
                {
                    break;
                }
                nIndex = line.IndexOf(": ");
                if (nIndex == -1)
                {
                    throw new FFatalException("receive: {1}", line);
                }
                _heads.Set(line.Substring(0, nIndex), line.Substring(nIndex + 2));
            }
            _data = null;
            String encoding = _heads["Transfer-Encoding"];

            if ("chunked".Equals(encoding, StringComparison.CurrentCultureIgnoreCase))
            {
                ReadChunked();
            }
            else
            {
                int length = Int32.Parse(_heads[EHttpHead.ContentLength]);
                if (length > 0)
                {
                    _data = _connection._socket.Input.ReadLength(length);
                }
            }
            //
            Console.WriteLine(Dump());
        }
Пример #22
0
        public override bool Parse(FAsmCommand command, FBytes memory, int offset)
        {
            int code = memory[offset];

            if (code == 0xCC)
            {
                // 1100 1100
                return(true);
            }
            else if (code == 0xCD)
            {
                // 1100 1101
                command.Size       = 2;
                command.Attributes = new string[] { memory[offset + 1].ToString("X2") };
                return(true);
            }
            return(false);
        }
Пример #23
0
        public override bool Parse(FAsmCommand command, FBytes memory, int offset)
        {
            int code = memory[offset];

            if (code == 0xC3)
            {
                // 11000011
                command.Size       = 3;
                command.Attributes = new object[] { memory.GetUint16(offset + 1) };
            }
            else if (code == 0xC2)
            {
                // 11000010
                command.Size       = 3;
                command.Attributes = new object[] { memory.GetUint16(offset + 1) };
            }
            return(true);
        }
Пример #24
0
        public override bool Parse(FAsmCommand cmd, FBytes memory, int offset)
        {
            int code = memory[offset++];

            if (code == 0xFF)
            {
                int code2 = memory[offset + 1];
                if ((code2 & 0x18) == 0x18)
                {
                    // 1111 1111 oo01 1mmm - MemFar
                    return(true);
                }
            }
            else if (code == 0xE8)
            {
                // 1110 1000 - Near
                cmd.Size       = 1 + RInt.BYTE_SIZE;
                cmd.Attributes = new object[] { memory.GetUint32(offset) };
                return(true);
            }
            else if (code == 0x9A)
            {
                // 1001 1010 - Far
                cmd.Size       = 1 + RAsm.W1_BYTES;
                cmd.Attributes = new object[] { memory.GetUint32(offset + 1) };
                return(true);
            }
            else if (code == 0xFF)
            {
                // 1111 1111 oo01 0mmm - RegWord
                return(true);
            }
            else if (code == 0xFF)
            {
                int code2 = memory[offset + 1];
                if ((code2 & 0x38) == 0x10)
                {
                    // 11111111oo010mmm - MemNear
                }
                return(true);
            }
            return(false);
        }
Пример #25
0
        public override bool Parse(FAsmCommand cmd, FBytes memory, int offset)
        {
            int code = memory[offset++];

            if ((code & 0xF0) == 0x70)
            {
                // 0111 cccc - Short
                return(true);
            }
            else if (code == 0x0F)
            {
                int code2 = memory[offset++];
                if ((code2 & 0xF0) == 0x80)
                {
                    // 0000 1111 1000 cccc - Near
                    cmd.Size = 2;
                }
            }
            return(false);
        }
Пример #26
0
        //============================================================
        // <T>读取所有数据。</T>
        //
        // @return 保存所有数据的数组
        //============================================================
        public FBytes ReadAll()
        {
            FBytes bytes = new FBytes();

            byte[] buffer = new byte[_readLimit];
            while (true)
            {
                int length = _socket.NativeSocket.Receive(buffer, 0, _readLimit, SocketFlags.None);
                if (length > 0)
                {
                    bytes.Append(buffer, 0, length);
                }
                // 检查是否完成
                if (length != _readLimit)
                {
                    break;
                }
            }
            return(bytes);
        }
Пример #27
0
        public FAsmCommands Parse(uint address, byte[] memory, int offset, int length)
        {
            FBytes bytes = new FBytes();

            bytes.Append(memory, offset, length);
            FAsmCommands cmds = new FAsmCommands();
            int          end  = offset + length;

            for (int n = offset; n < end; n++)
            {
                FAsmCommand cmd = new FAsmCommand();
                cmd.Address = address;
                if (_codes.Parse(cmd, bytes, n, 0))
                {
                    address += (uint)cmd.Size;
                    n       += cmd.Size - 1;
                    cmds.Push(cmd);
                }
            }
            return(cmds);
        }
Пример #28
0
        public override bool Parse(FAsmCommand cmd, FBytes memory, int offset, int bits)
        {
            byte       data     = memory[offset + bits / 8];
            bool       flag     = ((data & (0x01 << (7 - bits % 8))) == 0);
            FAsmOpPath opObject = flag ? _object0 : _object1;

            if (opObject != null)
            {
                return(opObject.Parse(cmd, memory, offset, bits + 1));
            }
            int count = _codes.Count;

            for (int n = 0; n < count; n++)
            {
                if (_codes[n].Parse(cmd, memory, offset, 0))
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #29
0
        private void ReadChunked()
        {
            int    length = 0;
            String line   = null;
            FBytes bytes  = new FBytes();

            while (true)
            {
                line = _connection._socket.Input.ReadLine(Encoding.ASCII);
                if (RString.IsEmpty(line))
                {
                    break;
                }
                line   = line.Trim();
                length = Convert.ToInt32(line, 16);
                if (length == 0)
                {
                    break;
                }
                _connection._socket.Input.ReadLength(bytes, length);
            }
            _data = bytes;
        }
Пример #30
0
        //============================================================
        // <T>执行处理。</T>
        //============================================================
        public override void OnProcess()
        {
            FBytes data = new FBytes();

            // 异步处理
            while (!IsStop)
            {
                // 接收数据
                int length = _socket.Input.ReadAll(data);
                if (length == -1)
                {
                    break;
                }
                if (length > 0)
                {
                    lock (_socketData) {
                        _socketData.Append(data);
                    }
                }
                data.Clear();
            }
            // 移除端口线程
            _service.SocketThreadRemove(this);
        }