Exemple #1
0
        internal int Process(int r)
        {
            int sourceIndex      = this.Codec.NextIn;
            int num1             = this.Codec.AvailableBytesIn;
            int number1          = this.Bitb;
            int num2             = this.Bitk;
            int destinationIndex = this.Write;
            int num3             = destinationIndex < this.Read ? this.Read - destinationIndex - 1 : this.End - destinationIndex;
            int num4;
            int num5;

            while (true)
            {
                switch (this.Mode)
                {
                case 0:
                    while (num2 < 3)
                    {
                        if (num1 != 0)
                        {
                            r = 0;
                            --num1;
                            number1 |= ((int)this.Codec.InputBuffer[sourceIndex++] & (int)byte.MaxValue) << num2;
                            num2    += 8;
                        }
                        else
                        {
                            this.Bitb = number1;
                            this.Bitk = num2;
                            this.Codec.AvailableBytesIn = num1;
                            this.Codec.TotalBytesIn    += (long)(sourceIndex - this.Codec.NextIn);
                            this.Codec.NextIn           = sourceIndex;
                            this.Write = destinationIndex;
                            return(this.Flush(r));
                        }
                    }
                    int number2 = number1 & 7;
                    this.Last = number2 & 1;
                    switch (SharedUtils.URShift(number2, 1))
                    {
                    case 0:
                        int number3 = SharedUtils.URShift(number1, 3);
                        int num6    = num2 - 3;
                        int bits1   = num6 & 7;
                        number1   = SharedUtils.URShift(number3, bits1);
                        num2      = num6 - bits1;
                        this.Mode = 1;
                        break;

                    case 1:
                        int[]   bl1 = new int[1];
                        int[]   bd1 = new int[1];
                        int[][] tl1 = new int[1][];
                        int[][] td1 = new int[1][];
                        InfTree.inflate_trees_fixed(bl1, bd1, tl1, td1, this.Codec);
                        this.Codes.Init(bl1[0], bd1[0], tl1[0], 0, td1[0], 0);
                        number1   = SharedUtils.URShift(number1, 3);
                        num2     -= 3;
                        this.Mode = 6;
                        break;

                    case 2:
                        number1   = SharedUtils.URShift(number1, 3);
                        num2     -= 3;
                        this.Mode = 3;
                        break;

                    case 3:
                        goto label_9;
                    }
                    break;

                case 1:
                    while (num2 < 32)
                    {
                        if (num1 != 0)
                        {
                            r = 0;
                            --num1;
                            number1 |= ((int)this.Codec.InputBuffer[sourceIndex++] & (int)byte.MaxValue) << num2;
                            num2    += 8;
                        }
                        else
                        {
                            this.Bitb = number1;
                            this.Bitk = num2;
                            this.Codec.AvailableBytesIn = num1;
                            this.Codec.TotalBytesIn    += (long)(sourceIndex - this.Codec.NextIn);
                            this.Codec.NextIn           = sourceIndex;
                            this.Write = destinationIndex;
                            return(this.Flush(r));
                        }
                    }
                    if ((SharedUtils.URShift(~number1, 16) & (int)ushort.MaxValue) == (number1 & (int)ushort.MaxValue))
                    {
                        this.Left = number1 & (int)ushort.MaxValue;
                        number1   = num2 = 0;
                        this.Mode = this.Left != 0 ? 2 : (this.Last != 0 ? 7 : 0);
                        break;
                    }
                    else
                    {
                        goto label_15;
                    }

                case 2:
                    if (num1 != 0)
                    {
                        if (num3 == 0)
                        {
                            if (destinationIndex == this.End && this.Read != 0)
                            {
                                destinationIndex = 0;
                                num3             = destinationIndex < this.Read ? this.Read - destinationIndex - 1 : this.End - destinationIndex;
                            }
                            if (num3 == 0)
                            {
                                this.Write       = destinationIndex;
                                r                = this.Flush(r);
                                destinationIndex = this.Write;
                                num3             = destinationIndex < this.Read ? this.Read - destinationIndex - 1 : this.End - destinationIndex;
                                if (destinationIndex == this.End && this.Read != 0)
                                {
                                    destinationIndex = 0;
                                    num3             = destinationIndex < this.Read ? this.Read - destinationIndex - 1 : this.End - destinationIndex;
                                }
                                if (num3 == 0)
                                {
                                    goto label_26;
                                }
                            }
                        }
                        r = 0;
                        int length = this.Left;
                        if (length > num1)
                        {
                            length = num1;
                        }
                        if (length > num3)
                        {
                            length = num3;
                        }
                        Array.Copy((Array)this.Codec.InputBuffer, sourceIndex, (Array)this.Window, destinationIndex, length);
                        sourceIndex      += length;
                        num1             -= length;
                        destinationIndex += length;
                        num3             -= length;
                        if ((this.Left -= length) == 0)
                        {
                            this.Mode = this.Last != 0 ? 7 : 0;
                            break;
                        }
                        else
                        {
                            break;
                        }
                    }
                    else
                    {
                        goto label_18;
                    }

                case 3:
                    while (num2 < 14)
                    {
                        if (num1 != 0)
                        {
                            r = 0;
                            --num1;
                            number1 |= ((int)this.Codec.InputBuffer[sourceIndex++] & (int)byte.MaxValue) << num2;
                            num2    += 8;
                        }
                        else
                        {
                            this.Bitb = number1;
                            this.Bitk = num2;
                            this.Codec.AvailableBytesIn = num1;
                            this.Codec.TotalBytesIn    += (long)(sourceIndex - this.Codec.NextIn);
                            this.Codec.NextIn           = sourceIndex;
                            this.Write = destinationIndex;
                            return(this.Flush(r));
                        }
                    }
                    int num7;
                    this.Table = num7 = number1 & 16383;
                    if ((num7 & 31) <= 29 && (num7 >> 5 & 31) <= 29)
                    {
                        int length = 258 + (num7 & 31) + (num7 >> 5 & 31);
                        if (this.Blens == null || this.Blens.Length < length)
                        {
                            this.Blens = new int[length];
                        }
                        else
                        {
                            for (int Index = 0; Index < length; ++Index)
                            {
                                this.Blens[Index] = 0;
                            }
                        }
                        number1    = SharedUtils.URShift(number1, 14);
                        num2      -= 14;
                        this.Index = 0;
                        this.Mode  = 4;
                        goto case 4;
                    }
                    else
                    {
                        goto label_39;
                    }

                case 4:
                    while (this.Index < 4 + SharedUtils.URShift(this.Table, 10))
                    {
                        while (num2 < 3)
                        {
                            if (num1 != 0)
                            {
                                r = 0;
                                --num1;
                                number1 |= ((int)this.Codec.InputBuffer[sourceIndex++] & (int)byte.MaxValue) << num2;
                                num2    += 8;
                            }
                            else
                            {
                                this.Bitb = number1;
                                this.Bitk = num2;
                                this.Codec.AvailableBytesIn = num1;
                                this.Codec.TotalBytesIn    += (long)(sourceIndex - this.Codec.NextIn);
                                this.Codec.NextIn           = sourceIndex;
                                this.Write = destinationIndex;
                                return(this.Flush(r));
                            }
                        }
                        this.Blens[InflateBlocks.border[this.Index++]] = number1 & 7;
                        number1 = SharedUtils.URShift(number1, 3);
                        num2   -= 3;
                    }
                    while (this.Index < 19)
                    {
                        this.Blens[InflateBlocks.border[this.Index++]] = 0;
                    }
                    this.Bb[0] = 7;
                    num4       = this.Inftree.inflate_trees_bits(this.Blens, this.Bb, this.Tb, this.Hufts, this.Codec);
                    if (num4 == 0)
                    {
                        this.Index = 0;
                        this.Mode  = 5;
                        goto case 5;
                    }
                    else
                    {
                        goto label_55;
                    }

                case 5:
                    while (true)
                    {
                        int num8 = this.Table;
                        if (this.Index < 258 + (num8 & 31) + (num8 >> 5 & 31))
                        {
                            int Index = this.Bb[0];
                            while (num2 < Index)
                            {
                                if (num1 != 0)
                                {
                                    r = 0;
                                    --num1;
                                    number1 |= ((int)this.Codec.InputBuffer[sourceIndex++] & (int)byte.MaxValue) << num2;
                                    num2    += 8;
                                }
                                else
                                {
                                    this.Bitb = number1;
                                    this.Bitk = num2;
                                    this.Codec.AvailableBytesIn = num1;
                                    this.Codec.TotalBytesIn    += (long)(sourceIndex - this.Codec.NextIn);
                                    this.Codec.NextIn           = sourceIndex;
                                    this.Write = destinationIndex;
                                    return(this.Flush(r));
                                }
                            }
                            if (this.Tb[0] != -1)
                            {
                            }
                            int bits2 = this.Hufts[(this.Tb[0] + (number1 & InflateBlocks.inflate_mask[Index])) * 3 + 1];
                            int num9  = this.Hufts[(this.Tb[0] + (number1 & InflateBlocks.inflate_mask[bits2])) * 3 + 2];
                            if (num9 < 16)
                            {
                                number1 = SharedUtils.URShift(number1, bits2);
                                num2   -= bits2;
                                this.Blens[this.Index++] = num9;
                            }
                            else
                            {
                                int bits3 = num9 == 18 ? 7 : num9 - 14;
                                int num10 = num9 == 18 ? 11 : 3;
                                while (num2 < bits2 + bits3)
                                {
                                    if (num1 != 0)
                                    {
                                        r = 0;
                                        --num1;
                                        number1 |= ((int)this.Codec.InputBuffer[sourceIndex++] & (int)byte.MaxValue) << num2;
                                        num2    += 8;
                                    }
                                    else
                                    {
                                        this.Bitb = number1;
                                        this.Bitk = num2;
                                        this.Codec.AvailableBytesIn = num1;
                                        this.Codec.TotalBytesIn    += (long)(sourceIndex - this.Codec.NextIn);
                                        this.Codec.NextIn           = sourceIndex;
                                        this.Write = destinationIndex;
                                        return(this.Flush(r));
                                    }
                                }
                                int number4 = SharedUtils.URShift(number1, bits2);
                                int num11   = num2 - bits2;
                                int num12   = num10 + (number4 & InflateBlocks.inflate_mask[bits3]);
                                number1 = SharedUtils.URShift(number4, bits3);
                                num2    = num11 - bits3;
                                int num13 = this.Index;
                                int num14 = this.Table;
                                if (num13 + num12 <= 258 + (num14 & 31) + (num14 >> 5 & 31) && (num9 != 16 || num13 >= 1))
                                {
                                    int num15 = num9 == 16 ? this.Blens[num13 - 1] : 0;
                                    do
                                    {
                                        this.Blens[num13++] = num15;
                                    }while (--num12 != 0);
                                    this.Index = num13;
                                }
                                else
                                {
                                    goto label_73;
                                }
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    this.Tb[0] = -1;
                    int[] bl2 = new int[1]
                    {
                        9
                    };
                    int[] bd2 = new int[1]
                    {
                        6
                    };
                    int[] tl2   = new int[1];
                    int[] td2   = new int[1];
                    int   num16 = this.Table;
                    num5 = this.Inftree.inflate_trees_dynamic(257 + (num16 & 31), 1 + (num16 >> 5 & 31), this.Blens, bl2, bd2, tl2, td2, this.Hufts, this.Codec);
                    switch (num5)
                    {
                    case 0:
                        this.Codes.Init(bl2[0], bd2[0], this.Hufts, tl2[0], this.Hufts, td2[0]);
                        this.Mode = 6;
                        goto label_83;

                    case -3:
                        goto label_80;

                    default:
                        goto label_81;
                    }

                case 6:
label_83:
                    this.Bitb = number1;
                    this.Bitk = num2;
                    this.Codec.AvailableBytesIn = num1;
                    this.Codec.TotalBytesIn    += (long)(sourceIndex - this.Codec.NextIn);
                    this.Codec.NextIn           = sourceIndex;
                    this.Write = destinationIndex;
                    if ((r = this.Codes.Process(this, r)) == 1)
                    {
                        r                = 0;
                        sourceIndex      = this.Codec.NextIn;
                        num1             = this.Codec.AvailableBytesIn;
                        number1          = this.Bitb;
                        num2             = this.Bitk;
                        destinationIndex = this.Write;
                        num3             = destinationIndex < this.Read ? this.Read - destinationIndex - 1 : this.End - destinationIndex;
                        if (this.Last == 0)
                        {
                            this.Mode = 0;
                            break;
                        }
                        else
                        {
                            goto label_87;
                        }
                    }
                    else
                    {
                        goto label_84;
                    }

                case 7:
                    goto label_88;

                case 8:
                    goto label_91;

                case 9:
                    goto label_92;

                default:
                    goto label_93;
                }
            }
label_9:
            int num17 = SharedUtils.URShift(number1, 3);
            int num18 = num2 - 3;

            this.Mode          = 9;
            this.Codec.Message = "invalid block type";
            r         = -3;
            this.Bitb = num17;
            this.Bitk = num18;
            this.Codec.AvailableBytesIn = num1;
            this.Codec.TotalBytesIn    += (long)(sourceIndex - this.Codec.NextIn);
            this.Codec.NextIn           = sourceIndex;
            this.Write = destinationIndex;
            return(this.Flush(r));

label_15:
            this.Mode          = 9;
            this.Codec.Message = "invalid stored block lengths";
            r         = -3;
            this.Bitb = number1;
            this.Bitk = num2;
            this.Codec.AvailableBytesIn = num1;
            this.Codec.TotalBytesIn    += (long)(sourceIndex - this.Codec.NextIn);
            this.Codec.NextIn           = sourceIndex;
            this.Write = destinationIndex;
            return(this.Flush(r));

label_18:
            this.Bitb = number1;
            this.Bitk = num2;
            this.Codec.AvailableBytesIn = num1;
            this.Codec.TotalBytesIn    += (long)(sourceIndex - this.Codec.NextIn);
            this.Codec.NextIn           = sourceIndex;
            this.Write = destinationIndex;
            return(this.Flush(r));

label_26:
            this.Bitb = number1;
            this.Bitk = num2;
            this.Codec.AvailableBytesIn = num1;
            this.Codec.TotalBytesIn    += (long)(sourceIndex - this.Codec.NextIn);
            this.Codec.NextIn           = sourceIndex;
            this.Write = destinationIndex;
            return(this.Flush(r));

label_39:
            this.Mode          = 9;
            this.Codec.Message = "too many length or distance symbols";
            r         = -3;
            this.Bitb = number1;
            this.Bitk = num2;
            this.Codec.AvailableBytesIn = num1;
            this.Codec.TotalBytesIn    += (long)(sourceIndex - this.Codec.NextIn);
            this.Codec.NextIn           = sourceIndex;
            this.Write = destinationIndex;
            return(this.Flush(r));

label_55:
            r = num4;
            if (r == -3)
            {
                this.Blens = (int[])null;
                this.Mode  = 9;
            }
            this.Bitb = number1;
            this.Bitk = num2;
            this.Codec.AvailableBytesIn = num1;
            this.Codec.TotalBytesIn    += (long)(sourceIndex - this.Codec.NextIn);
            this.Codec.NextIn           = sourceIndex;
            this.Write = destinationIndex;
            return(this.Flush(r));

label_73:
            this.Blens         = (int[])null;
            this.Mode          = 9;
            this.Codec.Message = "invalid bit length repeat";
            r         = -3;
            this.Bitb = number1;
            this.Bitk = num2;
            this.Codec.AvailableBytesIn = num1;
            this.Codec.TotalBytesIn    += (long)(sourceIndex - this.Codec.NextIn);
            this.Codec.NextIn           = sourceIndex;
            this.Write = destinationIndex;
            return(this.Flush(r));

label_80:
            this.Blens = (int[])null;
            this.Mode  = 9;
label_81:
            r         = num5;
            this.Bitb = number1;
            this.Bitk = num2;
            this.Codec.AvailableBytesIn = num1;
            this.Codec.TotalBytesIn    += (long)(sourceIndex - this.Codec.NextIn);
            this.Codec.NextIn           = sourceIndex;
            this.Write = destinationIndex;
            return(this.Flush(r));

label_84:
            return(this.Flush(r));

label_87:
            this.Mode = 7;
label_88:
            this.Write       = destinationIndex;
            r                = this.Flush(r);
            destinationIndex = this.Write;
            int num19 = destinationIndex < this.Read ? this.Read - destinationIndex - 1 : this.End - destinationIndex;

            if (this.Read != this.Write)
            {
                this.Bitb = number1;
                this.Bitk = num2;
                this.Codec.AvailableBytesIn = num1;
                this.Codec.TotalBytesIn    += (long)(sourceIndex - this.Codec.NextIn);
                this.Codec.NextIn           = sourceIndex;
                this.Write = destinationIndex;
                return(this.Flush(r));
            }
            else
            {
                this.Mode = 8;
            }
label_91:
            r         = 1;
            this.Bitb = number1;
            this.Bitk = num2;
            this.Codec.AvailableBytesIn = num1;
            this.Codec.TotalBytesIn    += (long)(sourceIndex - this.Codec.NextIn);
            this.Codec.NextIn           = sourceIndex;
            this.Write = destinationIndex;
            return(this.Flush(r));

label_92:
            r         = -3;
            this.Bitb = number1;
            this.Bitk = num2;
            this.Codec.AvailableBytesIn = num1;
            this.Codec.TotalBytesIn    += (long)(sourceIndex - this.Codec.NextIn);
            this.Codec.NextIn           = sourceIndex;
            this.Write = destinationIndex;
            return(this.Flush(r));

label_93:
            r         = -2;
            this.Bitb = number1;
            this.Bitk = num2;
            this.Codec.AvailableBytesIn = num1;
            this.Codec.TotalBytesIn    += (long)(sourceIndex - this.Codec.NextIn);
            this.Codec.NextIn           = sourceIndex;
            this.Write = destinationIndex;
            return(this.Flush(r));
        }
Exemple #2
0
        internal int Process(int r)
        {
            int num17;
            int nextIn           = this._codec.NextIn;
            int availableBytesIn = this._codec.AvailableBytesIn;
            int bitb             = this.bitb;
            int bitk             = this.bitk;
            int write            = this.write;
            int num6             = (write < this.read) ? ((this.read - write) - 1) : (this.end - write);

Label_0050:
            switch (this.mode)
            {
            case 0:
            {
                while (bitk < 3)
                {
                    if (availableBytesIn != 0)
                    {
                        r = 0;
                        availableBytesIn--;
                        bitb |= (this._codec.InputBuffer[nextIn++] & 0xff) << bitk;
                        bitk += 8;
                    }
                    else
                    {
                        this.bitb = bitb;
                        this.bitk = bitk;
                        this._codec.AvailableBytesIn = availableBytesIn;
                        this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
                        this._codec.NextIn           = nextIn;
                        this.write = write;
                        return(this.Flush(r));
                    }
                }
                int number = bitb & 7;
                this.last = number & 1;
                switch (SharedUtils.URShift(number, 1))
                {
                case 0:
                {
                    int num10 = SharedUtils.URShift(bitb, 3);
                    int num11 = bitk - 3;
                    int bits  = num11 & 7;
                    bitb      = SharedUtils.URShift(num10, bits);
                    bitk      = num11 - bits;
                    this.mode = 1;
                    break;
                }

                case 1:
                {
                    int[]   numArray  = new int[1];
                    int[]   numArray2 = new int[1];
                    int[][] numArray3 = new int[1][];
                    int[][] numArray4 = new int[1][];
                    InfTree.inflate_trees_fixed(numArray, numArray2, numArray3, numArray4, this._codec);
                    this.codes.Init(numArray[0], numArray2[0], numArray3[0], 0, numArray4[0], 0);
                    bitb      = SharedUtils.URShift(bitb, 3);
                    bitk     -= 3;
                    this.mode = 6;
                    break;
                }

                case 2:
                    bitb      = SharedUtils.URShift(bitb, 3);
                    bitk     -= 3;
                    this.mode = 3;
                    break;

                case 3:
                {
                    int num30 = SharedUtils.URShift(bitb, 3);
                    int num31 = bitk - 3;
                    this.mode           = 9;
                    this._codec.Message = "invalid block type";
                    r         = -3;
                    this.bitb = num30;
                    this.bitk = num31;
                    this._codec.AvailableBytesIn = availableBytesIn;
                    this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
                    this._codec.NextIn           = nextIn;
                    this.write = write;
                    return(this.Flush(r));
                }
                }
                goto Label_0050;
            }

            case 1:
                while (bitk < 0x20)
                {
                    if (availableBytesIn != 0)
                    {
                        r = 0;
                        availableBytesIn--;
                        bitb |= (this._codec.InputBuffer[nextIn++] & 0xff) << bitk;
                        bitk += 8;
                    }
                    else
                    {
                        this.bitb = bitb;
                        this.bitk = bitk;
                        this._codec.AvailableBytesIn = availableBytesIn;
                        this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
                        this._codec.NextIn           = nextIn;
                        this.write = write;
                        return(this.Flush(r));
                    }
                }
                if ((SharedUtils.URShift(~bitb, 0x10) & 0xffff) != (bitb & 0xffff))
                {
                    this.mode           = 9;
                    this._codec.Message = "invalid stored block lengths";
                    r         = -3;
                    this.bitb = bitb;
                    this.bitk = bitk;
                    this._codec.AvailableBytesIn = availableBytesIn;
                    this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
                    this._codec.NextIn           = nextIn;
                    this.write = write;
                    return(this.Flush(r));
                }
                this.left = bitb & 0xffff;
                bitb      = bitk = 0;
                this.mode = (this.left != 0) ? 2 : ((this.last != 0) ? 7 : 0);
                goto Label_0050;

            case 2:
            {
                if (availableBytesIn == 0)
                {
                    this.bitb = bitb;
                    this.bitk = bitk;
                    this._codec.AvailableBytesIn = availableBytesIn;
                    this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
                    this._codec.NextIn           = nextIn;
                    this.write = write;
                    return(this.Flush(r));
                }
                if (num6 == 0)
                {
                    if ((write == this.end) && (this.read != 0))
                    {
                        write = 0;
                        num6  = (write < this.read) ? ((this.read - write) - 1) : (this.end - write);
                    }
                    if (num6 == 0)
                    {
                        this.write = write;
                        r          = this.Flush(r);
                        write      = this.write;
                        num6       = (write < this.read) ? ((this.read - write) - 1) : (this.end - write);
                        if ((write == this.end) && (this.read != 0))
                        {
                            write = 0;
                            num6  = (write < this.read) ? ((this.read - write) - 1) : (this.end - write);
                        }
                        if (num6 == 0)
                        {
                            this.bitb = bitb;
                            this.bitk = bitk;
                            this._codec.AvailableBytesIn = availableBytesIn;
                            this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
                            this._codec.NextIn           = nextIn;
                            this.write = write;
                            return(this.Flush(r));
                        }
                    }
                }
                r = 0;
                int left = this.left;
                if (left > availableBytesIn)
                {
                    left = availableBytesIn;
                }
                if (left > num6)
                {
                    left = num6;
                }
                Array.Copy(this._codec.InputBuffer, nextIn, this.window, write, left);
                nextIn           += left;
                availableBytesIn -= left;
                write            += left;
                num6             -= left;
                this.left        -= left;
                if (this.left == 0)
                {
                    this.mode = (this.last != 0) ? 7 : 0;
                }
                goto Label_0050;
            }

            case 3:
            {
                int num14;
                while (bitk < 14)
                {
                    if (availableBytesIn != 0)
                    {
                        r = 0;
                        availableBytesIn--;
                        bitb |= (this._codec.InputBuffer[nextIn++] & 0xff) << bitk;
                        bitk += 8;
                    }
                    else
                    {
                        this.bitb = bitb;
                        this.bitk = bitk;
                        this._codec.AvailableBytesIn = availableBytesIn;
                        this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
                        this._codec.NextIn           = nextIn;
                        this.write = write;
                        return(this.Flush(r));
                    }
                }
                this.table = num14 = bitb & 0x3fff;
                if (((num14 & 0x1f) > 0x1d) || (((num14 >> 5) & 0x1f) > 0x1d))
                {
                    this.mode           = 9;
                    this._codec.Message = "too many length or distance symbols";
                    r         = -3;
                    this.bitb = bitb;
                    this.bitk = bitk;
                    this._codec.AvailableBytesIn = availableBytesIn;
                    this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
                    this._codec.NextIn           = nextIn;
                    this.write = write;
                    return(this.Flush(r));
                }
                int num15 = (0x102 + (num14 & 0x1f)) + ((num14 >> 5) & 0x1f);
                if ((this.blens == null) || (this.blens.Length < num15))
                {
                    this.blens = new int[num15];
                }
                else
                {
                    for (int i = 0; i < num15; i++)
                    {
                        this.blens[i] = 0;
                    }
                }
                bitb       = SharedUtils.URShift(bitb, 14);
                bitk      -= 14;
                this.index = 0;
                this.mode  = 4;
                break;
            }

            case 4:
                break;

            case 5:
                goto Label_068D;

            case 6:
                goto Label_09EA;

            case 7:
                goto Label_0E29;

            case 8:
                goto Label_0EAD;

            case 9:
                r         = -3;
                this.bitb = bitb;
                this.bitk = bitk;
                this._codec.AvailableBytesIn = availableBytesIn;
                this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
                this._codec.NextIn           = nextIn;
                this.write = write;
                return(this.Flush(r));

            default:
                r         = -2;
                this.bitb = bitb;
                this.bitk = bitk;
                this._codec.AvailableBytesIn = availableBytesIn;
                this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
                this._codec.NextIn           = nextIn;
                this.write = write;
                return(this.Flush(r));
            }
            while (this.index < (4 + SharedUtils.URShift(this.table, 10)))
            {
                while (bitk < 3)
                {
                    if (availableBytesIn != 0)
                    {
                        r = 0;
                        availableBytesIn--;
                        bitb |= (this._codec.InputBuffer[nextIn++] & 0xff) << bitk;
                        bitk += 8;
                    }
                    else
                    {
                        this.bitb = bitb;
                        this.bitk = bitk;
                        this._codec.AvailableBytesIn = availableBytesIn;
                        this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
                        this._codec.NextIn           = nextIn;
                        this.write = write;
                        return(this.Flush(r));
                    }
                }
                this.blens[border[this.index++]] = bitb & 7;
                bitb  = SharedUtils.URShift(bitb, 3);
                bitk -= 3;
            }
            while (this.index < 0x13)
            {
                this.blens[border[this.index++]] = 0;
            }
            this.bb[0] = 7;
            int num7 = this.inftree.inflate_trees_bits(this.blens, this.bb, this.tb, this.hufts, this._codec);

            if (num7 != 0)
            {
                r = num7;
                if (r == -3)
                {
                    this.blens = null;
                    this.mode  = 9;
                }
                this.bitb = bitb;
                this.bitk = bitk;
                this._codec.AvailableBytesIn = availableBytesIn;
                this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
                this._codec.NextIn           = nextIn;
                this.write = write;
                return(this.Flush(r));
            }
            this.index = 0;
            this.mode  = 5;
Label_068D:
            num17 = this.table;
            if (this.index < ((0x102 + (num17 & 0x1f)) + ((num17 >> 5) & 0x1f)))
            {
                int index = this.bb[0];
                while (bitk < index)
                {
                    if (availableBytesIn != 0)
                    {
                        r = 0;
                        availableBytesIn--;
                        bitb |= (this._codec.InputBuffer[nextIn++] & 0xff) << bitk;
                        bitk += 8;
                    }
                    else
                    {
                        this.bitb = bitb;
                        this.bitk = bitk;
                        this._codec.AvailableBytesIn = availableBytesIn;
                        this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
                        this._codec.NextIn           = nextIn;
                        this.write = write;
                        return(this.Flush(r));
                    }
                }
                int num1  = this.tb[0];
                int num19 = this.hufts[((this.tb[0] + (bitb & inflate_mask[index])) * 3) + 1];
                int num20 = this.hufts[((this.tb[0] + (bitb & inflate_mask[num19])) * 3) + 2];
                if (num20 < 0x10)
                {
                    bitb  = SharedUtils.URShift(bitb, num19);
                    bitk -= num19;
                    this.blens[this.index++] = num20;
                }
                else
                {
                    int num21 = (num20 == 0x12) ? 7 : (num20 - 14);
                    int num22 = (num20 == 0x12) ? 11 : 3;
                    while (bitk < (num19 + num21))
                    {
                        if (availableBytesIn != 0)
                        {
                            r = 0;
                            availableBytesIn--;
                            bitb |= (this._codec.InputBuffer[nextIn++] & 0xff) << bitk;
                            bitk += 8;
                        }
                        else
                        {
                            this.bitb = bitb;
                            this.bitk = bitk;
                            this._codec.AvailableBytesIn = availableBytesIn;
                            this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
                            this._codec.NextIn           = nextIn;
                            this.write = write;
                            return(this.Flush(r));
                        }
                    }
                    int num23 = SharedUtils.URShift(bitb, num19);
                    int num24 = bitk - num19;
                    int num25 = num22 + (num23 & inflate_mask[num21]);
                    bitb = SharedUtils.URShift(num23, num21);
                    bitk = num24 - num21;
                    int num26 = this.index;
                    int num27 = this.table;
                    if (((num26 + num25) > ((0x102 + (num27 & 0x1f)) + ((num27 >> 5) & 0x1f))) || ((num20 == 0x10) && (num26 < 1)))
                    {
                        this.blens          = null;
                        this.mode           = 9;
                        this._codec.Message = "invalid bit length repeat";
                        r         = -3;
                        this.bitb = bitb;
                        this.bitk = bitk;
                        this._codec.AvailableBytesIn = availableBytesIn;
                        this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
                        this._codec.NextIn           = nextIn;
                        this.write = write;
                        return(this.Flush(r));
                    }
                    int num28 = (num20 == 0x10) ? this.blens[num26 - 1] : 0;
                    do
                    {
                        this.blens[num26++] = num28;
                    }while (--num25 != 0);
                    this.index = num26;
                }
                goto Label_068D;
            }
            this.tb[0] = -1;
            int[] bl    = new int[] { 9 };
            int[] bd    = new int[] { 6 };
            int[] tl    = new int[1];
            int[] td    = new int[1];
            int   table = this.table;
            int   num8  = this.inftree.inflate_trees_dynamic(0x101 + (table & 0x1f), 1 + ((table >> 5) & 0x1f), this.blens, bl, bd, tl, td, this.hufts, this._codec);
            int   num38 = num8;

            if (num38 == -3)
            {
                this.blens = null;
                this.mode  = 9;
                goto Label_0DC0;
            }
            if (num38 != 0)
            {
                goto Label_0DC0;
            }
            this.codes.Init(bl[0], bd[0], this.hufts, tl[0], this.hufts, td[0]);
            this.mode = 6;
Label_09EA:
            this.bitb = bitb;
            this.bitk = bitk;
            this._codec.AvailableBytesIn = availableBytesIn;
            this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
            this._codec.NextIn           = nextIn;
            this.write = write;
            if ((r = this.codes.Process(this, r)) != 1)
            {
                return(this.Flush(r));
            }
            r                = 0;
            nextIn           = this._codec.NextIn;
            availableBytesIn = this._codec.AvailableBytesIn;
            bitb             = this.bitb;
            bitk             = this.bitk;
            write            = this.write;
            num6             = (write < this.read) ? ((this.read - write) - 1) : (this.end - write);
            if (this.last != 0)
            {
                this.mode = 7;
                goto Label_0E29;
            }
            this.mode = 0;
            goto Label_0050;
Label_0DC0:
            r         = num8;
            this.bitb = bitb;
            this.bitk = bitk;
            this._codec.AvailableBytesIn = availableBytesIn;
            this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
            this._codec.NextIn           = nextIn;
            this.write = write;
            return(this.Flush(r));

Label_0E29:
            this.write = write;
            r          = this.Flush(r);
            write      = this.write;
            if (this.read != this.write)
            {
                this.bitb = bitb;
                this.bitk = bitk;
                this._codec.AvailableBytesIn = availableBytesIn;
                this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
                this._codec.NextIn           = nextIn;
                this.write = write;
                return(this.Flush(r));
            }
            this.mode = 8;
Label_0EAD:
            r         = 1;
            this.bitb = bitb;
            this.bitk = bitk;
            this._codec.AvailableBytesIn = availableBytesIn;
            this._codec.TotalBytesIn    += nextIn - this._codec.NextIn;
            this._codec.NextIn           = nextIn;
            this.write = write;
            return(this.Flush(r));
        }