Пример #1
0
        public int GetSymbol(StreamManipulator input)
        {
            int num;

            if ((num = input.PeekBits(9)) >= 0)
            {
                int num2;
                if ((num2 = (int)this.tree[num]) >= 0)
                {
                    input.DropBits(num2 & 15);
                    return(num2 >> 4);
                }
                int num3     = -(num2 >> 4);
                int bitCount = num2 & 15;
                if ((num = input.PeekBits(bitCount)) >= 0)
                {
                    num2 = (int)this.tree[num3 | num >> 9];
                    input.DropBits(num2 & 15);
                    return(num2 >> 4);
                }
                int availableBits = input.AvailableBits;
                num  = input.PeekBits(availableBits);
                num2 = (int)this.tree[num3 | num >> 9];
                if ((num2 & 15) <= availableBits)
                {
                    input.DropBits(num2 & 15);
                    return(num2 >> 4);
                }
                return(-1);
            }
            else
            {
                int availableBits2 = input.AvailableBits;
                num = input.PeekBits(availableBits2);
                int num2 = (int)this.tree[num];
                if (num2 >= 0 && (num2 & 15) <= availableBits2)
                {
                    input.DropBits(num2 & 15);
                    return(num2 >> 4);
                }
                return(-1);
            }
        }
Пример #2
0
        /// <summary>
        /// Reads the next symbol from input.  The symbol is encoded using the
        /// huffman tree.
        /// </summary>
        /// <param name="input">
        /// input the input source.
        /// </param>
        /// <returns>
        /// the next symbol, or -1 if not enough input is available.
        /// </returns>
        public int GetSymbol(StreamManipulator input)
        {
            int lookahead, symbol;

            if ((lookahead = input.PeekBits(9)) >= 0)
            {
                if ((symbol = tree[lookahead]) >= 0)
                {
                    input.DropBits(symbol & 15);
                    return(symbol >> 4);
                }
                int subtree = -(symbol >> 4);
                int bitlen  = symbol & 15;
                if ((lookahead = input.PeekBits(bitlen)) >= 0)
                {
                    symbol = tree[subtree | (lookahead >> 9)];
                    input.DropBits(symbol & 15);
                    return(symbol >> 4);
                }
                int bits = input.AvailableBits;
                lookahead = input.PeekBits(bits);
                symbol    = tree[subtree | (lookahead >> 9)];
                if ((symbol & 15) <= bits)
                {
                    input.DropBits(symbol & 15);
                    return(symbol >> 4);
                }
                return(-1);
            }
            else
            {
                int bits = input.AvailableBits;
                lookahead = input.PeekBits(bits);
                symbol    = tree[lookahead];
                if (symbol >= 0 && (symbol & 15) <= bits)
                {
                    input.DropBits(symbol & 15);
                    return(symbol >> 4);
                }
                return(-1);
            }
        }
Пример #3
0
        /// <summary>
        ///   Decodes a zlib/RFC1950 header.
        /// </summary>
        /// <returns> False if more input is needed. </returns>
        /// <exception cref="SharpZipBaseException">The header is invalid.</exception>
        private bool DecodeHeader()
        {
            int header = input.PeekBits(16);

            if (header < 0)
            {
                return(false);
            }

            input.DropBits(16);

            /* The header is written in "wrong" byte order */
            header = ((header << 8) | (header >> 8)) & 0xffff;
            if (header % 31 != 0)
            {
                throw new SharpZipBaseException("Header checksum illegal");
            }

            if ((header & 0x0f00) != (Deflater.DEFLATED << 8))
            {
                throw new SharpZipBaseException("Compression Method unknown");
            }

            /* Maximum size of the backwards window in bits.
             * We currently ignore this, but we could use it to make the
             * inflater window more space efficient. On the other hand the
             * full window (15 bits) is needed most times, anyway.
             *          int max_wbits = ((header & 0x7000) >> 12) + 8;
             */
            if ((header & 0x0020) == 0)
            {
                // Dictionary flag?
                mode = DECODE_BLOCKS;
            }
            else
            {
                mode       = DECODE_DICT;
                neededBits = 32;
            }

            return(true);
        }
Пример #4
0
        private bool Decode()
        {
            switch (mode)
            {
            case 0:
                return(DecodeHeader());

            case 1:
                return(DecodeDict());

            case 11:
                return(DecodeChecksum());

            case 2:
                if (isLastBlock)
                {
                    mode = 12;
                    return(false);
                }

                int type = input.PeekBits(3);
                if (type < 0)
                {
                    return(false);
                }
                input.DropBits(3);

                isLastBlock |= (type & 1) != 0;
                switch (type >> 1)
                {
                case 0:
                    input.SkipToByteBoundary();
                    mode = 3;
                    break;

                case 1:
                    litlenTree = null;
                    distTree   = null;
                    mode       = 7;
                    break;

                case 2:
                    dynHeader = new Header();
                    mode      = 6;
                    break;
                }
                return(true);

            case 3:
            {
                if ((uncomprLen = input.PeekBits(16)) < 0)
                {
                    return(false);
                }
                input.DropBits(16);
                mode = 4;
            }
                goto case 4;

            case 4:
            {
                int nlen = input.PeekBits(16);
                if (nlen < 0)
                {
                    return(false);
                }
                input.DropBits(16);
                mode = 5;
            }
                goto case 5;

            case 5:
            {
                int more = output.CopyStored(input, uncomprLen);
                uncomprLen -= more;
                if (uncomprLen == 0)
                {
                    mode = 2;
                    return(true);
                }
                return(!input.isNeedingInput);
            }

            case 6:
                if (!dynHeader.Decode(input))
                {
                    return(false);
                }

                litlenTree = dynHeader.BuildLitLenTree();
                distTree   = dynHeader.BuildDistTree();
                mode       = 7;
                goto case 7;

            case 7:
            case 8:
            case 9:
            case 10:
                return(DecodeHuffman());

            case 12:
                return(false);

            default:
                throw new Exception("Inflater.Decode unknown mode");
            }
        }
