This class offers the completion for the compression algorithm
예제 #1
0
 public byte[] CompressDataToRdp8BulkEncodedData(byte[] data, PACKET_COMPR_FLAG compressedFlag)
 {
     //When the length of the original uncompressed message data being sent exceeds 1,590 bytes,
     //and bulk data compression of the channel data is desired, the DYNVC_DATA_FIRST_COMPRESSED (section 2.2.3.3) PDU is sent as the first data PDU.
     if (compressedFlag == (PACKET_COMPR_FLAG.PACKET_COMPR_TYPE_LITE | PACKET_COMPR_FLAG.PACKET_COMPRESSED))
     {
         CompressFactory cpf = new CompressFactory(
             (int)SEGMENT_PART_SISE.MAX_PACKET_COMPR_TYPE_RDP8_LITE_MATCH_DISTANCE,
             (int)SEGMENT_PART_SISE.MAX_PACKET_COMPR_TYPE_RDP8_LITE_SEGMENT_PART_SIZE);
         return(cpf.Compress(data));
     }
     if (compressedFlag == (PACKET_COMPR_FLAG.PACKET_COMPR_TYPE_RDP8 | PACKET_COMPR_FLAG.PACKET_COMPRESSED)
         )
     {
         CompressFactory cpf = new CompressFactory(
             (int)SEGMENT_PART_SISE.MAX_PACKET_COMPR_TYPE_RDP8_MATCH_DISTANCE,
             (int)SEGMENT_PART_SISE.MAX_PACKET_COMPR_TYPE_RDP8_SEGMENT_PART_SIZE);
         return(cpf.Compress(data));
     }
     //Otherwise, no compress
     return(data);
 }
        public byte[] CompressDataToRdp8BulkEncodedData(byte[] data, PACKET_COMPR_FLAG compressedFlag)
        {
            //When the length of the original uncompressed message data being sent exceeds 1,590 bytes,
            //and bulk data compression of the channel data is desired, the DYNVC_DATA_FIRST_COMPRESSED (section 2.2.3.3) PDU is sent as the first data PDU.
            if (compressedFlag == (PACKET_COMPR_FLAG.PACKET_COMPR_TYPE_LITE | PACKET_COMPR_FLAG.PACKET_COMPRESSED))
            {
                CompressFactory cpf = new CompressFactory(
                   (int)SEGMENT_PART_SISE.MAX_PACKET_COMPR_TYPE_RDP8_LITE_MATCH_DISTANCE,
                   (int)SEGMENT_PART_SISE.MAX_PACKET_COMPR_TYPE_RDP8_LITE_SEGMENT_PART_SIZE);
                return cpf.Compress(data);

            }
            if (compressedFlag == (PACKET_COMPR_FLAG.PACKET_COMPR_TYPE_RDP8 | PACKET_COMPR_FLAG.PACKET_COMPRESSED)
                )
            {
                CompressFactory cpf = new CompressFactory(
                   (int)SEGMENT_PART_SISE.MAX_PACKET_COMPR_TYPE_RDP8_MATCH_DISTANCE,
                   (int)SEGMENT_PART_SISE.MAX_PACKET_COMPR_TYPE_RDP8_SEGMENT_PART_SIZE);
                return cpf.Compress(data);
            }
            //Otherwise, no compress
            return data;
        }
