コード例 #1
0
ファイル: OutputWindow.cs プロジェクト: Corillian/corefx
        // Copy up to length of bytes from input directly.
        // This is used for uncompressed block.
        public int CopyFrom(InputBuffer input, int length)
        {
            length = Math.Min(Math.Min(length, WindowSize - _bytesUsed), input.AvailableBytes);
            int copied;

            // We might need wrap around to copy all bytes.
            int tailLen = WindowSize - _end;
            if (length > tailLen)
            {
                // copy the first part     
                copied = input.CopyTo(_window, _end, tailLen);
                if (copied == tailLen)
                {
                    // only try to copy the second part if we have enough bytes in input
                    copied += input.CopyTo(_window, 0, length - tailLen);
                }
            }
            else
            {
                // only one copy is needed if there is no wrap around.
                copied = input.CopyTo(_window, _end, length);
            }

            _end = (_end + copied) & WindowMask;
            _bytesUsed += copied;
            return copied;
        }
コード例 #2
0
ファイル: HuffmanTree.cs プロジェクト: lovenets/hprose-dotnet
 public int GetNextSymbol(InputBuffer input)
 {
     uint num = input.TryLoad16Bits();
     if (input.AvailableBits == 0) {
         return -1;
     }
     int index = this.table[(int)((IntPtr)(num & this.tableMask))];
     if (index < 0) {
         uint num3 = ((uint)1) << this.tableBits;
         do {
             index = -index;
             if ((num & num3) == 0) {
                 index = this.left[index];
             }
             else {
                 index = this.right[index];
             }
             num3 = num3 << 1;
         }
         while (index < 0);
     }
     if (this.codeLengthArray[index] > input.AvailableBits) {
         return -1;
     }
     input.SkipBits(this.codeLengthArray[index]);
     return index;
 }
コード例 #3
0
ファイル: Inflater.cs プロジェクト: cooclsee/hprose-dotnet
 public Inflater(bool doGZip) {
     this.using_gzip = doGZip;
     this.output = new OutputWindow();
     this.input = new InputBuffer();
     this.gZipDecoder = new GZipDecoder(this.input);
     this.codeList = new byte[320];
     this.codeLengthTreeCodeLength = new byte[0x13];
     this.Reset();
 }
コード例 #4
0
 public int CopyFrom(InputBuffer input, int length) {
     int num;
     length = Math.Min(Math.Min(length, 0x8000 - this.bytesUsed), input.AvailableBytes);
     int num2 = 0x8000 - this.end;
     if (length > num2) {
         num = input.CopyTo(this.window, this.end, num2);
         if (num == num2) {
             num += input.CopyTo(this.window, 0, length - num2);
         }
     }
     else {
         num = input.CopyTo(this.window, this.end, length);
     }
     this.end = (this.end + num) & 0x7fff;
     this.bytesUsed += num;
     return num;
 }
コード例 #5
0
        public int CopyFrom(InputBuffer input, int length)
        {
            int num;

            length = Math.Min(Math.Min(length, 0x8000 - this.bytesUsed), input.AvailableBytes);
            int num2 = 0x8000 - this.end;

            if (length > num2)
            {
                num = input.CopyTo(this.window, this.end, num2);
                if (num == num2)
                {
                    num += input.CopyTo(this.window, 0, length - num2);
                }
            }
            else
            {
                num = input.CopyTo(this.window, this.end, length);
            }
            this.end        = (this.end + num) & 0x7fff;
            this.bytesUsed += num;
            return(num);
        }
コード例 #6
0
 public bool ReadFooter(InputBuffer input)
 {
     input.SkipToByteBoundary();
     if (this.gzipFooterSubstate == GzipHeaderState.ReadingCRC)
     {
         while (this.loopCounter < 4)
         {
             int bits = input.GetBits(8);
             if (bits < 0)
             {
                 return(false);
             }
             this.expectedCrc32 |= (uint)(bits << (8 * this.loopCounter));
             this.loopCounter++;
         }
         this.gzipFooterSubstate = GzipHeaderState.ReadingFileSize;
         this.loopCounter        = 0;
     }
     if (this.gzipFooterSubstate == GzipHeaderState.ReadingFileSize)
     {
         if (this.loopCounter == 0)
         {
             this.expectedOutputStreamSize = 0;
         }
         while (this.loopCounter < 4)
         {
             int num2 = input.GetBits(8);
             if (num2 < 0)
             {
                 return(false);
             }
             this.expectedOutputStreamSize |= (uint)(num2 << (8 * this.loopCounter));
             this.loopCounter++;
         }
     }
     return(true);
 }