Пример #5
0
        public bool Decode(StreamManipulator input)
        {
decode_loop:
            for (;;)
            {
                switch (mode)
                {
                case LNUM:
                    lnum = input.PeekBits(5);
                    if (lnum < 0)
                    {
                        return(false);
                    }
                    lnum += 257;
                    input.DropBits(5);

                    mode = DNUM;
                    goto case DNUM;

                case DNUM:
                    dnum = input.PeekBits(5);
                    if (dnum < 0)
                    {
                        return(false);
                    }
                    dnum++;
                    input.DropBits(5);
                    num         = lnum + dnum;
                    litdistLens = new byte[num];
                    mode        = BLNUM;
                    goto case BLNUM;

                case BLNUM:
                    blnum = input.PeekBits(4);
                    if (blnum < 0)
                    {
                        return(false);
                    }
                    blnum += 4;
                    input.DropBits(4);
                    blLens = new byte[19];
                    ptr    = 0;
                    mode   = BLLENS;
                    goto case BLLENS;

                case BLLENS:
                    while (ptr < blnum)
                    {
                        int len = input.PeekBits(3);
                        if (len < 0)
                        {
                            return(false);
                        }
                        input.DropBits(3);

                        blLens[BL_ORDER[ptr]] = (byte)len;
                        ptr++;
                    }
                    blTree = new InflaterHuffmanTree(blLens);
                    blLens = null;
                    ptr    = 0;
                    mode   = LENS;
                    goto case LENS;

                case LENS:
                {
                    int symbol;
                    while (((symbol = blTree.GetSymbol(input)) & ~15) == 0)
                    {
                        litdistLens[ptr++] = lastLen = (byte)symbol;

                        if (ptr == num)
                        {
                            return(true);
                        }
                    }


                    if (symbol < 0)
                    {
                        return(false);
                    }


                    if (symbol >= 17)
                    {
                        lastLen = 0;
                    }
                    else
                    {
                        if (ptr == 0)
                        {
                            throw new SharpZipBaseException();
                        }
                    }
                    repSymbol = symbol - 16;
                }
                    mode = REPS;
                    goto case REPS;

                case REPS:
                {
                    int bits  = repBits[repSymbol];
                    int count = input.PeekBits(bits);
                    if (count < 0)
                    {
                        return(false);
                    }
                    input.DropBits(bits);
                    count += repMin[repSymbol];


                    if (ptr + count > num)
                    {
                        throw new SharpZipBaseException();
                    }
                    while (count-- > 0)
                    {
                        litdistLens[ptr++] = lastLen;
                    }

                    if (ptr == num)
                    {
                        return(true);
                    }
                }
                    mode = LENS;
                    goto decode_loop;
                }
            }
        }
        // Token: 0x06000863 RID: 2147 RVA: 0x00030D64 File Offset: 0x0002EF64
        public bool Decode(StreamManipulator input)
        {
            while (true)
            {
                switch (this.mode)
                {
                case 0:
                    this.lnum = input.PeekBits(5);
                    if (this.lnum < 0)
                    {
                        return(false);
                    }
                    this.lnum += 257;
                    input.DropBits(5);
                    this.mode = 1;
                    goto IL_61;

                case 1:
                    goto IL_61;

                case 2:
                    goto IL_B9;

                case 3:
                    break;

                case 4:
                    goto IL_1A8;

                case 5:
                    goto IL_1EE;

                default:
                    continue;
                }
IL_13B:
                while (this.ptr < this.blnum)
                {
                    int num = input.PeekBits(3);
                    if (num < 0)
                    {
                        return(false);
                    }
                    input.DropBits(3);
                    this.blLens[InflaterDynHeader.BL_ORDER[this.ptr]] = (byte)num;
                    this.ptr++;
                }
                this.blTree = new InflaterHuffmanTree(this.blLens);
                this.blLens = null;
                this.ptr    = 0;
                this.mode   = 4;
IL_1A8:
                int symbol;
                while (((symbol = this.blTree.GetSymbol(input)) & -16) == 0)
                {
                    this.litdistLens[this.ptr++] = (this.lastLen = (byte)symbol);
                    if (this.ptr == this.num)
                    {
                        return(true);
                    }
                }
                if (symbol < 0)
                {
                    return(false);
                }
                if (symbol >= 17)
                {
                    this.lastLen = 0;
                }
                else if (this.ptr == 0)
                {
                    goto Block_10;
                }
                this.repSymbol = symbol - 16;
                this.mode      = 5;
IL_1EE:
                int bitCount = InflaterDynHeader.repBits[this.repSymbol];
                int num2 = input.PeekBits(bitCount);
                if (num2 < 0)
                {
                    return(false);
                }
                input.DropBits(bitCount);
                num2 += InflaterDynHeader.repMin[this.repSymbol];
                if (this.ptr + num2 > this.num)
                {
                    goto Block_12;
                }
                while (num2-- > 0)
                {
                    this.litdistLens[this.ptr++] = this.lastLen;
                }
                if (this.ptr == this.num)
                {
                    return(true);
                }
                this.mode = 4;
                continue;
IL_B9:
                this.blnum = input.PeekBits(4);
                if (this.blnum < 0)
                {
                    return(false);
                }
                this.blnum += 4;
                input.DropBits(4);
                this.blLens = new byte[19];
                this.ptr    = 0;
                this.mode   = 3;
                goto IL_13B;
IL_61:
                this.dnum = input.PeekBits(5);
                if (this.dnum < 0)
                {
                    return(false);
                }
                this.dnum++;
                input.DropBits(5);
                this.num         = this.lnum + this.dnum;
                this.litdistLens = new byte[this.num];
                this.mode        = 2;
                goto IL_B9;
            }
            return(false);

Block_10:
            throw new SharpZipBaseException();
Block_12:
            throw new SharpZipBaseException();
        }
        public bool Decode(StreamManipulator input)
        {
decode_loop:
            for (;;)
            {
                switch (mode)
                {
                case LNUM:
                    lnum = input.PeekBits(5);
                    if (lnum < 0)
                    {
                        return(false);
                    }
                    lnum += 257;
                    input.DropBits(5);
                    litlenLens = new byte[lnum];
                    //          System.err.println("LNUM: "+lnum);
                    mode = DNUM;
                    goto case DNUM;                            /* fall through */

                case DNUM:
                    dnum = input.PeekBits(5);
                    if (dnum < 0)
                    {
                        return(false);
                    }
                    dnum++;
                    input.DropBits(5);
                    distLens = new byte[dnum];
                    //          System.err.println("DNUM: "+dnum);
                    mode = BLNUM;
                    goto case BLNUM;                            /* fall through */

                case BLNUM:
                    blnum = input.PeekBits(4);
                    if (blnum < 0)
                    {
                        return(false);
                    }
                    blnum += 4;
                    input.DropBits(4);
                    blLens = new byte[19];
                    ptr    = 0;
                    //          System.err.println("BLNUM: "+blnum);
                    mode = BLLENS;
                    goto case BLLENS;                            /* fall through */

                case BLLENS:
                    while (ptr < blnum)
                    {
                        int len = input.PeekBits(3);
                        if (len < 0)
                        {
                            return(false);
                        }
                        input.DropBits(3);
                        //          System.err.println("blLens["+BL_ORDER[ptr]+"]: "+len);
                        blLens[BL_ORDER[ptr]] = (byte)len;
                        ptr++;
                    }
                    blTree = new InflaterHuffmanTree(blLens);
                    blLens = null;
                    ptr    = 0;
                    mode   = LLENS;
                    goto case LLENS;                            /* fall through */

                case LLENS:
                    while (ptr < lnum)
                    {
                        int symbol = blTree.GetSymbol(input);
                        if (symbol < 0)
                        {
                            return(false);
                        }
                        switch (symbol)
                        {
                        default:
                            //              System.err.println("litlenLens["+ptr+"]: "+symbol);
                            litlenLens[ptr++] = (byte)symbol;
                            break;

                        case 16:                                         /* repeat last len 3-6 times */
                            if (ptr == 0)
                            {
                                throw new Exception("Repeating, but no prev len");
                            }

                            //              System.err.println("litlenLens["+ptr+"]: repeat");
                            repeatedLen = litlenLens[ptr - 1];
                            repBits     = 2;
                            for (int i = 3; i-- > 0;)
                            {
                                if (ptr >= lnum)
                                {
                                    throw new Exception();
                                }
                                litlenLens[ptr++] = repeatedLen;
                            }
                            mode = LREPS;
                            goto decode_loop;

                        case 17:                                         /* repeat zero 3-10 times */
                            //              System.err.println("litlenLens["+ptr+"]: zero repeat");
                            repeatedLen = 0;
                            repBits     = 3;
                            for (int i = 3; i-- > 0;)
                            {
                                if (ptr >= lnum)
                                {
                                    throw new Exception();
                                }
                                litlenLens[ptr++] = repeatedLen;
                            }
                            mode = LREPS;
                            goto decode_loop;

                        case 18:                                         /* repeat zero 11-138 times */
                            //              System.err.println("litlenLens["+ptr+"]: zero repeat");
                            repeatedLen = 0;
                            repBits     = 7;
                            for (int i = 11; i-- > 0;)
                            {
                                if (ptr >= lnum)
                                {
                                    throw new Exception();
                                }
                                litlenLens[ptr++] = repeatedLen;
                            }
                            mode = LREPS;
                            goto decode_loop;
                        }
                    }
                    ptr  = 0;
                    mode = DLENS;
                    goto case DLENS;                            /* fall through */

                case DLENS:
                    while (ptr < dnum)
                    {
                        int symbol = blTree.GetSymbol(input);
                        if (symbol < 0)
                        {
                            return(false);
                        }
                        switch (symbol)
                        {
                        default:
                            distLens[ptr++] = (byte)symbol;
                            //              System.err.println("distLens["+ptr+"]: "+symbol);
                            break;

                        case 16:                                                 /* repeat last len 3-6 times */
                            if (ptr == 0)
                            {
                                throw new Exception("Repeating, but no prev len");
                            }
                            //              System.err.println("distLens["+ptr+"]: repeat");
                            repeatedLen = distLens[ptr - 1];
                            repBits     = 2;
                            for (int i = 3; i-- > 0;)
                            {
                                if (ptr >= dnum)
                                {
                                    throw new Exception();
                                }
                                distLens[ptr++] = repeatedLen;
                            }
                            mode = DREPS;
                            goto decode_loop;

                        case 17:                                                 /* repeat zero 3-10 times */
                            //              System.err.println("distLens["+ptr+"]: repeat zero");
                            repeatedLen = 0;
                            repBits     = 3;
                            for (int i = 3; i-- > 0;)
                            {
                                if (ptr >= dnum)
                                {
                                    throw new Exception();
                                }
                                distLens[ptr++] = repeatedLen;
                            }
                            mode = DREPS;
                            goto decode_loop;

                        case 18:                                                 /* repeat zero 11-138 times */
                            //              System.err.println("distLens["+ptr+"]: repeat zero");
                            repeatedLen = 0;
                            repBits     = 7;
                            for (int i = 11; i-- > 0;)
                            {
                                if (ptr >= dnum)
                                {
                                    throw new Exception();
                                }
                                distLens[ptr++] = repeatedLen;
                            }
                            mode = DREPS;
                            goto decode_loop;
                        }
                    }
                    mode = FINISH;
                    return(true);

                case LREPS:
                {
                    int count = input.PeekBits(repBits);
                    if (count < 0)
                    {
                        return(false);
                    }
                    input.DropBits(repBits);
                    //            System.err.println("litlenLens repeat: "+repBits);
                    while (count-- > 0)
                    {
                        if (ptr >= lnum)
                        {
                            throw new Exception();
                        }
                        litlenLens[ptr++] = repeatedLen;
                    }
                }
                    mode = LLENS;
                    goto decode_loop;

                case DREPS:
                {
                    int count = input.PeekBits(repBits);
                    if (count < 0)
                    {
                        return(false);
                    }
                    input.DropBits(repBits);
                    while (count-- > 0)
                    {
                        if (ptr >= dnum)
                        {
                            throw new Exception();
                        }
                        distLens[ptr++] = repeatedLen;
                    }
                }
                    mode = DLENS;
                    goto decode_loop;
                }
            }
        }
