Пример #1
0
        public HandshakeMessage(IDataStream stream)
        {
            msg_type = (HandshakeType)stream.ReadByte();

            byte[] lengthData = new byte[] { 0, (byte)stream.ReadByte(), (byte)stream.ReadByte(), (byte)stream.ReadByte() };
            length = ByteUtil.ReadUInt32(lengthData, 0);

            if (msg_type == HandshakeType.client_hello)
            {
                body = new ClientHello(stream);
            }
            else
            {
                throw new Exception("TLS Handshake type \"" + msg_type + "\" is not supported.");
            }
        }
Пример #2
0
        public DesktopScreen(IDataStream s)
        {
            adapterIndex = (byte)s.ReadByte();
            outputIndex  = (byte)s.ReadByte();

            ushort strLength = s.ReadUInt16();

            adapterName = Encoding.UTF8.GetString(ByteUtil.ReadNBytes(s, strLength));

            strLength  = s.ReadUInt16();
            outputName = Encoding.UTF8.GetString(ByteUtil.ReadNBytes(s, strLength));

            X      = s.ReadInt16();
            Y      = s.ReadInt16();
            Width  = s.ReadUInt16();
            Height = s.ReadUInt16();
        }
Пример #3
0
        public DesktopInfo(IDataStream s)
        {
            int count = s.ReadByte();
            List <DesktopScreen> listOfScreens = new List <DesktopScreen>();

            for (int i = 0; i < count; i++)
            {
                listOfScreens.Add(new DesktopScreen(s));
            }
            screens = listOfScreens.ToArray();
        }
Пример #4
0
            public byte ReadByte(long index)
            {
                var off = index % fullChunkSize;

                if (off < chunkStart.Length)
                {
                    return(chunkStart.ReadByte(off));
                }
                else if (off > fullChunkSize - 3)
                {
                    return(chunkEnd.ReadByte(off - (fullChunkSize - 2)));
                }
                else
                {
                    var chunk = index / fullChunkSize;
                    off -= chunkStart.Length;
                    return(innerStream.ReadByte(chunk * chunkSize + off));
                }
            }
Пример #5
0
        public FragmentedImage(IDataStream s)
        {
            streamId = (byte)s.ReadByte();

            List <MovedImageFragment> moveList = new List <MovedImageFragment>();
            List <DirtyImageFragment> dirtList = new List <DirtyImageFragment>();

            ushort moveFragCount  = s.ReadUInt16();
            ushort dirtyFragCount = s.ReadUInt16();

            for (int i = 0; i < moveFragCount; i++)
            {
                moveList.Add(new MovedImageFragment(s));
            }
            for (int i = 0; i < dirtyFragCount; i++)
            {
                dirtList.Add(new DirtyImageFragment(s));
            }

            movedFragments = moveList.ToArray();
            dirtyFragments = dirtList.ToArray();
        }
Пример #6
0
 /// <inheritdoc/>
 public byte ReadByte(long index)
 {
     IDataStreamHelpers.ReadByteArgsCheck(this, index);
     return(stream.ReadByte(offset + index));
 }
Пример #7
0
 /// <inheritdoc/>
 public byte ReadByte(long index)
 {
     return(MessageData.ReadByte(index));
 }
Пример #8
0
            /// <summary>
            /// Parse the header from data stream
            /// </summary>
            /// <param name="s"></param>
            /// <returns>length of missing payload data (negative if there are more data than neccessary)</returns>
            public long ParseHeader(IDataStream s)
            {
                headerLength = 2;
                var len = s.Length;

                if (len < 2)
                {
                    throw new ArgumentException("Stream too short to contain the header!");
                }
                byte b1, b2;

                b1                = s.ReadByte(0);
                b2                = s.ReadByte(1);
                msg.FIN           = (b1 & 0x80) == 0x80;
                msg.RSV1          = (b1 & 0x40) == 0x40;
                msg.RSV2          = (b1 & 0x20) == 0x20;
                msg.RSV3          = (b1 & 0x10) == 0x10;
                msg.Opcode        = (OpcodeType)(b1 & 0x0F);
                msg.MASK          = (b2 & 0x80) == 0x80;
                msg.PayloadLength = b2 & ~0x80;
                byte[] buffer;
                if (msg.PayloadLength == 126)
                {
                    if (len < 4)
                    {
                        throw new ArgumentException("Stream too short to contain the header!");
                    }
                    buffer = new byte[2];
                    s.ReadBytesToBuffer(buffer, 2, 2);
                    if (BitConverter.IsLittleEndian)
                    {
                        b1        = buffer[0];
                        buffer[0] = buffer[1];
                        buffer[1] = b1;
                    }
                    msg.PayloadLength = BitConverter.ToUInt16(buffer, 0);
                    headerLength     += 2;
                }
                else if (msg.PayloadLength == 127)
                {
                    if (len < 10)
                    {
                        throw new ArgumentException("Stream too short to contain the header!");
                    }
                    buffer = new byte[8];
                    s.ReadBytesToBuffer(buffer, 2, 8);
                    if (BitConverter.IsLittleEndian)
                    {
                        Array.Reverse(buffer);
                    }
                    // lets hope no one will ever send a websocket message that long that this actually matters.
                    msg.PayloadLength = (long)BitConverter.ToUInt64(buffer, 0);
                    headerLength     += 8;
                }
                if (msg.MASK)
                {
                    buffer = new byte[4];
                    s.ReadBytesToBuffer(buffer, headerLength, 4);
                    msg.MaskingKey = buffer;
                    headerLength  += 4;
                }
                return(headerLength + msg.PayloadLength - len);
            }
Пример #9
0
 /// <inheritdoc/>
 public byte ReadByte(long index)
 {
     return(binaryStream.ReadByte(index));
 }
Пример #10
0
        /// <inheritdoc/>
        public byte ReadByte(long index)
        {
            var b = innerStream.ReadByte(index);

            return((byte)(b ^ mask[index % 4]));
        }
Пример #11
0
 /// <inheritdoc/>
 public byte ReadByte(long index)
 {
     return(innerStream.ReadByte(index));
 }