Exemple #1
0
        internal int proc(InfBlocks s, ZStream z, int r)
        {
            int num1;
            int num10;
            int num4 = 0;
            int num5 = 0;
            int num6 = 0;

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

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

Label_0051:
            switch (this.mode)
            {
            case 0:
                if ((num9 < 0x102) || (num7 < 10))
                {
                    break;
                }
                s.bitb          = num4;
                s.bitk          = num5;
                z.avail_in      = num7;
                z.total_in     += num6 - z.next_in_index;
                z.next_in_index = num6;
                s.write         = num8;
                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;
                num4 = s.bitb;
                num5 = s.bitk;
                num8 = s.write;
                num9 = (num8 < s.read) ? ((s.read - num8) - 1) : (s.end - num8);
                if (r == 0)
                {
                    break;
                }
                this.mode = (r == 1) ? 7 : 9;
                goto Label_0051;

            case 1:
                goto Label_0199;

            case 2:
                num1 = this.get_Renamed;
                while (num5 < num1)
                {
                    if (num7 != 0)
                    {
                        r = 0;
                    }
                    else
                    {
                        s.bitb          = num4;
                        s.bitk          = num5;
                        z.avail_in      = num7;
                        z.total_in     += num6 - z.next_in_index;
                        z.next_in_index = num6;
                        s.write         = num8;
                        return(s.inflate_flush(z, r));
                    }
                    num7--;
                    num4 |= (z.next_in[num6++] & 0xff) << (num5 & 0x1f);
                    num5 += 8;
                }
                this.len       += num4 & InfCodes.inflate_mask[num1];
                num4            = num4 >> (num1 & 0x1f);
                num5           -= num1;
                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:
                num1 = this.get_Renamed;
                while (num5 < num1)
                {
                    if (num7 != 0)
                    {
                        r = 0;
                    }
                    else
                    {
                        s.bitb          = num4;
                        s.bitk          = num5;
                        z.avail_in      = num7;
                        z.total_in     += num6 - z.next_in_index;
                        z.next_in_index = num6;
                        s.write         = num8;
                        return(s.inflate_flush(z, r));
                    }
                    num7--;
                    num4 |= (z.next_in[num6++] & 0xff) << (num5 & 0x1f);
                    num5 += 8;
                }
                this.dist += num4 & InfCodes.inflate_mask[num1];
                num4       = num4 >> (num1 & 0x1f);
                num5      -= num1;
                this.mode  = 5;
                goto Label_0635;

            case 5:
                goto Label_0635;

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

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

            case 8:
                goto Label_098A;

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

            default:
                r               = -2;
                s.bitb          = num4;
                s.bitk          = num5;
                z.avail_in      = num7;
                z.total_in     += num6 - z.next_in_index;
                z.next_in_index = num6;
                s.write         = num8;
                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:
            num1 = this.need;
            while (num5 < num1)
            {
                if (num7 != 0)
                {
                    r = 0;
                }
                else
                {
                    s.bitb          = num4;
                    s.bitk          = num5;
                    z.avail_in      = num7;
                    z.total_in     += num6 - z.next_in_index;
                    z.next_in_index = num6;
                    s.write         = num8;
                    return(s.inflate_flush(z, r));
                }
                num7--;
                num4 |= (z.next_in[num6++] & 0xff) << (num5 & 0x1f);
                num5 += 8;
            }
            int num2 = (this.tree_index + (num4 & InfCodes.inflate_mask[num1])) * 3;

            num4  = SupportClass.URShift(num4, this.tree[num2 + 1]);
            num5 -= this.tree[num2 + 1];
            int num3 = this.tree[num2];

            if (num3 == 0)
            {
                this.lit  = this.tree[num2 + 2];
                this.mode = 6;
                goto Label_0051;
            }
            if ((num3 & 0x10) != 0)
            {
                this.get_Renamed = num3 & 15;
                this.len         = this.tree[num2 + 2];
                this.mode        = 2;
                goto Label_0051;
            }
            if ((num3 & 0x40) == 0)
            {
                this.need       = num3;
                this.tree_index = (num2 / 3) + this.tree[num2 + 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          = num4;
            s.bitk          = num5;
            z.avail_in      = num7;
            z.total_in     += num6 - z.next_in_index;
            z.next_in_index = num6;
            s.write         = num8;
            return(s.inflate_flush(z, r));

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

Label_0635:
            num10 = num8 - this.dist;
            while (num10 < 0)
            {
                num10 += s.end;
            }
            while (this.len != 0)
            {
                if (num9 == 0)
                {
                    if ((num8 == s.end) && (s.read != 0))
                    {
                        num8 = 0;
                        num9 = (num8 < s.read) ? ((s.read - num8) - 1) : (s.end - num8);
                    }
                    if (num9 == 0)
                    {
                        s.write = num8;
                        r       = s.inflate_flush(z, r);
                        num8    = s.write;
                        num9    = (num8 < s.read) ? ((s.read - num8) - 1) : (s.end - num8);
                        if ((num8 == s.end) && (s.read != 0))
                        {
                            num8 = 0;
                            num9 = (num8 < s.read) ? ((s.read - num8) - 1) : (s.end - num8);
                        }
                        if (num9 == 0)
                        {
                            s.bitb          = num4;
                            s.bitk          = num5;
                            z.avail_in      = num7;
                            z.total_in     += num6 - z.next_in_index;
                            z.next_in_index = num6;
                            s.write         = num8;
                            return(s.inflate_flush(z, r));
                        }
                    }
                }
                s.window[num8++] = s.window[num10++];
                num9--;
                if (num10 == s.end)
                {
                    num10 = 0;
                }
                this.len--;
            }
            this.mode = 0;
            goto Label_0051;
Label_098A:
            r               = 1;
            s.bitb          = num4;
            s.bitk          = num5;
            z.avail_in      = num7;
            z.total_in     += num6 - z.next_in_index;
            z.next_in_index = num6;
            s.write         = num8;
            return(s.inflate_flush(z, r));
        }
        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);
                }
            }
        }