Пример #8
0
 /// <summary>
 /// Reads the next symbol from input.  The symbol is encoded using the
 /// huffman tree.
 /// </summary>
 /// <param name="input">
 /// input the input source.
 /// </param>
 /// <returns>
 /// the next symbol, or -1 if not enough input is available.
 /// </returns>
 public int GetSymbol(StreamManipulator input)
 {
     int lookahead, symbol;
     if ((lookahead = input.PeekBits(9)) >= 0) {
         if ((symbol = tree[lookahead]) >= 0) {
             input.DropBits(symbol & 15);
             return symbol >> 4;
         }
         int subtree = -(symbol >> 4);
         int bitlen = symbol & 15;
         if ((lookahead = input.PeekBits(bitlen)) >= 0) {
             symbol = tree[subtree | (lookahead >> 9)];
             input.DropBits(symbol & 15);
             return symbol >> 4;
         } else {
             int bits = input.AvailableBits;
             lookahead = input.PeekBits(bits);
             symbol = tree[subtree | (lookahead >> 9)];
             if ((symbol & 15) <= bits) {
                 input.DropBits(symbol & 15);
                 return symbol >> 4;
             } else {
                 return -1;
             }
         }
     } else {
         int bits = input.AvailableBits;
         lookahead = input.PeekBits(bits);
         symbol = tree[lookahead];
         if (symbol >= 0 && (symbol & 15) <= bits) {
             input.DropBits(symbol & 15);
             return symbol >> 4;
         } else {
             return -1;
         }
     }
 }
