Beispiel #1
0
 internal int End()
 {
     if (this.blocks != null)
     {
         this.blocks.Free();
     }
     this.blocks = null;
     return(0);
 }
Beispiel #2
0
 internal int Initialize(ZlibCodec codec, int w)
 {
     this._codec         = codec;
     this._codec.Message = null;
     this.blocks         = null;
     if (w < 8 || w > 15)
     {
         this.End();
         throw new ZlibException("Bad window size.");
     }
     this.wbits  = w;
     this.blocks = new InflateBlocks(codec, (!this.HandleRfc1950HeaderBytes) ? null : this, 1 << w);
     this.Reset();
     return(0);
 }
Beispiel #3
0
        internal int InflateFast(int bl, int bd, int[] tl, int tl_index, int[] td, int td_index, InflateBlocks s, ZlibCodec z)
        {
            int num12;
            int nextIn           = z.NextIn;
            int availableBytesIn = z.AvailableBytesIn;
            int bitb             = s.bitb;
            int bitk             = s.bitk;
            int writeAt          = s.writeAt;
            int num9             = (writeAt >= s.readAt) ? (s.end - writeAt) : ((s.readAt - writeAt) - 1);
            int num10            = InternalInflateConstants.InflateMask[bl];
            int num11            = InternalInflateConstants.InflateMask[bd];

Label_009B:
            while (bitk < 20)
            {
                availableBytesIn--;
                bitb |= (z.InputBuffer[nextIn++] & 0xff) << bitk;
                bitk += 8;
            }
            int num = bitb & num10;

            int[] numArray = tl;
            int   num2     = tl_index;
            int   index    = (num2 + num) * 3;
            int   num3     = numArray[index];

            if (num3 == 0)
            {
                bitb  = bitb >> numArray[index + 1];
                bitk -= numArray[index + 1];
                s.window[writeAt++] = (byte)numArray[index + 2];
                num9--;
                goto Label_062B;
            }
Label_00FB:
            bitb  = bitb >> numArray[index + 1];
            bitk -= numArray[index + 1];
            if ((num3 & 0x10) == 0)
            {
                if ((num3 & 0x40) == 0)
                {
                    num  += numArray[index + 2];
                    num  += bitb & InternalInflateConstants.InflateMask[num3];
                    index = (num2 + num) * 3;
                    num3  = numArray[index];
                    if (num3 != 0)
                    {
                        goto Label_00FB;
                    }
                    bitb  = bitb >> numArray[index + 1];
                    bitk -= numArray[index + 1];
                    s.window[writeAt++] = (byte)numArray[index + 2];
                    num9--;
                }
                else
                {
                    if ((num3 & 0x20) != 0)
                    {
                        num12              = z.AvailableBytesIn - availableBytesIn;
                        num12              = ((bitk >> 3) >= num12) ? num12 : (bitk >> 3);
                        availableBytesIn  += num12;
                        nextIn            -= num12;
                        bitk              -= num12 << 3;
                        s.bitb             = bitb;
                        s.bitk             = bitk;
                        z.AvailableBytesIn = availableBytesIn;
                        z.TotalBytesIn    += nextIn - z.NextIn;
                        z.NextIn           = nextIn;
                        s.writeAt          = writeAt;
                        return(1);
                    }
                    z.Message          = "invalid literal/length code";
                    num12              = z.AvailableBytesIn - availableBytesIn;
                    num12              = ((bitk >> 3) >= num12) ? num12 : (bitk >> 3);
                    availableBytesIn  += num12;
                    nextIn            -= num12;
                    bitk              -= num12 << 3;
                    s.bitb             = bitb;
                    s.bitk             = bitk;
                    z.AvailableBytesIn = availableBytesIn;
                    z.TotalBytesIn    += nextIn - z.NextIn;
                    z.NextIn           = nextIn;
                    s.writeAt          = writeAt;
                    return(-3);
                }
                goto Label_062B;
            }
            num3 &= 15;
            num12 = numArray[index + 2] + (bitb & InternalInflateConstants.InflateMask[num3]);
            bitb  = bitb >> num3;
            bitk -= num3;
            while (bitk < 15)
            {
                availableBytesIn--;
                bitb |= (z.InputBuffer[nextIn++] & 0xff) << bitk;
                bitk += 8;
            }
            num      = bitb & num11;
            numArray = td;
            num2     = td_index;
            index    = (num2 + num) * 3;
            num3     = numArray[index];
Label_0196:
            bitb  = bitb >> numArray[index + 1];
            bitk -= numArray[index + 1];
            if ((num3 & 0x10) != 0)
            {
                int num14;
                num3 &= 15;
                while (bitk < num3)
                {
                    availableBytesIn--;
                    bitb |= (z.InputBuffer[nextIn++] & 0xff) << bitk;
                    bitk += 8;
                }
                int num13 = numArray[index + 2] + (bitb & InternalInflateConstants.InflateMask[num3]);
                bitb  = bitb >> num3;
                bitk -= num3;
                num9 -= num12;
                if (writeAt >= num13)
                {
                    num14 = writeAt - num13;
                    if (((writeAt - num14) > 0) && (2 > (writeAt - num14)))
                    {
                        s.window[writeAt++] = s.window[num14++];
                        s.window[writeAt++] = s.window[num14++];
                        num12 -= 2;
                    }
                    else
                    {
                        Array.Copy(s.window, num14, s.window, writeAt, 2);
                        writeAt += 2;
                        num14   += 2;
                        num12   -= 2;
                    }
                }
                else
                {
                    num14 = writeAt - num13;
                    do
                    {
                        num14 += s.end;
                    }while (num14 < 0);
                    num3 = s.end - num14;
                    if (num12 > num3)
                    {
                        num12 -= num3;
                        if (((writeAt - num14) > 0) && (num3 > (writeAt - num14)))
                        {
                            do
                            {
                                s.window[writeAt++] = s.window[num14++];
                            }while (--num3 != 0);
                        }
                        else
                        {
                            Array.Copy(s.window, num14, s.window, writeAt, num3);
                            writeAt += num3;
                            num14   += num3;
                            num3     = 0;
                        }
                        num14 = 0;
                    }
                }
                if (((writeAt - num14) > 0) && (num12 > (writeAt - num14)))
                {
                    do
                    {
                        s.window[writeAt++] = s.window[num14++];
                    }while (--num12 != 0);
                }
                else
                {
                    Array.Copy(s.window, num14, s.window, writeAt, num12);
                    writeAt += num12;
                    num14   += num12;
                    num12    = 0;
                }
            }
            else
            {
                if ((num3 & 0x40) == 0)
                {
                    num  += numArray[index + 2];
                    num  += bitb & InternalInflateConstants.InflateMask[num3];
                    index = (num2 + num) * 3;
                    num3  = numArray[index];
                    goto Label_0196;
                }
                z.Message          = "invalid distance code";
                num12              = z.AvailableBytesIn - availableBytesIn;
                num12              = ((bitk >> 3) >= num12) ? num12 : (bitk >> 3);
                availableBytesIn  += num12;
                nextIn            -= num12;
                bitk              -= num12 << 3;
                s.bitb             = bitb;
                s.bitk             = bitk;
                z.AvailableBytesIn = availableBytesIn;
                z.TotalBytesIn    += nextIn - z.NextIn;
                z.NextIn           = nextIn;
                s.writeAt          = writeAt;
                return(-3);
            }
Label_062B:
            if ((num9 >= 0x102) && (availableBytesIn >= 10))
            {
                goto Label_009B;
            }
            num12              = z.AvailableBytesIn - availableBytesIn;
            num12              = ((bitk >> 3) >= num12) ? num12 : (bitk >> 3);
            availableBytesIn  += num12;
            nextIn            -= num12;
            bitk              -= num12 << 3;
            s.bitb             = bitb;
            s.bitk             = bitk;
            z.AvailableBytesIn = availableBytesIn;
            z.TotalBytesIn    += nextIn - z.NextIn;
            z.NextIn           = nextIn;
            s.writeAt          = writeAt;
            return(0);
        }
