The DYNVC_DATA_FIRST_COMPRESSED PDU is used to send the first block of data of a fragmented message when the data block is compressed.
Inheritance: DataDvcBasePdu
        private void SendFirstCompressedDataPdu(uint channelId, uint uncomprressedDataLength, byte[] rawChannelData, DynamicVC_TransportType transport)
        {
            //Assume that only the raw channel data of a single DataFirstCompressedDvcPdu are passed.
            DataFirstCompressedDvcPdu firstCompressedPdu = new DataFirstCompressedDvcPdu(channelId, uncomprressedDataLength, rawChannelData);

            firstCompressedPdu.GetNonDataSize();
            Send(firstCompressedPdu, transport);
        }
        private void SendFirstCompressedDataPdu(uint channelId, byte[] data, DynamicVC_TransportType transport, uint?dataLength = null)
        {
            //According to section 3.1.5.1.4 of MS-RDPEDYC,
            //If the total uncompressed length of the message exceeds 1,590 bytes,
            //the DYNVC_DATA_FIRST_COMPRESSED (section 2.2.3.3) PDU is sent as the first data PDU,
            //followed by DYNVC_DATA_COMPRESSED (section 2.2.3.4) PDUs until all the data has been sent.
            if (data.Length <= ConstLength.MAX_UNCOMPRESSED_DATA_LENGTH)
            {
                byte[] compressedData = pduBuilder.CompressDataToRdp8BulkEncodedData(data, PACKET_COMPR_FLAG.PACKET_COMPR_TYPE_LITE | PACKET_COMPR_FLAG.PACKET_COMPRESSED);
                DataFirstCompressedDvcPdu firstCompressedPdu = new DataFirstCompressedDvcPdu(channelId, (uint)data.Length, compressedData);
                firstCompressedPdu.GetNonDataSize();
                Send(firstCompressedPdu, transport);
            }
            else
            {
                //Cmd:4 bits, Len: 2 bits, cbChid:2 bits, ChannelId: 8 bit, Length: no more than 1600, so it it 16 bits. Totally, 4 bytes
                // Descriptor is 1 byte, Header is 1 byte
                //So the max length of the data should be 1600 (Max Chunk Length)-6
                byte[] uncompressedData = new byte[ConstLength.MAX_FIRST_COMPRESSED_DATA_LENGTH];
                Array.Copy(data, uncompressedData, ConstLength.MAX_FIRST_COMPRESSED_DATA_LENGTH);
                byte[] compressedData = pduBuilder.CompressDataToRdp8BulkEncodedData(uncompressedData, PACKET_COMPR_FLAG.PACKET_COMPR_TYPE_LITE | PACKET_COMPR_FLAG.PACKET_COMPRESSED);

                DataFirstCompressedDvcPdu firstCompressedPdu = new DataFirstCompressedDvcPdu(channelId, (uint)data.Length, compressedData);
                firstCompressedPdu.GetNonDataSize();
                Send(firstCompressedPdu, transport);

                int leftBytes         = uncompressedData.Length - (int)ConstLength.MAX_FIRST_COMPRESSED_DATA_LENGTH;
                int followingMsgCount = 0;

                if (leftBytes > 0)
                {
                    int followingLen = data.Length - (int)ConstLength.MAX_FIRST_COMPRESSED_DATA_LENGTH;
                    followingMsgCount = (followingLen / (int)ConstLength.MAX_COMPRESSED_DATA_LENGTH);
                    followingMsgCount = (followingLen % (int)ConstLength.MAX_COMPRESSED_DATA_LENGTH == 0) ? followingMsgCount : ++followingMsgCount;
                    for (int i = 0; i < followingMsgCount; i++)
                    {
                        if (i != followingMsgCount)
                        {
                            byte[] followingUnCompressedData = new byte[ConstLength.MAX_COMPRESSED_DATA_LENGTH];
                            Array.Copy(data, i * ConstLength.MAX_COMPRESSED_DATA_LENGTH + ConstLength.MAX_FIRST_COMPRESSED_DATA_LENGTH, followingUnCompressedData, 0, ConstLength.MAX_COMPRESSED_DATA_LENGTH);
                            byte[] followingCompressedData = pduBuilder.CompressDataToRdp8BulkEncodedData(followingUnCompressedData, PACKET_COMPR_FLAG.PACKET_COMPR_TYPE_LITE | PACKET_COMPR_FLAG.PACKET_COMPRESSED);

                            DynamicVCPDU followingCompressedPDU = pduBuilder.CreateDataCompressedReqPdu(channelId, followingCompressedData);
                            Send(followingCompressedPDU, transport);
                        }
                        else //Last message
                        {
                            byte[] lastUnCompressedData = new byte[data.Length - i * ConstLength.MAX_COMPRESSED_DATA_LENGTH];
                            Array.Copy(data, i * ConstLength.MAX_COMPRESSED_DATA_LENGTH + ConstLength.MAX_FIRST_COMPRESSED_DATA_LENGTH, lastUnCompressedData, 0, followingLen - i * ConstLength.MAX_COMPRESSED_DATA_LENGTH);
                            byte[] lastCompressedData = pduBuilder.CompressDataToRdp8BulkEncodedData(lastUnCompressedData, PACKET_COMPR_FLAG.PACKET_COMPR_TYPE_LITE | PACKET_COMPR_FLAG.PACKET_COMPRESSED);

                            DynamicVCPDU followingPdu = pduBuilder.CreateDataCompressedReqPdu(channelId, lastCompressedData);
                            Send(followingPdu, transport);
                        }
                    }
                }
            }
        }
        public void SendFirstCompressedDataPdu(uint channelId, byte[] data)
        {
            if (data.Length < 1599 - 4)//Cmd:4 bits, Len: 2 bits, cbChid:2 bits, ChannelId: 8 bit, Length: no more than 1599, so it it 16 bits. Totally, 4 bytes
            {
                byte[] compressedData = pduBuilder.CompressDataToRdp8BulkEncodedData(data, PACKET_COMPR_FLAG.PACKET_COMPR_TYPE_LITE | PACKET_COMPR_FLAG.PACKET_COMPRESSED);
                DataFirstCompressedDvcPdu firstCompressedPdu = new DataFirstCompressedDvcPdu(channelId, (uint)data.Length, compressedData);
                firstCompressedPdu.GetNonDataSize();
                Send(firstCompressedPdu, DynamicVC_TransportType.RDP_UDP_Reliable);
            }
            else
            {
                //Cmd:4 bits, Len: 2 bits, cbChid:2 bits, ChannelId: 8 bit, Length: no more than 1599, so it it 16 bits. Totally, 4 bytes
                //So the max length of the data should be 1599-4
                byte[] uncompressedData = new byte[1595];
                Array.Copy(data, uncompressedData, 1599 - 4);
                byte[] compressedData = pduBuilder.CompressDataToRdp8BulkEncodedData(uncompressedData, PACKET_COMPR_FLAG.PACKET_COMPR_TYPE_LITE | PACKET_COMPR_FLAG.PACKET_COMPRESSED);

                DataFirstCompressedDvcPdu firstCompressedPdu = new DataFirstCompressedDvcPdu(channelId, (uint)data.Length, compressedData);
                firstCompressedPdu.GetNonDataSize();
                Send(firstCompressedPdu, DynamicVC_TransportType.RDP_UDP_Reliable);

                int leftBytes         = uncompressedData.Length % 1595;
                int followingMsgCount = 0;

                if (leftBytes > 0)
                {
                    followingMsgCount = data.Length / 1595 + 1 - 1; //minus the FirstCompressedData
                    for (int i = 0; i < followingMsgCount; i++)
                    {
                        if (i != followingMsgCount)
                        {
                            byte[] followingUnCompressedData = new byte[1595];
                            Array.Copy(data, i * 1595, followingUnCompressedData, 0, 1595);
                            byte[] followingCompressedData = pduBuilder.CompressDataToRdp8BulkEncodedData(followingUnCompressedData, PACKET_COMPR_FLAG.PACKET_COMPR_TYPE_LITE | PACKET_COMPR_FLAG.PACKET_COMPRESSED);

                            DynamicVCPDU followingCompressedPDU = pduBuilder.CreateDataCompressedReqPdu(channelId, followingCompressedData);
                            Send(followingCompressedPDU, DynamicVC_TransportType.RDP_UDP_Reliable);
                        }
                        else //Last message
                        {
                            byte[] lastUnCompressedData = new byte[data.Length - i * 1595];
                            Array.Copy(data, i * 1595, lastUnCompressedData, 0, data.Length - i * 1595);
                            byte[] lastCompressedData = pduBuilder.CompressDataToRdp8BulkEncodedData(lastUnCompressedData, PACKET_COMPR_FLAG.PACKET_COMPR_TYPE_LITE | PACKET_COMPR_FLAG.PACKET_COMPRESSED);

                            DynamicVCPDU followingPdu = pduBuilder.CreateDataCompressedReqPdu(channelId, lastCompressedData);
                            Send(followingPdu, DynamicVC_TransportType.RDP_UDP_Reliable);
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        ///  Create DYNVC_DATA_FIRST_COMPRESSED
        /// </summary>
        public DataFirstCompressedDvcPdu CreateDataFristCompressedReqPdu(uint channelId, byte[] data)
        {
            DataFirstCompressedDvcPdu firstCompressedPdu = null;

            if (data.Length <= ConstLength.MAX_FIRST_COMPRESSED_DATA_LENGTH)
            {
                firstCompressedPdu = new DataFirstCompressedDvcPdu(channelId, (uint)data.Length, data);
            }
            else
            {
                byte[] firstBlockData = new byte[(int)SEGMENT_PART_SISE.MAX_PACKET_COMPR_TYPE_RDP8_LITE_SEGMENT_PART_SIZE];
                Array.Copy(data, firstBlockData, (long)SEGMENT_PART_SISE.MAX_PACKET_COMPR_TYPE_RDP8_LITE_SEGMENT_PART_SIZE);

                firstCompressedPdu = new DataFirstCompressedDvcPdu(channelId, (uint)data.Length, firstBlockData);
            }
            firstCompressedPdu.GetNonDataSize();


            return(firstCompressedPdu);
        }
        /// <summary>
        ///  Create DYNVC_DATA_FIRST_COMPRESSED 
        /// </summary>        
        public DataFirstCompressedDvcPdu CreateDataFristCompressedReqPdu(uint channelId, byte[] data)
        {
            DataFirstCompressedDvcPdu firstCompressedPdu = null;
            //int maxDataBlockLen = 1599-
            if (data.Length < 1599)
            {
                firstCompressedPdu = new DataFirstCompressedDvcPdu(channelId, (uint)data.Length, data);
            }
            else
            {

                byte[] firstBlockData = new byte[(int)SEGMENT_PART_SISE.MAX_PACKET_COMPR_TYPE_RDP8_LITE_SEGMENT_PART_SIZE];
                Array.Copy(data, firstBlockData, (long)SEGMENT_PART_SISE.MAX_PACKET_COMPR_TYPE_RDP8_LITE_SEGMENT_PART_SIZE);

                firstCompressedPdu = new DataFirstCompressedDvcPdu(channelId, (uint)data.Length, firstBlockData);
            }
            firstCompressedPdu.GetNonDataSize();

            return firstCompressedPdu;
        }
        public void SendFirstCompressedDataPdu(uint channelId, byte[] data)
        {
            if (data.Length < 1599-4)//Cmd:4 bits, Len: 2 bits, cbChid:2 bits, ChannelId: 8 bit, Length: no more than 1599, so it it 16 bits. Totally, 4 bytes
            {
                byte[] compressedData = pduBuilder.CompressDataToRdp8BulkEncodedData(data, PACKET_COMPR_FLAG.PACKET_COMPR_TYPE_LITE | PACKET_COMPR_FLAG.PACKET_COMPRESSED);
                DataFirstCompressedDvcPdu firstCompressedPdu = new DataFirstCompressedDvcPdu(channelId, (uint)data.Length, compressedData);
                firstCompressedPdu.GetNonDataSize();
                Send(firstCompressedPdu, DynamicVC_TransportType.RDP_UDP_Reliable);
            }
            else
            {
                //Cmd:4 bits, Len: 2 bits, cbChid:2 bits, ChannelId: 8 bit, Length: no more than 1599, so it it 16 bits. Totally, 4 bytes
                //So the max length of the data should be 1599-4
                byte[] uncompressedData = new byte[1595];
                Array.Copy(data, uncompressedData, 1599 - 4);
                byte[] compressedData = pduBuilder.CompressDataToRdp8BulkEncodedData(uncompressedData, PACKET_COMPR_FLAG.PACKET_COMPR_TYPE_LITE | PACKET_COMPR_FLAG.PACKET_COMPRESSED);

                DataFirstCompressedDvcPdu firstCompressedPdu = new DataFirstCompressedDvcPdu(channelId, (uint)data.Length, compressedData);
                firstCompressedPdu.GetNonDataSize();
                Send(firstCompressedPdu, DynamicVC_TransportType.RDP_UDP_Reliable);

                int leftBytes = uncompressedData.Length % 1595;
                int followingMsgCount = 0;

                if (leftBytes > 0)
                {
                    followingMsgCount = data.Length / 1595 + 1 - 1; //minus the FirstCompressedData
                    for (int i = 0; i < followingMsgCount; i++)
                    {
                        if (i != followingMsgCount)
                        {
                            byte[] followingUnCompressedData = new byte[1595];
                            Array.Copy(data, i * 1595, followingUnCompressedData, 0, 1595);
                            byte[] followingCompressedData = pduBuilder.CompressDataToRdp8BulkEncodedData(followingUnCompressedData, PACKET_COMPR_FLAG.PACKET_COMPR_TYPE_LITE | PACKET_COMPR_FLAG.PACKET_COMPRESSED);

                            DynamicVCPDU followingCompressedPDU = pduBuilder.CreateDataCompressedReqPdu(channelId, followingCompressedData);
                            Send(followingCompressedPDU, DynamicVC_TransportType.RDP_UDP_Reliable);
                        }
                        else //Last message
                        {
                            byte[] lastUnCompressedData = new byte[data.Length - i * 1595];
                            Array.Copy(data, i * 1595, lastUnCompressedData, 0, data.Length - i * 1595);
                            byte[] lastCompressedData = pduBuilder.CompressDataToRdp8BulkEncodedData(lastUnCompressedData, PACKET_COMPR_FLAG.PACKET_COMPR_TYPE_LITE | PACKET_COMPR_FLAG.PACKET_COMPRESSED);

                            DynamicVCPDU followingPdu = pduBuilder.CreateDataCompressedReqPdu(channelId, lastCompressedData);
                            Send(followingPdu, DynamicVC_TransportType.RDP_UDP_Reliable);
                        }
                    }
                }
            }
        }