コード例 #7
0
 public bool ReadFooter(InputBuffer input)
 {
     input.SkipToByteBoundary();
     if (this.gzipFooterSubstate == GzipHeaderState.ReadingCRC)
     {
         while (this.loopCounter < 4)
         {
             int bits = input.GetBits(8);
             if (bits < 0)
             {
                 return false;
             }
             this.expectedCrc32 |= (uint) (bits << (8 * this.loopCounter));
             this.loopCounter++;
         }
         this.gzipFooterSubstate = GzipHeaderState.ReadingFileSize;
         this.loopCounter = 0;
     }
     if (this.gzipFooterSubstate == GzipHeaderState.ReadingFileSize)
     {
         if (this.loopCounter == 0)
         {
             this.expectedOutputStreamSize = 0;
         }
         while (this.loopCounter < 4)
         {
             int num2 = input.GetBits(8);
             if (num2 < 0)
             {
                 return false;
             }
             this.expectedOutputStreamSize |= (uint) (num2 << (8 * this.loopCounter));
             this.loopCounter++;
         }
     }
     return true;
 }
コード例 #8
0
        GZipDecoder gZipDecoder;        // class to decode gzip header and footer

        public Inflater(bool doGZip) {
            using_gzip = doGZip;            
            output = new OutputWindow();
            input  = new InputBuffer();
            gZipDecoder = new GZipDecoder(input);

            codeList = new byte[HuffmanTree.MaxLiteralTreeElements + HuffmanTree.MaxDistTreeElements];
            codeLengthTreeCodeLength = new byte[HuffmanTree.NumberOfCodeLengthTreeElements];
            Reset();
        }
コード例 #9
0
ファイル: GZipDecoder.cs プロジェクト: lovenets/hprose-dotnet
 public GZipDecoder(InputBuffer input)
 {
     this.input = input;
     this.Reset();
 }
コード例 #10
0
ファイル: HuffmanTree.cs プロジェクト: geoffkizer/corefx
        //
        // This function will try to get enough bits from input and 
        // try to decode the bits.
        // If there are no enought bits in the input, this function will return -1.
        //
        public int GetNextSymbol(InputBuffer input)
        {
            // Try to load 16 bits into input buffer if possible and get the bitBuffer value.
            // If there aren't 16 bits available we will return all we have in the 
            // input buffer.
            uint bitBuffer = input.TryLoad16Bits();
            if (input.AvailableBits == 0)
            {    // running out of input.
                return -1;
            }

            // decode an element 
            int symbol = _table[bitBuffer & _tableMask];
            if (symbol < 0)
            {       //  this will be the start of the binary tree
                // navigate the tree
                uint mask = (uint)1 << _tableBits;
                do
                {
                    symbol = -symbol;
                    if ((bitBuffer & mask) == 0)
                        symbol = _left[symbol];
                    else
                        symbol = _right[symbol];
                    mask <<= 1;
                } while (symbol < 0);
            }

            int codeLength = _codeLengthArray[symbol];

            // huffman code lengths must be at least 1 bit long
            if (codeLength <= 0)
            {
                throw new InvalidDataException(SR.InvalidHuffmanData);
            }

            //
            // If this code is longer than the # bits we had in the bit buffer (i.e.
            // we read only part of the code), we can hit the entry in the table or the tree
            // for another symbol. However the length of another symbol will not match the 
            // available bits count.
            if (codeLength > input.AvailableBits)
            {
                // We already tried to load 16 bits and maximum length is 15, 
                // so this means we are running out of input. 
                return -1;
            }

            input.SkipBits(codeLength);
            return symbol;
        }