Beispiel #4
0
        internal int Process(InflateBlocks blocks, int r)
        {
            int       bitsToGet;
            int       num10;
            int       bitb   = 0;
            int       bitk   = 0;
            int       nextIn = 0;
            ZlibCodec z      = blocks._codec;

            nextIn = z.NextIn;
            int availableBytesIn = z.AvailableBytesIn;

            bitb = blocks.bitb;
            bitk = blocks.bitk;
            int writeAt = blocks.writeAt;
            int num9    = (writeAt >= blocks.readAt) ? (blocks.end - writeAt) : ((blocks.readAt - writeAt) - 1);

Label_0061:
            switch (this.mode)
            {
            case 0:
                if ((num9 < 0x102) || (availableBytesIn < 10))
                {
                    break;
                }
                blocks.bitb        = bitb;
                blocks.bitk        = bitk;
                z.AvailableBytesIn = availableBytesIn;
                z.TotalBytesIn    += nextIn - z.NextIn;
                z.NextIn           = nextIn;
                blocks.writeAt     = writeAt;
                r                = this.InflateFast(this.lbits, this.dbits, this.ltree, this.ltree_index, this.dtree, this.dtree_index, blocks, z);
                nextIn           = z.NextIn;
                availableBytesIn = z.AvailableBytesIn;
                bitb             = blocks.bitb;
                bitk             = blocks.bitk;
                writeAt          = blocks.writeAt;
                num9             = (writeAt >= blocks.readAt) ? (blocks.end - writeAt) : ((blocks.readAt - writeAt) - 1);
                if (r == 0)
                {
                    break;
                }
                this.mode = (r != 1) ? 9 : 7;
                goto Label_0061;

            case 1:
                goto Label_01C4;

            case 2:
                bitsToGet = this.bitsToGet;
                while (bitk < bitsToGet)
                {
                    if (availableBytesIn != 0)
                    {
                        r = 0;
                    }
                    else
                    {
                        blocks.bitb        = bitb;
                        blocks.bitk        = bitk;
                        z.AvailableBytesIn = availableBytesIn;
                        z.TotalBytesIn    += nextIn - z.NextIn;
                        z.NextIn           = nextIn;
                        blocks.writeAt     = writeAt;
                        return(blocks.Flush(r));
                    }
                    availableBytesIn--;
                    bitb |= (z.InputBuffer[nextIn++] & 0xff) << bitk;
                    bitk += 8;
                }
                this.len       += bitb & InternalInflateConstants.InflateMask[bitsToGet];
                bitb            = bitb >> bitsToGet;
                bitk           -= bitsToGet;
                this.need       = this.dbits;
                this.tree       = this.dtree;
                this.tree_index = this.dtree_index;
                this.mode       = 3;
                goto Label_0471;

            case 3:
                goto Label_0471;

            case 4:
                bitsToGet = this.bitsToGet;
                while (bitk < bitsToGet)
                {
                    if (availableBytesIn != 0)
                    {
                        r = 0;
                    }
                    else
                    {
                        blocks.bitb        = bitb;
                        blocks.bitk        = bitk;
                        z.AvailableBytesIn = availableBytesIn;
                        z.TotalBytesIn    += nextIn - z.NextIn;
                        z.NextIn           = nextIn;
                        blocks.writeAt     = writeAt;
                        return(blocks.Flush(r));
                    }
                    availableBytesIn--;
                    bitb |= (z.InputBuffer[nextIn++] & 0xff) << bitk;
                    bitk += 8;
                }
                this.dist += bitb & InternalInflateConstants.InflateMask[bitsToGet];
                bitb       = bitb >> bitsToGet;
                bitk      -= bitsToGet;
                this.mode  = 5;
                goto Label_06C3;

            case 5:
                goto Label_06C3;

            case 6:
                if (num9 == 0)
                {
                    if ((writeAt == blocks.end) && (blocks.readAt != 0))
                    {
                        writeAt = 0;
                        num9    = (writeAt >= blocks.readAt) ? (blocks.end - writeAt) : ((blocks.readAt - writeAt) - 1);
                    }
                    if (num9 == 0)
                    {
                        blocks.writeAt = writeAt;
                        r       = blocks.Flush(r);
                        writeAt = blocks.writeAt;
                        num9    = (writeAt >= blocks.readAt) ? (blocks.end - writeAt) : ((blocks.readAt - writeAt) - 1);
                        if ((writeAt == blocks.end) && (blocks.readAt != 0))
                        {
                            writeAt = 0;
                            num9    = (writeAt >= blocks.readAt) ? (blocks.end - writeAt) : ((blocks.readAt - writeAt) - 1);
                        }
                        if (num9 == 0)
                        {
                            blocks.bitb        = bitb;
                            blocks.bitk        = bitk;
                            z.AvailableBytesIn = availableBytesIn;
                            z.TotalBytesIn    += nextIn - z.NextIn;
                            z.NextIn           = nextIn;
                            blocks.writeAt     = writeAt;
                            return(blocks.Flush(r));
                        }
                    }
                }
                r = 0;
                blocks.window[writeAt++] = (byte)this.lit;
                num9--;
                this.mode = 0;
                goto Label_0061;

            case 7:
                if (bitk > 7)
                {
                    bitk -= 8;
                    availableBytesIn++;
                    nextIn--;
                }
                blocks.writeAt = writeAt;
                r       = blocks.Flush(r);
                writeAt = blocks.writeAt;
                num9    = (writeAt >= blocks.readAt) ? (blocks.end - writeAt) : ((blocks.readAt - writeAt) - 1);
                if (blocks.readAt != blocks.writeAt)
                {
                    blocks.bitb        = bitb;
                    blocks.bitk        = bitk;
                    z.AvailableBytesIn = availableBytesIn;
                    z.TotalBytesIn    += nextIn - z.NextIn;
                    z.NextIn           = nextIn;
                    blocks.writeAt     = writeAt;
                    return(blocks.Flush(r));
                }
                this.mode = 8;
                goto Label_0A7A;

            case 8:
                goto Label_0A7A;

            case 9:
                r                  = -3;
                blocks.bitb        = bitb;
                blocks.bitk        = bitk;
                z.AvailableBytesIn = availableBytesIn;
                z.TotalBytesIn    += nextIn - z.NextIn;
                z.NextIn           = nextIn;
                blocks.writeAt     = writeAt;
                return(blocks.Flush(r));

            default:
                r                  = -2;
                blocks.bitb        = bitb;
                blocks.bitk        = bitk;
                z.AvailableBytesIn = availableBytesIn;
                z.TotalBytesIn    += nextIn - z.NextIn;
                z.NextIn           = nextIn;
                blocks.writeAt     = writeAt;
                return(blocks.Flush(r));
            }
            this.need       = this.lbits;
            this.tree       = this.ltree;
            this.tree_index = this.ltree_index;
            this.mode       = 1;
Label_01C4:
            bitsToGet = this.need;
            while (bitk < bitsToGet)
            {
                if (availableBytesIn != 0)
                {
                    r = 0;
                }
                else
                {
                    blocks.bitb        = bitb;
                    blocks.bitk        = bitk;
                    z.AvailableBytesIn = availableBytesIn;
                    z.TotalBytesIn    += nextIn - z.NextIn;
                    z.NextIn           = nextIn;
                    blocks.writeAt     = writeAt;
                    return(blocks.Flush(r));
                }
                availableBytesIn--;
                bitb |= (z.InputBuffer[nextIn++] & 0xff) << bitk;
                bitk += 8;
            }
            int index = (this.tree_index + (bitb & InternalInflateConstants.InflateMask[bitsToGet])) * 3;

            bitb  = bitb >> this.tree[index + 1];
            bitk -= this.tree[index + 1];
            int num3 = this.tree[index];

            if (num3 == 0)
            {
                this.lit  = this.tree[index + 2];
                this.mode = 6;
                goto Label_0061;
            }
            if ((num3 & 0x10) != 0)
            {
                this.bitsToGet = num3 & 15;
                this.len       = this.tree[index + 2];
                this.mode      = 2;
                goto Label_0061;
            }
            if ((num3 & 0x40) == 0)
            {
                this.need       = num3;
                this.tree_index = (index / 3) + this.tree[index + 2];
                goto Label_0061;
            }
            if ((num3 & 0x20) != 0)
            {
                this.mode = 7;
                goto Label_0061;
            }
            this.mode          = 9;
            z.Message          = "invalid literal/length code";
            r                  = -3;
            blocks.bitb        = bitb;
            blocks.bitk        = bitk;
            z.AvailableBytesIn = availableBytesIn;
            z.TotalBytesIn    += nextIn - z.NextIn;
            z.NextIn           = nextIn;
            blocks.writeAt     = writeAt;
            return(blocks.Flush(r));

Label_0471:
            bitsToGet = this.need;
            while (bitk < bitsToGet)
            {
                if (availableBytesIn != 0)
                {
                    r = 0;
                }
                else
                {
                    blocks.bitb        = bitb;
                    blocks.bitk        = bitk;
                    z.AvailableBytesIn = availableBytesIn;
                    z.TotalBytesIn    += nextIn - z.NextIn;
                    z.NextIn           = nextIn;
                    blocks.writeAt     = writeAt;
                    return(blocks.Flush(r));
                }
                availableBytesIn--;
                bitb |= (z.InputBuffer[nextIn++] & 0xff) << bitk;
                bitk += 8;
            }
            index = (this.tree_index + (bitb & InternalInflateConstants.InflateMask[bitsToGet])) * 3;
            bitb  = bitb >> this.tree[index + 1];
            bitk -= this.tree[index + 1];
            num3  = this.tree[index];
            if ((num3 & 0x10) != 0)
            {
                this.bitsToGet = num3 & 15;
                this.dist      = this.tree[index + 2];
                this.mode      = 4;
                goto Label_0061;
            }
            if ((num3 & 0x40) == 0)
            {
                this.need       = num3;
                this.tree_index = (index / 3) + this.tree[index + 2];
                goto Label_0061;
            }
            this.mode          = 9;
            z.Message          = "invalid distance code";
            r                  = -3;
            blocks.bitb        = bitb;
            blocks.bitk        = bitk;
            z.AvailableBytesIn = availableBytesIn;
            z.TotalBytesIn    += nextIn - z.NextIn;
            z.NextIn           = nextIn;
            blocks.writeAt     = writeAt;
            return(blocks.Flush(r));

Label_06C3:
            num10 = writeAt - this.dist;
            while (num10 < 0)
            {
                num10 += blocks.end;
            }
            while (this.len != 0)
            {
                if (num9 == 0)
                {
                    if ((writeAt == blocks.end) && (blocks.readAt != 0))
                    {
                        writeAt = 0;
                        num9    = (writeAt >= blocks.readAt) ? (blocks.end - writeAt) : ((blocks.readAt - writeAt) - 1);
                    }
                    if (num9 == 0)
                    {
                        blocks.writeAt = writeAt;
                        r       = blocks.Flush(r);
                        writeAt = blocks.writeAt;
                        num9    = (writeAt >= blocks.readAt) ? (blocks.end - writeAt) : ((blocks.readAt - writeAt) - 1);
                        if ((writeAt == blocks.end) && (blocks.readAt != 0))
                        {
                            writeAt = 0;
                            num9    = (writeAt >= blocks.readAt) ? (blocks.end - writeAt) : ((blocks.readAt - writeAt) - 1);
                        }
                        if (num9 == 0)
                        {
                            blocks.bitb        = bitb;
                            blocks.bitk        = bitk;
                            z.AvailableBytesIn = availableBytesIn;
                            z.TotalBytesIn    += nextIn - z.NextIn;
                            z.NextIn           = nextIn;
                            blocks.writeAt     = writeAt;
                            return(blocks.Flush(r));
                        }
                    }
                }
                blocks.window[writeAt++] = blocks.window[num10++];
                num9--;
                if (num10 == blocks.end)
                {
                    num10 = 0;
                }
                this.len--;
            }
            this.mode = 0;
            goto Label_0061;
Label_0A7A:
            r                  = 1;
            blocks.bitb        = bitb;
            blocks.bitk        = bitk;
            z.AvailableBytesIn = availableBytesIn;
            z.TotalBytesIn    += nextIn - z.NextIn;
            z.NextIn           = nextIn;
            blocks.writeAt     = writeAt;
            return(blocks.Flush(r));
        }
        internal int Process(InflateBlocks blocks, int r)
        {
            ZlibCodec codec = blocks._codec;
            int       num   = codec.NextIn;
            int       num2  = codec.AvailableBytesIn;
            int       num3  = blocks.bitb;
            int       i     = blocks.bitk;
            int       num4  = blocks.writeAt;
            int       num5  = (num4 >= blocks.readAt) ? (blocks.end - num4) : (blocks.readAt - num4 - 1);

            while (true)
            {
                int num6;
                switch (this.mode)
                {
                case 0:
                    if (num5 >= 258 && num2 >= 10)
                    {
                        blocks.bitb            = num3;
                        blocks.bitk            = i;
                        codec.AvailableBytesIn = num2;
                        codec.TotalBytesIn    += (long)(num - codec.NextIn);
                        codec.NextIn           = num;
                        blocks.writeAt         = num4;
                        r    = this.InflateFast((int)this.lbits, (int)this.dbits, this.ltree, this.ltree_index, this.dtree, this.dtree_index, blocks, codec);
                        num  = codec.NextIn;
                        num2 = codec.AvailableBytesIn;
                        num3 = blocks.bitb;
                        i    = blocks.bitk;
                        num4 = blocks.writeAt;
                        num5 = ((num4 >= blocks.readAt) ? (blocks.end - num4) : (blocks.readAt - num4 - 1));
                        if (r != 0)
                        {
                            this.mode = ((r != 1) ? 9 : 7);
                            continue;
                        }
                    }
                    this.need       = (int)this.lbits;
                    this.tree       = this.ltree;
                    this.tree_index = this.ltree_index;
                    this.mode       = 1;
                    goto IL_1C4;

                case 1:
                    goto IL_1C4;

                case 2:
                    num6 = this.bitsToGet;
                    while (i < num6)
                    {
                        if (num2 == 0)
                        {
                            goto IL_3A5;
                        }
                        r = 0;
                        num2--;
                        num3 |= (int)(codec.InputBuffer[num++] & 255) << i;
                        i    += 8;
                    }
                    this.len       += (num3 & InternalInflateConstants.InflateMask[num6]);
                    num3          >>= num6;
                    i              -= num6;
                    this.need       = (int)this.dbits;
                    this.tree       = this.dtree;
                    this.tree_index = this.dtree_index;
                    this.mode       = 3;
                    goto IL_477;

                case 3:
                    goto IL_477;

                case 4:
                    num6 = this.bitsToGet;
                    while (i < num6)
                    {
                        if (num2 == 0)
                        {
                            goto IL_621;
                        }
                        r = 0;
                        num2--;
                        num3 |= (int)(codec.InputBuffer[num++] & 255) << i;
                        i    += 8;
                    }
                    this.dist += (num3 & InternalInflateConstants.InflateMask[num6]);
                    num3     >>= num6;
                    i         -= num6;
                    this.mode  = 5;
                    goto IL_6CF;

                case 5:
                    goto IL_6CF;

                case 6:
                    if (num5 == 0)
                    {
                        if (num4 == blocks.end && blocks.readAt != 0)
                        {
                            num4 = 0;
                            num5 = ((num4 >= blocks.readAt) ? (blocks.end - num4) : (blocks.readAt - num4 - 1));
                        }
                        if (num5 == 0)
                        {
                            blocks.writeAt = num4;
                            r    = blocks.Flush(r);
                            num4 = blocks.writeAt;
                            num5 = ((num4 >= blocks.readAt) ? (blocks.end - num4) : (blocks.readAt - num4 - 1));
                            if (num4 == blocks.end && blocks.readAt != 0)
                            {
                                num4 = 0;
                                num5 = ((num4 >= blocks.readAt) ? (blocks.end - num4) : (blocks.readAt - num4 - 1));
                            }
                            if (num5 == 0)
                            {
                                goto Block_44;
                            }
                        }
                    }
                    r = 0;
                    blocks.window[num4++] = (byte)this.lit;
                    num5--;
                    this.mode = 0;
                    continue;

                case 7:
                    goto IL_9C4;

                case 8:
                    goto IL_A86;

                case 9:
                    goto IL_AD3;
                }
                break;
                continue;
IL_1C4:
                num6 = this.need;
                while (i < num6)
                {
                    if (num2 == 0)
                    {
                        goto IL_1DF;
                    }
                    r = 0;
                    num2--;
                    num3 |= (int)(codec.InputBuffer[num++] & 255) << i;
                    i    += 8;
                }
                int num7 = (this.tree_index + (num3 & InternalInflateConstants.InflateMask[num6])) * 3;
                num3 >>= this.tree[num7 + 1];
                i     -= this.tree[num7 + 1];
                int num8 = this.tree[num7];
                if (num8 == 0)
                {
                    this.lit  = this.tree[num7 + 2];
                    this.mode = 6;
                    continue;
                }
                if ((num8 & 16) != 0)
                {
                    this.bitsToGet = (num8 & 15);
                    this.len       = this.tree[num7 + 2];
                    this.mode      = 2;
                    continue;
                }
                if ((num8 & 64) == 0)
                {
                    this.need       = num8;
                    this.tree_index = num7 / 3 + this.tree[num7 + 2];
                    continue;
                }
                if ((num8 & 32) != 0)
                {
                    this.mode = 7;
                    continue;
                }
                goto IL_328;
IL_477:
                num6 = this.need;
                while (i < num6)
                {
                    if (num2 == 0)
                    {
                        goto IL_492;
                    }
                    r = 0;
                    num2--;
                    num3 |= (int)(codec.InputBuffer[num++] & 255) << i;
                    i    += 8;
                }
                num7   = (this.tree_index + (num3 & InternalInflateConstants.InflateMask[num6])) * 3;
                num3 >>= this.tree[num7 + 1];
                i     -= this.tree[num7 + 1];
                num8   = this.tree[num7];
                if ((num8 & 16) != 0)
                {
                    this.bitsToGet = (num8 & 15);
                    this.dist      = this.tree[num7 + 2];
                    this.mode      = 4;
                    continue;
                }
                if ((num8 & 64) == 0)
                {
                    this.need       = num8;
                    this.tree_index = num7 / 3 + this.tree[num7 + 2];
                    continue;
                }
                goto IL_5A4;
IL_6CF:
                int j;
                for (j = num4 - this.dist; j < 0; j += blocks.end)
                {
                }
                while (this.len != 0)
                {
                    if (num5 == 0)
                    {
                        if (num4 == blocks.end && blocks.readAt != 0)
                        {
                            num4 = 0;
                            num5 = ((num4 >= blocks.readAt) ? (blocks.end - num4) : (blocks.readAt - num4 - 1));
                        }
                        if (num5 == 0)
                        {
                            blocks.writeAt = num4;
                            r    = blocks.Flush(r);
                            num4 = blocks.writeAt;
                            num5 = ((num4 >= blocks.readAt) ? (blocks.end - num4) : (blocks.readAt - num4 - 1));
                            if (num4 == blocks.end && blocks.readAt != 0)
                            {
                                num4 = 0;
                                num5 = ((num4 >= blocks.readAt) ? (blocks.end - num4) : (blocks.readAt - num4 - 1));
                            }
                            if (num5 == 0)
                            {
                                goto Block_32;
                            }
                        }
                    }
                    blocks.window[num4++] = blocks.window[j++];
                    num5--;
                    if (j == blocks.end)
                    {
                        j = 0;
                    }
                    this.len--;
                }
                this.mode = 0;
            }
            r                      = -2;
            blocks.bitb            = num3;
            blocks.bitk            = i;
            codec.AvailableBytesIn = num2;
            codec.TotalBytesIn    += (long)(num - codec.NextIn);
            codec.NextIn           = num;
            blocks.writeAt         = num4;
            return(blocks.Flush(r));

IL_1DF:
            blocks.bitb            = num3;
            blocks.bitk            = i;
            codec.AvailableBytesIn = num2;
            codec.TotalBytesIn    += (long)(num - codec.NextIn);
            codec.NextIn           = num;
            blocks.writeAt         = num4;
            return(blocks.Flush(r));

IL_328:
            this.mode              = 9;
            codec.Message          = "invalid literal/length code";
            r                      = -3;
            blocks.bitb            = num3;
            blocks.bitk            = i;
            codec.AvailableBytesIn = num2;
            codec.TotalBytesIn    += (long)(num - codec.NextIn);
            codec.NextIn           = num;
            blocks.writeAt         = num4;
            return(blocks.Flush(r));

IL_3A5:
            blocks.bitb            = num3;
            blocks.bitk            = i;
            codec.AvailableBytesIn = num2;
            codec.TotalBytesIn    += (long)(num - codec.NextIn);
            codec.NextIn           = num;
            blocks.writeAt         = num4;
            return(blocks.Flush(r));

IL_492:
            blocks.bitb            = num3;
            blocks.bitk            = i;
            codec.AvailableBytesIn = num2;
            codec.TotalBytesIn    += (long)(num - codec.NextIn);
            codec.NextIn           = num;
            blocks.writeAt         = num4;
            return(blocks.Flush(r));

IL_5A4:
            this.mode              = 9;
            codec.Message          = "invalid distance code";
            r                      = -3;
            blocks.bitb            = num3;
            blocks.bitk            = i;
            codec.AvailableBytesIn = num2;
            codec.TotalBytesIn    += (long)(num - codec.NextIn);
            codec.NextIn           = num;
            blocks.writeAt         = num4;
            return(blocks.Flush(r));

IL_621:
            blocks.bitb            = num3;
            blocks.bitk            = i;
            codec.AvailableBytesIn = num2;
            codec.TotalBytesIn    += (long)(num - codec.NextIn);
            codec.NextIn           = num;
            blocks.writeAt         = num4;
            return(blocks.Flush(r));

Block_32:
            blocks.bitb            = num3;
            blocks.bitk            = i;
            codec.AvailableBytesIn = num2;
            codec.TotalBytesIn    += (long)(num - codec.NextIn);
            codec.NextIn           = num;
            blocks.writeAt         = num4;
            return(blocks.Flush(r));

Block_44:
            blocks.bitb            = num3;
            blocks.bitk            = i;
            codec.AvailableBytesIn = num2;
            codec.TotalBytesIn    += (long)(num - codec.NextIn);
            codec.NextIn           = num;
            blocks.writeAt         = num4;
            return(blocks.Flush(r));

IL_9C4:
            if (i > 7)
            {
                i -= 8;
                num2++;
                num--;
            }
            blocks.writeAt = num4;
            r    = blocks.Flush(r);
            num4 = blocks.writeAt;
            int arg_A1D_0 = (num4 >= blocks.readAt) ? (blocks.end - num4) : (blocks.readAt - num4 - 1);

            if (blocks.readAt != blocks.writeAt)
            {
                blocks.bitb            = num3;
                blocks.bitk            = i;
                codec.AvailableBytesIn = num2;
                codec.TotalBytesIn    += (long)(num - codec.NextIn);
                codec.NextIn           = num;
                blocks.writeAt         = num4;
                return(blocks.Flush(r));
            }
            this.mode = 8;
IL_A86:
            r                      = 1;
            blocks.bitb            = num3;
            blocks.bitk            = i;
            codec.AvailableBytesIn = num2;
            codec.TotalBytesIn    += (long)(num - codec.NextIn);
            codec.NextIn           = num;
            blocks.writeAt         = num4;
            return(blocks.Flush(r));

IL_AD3:
            r                      = -3;
            blocks.bitb            = num3;
            blocks.bitk            = i;
            codec.AvailableBytesIn = num2;
            codec.TotalBytesIn    += (long)(num - codec.NextIn);
            codec.NextIn           = num;
            blocks.writeAt         = num4;
            return(blocks.Flush(r));
        }
        internal int Process(InflateBlocks blocks, int r)
        {
            int j;      // temporary storage
            int tindex; // temporary pointer
            int e;      // extra bits or operation
            int b = 0;  // bit buffer
            int k = 0;  // bits in bit buffer
            int p = 0;  // input data pointer
            int n;      // bytes available there
            int q;      // output window write pointer
            int m;      // bytes to end of window or read pointer
            int f;      // pointer to copy strings from

            ZlibCodec z = blocks._codec;

            // copy input/output information to locals (UPDATE macro restores)
            p = z.NextIn;
            n = z.AvailableBytesIn;
            b = blocks.bitb;
            k = blocks.bitk;
            q = blocks.writeAt; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q;

            // process input and output based on current state
            while (true)
            {
                switch (mode)
                {
                    // waiting for "i:"=input, "o:"=output, "x:"=nothing
                    case START:  // x: set up for LEN
                        if (m >= 258 && n >= 10)
                        {
                            blocks.bitb = b; blocks.bitk = k;
                            z.AvailableBytesIn = n;
                            z.TotalBytesIn += p - z.NextIn;
                            z.NextIn = p;
                            blocks.writeAt = q;
                            r = InflateFast(lbits, dbits, ltree, ltree_index, dtree, dtree_index, blocks, z);

                            p = z.NextIn;
                            n = z.AvailableBytesIn;
                            b = blocks.bitb;
                            k = blocks.bitk;
                            q = blocks.writeAt; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q;

                            if (r != ZlibConstants.Z_OK)
                            {
                                mode = (r == ZlibConstants.Z_STREAM_END) ? WASH : BADCODE;
                                break;
                            }
                        }
                        need = lbits;
                        tree = ltree;
                        tree_index = ltree_index;

                        mode = LEN;
                        goto case LEN;

                    case LEN:  // i: get length/literal/eob next
                        j = need;

                        while (k < j)
                        {
                            if (n != 0)
                                r = ZlibConstants.Z_OK;
                            else
                            {
                                blocks.bitb = b; blocks.bitk = k;
                                z.AvailableBytesIn = n;
                                z.TotalBytesIn += p - z.NextIn;
                                z.NextIn = p;
                                blocks.writeAt = q;
                                return blocks.Flush(r);
                            }
                            n--;
                            b |= (z.InputBuffer[p++] & 0xff) << k;
                            k += 8;
                        }

                        tindex = (tree_index + (b & InternalInflateConstants.InflateMask[j])) * 3;

                        b >>= (tree[tindex + 1]);
                        k -= (tree[tindex + 1]);

                        e = tree[tindex];

                        if (e == 0)
                        {
                            // literal
                            lit = tree[tindex + 2];
                            mode = LIT;
                            break;
                        }
                        if ((e & 16) != 0)
                        {
                            // length
                            bitsToGet = e & 15;
                            len = tree[tindex + 2];
                            mode = LENEXT;
                            break;
                        }
                        if ((e & 64) == 0)
                        {
                            // next table
                            need = e;
                            tree_index = tindex / 3 + tree[tindex + 2];
                            break;
                        }
                        if ((e & 32) != 0)
                        {
                            // end of block
                            mode = WASH;
                            break;
                        }
                        mode = BADCODE; // invalid code
                        z.Message = "invalid literal/length code";
                        r = ZlibConstants.Z_DATA_ERROR;

                        blocks.bitb = b; blocks.bitk = k;
                        z.AvailableBytesIn = n;
                        z.TotalBytesIn += p - z.NextIn;
                        z.NextIn = p;
                        blocks.writeAt = q;
                        return blocks.Flush(r);


                    case LENEXT:  // i: getting length extra (have base)
                        j = bitsToGet;

                        while (k < j)
                        {
                            if (n != 0)
                                r = ZlibConstants.Z_OK;
                            else
                            {
                                blocks.bitb = b; blocks.bitk = k;
                                z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p;
                                blocks.writeAt = q;
                                return blocks.Flush(r);
                            }
                            n--; b |= (z.InputBuffer[p++] & 0xff) << k;
                            k += 8;
                        }

                        len += (b & InternalInflateConstants.InflateMask[j]);

                        b >>= j;
                        k -= j;

                        need = dbits;
                        tree = dtree;
                        tree_index = dtree_index;
                        mode = DIST;
                        goto case DIST;

                    case DIST:  // i: get distance next
                        j = need;

                        while (k < j)
                        {
                            if (n != 0)
                                r = ZlibConstants.Z_OK;
                            else
                            {
                                blocks.bitb = b; blocks.bitk = k;
                                z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p;
                                blocks.writeAt = q;
                                return blocks.Flush(r);
                            }
                            n--; b |= (z.InputBuffer[p++] & 0xff) << k;
                            k += 8;
                        }

                        tindex = (tree_index + (b & InternalInflateConstants.InflateMask[j])) * 3;

                        b >>= tree[tindex + 1];
                        k -= tree[tindex + 1];

                        e = (tree[tindex]);
                        if ((e & 0x10) != 0)
                        {
                            // distance
                            bitsToGet = e & 15;
                            dist = tree[tindex + 2];
                            mode = DISTEXT;
                            break;
                        }
                        if ((e & 64) == 0)
                        {
                            // next table
                            need = e;
                            tree_index = tindex / 3 + tree[tindex + 2];
                            break;
                        }
                        mode = BADCODE; // invalid code
                        z.Message = "invalid distance code";
                        r = ZlibConstants.Z_DATA_ERROR;

                        blocks.bitb = b; blocks.bitk = k;
                        z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p;
                        blocks.writeAt = q;
                        return blocks.Flush(r);


                    case DISTEXT:  // i: getting distance extra
                        j = bitsToGet;

                        while (k < j)
                        {
                            if (n != 0)
                                r = ZlibConstants.Z_OK;
                            else
                            {
                                blocks.bitb = b; blocks.bitk = k;
                                z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p;
                                blocks.writeAt = q;
                                return blocks.Flush(r);
                            }
                            n--; b |= (z.InputBuffer[p++] & 0xff) << k;
                            k += 8;
                        }

                        dist += (b & InternalInflateConstants.InflateMask[j]);

                        b >>= j;
                        k -= j;

                        mode = COPY;
                        goto case COPY;

                    case COPY:  // o: copying bytes in window, waiting for space
                        f = q - dist;
                        while (f < 0)
                        {
                            // modulo window size-"while" instead
                            f += blocks.end; // of "if" handles invalid distances
                        }
                        while (len != 0)
                        {
                            if (m == 0)
                            {
                                if (q == blocks.end && blocks.readAt != 0)
                                {
                                    q = 0; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q;
                                }
                                if (m == 0)
                                {
                                    blocks.writeAt = q; r = blocks.Flush(r);
                                    q = blocks.writeAt; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q;

                                    if (q == blocks.end && blocks.readAt != 0)
                                    {
                                        q = 0; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q;
                                    }

                                    if (m == 0)
                                    {
                                        blocks.bitb = b; blocks.bitk = k;
                                        z.AvailableBytesIn = n;
                                        z.TotalBytesIn += p - z.NextIn;
                                        z.NextIn = p;
                                        blocks.writeAt = q;
                                        return blocks.Flush(r);
                                    }
                                }
                            }

                            blocks.window[q++] = blocks.window[f++]; m--;

                            if (f == blocks.end)
                                f = 0;
                            len--;
                        }
                        mode = START;
                        break;

                    case LIT:  // o: got literal, waiting for output space
                        if (m == 0)
                        {
                            if (q == blocks.end && blocks.readAt != 0)
                            {
                                q = 0; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q;
                            }
                            if (m == 0)
                            {
                                blocks.writeAt = q; r = blocks.Flush(r);
                                q = blocks.writeAt; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q;

                                if (q == blocks.end && blocks.readAt != 0)
                                {
                                    q = 0; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q;
                                }
                                if (m == 0)
                                {
                                    blocks.bitb = b; blocks.bitk = k;
                                    z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p;
                                    blocks.writeAt = q;
                                    return blocks.Flush(r);
                                }
                            }
                        }
                        r = ZlibConstants.Z_OK;

                        blocks.window[q++] = (byte)lit; m--;

                        mode = START;
                        break;

                    case WASH:  // o: got eob, possibly more output
                        if (k > 7)
                        {
                            // return unused byte, if any
                            k -= 8;
                            n++;
                            p--; // can always return one
                        }

                        blocks.writeAt = q; r = blocks.Flush(r);
                        q = blocks.writeAt; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q;

                        if (blocks.readAt != blocks.writeAt)
                        {
                            blocks.bitb = b; blocks.bitk = k;
                            z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p;
                            blocks.writeAt = q;
                            return blocks.Flush(r);
                        }
                        mode = END;
                        goto case END;

                    case END:
                        r = ZlibConstants.Z_STREAM_END;
                        blocks.bitb = b; blocks.bitk = k;
                        z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p;
                        blocks.writeAt = q;
                        return blocks.Flush(r);

                    case BADCODE:  // x: got error

                        r = ZlibConstants.Z_DATA_ERROR;

                        blocks.bitb = b; blocks.bitk = k;
                        z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p;
                        blocks.writeAt = q;
                        return blocks.Flush(r);

                    default:
                        r = ZlibConstants.Z_STREAM_ERROR;

                        blocks.bitb = b; blocks.bitk = k;
                        z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p;
                        blocks.writeAt = q;
                        return blocks.Flush(r);
                }
            }
        }
        internal int InflateFast(int bl, int bd, int[] tl, int tl_index, int[] td, int td_index, InflateBlocks s, ZlibCodec z)
        {
            int num  = z.NextIn;
            int num2 = z.AvailableBytesIn;
            int num3 = s.bitb;
            int i    = s.bitk;
            int num4 = s.writeAt;
            int num5 = (num4 >= s.readAt) ? (s.end - num4) : (s.readAt - num4 - 1);
            int num6 = InternalInflateConstants.InflateMask[bl];
            int num7 = InternalInflateConstants.InflateMask[bd];
            int num10;
            int num11;

            while (true)
            {
                while (i < 20)
                {
                    num2--;
                    num3 |= (int)(z.InputBuffer[num++] & 255) << i;
                    i    += 8;
                }
                int num8 = num3 & num6;
                int num9 = (tl_index + num8) * 3;
                if ((num10 = tl[num9]) == 0)
                {
                    num3           >>= tl[num9 + 1];
                    i               -= tl[num9 + 1];
                    s.window[num4++] = (byte)tl[num9 + 2];
                    num5--;
                }
                else
                {
                    while (true)
                    {
                        num3 >>= tl[num9 + 1];
                        i     -= tl[num9 + 1];
                        if ((num10 & 16) != 0)
                        {
                            break;
                        }
                        if ((num10 & 64) != 0)
                        {
                            goto IL_513;
                        }
                        num8 += tl[num9 + 2];
                        num8 += (num3 & InternalInflateConstants.InflateMask[num10]);
                        num9  = (tl_index + num8) * 3;
                        if ((num10 = tl[num9]) == 0)
                        {
                            goto Block_20;
                        }
                    }
                    num10 &= 15;
                    num11  = tl[num9 + 2] + (num3 & InternalInflateConstants.InflateMask[num10]);
                    num3 >>= num10;
                    for (i -= num10; i < 15; i += 8)
                    {
                        num2--;
                        num3 |= (int)(z.InputBuffer[num++] & 255) << i;
                    }
                    num8  = (num3 & num7);
                    num9  = (td_index + num8) * 3;
                    num10 = td[num9];
                    while (true)
                    {
                        num3 >>= td[num9 + 1];
                        i     -= td[num9 + 1];
                        if ((num10 & 16) != 0)
                        {
                            break;
                        }
                        if ((num10 & 64) != 0)
                        {
                            goto IL_409;
                        }
                        num8 += td[num9 + 2];
                        num8 += (num3 & InternalInflateConstants.InflateMask[num10]);
                        num9  = (td_index + num8) * 3;
                        num10 = td[num9];
                    }
                    num10 &= 15;
                    while (i < num10)
                    {
                        num2--;
                        num3 |= (int)(z.InputBuffer[num++] & 255) << i;
                        i    += 8;
                    }
                    int num12 = td[num9 + 2] + (num3 & InternalInflateConstants.InflateMask[num10]);
                    num3 >>= num10;
                    i     -= num10;
                    num5  -= num11;
                    int num13;
                    if (num4 >= num12)
                    {
                        num13 = num4 - num12;
                        if (num4 - num13 > 0 && 2 > num4 - num13)
                        {
                            s.window[num4++] = s.window[num13++];
                            s.window[num4++] = s.window[num13++];
                            num11           -= 2;
                        }
                        else
                        {
                            Array.Copy(s.window, num13, s.window, num4, 2);
                            num4  += 2;
                            num13 += 2;
                            num11 -= 2;
                        }
                    }
                    else
                    {
                        num13 = num4 - num12;
                        do
                        {
                            num13 += s.end;
                        }while (num13 < 0);
                        num10 = s.end - num13;
                        if (num11 > num10)
                        {
                            num11 -= num10;
                            if (num4 - num13 > 0 && num10 > num4 - num13)
                            {
                                do
                                {
                                    s.window[num4++] = s.window[num13++];
                                }while (--num10 != 0);
                            }
                            else
                            {
                                Array.Copy(s.window, num13, s.window, num4, num10);
                                num4  += num10;
                                num13 += num10;
                            }
                            num13 = 0;
                        }
                    }
                    if (num4 - num13 > 0 && num11 > num4 - num13)
                    {
                        do
                        {
                            s.window[num4++] = s.window[num13++];
                        }while (--num11 != 0);
                    }
                    else
                    {
                        Array.Copy(s.window, num13, s.window, num4, num11);
                        num4  += num11;
                        num13 += num11;
                    }
                    goto IL_634;
Block_20:
                    num3           >>= tl[num9 + 1];
                    i               -= tl[num9 + 1];
                    s.window[num4++] = (byte)tl[num9 + 2];
                    num5--;
                }
IL_634:
                if (num5 < 258 || num2 < 10)
                {
                    goto IL_649;
                }
            }
IL_409:
            z.Message          = "invalid distance code";
            num11              = z.AvailableBytesIn - num2;
            num11              = ((i >> 3 >= num11) ? num11 : (i >> 3));
            num2              += num11;
            num               -= num11;
            i                 -= num11 << 3;
            s.bitb             = num3;
            s.bitk             = i;
            z.AvailableBytesIn = num2;
            z.TotalBytesIn    += (long)(num - z.NextIn);
            z.NextIn           = num;
            s.writeAt          = num4;
            return(-3);

IL_513:
            if ((num10 & 32) != 0)
            {
                num11              = z.AvailableBytesIn - num2;
                num11              = ((i >> 3 >= num11) ? num11 : (i >> 3));
                num2              += num11;
                num               -= num11;
                i                 -= num11 << 3;
                s.bitb             = num3;
                s.bitk             = i;
                z.AvailableBytesIn = num2;
                z.TotalBytesIn    += (long)(num - z.NextIn);
                z.NextIn           = num;
                s.writeAt          = num4;
                return(1);
            }
            z.Message          = "invalid literal/length code";
            num11              = z.AvailableBytesIn - num2;
            num11              = ((i >> 3 >= num11) ? num11 : (i >> 3));
            num2              += num11;
            num               -= num11;
            i                 -= num11 << 3;
            s.bitb             = num3;
            s.bitk             = i;
            z.AvailableBytesIn = num2;
            z.TotalBytesIn    += (long)(num - z.NextIn);
            z.NextIn           = num;
            s.writeAt          = num4;
            return(-3);

IL_649:
            num11              = z.AvailableBytesIn - num2;
            num11              = ((i >> 3 >= num11) ? num11 : (i >> 3));
            num2              += num11;
            num               -= num11;
            i                 -= num11 << 3;
            s.bitb             = num3;
            s.bitk             = i;
            z.AvailableBytesIn = num2;
            z.TotalBytesIn    += (long)(num - z.NextIn);
            z.NextIn           = num;
            s.writeAt          = num4;
            return(0);
        }
        internal int Initialize(ZlibCodec codec, int w)
        {
            _codec = codec;
            _codec.Message = null;
            blocks = null;

            // handle undocumented nowrap option (no zlib header or check)
            //nowrap = 0;
            //if (w < 0)
            //{
            //    w = - w;
            //    nowrap = 1;
            //}

            // set window size
            if (w < 8 || w > 15)
            {
                End();
                throw new ZlibException("Bad window size.");

                //return ZlibConstants.Z_STREAM_ERROR;
            }
            wbits = w;

            blocks = new InflateBlocks(codec,
                HandleRfc1950HeaderBytes ? this : null,
                1 << w);

            // reset state
            Reset();
            return ZlibConstants.Z_OK;
        }
 internal int End()
 {
     if (blocks != null)
         blocks.Free();
     blocks = null;
     return ZlibConstants.Z_OK;
 }
        // Called with number of bytes left to write in window at least 258
        // (the maximum string length) and number of input bytes available
        // at least ten.  The ten bytes are six bytes for the longest length/
        // distance pair plus four bytes for overloading the bit buffer.

        internal int InflateFast(int bl, int bd, int[] tl, int tl_index, int[] td, int td_index, InflateBlocks s, ZlibCodec z)
        {
            int t;        // temporary pointer
            int[] tp;     // temporary pointer
            int tp_index; // temporary pointer
            int e;        // extra bits or operation
            int b;        // bit buffer
            int k;        // bits in bit buffer
            int p;        // input data pointer
            int n;        // bytes available there
            int q;        // output window write pointer
            int m;        // bytes to end of window or read pointer
            int ml;       // mask for literal/length tree
            int md;       // mask for distance tree
            int c;        // bytes to copy
            int d;        // distance back to copy from
            int r;        // copy source pointer

            int tp_index_t_3; // (tp_index+t)*3

            // load input, output, bit values
            p = z.NextIn; n = z.AvailableBytesIn; b = s.bitb; k = s.bitk;
            q = s.writeAt; m = q < s.readAt ? s.readAt - q - 1 : s.end - q;

            // initialize masks
            ml = InternalInflateConstants.InflateMask[bl];
            md = InternalInflateConstants.InflateMask[bd];

            // do until not enough input or output space for fast loop
            do
            {
                // assume called with m >= 258 && n >= 10
                // get literal/length code
                while (k < (20))
                {
                    // max bits for literal/length code
                    n--;
                    b |= (z.InputBuffer[p++] & 0xff) << k; k += 8;
                }

                t = b & ml;
                tp = tl;
                tp_index = tl_index;
                tp_index_t_3 = (tp_index + t) * 3;
                if ((e = tp[tp_index_t_3]) == 0)
                {
                    b >>= (tp[tp_index_t_3 + 1]); k -= (tp[tp_index_t_3 + 1]);

                    s.window[q++] = (byte)tp[tp_index_t_3 + 2];
                    m--;
                    continue;
                }
                do
                {

                    b >>= (tp[tp_index_t_3 + 1]); k -= (tp[tp_index_t_3 + 1]);

                    if ((e & 16) != 0)
                    {
                        e &= 15;
                        c = tp[tp_index_t_3 + 2] + ((int)b & InternalInflateConstants.InflateMask[e]);

                        b >>= e; k -= e;

                        // decode distance base of block to copy
                        while (k < 15)
                        {
                            // max bits for distance code
                            n--;
                            b |= (z.InputBuffer[p++] & 0xff) << k; k += 8;
                        }

                        t = b & md;
                        tp = td;
                        tp_index = td_index;
                        tp_index_t_3 = (tp_index + t) * 3;
                        e = tp[tp_index_t_3];

                        do
                        {

                            b >>= (tp[tp_index_t_3 + 1]); k -= (tp[tp_index_t_3 + 1]);

                            if ((e & 16) != 0)
                            {
                                // get extra bits to add to distance base
                                e &= 15;
                                while (k < e)
                                {
                                    // get extra bits (up to 13)
                                    n--;
                                    b |= (z.InputBuffer[p++] & 0xff) << k; k += 8;
                                }

                                d = tp[tp_index_t_3 + 2] + (b & InternalInflateConstants.InflateMask[e]);

                                b >>= e; k -= e;

                                // do the copy
                                m -= c;
                                if (q >= d)
                                {
                                    // offset before dest
                                    //  just copy
                                    r = q - d;
                                    if (q - r > 0 && 2 > (q - r))
                                    {
                                        s.window[q++] = s.window[r++]; // minimum count is three,
                                        s.window[q++] = s.window[r++]; // so unroll loop a little
                                        c -= 2;
                                    }
                                    else
                                    {
                                        Array.Copy(s.window, r, s.window, q, 2);
                                        q += 2; r += 2; c -= 2;
                                    }
                                }
                                else
                                {
                                    // else offset after destination
                                    r = q - d;
                                    do
                                    {
                                        r += s.end; // force pointer in window
                                    }
                                    while (r < 0); // covers invalid distances
                                    e = s.end - r;
                                    if (c > e)
                                    {
                                        // if source crosses,
                                        c -= e; // wrapped copy
                                        if (q - r > 0 && e > (q - r))
                                        {
                                            do
                                            {
                                                s.window[q++] = s.window[r++];
                                            }
                                            while (--e != 0);
                                        }
                                        else
                                        {
                                            Array.Copy(s.window, r, s.window, q, e);
                                            q += e; r += e; e = 0;
                                        }
                                        r = 0; // copy rest from start of window
                                    }
                                }

                                // copy all or what's left
                                if (q - r > 0 && c > (q - r))
                                {
                                    do
                                    {
                                        s.window[q++] = s.window[r++];
                                    }
                                    while (--c != 0);
                                }
                                else
                                {
                                    Array.Copy(s.window, r, s.window, q, c);
                                    q += c; r += c; c = 0;
                                }
                                break;
                            }
                            else if ((e & 64) == 0)
                            {
                                t += tp[tp_index_t_3 + 2];
                                t += (b & InternalInflateConstants.InflateMask[e]);
                                tp_index_t_3 = (tp_index + t) * 3;
                                e = tp[tp_index_t_3];
                            }
                            else
                            {
                                z.Message = "invalid distance code";

                                c = z.AvailableBytesIn - n; c = (k >> 3) < c ? k >> 3 : c; n += c; p -= c; k -= (c << 3);

                                s.bitb = b; s.bitk = k;
                                z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p;
                                s.writeAt = q;

                                return ZlibConstants.Z_DATA_ERROR;
                            }
                        }
                        while (true);
                        break;
                    }

                    if ((e & 64) == 0)
                    {
                        t += tp[tp_index_t_3 + 2];
                        t += (b & InternalInflateConstants.InflateMask[e]);
                        tp_index_t_3 = (tp_index + t) * 3;
                        if ((e = tp[tp_index_t_3]) == 0)
                        {
                            b >>= (tp[tp_index_t_3 + 1]); k -= (tp[tp_index_t_3 + 1]);
                            s.window[q++] = (byte)tp[tp_index_t_3 + 2];
                            m--;
                            break;
                        }
                    }
                    else if ((e & 32) != 0)
                    {
                        c = z.AvailableBytesIn - n; c = (k >> 3) < c ? k >> 3 : c; n += c; p -= c; k -= (c << 3);

                        s.bitb = b; s.bitk = k;
                        z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p;
                        s.writeAt = q;

                        return ZlibConstants.Z_STREAM_END;
                    }
                    else
                    {
                        z.Message = "invalid literal/length code";

                        c = z.AvailableBytesIn - n; c = (k >> 3) < c ? k >> 3 : c; n += c; p -= c; k -= (c << 3);

                        s.bitb = b; s.bitk = k;
                        z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p;
                        s.writeAt = q;

                        return ZlibConstants.Z_DATA_ERROR;
                    }
                }
                while (true);
            }
            while (m >= 258 && n >= 10);

            // not enough input or output--restore pointers and return
            c = z.AvailableBytesIn - n; c = (k >> 3) < c ? k >> 3 : c; n += c; p -= c; k -= (c << 3);

            s.bitb = b; s.bitk = k;
            z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p;
            s.writeAt = q;

            return ZlibConstants.Z_OK;
        }
