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

                        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];
                        var 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
        internal const int BMAX = 15;         // maximum bit length of any code

        internal static int huft_build(int[] b, int bindex, int n, int s, int[] d, int[] e, int[] t, int[] m, int[] hp, int[] hn, int[] v)
        {
            // Given a list of code lengths and a maximum table size, make a set of
            // tables to decode that set of codes.  Return Z_OK on success, Z_BUF_ERROR
            // if the given code set is incomplete (the tables are still built in this
            // case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of
            // lengths), or Z_MEM_ERROR if not enough memory.

            int a;                       // counter for codes of length k

            int[] c = new int[BMAX + 1]; // bit length count table
            int   f;                     // i repeats in table every f entries
            int   j;                     // counter
            int   mask;                  // (1 << w) - 1, to avoid cc -O bug on HP

            int[] r = new int[3];        // table entry for structure assignment
            int[] u = new int[BMAX];     // table stack
            int[] x = new int[BMAX + 1]; // bit offsets, then code stack
            int   y;                     // number of dummy codes added

            // Generate counts for each bit length

            var p = 0; // pointer into c[], b[], or v[]
            var i = n; // counter, current code

            do
            {
                c[b[bindex + p]]++; p++; i--;                 // assume all entries <= BMAX
            }while (i != 0);

            if (c[0] == n)
            {
                // null input--all zero length codes
                t[0] = -1;
                m[0] = 0;
                return(Z_OK);
            }

            // Find minimum and maximum length, bound *m by those
            var l = m[0]; // bits per table (returned in m)

            for (j = 1; j <= BMAX; j++)
            {
                if (c[j] != 0)
                {
                    break;
                }
            }
            var k = j; // number of bits in current code: minimum code length

            if (l < j)
            {
                l = j;
            }
            for (i = BMAX; i != 0; i--)
            {
                if (c[i] != 0)
                {
                    break;
                }
            }
            var g = i;             // maximum code length

            if (l > i)
            {
                l = i;
            }
            m[0] = l;

            // Adjust last length count to fill out codes, if needed
            for (y = 1 << j; j < i; j++, y <<= 1)
            {
                if ((y -= c[j]) < 0)
                {
                    return(Z_DATA_ERROR);
                }
            }
            if ((y -= c[i]) < 0)
            {
                return(Z_DATA_ERROR);
            }
            c[i] += y;

            // Generate starting offsets into the value table for each length
            x[1] = j = 0;
            p    = 1;
            var xp = 2; // pointer into x

            while (--i != 0)
            {
                // note that i == g from above
                x[xp] = (j += c[p]);
                xp++;
                p++;
            }

            // Make a table of values in order of bit lengths
            i = 0; p = 0;
            do
            {
                if ((j = b[bindex + p]) != 0)
                {
                    v[x[j]++] = i;
                }
                p++;
            }while (++i < n);
            n = x[g];             // set n to length of v

            // Generate the Huffman codes and for each, make the table entries
            x[0] = i = 0; // first Huffman code is zero
            p    = 0;     // grab values in bit order
            var h = -1;   // table level: no tables yet
            var w = -l;   // bits before this table == (l * h): bits decoded

            u[0] = 0;     // just to keep compilers happy
            var q = 0;    // points to current table
            var z = 0;    // number of entries in current table

            // go through the bit lengths (k already is bits in shortest code)
            for (; k <= g; k++)
            {
                a = c[k];
                while (a-- != 0)
                {
                    // here i is the Huffman code of length k bits for value *p
                    // make tables up to required level
                    while (k > w + l)
                    {
                        h++;
                        w += l;                         // previous table always l bits
                        // compute minimum size table less than or equal to l bits
                        z = g - w;
                        z = (z > l)?l:z;                         // table size upper limit
                        if ((f = 1 << (j = k - w)) > a + 1)
                        {
                            // try a k-w bit table
                            // too few codes for k-w bit table
                            f -= (a + 1);                             // deduct codes from patterns left
                            xp = k;
                            if (j < z)
                            {
                                while (++j < z)
                                {
                                    // try smaller tables up to z bits
                                    if ((f <<= 1) <= c[++xp])
                                    {
                                        break;                                      // enough codes to use up j bits
                                    }
                                    f -= c[xp];                                     // else deduct codes from patterns
                                }
                            }
                        }
                        z = 1 << j;                         // table entries for j-bit table

                        // allocate new table
                        if (hn[0] + z > MANY)
                        {
                            // (note: doesn't matter for fixed)
                            return(Z_DATA_ERROR);                 // overflow of MANY
                        }
                        u[h]   = q = hn[0];                       // DEBUG
                        hn[0] += z;

                        // connect to last table, if there is one
                        if (h != 0)
                        {
                            x[h] = i;                                    // save pattern for backing up
                            r[0] = (byte)j;                              // bits in this table
                            r[1] = (byte)l;                              // bits to dump before this table
                            j    = SupportClass.URShift(i, (w - l));
                            r[2] = (int)(q - u[h - 1] - j);              // offset to this table
                            Array.Copy(r, 0, hp, (u[h - 1] + j) * 3, 3); // connect to last table
                        }
                        else
                        {
                            t[0] = q;                             // first table is returned result
                        }
                    }

                    // set up table entry in r
                    r[1] = (byte)(k - w);
                    if (p >= n)
                    {
                        r[0] = 128 + 64;                         // out of values--invalid code
                    }
                    else if (v[p] < s)
                    {
                        r[0] = (byte)(v[p] < 256?0:32 + 64);   // 256 is end-of-block
                        r[2] = v[p++];                         // simple code is just the value
                    }
                    else
                    {
                        r[0] = (byte)(e[v[p] - s] + 16 + 64);                          // non-simple--look up in lists
                        r[2] = d[v[p++] - s];
                    }

                    // fill code-like entries with r
                    f = 1 << (k - w);
                    for (j = SupportClass.URShift(i, w); j < z; j += f)
                    {
                        Array.Copy(r, 0, hp, (q + j) * 3, 3);
                    }

                    // backwards increment the k-bit code i
                    for (j = 1 << (k - 1); (i & j) != 0; j = SupportClass.URShift(j, 1))
                    {
                        i ^= j;
                    }
                    i ^= j;

                    // backup over finished tables
                    mask = (1 << w) - 1;                     // needed on HP, cc -O bug
                    while ((i & mask) != x[h])
                    {
                        h--;                         // don't need to update q
                        w   -= l;
                        mask = (1 << w) - 1;
                    }
                }
            }
            // Return Z_BUF_ERROR if we were given an incomplete table
            return(y != 0 && g != 1?Z_BUF_ERROR:Z_OK);
        }