예제 #3
0
        public void SegmentAndCompressFrame(byte[] rawSvrData, byte compressFlag, uint segmentPartSize)
        {
            // Set descriptor type based on data length
            if (rawSvrData.Length <= segmentPartSize)
            {
                segHeader.descriptor = DescriptorTypes.SINGLE;
                segHeader.bulkData   = new RDP8_BULK_ENCODED_DATA();

                segHeader.bulkData.header = compressFlag;

                // RDP 8.0 compression here.
                if (compressFlag == ((byte)PACKET_COMPR_FLAG.PACKET_COMPR_TYPE_RDP8 | (byte)PACKET_COMPR_FLAG.PACKET_COMPRESSED))
                {
                    CompressFactory cpf            = new CompressFactory();
                    byte[]          compressedData = cpf.Compress(rawSvrData);
                    segHeader.bulkData.data = compressedData;

                    // ETW Provider Dump message
                    string messageName = "DecompressedData";
                    ExtendedLogger.DumpMessage(messageName, RdpbcgrUtility.DumpLevel_Layer3, "Decompressed data", rawSvrData);
                }
                else
                {
                    segHeader.bulkData.data = rawSvrData;
                }

                segHeadList.Add(segHeader);
            }
            else
            {
                segHeader.descriptor       = DescriptorTypes.MULTIPART;
                segHeader.uncompressedSize = (uint)(rawSvrData.Length);
                int totalLength = rawSvrData.Length;
                if (totalLength % segmentPartSize == 0)
                {
                    segHeader.segmentCount = (ushort)(totalLength / segmentPartSize);
                }
                else
                {
                    segHeader.segmentCount = (ushort)(totalLength / segmentPartSize + 1);
                }

                segHeader.segmentArray = new RDP_DATA_SEGMENT[segHeader.segmentCount];
                uint baseIndex = 0;
                uint cnt       = 0;

                while (cnt < segHeader.segmentCount)
                {
                    Byte[] rawPartData;
                    if (cnt + 1 < segHeader.segmentCount)
                    {
                        rawPartData = new Byte[segmentPartSize];
                        Array.Copy(rawSvrData, baseIndex, rawPartData, 0, segmentPartSize);
                    }
                    else // Last segment.
                    {
                        rawPartData = new Byte[(uint)totalLength - baseIndex];
                        Array.Copy(rawSvrData, baseIndex, rawPartData, 0, (uint)totalLength - baseIndex);
                    }

                    segHeader.segmentArray[cnt] = new RDP_DATA_SEGMENT();
                    if (compressFlag == ((byte)PACKET_COMPR_FLAG.PACKET_COMPR_TYPE_RDP8 | (byte)PACKET_COMPR_FLAG.PACKET_COMPRESSED))
                    {
                        CompressFactory cpf          = new CompressFactory();
                        byte[]          compressData = cpf.Compress(rawPartData);
                        segHeader.segmentArray[cnt].bulkData        = new RDP8_BULK_ENCODED_DATA();
                        segHeader.segmentArray[cnt].bulkData.header = compressFlag;
                        segHeader.segmentArray[cnt].bulkData.data   = compressData;
                        segHeader.segmentArray[cnt].size            = (uint)(segHeader.segmentArray[cnt].bulkData.data.Length + 1);

                        // ETW Provider Dump message
                        string messageName = "DecompressedData";
                        ExtendedLogger.DumpMessage(messageName, RdpbcgrUtility.DumpLevel_Layer3, "Decompressed data", rawPartData);
                    }
                    else
                    {
                        segHeader.segmentArray[cnt].bulkData        = new RDP8_BULK_ENCODED_DATA();
                        segHeader.segmentArray[cnt].bulkData.header = compressFlag;
                        segHeader.segmentArray[cnt].bulkData.data   = rawPartData;
                        segHeader.segmentArray[cnt].size            = (uint)(segHeader.segmentArray[cnt].bulkData.data.Length + 1);
                    }

                    baseIndex += segmentPartSize;
                    cnt++;
                }

                // Add segmented data into segHeadList.
                segHeadList.Add(segHeader);
            }
        }
        public void SegmentAndCompressFrame(byte[] rawSvrData, byte compressFlag, uint segmentPartSize)
        {
            // Set descriptor type based on data length
            if (rawSvrData.Length <= segmentPartSize)
            {
                segHeader.descriptor = DescriptorTypes.SINGLE;
                segHeader.bulkData = new RDP8_BULK_ENCODED_DATA();

                segHeader.bulkData.header = compressFlag;

                // RDP 8.0 compression here.
                if (compressFlag == ((byte)PACKET_COMPR_FLAG.PACKET_COMPR_TYPE_RDP8 | (byte)PACKET_COMPR_FLAG.PACKET_COMPRESSED))
                {
                    CompressFactory cpf = new CompressFactory();
                    byte[] compressedData = cpf.Compress(rawSvrData);
                    segHeader.bulkData.data = compressedData;

                    // ETW Provider Dump message
                    string messageName = "DecompressedData";
                    ExtendedLogger.DumpMessage(messageName, RdpbcgrUtility.DumpLevel_Layer3, "Decompressed data", rawSvrData);
                }
                else
                {
                    segHeader.bulkData.data = rawSvrData;
                }

                segHeadList.Add(segHeader);
            }
            else
            {
                segHeader.descriptor = DescriptorTypes.MULTIPART;
                segHeader.uncompressedSize = (uint)(rawSvrData.Length);
                int totalLength = rawSvrData.Length;
                if (totalLength % segmentPartSize == 0)
                {
                    segHeader.segmentCount = (ushort)(totalLength / segmentPartSize);
                }
                else
                {
                    segHeader.segmentCount = (ushort)(totalLength / segmentPartSize + 1);
                }

                segHeader.segmentArray = new RDP_DATA_SEGMENT[segHeader.segmentCount];
                uint baseIndex = 0;
                uint cnt = 0;

                while (cnt < segHeader.segmentCount)
                {
                    Byte[] rawPartData;
                    if (cnt + 1 < segHeader.segmentCount)
                    {
                        rawPartData = new Byte[segmentPartSize];
                        Array.Copy(rawSvrData, baseIndex, rawPartData, 0, segmentPartSize);
                    }
                    else // Last segment.
                    {
                        rawPartData = new Byte[(uint)totalLength - baseIndex];
                        Array.Copy(rawSvrData, baseIndex, rawPartData, 0, (uint)totalLength - baseIndex);
                    }

                    segHeader.segmentArray[cnt] = new RDP_DATA_SEGMENT();
                    if (compressFlag == ((byte)PACKET_COMPR_FLAG.PACKET_COMPR_TYPE_RDP8 | (byte)PACKET_COMPR_FLAG.PACKET_COMPRESSED))
                    {
                        CompressFactory cpf = new CompressFactory();
                        byte[] compressData = cpf.Compress(rawPartData);
                        segHeader.segmentArray[cnt].bulkData = new RDP8_BULK_ENCODED_DATA();
                        segHeader.segmentArray[cnt].bulkData.header = compressFlag;
                        segHeader.segmentArray[cnt].bulkData.data = compressData;
                        segHeader.segmentArray[cnt].size = (uint)(segHeader.segmentArray[cnt].bulkData.data.Length + 1);

                        // ETW Provider Dump message
                        string messageName = "DecompressedData";
                        ExtendedLogger.DumpMessage(messageName, RdpbcgrUtility.DumpLevel_Layer3, "Decompressed data", rawPartData);
                    }
                    else
                    {
                        segHeader.segmentArray[cnt].bulkData = new RDP8_BULK_ENCODED_DATA();
                        segHeader.segmentArray[cnt].bulkData.header = compressFlag;
                        segHeader.segmentArray[cnt].bulkData.data = rawPartData;
                        segHeader.segmentArray[cnt].size = (uint)(segHeader.segmentArray[cnt].bulkData.data.Length + 1);
                    }

                    baseIndex += segmentPartSize;
                    cnt++;
                }

                // Add segmented data into segHeadList.
                segHeadList.Add(segHeader);
            }
        }
        /// <summary>
        /// Process DVC Data
        /// </summary>
        /// <param name="pdu"></param>
        private void ProcessDataPdu(DataDvcBasePdu pdu)
        {
            if (pdu is DataFirstDvcPdu)
            {
                dataFragmentManager = new DataFragmentManager();
                DataFirstDvcPdu first = (DataFirstDvcPdu)pdu;
                dataFragmentManager.AddFirstData(first.Length, first.Data);
            }
            else if (pdu is DataDvcPdu)
            {
                if (dataFragmentManager == null)
                {
                    // Single data PDU which is not fragmented.
                    if (this.Received != null)
                    {
                        this.Received(pdu.Data, this.ChannelId);
                    }
                    return;
                }
                else
                {
                    // Received a fragment.
                    dataFragmentManager.AppendData(pdu.Data);
                }
            }
            else if (pdu is DataCompressedDvcPdu)
            {
                CompressFactory Compressor = new CompressFactory();
                if (dataFragmentManager == null)
                {
                    RDP_SEGMENTED_DATA segData = new RDP_SEGMENTED_DATA();
                    bool fResult = PduMarshaler.Unmarshal(pdu.Data, segData);
                    if (fResult)
                    {
                        if (segData.descriptor == DescriptorTypes.SINGLE)
                        {
                            byte[] rawData = Compressor.Decompress(segData.bulkData.data, segData.bulkData.header);
                            // Single data PDU which is not fragmented.
                            if (this.Received != null)
                            {
                                this.Received(rawData, this.ChannelId);
                            }
                            return;
                        }
                    }
                }
                else
                {
                    // Received a fragment.
                    dataFragmentManager.AppendData(pdu.Data);
                }
            }

            if (dataFragmentManager.Completed)
            {
                if (this.Received != null)
                {
                    this.Received(dataFragmentManager.Data, this.ChannelId);
                }
                dataFragmentManager = null;
            }
        }