Пример #9
0
        public bool Decode(StreamManipulator input)
        {
            decode_loop:
            for (;;) {
                switch (mode) {
                    case LNUM:
                        lnum = input.PeekBits(5);
                        if (lnum < 0) {
                            return false;
                        }
                        lnum += 257;
                        input.DropBits(5);
                        litlenLens = new byte[lnum];
                        //  	    System.err.println("LNUM: "+lnum);
                        mode = DNUM;
                        goto case DNUM;/* fall through */
                    case DNUM:
                        dnum = input.PeekBits(5);
                        if (dnum < 0) {
                            return false;
                        }
                        dnum++;
                        input.DropBits(5);
                        distLens = new byte[dnum];
                        //  	    System.err.println("DNUM: "+dnum);
                        mode = BLNUM;
                        goto case BLNUM;/* fall through */
                    case BLNUM:
                        blnum = input.PeekBits(4);
                        if (blnum < 0) {
                            return false;
                        }
                        blnum += 4;
                        input.DropBits(4);
                        blLens = new byte[19];
                        ptr = 0;
                        //  	    System.err.println("BLNUM: "+blnum);
                        mode = BLLENS;
                        goto case BLLENS;/* fall through */
                    case BLLENS:
                        while (ptr < blnum) {
                            int len = input.PeekBits(3);
                            if (len < 0) {
                                return false;
                            }
                            input.DropBits(3);
                            //  		System.err.println("blLens["+BL_ORDER[ptr]+"]: "+len);
                            blLens[BL_ORDER[ptr]] = (byte) len;
                            ptr++;
                        }
                        blTree = new InflaterHuffmanTree(blLens);
                        blLens = null;
                        ptr = 0;
                        mode = LLENS;
                        goto case LLENS;/* fall through */
                    case LLENS:
                        while (ptr < lnum) {
                            int symbol = blTree.GetSymbol(input);
                            if (symbol < 0) {
                                return false;
                            }
                            switch (symbol) {
                                default:
                                    //  		    System.err.println("litlenLens["+ptr+"]: "+symbol);
                                    litlenLens[ptr++] = (byte) symbol;
                                    break;
                                case 16: /* repeat last len 3-6 times */
                                    if (ptr == 0) {
                                        throw new Exception("Repeating, but no prev len");
                                    }

                                    //  		    System.err.println("litlenLens["+ptr+"]: repeat");
                                    repeatedLen = litlenLens[ptr-1];
                                    repBits = 2;
                                    for (int i = 3; i-- > 0; ) {
                                        if (ptr >= lnum) {
                                            throw new Exception();
                                        }
                                        litlenLens[ptr++] = repeatedLen;
                                    }
                                    mode = LREPS;
                                    goto decode_loop;
                                case 17: /* repeat zero 3-10 times */
                                    //  		    System.err.println("litlenLens["+ptr+"]: zero repeat");
                                    repeatedLen = 0;
                                    repBits = 3;
                                    for (int i = 3; i-- > 0; ) {
                                        if (ptr >= lnum) {
                                            throw new Exception();
                                        }
                                        litlenLens[ptr++] = repeatedLen;
                                    }
                                    mode = LREPS;
                                    goto decode_loop;
                                case 18: /* repeat zero 11-138 times */
                                    //  		    System.err.println("litlenLens["+ptr+"]: zero repeat");
                                    repeatedLen = 0;
                                    repBits = 7;
                                    for (int i = 11; i-- > 0; ) {
                                        if (ptr >= lnum) {
                                            throw new Exception();
                                        }
                                        litlenLens[ptr++] = repeatedLen;
                                    }
                                    mode = LREPS;
                                    goto decode_loop;
                            }
                        }
                        ptr = 0;
                        mode = DLENS;
                        goto case DLENS;/* fall through */
                        case DLENS:
                            while (ptr < dnum) {
                                int symbol = blTree.GetSymbol(input);
                                if (symbol < 0) {
                                    return false;
                                }
                                switch (symbol) {
                                    default:
                                        distLens[ptr++] = (byte) symbol;
                                        //  		    System.err.println("distLens["+ptr+"]: "+symbol);
                                        break;
                                    case 16: /* repeat last len 3-6 times */
                                        if (ptr == 0) {
                                            throw new Exception("Repeating, but no prev len");
                                        }
                                        //  		    System.err.println("distLens["+ptr+"]: repeat");
                                        repeatedLen = distLens[ptr-1];
                                        repBits = 2;
                                        for (int i = 3; i-- > 0; ) {
                                            if (ptr >= dnum) {
                                                throw new Exception();
                                            }
                                            distLens[ptr++] = repeatedLen;
                                        }
                                        mode = DREPS;
                                        goto decode_loop;
                                    case 17: /* repeat zero 3-10 times */
                                        //  		    System.err.println("distLens["+ptr+"]: repeat zero");
                                        repeatedLen = 0;
                                        repBits = 3;
                                        for (int i = 3; i-- > 0; ) {
                                            if (ptr >= dnum) {
                                                throw new Exception();
                                            }
                                            distLens[ptr++] = repeatedLen;
                                        }
                                        mode = DREPS;
                                        goto decode_loop;
                                    case 18: /* repeat zero 11-138 times */
                                        //  		    System.err.println("distLens["+ptr+"]: repeat zero");
                                        repeatedLen = 0;
                                        repBits = 7;
                                        for (int i = 11; i-- > 0; ) {
                                            if (ptr >= dnum) {
                                                throw new Exception();
                                            }
                                            distLens[ptr++] = repeatedLen;
                                        }
                                        mode = DREPS;
                                        goto decode_loop;
                                }
                            }
                            mode = FINISH;
                        return true;
                    case LREPS:
                        {
                            int count = input.PeekBits(repBits);
                            if (count < 0) {
                                return false;
                            }
                            input.DropBits(repBits);
                            //  	      System.err.println("litlenLens repeat: "+repBits);
                            while (count-- > 0) {
                                if (ptr >= lnum) {
                                    throw new Exception();
                                }
                                litlenLens[ptr++] = repeatedLen;
                            }
                        }
                        mode = LLENS;
                        goto decode_loop;
                    case DREPS:
                        {
                            int count = input.PeekBits(repBits);
                            if (count < 0) {
                                return false;
                            }
                            input.DropBits(repBits);
                            while (count-- > 0) {
                                if (ptr >= dnum) {
                                    throw new Exception();
                                }
                                distLens[ptr++] = repeatedLen;
                            }
                        }
                        mode = DLENS;
                        goto decode_loop;
                }
            }
        }