コード例 #11
0
        public bool ReadHeader(InputBuffer input)
        {
            while (true)
            {
                int bits;
                switch (gzipHeaderSubstate)
                {
                case GzipHeaderState.ReadingID1:
                    bits = input.GetBits(8);
                    if (bits < 0)
                    {
                        return(false);
                    }

                    if (bits != GZipConstants.ID1)
                    {
                        throw new InvalidDataException(SR.GetString(SR.CorruptedGZipHeader));
                    }
                    gzipHeaderSubstate = GzipHeaderState.ReadingID2;
                    goto case GzipHeaderState.ReadingID2;

                case GzipHeaderState.ReadingID2:
                    bits = input.GetBits(8);
                    if (bits < 0)
                    {
                        return(false);
                    }

                    if (bits != GZipConstants.ID2)
                    {
                        throw new InvalidDataException(SR.GetString(SR.CorruptedGZipHeader));
                    }

                    gzipHeaderSubstate = GzipHeaderState.ReadingCM;
                    goto case GzipHeaderState.ReadingCM;

                case GzipHeaderState.ReadingCM:
                    bits = input.GetBits(8);
                    if (bits < 0)
                    {
                        return(false);
                    }

                    if (bits != GZipConstants.Deflate)               // compression mode must be 8 (deflate)
                    {
                        throw new InvalidDataException(SR.GetString(SR.UnknownCompressionMode));
                    }

                    gzipHeaderSubstate = GzipHeaderState.ReadingFLG;;
                    goto case GzipHeaderState.ReadingFLG;

                case GzipHeaderState.ReadingFLG:
                    bits = input.GetBits(8);
                    if (bits < 0)
                    {
                        return(false);
                    }

                    gzip_header_flag   = bits;
                    gzipHeaderSubstate = GzipHeaderState.ReadingMMTime;
                    loopCounter        = 0; // 4 MMTIME bytes
                    goto case GzipHeaderState.ReadingMMTime;

                case GzipHeaderState.ReadingMMTime:
                    bits = 0;
                    while (loopCounter < 4)
                    {
                        bits = input.GetBits(8);
                        if (bits < 0)
                        {
                            return(false);
                        }

                        loopCounter++;
                    }

                    gzipHeaderSubstate = GzipHeaderState.ReadingXFL;
                    loopCounter        = 0;
                    goto case GzipHeaderState.ReadingXFL;

                case GzipHeaderState.ReadingXFL:          // ignore XFL
                    bits = input.GetBits(8);
                    if (bits < 0)
                    {
                        return(false);
                    }

                    gzipHeaderSubstate = GzipHeaderState.ReadingOS;
                    goto case GzipHeaderState.ReadingOS;

                case GzipHeaderState.ReadingOS:          // ignore OS
                    bits = input.GetBits(8);
                    if (bits < 0)
                    {
                        return(false);
                    }

                    gzipHeaderSubstate = GzipHeaderState.ReadingXLen1;
                    goto case GzipHeaderState.ReadingXLen1;

                case GzipHeaderState.ReadingXLen1:
                    if ((gzip_header_flag & (int)GZipOptionalHeaderFlags.ExtraFieldsFlag) == 0)
                    {
                        goto case GzipHeaderState.ReadingFileName;
                    }

                    bits = input.GetBits(8);
                    if (bits < 0)
                    {
                        return(false);
                    }

                    gzip_header_xlen   = bits;
                    gzipHeaderSubstate = GzipHeaderState.ReadingXLen2;
                    goto case GzipHeaderState.ReadingXLen2;

                case GzipHeaderState.ReadingXLen2:
                    bits = input.GetBits(8);
                    if (bits < 0)
                    {
                        return(false);
                    }

                    gzip_header_xlen  |= (bits << 8);
                    gzipHeaderSubstate = GzipHeaderState.ReadingXLenData;
                    loopCounter        = 0; // 0 bytes of XLEN data read so far
                    goto case GzipHeaderState.ReadingXLenData;

                case GzipHeaderState.ReadingXLenData:
                    bits = 0;
                    while (loopCounter < gzip_header_xlen)
                    {
                        bits = input.GetBits(8);
                        if (bits < 0)
                        {
                            return(false);
                        }

                        loopCounter++;
                    }
                    gzipHeaderSubstate = GzipHeaderState.ReadingFileName;
                    loopCounter        = 0;
                    goto case GzipHeaderState.ReadingFileName;

                case GzipHeaderState.ReadingFileName:
                    if ((gzip_header_flag & (int)GZipOptionalHeaderFlags.FileNameFlag) == 0)
                    {
                        gzipHeaderSubstate = GzipHeaderState.ReadingComment;
                        goto case GzipHeaderState.ReadingComment;
                    }

                    do
                    {
                        bits = input.GetBits(8);
                        if (bits < 0)
                        {
                            return(false);
                        }

                        if (bits == 0)         // see '\0' in the file name string
                        {
                            break;
                        }
                    } while (true);

                    gzipHeaderSubstate = GzipHeaderState.ReadingComment;
                    goto case GzipHeaderState.ReadingComment;

                case GzipHeaderState.ReadingComment:
                    if ((gzip_header_flag & (int)GZipOptionalHeaderFlags.CommentFlag) == 0)
                    {
                        gzipHeaderSubstate = GzipHeaderState.ReadingCRC16Part1;
                        goto case GzipHeaderState.ReadingCRC16Part1;
                    }

                    do
                    {
                        bits = input.GetBits(8);
                        if (bits < 0)
                        {
                            return(false);
                        }

                        if (bits == 0)         // see '\0' in the file name string
                        {
                            break;
                        }
                    } while (true);

                    gzipHeaderSubstate = GzipHeaderState.ReadingCRC16Part1;
                    goto case GzipHeaderState.ReadingCRC16Part1;

                case GzipHeaderState.ReadingCRC16Part1:
                    if ((gzip_header_flag & (int)GZipOptionalHeaderFlags.CRCFlag) == 0)
                    {
                        gzipHeaderSubstate = GzipHeaderState.Done;
                        goto case GzipHeaderState.Done;
                    }

                    bits = input.GetBits(8);         // ignore crc
                    if (bits < 0)
                    {
                        return(false);
                    }

                    gzipHeaderSubstate = GzipHeaderState.ReadingCRC16Part2;
                    goto case GzipHeaderState.ReadingCRC16Part2;

                case GzipHeaderState.ReadingCRC16Part2:
                    bits = input.GetBits(8);         // ignore crc
                    if (bits < 0)
                    {
                        return(false);
                    }

                    gzipHeaderSubstate = GzipHeaderState.Done;
                    goto case GzipHeaderState.Done;

                case GzipHeaderState.Done:
                    return(true);

                default:
                    Debug.Assert(false, "We should not reach unknown state!");
                    throw new InvalidDataException(SR.GetString(SR.UnknownState));
                }
            }
        }
