Пример #1
0
        internal static int bi_reverse(int code, int len)
        {
            int number = 0;

            do
            {
                number |= code & 1;
                code    = SupportClass.URShift(code, 1);
                number  = number << 1;
            }while(--len > 0);
            return(SupportClass.URShift(number, 1));
        }
Пример #2
0
 internal void bi_flush()
 {
     if (this.bi_valid == 0x10)
     {
         this.put_short(this.bi_buf);
         this.bi_buf   = 0;
         this.bi_valid = 0;
     }
     else if (this.bi_valid >= 8)
     {
         this.put_byte((byte)this.bi_buf);
         this.bi_buf    = (short)SupportClass.URShift((int)this.bi_buf, 8);
         this.bi_valid -= 8;
     }
 }
Пример #3
0
        internal void _tr_flush_block(int buf, int stored_len, bool eof)
        {
            int num;
            int num2;
            int num3 = 0;

            if (this.level > 0)
            {
                if (this.data_type == 2)
                {
                    this.set_data_type();
                }
                this.l_desc.build_tree(this);
                this.d_desc.build_tree(this);
                num3 = this.build_bl_tree();
                num  = SupportClass.URShift((int)((this.opt_len + 3) + 7), 3);
                num2 = SupportClass.URShift((int)((this.static_len + 3) + 7), 3);
                if (num2 <= num)
                {
                    num = num2;
                }
            }
            else
            {
                num = num2 = stored_len + 5;
            }
            if (((stored_len + 4) <= num) && (buf != -1))
            {
                this._tr_stored_block(buf, stored_len, eof);
            }
            else if (num2 == num)
            {
                this.send_bits(2 + (eof ? 1 : 0), 3);
                this.compress_block(StaticTree.static_ltree, StaticTree.static_dtree);
            }
            else
            {
                this.send_bits(4 + (eof ? 1 : 0), 3);
                this.send_all_trees(this.l_desc.max_code + 1, this.d_desc.max_code + 1, num3 + 1);
                this.compress_block(this.dyn_ltree, this.dyn_dtree);
            }
            this.init_block();
            if (eof)
            {
                this.bi_windup();
            }
        }
Пример #4
0
        internal void send_bits(int value_Renamed, int length)
        {
            int num = length;

            if (this.bi_valid > (0x10 - num))
            {
                int number = value_Renamed;
                this.bi_buf = (short)(((ushort)this.bi_buf) | ((ushort)((number << this.bi_valid) & 0xffff)));
                this.put_short(this.bi_buf);
                this.bi_buf    = (short)SupportClass.URShift(number, (int)(0x10 - this.bi_valid));
                this.bi_valid += num - 0x10;
            }
            else
            {
                this.bi_buf    = (short)(((ushort)this.bi_buf) | ((ushort)((value_Renamed << this.bi_valid) & 0xffff)));
                this.bi_valid += num;
            }
        }
Пример #5
0
        internal void set_data_type()
        {
            int num    = 0;
            int number = 0;
            int num3   = 0;

            while (num < 7)
            {
                num3 += this.dyn_ltree[num * 2];
                num++;
            }
            while (num < 0x80)
            {
                number += this.dyn_ltree[num * 2];
                num++;
            }
            while (num < 0x100)
            {
                num3 += this.dyn_ltree[num * 2];
                num++;
            }
            this.data_type = (num3 > SupportClass.URShift(number, 2)) ? ((byte)0) : ((byte)1);
        }
