Beispiel #1
0
        internal int deflate(ZStream strm, int flush)
        {
            if ((flush > 4) || (flush < 0))
            {
                return(-2);
            }
            if (((strm.next_out == null) || ((strm.next_in == null) && (strm.avail_in != 0))) || ((this.status == 0x29a) && (flush != 4)))
            {
                strm.msg = z_errmsg[4];
                return(-2);
            }
            if (strm.avail_out == 0)
            {
                strm.msg = z_errmsg[7];
                return(-5);
            }
            this.strm = strm;
            int num = this.last_flush;

            this.last_flush = flush;
            if (this.status == 0x2a)
            {
                int b    = (8 + ((this.w_bits - 8) << 4)) << 8;
                int num3 = ((this.level - 1) & 0xff) >> 1;
                if (num3 > 3)
                {
                    num3 = 3;
                }
                b |= num3 << 6;
                if (this.strstart != 0)
                {
                    b |= 0x20;
                }
                b          += 0x1f - (b % 0x1f);
                this.status = 0x71;
                this.putShortMSB(b);
                if (this.strstart != 0)
                {
                    this.putShortMSB((int)SupportClass.URShift(strm.adler, 0x10));
                    this.putShortMSB((int)(strm.adler & 0xffffL));
                }
                strm.adler = strm._adler.adler32(0L, null, 0, 0);
            }
            if (this.pending != 0)
            {
                strm.flush_pending();
                if (strm.avail_out == 0)
                {
                    this.last_flush = -1;
                    return(0);
                }
            }
            else if (((strm.avail_in == 0) && (flush <= num)) && (flush != 4))
            {
                strm.msg = z_errmsg[7];
                return(-5);
            }
            if ((this.status == 0x29a) && (strm.avail_in != 0))
            {
                strm.msg = z_errmsg[7];
                return(-5);
            }
            if (((strm.avail_in != 0) || (this.lookahead != 0)) || ((flush != 0) && (this.status != 0x29a)))
            {
                int num4 = -1;
                switch (config_table[this.level].func)
                {
                case 0:
                    num4 = this.deflate_stored(flush);
                    break;

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

                case 2:
                    num4 = this.deflate_slow(flush);
                    break;
                }
                switch (num4)
                {
                case 2:
                case 3:
                    this.status = 0x29a;
                    break;
                }
                if ((num4 == 0) || (num4 == 2))
                {
                    if (strm.avail_out == 0)
                    {
                        this.last_flush = -1;
                    }
                    return(0);
                }
                if (num4 == 1)
                {
                    if (flush == 1)
                    {
                        this._tr_align();
                    }
                    else
                    {
                        this._tr_stored_block(0, 0, false);
                        if (flush == 3)
                        {
                            for (int i = 0; i < this.hash_size; i++)
                            {
                                this.head[i] = 0;
                            }
                        }
                    }
                    strm.flush_pending();
                    if (strm.avail_out == 0)
                    {
                        this.last_flush = -1;
                        return(0);
                    }
                }
            }
            if (flush == 4)
            {
                if (this.noheader != 0)
                {
                    return(1);
                }
                this.putShortMSB((int)SupportClass.URShift(strm.adler, 0x10));
                this.putShortMSB((int)(strm.adler & 0xffffL));
                strm.flush_pending();
                this.noheader = -1;
                if (this.pending == 0)
                {
                    return(1);
                }
            }
            return(0);
        }
Beispiel #2
0
 internal void put_short(int w)
 {
     this.put_byte((byte)w);
     this.put_byte((byte)SupportClass.URShift(w, 8));
 }
