Esempio n. 1
0
        internal static int inflate_trees_dynamic(int nl, int nd, int[] c, int[] bl, int[] bd, int[] tl, int[] td, int[] hp, ZStream z)
        {
            int[] hn  = new int[1];
            int[] v   = new int[288];
            int   num = InfTree.huft_build(c, 0, nl, 257, InfTree.cplens, InfTree.cplext, tl, bl, hp, hn, v);

            if (num != 0 || bl[0] == 0)
            {
                if (num == -3)
                {
                    z.msg = "oversubscribed literal/length tree";
                }
                else
                {
                    if (num != -4)
                    {
                        z.msg = "incomplete literal/length tree";
                        num   = -3;
                    }
                }
                return(num);
            }
            num = InfTree.huft_build(c, nl, nd, 0, InfTree.cpdist, InfTree.cpdext, td, bd, hp, hn, v);
            if (num != 0 || (bd[0] == 0 && nl > 257))
            {
                if (num == -3)
                {
                    z.msg = "oversubscribed distance tree";
                }
                else
                {
                    if (num == -5)
                    {
                        z.msg = "incomplete distance tree";
                        num   = -3;
                    }
                    else
                    {
                        if (num != -4)
                        {
                            z.msg = "empty distance tree with lengths";
                            num   = -3;
                        }
                    }
                }
                return(num);
            }
            return(0);
        }
Esempio n. 2
0
        internal static int inflate_trees_bits(int[] c, int[] bb, int[] tb, int[] hp, ZStream z)
        {
            int[] hn  = new int[1];
            int[] v   = new int[19];
            int   num = InfTree.huft_build(c, 0, 19, 19, null, null, tb, bb, hp, hn, v);

            if (num == -3)
            {
                z.msg = "oversubscribed dynamic bit lengths tree";
            }
            else if (num == -5 || bb[0] == 0)
            {
                z.msg = "incomplete dynamic bit lengths tree";
                num   = -3;
            }
            return(num);
        }
Esempio n. 3
0
        internal static int inflate_trees_bits(int[] c, int[] bb, int[] tb, int[] hp, ZStream z)
        {
            int[] numArray1 = new int[1];
            int[] numArray2 = new int[0x13];
            int   num1      = InfTree.huft_build(c, 0, 0x13, 0x13, null, null, tb, bb, hp, numArray1, numArray2);

            if (num1 == -3)
            {
                z.msg = "oversubscribed dynamic bit lengths tree";
                return(num1);
            }
            if ((num1 != -5) && (bb[0] != 0))
            {
                return(num1);
            }
            z.msg = "incomplete dynamic bit lengths tree";
            return(-3);
        }
Esempio n. 4
0
        internal static int inflate_trees_dynamic(int nl, int nd, int[] c, int[] bl, int[] bd, int[] tl, int[] td, int[] hp, ZStream z)
        {
            int[] numArray1 = new int[1];
            int[] numArray2 = new int[0x120];
            int   num1      = InfTree.huft_build(c, 0, nl, 0x101, InfTree.cplens, InfTree.cplext, tl, bl, hp, numArray1, numArray2);

            if ((num1 != 0) || (bl[0] == 0))
            {
                if (num1 == -3)
                {
                    z.msg = "oversubscribed literal/length tree";
                    return(num1);
                }
                if (num1 != -4)
                {
                    z.msg = "incomplete literal/length tree";
                    num1  = -3;
                }
                return(num1);
            }
            num1 = InfTree.huft_build(c, nl, nd, 0, InfTree.cpdist, InfTree.cpdext, td, bd, hp, numArray1, numArray2);
            if ((num1 == 0) && ((bd[0] != 0) || (nl <= 0x101)))
            {
                return(0);
            }
            if (num1 == -3)
            {
                z.msg = "oversubscribed distance tree";
                return(num1);
            }
            if (num1 == -5)
            {
                z.msg = "incomplete distance tree";
                return(-3);
            }
            if (num1 != -4)
            {
                z.msg = "empty distance tree with lengths";
                num1  = -3;
            }
            return(num1);
        }
Esempio n. 5
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;
                    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, z);
                    this.codes = new InfCodes(numArray[0], numArray2[0], numArray3[0], numArray4[0], z);
                    bitb       = SupportClass.URShift(bitb, 3);
                    bitk      -= 3;
                    this.mode  = 6;
                    break;
                }

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

                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));
        }