Пример #10
0
        private bool Decode()
        {
            int num2;
            int num3;

            switch (mode)
            {
            case 0:
                return(DecodeHeader());

            case 1:
                return(DecodeDict());

            case 2:
                if (!isLastBlock)
                {
                    int num = input.PeekBits(3);
                    if (num < 0)
                    {
                        return(false);
                    }
                    input.DropBits(3);
                    if ((num & 1) != 0)
                    {
                        isLastBlock = true;
                    }
                    switch ((num >> 1))
                    {
                    case 0:
                        input.SkipToByteBoundary();
                        mode = 3;
                        goto Label_0134;

                    case 1:
                        litlenTree = InflaterHuffmanTree.DefLitLenTree;
                        distTree   = InflaterHuffmanTree.DefDistTree;
                        mode       = 7;
                        goto Label_0134;

                    case 2:
                        dynHeader = new InflaterDynHeader();
                        mode      = 6;
                        goto Label_0134;
                    }
                    throw new SharpZipBaseException("Unknown block type " + num);
                }
                if (!noHeader)
                {
                    input.SkipToByteBoundary();
                    neededBits = 0x20;
                    mode       = DECODE_CHKSUM;
                    return(true);
                }
                mode = FINISHED;
                return(false);

            case 3:
                uncomprLen = input.PeekBits(0x10);
                if (uncomprLen >= 0)
                {
                    input.DropBits(0x10);
                    mode = 4;
                    goto Label_0167;
                }
                return(false);

            case 4:
                goto Label_0167;

            case 5:
                goto Label_01A9;

            case 6:
                if (dynHeader.Decode(input))
                {
                    litlenTree = dynHeader.BuildLitLenTree();
                    distTree   = dynHeader.BuildDistTree();
                    mode       = 7;
                    goto Label_022D;
                }
                return(false);

            case 7:
            case 8:
            case 9:
            case 10:
                goto Label_022D;

            case DECODE_CHKSUM:
                return(DecodeChksum());

            case FINISHED:
                return(false);

            default:
                throw new SharpZipBaseException("Inflater.Decode unknown mode");
            }
Label_0134:
            return(true);

Label_0167:
            num2 = input.PeekBits(0x10);
            if (num2 < 0)
            {
                return(false);
            }
            input.DropBits(0x10);
            if (num2 != (uncomprLen ^ 0xffff))
            {
                throw new SharpZipBaseException("broken uncompressed block");
            }
            mode = 5;
Label_01A9:
            num3        = outputWindow.CopyStored(input, uncomprLen);
            uncomprLen -= num3;
            if (uncomprLen == 0)
            {
                mode = 2;
                return(true);
            }
            return(!input.IsNeedingInput);

Label_022D:
            return(DecodeHuffman());
        }
Пример #11
0
        public bool Decode(StreamManipulator input)
        {
            while (true)
            {
                switch (mode)
                {
                default:
                    continue;

                case 0:
                    lnum = input.PeekBits(5);
                    if (lnum < 0)
                    {
                        return(false);
                    }
                    lnum += 257;
                    input.DropBits(5);
                    mode = 1;
                    goto case 1;

                case 1:
                    dnum = input.PeekBits(5);
                    if (dnum < 0)
                    {
                        return(false);
                    }
                    dnum++;
                    input.DropBits(5);
                    this.num    = lnum + dnum;
                    litdistLens = new byte[this.num];
                    mode        = 2;
                    goto case 2;

                case 2:
                    blnum = input.PeekBits(4);
                    if (blnum < 0)
                    {
                        return(false);
                    }
                    blnum += 4;
                    input.DropBits(4);
                    blLens = new byte[19];
                    ptr    = 0;
                    mode   = 3;
                    goto case 3;

                case 3:
                    while (ptr < blnum)
                    {
                        int num = input.PeekBits(3);
                        if (num < 0)
                        {
                            return(false);
                        }
                        input.DropBits(3);
                        blLens[BL_ORDER[ptr]] = (byte)num;
                        ptr++;
                    }
                    blTree = new InflaterHuffmanTree(blLens);
                    blLens = null;
                    ptr    = 0;
                    mode   = 4;
                    goto case 4;

                case 4:
                {
                    int symbol;
                    while (((symbol = blTree.GetSymbol(input)) & -16) == 0)
                    {
                        litdistLens[ptr++] = (lastLen = (byte)symbol);
                        if (ptr == this.num)
                        {
                            return(true);
                        }
                    }
                    if (symbol < 0)
                    {
                        return(false);
                    }
                    if (symbol >= 17)
                    {
                        lastLen = 0;
                    }
                    else if (ptr == 0)
                    {
                        throw new SharpZipBaseException();
                    }
                    repSymbol = symbol - 16;
                    mode      = 5;
                    break;
                }

                case 5:
                    break;
                }
                int bitCount = repBits[repSymbol];
                int num2     = input.PeekBits(bitCount);
                if (num2 < 0)
                {
                    return(false);
                }
                input.DropBits(bitCount);
                num2 += repMin[repSymbol];
                if (ptr + num2 > this.num)
                {
                    throw new SharpZipBaseException();
                }
                while (num2-- > 0)
                {
                    litdistLens[ptr++] = lastLen;
                }
                if (ptr == this.num)
                {
                    break;
                }
                mode = 4;
            }
            return(true);
        }
Пример #12
0
        public bool Decode(StreamManipulator input)
        {
            int mode;
            int num5;

TR_002D:
            while (true)
            {
                mode = this.mode;
                switch (mode)
                {
                case 0:
                    this.lnum = input.PeekBits(5);
                    if (this.lnum < 0)
                    {
                        return(false);
                    }
                    this.lnum += 0x101;
                    input.DropBits(5);
                    this.mode = 1;
                    goto TR_0026;

                case 1:
                    goto TR_0026;

                case 2:
                    goto TR_0023;

                case 3:
                    goto TR_0021;

                case 4:
                    goto TR_001A;

                case 5:
                    break;

                default:
                {
                    continue;
                }
                }
                goto TR_000E;
            }
            goto TR_0026;
TR_000E:
            num5 = repBits[this.repSymbol];
            int num6 = input.PeekBits(num5);

            if (num6 < 0)
            {
                return(false);
            }
            input.DropBits(num5);
            num6 += repMin[this.repSymbol];
            if ((this.ptr + num6) > this.num)
            {
                throw new SharpZipBaseException();
            }
            while (true)
            {
                if (num6-- <= 0)
                {
                    if (this.ptr == this.num)
                    {
                        return(true);
                    }
                    this.mode = 4;
                    break;
                }
                mode     = this.ptr;
                this.ptr = mode + 1;
                this.litdistLens[mode] = this.lastLen;
            }
            goto TR_002D;
TR_001A:
            while (true)
            {
                int num3;
                if (((num3 = this.blTree.GetSymbol(input)) & -16) != 0)
                {
                    if (num3 < 0)
                    {
                        return(false);
                    }
                    if (num3 >= 0x11)
                    {
                        this.lastLen = 0;
                    }
                    else if (this.ptr == 0)
                    {
                        throw new SharpZipBaseException();
                    }
                    this.repSymbol = num3 - 0x10;
                    this.mode      = 5;
                    break;
                }
                mode     = this.ptr;
                this.ptr = mode + 1;
                this.litdistLens[mode] = this.lastLen = (byte)num3;
                if (this.ptr == this.num)
                {
                    return(true);
                }
            }
            goto TR_000E;
TR_0021:
            while (true)
            {
                if (this.ptr >= this.blnum)
                {
                    this.blTree = new InflaterHuffmanTree(this.blLens);
                    this.blLens = null;
                    this.ptr    = 0;
                    this.mode   = 4;
                    break;
                }
                int num2 = input.PeekBits(3);
                if (num2 < 0)
                {
                    return(false);
                }
                input.DropBits(3);
                this.blLens[BL_ORDER[this.ptr]] = (byte)num2;
                this.ptr++;
            }
            goto TR_001A;
TR_0023:
            this.blnum = input.PeekBits(4);
            if (this.blnum < 0)
            {
                return(false);
            }
            this.blnum += 4;
            input.DropBits(4);
            this.blLens = new byte[0x13];
            this.ptr    = 0;
            this.mode   = 3;
            goto TR_0021;
TR_0026:
            this.dnum = input.PeekBits(5);
            if (this.dnum < 0)
            {
                return(false);
            }
            this.dnum++;
            input.DropBits(5);
            this.num         = this.lnum + this.dnum;
            this.litdistLens = new byte[this.num];
            this.mode        = 2;
            goto TR_0023;
        }