コード例 #12
0
        public bool ReadHeader(InputBuffer input)
        {
            int bits;
            switch (this.gzipHeaderSubstate)
            {
                case GzipHeaderState.ReadingID1:
                    bits = input.GetBits(8);
                    if (bits >= 0)
                    {
                        if (bits != 0x1f)
                        {
                            throw new InvalidDataException(SR.GetString("CorruptedGZipHeader"));
                        }
                        this.gzipHeaderSubstate = GzipHeaderState.ReadingID2;
                        break;
                    }
                    return false;

                case GzipHeaderState.ReadingID2:
                    break;

                case GzipHeaderState.ReadingCM:
                    goto Label_00A5;

                case GzipHeaderState.ReadingFLG:
                    goto Label_00CE;

                case GzipHeaderState.ReadingMMTime:
                    goto Label_00F1;

                case GzipHeaderState.ReadingXFL:
                    goto Label_0128;

                case GzipHeaderState.ReadingOS:
                    goto Label_013D;

                case GzipHeaderState.ReadingXLen1:
                    goto Label_0152;

                case GzipHeaderState.ReadingXLen2:
                    goto Label_017B;

                case GzipHeaderState.ReadingXLenData:
                    goto Label_01A8;

                case GzipHeaderState.ReadingFileName:
                    goto Label_01E5;

                case GzipHeaderState.ReadingComment:
                    goto Label_0212;

                case GzipHeaderState.ReadingCRC16Part1:
                    goto Label_0240;

                case GzipHeaderState.ReadingCRC16Part2:
                    goto Label_026A;

                case GzipHeaderState.Done:
                    goto Label_0280;

                default:
                    throw new InvalidDataException(SR.GetString("UnknownState"));
            }
            bits = input.GetBits(8);
            if (bits < 0)
            {
                return false;
            }
            if (bits != 0x8b)
            {
                throw new InvalidDataException(SR.GetString("CorruptedGZipHeader"));
            }
            this.gzipHeaderSubstate = GzipHeaderState.ReadingCM;
        Label_00A5:
            bits = input.GetBits(8);
            if (bits < 0)
            {
                return false;
            }
            if (bits != 8)
            {
                throw new InvalidDataException(SR.GetString("UnknownCompressionMode"));
            }
            this.gzipHeaderSubstate = GzipHeaderState.ReadingFLG;
        Label_00CE:
            bits = input.GetBits(8);
            if (bits < 0)
            {
                return false;
            }
            this.gzip_header_flag = bits;
            this.gzipHeaderSubstate = GzipHeaderState.ReadingMMTime;
            this.loopCounter = 0;
        Label_00F1:
            bits = 0;
            while (this.loopCounter < 4)
            {
                if (input.GetBits(8) < 0)
                {
                    return false;
                }
                this.loopCounter++;
            }
            this.gzipHeaderSubstate = GzipHeaderState.ReadingXFL;
            this.loopCounter = 0;
        Label_0128:
            if (input.GetBits(8) < 0)
            {
                return false;
            }
            this.gzipHeaderSubstate = GzipHeaderState.ReadingOS;
        Label_013D:
            if (input.GetBits(8) < 0)
            {
                return false;
            }
            this.gzipHeaderSubstate = GzipHeaderState.ReadingXLen1;
        Label_0152:
            if ((this.gzip_header_flag & 4) == 0)
            {
                goto Label_01E5;
            }
            bits = input.GetBits(8);
            if (bits < 0)
            {
                return false;
            }
            this.gzip_header_xlen = bits;
            this.gzipHeaderSubstate = GzipHeaderState.ReadingXLen2;
        Label_017B:
            bits = input.GetBits(8);
            if (bits < 0)
            {
                return false;
            }
            this.gzip_header_xlen |= bits << 8;
            this.gzipHeaderSubstate = GzipHeaderState.ReadingXLenData;
            this.loopCounter = 0;
        Label_01A8:
            bits = 0;
            while (this.loopCounter < this.gzip_header_xlen)
            {
                if (input.GetBits(8) < 0)
                {
                    return false;
                }
                this.loopCounter++;
            }
            this.gzipHeaderSubstate = GzipHeaderState.ReadingFileName;
            this.loopCounter = 0;
        Label_01E5:
            if ((this.gzip_header_flag & 8) == 0)
            {
                this.gzipHeaderSubstate = GzipHeaderState.ReadingComment;
            }
            else
            {
                do
                {
                    bits = input.GetBits(8);
                    if (bits < 0)
                    {
                        return false;
                    }
                }
                while (bits != 0);
                this.gzipHeaderSubstate = GzipHeaderState.ReadingComment;
            }
        Label_0212:
            if ((this.gzip_header_flag & 0x10) == 0)
            {
                this.gzipHeaderSubstate = GzipHeaderState.ReadingCRC16Part1;
            }
            else
            {
                do
                {
                    bits = input.GetBits(8);
                    if (bits < 0)
                    {
                        return false;
                    }
                }
                while (bits != 0);
                this.gzipHeaderSubstate = GzipHeaderState.ReadingCRC16Part1;
            }
        Label_0240:
            if ((this.gzip_header_flag & 2) == 0)
            {
                this.gzipHeaderSubstate = GzipHeaderState.Done;
                goto Label_0280;
            }
            if (input.GetBits(8) < 0)
            {
                return false;
            }
            this.gzipHeaderSubstate = GzipHeaderState.ReadingCRC16Part2;
        Label_026A:
            if (input.GetBits(8) < 0)
            {
                return false;
            }
            this.gzipHeaderSubstate = GzipHeaderState.Done;
        Label_0280:
            return true;
        }