Esempio n. 6
0
        internal int proc(ZStream z, int r)
        {
            int t;             // temporary storage
            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

            // copy input/output information to locals (UPDATE macro restores)
            {
                p = z.next_in_index; n = z.avail_in; b = bitb; k = bitk;
            }
            {
                q = write; m = (int)(q < read?read - q - 1:end - q);
            }

            // process input based on current state
            while (true)
            {
                switch (mode)
                {
                case TYPE:

                    while (k < (3))
                    {
                        if (n != 0)
                        {
                            r = Z_OK;
                        }
                        else
                        {
                            bitb        = b; bitk = k;
                            z.avail_in  = n;
                            z.total_in += p - z.next_in_index; z.next_in_index = p;
                            write       = q;
                            return(inflate_flush(z, r));
                        }
                        ;
                        n--;
                        b |= (z.next_in[p++] & 0xff) << k;
                        k += 8;
                    }
                    t    = (int)(b & 7);
                    last = t & 1;

                    switch (SupportClass.URShift(t, 1))
                    {
                    case 0:                                      // stored
                    {
                        b = SupportClass.URShift(b, (3)); k -= (3);
                    }
                        t = k & 7;                                         // go to byte boundary

                        {
                            b = SupportClass.URShift(b, (t)); k -= (t);
                        }
                        mode = LENS;                                         // get length of stored block
                        break;

                    case 1:                                      // fixed
                    {
                        int[]   bl = new int[1];
                        int[]   bd = new int[1];
                        int[][] tl = new int[1][];
                        int[][] td = new int[1][];

                        InfTree.inflate_trees_fixed(bl, bd, tl, td, z);
                        codes = new InfCodes(bl[0], bd[0], tl[0], td[0], z);
                    }

                        {
                            b = SupportClass.URShift(b, (3)); k -= (3);
                        }

                        mode = CODES;
                        break;

                    case 2:                                      // dynamic

                    {
                        b = SupportClass.URShift(b, (3)); k -= (3);
                    }

                        mode = TABLE;
                        break;

                    case 3:                                      // illegal

                    {
                        b = SupportClass.URShift(b, (3)); k -= (3);
                    }
                        mode  = BAD;
                        z.msg = "invalid block type";
                        r     = Z_DATA_ERROR;

                        bitb       = b; bitk = k;
                        z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p;
                        write      = q;
                        return(inflate_flush(z, r));
                    }
                    break;

                case LENS:

                    while (k < (32))
                    {
                        if (n != 0)
                        {
                            r = Z_OK;
                        }
                        else
                        {
                            bitb        = b; bitk = k;
                            z.avail_in  = n;
                            z.total_in += p - z.next_in_index; z.next_in_index = p;
                            write       = q;
                            return(inflate_flush(z, r));
                        }
                        ;
                        n--;
                        b |= (z.next_in[p++] & 0xff) << k;
                        k += 8;
                    }

                    if (((SupportClass.URShift((~b), 16)) & 0xffff) != (b & 0xffff))
                    {
                        mode  = BAD;
                        z.msg = "invalid stored block lengths";
                        r     = Z_DATA_ERROR;

                        bitb       = b; bitk = k;
                        z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p;
                        write      = q;
                        return(inflate_flush(z, r));
                    }
                    left = (b & 0xffff);
                    b    = k = 0;                          // dump bits
                    mode = left != 0?STORED:(last != 0?DRY:TYPE);
                    break;

                case STORED:
                    if (n == 0)
                    {
                        bitb       = b; bitk = k;
                        z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p;
                        write      = q;
                        return(inflate_flush(z, r));
                    }

                    if (m == 0)
                    {
                        if (q == end && read != 0)
                        {
                            q = 0; m = (int)(q < read?read - q - 1:end - q);
                        }
                        if (m == 0)
                        {
                            write = q;
                            r     = inflate_flush(z, r);
                            q     = write; m = (int)(q < read?read - q - 1:end - q);
                            if (q == end && read != 0)
                            {
                                q = 0; m = (int)(q < read?read - q - 1:end - q);
                            }
                            if (m == 0)
                            {
                                bitb       = b; bitk = k;
                                z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p;
                                write      = q;
                                return(inflate_flush(z, r));
                            }
                        }
                    }
                    r = Z_OK;

                    t = left;
                    if (t > n)
                    {
                        t = n;
                    }
                    if (t > m)
                    {
                        t = m;
                    }
                    Array.Copy(z.next_in, p, window, q, t);
                    p += t; n -= t;
                    q += t; m -= t;
                    if ((left -= t) != 0)
                    {
                        break;
                    }
                    mode = last != 0?DRY:TYPE;
                    break;

                case TABLE:

                    while (k < (14))
                    {
                        if (n != 0)
                        {
                            r = Z_OK;
                        }
                        else
                        {
                            bitb        = b; bitk = k;
                            z.avail_in  = n;
                            z.total_in += p - z.next_in_index; z.next_in_index = p;
                            write       = q;
                            return(inflate_flush(z, r));
                        }
                        ;
                        n--;
                        b |= (z.next_in[p++] & 0xff) << k;
                        k += 8;
                    }

                    table = t = (b & 0x3fff);
                    if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29)
                    {
                        mode  = BAD;
                        z.msg = "too many length or distance symbols";
                        r     = Z_DATA_ERROR;

                        bitb       = b; bitk = k;
                        z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p;
                        write      = q;
                        return(inflate_flush(z, r));
                    }
                    t     = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
                    blens = new int[t];

                    {
                        b = SupportClass.URShift(b, (14)); k -= (14);
                    }

                    index = 0;
                    mode  = BTREE;
                    goto case BTREE;

                case BTREE:
                    while (index < 4 + (SupportClass.URShift(table, 10)))
                    {
                        while (k < (3))
                        {
                            if (n != 0)
                            {
                                r = Z_OK;
                            }
                            else
                            {
                                bitb        = b; bitk = k;
                                z.avail_in  = n;
                                z.total_in += p - z.next_in_index; z.next_in_index = p;
                                write       = q;
                                return(inflate_flush(z, r));
                            }
                            ;
                            n--;
                            b |= (z.next_in[p++] & 0xff) << k;
                            k += 8;
                        }

                        blens[border[index++]] = b & 7;

                        {
                            b = SupportClass.URShift(b, (3)); k -= (3);
                        }
                    }

                    while (index < 19)
                    {
                        blens[border[index++]] = 0;
                    }

                    bb[0] = 7;
                    t     = InfTree.inflate_trees_bits(blens, bb, tb, hufts, z);
                    if (t != Z_OK)
                    {
                        r = t;
                        if (r == Z_DATA_ERROR)
                        {
                            blens = null;
                            mode  = BAD;
                        }

                        bitb       = b; bitk = k;
                        z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p;
                        write      = q;
                        return(inflate_flush(z, r));
                    }

                    index = 0;
                    mode  = DTREE;
                    goto case DTREE;

                case DTREE:
                    while (true)
                    {
                        t = table;
                        if (!(index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f)))
                        {
                            break;
                        }


                        int i, j, c;

                        t = bb[0];

                        while (k < (t))
                        {
                            if (n != 0)
                            {
                                r = Z_OK;
                            }
                            else
                            {
                                bitb        = b; bitk = k;
                                z.avail_in  = n;
                                z.total_in += p - z.next_in_index; z.next_in_index = p;
                                write       = q;
                                return(inflate_flush(z, r));
                            }
                            ;
                            n--;
                            b |= (z.next_in[p++] & 0xff) << k;
                            k += 8;
                        }

                        if (tb[0] == -1)
                        {
                            //System.err.println("null...");
                        }

                        t = hufts[(tb[0] + (b & inflate_mask[t])) * 3 + 1];
                        c = hufts[(tb[0] + (b & inflate_mask[t])) * 3 + 2];

                        if (c < 16)
                        {
                            b = SupportClass.URShift(b, (t)); k -= (t);
                            blens[index++] = c;
                        }
                        else
                        {
                            // c == 16..18
                            i = c == 18?7:c - 14;
                            j = c == 18?11:3;

                            while (k < (t + i))
                            {
                                if (n != 0)
                                {
                                    r = Z_OK;
                                }
                                else
                                {
                                    bitb        = b; bitk = k;
                                    z.avail_in  = n;
                                    z.total_in += p - z.next_in_index; z.next_in_index = p;
                                    write       = q;
                                    return(inflate_flush(z, r));
                                }
                                ;
                                n--;
                                b |= (z.next_in[p++] & 0xff) << k;
                                k += 8;
                            }

                            b = SupportClass.URShift(b, (t)); k -= (t);

                            j += (b & inflate_mask[i]);

                            b = SupportClass.URShift(b, (i)); k -= (i);

                            i = index;
                            t = table;
                            if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) || (c == 16 && i < 1))
                            {
                                blens = null;
                                mode  = BAD;
                                z.msg = "invalid bit length repeat";
                                r     = Z_DATA_ERROR;

                                bitb       = b; bitk = k;
                                z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p;
                                write      = q;
                                return(inflate_flush(z, r));
                            }

                            c = c == 16?blens[i - 1]:0;
                            do
                            {
                                blens[i++] = c;
                            }while (--j != 0);
                            index = i;
                        }
                    }

                    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;                                 // must be <= 9 for lookahead assumptions
                        bd[0] = 6;                                 // must be <= 9 for lookahead assumptions
                        t     = table;
                        t     = InfTree.inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f), blens, bl, bd, tl, td, hufts, z);
                        if (t != Z_OK)
                        {
                            if (t == Z_DATA_ERROR)
                            {
                                blens = null;
                                mode  = BAD;
                            }
                            r = t;

                            bitb       = b; bitk = k;
                            z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p;
                            write      = q;
                            return(inflate_flush(z, r));
                        }

                        codes = new InfCodes(bl[0], bd[0], hufts, tl[0], hufts, td[0], z);
                    }
                    blens = null;
                    mode  = CODES;
                    goto case CODES;

                case CODES:
                    bitb       = b; bitk = k;
                    z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p;
                    write      = q;

                    if ((r = codes.proc(this, z, r)) != Z_STREAM_END)
                    {
                        return(inflate_flush(z, r));
                    }
                    r = Z_OK;
                    codes.free(z);

                    p = z.next_in_index; n = z.avail_in; b = bitb; k = bitk;
                    q = write; m = (int)(q < read?read - q - 1:end - q);

                    if (last == 0)
                    {
                        mode = TYPE;
                        break;
                    }
                    mode = DRY;
                    goto case DRY;

                case DRY:
                    write = q;
                    r     = inflate_flush(z, r);
                    q     = write; m = (int)(q < read?read - q - 1:end - q);
                    if (read != write)
                    {
                        bitb       = b; bitk = k;
                        z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p;
                        write      = q;
                        return(inflate_flush(z, r));
                    }
                    mode = DONE;
                    goto case DONE;

                case DONE:
                    r = Z_STREAM_END;

                    bitb       = b; bitk = k;
                    z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p;
                    write      = q;
                    return(inflate_flush(z, r));

                case BAD:
                    r = Z_DATA_ERROR;

                    bitb       = b; bitk = k;
                    z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p;
                    write      = q;
                    return(inflate_flush(z, r));


                default:
                    r = Z_STREAM_ERROR;

                    bitb       = b; bitk = k;
                    z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p;
                    write      = q;
                    return(inflate_flush(z, r));
                }
            }
        }
