示例#1
0
        internal static int inflate_trees_bits(int[] c, int[] bb, int[] tb, int[] hp, ZStream z)
        {
            int[] numArray  = new int[1];
            int[] numArray1 = new int[19];
            int   num       = InfTree.huft_build(c, 0, 19, 19, null, null, tb, bb, hp, numArray, numArray1);

            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);
        }
示例#2
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[] numArray  = new int[1];
            int[] numArray1 = new int[288];
            int   num       = InfTree.huft_build(c, 0, nl, 257, InfTree.cplens, InfTree.cplext, tl, bl, hp, numArray, numArray1);

            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, numArray, numArray1);
            if (num == 0 && (bd[0] != 0 || nl <= 257))
            {
                return(0);
            }
            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);
        }
示例#3
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 = 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    = 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
                    {
                        var bl = new int[1];
                        var bd = new int[1];
                        var tl = new int[1][];
                        var 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 = q < read ? read - q - 1 : end - q;
                        }
                        if (m == 0)
                        {
                            write = q;
                            r     = inflate_flush(z, r);
                            q     = write;
                            m     = q < read ? read - q - 1 : end - q;
                            if (q == end && read != 0)
                            {
                                q = 0;
                                m = 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;
                    {
                        var bl = new int[1];
                        var bd = new int[1];
                        var tl = new int[1];
                        var 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 = 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     = 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));
                }
            }
        }