Exemple #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));
                }
            }
        }
Exemple #4
0
        internal int proc(InfBlocks s, ZStream z, int r)
        {
            int num  = z.next_in_index;
            int num2 = z.avail_in;
            int num3 = s.bitb;
            int i    = s.bitk;
            int num4 = s.write;
            int num5 = (num4 < s.read) ? (s.read - num4 - 1) : (s.end - num4);

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

                case 1:
                    goto IL_199;

                case 2:
                    num6 = this.get_Renamed;
                    while (i < num6)
                    {
                        if (num2 == 0)
                        {
                            goto IL_34F;
                        }
                        r = 0;
                        num2--;
                        num3 |= (int)(z.next_in[num++] & 255) << i;
                        i    += 8;
                    }
                    this.len       += (num3 & InfCodes.inflate_mask[num6]);
                    num3          >>= num6;
                    i              -= num6;
                    this.need       = (int)this.dbits;
                    this.tree       = this.dtree;
                    this.tree_index = this.dtree_index;
                    this.mode       = 3;
                    goto IL_412;

                case 3:
                    goto IL_412;

                case 4:
                    num6 = this.get_Renamed;
                    while (i < num6)
                    {
                        if (num2 == 0)
                        {
                            goto IL_596;
                        }
                        r = 0;
                        num2--;
                        num3 |= (int)(z.next_in[num++] & 255) << i;
                        i    += 8;
                    }
                    this.dist += (num3 & InfCodes.inflate_mask[num6]);
                    num3     >>= num6;
                    i         -= num6;
                    this.mode  = 5;
                    goto IL_635;

                case 5:
                    goto IL_635;

                case 6:
                    if (num5 == 0)
                    {
                        if (num4 == s.end && s.read != 0)
                        {
                            num4 = 0;
                            num5 = ((num4 < s.read) ? (s.read - num4 - 1) : (s.end - num4));
                        }
                        if (num5 == 0)
                        {
                            s.write = num4;
                            r       = s.inflate_flush(z, r);
                            num4    = s.write;
                            num5    = ((num4 < s.read) ? (s.read - num4 - 1) : (s.end - num4));
                            if (num4 == s.end && s.read != 0)
                            {
                                num4 = 0;
                                num5 = ((num4 < s.read) ? (s.read - num4 - 1) : (s.end - num4));
                            }
                            if (num5 == 0)
                            {
                                goto Block_44;
                            }
                        }
                    }
                    r = 0;
                    s.window[num4++] = (byte)this.lit;
                    num5--;
                    this.mode = 0;
                    continue;

                case 7:
                    goto IL_8DB;

                case 8:
                    goto IL_98A;

                case 9:
                    goto IL_9D4;
                }
                break;