Пример #6
0
        internal int deflate(ZStream strm, int flush)
        {
            if ((flush > 4) || (flush < 0))
            {
                return(-2);
            }
            if (((strm.next_out == null) || ((strm.next_in == null) && (strm.avail_in != 0))) || ((this.status == 0x29a) && (flush != 4)))
            {
                strm.msg = z_errmsg[4];
                return(-2);
            }
            if (strm.avail_out == 0)
            {
                strm.msg = z_errmsg[7];
                return(-5);
            }
            this.strm = strm;
            int num = this.last_flush;

            this.last_flush = flush;
            if (this.status == 0x2a)
            {
                int b    = (8 + ((this.w_bits - 8) << 4)) << 8;
                int num3 = ((this.level - 1) & 0xff) >> 1;
                if (num3 > 3)
                {
                    num3 = 3;
                }
                b |= num3 << 6;
                if (this.strstart != 0)
                {
                    b |= 0x20;
                }
                b          += 0x1f - (b % 0x1f);
                this.status = 0x71;
                this.putShortMSB(b);
                if (this.strstart != 0)
                {
                    this.putShortMSB((int)SupportClass.URShift(strm.adler, 0x10));
                    this.putShortMSB((int)(strm.adler & 0xffffL));
                }
                strm.adler = strm._adler.adler32(0L, null, 0, 0);
            }
            if (this.pending != 0)
            {
                strm.flush_pending();
                if (strm.avail_out == 0)
                {
                    this.last_flush = -1;
                    return(0);
                }
            }
            else if (((strm.avail_in == 0) && (flush <= num)) && (flush != 4))
            {
                strm.msg = z_errmsg[7];
                return(-5);
            }
            if ((this.status == 0x29a) && (strm.avail_in != 0))
            {
                strm.msg = z_errmsg[7];
                return(-5);
            }
            if (((strm.avail_in != 0) || (this.lookahead != 0)) || ((flush != 0) && (this.status != 0x29a)))
            {
                int num4 = -1;
                switch (config_table[this.level].func)
                {
                case 0:
                    num4 = this.deflate_stored(flush);
                    break;

                case 1:
                    num4 = this.deflate_fast(flush);
                    break;

                case 2:
                    num4 = this.deflate_slow(flush);
                    break;
                }
                switch (num4)
                {
                case 2:
                case 3:
                    this.status = 0x29a;
                    break;
                }
                if ((num4 == 0) || (num4 == 2))
                {
                    if (strm.avail_out == 0)
                    {
                        this.last_flush = -1;
                    }
                    return(0);
                }
                if (num4 == 1)
                {
                    if (flush == 1)
                    {
                        this._tr_align();
                    }
                    else
                    {
                        this._tr_stored_block(0, 0, false);
                        if (flush == 3)
                        {
                            for (int i = 0; i < this.hash_size; i++)
                            {
                                this.head[i] = 0;
                            }
                        }
                    }
                    strm.flush_pending();
                    if (strm.avail_out == 0)
                    {
                        this.last_flush = -1;
                        return(0);
                    }
                }
            }
            if (flush == 4)
            {
                if (this.noheader != 0)
                {
                    return(1);
                }
                this.putShortMSB((int)SupportClass.URShift(strm.adler, 0x10));
                this.putShortMSB((int)(strm.adler & 0xffffL));
                strm.flush_pending();
                this.noheader = -1;
                if (this.pending == 0)
                {
                    return(1);
                }
            }
            return(0);
        }
Пример #7
0
 internal void put_short(int w)
 {
     this.put_byte((byte)w);
     this.put_byte((byte)SupportClass.URShift(w, 8));
 }