コード例 #13
0
        public bool ReadFooter(InputBuffer input) {
            input.SkipToByteBoundary();
            if (gzipFooterSubstate == GzipHeaderState.ReadingCRC) {
                while (loopCounter < 4) { 
                    int bits = input.GetBits(8);
                    if (bits < 0) {
                        return false;
                    }

                    expectedCrc32 |= ((uint)bits << (8 * loopCounter));
                    loopCounter++;
                }
                gzipFooterSubstate = GzipHeaderState.ReadingFileSize;
                loopCounter = 0;

            }

            if (gzipFooterSubstate == GzipHeaderState.ReadingFileSize) {
                if (loopCounter == 0)
                    expectedOutputStreamSizeModulo = 0;

                while (loopCounter < 4) {
                    int bits = input.GetBits(8);
                    if (bits < 0) {
                        return false;
                    }

                    expectedOutputStreamSizeModulo |= ((uint) bits << (8 * loopCounter));
                    loopCounter++;
                }
            }

            return true;
        }
コード例 #14
0
        public bool ReadHeader(InputBuffer input)
        {
            int bits;

            switch (this.gzipHeaderSubstate)
            {
            case GzipHeaderState.ReadingID1:
                bits = input.GetBits(8);
                if (bits >= 0)
                {
                    if (bits != 0x1f)
                    {
                        throw new InvalidDataException(SR.GetString("CorruptedGZipHeader"));
                    }
                    this.gzipHeaderSubstate = GzipHeaderState.ReadingID2;
                    break;
                }
                return(false);

            case GzipHeaderState.ReadingID2:
                break;

            case GzipHeaderState.ReadingCM:
                goto Label_00A5;

            case GzipHeaderState.ReadingFLG:
                goto Label_00CE;

            case GzipHeaderState.ReadingMMTime:
                goto Label_00F1;

            case GzipHeaderState.ReadingXFL:
                goto Label_0128;

            case GzipHeaderState.ReadingOS:
                goto Label_013D;

            case GzipHeaderState.ReadingXLen1:
                goto Label_0152;

            case GzipHeaderState.ReadingXLen2:
                goto Label_017B;

            case GzipHeaderState.ReadingXLenData:
                goto Label_01A8;

            case GzipHeaderState.ReadingFileName:
                goto Label_01E5;

            case GzipHeaderState.ReadingComment:
                goto Label_0212;

            case GzipHeaderState.ReadingCRC16Part1:
                goto Label_0240;

            case GzipHeaderState.ReadingCRC16Part2:
                goto Label_026A;

            case GzipHeaderState.Done:
                goto Label_0280;

            default:
                throw new InvalidDataException(SR.GetString("UnknownState"));
            }
            bits = input.GetBits(8);
            if (bits < 0)
            {
                return(false);
            }
            if (bits != 0x8b)
            {
                throw new InvalidDataException(SR.GetString("CorruptedGZipHeader"));
            }
            this.gzipHeaderSubstate = GzipHeaderState.ReadingCM;
Label_00A5:
            bits = input.GetBits(8);
            if (bits < 0)
            {
                return(false);
            }
            if (bits != 8)
            {
                throw new InvalidDataException(SR.GetString("UnknownCompressionMode"));
            }
            this.gzipHeaderSubstate = GzipHeaderState.ReadingFLG;
Label_00CE:
            bits = input.GetBits(8);
            if (bits < 0)
            {
                return(false);
            }
            this.gzip_header_flag   = bits;
            this.gzipHeaderSubstate = GzipHeaderState.ReadingMMTime;
            this.loopCounter        = 0;
Label_00F1:
            bits = 0;
            while (this.loopCounter < 4)
            {
                if (input.GetBits(8) < 0)
                {
                    return(false);
                }
                this.loopCounter++;
            }
            this.gzipHeaderSubstate = GzipHeaderState.ReadingXFL;
            this.loopCounter        = 0;
Label_0128:
            if (input.GetBits(8) < 0)
            {
                return(false);
            }
            this.gzipHeaderSubstate = GzipHeaderState.ReadingOS;
Label_013D:
            if (input.GetBits(8) < 0)
            {
                return(false);
            }
            this.gzipHeaderSubstate = GzipHeaderState.ReadingXLen1;
Label_0152:
            if ((this.gzip_header_flag & 4) == 0)
            {
                goto Label_01E5;
            }
            bits = input.GetBits(8);
            if (bits < 0)
            {
                return(false);
            }
            this.gzip_header_xlen   = bits;
            this.gzipHeaderSubstate = GzipHeaderState.ReadingXLen2;
Label_017B:
            bits = input.GetBits(8);
            if (bits < 0)
            {
                return(false);
            }
            this.gzip_header_xlen  |= bits << 8;
            this.gzipHeaderSubstate = GzipHeaderState.ReadingXLenData;
            this.loopCounter        = 0;
Label_01A8:
            bits = 0;
            while (this.loopCounter < this.gzip_header_xlen)
            {
                if (input.GetBits(8) < 0)
                {
                    return(false);
                }
                this.loopCounter++;
            }
            this.gzipHeaderSubstate = GzipHeaderState.ReadingFileName;
            this.loopCounter        = 0;
Label_01E5:
            if ((this.gzip_header_flag & 8) == 0)
            {
                this.gzipHeaderSubstate = GzipHeaderState.ReadingComment;
            }
            else
            {
                do
                {
                    bits = input.GetBits(8);
                    if (bits < 0)
                    {
                        return(false);
                    }
                }while (bits != 0);
                this.gzipHeaderSubstate = GzipHeaderState.ReadingComment;
            }
Label_0212:
            if ((this.gzip_header_flag & 0x10) == 0)
            {
                this.gzipHeaderSubstate = GzipHeaderState.ReadingCRC16Part1;
            }
            else
            {
                do
                {
                    bits = input.GetBits(8);
                    if (bits < 0)
                    {
                        return(false);
                    }
                }while (bits != 0);
                this.gzipHeaderSubstate = GzipHeaderState.ReadingCRC16Part1;
            }
Label_0240:
            if ((this.gzip_header_flag & 2) == 0)
            {
                this.gzipHeaderSubstate = GzipHeaderState.Done;
                goto Label_0280;
            }
            if (input.GetBits(8) < 0)
            {
                return(false);
            }
            this.gzipHeaderSubstate = GzipHeaderState.ReadingCRC16Part2;
Label_026A:
            if (input.GetBits(8) < 0)
            {
                return(false);
            }
            this.gzipHeaderSubstate = GzipHeaderState.Done;
Label_0280:
            return(true);
        }