IL_199:
                num6 = this.need;
                while (i < num6)
                {
                    if (num2 == 0)
                    {
                        goto IL_1AB;
                    }
                    r = 0;
                    num2--;
                    num3 |= (int)(z.next_in[num++] & 255) << i;
                    i    += 8;
                }
                int num7 = (this.tree_index + (num3 & InfCodes.inflate_mask[num6])) * 3;
                num3 = SupportClass.URShift(num3, this.tree[num7 + 1]);
                i   -= this.tree[num7 + 1];
                int num8 = this.tree[num7];
                if (num8 == 0)
                {
                    this.lit  = this.tree[num7 + 2];
                    this.mode = 6;
                    continue;
                }
                if ((num8 & 16) != 0)
                {
                    this.get_Renamed = (num8 & 15);
                    this.len         = this.tree[num7 + 2];
                    this.mode        = 2;
                    continue;
                }
                if ((num8 & 64) == 0)
                {
                    this.need       = num8;
                    this.tree_index = num7 / 3 + this.tree[num7 + 2];
                    continue;
                }
                if ((num8 & 32) != 0)
                {
                    this.mode = 7;
                    continue;
                }
                goto IL_2DF;
IL_412:
                num6 = this.need;
                while (i < num6)
                {
                    if (num2 == 0)
                    {
                        goto IL_424;
                    }
                    r = 0;
                    num2--;
                    num3 |= (int)(z.next_in[num++] & 255) << i;
                    i    += 8;
                }
                num7   = (this.tree_index + (num3 & InfCodes.inflate_mask[num6])) * 3;
                num3 >>= this.tree[num7 + 1];
                i     -= this.tree[num7 + 1];
                num8   = this.tree[num7];
                if ((num8 & 16) != 0)
                {
                    this.get_Renamed = (num8 & 15);
                    this.dist        = this.tree[num7 + 2];
                    this.mode        = 4;
                    continue;
                }
                if ((num8 & 64) == 0)
                {
                    this.need       = num8;
                    this.tree_index = num7 / 3 + this.tree[num7 + 2];
                    continue;
                }
                goto IL_526;
IL_635:
                int j;
                for (j = num4 - this.dist; j < 0; j += s.end)
                {
                }
                while (this.len != 0)
                {
                    if (num5 == 0)
                    {
                        if (num4 == s.end && s.read != 0)
                        {
                            num4 = 0;
                            num5 = ((num4 < s.read) ? (s.read - num4 - 1) : (s.end - num4));
                        }
                        if (num5 == 0)
                        {
                            s.write = num4;
                            r       = s.inflate_flush(z, r);
                            num4    = s.write;
                            num5    = ((num4 < s.read) ? (s.read - num4 - 1) : (s.end - num4));
                            if (num4 == s.end && s.read != 0)
                            {
                                num4 = 0;
                                num5 = ((num4 < s.read) ? (s.read - num4 - 1) : (s.end - num4));
                            }
                            if (num5 == 0)
                            {
                                goto Block_32;
                            }
                        }
                    }
                    s.window[num4++] = s.window[j++];
                    num5--;
                    if (j == s.end)
                    {
                        j = 0;
                    }
                    this.len--;
                }
                this.mode = 0;
            }
            r               = -2;
            s.bitb          = num3;
            s.bitk          = i;
            z.avail_in      = num2;
            z.total_in     += (long)(num - z.next_in_index);
            z.next_in_index = num;
            s.write         = num4;
            return(s.inflate_flush(z, r));

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

IL_2DF:
            this.mode       = 9;
            z.msg           = "invalid literal/length code";
            r               = -3;
            s.bitb          = num3;
            s.bitk          = i;
            z.avail_in      = num2;
            z.total_in     += (long)(num - z.next_in_index);
            z.next_in_index = num;
            s.write         = num4;
            return(s.inflate_flush(z, r));

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

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

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

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

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

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