Пример #13
0
        internal bool Decode(StreamManipulator input)
        {
decode_loop:
            while (true)
            {
                switch (mode)
                {
                case 0:
                    lnum = input.PeekBits(5);
                    if (lnum < 0)
                    {
                        return(false);
                    }
                    lnum += 257;
                    input.DropBits(5);
                    mode = 1;
                    goto case 1;

                case 1:
                    dnum = input.PeekBits(5);
                    if (dnum < 0)
                    {
                        return(false);
                    }
                    dnum++;
                    input.DropBits(5);
                    num         = lnum + dnum;
                    litdistLens = new byte[num];
                    mode        = 2;
                    goto case 2;

                case 2:
                    blnum = input.PeekBits(4);
                    if (blnum < 0)
                    {
                        return(false);
                    }
                    blnum += 4;
                    input.DropBits(4);
                    blLens = new byte[19];
                    ptr    = 0;
                    mode   = 3;
                    goto case 3;

                case 3:
                    while (ptr < blnum)
                    {
                        int len = input.PeekBits(3);
                        if (len < 0)
                        {
                            return(false);
                        }
                        input.DropBits(3);
                        blLens[BL_ORDER[ptr]] = (byte)len;
                        ptr++;
                    }
                    blTree = new HuffmanTree(blLens);
                    blLens = null;
                    ptr    = 0;
                    mode   = 4;
                    goto case 4;

                case 4:
                    int symbol;
                    while (((symbol = blTree.GetSymbol(input)) & ~15) == 0)
                    {
                        litdistLens[ptr++] = lastLen = (byte)symbol;
                        if (ptr == num)
                        {
                            return(true);
                        }
                    }

                    if (symbol < 0)
                    {
                        return(false);
                    }

                    if (symbol >= 17)
                    {
                        lastLen = 0;
                    }
                    repSymbol = symbol - 16;
                    mode      = 5;
                    goto case 5;

                case 5:
                    int bits  = repBits[repSymbol];
                    int count = input.PeekBits(bits);
                    if (count < 0)
                    {
                        return(false);
                    }
                    input.DropBits(bits);
                    count += repMin[repSymbol];
                    while (count-- > 0)
                    {
                        litdistLens[ptr++] = lastLen;
                    }

                    if (ptr == num)
                    {
                        return(true);
                    }
                    mode = 4;
                    goto decode_loop;
                }
            }
        }
Пример #14
0
		/// <summary>
		/// Decodes a zlib/RFC1950 header - to evaluate input if
		/// decompression is needed or not.
		/// </summary>
		/// <param name="input">The input as an object of type <see cref="StreamManipulator"/></param>
		/// <returns>wheater is input is compressed [true] or its not compressed [false]</returns>
		private static bool DecodeHeader(StreamManipulator input)
		{
			#region Access Log
#if TRACE
			
			{
				Handler.LogHandler.Tracking("Access Method: " + typeof(Compression).FullName + "->" + ((object)MethodBase.GetCurrentMethod()).ToString() + " ;");
			}
#endif
			#endregion Access Log

			int header = input.PeekBits(16);
			if (header < 0)
			{
				return false;
			}
			input.DropBits(16);

			/* header is written in "wrong" byte order */
			header = ((header << 8) | (header >> 8)) & 0xffff;
			if (header % 31 != 0)
			{
				// not compressed
				return false;
			}
			// its compressed
			return true;
		}
Пример #15
0
        public bool Decode(StreamManipulator input)
        {
            int num2;
            int num3;

Label_0000:
            switch (this._mode)
            {
            case 0:
                this._lnum = input.PeekBits(Reps);
                if (this._lnum >= 0)
                {
                    this._lnum += 0x101;
                    input.DropBits(Reps);
                    this._mode = 1;
                    break;
                }
                return(false);

            case 1:
                break;

            case 2:
                goto Label_00B9;

            case 3:
                goto Label_013B;

            case Lens:
                goto Label_01A8;

            case Reps:
                goto Label_01EE;

            default:
                goto Label_0000;
            }
            _dnum = input.PeekBits(Reps);
            if (_dnum < 0)
            {
                return(false);
            }
            _dnum++;
            input.DropBits(Reps);
            this._num    = _lnum + _dnum;
            _litdistLens = new byte[this._num];
            _mode        = 2;
Label_00B9:
            this._blnum = input.PeekBits(4);
            if (this._blnum < 0)
            {
                return(false);
            }
            _blnum += Lens;
            input.DropBits(Lens);
            _blLens    = new byte[0x13];
            this._ptr  = 0;
            this._mode = 3;
Label_013B:
            while (this._ptr < this._blnum)
            {
                int num = input.PeekBits(3);
                if (num < 0)
                {
                    return(false);
                }
                input.DropBits(3);
                this._blLens[BlOrder[this._ptr]] = (byte)num;
                this._ptr++;
            }
            this._blTree = new InflaterHuffmanTree(this._blLens);
            this._blLens = null;
            this._ptr    = 0;
            this._mode   = Lens;
Label_01A8:
            while (((num2 = this._blTree.GetSymbol(input)) & -16) == 0)
            {
                this._litdistLens[this._ptr++] = this._lastLen = (byte)num2;
                if (this._ptr == this._num)
                {
                    return(true);
                }
            }
            if (num2 < 0)
            {
                return(false);
            }
            if (num2 >= 0x11)
            {
                this._lastLen = 0;
            }
            else if (_ptr == 0)
            {
                throw new SharpZipBaseException();
            }
            _repSymbol = num2 - 0x10;
            _mode      = Reps;
Label_01EE:
            num3 = RepBits[_repSymbol];
            int num4 = input.PeekBits(num3);

            if (num4 < 0)
            {
                return(false);
            }
            input.DropBits(num3);
            num4 += RepMin[_repSymbol];
            if ((_ptr + num4) > this._num)
            {
                throw new SharpZipBaseException();
            }
            while (num4-- > 0)
            {
                _litdistLens[_ptr++] = _lastLen;
            }
            if (this._ptr == this._num)
            {
                return(true);
            }
            this._mode = Lens;
            goto Label_0000;
        }