Пример #8
0
        internal int proc(InfBlocks s, ZStream z, int r)
        {
            int num;
            int num10;
            int number = 0;
            int bitk   = 0;
            int num6   = 0;

            num6 = z.next_in_index;
            int num7 = z.avail_in;

            number = s.bitb;
            bitk   = s.bitk;
            int write = s.write;
            int num9  = (write < s.read) ? ((s.read - write) - 1) : (s.end - write);

Label_0051:
            switch (this.mode)
            {
            case 0:
                if ((num9 < 0x102) || (num7 < 10))
                {
                    break;
                }
                s.bitb          = number;
                s.bitk          = bitk;
                z.avail_in      = num7;
                z.total_in     += num6 - z.next_in_index;
                z.next_in_index = num6;
                s.write         = write;
                r      = this.inflate_fast(this.lbits, this.dbits, this.ltree, this.ltree_index, this.dtree, this.dtree_index, s, z);
                num6   = z.next_in_index;
                num7   = z.avail_in;
                number = s.bitb;
                bitk   = s.bitk;
                write  = s.write;
                num9   = (write < s.read) ? ((s.read - write) - 1) : (s.end - write);
                if (r == 0)
                {
                    break;
                }
                this.mode = (r == 1) ? 7 : 9;
                goto Label_0051;

            case 1:
                goto Label_0199;

            case 2:
                num = this.get_Renamed;
                while (bitk < num)
                {
                    if (num7 != 0)
                    {
                        r = 0;
                    }
                    else
                    {
                        s.bitb          = number;
                        s.bitk          = bitk;
                        z.avail_in      = num7;
                        z.total_in     += num6 - z.next_in_index;
                        z.next_in_index = num6;
                        s.write         = write;
                        return(s.inflate_flush(z, r));
                    }
                    num7--;
                    number |= (z.next_in[num6++] & 0xff) << bitk;
                    bitk   += 8;
                }
                this.len       += number & inflate_mask[num];
                number          = number >> num;
                bitk           -= num;
                this.need       = this.dbits;
                this.tree       = this.dtree;
                this.tree_index = this.dtree_index;
                this.mode       = 3;
                goto Label_0412;

            case 3:
                goto Label_0412;

            case 4:
                num = this.get_Renamed;
                while (bitk < num)
                {
                    if (num7 != 0)
                    {
                        r = 0;
                    }
                    else
                    {
                        s.bitb          = number;
                        s.bitk          = bitk;
                        z.avail_in      = num7;
                        z.total_in     += num6 - z.next_in_index;
                        z.next_in_index = num6;
                        s.write         = write;
                        return(s.inflate_flush(z, r));
                    }
                    num7--;
                    number |= (z.next_in[num6++] & 0xff) << bitk;
                    bitk   += 8;
                }
                this.dist += number & inflate_mask[num];
                number     = number >> num;
                bitk      -= num;
                this.mode  = 5;
                goto Label_0635;

            case 5:
                goto Label_0635;

            case 6:
                if (num9 == 0)
                {
                    if ((write == s.end) && (s.read != 0))
                    {
                        write = 0;
                        num9  = (write < s.read) ? ((s.read - write) - 1) : (s.end - write);
                    }
                    if (num9 == 0)
                    {
                        s.write = write;
                        r       = s.inflate_flush(z, r);
                        write   = s.write;
                        num9    = (write < s.read) ? ((s.read - write) - 1) : (s.end - write);
                        if ((write == s.end) && (s.read != 0))
                        {
                            write = 0;
                            num9  = (write < s.read) ? ((s.read - write) - 1) : (s.end - write);
                        }
                        if (num9 == 0)
                        {
                            s.bitb          = number;
                            s.bitk          = bitk;
                            z.avail_in      = num7;
                            z.total_in     += num6 - z.next_in_index;
                            z.next_in_index = num6;
                            s.write         = write;
                            return(s.inflate_flush(z, r));
                        }
                    }
                }
                r = 0;
                s.window[write++] = (byte)this.lit;
                num9--;
                this.mode = 0;
                goto Label_0051;

            case 7:
                if (bitk > 7)
                {
                    bitk -= 8;
                    num7++;
                    num6--;
                }
                s.write = write;
                r       = s.inflate_flush(z, r);
                write   = s.write;
                num9    = (write < s.read) ? ((s.read - write) - 1) : (s.end - write);
                if (s.read != s.write)
                {
                    s.bitb          = number;
                    s.bitk          = bitk;
                    z.avail_in      = num7;
                    z.total_in     += num6 - z.next_in_index;
                    z.next_in_index = num6;
                    s.write         = write;
                    return(s.inflate_flush(z, r));
                }
                this.mode = 8;
                goto Label_098A;

            case 8:
                goto Label_098A;

            case 9:
                r               = -3;
                s.bitb          = number;
                s.bitk          = bitk;
                z.avail_in      = num7;
                z.total_in     += num6 - z.next_in_index;
                z.next_in_index = num6;
                s.write         = write;
                return(s.inflate_flush(z, r));

            default:
                r               = -2;
                s.bitb          = number;
                s.bitk          = bitk;
                z.avail_in      = num7;
                z.total_in     += num6 - z.next_in_index;
                z.next_in_index = num6;
                s.write         = write;
                return(s.inflate_flush(z, r));
            }
            this.need       = this.lbits;
            this.tree       = this.ltree;
            this.tree_index = this.ltree_index;
            this.mode       = 1;
Label_0199:
            num = this.need;
            while (bitk < num)
            {
                if (num7 != 0)
                {
                    r = 0;
                }
                else
                {
                    s.bitb          = number;
                    s.bitk          = bitk;
                    z.avail_in      = num7;
                    z.total_in     += num6 - z.next_in_index;
                    z.next_in_index = num6;
                    s.write         = write;
                    return(s.inflate_flush(z, r));
                }
                num7--;
                number |= (z.next_in[num6++] & 0xff) << bitk;
                bitk   += 8;
            }
            int index = (this.tree_index + (number & inflate_mask[num])) * 3;

            number = SupportClass.URShift(number, 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_0051;
            }
            if ((num3 & 0x10) != 0)
            {
                this.get_Renamed = num3 & 15;
                this.len         = this.tree[index + 2];
                this.mode        = 2;
                goto Label_0051;
            }
            if ((num3 & 0x40) == 0)
            {
                this.need       = num3;
                this.tree_index = (index / 3) + this.tree[index + 2];
                goto Label_0051;
            }
            if ((num3 & 0x20) != 0)
            {
                this.mode = 7;
                goto Label_0051;
            }
            this.mode       = 9;
            z.msg           = "invalid literal/length code";
            r               = -3;
            s.bitb          = number;
            s.bitk          = bitk;
            z.avail_in      = num7;
            z.total_in     += num6 - z.next_in_index;
            z.next_in_index = num6;
            s.write         = write;
            return(s.inflate_flush(z, r));

Label_0412:
            num = this.need;
            while (bitk < num)
            {
                if (num7 != 0)
                {
                    r = 0;
                }
                else
                {
                    s.bitb          = number;
                    s.bitk          = bitk;
                    z.avail_in      = num7;
                    z.total_in     += num6 - z.next_in_index;
                    z.next_in_index = num6;
                    s.write         = write;
                    return(s.inflate_flush(z, r));
                }
                num7--;
                number |= (z.next_in[num6++] & 0xff) << bitk;
                bitk   += 8;
            }
            index  = (this.tree_index + (number & inflate_mask[num])) * 3;
            number = number >> this.tree[index + 1];
            bitk  -= this.tree[index + 1];
            num3   = this.tree[index];
            if ((num3 & 0x10) != 0)
            {
                this.get_Renamed = num3 & 15;
                this.dist        = this.tree[index + 2];
                this.mode        = 4;
                goto Label_0051;
            }
            if ((num3 & 0x40) == 0)
            {
                this.need       = num3;
                this.tree_index = (index / 3) + this.tree[index + 2];
                goto Label_0051;
            }
            this.mode       = 9;
            z.msg           = "invalid distance code";
            r               = -3;
            s.bitb          = number;
            s.bitk          = bitk;
            z.avail_in      = num7;
            z.total_in     += num6 - z.next_in_index;
            z.next_in_index = num6;
            s.write         = write;
            return(s.inflate_flush(z, r));

Label_0635:
            num10 = write - this.dist;
            while (num10 < 0)
            {
                num10 += s.end;
            }
            while (this.len != 0)
            {
                if (num9 == 0)
                {
                    if ((write == s.end) && (s.read != 0))
                    {
                        write = 0;
                        num9  = (write < s.read) ? ((s.read - write) - 1) : (s.end - write);
                    }
                    if (num9 == 0)
                    {
                        s.write = write;
                        r       = s.inflate_flush(z, r);
                        write   = s.write;
                        num9    = (write < s.read) ? ((s.read - write) - 1) : (s.end - write);
                        if ((write == s.end) && (s.read != 0))
                        {
                            write = 0;
                            num9  = (write < s.read) ? ((s.read - write) - 1) : (s.end - write);
                        }
                        if (num9 == 0)
                        {
                            s.bitb          = number;
                            s.bitk          = bitk;
                            z.avail_in      = num7;
                            z.total_in     += num6 - z.next_in_index;
                            z.next_in_index = num6;
                            s.write         = write;
                            return(s.inflate_flush(z, r));
                        }
                    }
                }
                s.window[write++] = s.window[num10++];
                num9--;
                if (num10 == s.end)
                {
                    num10 = 0;
                }
                this.len--;
            }
            this.mode = 0;
            goto Label_0051;
Label_098A:
            r               = 1;
            s.bitb          = number;
            s.bitk          = bitk;
            z.avail_in      = num7;
            z.total_in     += num6 - z.next_in_index;
            z.next_in_index = num6;
            s.write         = write;
            return(s.inflate_flush(z, r));
        }