IL_8DB:
            if (i > 7)
            {
                i -= 8;
                num2++;
                num--;
            }
            s.write = num4;
            r       = s.inflate_flush(z, r);
            num4    = s.write;
            int arg_92C_0 = (num4 < s.read) ? (s.read - num4 - 1) : (s.end - num4);

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

IL_9D4:
            r               = -3;
            s.bitb          = num3;
            s.bitk          = i;
            z.avail_in      = num2;
            z.total_in     += (long)(num - z.next_in_index);
            z.next_in_index = num;
            s.write         = num4;
            return(s.inflate_flush(z, r));
        }
        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);
        }
Exemple #6
0
        internal int proc(InfBlocks s, ZStream z, int r)
        {
            int num1;
            int num10;
            int num4 = 0;
            int num5 = 0;
            int num6 = 0;
            num6 = z.next_in_index;
            int num7 = z.avail_in;
            num4 = s.bitb;
            num5 = s.bitk;
            int num8 = s.write;
            int num9 = (num8 < s.read) ? ((s.read - num8) - 1) : (s.end - num8);
        Label_0051:
            switch (this.mode)
            {
                case 0:
                    if ((num9 < 0x102) || (num7 < 10))
                    {
                        break;
                    }
                    s.bitb = num4;
                    s.bitk = num5;
                    z.avail_in = num7;
                    z.total_in += num6 - z.next_in_index;
                    z.next_in_index = num6;
                    s.write = num8;
                    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;
                    num4 = s.bitb;
                    num5 = s.bitk;
                    num8 = s.write;
                    num9 = (num8 < s.read) ? ((s.read - num8) - 1) : (s.end - num8);
                    if (r == 0)
                    {
                        break;
                    }
                    this.mode = (r == 1) ? 7 : 9;
                    goto Label_0051;

                case 1:
                    goto Label_0199;

                case 2:
                    num1 = this.get_Renamed;
                    while (num5 < num1)
                    {
                        if (num7 != 0)
                        {
                            r = 0;
                        }
                        else
                        {
                            s.bitb = num4;
                            s.bitk = num5;
                            z.avail_in = num7;
                            z.total_in += num6 - z.next_in_index;
                            z.next_in_index = num6;
                            s.write = num8;
                            return s.inflate_flush(z, r);
                        }
                        num7--;
                        num4 |= (z.next_in[num6++] & 0xff) << (num5 & 0x1f);
                        num5 += 8;
                    }
                    this.len += num4 & InfCodes.inflate_mask[num1];
                    num4 = num4 >> (num1 & 0x1f);
                    num5 -= num1;
                    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:
                    num1 = this.get_Renamed;
                    while (num5 < num1)
                    {
                        if (num7 != 0)
                        {
                            r = 0;
                        }
                        else
                        {
                            s.bitb = num4;
                            s.bitk = num5;
                            z.avail_in = num7;
                            z.total_in += num6 - z.next_in_index;
                            z.next_in_index = num6;
                            s.write = num8;
                            return s.inflate_flush(z, r);
                        }
                        num7--;
                        num4 |= (z.next_in[num6++] & 0xff) << (num5 & 0x1f);
                        num5 += 8;
                    }
                    this.dist += num4 & InfCodes.inflate_mask[num1];
                    num4 = num4 >> (num1 & 0x1f);
                    num5 -= num1;
                    this.mode = 5;
                    goto Label_0635;

                case 5:
                    goto Label_0635;

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

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

                case 8:
                    goto Label_098A;

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

                default:
                    r = -2;
                    s.bitb = num4;
                    s.bitk = num5;
                    z.avail_in = num7;
                    z.total_in += num6 - z.next_in_index;
                    z.next_in_index = num6;
                    s.write = num8;
                    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:
            num1 = this.need;
            while (num5 < num1)
            {
                if (num7 != 0)
                {
                    r = 0;
                }
                else
                {
                    s.bitb = num4;
                    s.bitk = num5;
                    z.avail_in = num7;
                    z.total_in += num6 - z.next_in_index;
                    z.next_in_index = num6;
                    s.write = num8;
                    return s.inflate_flush(z, r);
                }
                num7--;
                num4 |= (z.next_in[num6++] & 0xff) << (num5 & 0x1f);
                num5 += 8;
            }
            int num2 = (this.tree_index + (num4 & InfCodes.inflate_mask[num1])) * 3;
            num4 = SupportClass.URShift(num4, this.tree[num2 + 1]);
            num5 -= this.tree[num2 + 1];
            int num3 = this.tree[num2];
            if (num3 == 0)
            {
                this.lit = this.tree[num2 + 2];
                this.mode = 6;
                goto Label_0051;
            }
            if ((num3 & 0x10) != 0)
            {
                this.get_Renamed = num3 & 15;
                this.len = this.tree[num2 + 2];
                this.mode = 2;
                goto Label_0051;
            }
            if ((num3 & 0x40) == 0)
            {
                this.need = num3;
                this.tree_index = (num2 / 3) + this.tree[num2 + 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 = num4;
            s.bitk = num5;
            z.avail_in = num7;
            z.total_in += num6 - z.next_in_index;
            z.next_in_index = num6;
            s.write = num8;
            return s.inflate_flush(z, r);
        Label_0412:
            num1 = this.need;
            while (num5 < num1)
            {
                if (num7 != 0)
                {
                    r = 0;
                }
                else
                {
                    s.bitb = num4;
                    s.bitk = num5;
                    z.avail_in = num7;
                    z.total_in += num6 - z.next_in_index;
                    z.next_in_index = num6;
                    s.write = num8;
                    return s.inflate_flush(z, r);
                }
                num7--;
                num4 |= (z.next_in[num6++] & 0xff) << (num5 & 0x1f);
                num5 += 8;
            }
            num2 = (this.tree_index + (num4 & InfCodes.inflate_mask[num1])) * 3;
            num4 = num4 >> (this.tree[num2 + 1] & 0x1f);
            num5 -= this.tree[num2 + 1];
            num3 = this.tree[num2];
            if ((num3 & 0x10) != 0)
            {
                this.get_Renamed = num3 & 15;
                this.dist = this.tree[num2 + 2];
                this.mode = 4;
                goto Label_0051;
            }
            if ((num3 & 0x40) == 0)
            {
                this.need = num3;
                this.tree_index = (num2 / 3) + this.tree[num2 + 2];
                goto Label_0051;
            }
            this.mode = 9;
            z.msg = "invalid distance code";
            r = -3;
            s.bitb = num4;
            s.bitk = num5;
            z.avail_in = num7;
            z.total_in += num6 - z.next_in_index;
            z.next_in_index = num6;
            s.write = num8;
            return s.inflate_flush(z, r);
        Label_0635:
            num10 = num8 - this.dist;
            while (num10 < 0)
            {
                num10 += s.end;
            }
            while (this.len != 0)
            {
                if (num9 == 0)
                {
                    if ((num8 == s.end) && (s.read != 0))
                    {
                        num8 = 0;
                        num9 = (num8 < s.read) ? ((s.read - num8) - 1) : (s.end - num8);
                    }
                    if (num9 == 0)
                    {
                        s.write = num8;
                        r = s.inflate_flush(z, r);
                        num8 = s.write;
                        num9 = (num8 < s.read) ? ((s.read - num8) - 1) : (s.end - num8);
                        if ((num8 == s.end) && (s.read != 0))
                        {
                            num8 = 0;
                            num9 = (num8 < s.read) ? ((s.read - num8) - 1) : (s.end - num8);
                        }
                        if (num9 == 0)
                        {
                            s.bitb = num4;
                            s.bitk = num5;
                            z.avail_in = num7;
                            z.total_in += num6 - z.next_in_index;
                            z.next_in_index = num6;
                            s.write = num8;
                            return s.inflate_flush(z, r);
                        }
                    }
                }
                s.window[num8++] = s.window[num10++];
                num9--;
                if (num10 == s.end)
                {
                    num10 = 0;
                }
                this.len--;
            }
            this.mode = 0;
            goto Label_0051;
        Label_098A:
            r = 1;
            s.bitb = num4;
            s.bitk = num5;
            z.avail_in = num7;
            z.total_in += num6 - z.next_in_index;
            z.next_in_index = num6;
            s.write = num8;
            return s.inflate_flush(z, r);
        }