Esempio n. 7
0
        internal int proc(ZStream z, int r)
        {
            int num  = z.next_in_index;
            int num2 = z.avail_in;
            int num3 = this.bitb;
            int i    = this.bitk;
            int num4 = this.write;
            int num5 = (num4 < this.read) ? (this.read - num4 - 1) : (this.end - num4);
            int num6;

            while (true)
            {
                switch (this.mode)
                {
                case 0:
                    while (i < 3)
                    {
                        if (num2 == 0)
                        {
                            goto IL_8C;
                        }
                        r = 0;
                        num2--;
                        num3 |= (int)(z.next_in[num++] & 255) << i;
                        i    += 8;
                    }
                    num6      = (num3 & 7);
                    this.last = (num6 & 1);
                    switch (SupportClass.URShift(num6, 1))
                    {
                    case 0:
                        num3      = SupportClass.URShift(num3, 3);
                        i        -= 3;
                        num6      = (i & 7);
                        num3      = SupportClass.URShift(num3, num6);
                        i        -= num6;
                        this.mode = 1;
                        continue;

                    case 1:
                    {
                        int[]   array  = new int[1];
                        int[]   array2 = new int[1];
                        int[][] array3 = new int[1][];
                        int[][] array4 = new int[1][];
                        InfTree.inflate_trees_fixed(array, array2, array3, array4, z);
                        this.codes = new InfCodes(array[0], array2[0], array3[0], array4[0], z);
                        num3       = SupportClass.URShift(num3, 3);
                        i         -= 3;
                        this.mode  = 6;
                        continue;
                    }

                    case 2:
                        num3      = SupportClass.URShift(num3, 3);
                        i        -= 3;
                        this.mode = 3;
                        continue;

                    case 3:
                        goto IL_1CD;

                    default:
                        continue;
                    }
                    break;

                case 1:
                    while (i < 32)
                    {
                        if (num2 == 0)
                        {
                            goto IL_23D;
                        }
                        r = 0;
                        num2--;
                        num3 |= (int)(z.next_in[num++] & 255) << i;
                        i    += 8;
                    }
                    if ((SupportClass.URShift(~num3, 16) & 65535) != (num3 & 65535))
                    {
                        goto Block_8;
                    }
                    this.left = (num3 & 65535);
                    i         = (num3 = 0);
                    this.mode = ((this.left != 0) ? 2 : ((this.last != 0) ? 7 : 0));
                    continue;

                case 2:
                    if (num2 == 0)
                    {
                        goto Block_11;
                    }
                    if (num5 == 0)
                    {
                        if (num4 == this.end && this.read != 0)
                        {
                            num4 = 0;
                            num5 = ((num4 < this.read) ? (this.read - num4 - 1) : (this.end - num4));
                        }
                        if (num5 == 0)
                        {
                            this.write = num4;
                            r          = this.inflate_flush(z, r);
                            num4       = this.write;
                            num5       = ((num4 < this.read) ? (this.read - num4 - 1) : (this.end - num4));
                            if (num4 == this.end && this.read != 0)
                            {
                                num4 = 0;
                                num5 = ((num4 < this.read) ? (this.read - num4 - 1) : (this.end - num4));
                            }
                            if (num5 == 0)
                            {
                                goto Block_21;
                            }
                        }
                    }
                    r    = 0;
                    num6 = this.left;
                    if (num6 > num2)
                    {
                        num6 = num2;
                    }
                    if (num6 > num5)
                    {
                        num6 = num5;
                    }
                    Array.Copy(z.next_in, num, this.window, num4, num6);
                    num  += num6;
                    num2 -= num6;
                    num4 += num6;
                    num5 -= num6;
                    if ((this.left -= num6) == 0)
                    {
                        this.mode = ((this.last != 0) ? 7 : 0);
                        continue;
                    }
                    continue;

                case 3:
                    while (i < 14)
                    {
                        if (num2 == 0)
                        {
                            goto IL_515;
                        }
                        r = 0;
                        num2--;
                        num3 |= (int)(z.next_in[num++] & 255) << i;
                        i    += 8;
                    }
                    num6 = (this.table = (num3 & 16383));
                    if ((num6 & 31) > 29 || (num6 >> 5 & 31) > 29)
                    {
                        goto IL_5A3;
                    }
                    num6       = 258 + (num6 & 31) + (num6 >> 5 & 31);
                    this.blens = new int[num6];
                    num3       = SupportClass.URShift(num3, 14);
                    i         -= 14;
                    this.index = 0;
                    this.mode  = 4;
                    goto IL_6E2;

                case 4:
                    goto IL_6E2;

                case 5:
                    goto IL_7BB;

                case 6:
                    goto IL_B66;

                case 7:
                    goto IL_C2F;

                case 8:
                    goto IL_CC4;

                case 9:
                    goto IL_D0B;
                }
                break;
IL_6E2:
                while (this.index < 4 + SupportClass.URShift(this.table, 10))
                {
                    while (i < 3)
                    {
                        if (num2 == 0)
                        {
                            goto IL_646;
                        }
                        r = 0;
                        num2--;
                        num3 |= (int)(z.next_in[num++] & 255) << i;
                        i    += 8;
                    }
                    int[] arg_6D5_0 = this.blens;
                    int[] arg_6D1_0 = InfBlocks.border;
                    int   num7      = this.index;
                    this.index = num7 + 1;
                    arg_6D5_0[arg_6D1_0[num7]] = (num3 & 7);
                    num3 = SupportClass.URShift(num3, 3);
                    i   -= 3;
                }
                while (this.index < 19)
                {
                    int[] arg_71C_0 = this.blens;
                    int[] arg_71A_0 = InfBlocks.border;
                    int   num7      = this.index;
                    this.index = num7 + 1;
                    arg_71C_0[arg_71A_0[num7]] = 0;
                }
                this.bb[0] = 7;
                num6       = InfTree.inflate_trees_bits(this.blens, this.bb, this.tb, this.hufts, z);
                if (num6 != 0)
                {
                    goto Block_33;
                }
                this.index = 0;
                this.mode  = 5;
IL_7BB:
                while (true)
                {
                    num6 = this.table;
                    if (this.index >= 258 + (num6 & 31) + (num6 >> 5 & 31))
                    {
                        break;
                    }
                    num6 = this.bb[0];
                    while (i < num6)
                    {
                        if (num2 == 0)
                        {
                            goto IL_7F2;
                        }
                        r = 0;
                        num2--;
                        num3 |= (int)(z.next_in[num++] & 255) << i;
                        i    += 8;
                    }
                    int arg_868_0 = this.tb[0];
                    num6 = this.hufts[(this.tb[0] + (num3 & InfBlocks.inflate_mask[num6])) * 3 + 1];
                    int num8 = this.hufts[(this.tb[0] + (num3 & InfBlocks.inflate_mask[num6])) * 3 + 2];
                    if (num8 < 16)
                    {
                        num3 = SupportClass.URShift(num3, num6);
                        i   -= num6;
                        int[] arg_8D4_0 = this.blens;
                        int   num7      = this.index;
                        this.index      = num7 + 1;
                        arg_8D4_0[num7] = num8;
                    }
                    else
                    {
                        int num9  = (num8 == 18) ? 7 : (num8 - 14);
                        int num10 = (num8 == 18) ? 11 : 3;
                        while (i < num6 + num9)
                        {
                            if (num2 == 0)
                            {
                                goto IL_902;
                            }
                            r = 0;
                            num2--;
                            num3 |= (int)(z.next_in[num++] & 255) << i;
                            i    += 8;
                        }
                        num3   = SupportClass.URShift(num3, num6);
                        i     -= num6;
                        num10 += (num3 & InfBlocks.inflate_mask[num9]);
                        num3   = SupportClass.URShift(num3, num9);
                        i     -= num9;
                        num9   = this.index;
                        num6   = this.table;
                        if (num9 + num10 > 258 + (num6 & 31) + (num6 >> 5 & 31) || (num8 == 16 && num9 < 1))
                        {
                            goto IL_9CC;
                        }
                        num8 = ((num8 == 16) ? this.blens[num9 - 1] : 0);
                        do
                        {
                            this.blens[num9++] = num8;
                        }while (--num10 != 0);
                        this.index = num9;
                    }
                }
                this.tb[0] = -1;
                int[] array5 = new int[1];
                int[] array6 = new int[1];
                int[] array7 = new int[1];
                int[] array8 = new int[1];
                array5[0] = 9;
                array6[0] = 6;
                num6      = this.table;
                num6      = InfTree.inflate_trees_dynamic(257 + (num6 & 31), 1 + (num6 >> 5 & 31), this.blens, array5, array6, array7, array8, this.hufts, z);
                if (num6 != 0)
                {
                    goto Block_47;
                }
                this.codes = new InfCodes(array5[0], array6[0], this.hufts, array7[0], this.hufts, array8[0], z);
                this.blens = null;
                this.mode  = 6;
IL_B66:
                this.bitb       = num3;
                this.bitk       = i;
                z.avail_in      = num2;
                z.total_in     += (long)(num - z.next_in_index);
                z.next_in_index = num;
                this.write      = num4;
                if ((r = this.codes.proc(this, z, r)) != 1)
                {
                    goto Block_49;
                }
                r = 0;
                this.codes.free(z);
                num  = z.next_in_index;
                num2 = z.avail_in;
                num3 = this.bitb;
                i    = this.bitk;
                num4 = this.write;
                num5 = ((num4 < this.read) ? (this.read - num4 - 1) : (this.end - num4));
                if (this.last != 0)
                {
                    goto IL_C28;
                }
                this.mode = 0;
            }
            r               = -2;
            this.bitb       = num3;
            this.bitk       = i;
            z.avail_in      = num2;
            z.total_in     += (long)(num - z.next_in_index);
            z.next_in_index = num;
            this.write      = num4;
            return(this.inflate_flush(z, r));

IL_8C:
            this.bitb       = num3;
            this.bitk       = i;
            z.avail_in      = num2;
            z.total_in     += (long)(num - z.next_in_index);
            z.next_in_index = num;
            this.write      = num4;
            return(this.inflate_flush(z, r));

IL_1CD:
            num3            = SupportClass.URShift(num3, 3);
            i              -= 3;
            this.mode       = 9;
            z.msg           = "invalid block type";
            r               = -3;
            this.bitb       = num3;
            this.bitk       = i;
            z.avail_in      = num2;
            z.total_in     += (long)(num - z.next_in_index);
            z.next_in_index = num;
            this.write      = num4;
            return(this.inflate_flush(z, r));

IL_23D:
            this.bitb       = num3;
            this.bitk       = i;
            z.avail_in      = num2;
            z.total_in     += (long)(num - z.next_in_index);
            z.next_in_index = num;
            this.write      = num4;
            return(this.inflate_flush(z, r));

Block_8:
            this.mode       = 9;
            z.msg           = "invalid stored block lengths";
            r               = -3;
            this.bitb       = num3;
            this.bitk       = i;
            z.avail_in      = num2;
            z.total_in     += (long)(num - z.next_in_index);
            z.next_in_index = num;
            this.write      = num4;
            return(this.inflate_flush(z, r));

Block_11:
            this.bitb       = num3;
            this.bitk       = i;
            z.avail_in      = num2;
            z.total_in     += (long)(num - z.next_in_index);
            z.next_in_index = num;
            this.write      = num4;
            return(this.inflate_flush(z, r));

Block_21:
            this.bitb       = num3;
            this.bitk       = i;
            z.avail_in      = num2;
            z.total_in     += (long)(num - z.next_in_index);
            z.next_in_index = num;
            this.write      = num4;
            return(this.inflate_flush(z, r));

IL_515:
            this.bitb       = num3;
            this.bitk       = i;
            z.avail_in      = num2;
            z.total_in     += (long)(num - z.next_in_index);
            z.next_in_index = num;
            this.write      = num4;
            return(this.inflate_flush(z, r));

IL_5A3:
            this.mode       = 9;
            z.msg           = "too many length or distance symbols";
            r               = -3;
            this.bitb       = num3;
            this.bitk       = i;
            z.avail_in      = num2;
            z.total_in     += (long)(num - z.next_in_index);
            z.next_in_index = num;
            this.write      = num4;
            return(this.inflate_flush(z, r));

IL_646:
            this.bitb       = num3;
            this.bitk       = i;
            z.avail_in      = num2;
            z.total_in     += (long)(num - z.next_in_index);
            z.next_in_index = num;
            this.write      = num4;
            return(this.inflate_flush(z, r));

Block_33:
            r = num6;
            if (r == -3)
            {
                this.blens = null;
                this.mode  = 9;
            }
            this.bitb       = num3;
            this.bitk       = i;
            z.avail_in      = num2;
            z.total_in     += (long)(num - z.next_in_index);
            z.next_in_index = num;
            this.write      = num4;
            return(this.inflate_flush(z, r));

IL_7F2:
            this.bitb       = num3;
            this.bitk       = i;
            z.avail_in      = num2;
            z.total_in     += (long)(num - z.next_in_index);
            z.next_in_index = num;
            this.write      = num4;
            return(this.inflate_flush(z, r));

IL_902:
            this.bitb       = num3;
            this.bitk       = i;
            z.avail_in      = num2;
            z.total_in     += (long)(num - z.next_in_index);
            z.next_in_index = num;
            this.write      = num4;
            return(this.inflate_flush(z, r));

IL_9CC:
            this.blens      = null;
            this.mode       = 9;
            z.msg           = "invalid bit length repeat";
            r               = -3;
            this.bitb       = num3;
            this.bitk       = i;
            z.avail_in      = num2;
            z.total_in     += (long)(num - z.next_in_index);
            z.next_in_index = num;
            this.write      = num4;
            return(this.inflate_flush(z, r));

Block_47:
            if (num6 == -3)
            {
                this.blens = null;
                this.mode  = 9;
            }
            r               = num6;
            this.bitb       = num3;
            this.bitk       = i;
            z.avail_in      = num2;
            z.total_in     += (long)(num - z.next_in_index);
            z.next_in_index = num;
            this.write      = num4;
            return(this.inflate_flush(z, r));

Block_49:
            return(this.inflate_flush(z, r));

IL_C28:
            this.mode = 7;
IL_C2F:
            this.write = num4;
            r          = this.inflate_flush(z, r);
            num4       = this.write;
            int arg_C69_0 = (num4 < this.read) ? (this.read - num4 - 1) : (this.end - num4);

            if (this.read != this.write)
            {
                this.bitb       = num3;
                this.bitk       = i;
                z.avail_in      = num2;
                z.total_in     += (long)(num - z.next_in_index);
                z.next_in_index = num;
                this.write      = num4;
                return(this.inflate_flush(z, r));
            }
            this.mode = 8;
IL_CC4:
            r               = 1;
            this.bitb       = num3;
            this.bitk       = i;
            z.avail_in      = num2;
            z.total_in     += (long)(num - z.next_in_index);
            z.next_in_index = num;
            this.write      = num4;
            return(this.inflate_flush(z, r));

IL_D0B:
            r               = -3;
            this.bitb       = num3;
            this.bitk       = i;
            z.avail_in      = num2;
            z.total_in     += (long)(num - z.next_in_index);
            z.next_in_index = num;
            this.write      = num4;
            return(this.inflate_flush(z, r));
        }