Пример #9
0
        internal static int huft_build(int[] b, int bindex, int n, int s, int[] d, int[] e, int[] t, int[] m, int[] hp, int[] hn, int[] v)
        {
            int[] numArray    = new int[0x10];
            int[] sourceArray = new int[3];
            int[] numArray3   = new int[15];
            int[] numArray4   = new int[0x10];
            int   index       = 0;
            int   num5        = n;

            do
            {
                numArray[b[bindex + index]]++;
                index++;
                num5--;
            }while(num5 != 0);
            if (numArray[0] == n)
            {
                t[0] = -1;
                m[0] = 0;
                return(0);
            }
            int num8 = m[0];
            int num6 = 1;

            while (num6 <= 15)
            {
                if (numArray[num6] != 0)
                {
                    break;
                }
                num6++;
            }
            int num7 = num6;

            if (num8 < num6)
            {
                num8 = num6;
            }
            num5 = 15;
            while (num5 != 0)
            {
                if (numArray[num5] != 0)
                {
                    break;
                }
                num5--;
            }
            int num3 = num5;

            if (num8 > num5)
            {
                num8 = num5;
            }
            m[0] = num8;
            int num14 = ((int)1) << num6;

            while (num6 < num5)
            {
                num14 -= numArray[num6];
                if (num14 < 0)
                {
                    return(-3);
                }
                num6++;
                num14 = num14 << 1;
            }
            num14 -= numArray[num5];
            if (num14 < 0)
            {
                return(-3);
            }
            numArray[num5] += num14;
            numArray4[1]    = num6 = 0;
            index           = 1;
            int num13 = 2;

            while (--num5 != 0)
            {
                numArray4[num13] = num6 += numArray[index];
                num13++;
                index++;
            }
            num5  = 0;
            index = 0;
            do
            {
                num6 = b[bindex + index];
                if (num6 != 0)
                {
                    v[numArray4[num6]++] = num5;
                }
                index++;
            }while(++num5 < n);
            n            = numArray4[num3];
            numArray4[0] = num5 = 0;
            index        = 0;
            int num4 = -1;
            int bits = -num8;

            numArray3[0] = 0;
            int num11 = 0;
            int num15 = 0;

            while (num7 <= num3)
            {
                int num2;
                int num = numArray[num7];
                goto Label_03BD;
Label_01B2:
                num4++;
                bits += num8;
                num15 = num3 - bits;
                num15 = (num15 > num8) ? num8 : num15;
                if ((num2 = ((int)1) << (num6 = num7 - bits)) > (num + 1))
                {
                    num2 -= num + 1;
                    num13 = num7;
                    if (num6 < num15)
                    {
                        while (++num6 < num15)
                        {
                            if ((num2 = num2 << 1) <= numArray[++num13])
                            {
                                break;
                            }
                            num2 -= numArray[num13];
                        }
                    }
                }
                num15 = ((int)1) << num6;
                if ((hn[0] + num15) > 0x5a0)
                {
                    return(-3);
                }
                numArray3[num4] = num11 = hn[0];
                hn[0]          += num15;
                if (num4 != 0)
                {
                    numArray4[num4] = num5;
                    sourceArray[0]  = (byte)num6;
                    sourceArray[1]  = (byte)num8;
                    num6            = SupportClass.URShift(num5, (int)(bits - num8));
                    sourceArray[2]  = (num11 - numArray3[num4 - 1]) - num6;
                    Array.Copy(sourceArray, 0, hp, (numArray3[num4 - 1] + num6) * 3, 3);
                }
                else
                {
                    t[0] = num11;
                }
Label_02AE:
                if (num7 > (bits + num8))
                {
                    goto Label_01B2;
                }
                sourceArray[1] = (byte)(num7 - bits);
                if (index >= n)
                {
                    sourceArray[0] = 0xc0;
                }
                else if (v[index] < s)
                {
                    sourceArray[0] = (v[index] < 0x100) ? ((byte)0) : ((byte)0x60);
                    sourceArray[2] = v[index++];
                }
                else
                {
                    sourceArray[0] = (byte)((e[v[index] - s] + 0x10) + 0x40);
                    sourceArray[2] = d[v[index++] - s];
                }
                num2 = ((int)1) << (num7 - bits);
                num6 = SupportClass.URShift(num5, bits);
                while (num6 < num15)
                {
                    Array.Copy(sourceArray, 0, hp, (num11 + num6) * 3, 3);
                    num6 += num2;
                }
                num6 = ((int)1) << (num7 - 1);
                while ((num5 & num6) != 0)
                {
                    num5 ^= num6;
                    num6  = SupportClass.URShift(num6, 1);
                }
                num5 ^= num6;
                for (int i = (((int)1) << bits) - 1; (num5 & i) != numArray4[num4]; i = (((int)1) << bits) - 1)
                {
                    num4--;
                    bits -= num8;
                }
Label_03BD:
                if (num-- != 0)
                {
                    goto Label_02AE;
                }
                num7++;
            }
            if ((num14 != 0) && (num3 != 1))
            {
                return(-5);
            }
            return(0);
        }