Пример #16
0
        /// <summary>
        /// Decodes the deflated stream.
        /// </summary>
        /// <returns>
        /// false if more input is needed, or if finished.
        /// </returns>
        /// <exception cref="SharpZipBaseException">
        /// if deflated stream is invalid.
        /// </exception>
        private bool Decode()
        {
            switch (mode)
            {
            case DECODE_HEADER:
                return(DecodeHeader());

            case DECODE_DICT:
                return(DecodeDict());

            case DECODE_CHKSUM:
                return(DecodeChksum());

            case DECODE_BLOCKS:
                if (isLastBlock)
                {
                    if (noHeader)
                    {
                        mode = FINISHED;
                        return(false);
                    }
                    else
                    {
                        input.SkipToByteBoundary();
                        neededBits = 32;
                        mode       = DECODE_CHKSUM;
                        return(true);
                    }
                }

                int type = input.PeekBits(3);
                if (type < 0)
                {
                    return(false);
                }
                input.DropBits(3);

                if ((type & 1) != 0)
                {
                    isLastBlock = true;
                }
                switch (type >> 1)
                {
                case DeflaterConstants.STORED_BLOCK:
                    input.SkipToByteBoundary();
                    mode = DECODE_STORED_LEN1;
                    break;

                case DeflaterConstants.STATIC_TREES:
                    litlenTree = InflaterHuffmanTree.defLitLenTree;
                    distTree   = InflaterHuffmanTree.defDistTree;
                    mode       = DECODE_HUFFMAN;
                    break;

                case DeflaterConstants.DYN_TREES:
                    dynHeader = new InflaterDynHeader();
                    mode      = DECODE_DYN_HEADER;
                    break;

                default:
                    throw new SharpZipBaseException("Unknown block type " + type);
                }
                return(true);

            case DECODE_STORED_LEN1:
            {
                if ((uncomprLen = input.PeekBits(16)) < 0)
                {
                    return(false);
                }
                input.DropBits(16);
                mode = DECODE_STORED_LEN2;
            }
                goto case DECODE_STORED_LEN2;     // fall through

            case DECODE_STORED_LEN2:
            {
                int nlen = input.PeekBits(16);
                if (nlen < 0)
                {
                    return(false);
                }
                input.DropBits(16);
                if (nlen != (uncomprLen ^ 0xffff))
                {
                    throw new SharpZipBaseException("broken uncompressed block");
                }
                mode = DECODE_STORED;
            }
                goto case DECODE_STORED;     // fall through

            case DECODE_STORED:
            {
                int more = outputWindow.CopyStored(input, uncomprLen);
                uncomprLen -= more;
                if (uncomprLen == 0)
                {
                    mode = DECODE_BLOCKS;
                    return(true);
                }
                return(!input.IsNeedingInput);
            }

            case DECODE_DYN_HEADER:
                if (!dynHeader.Decode(input))
                {
                    return(false);
                }

                litlenTree = dynHeader.BuildLitLenTree();
                distTree   = dynHeader.BuildDistTree();
                mode       = DECODE_HUFFMAN;
                goto case DECODE_HUFFMAN;     // fall through

            case DECODE_HUFFMAN:
            case DECODE_HUFFMAN_LENBITS:
            case DECODE_HUFFMAN_DIST:
            case DECODE_HUFFMAN_DISTBITS:
                return(DecodeHuffman());

            case FINISHED:
                return(false);

            default:
                throw new SharpZipBaseException("Inflater.Decode unknown mode");
            }
        }
Пример #17
0
        public bool Decode(StreamManipulator input)
        {
            decode_loop:
                for (;;) {
                    switch (mode) {
                        case LNUM:
                            lnum = input.PeekBits(5);
                            if (lnum < 0) {
                                return false;
                            }
                            lnum += 257;
                            input.DropBits(5);
                            //  	    System.err.println("LNUM: "+lnum);
                            mode = DNUM;
                            goto case DNUM; // fall through
                        case DNUM:
                            dnum = input.PeekBits(5);
                            if (dnum < 0) {
                                return false;
                            }
                            dnum++;
                            input.DropBits(5);
                            //  	    System.err.println("DNUM: "+dnum);
                            num = lnum+dnum;
                            litdistLens = new byte[num];
                            mode = BLNUM;
                            goto case BLNUM; // fall through
                        case BLNUM:
                            blnum = input.PeekBits(4);
                            if (blnum < 0) {
                                return false;
                            }
                            blnum += 4;
                            input.DropBits(4);
                            blLens = new byte[19];
                            ptr = 0;
                            //  	    System.err.println("BLNUM: "+blnum);
                            mode = BLLENS;
                            goto case BLLENS; // fall through
                        case BLLENS:
                            while (ptr < blnum) {
                                int len = input.PeekBits(3);
                                if (len < 0) {
                                    return false;
                                }
                                input.DropBits(3);
                                //  		System.err.println("blLens["+BL_ORDER[ptr]+"]: "+len);
                                blLens[BL_ORDER[ptr]] = (byte) len;
                                ptr++;
                            }
                            blTree = new InflaterHuffmanTree(blLens);
                            blLens = null;
                            ptr = 0;
                            mode = LENS;
                            goto case LENS; // fall through
                        case LENS:
                        {
                            int symbol;
                            while (((symbol = blTree.GetSymbol(input)) & ~15) == 0) {
                                /* Normal case: symbol in [0..15] */

                                //  		  System.err.println("litdistLens["+ptr+"]: "+symbol);
                                litdistLens[ptr++] = lastLen = (byte)symbol;

                                if (ptr == num) {
                                    /* Finished */
                                    return true;
                                }
                            }

                            /* need more input ? */
                            if (symbol < 0) {
                                return false;
                            }

                            /* otherwise repeat code */
                            if (symbol >= 17) {
                                /* repeat zero */
                                //  		  System.err.println("repeating zero");
                                lastLen = 0;
                            } else {
                                if (ptr == 0) {
                                    throw new SharpZipBaseException();
                                }
                            }
                            repSymbol = symbol-16;
                        }
                            mode = REPS;
                            goto case REPS; // fall through
                        case REPS:
                        {
                            int bits = repBits[repSymbol];
                            int count = input.PeekBits(bits);
                            if (count < 0) {
                                return false;
                            }
                            input.DropBits(bits);
                            count += repMin[repSymbol];
                            //  	      System.err.println("litdistLens repeated: "+count);

                            if (ptr + count > num) {
                                throw new SharpZipBaseException();
                            }
                            while (count-- > 0) {
                                litdistLens[ptr++] = lastLen;
                            }

                            if (ptr == num) {
                                /* Finished */
                                return true;
                            }
                        }
                            mode = LENS;
                            goto decode_loop;
                    }
                }
        }