Beispiel #3
0
        internal static int huft_build(int[] b, int bindex, int n, int s, int[] d, int[] e, int[] t, int[] m, int[] hp, int[] hn, int[] v)
        {
            int[] numArray    = new int[0x10];
            int[] sourceArray = new int[3];
            int[] numArray3   = new int[15];
            int[] numArray4   = new int[0x10];
            int   index       = 0;
            int   num5        = n;

            do
            {
                numArray[b[bindex + index]]++;
                index++;
                num5--;
            }while(num5 != 0);
            if (numArray[0] == n)
            {
                t[0] = -1;
                m[0] = 0;
                return(0);
            }
            int num8 = m[0];
            int num6 = 1;

            while (num6 <= 15)
            {
                if (numArray[num6] != 0)
                {
                    break;
                }
                num6++;
            }
            int num7 = num6;

            if (num8 < num6)
            {
                num8 = num6;
            }
            num5 = 15;
            while (num5 != 0)
            {
                if (numArray[num5] != 0)
                {
                    break;
                }
                num5--;
            }
            int num3 = num5;

            if (num8 > num5)
            {
                num8 = num5;
            }
            m[0] = num8;
            int num14 = ((int)1) << num6;

            while (num6 < num5)
            {
                num14 -= numArray[num6];
                if (num14 < 0)
                {
                    return(-3);
                }
                num6++;
                num14 = num14 << 1;
            }
            num14 -= numArray[num5];
            if (num14 < 0)
            {
                return(-3);
            }
            numArray[num5] += num14;
            numArray4[1]    = num6 = 0;
            index           = 1;
            int num13 = 2;

            while (--num5 != 0)
            {
                numArray4[num13] = num6 += numArray[index];
                num13++;
                index++;
            }
            num5  = 0;
            index = 0;
            do
            {
                num6 = b[bindex + index];
                if (num6 != 0)
                {
                    v[numArray4[num6]++] = num5;
                }
                index++;
            }while(++num5 < n);
            n            = numArray4[num3];
            numArray4[0] = num5 = 0;
            index        = 0;
            int num4 = -1;
            int bits = -num8;

            numArray3[0] = 0;
            int num11 = 0;
            int num15 = 0;

            while (num7 <= num3)
            {
                int num2;
                int num = numArray[num7];
                goto Label_03BD;
Label_01B2:
                num4++;
                bits += num8;
                num15 = num3 - bits;
                num15 = (num15 > num8) ? num8 : num15;
                if ((num2 = ((int)1) << (num6 = num7 - bits)) > (num + 1))
                {
                    num2 -= num + 1;
                    num13 = num7;
                    if (num6 < num15)
                    {
                        while (++num6 < num15)
                        {
                            if ((num2 = num2 << 1) <= numArray[++num13])
                            {
                                break;
                            }
                            num2 -= numArray[num13];
                        }
                    }
                }
                num15 = ((int)1) << num6;
                if ((hn[0] + num15) > 0x5a0)
                {
                    return(-3);
                }
                numArray3[num4] = num11 = hn[0];
                hn[0]          += num15;
                if (num4 != 0)
                {
                    numArray4[num4] = num5;
                    sourceArray[0]  = (byte)num6;
                    sourceArray[1]  = (byte)num8;
                    num6            = SupportClass.URShift(num5, (int)(bits - num8));
                    sourceArray[2]  = (num11 - numArray3[num4 - 1]) - num6;
                    Array.Copy(sourceArray, 0, hp, (numArray3[num4 - 1] + num6) * 3, 3);
                }
                else
                {
                    t[0] = num11;
                }
Label_02AE:
                if (num7 > (bits + num8))
                {
                    goto Label_01B2;
                }
                sourceArray[1] = (byte)(num7 - bits);
                if (index >= n)
                {
                    sourceArray[0] = 0xc0;
                }
                else if (v[index] < s)
                {
                    sourceArray[0] = (v[index] < 0x100) ? ((byte)0) : ((byte)0x60);
                    sourceArray[2] = v[index++];
                }
                else
                {
                    sourceArray[0] = (byte)((e[v[index] - s] + 0x10) + 0x40);
                    sourceArray[2] = d[v[index++] - s];
                }
                num2 = ((int)1) << (num7 - bits);
                num6 = SupportClass.URShift(num5, bits);
                while (num6 < num15)
                {
                    Array.Copy(sourceArray, 0, hp, (num11 + num6) * 3, 3);
                    num6 += num2;
                }
                num6 = ((int)1) << (num7 - 1);
                while ((num5 & num6) != 0)
                {
                    num5 ^= num6;
                    num6  = SupportClass.URShift(num6, 1);
                }
                num5 ^= num6;
                for (int i = (((int)1) << bits) - 1; (num5 & i) != numArray4[num4]; i = (((int)1) << bits) - 1)
                {
                    num4--;
                    bits -= num8;
                }
Label_03BD:
                if (num-- != 0)
                {
                    goto Label_02AE;
                }
                num7++;
            }
            if ((num14 != 0) && (num3 != 1))
            {
                return(-5);
            }
            return(0);
        }