예제 #3
0
        internal int proc(InfBlocks s, ZStream z, int r)
        {
            int j;             // temporary storage
            //int[] t; // temporary pointer
            int tindex;        // temporary pointer
            int e;             // extra bits or operation
            int b = 0;         // bit buffer
            int k = 0;         // bits in bit buffer
            int p = 0;         // input data pointer
            int n;             // bytes available there
            int q;             // output window write pointer
            int m;             // bytes to end of window or read pointer
            int f;             // pointer to copy strings from

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

            // process input and output based on current state
            while (true)
            {
                switch (mode)
                {
                // waiting for "i:"=input, "o:"=output, "x:"=nothing
                case START:                          // x: set up for LEN
                    if (m >= 258 && n >= 10)
                    {
                        s.bitb     = b; s.bitk = k;
                        z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p;
                        s.write    = q;
                        r          = inflate_fast(lbits, dbits, ltree, ltree_index, dtree, dtree_index, s, z);

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

                        if (r != Z_OK)
                        {
                            mode = r == Z_STREAM_END?WASH:BADCODE;
                            break;
                        }
                    }
                    need       = lbits;
                    tree       = ltree;
                    tree_index = ltree_index;

                    mode = LEN;
                    goto case LEN;

                case LEN:                          // i: get length/literal/eob next
                    j = need;

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

                    tindex = (tree_index + (b & inflate_mask[j])) * 3;

                    b  = SupportClass.URShift(b, (tree[tindex + 1]));
                    k -= (tree[tindex + 1]);

                    e = tree[tindex];

                    if (e == 0)
                    {
                        // literal
                        lit  = tree[tindex + 2];
                        mode = LIT;
                        break;
                    }
                    if ((e & 16) != 0)
                    {
                        // length
                        get_Renamed = e & 15;
                        len         = tree[tindex + 2];
                        mode        = LENEXT;
                        break;
                    }
                    if ((e & 64) == 0)
                    {
                        // next table
                        need       = e;
                        tree_index = tindex / 3 + tree[tindex + 2];
                        break;
                    }
                    if ((e & 32) != 0)
                    {
                        // end of block
                        mode = WASH;
                        break;
                    }
                    mode  = BADCODE;                            // invalid code
                    z.msg = "invalid literal/length code";
                    r     = Z_DATA_ERROR;

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


                case LENEXT:                          // i: getting length extra (have base)
                    j = get_Renamed;

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

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

                    b >>= j;
                    k  -= j;

                    need       = dbits;
                    tree       = dtree;
                    tree_index = dtree_index;
                    mode       = DIST;
                    goto case DIST;

                case DIST:                          // i: get distance next
                    j = need;

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

                    tindex = (tree_index + (b & inflate_mask[j])) * 3;

                    b >>= tree[tindex + 1];
                    k  -= tree[tindex + 1];

                    e = (tree[tindex]);
                    if ((e & 16) != 0)
                    {
                        // distance
                        get_Renamed = e & 15;
                        dist        = tree[tindex + 2];
                        mode        = DISTEXT;
                        break;
                    }
                    if ((e & 64) == 0)
                    {
                        // next table
                        need       = e;
                        tree_index = tindex / 3 + tree[tindex + 2];
                        break;
                    }
                    mode  = BADCODE;                            // invalid code
                    z.msg = "invalid distance code";
                    r     = Z_DATA_ERROR;

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


                case DISTEXT:                          // i: getting distance extra
                    j = get_Renamed;

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

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

                    b >>= j;
                    k  -= j;

                    mode = COPY;
                    goto case COPY;

                case COPY:                          // o: copying bytes in window, waiting for space
                    f = q - dist;
                    while (f < 0)
                    {
                        // modulo window size-"while" instead
                        f += s.end;                                 // of "if" handles invalid distances
                    }
                    while (len != 0)
                    {
                        if (m == 0)
                        {
                            if (q == s.end && s.read != 0)
                            {
                                q = 0; m = q < s.read?s.read - q - 1:s.end - q;
                            }
                            if (m == 0)
                            {
                                s.write = q; r = s.inflate_flush(z, r);
                                q       = s.write; m = q < s.read?s.read - q - 1:s.end - q;

                                if (q == s.end && s.read != 0)
                                {
                                    q = 0; m = q < s.read?s.read - q - 1:s.end - q;
                                }

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

                        s.window[q++] = s.window[f++]; m--;

                        if (f == s.end)
                        {
                            f = 0;
                        }
                        len--;
                    }
                    mode = START;
                    break;

                case LIT:                          // o: got literal, waiting for output space
                    if (m == 0)
                    {
                        if (q == s.end && s.read != 0)
                        {
                            q = 0; m = q < s.read?s.read - q - 1:s.end - q;
                        }
                        if (m == 0)
                        {
                            s.write = q; r = s.inflate_flush(z, r);
                            q       = s.write; m = q < s.read?s.read - q - 1:s.end - q;

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

                    s.window[q++] = (byte)lit; m--;

                    mode = START;
                    break;

                case WASH:                          // o: got eob, possibly more output
                    if (k > 7)
                    {
                        // return unused byte, if any
                        k -= 8;
                        n++;
                        p--;                                 // can always return one
                    }

                    s.write = q; r = s.inflate_flush(z, r);
                    q       = s.write; m = q < s.read?s.read - q - 1:s.end - q;

                    if (s.read != s.write)
                    {
                        s.bitb     = b; s.bitk = k;
                        z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p;
                        s.write    = q;
                        return(s.inflate_flush(z, r));
                    }
                    mode = END;
                    goto case END;

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


                case BADCODE:                          // x: got error

                    r = Z_DATA_ERROR;

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


                default:
                    r = Z_STREAM_ERROR;

                    s.bitb     = b; s.bitk = k;
                    z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p;
                    s.write    = q;
                    return(s.inflate_flush(z, r));
                }
            }
        }
예제 #4
0
 // Mapping from a distance to a distance code. dist is the distance - 1 and
 // must not have side effects. _dist_code[256] and _dist_code[257] are never
 // used.
 internal static int d_code(int dist)
 {
     return((dist) < 256?_dist_code[dist]:_dist_code[256 + (SupportClass.URShift((dist), 7))]);
 }
예제 #5
0
파일: Tree.cs 프로젝트: Duke-Jones/NVNC
        internal StaticTree stat_desc; // the corresponding static tree

        // Mapping from a distance to a distance code. dist is the distance - 1 and
        // must not have side effects. _dist_code[256] and _dist_code[257] are never
        // used.
        internal static int d_code(int dist)
        {
            return(dist < 256 ? _dist_code[dist] : _dist_code[256 + SupportClass.URShift(dist, 7)]);
        }
예제 #6
0
 internal void put_short(int w)
 {
     put_byte((byte)w);
     put_byte((byte)SupportClass.URShift(w, 8));
 }
예제 #7
0
        internal int proc(InfBlocks s, ZStream z, int r)
        {
            int num  = 0;
            int num2 = 0;
            int num3 = 0;

            num3 = z.next_in_index;
            int num4 = z.avail_in;

            num  = s.bitb;
            num2 = s.bitk;
            int num5 = s.write;
            int num6 = ((num5 >= s.read) ? (s.end - num5) : (s.read - num5 - 1));

            while (true)
            {
                switch (mode)
                {
                case 0:
                    if (num6 >= 258 && num4 >= 10)
                    {
                        s.bitb          = num;
                        s.bitk          = num2;
                        z.avail_in      = num4;
                        z.total_in     += num3 - z.next_in_index;
                        z.next_in_index = num3;
                        s.write         = num5;
                        r    = inflate_fast(lbits, dbits, ltree, ltree_index, dtree, dtree_index, s, z);
                        num3 = z.next_in_index;
                        num4 = z.avail_in;
                        num  = s.bitb;
                        num2 = s.bitk;
                        num5 = s.write;
                        num6 = ((num5 >= s.read) ? (s.end - num5) : (s.read - num5 - 1));
                        if (r != 0)
                        {
                            mode = ((r != 1) ? 9 : 7);
                            break;
                        }
                    }
                    need       = lbits;
                    tree       = ltree;
                    tree_index = ltree_index;
                    mode       = 1;
                    goto case 1;

                case 1:
                {
                    int num7;
                    for (num7 = need; num2 < num7; num2 += 8)
                    {
                        if (num4 != 0)
                        {
                            r = 0;
                            num4--;
                            num |= (z.next_in[num3++] & 0xFF) << num2;
                            continue;
                        }
                        s.bitb          = num;
                        s.bitk          = num2;
                        z.avail_in      = num4;
                        z.total_in     += num3 - z.next_in_index;
                        z.next_in_index = num3;
                        s.write         = num5;
                        return(s.inflate_flush(z, r));
                    }
                    int num8 = (tree_index + (num & inflate_mask[num7])) * 3;
                    num   = SupportClass.URShift(num, tree[num8 + 1]);
                    num2 -= tree[num8 + 1];
                    int num9 = tree[num8];
                    if (num9 == 0)
                    {
                        lit  = tree[num8 + 2];
                        mode = 6;
                        break;
                    }
                    if (((uint)num9 & 0x10u) != 0)
                    {
                        get_Renamed = num9 & 0xF;
                        len         = tree[num8 + 2];
                        mode        = 2;
                        break;
                    }
                    if ((num9 & 0x40) == 0)
                    {
                        need       = num9;
                        tree_index = num8 / 3 + tree[num8 + 2];
                        break;
                    }
                    if (((uint)num9 & 0x20u) != 0)
                    {
                        mode = 7;
                        break;
                    }
                    mode            = 9;
                    z.msg           = "invalid literal/length code";
                    r               = -3;
                    s.bitb          = num;
                    s.bitk          = num2;
                    z.avail_in      = num4;
                    z.total_in     += num3 - z.next_in_index;
                    z.next_in_index = num3;
                    s.write         = num5;
                    return(s.inflate_flush(z, r));
                }

                case 2:
                {
                    int num7;
                    for (num7 = get_Renamed; num2 < num7; num2 += 8)
                    {
                        if (num4 != 0)
                        {
                            r = 0;
                            num4--;
                            num |= (z.next_in[num3++] & 0xFF) << num2;
                            continue;
                        }
                        s.bitb          = num;
                        s.bitk          = num2;
                        z.avail_in      = num4;
                        z.total_in     += num3 - z.next_in_index;
                        z.next_in_index = num3;
                        s.write         = num5;
                        return(s.inflate_flush(z, r));
                    }
                    len       += num & inflate_mask[num7];
                    num      >>= num7;
                    num2      -= num7;
                    need       = dbits;
                    tree       = dtree;
                    tree_index = dtree_index;
                    mode       = 3;
                    goto case 3;
                }

                case 3:
                {
                    int num7;
                    for (num7 = need; num2 < num7; num2 += 8)
                    {
                        if (num4 != 0)
                        {
                            r = 0;
                            num4--;
                            num |= (z.next_in[num3++] & 0xFF) << num2;
                            continue;
                        }
                        s.bitb          = num;
                        s.bitk          = num2;
                        z.avail_in      = num4;
                        z.total_in     += num3 - z.next_in_index;
                        z.next_in_index = num3;
                        s.write         = num5;
                        return(s.inflate_flush(z, r));
                    }
                    int num8 = (tree_index + (num & inflate_mask[num7])) * 3;
                    num >>= tree[num8 + 1];
                    num2 -= tree[num8 + 1];
                    int num9 = tree[num8];
                    if (((uint)num9 & 0x10u) != 0)
                    {
                        get_Renamed = num9 & 0xF;
                        dist        = tree[num8 + 2];
                        mode        = 4;
                        break;
                    }
                    if ((num9 & 0x40) == 0)
                    {
                        need       = num9;
                        tree_index = num8 / 3 + tree[num8 + 2];
                        break;
                    }
                    mode            = 9;
                    z.msg           = "invalid distance code";
                    r               = -3;
                    s.bitb          = num;
                    s.bitk          = num2;
                    z.avail_in      = num4;
                    z.total_in     += num3 - z.next_in_index;
                    z.next_in_index = num3;
                    s.write         = num5;
                    return(s.inflate_flush(z, r));
                }

                case 4:
                {
                    int num7;
                    for (num7 = get_Renamed; num2 < num7; num2 += 8)
                    {
                        if (num4 != 0)
                        {
                            r = 0;
                            num4--;
                            num |= (z.next_in[num3++] & 0xFF) << num2;
                            continue;
                        }
                        s.bitb          = num;
                        s.bitk          = num2;
                        z.avail_in      = num4;
                        z.total_in     += num3 - z.next_in_index;
                        z.next_in_index = num3;
                        s.write         = num5;
                        return(s.inflate_flush(z, r));
                    }
                    dist += num & inflate_mask[num7];
                    num >>= num7;
                    num2 -= num7;
                    mode  = 5;
                    goto case 5;
                }

                case 5:
                {
                    int i;
                    for (i = num5 - dist; i < 0; i += s.end)
                    {
                    }
                    while (len != 0)
                    {
                        if (num6 == 0)
                        {
                            if (num5 == s.end && s.read != 0)
                            {
                                num5 = 0;
                                num6 = ((num5 >= s.read) ? (s.end - num5) : (s.read - num5 - 1));
                            }
                            if (num6 == 0)
                            {
                                s.write = num5;
                                r       = s.inflate_flush(z, r);
                                num5    = s.write;
                                num6    = ((num5 >= s.read) ? (s.end - num5) : (s.read - num5 - 1));
                                if (num5 == s.end && s.read != 0)
                                {
                                    num5 = 0;
                                    num6 = ((num5 >= s.read) ? (s.end - num5) : (s.read - num5 - 1));
                                }
                                if (num6 == 0)
                                {
                                    s.bitb          = num;
                                    s.bitk          = num2;
                                    z.avail_in      = num4;
                                    z.total_in     += num3 - z.next_in_index;
                                    z.next_in_index = num3;
                                    s.write         = num5;
                                    return(s.inflate_flush(z, r));
                                }
                            }
                        }
                        s.window[num5++] = s.window[i++];
                        num6--;
                        if (i == s.end)
                        {
                            i = 0;
                        }
                        len--;
                    }
                    mode = 0;
                    break;
                }

                case 6:
                    if (num6 == 0)
                    {
                        if (num5 == s.end && s.read != 0)
                        {
                            num5 = 0;
                            num6 = ((num5 >= s.read) ? (s.end - num5) : (s.read - num5 - 1));
                        }
                        if (num6 == 0)
                        {
                            s.write = num5;
                            r       = s.inflate_flush(z, r);
                            num5    = s.write;
                            num6    = ((num5 >= s.read) ? (s.end - num5) : (s.read - num5 - 1));
                            if (num5 == s.end && s.read != 0)
                            {
                                num5 = 0;
                                num6 = ((num5 >= s.read) ? (s.end - num5) : (s.read - num5 - 1));
                            }
                            if (num6 == 0)
                            {
                                s.bitb          = num;
                                s.bitk          = num2;
                                z.avail_in      = num4;
                                z.total_in     += num3 - z.next_in_index;
                                z.next_in_index = num3;
                                s.write         = num5;
                                return(s.inflate_flush(z, r));
                            }
                        }
                    }
                    r = 0;
                    s.window[num5++] = (byte)lit;
                    num6--;
                    mode = 0;
                    break;

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

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

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

                default:
                    r               = -2;
                    s.bitb          = num;
                    s.bitk          = num2;
                    z.avail_in      = num4;
                    z.total_in     += num3 - z.next_in_index;
                    z.next_in_index = num3;
                    s.write         = num5;
                    return(s.inflate_flush(z, r));
                }
            }
        }
예제 #8
0
        internal int deflate(ZStream strm, int flush)
        {
            if (flush > 4 || flush < 0)
            {
                return(-2);
            }
            if (strm.next_out == null || (strm.next_in == null && strm.avail_in != 0) || (status == 666 && flush != 4))
            {
                strm.msg = z_errmsg[4];
                return(-2);
            }
            if (strm.avail_out == 0)
            {
                strm.msg = z_errmsg[7];
                return(-5);
            }
            this.strm = strm;
            int num = last_flush;

            last_flush = flush;
            if (status == 42)
            {
                int num2 = 8 + (w_bits - 8 << 4) << 8;
                int num3 = ((level - 1) & 0xFF) >> 1;
                if (num3 > 3)
                {
                    num3 = 3;
                }
                num2 |= num3 << 6;
                if (strstart != 0)
                {
                    num2 |= 0x20;
                }
                num2  += 31 - num2 % 31;
                status = 113;
                putShortMSB(num2);
                if (strstart != 0)
                {
                    putShortMSB((int)SupportClass.URShift(strm.adler, 16));
                    putShortMSB((int)(strm.adler & 0xFFFF));
                }
                strm.adler = strm._adler.adler32(0L, null, 0, 0);
            }
            if (pending != 0)
            {
                strm.flush_pending();
                if (strm.avail_out == 0)
                {
                    last_flush = -1;
                    return(0);
                }
            }
            else if (strm.avail_in == 0 && flush <= num && flush != 4)
            {
                strm.msg = z_errmsg[7];
                return(-5);
            }
            if (status == 666 && strm.avail_in != 0)
            {
                strm.msg = z_errmsg[7];
                return(-5);
            }
            if (strm.avail_in != 0 || lookahead != 0 || (flush != 0 && status != 666))
            {
                int num4 = -1;
                switch (config_table[level].func)
                {
                case 0:
                    num4 = deflate_stored(flush);
                    break;

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

                case 2:
                    num4 = deflate_slow(flush);
                    break;
                }
                if (num4 == 2 || num4 == 3)
                {
                    status = 666;
                }
                switch (num4)
                {
                case 0:
                case 2:
                    if (strm.avail_out == 0)
                    {
                        last_flush = -1;
                    }
                    return(0);

                case 1:
                    if (flush == 1)
                    {
                        _tr_align();
                    }
                    else
                    {
                        _tr_stored_block(0, 0, eof: false);
                        if (flush == 3)
                        {
                            for (int i = 0; i < hash_size; i++)
                            {
                                head[i] = 0;
                            }
                        }
                    }
                    strm.flush_pending();
                    if (strm.avail_out == 0)
                    {
                        last_flush = -1;
                        return(0);
                    }
                    break;
                }
            }
            if (flush != 4)
            {
                return(0);
            }
            if (noheader != 0)
            {
                return(1);
            }
            putShortMSB((int)SupportClass.URShift(strm.adler, 16));
            putShortMSB((int)(strm.adler & 0xFFFF));
            strm.flush_pending();
            noheader = -1;
            return((pending == 0) ? 1 : 0);
        }
예제 #9
0
        internal void scan_tree(short[] tree, int max_code)
        {
            int num  = -1;
            int num2 = tree[1];
            int num3 = 0;
            int num4 = 7;
            int num5 = 4;

            if (num2 == 0)
            {
                num4 = 138;
                num5 = 3;
            }
            tree[(max_code + 1) * 2 + 1] = (short)SupportClass.Identity(65535L);
            for (int i = 0; i <= max_code; i++)
            {
                int num6 = num2;
                num2 = tree[(i + 1) * 2 + 1];
                if (++num3 < num4 && num6 == num2)
                {
                    continue;
                }
                if (num3 < num5)
                {
                    bl_tree[num6 * 2] = (short)(bl_tree[num6 * 2] + num3);
                }
                else if (num6 != 0)
                {
                    if (num6 != num)
                    {
                        bl_tree[num6 * 2]++;
                    }
                    bl_tree[32]++;
                }
                else if (num3 <= 10)
                {
                    bl_tree[34]++;
                }
                else
                {
                    bl_tree[36]++;
                }
                num3 = 0;
                num  = num6;
                if (num2 == 0)
                {
                    num4 = 138;
                    num5 = 3;
                }
                else if (num6 == num2)
                {
                    num4 = 6;
                    num5 = 3;
                }
                else
                {
                    num4 = 7;
                    num5 = 4;
                }
            }
        }
예제 #10
0
 public static int URShift(int number, long bits)
 {
     return(SupportClass.URShift(number, (int)bits));
 }
예제 #11
0
        internal static int huft_build(int[] b, int bindex, int n, int s, int[] d, int[] e, int[] t, int[] m, int[] hp, int[] hn, int[] v)
        {
            int[] array  = new int[16];
            int[] array2 = new int[3];
            int[] array3 = new int[15];
            int[] array4 = new int[16];
            int   num    = 0;
            int   num2   = n;

            do
            {
                array[b[bindex + num]]++;
                num++;
                num2--;
            }while (num2 != 0);
            if (array[0] == n)
            {
                t[0] = -1;
                m[0] = 0;
                return(0);
            }
            int num3 = m[0];
            int i;

            for (i = 1; i <= 15 && array[i] == 0; i++)
            {
            }
            int j = i;

            if (num3 < i)
            {
                num3 = i;
            }
            num2 = 15;
            while (num2 != 0 && array[num2] == 0)
            {
                num2--;
            }
            int num4 = num2;

            if (num3 > num2)
            {
                num3 = num2;
            }
            m[0] = num3;
            int num5 = 1 << i;

            while (i < num2)
            {
                if ((num5 -= array[i]) < 0)
                {
                    return(-3);
                }
                i++;
                num5 <<= 1;
            }
            if ((num5 -= array[num2]) < 0)
            {
                return(-3);
            }
            array[num2] += num5;
            i            = (array4[1] = 0);
            num          = 1;
            int num6 = 2;

            while (--num2 != 0)
            {
                i = (array4[num6] = i + array[num]);
                num6++;
                num++;
            }
            num2 = 0;
            num  = 0;
            do
            {
                if ((i = b[bindex + num]) != 0)
                {
                    v[array4[i]++] = num2;
                }
                num++;
            }while (++num2 < n);
            n    = array4[num4];
            num2 = (array4[0] = 0);
            num  = 0;
            int num7 = -1;
            int num8 = -num3;

            array3[0] = 0;
            int num9  = 0;
            int num10 = 0;

            for (; j <= num4; j++)
            {
                int num11 = array[j];
                while (num11-- != 0)
                {
                    int num12;
                    while (j > num8 + num3)
                    {
                        num7++;
                        num8 += num3;
                        num10 = num4 - num8;
                        num10 = ((num10 <= num3) ? num10 : num3);
                        if ((num12 = 1 << (i = j - num8)) > num11 + 1)
                        {
                            num12 -= num11 + 1;
                            num6   = j;
                            if (i < num10)
                            {
                                while (++i < num10 && (num12 <<= 1) > array[++num6])
                                {
                                    num12 -= array[num6];
                                }
                            }
                        }
                        num10 = 1 << i;
                        if (hn[0] + num10 > 1440)
                        {
                            return(-3);
                        }
                        num9   = (array3[num7] = hn[0]);
                        hn[0] += num10;
                        if (num7 != 0)
                        {
                            array4[num7] = num2;
                            array2[0]    = (byte)i;
                            array2[1]    = (byte)num3;
                            i            = SupportClass.URShift(num2, num8 - num3);
                            array2[2]    = num9 - array3[num7 - 1] - i;
                            Array.Copy(array2, 0, hp, (array3[num7 - 1] + i) * 3, 3);
                        }
                        else
                        {
                            t[0] = num9;
                        }
                    }
                    array2[1] = (byte)(j - num8);
                    if (num >= n)
                    {
                        array2[0] = 192;
                    }
                    else if (v[num] < s)
                    {
                        array2[0] = (byte)((v[num] >= 256) ? 96 : 0);
                        array2[2] = v[num++];
                    }
                    else
                    {
                        array2[0] = (byte)(e[v[num] - s] + 16 + 64);
                        array2[2] = d[v[num++] - s];
                    }
                    num12 = 1 << j - num8;
                    for (i = SupportClass.URShift(num2, num8); i < num10; i += num12)
                    {
                        Array.Copy(array2, 0, hp, (num9 + i) * 3, 3);
                    }
                    i = 1 << j - 1;
                    while ((num2 & i) != 0)
                    {
                        num2 ^= i;
                        i     = SupportClass.URShift(i, 1);
                    }
                    num2 ^= i;
                    int num13 = (1 << num8) - 1;
                    while ((num2 & num13) != array4[num7])
                    {
                        num7--;
                        num8 -= num3;
                        num13 = (1 << num8) - 1;
                    }
                }
            }
            return((num5 != 0 && num4 != 1) ? (-5) : 0);
        }
예제 #12
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));
                }
            }
        }