コード例 #15
0
ファイル: Inflater.cs プロジェクト: REALTOBIZ/mono
        IFileFormatReader formatReader;  // class to decode header and footer (e.g. gzip)

        public Inflater() {           
            output = new OutputWindow();
            input  = new InputBuffer();

            codeList = new byte[HuffmanTree.MaxLiteralTreeElements + HuffmanTree.MaxDistTreeElements];
            codeLengthTreeCodeLength = new byte[HuffmanTree.NumberOfCodeLengthTreeElements];
            Reset();
        }
コード例 #16
0
ファイル: InflaterManaged.cs プロジェクト: Corillian/corefx
        internal InflaterManaged(IFileFormatReader reader, bool deflate64)
        {
            _output = new OutputWindow();
            _input = new InputBuffer();

            _codeList = new byte[HuffmanTree.MaxLiteralTreeElements + HuffmanTree.MaxDistTreeElements];
            _codeLengthTreeCodeLength = new byte[HuffmanTree.NumberOfCodeLengthTreeElements];
            _deflate64 = deflate64;
            if (reader != null)
            {
                _formatReader = reader;
                _hasFormatReader = true;
            }
            Reset();
        }
コード例 #17
0
ファイル: InflaterManaged.cs プロジェクト: Corillian/corefx
        private IFileFormatReader _formatReader;  // class to decode header and footer (e.g. gzip)

        public InflaterManaged(bool deflate64)
        {
            _output = new OutputWindow();
            _input = new InputBuffer();

            _codeList = new byte[HuffmanTree.MaxLiteralTreeElements + HuffmanTree.MaxDistTreeElements];
            _codeLengthTreeCodeLength = new byte[HuffmanTree.NumberOfCodeLengthTreeElements];
            _deflate64 = deflate64;
            Reset();
        }