Beispiel #4
0
        public int read(byte[] b, int off, int len)
        {
            int num;

            if (len == 0)
            {
                return(0);
            }
            this.z.next_out       = b;
            this.z.next_out_index = off;
            this.z.avail_out      = len;
            do
            {
                if ((this.z.avail_in == 0) && !this.nomoreinput)
                {
                    this.z.next_in_index = 0;
                    int bufsize = this.bufsize;
                    if (this.maxInput > 0L)
                    {
                        if (this.TotalIn < this.maxInput)
                        {
                            bufsize = (int)Math.Min(this.maxInput - this.TotalIn, (long)this.bufsize);
                        }
                        else
                        {
                            this.z.avail_in = -1;
                        }
                    }
                    if (this.z.avail_in != -1)
                    {
                        this.z.avail_in = SupportClass.ReadInput(this.in_Renamed, this.buf, 0, bufsize);
                    }
                    if (this.z.avail_in == -1)
                    {
                        this.z.avail_in  = 0;
                        this.nomoreinput = true;
                    }
                }
                if (this.compress)
                {
                    num = this.z.deflate(this.flush);
                }
                else
                {
                    num = this.z.inflate(this.flush);
                }
                if (this.nomoreinput && (num == -5))
                {
                    return(-1);
                }
                if ((num != 0) && (num != 1))
                {
                    throw new ZStreamException((this.compress ? "de" : "in") + "flating: " + this.z.msg);
                }
                if (this.nomoreinput && (this.z.avail_out == len))
                {
                    return(-1);
                }
            }while((this.z.avail_out > 0) && (num == 0));
            return(len - this.z.avail_out);
        }