예제 #13
0
        internal static int huft_build(int[] b, int bindex, int n, int s, int[] d, int[] e, int[] t, int[] m, int[] hp, int[] hn, int[] v)
        {
            int    num;
            int    num1;
            object obj;

            int[] numArray  = new int[16];
            int[] numArray1 = new int[3];
            int[] numArray2 = new int[15];
            int[] numArray3 = new int[16];
            int   num2      = 0;
            int   num3      = n;

            do
            {
                numArray[b[bindex + num2]] = numArray[b[bindex + num2]] + 1;
                num2++;
                num3--;
            }while (num3 != 0);
            if (numArray[0] == n)
            {
                t[0] = -1;
                m[0] = 0;
                return(0);
            }
            int num4 = m[0];
            int i    = 1;

            while (i <= 15 && numArray[i] == 0)
            {
                i++;
            }
            int num5 = i;

            if (num4 < i)
            {
                num4 = i;
            }
            num3 = 15;
            while (num3 != 0 && numArray[num3] == 0)
            {
                num3--;
            }
            int num6 = num3;

            if (num4 > num3)
            {
                num4 = num3;
            }
            m[0] = num4;
            int num7 = 1 << (i & 31);

            while (i < num3)
            {
                int num8 = num7 - numArray[i];
                num7 = num8;
                if (num8 < 0)
                {
                    return(-3);
                }
                i++;
                num7 = num7 << 1;
            }
            int num9 = num7 - numArray[num3];

            num7 = num9;
            if (num9 < 0)
            {
                return(-3);
            }
            numArray[num3] = numArray[num3] + num7;
            int num10 = 0;

            i            = num10;
            numArray3[1] = num10;
            num2         = 1;
            int num11 = 2;

            while (true)
            {
                int num12 = num3 - 1;
                num3 = num12;
                if (num12 == 0)
                {
                    break;
                }
                int num13 = i + numArray[num2];
                i = num13;
                numArray3[num11] = num13;
                num11++;
                num2++;
            }
            num3 = 0;
            num2 = 0;
            do
            {
                int num14 = b[bindex + num2];
                i = num14;
                if (num14 != 0)
                {
                    int num15 = numArray3[i];
                    int num16 = num15;
                    numArray3[i] = num15 + 1;
                    v[num16]     = num3;
                }
                num2++;
                num1 = num3 + 1;
                num3 = num1;
            }while (num1 < n);
            n = numArray3[num6];
            int num17 = 0;

            num3         = num17;
            numArray3[0] = num17;
            num2         = 0;
            int num18 = -1;
            int num19 = -num4;

            numArray2[0] = 0;
            int num20 = 0;
            int num21 = 0;

Label1:
            if (num5 > num6)
            {
                if (num7 != 0 && num6 != 1)
                {
                    return(-5);
                }
                return(0);
            }
            int num22 = numArray[num5];

Label2:
            int num23 = num22;

            num22 = num23 - 1;
            if (num23 != 0)
            {
                goto Label0;
            }
            num5++;
            goto Label1;
Label0:
            while (num5 > num19 + num4)
            {
                num18++;
                num19 = num19 + num4;
                num21 = num6 - num19;
                num21 = (num21 > num4 ? num4 : num21);
                int num24 = num5 - num19;
                i = num24;
                int num25 = 1 << (num24 & 31);
                num = num25;
                if (num25 > num22 + 1)
                {
                    num   = num - (num22 + 1);
                    num11 = num5;
                    if (i < num21)
                    {
                        while (true)
                        {
                            int num26 = i + 1;
                            i = num26;
                            if (num26 >= num21)
                            {
                                break;
                            }
                            int num27 = num << 1;
                            num = num27;
                            int num28 = num11 + 1;
                            num11 = num28;
                            if (num27 <= numArray[num28])
                            {
                                break;
                            }
                            num = num - numArray[num11];
                        }
                    }
                }
                num21 = 1 << (i & 31);
                if (hn[0] + num21 > 1440)
                {
                    return(-3);
                }
                int num29 = hn[0];
                num20            = num29;
                numArray2[num18] = num29;
                hn[0]            = hn[0] + num21;
                if (num18 == 0)
                {
                    t[0] = num20;
                }
                else
                {
                    numArray3[num18] = num3;
                    numArray1[0]     = (byte)i;
                    numArray1[1]     = (byte)num4;
                    i            = SupportClass.URShift(num3, num19 - num4);
                    numArray1[2] = num20 - numArray2[num18 - 1] - i;
                    Array.Copy(numArray1, 0, hp, (numArray2[num18 - 1] + i) * 3, 3);
                }
            }
            numArray1[1] = (byte)(num5 - num19);
            if (num2 >= n)
            {
                numArray1[0] = 192;
            }
            else if (v[num2] >= s)
            {
                numArray1[0] = (byte)(e[v[num2] - s] + 16 + 64);
                int num30 = num2;
                num2         = num30 + 1;
                numArray1[2] = d[v[num30] - s];
            }
            else
            {
                int[] numArray4 = numArray1;
                if (v[num2] < 256)
                {
                    obj = null;
                }
                else
                {
                    obj = 96;
                }
                numArray4[0] = (byte)obj;
                int num31 = num2;
                num2         = num31 + 1;
                numArray1[2] = v[num31];
            }
            num = 1 << (num5 - num19 & 31);
            for (i = SupportClass.URShift(num3, num19); i < num21; i = i + num)
            {
                Array.Copy(numArray1, 0, hp, (num20 + i) * 3, 3);
            }
            for (i = 1 << (num5 - 1 & 31); (num3 & i) != 0; i = SupportClass.URShift(i, 1))
            {
                num3 = num3 ^ i;
            }
            num3 = num3 ^ i;
            for (int j = (1 << (num19 & 31)) - 1; (num3 & j) != numArray3[num18]; j = (1 << (num19 & 31)) - 1)
            {
                num18--;
                num19 = num19 - num4;
            }
            goto Label2;
        }
예제 #14
0
        internal int proc(InfBlocks s, ZStream z, int r)
        {
            int num;
            int num10;
            int number = 0;
            int bitk   = 0;
            int num6   = 0;

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

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

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

            case 1:
                goto Label_0199;

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

            case 3:
                goto Label_0412;

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

            case 5:
                goto Label_0635;

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

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

            case 8:
                goto Label_098A;

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

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

            number = SupportClass.URShift(number, this.tree[index + 1]);
            bitk  -= this.tree[index + 1];
            int num3 = this.tree[index];

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

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

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