Пример #10
0
        internal int proc(ZStream z, int r)
        {
            int table;
            int sourceIndex = z.next_in_index;
            int num5        = z.avail_in;
            int bitb        = this.bitb;
            int bitk        = this.bitk;
            int write       = this.write;
            int num7        = (write < this.read) ? ((this.read - write) - 1) : (this.end - write);

Label_0047:
            switch (this.mode)
            {
            case 0:
                while (bitk < 3)
                {
                    if (num5 != 0)
                    {
                        r = 0;
                    }
                    else
                    {
                        this.bitb       = bitb;
                        this.bitk       = bitk;
                        z.avail_in      = num5;
                        z.total_in     += sourceIndex - z.next_in_index;
                        z.next_in_index = sourceIndex;
                        this.write      = write;
                        return(this.inflate_flush(z, r));
                    }
                    num5--;
                    bitb |= (z.next_in[sourceIndex++] & 0xff) << bitk;
                    bitk += 8;
                }
                table     = bitb & 7;
                this.last = table & 1;
                switch (SupportClass.URShift(table, 1))
                {
                case 0:
                    bitb      = SupportClass.URShift(bitb, 3);
                    bitk     -= 3;
                    table     = bitk & 7;
                    bitb      = SupportClass.URShift(bitb, table);
                    bitk     -= table;
                    this.mode = 1;
                    goto Label_0047;

                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, z);
                    this.codes = new InfCodes(numArray[0], numArray2[0], numArray3[0], numArray4[0], z);
                    bitb       = SupportClass.URShift(bitb, 3);
                    bitk      -= 3;
                    this.mode  = 6;
                    goto Label_0047;
                }

                case 2:
                    bitb      = SupportClass.URShift(bitb, 3);
                    bitk     -= 3;
                    this.mode = 3;
                    goto Label_0047;

                case 3:
                    bitb            = SupportClass.URShift(bitb, 3);
                    bitk           -= 3;
                    this.mode       = 9;
                    z.msg           = "invalid block type";
                    r               = -3;
                    this.bitb       = bitb;
                    this.bitk       = bitk;
                    z.avail_in      = num5;
                    z.total_in     += sourceIndex - z.next_in_index;
                    z.next_in_index = sourceIndex;
                    this.write      = write;
                    return(this.inflate_flush(z, r));
                }
                goto Label_0047;

            case 1:
                while (bitk < 0x20)
                {
                    if (num5 != 0)
                    {
                        r = 0;
                    }
                    else
                    {
                        this.bitb       = bitb;
                        this.bitk       = bitk;
                        z.avail_in      = num5;
                        z.total_in     += sourceIndex - z.next_in_index;
                        z.next_in_index = sourceIndex;
                        this.write      = write;
                        return(this.inflate_flush(z, r));
                    }
                    num5--;
                    bitb |= (z.next_in[sourceIndex++] & 0xff) << bitk;
                    bitk += 8;
                }
                if ((SupportClass.URShift(~bitb, 0x10) & 0xffff) != (bitb & 0xffff))
                {
                    this.mode       = 9;
                    z.msg           = "invalid stored block lengths";
                    r               = -3;
                    this.bitb       = bitb;
                    this.bitk       = bitk;
                    z.avail_in      = num5;
                    z.total_in     += sourceIndex - z.next_in_index;
                    z.next_in_index = sourceIndex;
                    this.write      = write;
                    return(this.inflate_flush(z, r));
                }
                this.left = bitb & 0xffff;
                bitb      = bitk = 0;
                this.mode = (this.left != 0) ? 2 : ((this.last != 0) ? 7 : 0);
                goto Label_0047;

            case 2:
                if (num5 != 0)
                {
                    if (num7 == 0)
                    {
                        if ((write == this.end) && (this.read != 0))
                        {
                            write = 0;
                            num7  = (write < this.read) ? ((this.read - write) - 1) : (this.end - write);
                        }
                        if (num7 == 0)
                        {
                            this.write = write;
                            r          = this.inflate_flush(z, r);
                            write      = this.write;
                            num7       = (write < this.read) ? ((this.read - write) - 1) : (this.end - write);
                            if ((write == this.end) && (this.read != 0))
                            {
                                write = 0;
                                num7  = (write < this.read) ? ((this.read - write) - 1) : (this.end - write);
                            }
                            if (num7 == 0)
                            {
                                this.bitb       = bitb;
                                this.bitk       = bitk;
                                z.avail_in      = num5;
                                z.total_in     += sourceIndex - z.next_in_index;
                                z.next_in_index = sourceIndex;
                                this.write      = write;
                                return(this.inflate_flush(z, r));
                            }
                        }
                    }
                    r     = 0;
                    table = this.left;
                    if (table > num5)
                    {
                        table = num5;
                    }
                    if (table > num7)
                    {
                        table = num7;
                    }
                    Array.Copy(z.next_in, sourceIndex, this.window, write, table);
                    sourceIndex += table;
                    num5        -= table;
                    write       += table;
                    num7        -= table;
                    this.left   -= table;
                    if (this.left == 0)
                    {
                        this.mode = (this.last != 0) ? 7 : 0;
                    }
                    goto Label_0047;
                }
                this.bitb       = bitb;
                this.bitk       = bitk;
                z.avail_in      = num5;
                z.total_in     += sourceIndex - z.next_in_index;
                z.next_in_index = sourceIndex;
                this.write      = write;
                return(this.inflate_flush(z, r));

            case 3:
                while (bitk < 14)
                {
                    if (num5 != 0)
                    {
                        r = 0;
                    }
                    else
                    {
                        this.bitb       = bitb;
                        this.bitk       = bitk;
                        z.avail_in      = num5;
                        z.total_in     += sourceIndex - z.next_in_index;
                        z.next_in_index = sourceIndex;
                        this.write      = write;
                        return(this.inflate_flush(z, r));
                    }
                    num5--;
                    bitb |= (z.next_in[sourceIndex++] & 0xff) << bitk;
                    bitk += 8;
                }
                this.table = table = bitb & 0x3fff;
                if (((table & 0x1f) > 0x1d) || (((table >> 5) & 0x1f) > 0x1d))
                {
                    this.mode       = 9;
                    z.msg           = "too many length or distance symbols";
                    r               = -3;
                    this.bitb       = bitb;
                    this.bitk       = bitk;
                    z.avail_in      = num5;
                    z.total_in     += sourceIndex - z.next_in_index;
                    z.next_in_index = sourceIndex;
                    this.write      = write;
                    return(this.inflate_flush(z, r));
                }
                table      = (0x102 + (table & 0x1f)) + ((table >> 5) & 0x1f);
                this.blens = new int[table];
                bitb       = SupportClass.URShift(bitb, 14);
                bitk      -= 14;
                this.index = 0;
                this.mode  = 4;
                break;

            case 4:
                break;

            case 5:
                goto Label_07B9;

            case 6:
                goto Label_0B63;

            case 7:
                goto Label_0C2C;

            case 8:
                goto Label_0CC1;

            case 9:
                r               = -3;
                this.bitb       = bitb;
                this.bitk       = bitk;
                z.avail_in      = num5;
                z.total_in     += sourceIndex - z.next_in_index;
                z.next_in_index = sourceIndex;
                this.write      = write;
                return(this.inflate_flush(z, r));

            default:
                r               = -2;
                this.bitb       = bitb;
                this.bitk       = bitk;
                z.avail_in      = num5;
                z.total_in     += sourceIndex - z.next_in_index;
                z.next_in_index = sourceIndex;
                this.write      = write;
                return(this.inflate_flush(z, r));
            }
            while (this.index < (4 + SupportClass.URShift(this.table, 10)))
            {
                while (bitk < 3)
                {
                    if (num5 != 0)
                    {
                        r = 0;
                    }
                    else
                    {
                        this.bitb       = bitb;
                        this.bitk       = bitk;
                        z.avail_in      = num5;
                        z.total_in     += sourceIndex - z.next_in_index;
                        z.next_in_index = sourceIndex;
                        this.write      = write;
                        return(this.inflate_flush(z, r));
                    }
                    num5--;
                    bitb |= (z.next_in[sourceIndex++] & 0xff) << bitk;
                    bitk += 8;
                }
                this.blens[border[this.index++]] = bitb & 7;
                bitb  = SupportClass.URShift(bitb, 3);
                bitk -= 3;
            }
            while (this.index < 0x13)
            {
                this.blens[border[this.index++]] = 0;
            }
            this.bb[0] = 7;
            table      = InfTree.inflate_trees_bits(this.blens, this.bb, this.tb, this.hufts, z);
            if (table != 0)
            {
                r = table;
                if (r == -3)
                {
                    this.blens = null;
                    this.mode  = 9;
                }
                this.bitb       = bitb;
                this.bitk       = bitk;
                z.avail_in      = num5;
                z.total_in     += sourceIndex - z.next_in_index;
                z.next_in_index = sourceIndex;
                this.write      = write;
                return(this.inflate_flush(z, r));
            }
            this.index = 0;
            this.mode  = 5;
