Example #1
0
        static Smb2Compression()
        {
            compressorInstances = new Dictionary <CompressionAlgorithm, XcaCompressor>
            {
                [CompressionAlgorithm.LZNT1]       = new LZNT1Compressor(),
                [CompressionAlgorithm.LZ77]        = new PlainLZ77Compressor(),
                [CompressionAlgorithm.LZ77Huffman] = new LZ77HuffmanCompressor()
            };
            decompressorInstances = new Dictionary <CompressionAlgorithm, XcaDecompressor>
            {
                [CompressionAlgorithm.LZNT1]       = new LZNT1Decompressor(),
                [CompressionAlgorithm.LZ77]        = new PlainLZ77Decompressor(),
                [CompressionAlgorithm.LZ77Huffman] = new LZ77HuffmanDecompressor()
            };

            var pattern = new SMB2_COMPRESSION_PATTERN_PAYLOAD_V1();

            PatternPayloadLength = TypeMarshal.GetBlockMemorySize(pattern);

            var payloadHeader = new SMB2_COMPRESSION_PAYLOAD_HEADER();

            FieldSizeOriginalPayloadSize = TypeMarshal.GetBlockMemorySize(payloadHeader.OriginalPayloadSize);
        }
        private static void ScanForPatternV1(byte[] data, out SMB2_COMPRESSION_PATTERN_PAYLOAD_V1?forwardDataPattern, out SMB2_COMPRESSION_PATTERN_PAYLOAD_V1?backwardDataPattern)
        {
            forwardDataPattern = null;

            backwardDataPattern = null;

            int endPosition;

            if (data.Length < 64)
            {
                return;
            }

            byte front = data[0];

            int frontRepetition = 1;

            for (int i = 1; i < data.Length; i++)
            {
                if (data[i] == front)
                {
                    frontRepetition++;
                }
                else
                {
                    break;
                }
            }

            if (frontRepetition >= 64)
            {
                forwardDataPattern = new SMB2_COMPRESSION_PATTERN_PAYLOAD_V1()
                {
                    Pattern     = front,
                    Reserved1   = 0,
                    Reserved2   = 0,
                    Repetitions = (UInt32)frontRepetition,
                };
            }

            endPosition = frontRepetition;

            byte end = data[data.Length - 1];

            int endRepetition = 1;

            for (int i = data.Length - 2; i >= endPosition; i--)
            {
                if (data[i] == end)
                {
                    endRepetition++;
                }
                else
                {
                    break;
                }
            }

            if (endRepetition >= 64)
            {
                backwardDataPattern = new SMB2_COMPRESSION_PATTERN_PAYLOAD_V1()
                {
                    Pattern     = end,
                    Reserved1   = 0,
                    Reserved2   = 0,
                    Repetitions = (UInt32)endRepetition,
                };
            }
        }