Beispiel #5
0
        internal int proc(ZStream z, int r)
        {
            int table;
            int sourceIndex = z.next_in_index;
            int num5        = z.avail_in;
            int bitb        = this.bitb;
            int bitk        = this.bitk;
            int write       = this.write;
            int num7        = (write < this.read) ? ((this.read - write) - 1) : (this.end - write);

Label_0047:
            switch (this.mode)
            {
            case 0:
                while (bitk < 3)
                {
                    if (num5 != 0)
                    {
                        r = 0;
                    }
                    else
                    {
                        this.bitb       = bitb;
                        this.bitk       = bitk;
                        z.avail_in      = num5;
                        z.total_in     += sourceIndex - z.next_in_index;
                        z.next_in_index = sourceIndex;
                        this.write      = write;
                        return(this.inflate_flush(z, r));
                    }
                    num5--;
                    bitb |= (z.next_in[sourceIndex++] & 0xff) << bitk;
                    bitk += 8;
                }
                table     = bitb & 7;
                this.last = table & 1;
                switch (SupportClass.URShift(table, 1))
                {
                case 0:
                    bitb      = SupportClass.URShift(bitb, 3);
                    bitk     -= 3;
                    table     = bitk & 7;
                    bitb      = SupportClass.URShift(bitb, table);
                    bitk     -= table;
                    this.mode = 1;
                    goto Label_0047;

                case 1: {
                    int[]   numArray  = new int[1];
                    int[]   numArray2 = new int[1];
                    int[][] numArray3 = new int[1][];
                    int[][] numArray4 = new int[1][];
                    InfTree.inflate_trees_fixed(numArray, numArray2, numArray3, numArray4, z);
                    this.codes = new InfCodes(numArray[0], numArray2[0], numArray3[0], numArray4[0], z);
                    bitb       = SupportClass.URShift(bitb, 3);
                    bitk      -= 3;
                    this.mode  = 6;
                    goto Label_0047;
                }

                case 2:
                    bitb      = SupportClass.URShift(bitb, 3);
                    bitk     -= 3;
                    this.mode = 3;
                    goto Label_0047;

                case 3:
                    bitb            = SupportClass.URShift(bitb, 3);
                    bitk           -= 3;
                    this.mode       = 9;
                    z.msg           = "invalid block type";
                    r               = -3;
                    this.bitb       = bitb;
                    this.bitk       = bitk;
                    z.avail_in      = num5;
                    z.total_in     += sourceIndex - z.next_in_index;
                    z.next_in_index = sourceIndex;
                    this.write      = write;
                    return(this.inflate_flush(z, r));
                }
                goto Label_0047;

            case 1:
                while (bitk < 0x20)
                {
                    if (num5 != 0)
                    {
                        r = 0;
                    }
                    else
                    {
                        this.bitb       = bitb;
                        this.bitk       = bitk;
                        z.avail_in      = num5;
                        z.total_in     += sourceIndex - z.next_in_index;
                        z.next_in_index = sourceIndex;
                        this.write      = write;
                        return(this.inflate_flush(z, r));
                    }
                    num5--;
                    bitb |= (z.next_in[sourceIndex++] & 0xff) << bitk;
                    bitk += 8;
                }
                if ((SupportClass.URShift(~bitb, 0x10) & 0xffff) != (bitb & 0xffff))
                {
                    this.mode       = 9;
                    z.msg           = "invalid stored block lengths";
                    r               = -3;
                    this.bitb       = bitb;
                    this.bitk       = bitk;
                    z.avail_in      = num5;
                    z.total_in     += sourceIndex - z.next_in_index;
                    z.next_in_index = sourceIndex;
                    this.write      = write;
                    return(this.inflate_flush(z, r));
                }
                this.left = bitb & 0xffff;
                bitb      = bitk = 0;
                this.mode = (this.left != 0) ? 2 : ((this.last != 0) ? 7 : 0);
                goto Label_0047;

            case 2:
                if (num5 != 0)
                {
                    if (num7 == 0)
                    {
                        if ((write == this.end) && (this.read != 0))
                        {
                            write = 0;
                            num7  = (write < this.read) ? ((this.read - write) - 1) : (this.end - write);
                        }
                        if (num7 == 0)
                        {
                            this.write = write;
                            r          = this.inflate_flush(z, r);
                            write      = this.write;
                            num7       = (write < this.read) ? ((this.read - write) - 1) : (this.end - write);
                            if ((write == this.end) && (this.read != 0))
                            {
                                write = 0;
                                num7  = (write < this.read) ? ((this.read - write) - 1) : (this.end - write);
                            }
                            if (num7 == 0)
                            {
                                this.bitb       = bitb;
                                this.bitk       = bitk;
                                z.avail_in      = num5;
                                z.total_in     += sourceIndex - z.next_in_index;
                                z.next_in_index = sourceIndex;
                                this.write      = write;
                                return(this.inflate_flush(z, r));
                            }
                        }
                    }
                    r     = 0;
                    table = this.left;
                    if (table > num5)
                    {
                        table = num5;
                    }
                    if (table > num7)
                    {
                        table = num7;
                    }
                    Array.Copy(z.next_in, sourceIndex, this.window, write, table);
                    sourceIndex += table;
                    num5        -= table;
                    write       += table;
                    num7        -= table;
                    this.left   -= table;
                    if (this.left == 0)
                    {
                        this.mode = (this.last != 0) ? 7 : 0;
                    }
                    goto Label_0047;
                }
                this.bitb       = bitb;
                this.bitk       = bitk;
                z.avail_in      = num5;
                z.total_in     += sourceIndex - z.next_in_index;
                z.next_in_index = sourceIndex;
                this.write      = write;
                return(this.inflate_flush(z, r));

            case 3:
                while (bitk < 14)
                {
                    if (num5 != 0)
                    {
                        r = 0;
                    }
                    else
                    {
                        this.bitb       = bitb;
                        this.bitk       = bitk;
                        z.avail_in      = num5;
                        z.total_in     += sourceIndex - z.next_in_index;
                        z.next_in_index = sourceIndex;
                        this.write      = write;
                        return(this.inflate_flush(z, r));
                    }
                    num5--;
                    bitb |= (z.next_in[sourceIndex++] & 0xff) << bitk;
                    bitk += 8;
                }
                this.table = table = bitb & 0x3fff;
                if (((table & 0x1f) > 0x1d) || (((table >> 5) & 0x1f) > 0x1d))
                {
                    this.mode       = 9;
                    z.msg           = "too many length or distance symbols";
                    r               = -3;
                    this.bitb       = bitb;
                    this.bitk       = bitk;
                    z.avail_in      = num5;
                    z.total_in     += sourceIndex - z.next_in_index;
                    z.next_in_index = sourceIndex;
                    this.write      = write;
                    return(this.inflate_flush(z, r));
                }
                table      = (0x102 + (table & 0x1f)) + ((table >> 5) & 0x1f);
                this.blens = new int[table];
                bitb       = SupportClass.URShift(bitb, 14);
                bitk      -= 14;
                this.index = 0;
                this.mode  = 4;
                break;

            case 4:
                break;

            case 5:
                goto Label_07B9;

            case 6:
                goto Label_0B63;

            case 7:
                goto Label_0C2C;

            case 8:
                goto Label_0CC1;

            case 9:
                r               = -3;
                this.bitb       = bitb;
                this.bitk       = bitk;
                z.avail_in      = num5;
                z.total_in     += sourceIndex - z.next_in_index;
                z.next_in_index = sourceIndex;
                this.write      = write;
                return(this.inflate_flush(z, r));

            default:
                r               = -2;
                this.bitb       = bitb;
                this.bitk       = bitk;
                z.avail_in      = num5;
                z.total_in     += sourceIndex - z.next_in_index;
                z.next_in_index = sourceIndex;
                this.write      = write;
                return(this.inflate_flush(z, r));
            }
            while (this.index < (4 + SupportClass.URShift(this.table, 10)))
            {
                while (bitk < 3)
                {
                    if (num5 != 0)
                    {
                        r = 0;
                    }
                    else
                    {
                        this.bitb       = bitb;
                        this.bitk       = bitk;
                        z.avail_in      = num5;
                        z.total_in     += sourceIndex - z.next_in_index;
                        z.next_in_index = sourceIndex;
                        this.write      = write;
                        return(this.inflate_flush(z, r));
                    }
                    num5--;
                    bitb |= (z.next_in[sourceIndex++] & 0xff) << bitk;
                    bitk += 8;
                }
                this.blens[border[this.index++]] = bitb & 7;
                bitb  = SupportClass.URShift(bitb, 3);
                bitk -= 3;
            }
            while (this.index < 0x13)
            {
                this.blens[border[this.index++]] = 0;
            }
            this.bb[0] = 7;
            table      = InfTree.inflate_trees_bits(this.blens, this.bb, this.tb, this.hufts, z);
            if (table != 0)
            {
                r = table;
                if (r == -3)
                {
                    this.blens = null;
                    this.mode  = 9;
                }
                this.bitb       = bitb;
                this.bitk       = bitk;
                z.avail_in      = num5;
                z.total_in     += sourceIndex - z.next_in_index;
                z.next_in_index = sourceIndex;
                this.write      = write;
                return(this.inflate_flush(z, r));
            }
            this.index = 0;
            this.mode  = 5;
Label_07B9:
            table = this.table;
            if (this.index < ((0x102 + (table & 0x1f)) + ((table >> 5) & 0x1f)))
            {
                table = this.bb[0];
                while (bitk < table)
                {
                    if (num5 != 0)
                    {
                        r = 0;
                    }
                    else
                    {
                        this.bitb       = bitb;
                        this.bitk       = bitk;
                        z.avail_in      = num5;
                        z.total_in     += sourceIndex - z.next_in_index;
                        z.next_in_index = sourceIndex;
                        this.write      = write;
                        return(this.inflate_flush(z, r));
                    }
                    num5--;
                    bitb |= (z.next_in[sourceIndex++] & 0xff) << bitk;
                    bitk += 8;
                }
                int num1 = this.tb[0];
                table = this.hufts[((this.tb[0] + (bitb & inflate_mask[table])) * 3) + 1];
                int num10 = this.hufts[((this.tb[0] + (bitb & inflate_mask[table])) * 3) + 2];
                if (num10 < 0x10)
                {
                    bitb  = SupportClass.URShift(bitb, table);
                    bitk -= table;
                    this.blens[this.index++] = num10;
                }
                else
                {
                    int index = (num10 == 0x12) ? 7 : (num10 - 14);
                    int num9  = (num10 == 0x12) ? 11 : 3;
                    while (bitk < (table + index))
                    {
                        if (num5 != 0)
                        {
                            r = 0;
                        }
                        else
                        {
                            this.bitb       = bitb;
                            this.bitk       = bitk;
                            z.avail_in      = num5;
                            z.total_in     += sourceIndex - z.next_in_index;
                            z.next_in_index = sourceIndex;
                            this.write      = write;
                            return(this.inflate_flush(z, r));
                        }
                        num5--;
                        bitb |= (z.next_in[sourceIndex++] & 0xff) << bitk;
                        bitk += 8;
                    }
                    bitb  = SupportClass.URShift(bitb, table);
                    bitk -= table;
                    num9 += bitb & inflate_mask[index];
                    bitb  = SupportClass.URShift(bitb, index);
                    bitk -= index;
                    index = this.index;
                    table = this.table;
                    if (((index + num9) > ((0x102 + (table & 0x1f)) + ((table >> 5) & 0x1f))) || ((num10 == 0x10) && (index < 1)))
                    {
                        this.blens      = null;
                        this.mode       = 9;
                        z.msg           = "invalid bit length repeat";
                        r               = -3;
                        this.bitb       = bitb;
                        this.bitk       = bitk;
                        z.avail_in      = num5;
                        z.total_in     += sourceIndex - z.next_in_index;
                        z.next_in_index = sourceIndex;
                        this.write      = write;
                        return(this.inflate_flush(z, r));
                    }
                    num10 = (num10 == 0x10) ? this.blens[index - 1] : 0;
                    do
                    {
                        this.blens[index++] = num10;
                    }while(--num9 != 0);
                    this.index = index;
                }
                goto Label_07B9;
            }
            this.tb[0] = -1;
            int[] bl = new int[1];
            int[] bd = new int[1];
            int[] tl = new int[1];
            int[] td = new int[1];
            bl[0] = 9;
            bd[0] = 6;
            table = this.table;
            table = InfTree.inflate_trees_dynamic(0x101 + (table & 0x1f), 1 + ((table >> 5) & 0x1f), this.blens, bl, bd, tl, td, this.hufts, z);
            switch (table)
            {
            case 0:
                this.codes = new InfCodes(bl[0], bd[0], this.hufts, tl[0], this.hufts, td[0], z);
                this.blens = null;
                this.mode  = 6;
                goto Label_0B63;

            case -3:
                this.blens = null;
                this.mode  = 9;
                break;
            }
            r               = table;
            this.bitb       = bitb;
            this.bitk       = bitk;
            z.avail_in      = num5;
            z.total_in     += sourceIndex - z.next_in_index;
            z.next_in_index = sourceIndex;
            this.write      = write;
            return(this.inflate_flush(z, r));

Label_0B63:
            this.bitb       = bitb;
            this.bitk       = bitk;
            z.avail_in      = num5;
            z.total_in     += sourceIndex - z.next_in_index;
            z.next_in_index = sourceIndex;
            this.write      = write;
            if ((r = this.codes.proc(this, z, r)) != 1)
            {
                return(this.inflate_flush(z, r));
            }
            r = 0;
            this.codes.free(z);
            sourceIndex = z.next_in_index;
            num5        = z.avail_in;
            bitb        = this.bitb;
            bitk        = this.bitk;
            write       = this.write;
            num7        = (write < this.read) ? ((this.read - write) - 1) : (this.end - write);
            if (this.last == 0)
            {
                this.mode = 0;
                goto Label_0047;
            }
            this.mode = 7;
Label_0C2C:
            this.write = write;
            r          = this.inflate_flush(z, r);
            write      = this.write;
            num7       = (write < this.read) ? ((this.read - write) - 1) : (this.end - write);
            if (this.read != this.write)
            {
                this.bitb       = bitb;
                this.bitk       = bitk;
                z.avail_in      = num5;
                z.total_in     += sourceIndex - z.next_in_index;
                z.next_in_index = sourceIndex;
                this.write      = write;
                return(this.inflate_flush(z, r));
            }
            this.mode = 8;
Label_0CC1:
            r               = 1;
            this.bitb       = bitb;
            this.bitk       = bitk;
            z.avail_in      = num5;
            z.total_in     += sourceIndex - z.next_in_index;
            z.next_in_index = sourceIndex;
            this.write      = write;
            return(this.inflate_flush(z, r));
        }