Label_07B9:
            table = this.table;
            if (this.index < ((0x102 + (table & 0x1f)) + ((table >> 5) & 0x1f)))
            {
                table = this.bb[0];
                while (bitk < table)
                {
                    if (num5 != 0)
                    {
                        r = 0;
                    }
                    else
                    {
                        this.bitb       = bitb;
                        this.bitk       = bitk;
                        z.avail_in      = num5;
                        z.total_in     += sourceIndex - z.next_in_index;
                        z.next_in_index = sourceIndex;
                        this.write      = write;
                        return(this.inflate_flush(z, r));
                    }
                    num5--;
                    bitb |= (z.next_in[sourceIndex++] & 0xff) << bitk;
                    bitk += 8;
                }
                int num1 = this.tb[0];
                table = this.hufts[((this.tb[0] + (bitb & inflate_mask[table])) * 3) + 1];
                int num10 = this.hufts[((this.tb[0] + (bitb & inflate_mask[table])) * 3) + 2];
                if (num10 < 0x10)
                {
                    bitb  = SupportClass.URShift(bitb, table);
                    bitk -= table;
                    this.blens[this.index++] = num10;
                }
                else
                {
                    int index = (num10 == 0x12) ? 7 : (num10 - 14);
                    int num9  = (num10 == 0x12) ? 11 : 3;
                    while (bitk < (table + index))
                    {
                        if (num5 != 0)
                        {
                            r = 0;
                        }
                        else
                        {
                            this.bitb       = bitb;
                            this.bitk       = bitk;
                            z.avail_in      = num5;
                            z.total_in     += sourceIndex - z.next_in_index;
                            z.next_in_index = sourceIndex;
                            this.write      = write;
                            return(this.inflate_flush(z, r));
                        }
                        num5--;
                        bitb |= (z.next_in[sourceIndex++] & 0xff) << bitk;
                        bitk += 8;
                    }
                    bitb  = SupportClass.URShift(bitb, table);
                    bitk -= table;
                    num9 += bitb & inflate_mask[index];
                    bitb  = SupportClass.URShift(bitb, index);
                    bitk -= index;
                    index = this.index;
                    table = this.table;
                    if (((index + num9) > ((0x102 + (table & 0x1f)) + ((table >> 5) & 0x1f))) || ((num10 == 0x10) && (index < 1)))
                    {
                        this.blens      = null;
                        this.mode       = 9;
                        z.msg           = "invalid bit length repeat";
                        r               = -3;
                        this.bitb       = bitb;
                        this.bitk       = bitk;
                        z.avail_in      = num5;
                        z.total_in     += sourceIndex - z.next_in_index;
                        z.next_in_index = sourceIndex;
                        this.write      = write;
                        return(this.inflate_flush(z, r));
                    }
                    num10 = (num10 == 0x10) ? this.blens[index - 1] : 0;
                    do
                    {
                        this.blens[index++] = num10;
                    }while(--num9 != 0);
                    this.index = index;
                }
                goto Label_07B9;
            }
            this.tb[0] = -1;
            int[] bl = new int[1];
            int[] bd = new int[1];
            int[] tl = new int[1];
            int[] td = new int[1];
            bl[0] = 9;
            bd[0] = 6;
            table = this.table;
            table = InfTree.inflate_trees_dynamic(0x101 + (table & 0x1f), 1 + ((table >> 5) & 0x1f), this.blens, bl, bd, tl, td, this.hufts, z);
            switch (table)
            {
            case 0:
                this.codes = new InfCodes(bl[0], bd[0], this.hufts, tl[0], this.hufts, td[0], z);
                this.blens = null;
                this.mode  = 6;
                goto Label_0B63;

            case -3:
                this.blens = null;
                this.mode  = 9;
                break;
            }
            r               = table;
            this.bitb       = bitb;
            this.bitk       = bitk;
            z.avail_in      = num5;
            z.total_in     += sourceIndex - z.next_in_index;
            z.next_in_index = sourceIndex;
            this.write      = write;
            return(this.inflate_flush(z, r));