示例#4
0
        internal int proc(ZStream z, int r)
        {
            int num  = z.next_in_index;
            int num2 = z.avail_in;
            int num3 = bitb;
            int i    = bitk;
            int num4 = write;
            int num5 = ((num4 >= read) ? (end - num4) : (read - num4 - 1));

            while (true)
            {
                switch (mode)
                {
                case 0:
                {
                    for (; i < 3; i += 8)
                    {
                        if (num2 != 0)
                        {
                            r = 0;
                            num2--;
                            num3 |= (z.next_in[num++] & 0xFF) << i;
                            continue;
                        }
                        bitb            = num3;
                        bitk            = i;
                        z.avail_in      = num2;
                        z.total_in     += num - z.next_in_index;
                        z.next_in_index = num;
                        write           = num4;
                        return(inflate_flush(z, r));
                    }
                    int num6 = num3 & 7;
                    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;
                        mode = 1;
                        break;

                    case 1:
                    {
                        int[]   array5 = new int[1];
                        int[]   array6 = new int[1];
                        int[][] array7 = new int[1][];
                        int[][] array8 = new int[1][];
                        InfTree.inflate_trees_fixed(array5, array6, array7, array8, z);
                        codes = new InfCodes(array5[0], array6[0], array7[0], array8[0], z);
                        num3  = SupportClass.URShift(num3, 3);
                        i    -= 3;
                        mode  = 6;
                        break;
                    }

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

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

                case 1:
                    for (; i < 32; i += 8)
                    {
                        if (num2 != 0)
                        {
                            r = 0;
                            num2--;
                            num3 |= (z.next_in[num++] & 0xFF) << i;
                            continue;
                        }
                        bitb            = num3;
                        bitk            = i;
                        z.avail_in      = num2;
                        z.total_in     += num - z.next_in_index;
                        z.next_in_index = num;
                        write           = num4;
                        return(inflate_flush(z, r));
                    }
                    if ((SupportClass.URShift(~num3, 16) & 0xFFFF) != (num3 & 0xFFFF))
                    {
                        mode            = 9;
                        z.msg           = "invalid stored block lengths";
                        r               = -3;
                        bitb            = num3;
                        bitk            = i;
                        z.avail_in      = num2;
                        z.total_in     += num - z.next_in_index;
                        z.next_in_index = num;
                        write           = num4;
                        return(inflate_flush(z, r));
                    }
                    left = num3 & 0xFFFF;
                    num3 = (i = 0);
                    mode = ((left != 0) ? 2 : ((last != 0) ? 7 : 0));
                    break;

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

                case 3:
                {
                    for (; i < 14; i += 8)
                    {
                        if (num2 != 0)
                        {
                            r = 0;
                            num2--;
                            num3 |= (z.next_in[num++] & 0xFF) << i;
                            continue;
                        }
                        bitb            = num3;
                        bitk            = i;
                        z.avail_in      = num2;
                        z.total_in     += num - z.next_in_index;
                        z.next_in_index = num;
                        write           = num4;
                        return(inflate_flush(z, r));
                    }
                    int num6 = (table = num3 & 0x3FFF);
                    if ((num6 & 0x1F) > 29 || ((num6 >> 5) & 0x1F) > 29)
                    {
                        mode            = 9;
                        z.msg           = "too many length or distance symbols";
                        r               = -3;
                        bitb            = num3;
                        bitk            = i;
                        z.avail_in      = num2;
                        z.total_in     += num - z.next_in_index;
                        z.next_in_index = num;
                        write           = num4;
                        return(inflate_flush(z, r));
                    }
                    num6  = 258 + (num6 & 0x1F) + ((num6 >> 5) & 0x1F);
                    blens = new int[num6];
                    num3  = SupportClass.URShift(num3, 14);
                    i    -= 14;
                    index = 0;
                    mode  = 4;
                    goto case 4;
                }

                case 4:
                {
                    while (index < 4 + SupportClass.URShift(table, 10))
                    {
                        for (; i < 3; i += 8)
                        {
                            if (num2 != 0)
                            {
                                r = 0;
                                num2--;
                                num3 |= (z.next_in[num++] & 0xFF) << i;
                                continue;
                            }
                            bitb            = num3;
                            bitk            = i;
                            z.avail_in      = num2;
                            z.total_in     += num - z.next_in_index;
                            z.next_in_index = num;
                            write           = num4;
                            return(inflate_flush(z, r));
                        }
                        blens[border[index++]] = num3 & 7;
                        num3 = SupportClass.URShift(num3, 3);
                        i   -= 3;
                    }
                    while (index < 19)
                    {
                        blens[border[index++]] = 0;
                    }
                    bb[0] = 7;
                    int num6 = InfTree.inflate_trees_bits(blens, bb, tb, hufts, z);
                    if (num6 != 0)
                    {
                        r = num6;
                        if (r == -3)
                        {
                            blens = null;
                            mode  = 9;
                        }
                        bitb            = num3;
                        bitk            = i;
                        z.avail_in      = num2;
                        z.total_in     += num - z.next_in_index;
                        z.next_in_index = num;
                        write           = num4;
                        return(inflate_flush(z, r));
                    }
                    index = 0;
                    mode  = 5;
                    goto case 5;
                }

                case 5:
                {
                    int num6;
                    while (true)
                    {
                        num6 = table;
                        if (index >= 258 + (num6 & 0x1F) + ((num6 >> 5) & 0x1F))
                        {
                            break;
                        }
                        for (num6 = bb[0]; i < num6; i += 8)
                        {
                            if (num2 != 0)
                            {
                                r = 0;
                                num2--;
                                num3 |= (z.next_in[num++] & 0xFF) << i;
                                continue;
                            }
                            bitb            = num3;
                            bitk            = i;
                            z.avail_in      = num2;
                            z.total_in     += num - z.next_in_index;
                            z.next_in_index = num;
                            write           = num4;
                            return(inflate_flush(z, r));
                        }
                        if (tb[0] == -1)
                        {
                        }
                        num6 = hufts[(tb[0] + (num3 & inflate_mask[num6])) * 3 + 1];
                        int num7 = hufts[(tb[0] + (num3 & inflate_mask[num6])) * 3 + 2];
                        if (num7 < 16)
                        {
                            num3           = SupportClass.URShift(num3, num6);
                            i             -= num6;
                            blens[index++] = num7;
                            continue;
                        }
                        int num8 = ((num7 != 18) ? (num7 - 14) : 7);
                        int num9 = ((num7 != 18) ? 3 : 11);
                        for (; i < num6 + num8; i += 8)
                        {
                            if (num2 != 0)
                            {
                                r = 0;
                                num2--;
                                num3 |= (z.next_in[num++] & 0xFF) << i;
                                continue;
                            }
                            bitb            = num3;
                            bitk            = i;
                            z.avail_in      = num2;
                            z.total_in     += num - z.next_in_index;
                            z.next_in_index = num;
                            write           = num4;
                            return(inflate_flush(z, r));
                        }
                        num3  = SupportClass.URShift(num3, num6);
                        i    -= num6;
                        num9 += num3 & inflate_mask[num8];
                        num3  = SupportClass.URShift(num3, num8);
                        i    -= num8;
                        num8  = index;
                        num6  = table;
                        if (num8 + num9 > 258 + (num6 & 0x1F) + ((num6 >> 5) & 0x1F) || (num7 == 16 && num8 < 1))
                        {
                            blens           = null;
                            mode            = 9;
                            z.msg           = "invalid bit length repeat";
                            r               = -3;
                            bitb            = num3;
                            bitk            = i;
                            z.avail_in      = num2;
                            z.total_in     += num - z.next_in_index;
                            z.next_in_index = num;
                            write           = num4;
                            return(inflate_flush(z, r));
                        }
                        num7 = ((num7 == 16) ? blens[num8 - 1] : 0);
                        do
                        {
                            blens[num8++] = num7;
                        }while (--num9 != 0);
                        index = num8;
                    }
                    tb[0] = -1;
                    int[] array  = new int[1];
                    int[] array2 = new int[1];
                    int[] array3 = new int[1];
                    int[] array4 = new int[1];
                    array[0]  = 9;
                    array2[0] = 6;
                    num6      = table;
                    num6      = InfTree.inflate_trees_dynamic(257 + (num6 & 0x1F), 1 + ((num6 >> 5) & 0x1F), blens, array, array2, array3, array4, hufts, z);
                    if (num6 != 0)
                    {
                        if (num6 == -3)
                        {
                            blens = null;
                            mode  = 9;
                        }
                        r               = num6;
                        bitb            = num3;
                        bitk            = i;
                        z.avail_in      = num2;
                        z.total_in     += num - z.next_in_index;
                        z.next_in_index = num;
                        write           = num4;
                        return(inflate_flush(z, r));
                    }
                    codes = new InfCodes(array[0], array2[0], hufts, array3[0], hufts, array4[0], z);
                    blens = null;
                    mode  = 6;
                    goto case 6;
                }

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

                case 7:
                    write = num4;
                    r     = inflate_flush(z, r);
                    num4  = write;
                    num5  = ((num4 >= read) ? (end - num4) : (read - num4 - 1));
                    if (read != write)
                    {
                        bitb            = num3;
                        bitk            = i;
                        z.avail_in      = num2;
                        z.total_in     += num - z.next_in_index;
                        z.next_in_index = num;
                        write           = num4;
                        return(inflate_flush(z, r));
                    }
                    mode = 8;
                    goto case 8;

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

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

                default:
                    r               = -2;
                    bitb            = num3;
                    bitk            = i;
                    z.avail_in      = num2;
                    z.total_in     += num - z.next_in_index;
                    z.next_in_index = num;
                    write           = num4;
                    return(inflate_flush(z, r));
                }
            }
        }
示例#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));
        }