Esempio n. 8
0
        // zlib.InfBlocks
        // zlib.InfBlocks
        internal int proc(ZStream z, int r)
        {
            int num  = z.next_in_index;
            int num2 = z.avail_in;
            int num3 = this.bitb;
            int i    = this.bitk;
            int num4 = this.write;
            int num5 = (num4 < this.read) ? (this.read - num4 - 1) : (this.end - num4);
            int num6;

            while (true)
            {
                switch (this.mode)
                {
                case 0:
                    while (i < 3)
                    {
                        if (num2 == 0)
                        {
                            return(procRet(z, i, r, num, num2, num3, num4));
                        }
                        r = 0;
                        num2--;
                        num3 |= (int)(z.next_in[num++] & 255) << i;
                        i    += 8;
                    }
                    num6      = (num3 & 7);
                    this.last = (num6 & 1);
                    switch (SupportClass.URShift(num6, 1))
                    {
                    case 0:
                        num3      = SupportClass.URShift(num3, 3);
                        i        -= 3;
                        num6      = (i & 7);
                        num3      = SupportClass.URShift(num3, num6);
                        i        -= num6;
                        this.mode = 1;
                        continue;

                    case 1:
                    {
                        int[]   array  = new int[1];
                        int[]   array2 = new int[1];
                        int[][] array3 = new int[1][];
                        int[][] array4 = new int[1][];
                        InfTree.inflate_trees_fixed(array, array2, array3, array4, z);
                        this.codes = new InfCodes(array[0], array2[0], array3[0], array4[0], z);
                        num3       = SupportClass.URShift(num3, 3);
                        i         -= 3;
                        this.mode  = 6;
                        continue;
                    }

                    case 2:
                        num3      = SupportClass.URShift(num3, 3);
                        i        -= 3;
                        this.mode = 3;
                        continue;

                    case 3:
                        num3      = SupportClass.URShift(num3, 3);
                        i        -= 3;
                        this.mode = 9;
                        z.msg     = "invalid block type";
                        return(procRet(z, i, -3, num, num2, num3, num4));

                    default:
                        continue;
                    }
                    break;

                case 1:
                {
                    while (i < 32)
                    {
                        if (num2 == 0)
                        {
                            return(procRet(z, i, r, num, num2, num3, num4));
                        }
                        r = 0;
                        num2--;
                        num3 |= (int)(z.next_in[num++] & 255) << i;
                        i    += 8;
                    }
                    if ((SupportClass.URShift(~num3, 16) & 65535) != (num3 & 65535))
                    {
                        this.mode = 9;
                        z.msg     = "invalid stored block lengths";
                        return(procRet(z, i, -3, num, num2, num3, num4));
                    }
                    this.left = (num3 & 65535);
                    int arg_686_0 = 0;
                    i         = 0;
                    num3      = arg_686_0;
                    this.mode = ((this.left != 0) ? 2 : ((this.last != 0) ? 7 : 0));
                    continue;
                }

                case 2:
                    if (num2 == 0)
                    {
                        return(procRet(z, i, r, num, num2, num3, num4));
                    }
                    if (num5 == 0)
                    {
                        if (num4 == this.end && this.read != 0)
                        {
                            num4 = 0;
                            num5 = ((0 < this.read) ? (this.read - num4 - 1) : (this.end - num4));
                        }
                        if (num5 == 0)
                        {
                            this.write = num4;
                            r          = this.inflate_flush(z, r);
                            num4       = this.write;
                            num5       = ((num4 < this.read) ? (this.read - num4 - 1) : (this.end - num4));
                            if (num4 == this.end && this.read != 0)
                            {
                                num4 = 0;
                                num5 = ((0 < this.read) ? (this.read - num4 - 1) : (this.end - num4));
                            }
                            if (num5 == 0)
                            {
                                return(procRet(z, i, r, num, num2, num3, num4));
                            }
                        }
                    }
                    r    = 0;
                    num6 = this.left;
                    if (num6 > num2)
                    {
                        num6 = num2;
                    }
                    if (num6 > num5)
                    {
                        num6 = num5;
                    }
                    Array.Copy(z.next_in, num, this.window, num4, num6);
                    num  += num6;
                    num2 -= num6;
                    num4 += num6;
                    num5 -= num6;
                    if ((this.left -= num6) == 0)
                    {
                        this.mode = ((this.last != 0) ? 7 : 0);
                        continue;
                    }
                    continue;

                case 3:
                    while (i < 14)
                    {
                        if (num2 == 0)
                        {
                            return(procRet(z, i, r, num, num2, num3, num4));
                        }
                        r = 0;
                        num2--;
                        num3 |= (int)(z.next_in[num++] & 255) << i;
                        i    += 8;
                    }
                    num6 = (this.table = (num3 & 16383));
                    if ((num6 & 31) <= 29 && (num6 >> 5 & 31) <= 29)
                    {
                        num6       = 258 + (num6 & 31) + (num6 >> 5 & 31);
                        this.blens = new int[num6];
                        num3       = SupportClass.URShift(num3, 14);
                        i         -= 14;
                        this.index = 0;
                        this.mode  = 4;
                        goto case 4;
                    }
                    this.mode = 9;
                    z.msg     = "too many length or distance symbols";
                    return(procRet(z, i, -3, num, num2, num3, num4));

                case 4:
                    while (this.index < 4 + SupportClass.URShift(this.table, 10))
                    {
                        while (i < 3)
                        {
                            if (num2 == 0)
                            {
                                return(procRet(z, i, r, num, num2, num3, num4));
                            }
                            r = 0;
                            num2--;
                            num3 |= (int)(z.next_in[num++] & 255) << i;
                            i    += 8;
                        }
                        this.blens[InfBlocks.border[this.index++]] = (num3 & 7);
                        num3 = SupportClass.URShift(num3, 3);
                        i   -= 3;
                    }
                    while (this.index < 19)
                    {
                        this.blens[InfBlocks.border[this.index++]] = 0;
                    }
                    this.bb[0] = 7;
                    num6       = InfTree.inflate_trees_bits(this.blens, this.bb, this.tb, this.hufts, z);
                    if (num6 == 0)
                    {
                        this.index = 0;
                        this.mode  = 5;
                        goto case 5;
                    }
                    if (num6 == -3)
                    {
                        this.blens = null;
                        this.mode  = 9;
                    }
                    return(procRet(z, i, num6, num, num2, num3, num4));

                case 5:
                    while (true)
                    {
                        num6 = this.table;
                        if (this.index >= 258 + (num6 & 31) + (num6 >> 5 & 31))
                        {
                            break;
                        }
                        num6 = this.bb[0];
                        while (i < num6)
                        {
                            if (num2 == 0)
                            {
                                return(procRet(z, i, r, num, num2, num3, num4));
                            }
                            r = 0;
                            num2--;
                            num3 |= (int)(z.next_in[num++] & 255) << i;
                            i    += 8;
                        }
                        num6 = this.hufts[(this.tb[0] + (num3 & InfBlocks.inflate_mask[num6])) * 3 + 1];
                        int num7 = this.hufts[(this.tb[0] + (num3 & InfBlocks.inflate_mask[num6])) * 3 + 2];
                        if (num7 < 16)
                        {
                            num3 = SupportClass.URShift(num3, num6);
                            i   -= num6;
                            this.blens[this.index++] = num7;
                        }
                        else
                        {
                            int num8 = (num7 == 18) ? 7 : (num7 - 14);
                            int num9 = (num7 == 18) ? 11 : 3;
                            while (i < num6 + num8)
                            {
                                if (num2 == 0)
                                {
                                    return(procRet(z, i, r, num, num2, num3, num4));
                                }
                                r = 0;
                                num2--;
                                num3 |= (int)(z.next_in[num++] & 255) << i;
                                i    += 8;
                            }
                            num3  = SupportClass.URShift(num3, num6);
                            i    -= num6;
                            num9 += (num3 & InfBlocks.inflate_mask[num8]);
                            num3  = SupportClass.URShift(num3, num8);
                            i    -= num8;
                            num8  = this.index;
                            num6  = this.table;
                            if (num8 + num9 > 258 + (num6 & 31) + (num6 >> 5 & 31) || (num7 == 16 && num8 < 1))
                            {
                                this.blens = null;
                                this.mode  = 9;
                                z.msg      = "invalid bit length repeat";
                                return(procRet(z, i, -3, num, num2, num3, num4));
                            }
                            num7 = ((num7 == 16) ? this.blens[num8 - 1] : 0);
                            do
                            {
                                this.blens[num8++] = num7;
                            } while (--num9 != 0);
                            this.index = num8;
                        }
                    }
                    this.tb[0] = -1;
                    int[] array5 = new int[1];
                    int[] array6 = new int[1];
                    int[] array7 = new int[1];
                    int[] array8 = new int[1];
                    array5[0] = 9;
                    array6[0] = 6;
                    num6      = this.table;
                    num6      = InfTree.inflate_trees_dynamic(257 + (num6 & 31), 1 + (num6 >> 5 & 31), this.blens, array5, array6, array7, array8, this.hufts, z);
                    if (num6 == 0)
                    {
                        this.codes = new InfCodes(array5[0], array6[0], this.hufts, array7[0], this.hufts, array8[0], z);
                        this.blens = null;
                        this.mode  = 6;
                        goto case 6;
                    }
                    if (num6 == -3)
                    {
                        this.blens = null;
                        this.mode  = 9;
                    }
                    return(procRet(z, i, num6, num, num2, num3, num4));

                case 6:
                    this.bitb       = num3;
                    this.bitk       = i;
                    z.avail_in      = num2;
                    z.total_in     += (long)(num - z.next_in_index);
                    z.next_in_index = num;
                    this.write      = num4;
                    if ((r = this.codes.proc(this, z, r)) != 1)
                    {
                        break;
                    }
                    r = 0;
                    this.codes.free(z);
                    num  = z.next_in_index;
                    num2 = z.avail_in;
                    num3 = this.bitb;
                    i    = this.bitk;
                    num4 = this.write;
                    num5 = ((num4 < this.read) ? (this.read - num4 - 1) : (this.end - num4));
                    if (this.last != 0)
                    {
                        this.mode = 7;
                        goto case 7;
                    }
                    this.mode = 0;
                    continue;

                case 7:
                    this.write = num4;
                    r          = this.inflate_flush(z, r);
                    num4       = this.write;
                    int arg_CC8_0 = (num4 < this.read) ? (this.read - num4 - 1) : (this.end - num4);
                    if (this.read != this.write)
                    {
                        return(procRet(z, i, r, num, num2, num3, num4));
                    }
                    this.mode = 8;
                    goto case 8;

                case 8:
                    return(procRet(z, i, 1, num, num2, num3, num4));

                case 9:
                    return(procRet(z, i, -3, num, num2, num3, num4));
                }
                return(procRet(z, i, -2, num, num2, num3, num4));
            }
            return(this.inflate_flush(z, r));
        }
