inflate_flush() private method

private inflate_flush ( ZStream z, int r ) : int
z ZStream
r int
return int
Ejemplo n.º 1
0
        internal int proc(InfBlocks s, ZStream z, int r)
        {
            int j;              // temporary storage
            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 >>= (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  = 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;

                    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  = 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;

                    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));
                }
            }
        }
Ejemplo n.º 2
0
        internal int proc(InfBlocks s, ZStream z, int r){ 
            int j;              // temporary storage
            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>>=(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 = 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;

                        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 = 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;

                        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);
                }
            }
        }
Ejemplo n.º 3
0
        internal int proc(InfBlocks s, ZStream z, int r)
        {
            int get;
            int num10;
            int bitb = 0;
            int bitk = 0;
            int num6 = 0;

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

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

Label_0057:
            switch (this.mode)
            {
            case 0:
                if ((num9 < 0x102) || (num7 < 10))
                {
                    break;
                }
                s.bitb          = bitb;
                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;
                bitb  = s.bitb;
                bitk  = s.bitk;
                write = s.write;
                num9  = (write >= s.read) ? (s.end - write) : ((s.read - write) - 1);
                if (r == 0)
                {
                    break;
                }
                this.mode = (r != 1) ? 9 : 7;
                goto Label_0057;

            case 1:
                goto Label_01B3;

            case 2:
                get = this.get;
                while (bitk < get)
                {
                    if (num7 != 0)
                    {
                        r = 0;
                    }
                    else
                    {
                        s.bitb          = bitb;
                        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--;
                    bitb |= (z.next_in[num6++] & 0xff) << bitk;
                    bitk += 8;
                }
                this.len       += bitb & inflate_mask[get];
                bitb            = bitb >> get;
                bitk           -= get;
                this.need       = this.dbits;
                this.tree       = this.dtree;
                this.tree_index = this.dtree_index;
                this.mode       = 3;
                goto Label_0454;

            case 3:
                goto Label_0454;

            case 4:
                get = this.get;
                while (bitk < get)
                {
                    if (num7 != 0)
                    {
                        r = 0;
                    }
                    else
                    {
                        s.bitb          = bitb;
                        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--;
                    bitb |= (z.next_in[num6++] & 0xff) << bitk;
                    bitk += 8;
                }
                this.dist += bitb & inflate_mask[get];
                bitb       = bitb >> get;
                bitk      -= get;
                this.mode  = 5;
                goto Label_069A;

            case 5:
                goto Label_069A;

            case 6:
                if (num9 == 0)
                {
                    if ((write == s.end) && (s.read != 0))
                    {
                        write = 0;
                        num9  = (write >= s.read) ? (s.end - write) : ((s.read - write) - 1);
                    }
                    if (num9 == 0)
                    {
                        s.write = write;
                        r       = s.inflate_flush(z, r);
                        write   = s.write;
                        num9    = (write >= s.read) ? (s.end - write) : ((s.read - write) - 1);
                        if ((write == s.end) && (s.read != 0))
                        {
                            write = 0;
                            num9  = (write >= s.read) ? (s.end - write) : ((s.read - write) - 1);
                        }
                        if (num9 == 0)
                        {
                            s.bitb          = bitb;
                            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_0057;

            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.end - write) : ((s.read - write) - 1);
                if (s.read != s.write)
                {
                    s.bitb          = bitb;
                    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_0A4B;

            case 8:
                goto Label_0A4B;

            case 9:
                r               = -3;
                s.bitb          = bitb;
                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          = bitb;
                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_01B3:
            get = this.need;
            while (bitk < get)
            {
                if (num7 != 0)
                {
                    r = 0;
                }
                else
                {
                    s.bitb          = bitb;
                    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--;
                bitb |= (z.next_in[num6++] & 0xff) << bitk;
                bitk += 8;
            }
            int index = (this.tree_index + (bitb & inflate_mask[get])) * 3;

            bitb  = bitb >> 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_0057;
            }
            if ((num3 & 0x10) != 0)
            {
                this.get  = num3 & 15;
                this.len  = this.tree[index + 2];
                this.mode = 2;
                goto Label_0057;
            }
            if ((num3 & 0x40) == 0)
            {
                this.need       = num3;
                this.tree_index = (index / 3) + this.tree[index + 2];
                goto Label_0057;
            }
            if ((num3 & 0x20) != 0)
            {
                this.mode = 7;
                goto Label_0057;
            }
            this.mode       = 9;
            z.msg           = "invalid literal/length code";
            r               = -3;
            s.bitb          = bitb;
            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_0454:
            get = this.need;
            while (bitk < get)
            {
                if (num7 != 0)
                {
                    r = 0;
                }
                else
                {
                    s.bitb          = bitb;
                    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--;
                bitb |= (z.next_in[num6++] & 0xff) << bitk;
                bitk += 8;
            }
            index = (this.tree_index + (bitb & inflate_mask[get])) * 3;
            bitb  = bitb >> this.tree[index + 1];
            bitk -= this.tree[index + 1];
            num3  = this.tree[index];
            if ((num3 & 0x10) != 0)
            {
                this.get  = num3 & 15;
                this.dist = this.tree[index + 2];
                this.mode = 4;
                goto Label_0057;
            }
            if ((num3 & 0x40) == 0)
            {
                this.need       = num3;
                this.tree_index = (index / 3) + this.tree[index + 2];
                goto Label_0057;
            }
            this.mode       = 9;
            z.msg           = "invalid distance code";
            r               = -3;
            s.bitb          = bitb;
            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_069A:
            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.end - write) : ((s.read - write) - 1);
                    }
                    if (num9 == 0)
                    {
                        s.write = write;
                        r       = s.inflate_flush(z, r);
                        write   = s.write;
                        num9    = (write >= s.read) ? (s.end - write) : ((s.read - write) - 1);
                        if ((write == s.end) && (s.read != 0))
                        {
                            write = 0;
                            num9  = (write >= s.read) ? (s.end - write) : ((s.read - write) - 1);
                        }
                        if (num9 == 0)
                        {
                            s.bitb          = bitb;
                            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_0057;
Label_0A4B:
            r               = 1;
            s.bitb          = bitb;
            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));
        }
Ejemplo n.º 4
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 num8;
                    for (num8 = need; num2 < num8; num2 += 8)
                    {
                        if (num4 == 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;
                        num4--;
                        num |= (z.next_in[num3++] & 0xFF) << num2;
                    }
                    int num11 = (tree_index + (num & inflate_mask[num8])) * 3;
                    num >>= tree[num11 + 1];
                    num2 -= tree[num11 + 1];
                    int num12 = tree[num11];
                    if (num12 == 0)
                    {
                        lit  = tree[num11 + 2];
                        mode = 6;
                    }
                    else if ((num12 & 0x10) != 0)
                    {
                        get  = (num12 & 0xF);
                        len  = tree[num11 + 2];
                        mode = 2;
                    }
                    else if ((num12 & 0x40) == 0)
                    {
                        need       = num12;
                        tree_index = num11 / 3 + tree[num11 + 2];
                    }
                    else
                    {
                        if ((num12 & 0x20) == 0)
                        {
                            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));
                        }
                        mode = 7;
                    }
                    break;
                }

                case 2:
                {
                    int num8;
                    for (num8 = get; num2 < num8; num2 += 8)
                    {
                        if (num4 == 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;
                        num4--;
                        num |= (z.next_in[num3++] & 0xFF) << num2;
                    }
                    len       += (num & inflate_mask[num8]);
                    num      >>= num8;
                    num2      -= num8;
                    need       = dbits;
                    tree       = dtree;
                    tree_index = dtree_index;
                    mode       = 3;
                    goto case 3;
                }

                case 3:
                {
                    int num8;
                    for (num8 = need; num2 < num8; num2 += 8)
                    {
                        if (num4 == 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;
                        num4--;
                        num |= (z.next_in[num3++] & 0xFF) << num2;
                    }
                    int num11 = (tree_index + (num & inflate_mask[num8])) * 3;
                    num >>= tree[num11 + 1];
                    num2 -= tree[num11 + 1];
                    int num12 = tree[num11];
                    if ((num12 & 0x10) != 0)
                    {
                        get  = (num12 & 0xF);
                        dist = tree[num11 + 2];
                        mode = 4;
                    }
                    else
                    {
                        if ((num12 & 0x40) != 0)
                        {
                            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));
                        }
                        need       = num12;
                        tree_index = num11 / 3 + tree[num11 + 2];
                    }
                    break;
                }

                case 4:
                {
                    int num8;
                    for (num8 = get; num2 < num8; num2 += 8)
                    {
                        if (num4 == 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;
                        num4--;
                        num |= (z.next_in[num3++] & 0xFF) << num2;
                    }
                    dist += (num & inflate_mask[num8]);
                    num >>= num8;
                    num2 -= num8;
                    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));
                }
            }
        }
Ejemplo n.º 5
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;
                    while (i < num6)
                    {
                        if (num2 == 0)
                        {
                            goto IL_34E;
                        }
                        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_411;

                case 3:
                    goto IL_411;

                case 4:
                    num6 = this.get;
                    while (i < num6)
                    {
                        if (num2 == 0)
                        {
                            goto IL_595;
                        }
                        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_634;

                case 5:
                    goto IL_634;

                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_8DA;

                case 8:
                    goto IL_989;

                case 9:
                    goto IL_9D3;
                }
                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 >>= 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  = (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_2DE;
IL_411:
                num6 = this.need;
                while (i < num6)
                {
                    if (num2 == 0)
                    {
                        goto IL_423;
                    }
                    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  = (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_525;
IL_634:
                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_2DE:
            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_34E:
            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_423:
            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_525:
            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_595:
            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_8DA:
            if (i > 7)
            {
                i -= 8;
                num2++;
                num--;
            }
            s.write = num4;
            r       = s.inflate_flush(z, r);
            num4    = s.write;
            int arg_92B_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_989:
            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_9D3:
            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));
        }