Beispiel #11
0
        internal int Process(InflateBlocks blocks, int r)
        {
            int       num   = 0;
            int       num2  = 0;
            int       num3  = 0;
            ZlibCodec codec = blocks._codec;

            num3 = codec.NextIn;
            int num4 = codec.AvailableBytesIn;

            num  = blocks.bitb;
            num2 = blocks.bitk;
            int num5 = blocks.writeAt;
            int num6 = (num5 >= blocks.readAt) ? (blocks.end - num5) : (blocks.readAt - num5 - 1);

            while (true)
            {
                switch (mode)
                {
                case 0:
                    if (num6 >= 258 && num4 >= 10)
                    {
                        blocks.bitb            = num;
                        blocks.bitk            = num2;
                        codec.AvailableBytesIn = num4;
                        codec.TotalBytesIn    += num3 - codec.NextIn;
                        codec.NextIn           = num3;
                        blocks.writeAt         = num5;
                        r    = InflateFast(lbits, dbits, ltree, ltree_index, dtree, dtree_index, blocks, codec);
                        num3 = codec.NextIn;
                        num4 = codec.AvailableBytesIn;
                        num  = blocks.bitb;
                        num2 = blocks.bitk;
                        num5 = blocks.writeAt;
                        num6 = ((num5 >= blocks.readAt) ? (blocks.end - num5) : (blocks.readAt - num5 - 1));
                        if (r != 0)
                        {
                            mode = ((r != 1) ? 9 : 7);
                            break;
                        }
                    }
                    need       = lbits;
                    tree       = ltree;
                    tree_index = ltree_index;
                    mode       = 1;
                    goto case 1;

                case 1:
                {
                    int num8;
                    for (num8 = need; num2 < num8; num2 += 8)
                    {
                        if (num4 == 0)
                        {
                            blocks.bitb            = num;
                            blocks.bitk            = num2;
                            codec.AvailableBytesIn = num4;
                            codec.TotalBytesIn    += num3 - codec.NextIn;
                            codec.NextIn           = num3;
                            blocks.writeAt         = num5;
                            return(blocks.Flush(r));
                        }
                        r = 0;
                        num4--;
                        num |= (codec.InputBuffer[num3++] & 0xFF) << num2;
                    }
                    int num11 = (tree_index + (num & InternalInflateConstants.InflateMask[num8])) * 3;
                    num >>= tree[num11 + 1];
                    num2 -= tree[num11 + 1];
                    int num12 = tree[num11];
                    if (num12 == 0)
                    {
                        lit  = tree[num11 + 2];
                        mode = 6;
                    }
                    else if ((num12 & 0x10) != 0)
                    {
                        bitsToGet = (num12 & 0xF);
                        len       = tree[num11 + 2];
                        mode      = 2;
                    }
                    else if ((num12 & 0x40) == 0)
                    {
                        need       = num12;
                        tree_index = num11 / 3 + tree[num11 + 2];
                    }
                    else
                    {
                        if ((num12 & 0x20) == 0)
                        {
                            mode                   = 9;
                            codec.Message          = "invalid literal/length code";
                            r                      = -3;
                            blocks.bitb            = num;
                            blocks.bitk            = num2;
                            codec.AvailableBytesIn = num4;
                            codec.TotalBytesIn    += num3 - codec.NextIn;
                            codec.NextIn           = num3;
                            blocks.writeAt         = num5;
                            return(blocks.Flush(r));
                        }
                        mode = 7;
                    }
                    break;
                }

                case 2:
                {
                    int num8;
                    for (num8 = bitsToGet; num2 < num8; num2 += 8)
                    {
                        if (num4 == 0)
                        {
                            blocks.bitb            = num;
                            blocks.bitk            = num2;
                            codec.AvailableBytesIn = num4;
                            codec.TotalBytesIn    += num3 - codec.NextIn;
                            codec.NextIn           = num3;
                            blocks.writeAt         = num5;
                            return(blocks.Flush(r));
                        }
                        r = 0;
                        num4--;
                        num |= (codec.InputBuffer[num3++] & 0xFF) << num2;
                    }
                    len       += (num & InternalInflateConstants.InflateMask[num8]);
                    num      >>= num8;
                    num2      -= num8;
                    need       = dbits;
                    tree       = dtree;
                    tree_index = dtree_index;
                    mode       = 3;
                    goto case 3;
                }

                case 3:
                {
                    int num8;
                    for (num8 = need; num2 < num8; num2 += 8)
                    {
                        if (num4 == 0)
                        {
                            blocks.bitb            = num;
                            blocks.bitk            = num2;
                            codec.AvailableBytesIn = num4;
                            codec.TotalBytesIn    += num3 - codec.NextIn;
                            codec.NextIn           = num3;
                            blocks.writeAt         = num5;
                            return(blocks.Flush(r));
                        }
                        r = 0;
                        num4--;
                        num |= (codec.InputBuffer[num3++] & 0xFF) << num2;
                    }
                    int num11 = (tree_index + (num & InternalInflateConstants.InflateMask[num8])) * 3;
                    num >>= tree[num11 + 1];
                    num2 -= tree[num11 + 1];
                    int num12 = tree[num11];
                    if ((num12 & 0x10) != 0)
                    {
                        bitsToGet = (num12 & 0xF);
                        dist      = tree[num11 + 2];
                        mode      = 4;
                    }
                    else
                    {
                        if ((num12 & 0x40) != 0)
                        {
                            mode                   = 9;
                            codec.Message          = "invalid distance code";
                            r                      = -3;
                            blocks.bitb            = num;
                            blocks.bitk            = num2;
                            codec.AvailableBytesIn = num4;
                            codec.TotalBytesIn    += num3 - codec.NextIn;
                            codec.NextIn           = num3;
                            blocks.writeAt         = num5;
                            return(blocks.Flush(r));
                        }
                        need       = num12;
                        tree_index = num11 / 3 + tree[num11 + 2];
                    }
                    break;
                }

                case 4:
                {
                    int num8;
                    for (num8 = bitsToGet; num2 < num8; num2 += 8)
                    {
                        if (num4 == 0)
                        {
                            blocks.bitb            = num;
                            blocks.bitk            = num2;
                            codec.AvailableBytesIn = num4;
                            codec.TotalBytesIn    += num3 - codec.NextIn;
                            codec.NextIn           = num3;
                            blocks.writeAt         = num5;
                            return(blocks.Flush(r));
                        }
                        r = 0;
                        num4--;
                        num |= (codec.InputBuffer[num3++] & 0xFF) << num2;
                    }
                    dist += (num & InternalInflateConstants.InflateMask[num8]);
                    num >>= num8;
                    num2 -= num8;
                    mode  = 5;
                    goto case 5;
                }

                case 5:
                {
                    int i;
                    for (i = num5 - dist; i < 0; i += blocks.end)
                    {
                    }
                    while (len != 0)
                    {
                        if (num6 == 0)
                        {
                            if (num5 == blocks.end && blocks.readAt != 0)
                            {
                                num5 = 0;
                                num6 = ((num5 >= blocks.readAt) ? (blocks.end - num5) : (blocks.readAt - num5 - 1));
                            }
                            if (num6 == 0)
                            {
                                blocks.writeAt = num5;
                                r    = blocks.Flush(r);
                                num5 = blocks.writeAt;
                                num6 = ((num5 >= blocks.readAt) ? (blocks.end - num5) : (blocks.readAt - num5 - 1));
                                if (num5 == blocks.end && blocks.readAt != 0)
                                {
                                    num5 = 0;
                                    num6 = ((num5 >= blocks.readAt) ? (blocks.end - num5) : (blocks.readAt - num5 - 1));
                                }
                                if (num6 == 0)
                                {
                                    blocks.bitb            = num;
                                    blocks.bitk            = num2;
                                    codec.AvailableBytesIn = num4;
                                    codec.TotalBytesIn    += num3 - codec.NextIn;
                                    codec.NextIn           = num3;
                                    blocks.writeAt         = num5;
                                    return(blocks.Flush(r));
                                }
                            }
                        }
                        blocks.window[num5++] = blocks.window[i++];
                        num6--;
                        if (i == blocks.end)
                        {
                            i = 0;
                        }
                        len--;
                    }
                    mode = 0;
                    break;
                }

                case 6:
                    if (num6 == 0)
                    {
                        if (num5 == blocks.end && blocks.readAt != 0)
                        {
                            num5 = 0;
                            num6 = ((num5 >= blocks.readAt) ? (blocks.end - num5) : (blocks.readAt - num5 - 1));
                        }
                        if (num6 == 0)
                        {
                            blocks.writeAt = num5;
                            r    = blocks.Flush(r);
                            num5 = blocks.writeAt;
                            num6 = ((num5 >= blocks.readAt) ? (blocks.end - num5) : (blocks.readAt - num5 - 1));
                            if (num5 == blocks.end && blocks.readAt != 0)
                            {
                                num5 = 0;
                                num6 = ((num5 >= blocks.readAt) ? (blocks.end - num5) : (blocks.readAt - num5 - 1));
                            }
                            if (num6 == 0)
                            {
                                blocks.bitb            = num;
                                blocks.bitk            = num2;
                                codec.AvailableBytesIn = num4;
                                codec.TotalBytesIn    += num3 - codec.NextIn;
                                codec.NextIn           = num3;
                                blocks.writeAt         = num5;
                                return(blocks.Flush(r));
                            }
                        }
                    }
                    r = 0;
                    blocks.window[num5++] = (byte)lit;
                    num6--;
                    mode = 0;
                    break;

                case 7:
                    if (num2 > 7)
                    {
                        num2 -= 8;
                        num4++;
                        num3--;
                    }
                    blocks.writeAt = num5;
                    r    = blocks.Flush(r);
                    num5 = blocks.writeAt;
                    num6 = ((num5 >= blocks.readAt) ? (blocks.end - num5) : (blocks.readAt - num5 - 1));
                    if (blocks.readAt != blocks.writeAt)
                    {
                        blocks.bitb            = num;
                        blocks.bitk            = num2;
                        codec.AvailableBytesIn = num4;
                        codec.TotalBytesIn    += num3 - codec.NextIn;
                        codec.NextIn           = num3;
                        blocks.writeAt         = num5;
                        return(blocks.Flush(r));
                    }
                    mode = 8;
                    goto case 8;

                case 8:
                    r                      = 1;
                    blocks.bitb            = num;
                    blocks.bitk            = num2;
                    codec.AvailableBytesIn = num4;
                    codec.TotalBytesIn    += num3 - codec.NextIn;
                    codec.NextIn           = num3;
                    blocks.writeAt         = num5;
                    return(blocks.Flush(r));

                case 9:
                    r                      = -3;
                    blocks.bitb            = num;
                    blocks.bitk            = num2;
                    codec.AvailableBytesIn = num4;
                    codec.TotalBytesIn    += num3 - codec.NextIn;
                    codec.NextIn           = num3;
                    blocks.writeAt         = num5;
                    return(blocks.Flush(r));

                default:
                    r                      = -2;
                    blocks.bitb            = num;
                    blocks.bitk            = num2;
                    codec.AvailableBytesIn = num4;
                    codec.TotalBytesIn    += num3 - codec.NextIn;
                    codec.NextIn           = num3;
                    blocks.writeAt         = num5;
                    return(blocks.Flush(r));
                }
            }
        }