Label_0B63:
            this.bitb       = bitb;
            this.bitk       = bitk;
            z.avail_in      = num5;
            z.total_in     += sourceIndex - z.next_in_index;
            z.next_in_index = sourceIndex;
            this.write      = write;
            if ((r = this.codes.proc(this, z, r)) != 1)
            {
                return(this.inflate_flush(z, r));
            }
            r = 0;
            this.codes.free(z);
            sourceIndex = z.next_in_index;
            num5        = z.avail_in;
            bitb        = this.bitb;
            bitk        = this.bitk;
            write       = this.write;
            num7        = (write < this.read) ? ((this.read - write) - 1) : (this.end - write);
            if (this.last == 0)
            {
                this.mode = 0;
                goto Label_0047;
            }
            this.mode = 7;
Label_0C2C:
            this.write = write;
            r          = this.inflate_flush(z, r);
            write      = this.write;
            num7       = (write < this.read) ? ((this.read - write) - 1) : (this.end - write);
            if (this.read != this.write)
            {
                this.bitb       = bitb;
                this.bitk       = bitk;
                z.avail_in      = num5;
                z.total_in     += sourceIndex - z.next_in_index;
                z.next_in_index = sourceIndex;
                this.write      = write;
                return(this.inflate_flush(z, r));
            }
            this.mode = 8;
Label_0CC1:
            r               = 1;
            this.bitb       = bitb;
            this.bitk       = bitk;
            z.avail_in      = num5;
            z.total_in     += sourceIndex - z.next_in_index;
            z.next_in_index = sourceIndex;
            this.write      = write;
            return(this.inflate_flush(z, r));
        }