Esempio n. 9
0
        internal int proc(ZStream z, int r)
        {
            int num1;
            int num4 = z.next_in_index;
            int num5 = z.avail_in;
            int num2 = this.bitb;
            int num3 = this.bitk;
            int num6 = this.write;
            int num7 = (num6 < this.read) ? ((this.read - num6) - 1) : (this.end - num6);

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

                case 1:
                {
                    int[]   numArray1      = new int[1];
                    int[]   numArray2      = new int[1];
                    int[][] numArrayArray1 = new int[1][];
                    int[][] numArrayArray2 = new int[1][];
                    InfTree.inflate_trees_fixed(numArray1, numArray2, numArrayArray1, numArrayArray2, z);
                    this.codes = new InfCodes(numArray1[0], numArray2[0], numArrayArray1[0], numArrayArray2[0], z);
                    num2       = SupportClass.URShift(num2, 3);
                    num3      -= 3;
                    this.mode  = 6;
                    goto Label_0047;
                }

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

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

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

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

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

            case 4:
                goto Label_06E1;

            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       = num2;
                this.bitk       = num3;
                z.avail_in      = num5;
                z.total_in     += num4 - z.next_in_index;
                z.next_in_index = num4;
                this.write      = num6;
                return(this.inflate_flush(z, r));

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

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

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