예제 #1
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));
                }
            }
        }
예제 #2
0
파일: InfBlocks.cs 프로젝트: BjkGkh/R106
        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);

                }
            }
        }
예제 #3
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_6E1;

                case 4:
                    goto IL_6E1;

                case 5:
                    goto IL_7B9;

                case 6:
                    goto IL_B63;

                case 7:
                    goto IL_C2C;

                case 8:
                    goto IL_CC1;

                case 9:
                    goto IL_D08;
                }
                break;
IL_6E1:
                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;
                    }
                    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)
                {
                    goto Block_33;
                }
                this.index = 0;
                this.mode  = 5;
                while (true)
                {
IL_7B9:
                    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_7F0;
                        }
                        r = 0;
                        num2--;
                        num3 |= (int)(z.next_in[num++] & 255) << i;
                        i    += 8;
                    }
                    int arg_866_0 = this.tb[0];
                    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)
                            {
                                goto IL_8FF;
                            }
                            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))
                        {
                            goto IL_9C9;
                        }
                        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)
                {
                    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_B63:
                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_C25;
                }
                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_7F0:
            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_8FF:
            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_9C9:
            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_C25:
            this.mode = 7;
IL_C2C:
            this.write = num4;
            r          = this.inflate_flush(z, r);
            num4       = this.write;
            int arg_C66_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_CC1:
            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_D08:
            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));
        }