Beispiel #12
0
        internal int InflateFast(int bl, int bd, int[] tl, int tl_index, int[] td, int td_index, InflateBlocks s, ZlibCodec z)
        {
            int num  = z.NextIn;
            int num2 = z.AvailableBytesIn;
            int num3 = s.bitb;
            int num4 = s.bitk;
            int num5 = s.writeAt;
            int num6 = (num5 >= s.readAt) ? (s.end - num5) : (s.readAt - num5 - 1);
            int num7 = InternalInflateConstants.InflateMask[bl];
            int num8 = InternalInflateConstants.InflateMask[bd];
            int num13;

            while (true)
            {
                if (num4 < 20)
                {
                    num2--;
                    num3 |= (z.InputBuffer[num++] & 0xFF) << (num4 & 0x1F);
                    num4 += 8;
                }
                else
                {
                    int num10 = num3 & num7;
                    int num11 = (tl_index + num10) * 3;
                    int num12;
                    if ((num12 = tl[num11]) != 0)
                    {
                        while (true)
                        {
                            num3 >>= tl[num11 + 1];
                            num4  -= tl[num11 + 1];
                            if ((num12 & 0x10) != 0)
                            {
                                num12 &= 0xF;
                                num13  = tl[num11 + 2] + (num3 & InternalInflateConstants.InflateMask[num12]);
                                num3 >>= num12;
                                for (num4 -= num12; num4 < 15; num4 += 8)
                                {
                                    num2--;
                                    num3 |= (z.InputBuffer[num++] & 0xFF) << num4;
                                }
                                num10 = (num3 & num8);
                                num11 = (td_index + num10) * 3;
                                num12 = td[num11];
                                while (true)
                                {
                                    num3 >>= td[num11 + 1];
                                    num4  -= td[num11 + 1];
                                    if ((num12 & 0x10) != 0)
                                    {
                                        break;
                                    }
                                    if ((num12 & 0x40) != 0)
                                    {
                                        z.Message          = "invalid distance code";
                                        num13              = z.AvailableBytesIn - num2;
                                        num13              = ((num4 >> 3 >= num13) ? num13 : (num4 >> 3));
                                        num2              += num13;
                                        num               -= num13;
                                        num4              -= num13 << 3;
                                        s.bitb             = num3;
                                        s.bitk             = num4;
                                        z.AvailableBytesIn = num2;
                                        z.TotalBytesIn    += num - z.NextIn;
                                        z.NextIn           = num;
                                        s.writeAt          = num5;
                                        return(-3);
                                    }
                                    num10 += td[num11 + 2];
                                    num10 += (num3 & InternalInflateConstants.InflateMask[num12]);
                                    num11  = (td_index + num10) * 3;
                                    num12  = td[num11];
                                }
                                for (num12 &= 0xF; num4 < num12; num4 += 8)
                                {
                                    num2--;
                                    num3 |= (z.InputBuffer[num++] & 0xFF) << num4;
                                }
                                int num16 = td[num11 + 2] + (num3 & InternalInflateConstants.InflateMask[num12]);
                                num3 >>= num12;
                                num4  -= num12;
                                num6  -= num13;
                                int num17;
                                if (num5 >= num16)
                                {
                                    num17 = num5 - num16;
                                    if (num5 - num17 > 0 && 2 > num5 - num17)
                                    {
                                        s.window[num5++] = s.window[num17++];
                                        s.window[num5++] = s.window[num17++];
                                        num13           -= 2;
                                    }
                                    else
                                    {
                                        Array.Copy(s.window, num17, s.window, num5, 2);
                                        num5  += 2;
                                        num17 += 2;
                                        num13 -= 2;
                                    }
                                }
                                else
                                {
                                    num17 = num5 - num16;
                                    do
                                    {
                                        num17 += s.end;
                                    }while (num17 < 0);
                                    num12 = s.end - num17;
                                    if (num13 > num12)
                                    {
                                        num13 -= num12;
                                        if (num5 - num17 > 0 && num12 > num5 - num17)
                                        {
                                            do
                                            {
                                                s.window[num5++] = s.window[num17++];
                                            }while (--num12 != 0);
                                        }
                                        else
                                        {
                                            Array.Copy(s.window, num17, s.window, num5, num12);
                                            num5  += num12;
                                            num17 += num12;
                                            num12  = 0;
                                        }
                                        num17 = 0;
                                    }
                                }
                                if (num5 - num17 > 0 && num13 > num5 - num17)
                                {
                                    do
                                    {
                                        s.window[num5++] = s.window[num17++];
                                    }while (--num13 != 0);
                                }
                                else
                                {
                                    Array.Copy(s.window, num17, s.window, num5, num13);
                                    num5  += num13;
                                    num17 += num13;
                                    num13  = 0;
                                }
                                break;
                            }
                            if ((num12 & 0x40) != 0)
                            {
                                if ((num12 & 0x20) != 0)
                                {
                                    num13              = z.AvailableBytesIn - num2;
                                    num13              = ((num4 >> 3 >= num13) ? num13 : (num4 >> 3));
                                    num2              += num13;
                                    num               -= num13;
                                    num4              -= num13 << 3;
                                    s.bitb             = num3;
                                    s.bitk             = num4;
                                    z.AvailableBytesIn = num2;
                                    z.TotalBytesIn    += num - z.NextIn;
                                    z.NextIn           = num;
                                    s.writeAt          = num5;
                                    return(1);
                                }
                                z.Message          = "invalid literal/length code";
                                num13              = z.AvailableBytesIn - num2;
                                num13              = ((num4 >> 3 >= num13) ? num13 : (num4 >> 3));
                                num2              += num13;
                                num               -= num13;
                                num4              -= num13 << 3;
                                s.bitb             = num3;
                                s.bitk             = num4;
                                z.AvailableBytesIn = num2;
                                z.TotalBytesIn    += num - z.NextIn;
                                z.NextIn           = num;
                                s.writeAt          = num5;
                                return(-3);
                            }
                            num10 += tl[num11 + 2];
                            num10 += (num3 & InternalInflateConstants.InflateMask[num12]);
                            num11  = (tl_index + num10) * 3;
                            if ((num12 = tl[num11]) == 0)
                            {
                                num3           >>= tl[num11 + 1];
                                num4            -= tl[num11 + 1];
                                s.window[num5++] = (byte)tl[num11 + 2];
                                num6--;
                                break;
                            }
                        }
                    }
                    else
                    {
                        num3           >>= tl[num11 + 1];
                        num4            -= tl[num11 + 1];
                        s.window[num5++] = (byte)tl[num11 + 2];
                        num6--;
                    }
                    if (num6 < 258 || num2 < 10)
                    {
                        break;
                    }
                }
            }
            num13              = z.AvailableBytesIn - num2;
            num13              = ((num4 >> 3 >= num13) ? num13 : (num4 >> 3));
            num2              += num13;
            num               -= num13;
            num4              -= num13 << 3;
            s.bitb             = num3;
            s.bitk             = num4;
            z.AvailableBytesIn = num2;
            z.TotalBytesIn    += num - z.NextIn;
            z.NextIn           = num;
            s.writeAt          = num5;
            return(0);
        }