Пример #18
0
        public bool Decode(StreamManipulator input)
        {
decode_loop:
            for (;;)
            {
                switch (mode)
                {
                case LNUM:
                    lnum = input.PeekBits(5);
                    if (lnum < 0)
                    {
                        return(false);
                    }
                    lnum += 257;
                    input.DropBits(5);
                    //          System.err.println("LNUM: "+lnum);
                    mode = DNUM;
                    goto case DNUM;     // fall through

                case DNUM:
                    dnum = input.PeekBits(5);
                    if (dnum < 0)
                    {
                        return(false);
                    }
                    dnum++;
                    input.DropBits(5);
                    //          System.err.println("DNUM: "+dnum);
                    num         = lnum + dnum;
                    litdistLens = new byte[num];
                    mode        = BLNUM;
                    goto case BLNUM;     // fall through

                case BLNUM:
                    blnum = input.PeekBits(4);
                    if (blnum < 0)
                    {
                        return(false);
                    }
                    blnum += 4;
                    input.DropBits(4);
                    blLens = new byte[19];
                    ptr    = 0;
                    //          System.err.println("BLNUM: "+blnum);
                    mode = BLLENS;
                    goto case BLLENS;     // fall through

                case BLLENS:
                    while (ptr < blnum)
                    {
                        int len = input.PeekBits(3);
                        if (len < 0)
                        {
                            return(false);
                        }
                        input.DropBits(3);
                        //          System.err.println("blLens["+BL_ORDER[ptr]+"]: "+len);
                        blLens[BL_ORDER[ptr]] = (byte)len;
                        ptr++;
                    }
                    blTree = new InflaterHuffmanTree(blLens);
                    blLens = null;
                    ptr    = 0;
                    mode   = LENS;
                    goto case LENS;     // fall through

                case LENS:
                {
                    int symbol;
                    while (((symbol = blTree.GetSymbol(input)) & ~15) == 0)
                    {
                        /* Normal case: symbol in [0..15] */

                        //            System.err.println("litdistLens["+ptr+"]: "+symbol);
                        litdistLens[ptr++] = lastLen = (byte)symbol;

                        if (ptr == num)
                        {
                            /* Finished */
                            return(true);
                        }
                    }

                    /* need more input ? */
                    if (symbol < 0)
                    {
                        return(false);
                    }

                    /* otherwise repeat code */
                    if (symbol >= 17)
                    {
                        /* repeat zero */
                        //            System.err.println("repeating zero");
                        lastLen = 0;
                    }
                    else
                    {
                        if (ptr == 0)
                        {
                            throw new SharpZipBaseException();
                        }
                    }
                    repSymbol = symbol - 16;
                }
                    mode = REPS;
                    goto case REPS;     // fall through

                case REPS:
                {
                    int bits  = repBits[repSymbol];
                    int count = input.PeekBits(bits);
                    if (count < 0)
                    {
                        return(false);
                    }
                    input.DropBits(bits);
                    count += repMin[repSymbol];
                    //            System.err.println("litdistLens repeated: "+count);

                    if (ptr + count > num)
                    {
                        throw new SharpZipBaseException();
                    }
                    while (count-- > 0)
                    {
                        litdistLens[ptr++] = lastLen;
                    }

                    if (ptr == num)
                    {
                        /* Finished */
                        return(true);
                    }
                }
                    mode = LENS;
                    goto decode_loop;
                }
            }
        }
Пример #19
0
        public bool Decode(StreamManipulator input)
        {
            int  num2;
            int  num3;
            bool flag2;

            goto Label_034E;
Label_007E:
            this.dnum = input.PeekBits(5);
            if (this.dnum < 0)
            {
                return(false);
            }
            this.dnum++;
            input.DropBits(5);
            this.num         = this.lnum + this.dnum;
            this.litdistLens = new byte[this.num];
            this.mode        = 2;
Label_00E9:
            this.blnum = input.PeekBits(4);
            if (this.blnum < 0)
            {
                return(false);
            }
            this.blnum += 4;
            input.DropBits(4);
            this.blLens = new byte[0x13];
            this.ptr    = 0;
            this.mode   = 3;
Label_0191:
            while (this.ptr < this.blnum)
            {
                int num = input.PeekBits(3);
                if (num < 0)
                {
                    return(false);
                }
                input.DropBits(3);
                this.blLens[BL_ORDER[this.ptr]] = (byte)num;
                this.ptr++;
            }
            this.blTree = new InflaterHuffmanTree(this.blLens);
            this.blLens = null;
            this.ptr    = 0;
            this.mode   = 4;
Label_0219:
            while (((num2 = this.blTree.GetSymbol(input)) & -16) == 0)
            {
                this.litdistLens[this.ptr++] = this.lastLen = (byte)num2;
                if (this.ptr == this.num)
                {
                    return(true);
                }
            }
            if (num2 < 0)
            {
                return(false);
            }
            if (num2 >= 0x11)
            {
                this.lastLen = 0;
            }
            else if (this.ptr == 0)
            {
                throw new SharpZipBaseException();
            }
            this.repSymbol = num2 - 0x10;
            this.mode      = 5;
Label_028E:
            num3 = repBits[this.repSymbol];
            int num4 = input.PeekBits(num3);

            if (num4 < 0)
            {
                return(false);
            }
            input.DropBits(num3);
            num4 += repMin[this.repSymbol];
            if ((this.ptr + num4) > this.num)
            {
                throw new SharpZipBaseException();
            }
            while (num4-- > 0)
            {
                this.litdistLens[this.ptr++] = this.lastLen;
            }
            if (this.ptr == this.num)
            {
                return(true);
            }
            this.mode = 4;
Label_034E:
            flag2 = true;
            switch (this.mode)
            {
            case 0:
                this.lnum = input.PeekBits(5);
                if (this.lnum >= 0)
                {
                    this.lnum += 0x101;
                    input.DropBits(5);
                    this.mode = 1;
                    goto Label_007E;
                }
                return(false);

            case 1:
                goto Label_007E;

            case 2:
                goto Label_00E9;

            case 3:
                goto Label_0191;

            case 4:
                goto Label_0219;

            case 5:
                goto Label_028E;
            }
            goto Label_034E;
        }