コード例 #18
0
 public int GetNextSymbol(InputBuffer input)
 {
     uint num = input.TryLoad16Bits();
     if (input.AvailableBits == 0)
     {
         return -1;
     }
     int index = this.table[(int) ((IntPtr) (num & this.tableMask))];
     if (index < 0)
     {
         uint num3 = ((uint) 1) << this.tableBits;
         do
         {
             index = -index;
             if ((num & num3) == 0)
             {
                 index = this.left[index];
             }
             else
             {
                 index = this.right[index];
             }
             num3 = num3 << 1;
         }
         while (index < 0);
     }
     int n = this.codeLengthArray[index];
     if (n <= 0)
     {
         throw new InvalidDataException(SR.GetString("InvalidHuffmanData"));
     }
     if (n > input.AvailableBits)
     {
         return -1;
     }
     input.SkipBits(n);
     return index;
 }
コード例 #19
0
        public bool ReadHeader(InputBuffer input) {

            while (true) {
                int bits;
                switch (gzipHeaderSubstate) {
                    case GzipHeaderState.ReadingID1:
                        bits = input.GetBits(8);
                        if (bits < 0) {
                            return false;
                        }

                        if (bits != GZipConstants.ID1) {
                            throw new InvalidDataException(SR.GetString(SR.CorruptedGZipHeader));
                        }
                        gzipHeaderSubstate = GzipHeaderState.ReadingID2;
                        goto case GzipHeaderState.ReadingID2;

                    case GzipHeaderState.ReadingID2:
                        bits = input.GetBits(8);
                        if (bits < 0) {
                            return false;
                        }

                        if (bits != GZipConstants.ID2) {
                            throw new InvalidDataException(SR.GetString(SR.CorruptedGZipHeader));
                        }

                        gzipHeaderSubstate = GzipHeaderState.ReadingCM;
                        goto case GzipHeaderState.ReadingCM;

                    case GzipHeaderState.ReadingCM:
                        bits = input.GetBits(8);
                        if (bits < 0) {
                            return false;
                        }

                        if (bits != GZipConstants.Deflate) {         // compression mode must be 8 (deflate)
                            throw new InvalidDataException(SR.GetString(SR.UnknownCompressionMode));
                        }

                        gzipHeaderSubstate = GzipHeaderState.ReadingFLG; ;
                        goto case GzipHeaderState.ReadingFLG;

                    case GzipHeaderState.ReadingFLG:
                        bits = input.GetBits(8);
                        if (bits < 0) {
                            return false;
                        }

                        gzip_header_flag = bits;
                        gzipHeaderSubstate = GzipHeaderState.ReadingMMTime;
                        loopCounter = 0; // 4 MMTIME bytes
                        goto case GzipHeaderState.ReadingMMTime;

                    case GzipHeaderState.ReadingMMTime:
                        bits = 0;
                        while (loopCounter < 4) {
                            bits = input.GetBits(8);
                            if (bits < 0) {
                                return false;
                            }

                            loopCounter++;
                        }

                        gzipHeaderSubstate = GzipHeaderState.ReadingXFL;
                        loopCounter = 0;
                        goto case GzipHeaderState.ReadingXFL;

                    case GzipHeaderState.ReadingXFL:      // ignore XFL
                        bits = input.GetBits(8);
                        if (bits < 0) {
                            return false;
                        }

                        gzipHeaderSubstate = GzipHeaderState.ReadingOS;
                        goto case GzipHeaderState.ReadingOS;

                    case GzipHeaderState.ReadingOS:      // ignore OS
                        bits = input.GetBits(8);
                        if (bits < 0) {
                            return false;
                        }

                        gzipHeaderSubstate = GzipHeaderState.ReadingXLen1;
                        goto case GzipHeaderState.ReadingXLen1;

                    case GzipHeaderState.ReadingXLen1:
                        if ((gzip_header_flag & (int)GZipOptionalHeaderFlags.ExtraFieldsFlag) == 0) {
                            goto case GzipHeaderState.ReadingFileName;
                        }

                        bits = input.GetBits(8);
                        if (bits < 0) {
                            return false;
                        }

                        gzip_header_xlen = bits;
                        gzipHeaderSubstate = GzipHeaderState.ReadingXLen2;
                        goto case GzipHeaderState.ReadingXLen2;

                    case GzipHeaderState.ReadingXLen2:
                        bits = input.GetBits(8);
                        if (bits < 0) {
                            return false;
                        }

                        gzip_header_xlen |= (bits << 8);
                        gzipHeaderSubstate = GzipHeaderState.ReadingXLenData;
                        loopCounter = 0; // 0 bytes of XLEN data read so far
                        goto case GzipHeaderState.ReadingXLenData;

                    case GzipHeaderState.ReadingXLenData:
                        bits = 0;
                        while (loopCounter < gzip_header_xlen) {
                            bits = input.GetBits(8);
                            if (bits < 0) {
                                return false;
                            }

                            loopCounter++;
                        }
                        gzipHeaderSubstate = GzipHeaderState.ReadingFileName;
                        loopCounter = 0;
                        goto case GzipHeaderState.ReadingFileName;

                    case GzipHeaderState.ReadingFileName:
                        if ((gzip_header_flag & (int)GZipOptionalHeaderFlags.FileNameFlag) == 0) {
                            gzipHeaderSubstate = GzipHeaderState.ReadingComment;
                            goto case GzipHeaderState.ReadingComment;
                        }

                        do {
                            bits = input.GetBits(8);
                            if (bits < 0) {
                                return false;
                            }

                            if (bits == 0) {   // see '\0' in the file name string
                                break;
                            }
                        } while (true);

                        gzipHeaderSubstate = GzipHeaderState.ReadingComment;
                        goto case GzipHeaderState.ReadingComment;

                    case GzipHeaderState.ReadingComment:
                        if ((gzip_header_flag & (int)GZipOptionalHeaderFlags.CommentFlag) == 0) {
                            gzipHeaderSubstate = GzipHeaderState.ReadingCRC16Part1;
                            goto case GzipHeaderState.ReadingCRC16Part1;
                        }

                        do {
                            bits = input.GetBits(8);
                            if (bits < 0) {
                                return false;
                            }

                            if (bits == 0) {   // see '\0' in the file name string
                                break;
                            }
                        } while (true);

                        gzipHeaderSubstate = GzipHeaderState.ReadingCRC16Part1;
                        goto case GzipHeaderState.ReadingCRC16Part1;

                    case GzipHeaderState.ReadingCRC16Part1:
                        if ((gzip_header_flag & (int)GZipOptionalHeaderFlags.CRCFlag) == 0) {
                            gzipHeaderSubstate = GzipHeaderState.Done;
                            goto case GzipHeaderState.Done;
                        }

                        bits = input.GetBits(8);     // ignore crc
                        if (bits < 0) {
                            return false;
                        }

                        gzipHeaderSubstate = GzipHeaderState.ReadingCRC16Part2;
                        goto case GzipHeaderState.ReadingCRC16Part2;

                    case GzipHeaderState.ReadingCRC16Part2:
                        bits = input.GetBits(8);     // ignore crc
                        if (bits < 0) {
                            return false;
                        }

                        gzipHeaderSubstate = GzipHeaderState.Done;
                        goto case GzipHeaderState.Done;

                    case GzipHeaderState.Done:
                        return true;
                    default:
                        Debug.Assert(false, "We should not reach unknown state!");
                        throw new InvalidDataException(SR.GetString(SR.UnknownState));
                }
            }
        }
コード例 #20
0
 public GZipDecoder(InputBuffer input)
 {
     this.input = input;
     this.Reset();
 }