internal void scan_tree(short[] tree, int max_code) { int num = -1; int num2 = (int)tree[1]; int num3 = 0; int num4 = 7; int num5 = 4; if (num2 == 0) { num4 = 138; num5 = 3; } tree[(max_code + 1) * 2 + 1] = (short)SupportClass.Identity(65535L); for (int i = 0; i <= max_code; i++) { int num6 = num2; num2 = (int)tree[(i + 1) * 2 + 1]; if (++num3 >= num4 || num6 != num2) { if (num3 < num5) { this.bl_tree[num6 * 2] = (short)((int)this.bl_tree[num6 * 2] + num3); } else if (num6 != 0) { short[] array; if (num6 != num) { IntPtr intPtr; (array = this.bl_tree)[(int)(intPtr = (IntPtr)(num6 * 2))] = (short)(array[(int)intPtr] + 1); } (array = this.bl_tree)[32] = (short)(array[32] + 1); } else if (num3 <= 10) { short[] array; (array = this.bl_tree)[34] = (short)(array[34] + 1); } else { short[] array; (array = this.bl_tree)[36] = (short)(array[36] + 1); } num3 = 0; num = num6; if (num2 == 0) { num4 = 138; num5 = 3; } else if (num6 == num2) { num4 = 6; num5 = 3; } else { num4 = 7; num5 = 4; } } } }
internal void put_short(int w) { this.put_byte((byte)w); this.put_byte((byte)SupportClass.URShift(w, 8)); }
internal int proc(ZStream z, int r) { int t; // temporary storage int b; // bit buffer int k; // bits in bit buffer int p; // input data pointer int n; // bytes available there int q; // output window write pointer int m; // bytes to end of window or read pointer // copy input/output information to locals (UPDATE macro restores) { p = z.next_in_index; n = z.avail_in; b = bitb; k = bitk; } { q = write; m = (int)(q < read?read - q - 1:end - q); } // process input based on current state while (true) { switch (mode) { case TYPE: while (k < (3)) { if (n != 0) { r = Z_OK; } else { bitb = b; bitk = k; z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p; write = q; return(inflate_flush(z, r)); } ; n--; b |= (z.next_in[p++] & 0xff) << k; k += 8; } t = (int)(b & 7); last = t & 1; switch (SupportClass.URShift(t, 1)) { case 0: // stored { b = SupportClass.URShift(b, (3)); k -= (3); } t = k & 7; // go to byte boundary { b = SupportClass.URShift(b, (t)); k -= (t); } mode = LENS; // get length of stored block break; case 1: // fixed { int[] bl = new int[1]; int[] bd = new int[1]; int[][] tl = new int[1][]; int[][] td = new int[1][]; InfTree.inflate_trees_fixed(bl, bd, tl, td, z); codes = new InfCodes(bl[0], bd[0], tl[0], td[0], z); } { b = SupportClass.URShift(b, (3)); k -= (3); } mode = CODES; break; case 2: // dynamic { b = SupportClass.URShift(b, (3)); k -= (3); } mode = TABLE; break; case 3: // illegal { b = SupportClass.URShift(b, (3)); k -= (3); } mode = BAD; z.msg = "invalid block type"; r = Z_DATA_ERROR; bitb = b; bitk = k; z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p; write = q; return(inflate_flush(z, r)); } break; case LENS: while (k < (32)) { if (n != 0) { r = Z_OK; } else { bitb = b; bitk = k; z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p; write = q; return(inflate_flush(z, r)); } ; n--; b |= (z.next_in[p++] & 0xff) << k; k += 8; } if (((SupportClass.URShift((~b), 16)) & 0xffff) != (b & 0xffff)) { mode = BAD; z.msg = "invalid stored block lengths"; r = Z_DATA_ERROR; bitb = b; bitk = k; z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p; write = q; return(inflate_flush(z, r)); } left = (b & 0xffff); b = k = 0; // dump bits mode = left != 0?STORED:(last != 0?DRY:TYPE); break; case STORED: if (n == 0) { bitb = b; bitk = k; z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p; write = q; return(inflate_flush(z, r)); } if (m == 0) { if (q == end && read != 0) { q = 0; m = (int)(q < read?read - q - 1:end - q); } if (m == 0) { write = q; r = inflate_flush(z, r); q = write; m = (int)(q < read?read - q - 1:end - q); if (q == end && read != 0) { q = 0; m = (int)(q < read?read - q - 1:end - q); } if (m == 0) { bitb = b; bitk = k; z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p; write = q; return(inflate_flush(z, r)); } } } r = Z_OK; t = left; if (t > n) { t = n; } if (t > m) { t = m; } Array.Copy(z.next_in, p, window, q, t); p += t; n -= t; q += t; m -= t; if ((left -= t) != 0) { break; } mode = last != 0?DRY:TYPE; break; case TABLE: while (k < (14)) { if (n != 0) { r = Z_OK; } else { bitb = b; bitk = k; z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p; write = q; return(inflate_flush(z, r)); } ; n--; b |= (z.next_in[p++] & 0xff) << k; k += 8; } table = t = (b & 0x3fff); if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29) { mode = BAD; z.msg = "too many length or distance symbols"; r = Z_DATA_ERROR; bitb = b; bitk = k; z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p; write = q; return(inflate_flush(z, r)); } t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f); blens = new int[t]; { b = SupportClass.URShift(b, (14)); k -= (14); } index = 0; mode = BTREE; goto case BTREE; case BTREE: while (index < 4 + (SupportClass.URShift(table, 10))) { while (k < (3)) { if (n != 0) { r = Z_OK; } else { bitb = b; bitk = k; z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p; write = q; return(inflate_flush(z, r)); } ; n--; b |= (z.next_in[p++] & 0xff) << k; k += 8; } blens[border[index++]] = b & 7; { b = SupportClass.URShift(b, (3)); k -= (3); } } while (index < 19) { blens[border[index++]] = 0; } bb[0] = 7; t = InfTree.inflate_trees_bits(blens, bb, tb, hufts, z); if (t != Z_OK) { r = t; if (r == Z_DATA_ERROR) { blens = null; mode = BAD; } bitb = b; bitk = k; z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p; write = q; return(inflate_flush(z, r)); } index = 0; mode = DTREE; goto case DTREE; case DTREE: while (true) { t = table; if (!(index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f))) { break; } int i, j, c; t = bb[0]; while (k < (t)) { if (n != 0) { r = Z_OK; } else { bitb = b; bitk = k; z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p; write = q; return(inflate_flush(z, r)); } ; n--; b |= (z.next_in[p++] & 0xff) << k; k += 8; } if (tb[0] == -1) { //System.err.println("null..."); } t = hufts[(tb[0] + (b & inflate_mask[t])) * 3 + 1]; c = hufts[(tb[0] + (b & inflate_mask[t])) * 3 + 2]; if (c < 16) { b = SupportClass.URShift(b, (t)); k -= (t); blens[index++] = c; } else { // c == 16..18 i = c == 18?7:c - 14; j = c == 18?11:3; while (k < (t + i)) { if (n != 0) { r = Z_OK; } else { bitb = b; bitk = k; z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p; write = q; return(inflate_flush(z, r)); } ; n--; b |= (z.next_in[p++] & 0xff) << k; k += 8; } b = SupportClass.URShift(b, (t)); k -= (t); j += (b & inflate_mask[i]); b = SupportClass.URShift(b, (i)); k -= (i); i = index; t = table; if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) || (c == 16 && i < 1)) { blens = null; mode = BAD; z.msg = "invalid bit length repeat"; r = Z_DATA_ERROR; bitb = b; bitk = k; z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p; write = q; return(inflate_flush(z, r)); } c = c == 16?blens[i - 1]:0; do { blens[i++] = c; }while (--j != 0); index = i; } } tb[0] = -1; { int[] bl = new int[1]; int[] bd = new int[1]; int[] tl = new int[1]; int[] td = new int[1]; bl[0] = 9; // must be <= 9 for lookahead assumptions bd[0] = 6; // must be <= 9 for lookahead assumptions t = table; t = InfTree.inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f), blens, bl, bd, tl, td, hufts, z); if (t != Z_OK) { if (t == Z_DATA_ERROR) { blens = null; mode = BAD; } r = t; bitb = b; bitk = k; z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p; write = q; return(inflate_flush(z, r)); } codes = new InfCodes(bl[0], bd[0], hufts, tl[0], hufts, td[0], z); } blens = null; mode = CODES; goto case CODES; case CODES: bitb = b; bitk = k; z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p; write = q; if ((r = codes.proc(this, z, r)) != Z_STREAM_END) { return(inflate_flush(z, r)); } r = Z_OK; codes.free(z); p = z.next_in_index; n = z.avail_in; b = bitb; k = bitk; q = write; m = (int)(q < read?read - q - 1:end - q); if (last == 0) { mode = TYPE; break; } mode = DRY; goto case DRY; case DRY: write = q; r = inflate_flush(z, r); q = write; m = (int)(q < read?read - q - 1:end - q); if (read != write) { bitb = b; bitk = k; z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p; write = q; return(inflate_flush(z, r)); } mode = DONE; goto case DONE; case DONE: r = Z_STREAM_END; bitb = b; bitk = k; z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p; write = q; return(inflate_flush(z, r)); case BAD: r = Z_DATA_ERROR; bitb = b; bitk = k; z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p; write = q; return(inflate_flush(z, r)); default: r = Z_STREAM_ERROR; bitb = b; bitk = k; z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p; write = q; return(inflate_flush(z, r)); } } }
internal int deflate(ZStream strm, int flush) { if (flush <= 4 && flush >= 0) { if (strm.next_out != null && (strm.next_in != null || strm.avail_in == 0)) { if (this.status != 666 || flush == 4) { if (strm.avail_out == 0) { strm.msg = Deflate.z_errmsg[7]; return(-5); } this.strm = strm; int num = this.last_flush; this.last_flush = flush; if (this.status == 42) { int num2 = 8 + (this.w_bits - 8 << 4) << 8; int num3 = (this.level - 1 & 255) >> 1; if (num3 > 3) { num3 = 3; } num2 |= num3 << 6; if (this.strstart != 0) { num2 |= 32; } num2 += 31 - num2 % 31; this.status = 113; this.putShortMSB(num2); if (this.strstart != 0) { this.putShortMSB((int)SupportClass.URShift(strm.adler, 16)); this.putShortMSB((int)(strm.adler & 65535L)); } 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 = Deflate.z_errmsg[7]; return(-5); } if (this.status == 666 && strm.avail_in != 0) { strm.msg = Deflate.z_errmsg[7]; return(-5); } if (strm.avail_in != 0 || this.lookahead != 0 || (flush != 0 && this.status != 666)) { int num4 = -1; switch (Deflate.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; } if (num4 == 2 || num4 == 3) { this.status = 666; } if (num4 != 0) { if (num4 != 2) { if (num4 != 1) { goto IL_263; } 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); } goto IL_263; } } if (strm.avail_out == 0) { this.last_flush = -1; } return(0); } IL_263: if (flush != 4) { return(0); } if (this.noheader != 0) { return(1); } this.putShortMSB((int)SupportClass.URShift(strm.adler, 16)); this.putShortMSB((int)(strm.adler & 65535L)); strm.flush_pending(); this.noheader = -1; if (this.pending == 0) { return(1); } return(0); } } strm.msg = Deflate.z_errmsg[4]; return(-2); } return(-2); }
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 = Deflate.z_errmsg[4]; return(-2); } if (strm.avail_out == 0) { strm.msg = Deflate.z_errmsg[7]; return(-5); } this.strm = strm; int num1 = this.last_flush; this.last_flush = flush; if (this.status == 0x2a) { int num2 = (8 + ((this.w_bits - 8) << 4)) << 8; int num3 = ((this.level - 1) & 0xff) >> 1; if (num3 > 3) { num3 = 3; } num2 |= num3 << 6; if (this.strstart != 0) { num2 |= 0x20; } num2 += 0x1f - (num2 % 0x1f); this.status = 0x71; this.putShortMSB(num2); if (this.strstart != 0) { this.putShortMSB((int)SupportClass.URShift(strm.adler, 0x10)); this.putShortMSB(((int)strm.adler) & 0xffff); } strm.adler = strm._adler.adler32((long)0, 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 <= num1)) && (flush != 4)) { strm.msg = Deflate.z_errmsg[7]; return(-5); } if ((this.status == 0x29a) && (strm.avail_in != 0)) { strm.msg = Deflate.z_errmsg[7]; return(-5); } if (((strm.avail_in != 0) || (this.lookahead != 0)) || ((flush != 0) && (this.status != 0x29a))) { int num4 = -1; switch (Deflate.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; } switch (num4) { case 0: case 2: if (strm.avail_out == 0) { this.last_flush = -1; } return(0); default: if (num4 == 1) { if (flush == 1) { this._tr_align(); } else { this._tr_stored_block(0, 0, false); if (flush == 3) { for (int num5 = 0; num5 < this.hash_size; num5++) { this.head[num5] = 0; } } } strm.flush_pending(); if (strm.avail_out == 0) { this.last_flush = -1; return(0); } } break; } } if (flush == 4) { if (this.noheader != 0) { return(1); } this.putShortMSB((int)SupportClass.URShift(strm.adler, 0x10)); this.putShortMSB(((int)strm.adler) & 0xffff); strm.flush_pending(); this.noheader = -1; if (this.pending == 0) { return(1); } } return(0); }
internal int proc(InfBlocks s, ZStream z, int r) { int num = z.next_in_index; int num2 = z.avail_in; int num3 = s.bitb; int i = s.bitk; int num4 = s.write; int num5 = (num4 < s.read) ? (s.read - num4 - 1) : (s.end - num4); while (true) { int num6; switch (this.mode) { case 0: if (num5 >= 258 && num2 >= 10) { s.bitb = num3; s.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; s.write = num4; r = this.inflate_fast((int)this.lbits, (int)this.dbits, this.ltree, this.ltree_index, this.dtree, this.dtree_index, s, z); num = z.next_in_index; num2 = z.avail_in; num3 = s.bitb; i = s.bitk; num4 = s.write; num5 = ((num4 < s.read) ? (s.read - num4 - 1) : (s.end - num4)); if (r != 0) { this.mode = ((r == 1) ? 7 : 9); continue; } } this.need = (int)this.lbits; this.tree = this.ltree; this.tree_index = this.ltree_index; this.mode = 1; goto IL_199; case 1: goto IL_199; case 2: num6 = this.get_Renamed; while (i < num6) { if (num2 == 0) { goto IL_34F; } r = 0; num2--; num3 |= (int)(z.next_in[num++] & 255) << i; i += 8; } this.len += (num3 & InfCodes.inflate_mask[num6]); num3 >>= num6; i -= num6; this.need = (int)this.dbits; this.tree = this.dtree; this.tree_index = this.dtree_index; this.mode = 3; goto IL_412; case 3: goto IL_412; case 4: num6 = this.get_Renamed; while (i < num6) { if (num2 == 0) { goto IL_596; } r = 0; num2--; num3 |= (int)(z.next_in[num++] & 255) << i; i += 8; } this.dist += (num3 & InfCodes.inflate_mask[num6]); num3 >>= num6; i -= num6; this.mode = 5; goto IL_635; case 5: goto IL_635; case 6: if (num5 == 0) { if (num4 == s.end && s.read != 0) { num4 = 0; num5 = ((num4 < s.read) ? (s.read - num4 - 1) : (s.end - num4)); } if (num5 == 0) { s.write = num4; r = s.inflate_flush(z, r); num4 = s.write; num5 = ((num4 < s.read) ? (s.read - num4 - 1) : (s.end - num4)); if (num4 == s.end && s.read != 0) { num4 = 0; num5 = ((num4 < s.read) ? (s.read - num4 - 1) : (s.end - num4)); } if (num5 == 0) { goto Block_44; } } } r = 0; s.window[num4++] = (byte)this.lit; num5--; this.mode = 0; continue; case 7: goto IL_8DB; case 8: goto IL_98A; case 9: goto IL_9D4; } break; IL_199: num6 = this.need; while (i < num6) { if (num2 == 0) { goto IL_1AB; } r = 0; num2--; num3 |= (int)(z.next_in[num++] & 255) << i; i += 8; } int num7 = (this.tree_index + (num3 & InfCodes.inflate_mask[num6])) * 3; num3 = SupportClass.URShift(num3, this.tree[num7 + 1]); i -= this.tree[num7 + 1]; int num8 = this.tree[num7]; if (num8 == 0) { this.lit = this.tree[num7 + 2]; this.mode = 6; continue; } if ((num8 & 16) != 0) { this.get_Renamed = (num8 & 15); this.len = this.tree[num7 + 2]; this.mode = 2; continue; } if ((num8 & 64) == 0) { this.need = num8; this.tree_index = num7 / 3 + this.tree[num7 + 2]; continue; } if ((num8 & 32) != 0) { this.mode = 7; continue; } goto IL_2DF; IL_412: num6 = this.need; while (i < num6) { if (num2 == 0) { goto IL_424; } r = 0; num2--; num3 |= (int)(z.next_in[num++] & 255) << i; i += 8; } num7 = (this.tree_index + (num3 & InfCodes.inflate_mask[num6])) * 3; num3 >>= this.tree[num7 + 1]; i -= this.tree[num7 + 1]; num8 = this.tree[num7]; if ((num8 & 16) != 0) { this.get_Renamed = (num8 & 15); this.dist = this.tree[num7 + 2]; this.mode = 4; continue; } if ((num8 & 64) == 0) { this.need = num8; this.tree_index = num7 / 3 + this.tree[num7 + 2]; continue; } goto IL_526; IL_635: int j; for (j = num4 - this.dist; j < 0; j += s.end) { } while (this.len != 0) { if (num5 == 0) { if (num4 == s.end && s.read != 0) { num4 = 0; num5 = ((num4 < s.read) ? (s.read - num4 - 1) : (s.end - num4)); } if (num5 == 0) { s.write = num4; r = s.inflate_flush(z, r); num4 = s.write; num5 = ((num4 < s.read) ? (s.read - num4 - 1) : (s.end - num4)); if (num4 == s.end && s.read != 0) { num4 = 0; num5 = ((num4 < s.read) ? (s.read - num4 - 1) : (s.end - num4)); } if (num5 == 0) { goto Block_32; } } } s.window[num4++] = s.window[j++]; num5--; if (j == s.end) { j = 0; } this.len--; } this.mode = 0; } r = -2; s.bitb = num3; s.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; s.write = num4; return(s.inflate_flush(z, r)); IL_1AB: s.bitb = num3; s.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; s.write = num4; return(s.inflate_flush(z, r)); IL_2DF: this.mode = 9; z.msg = "invalid literal/length code"; r = -3; s.bitb = num3; s.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; s.write = num4; return(s.inflate_flush(z, r)); IL_34F: s.bitb = num3; s.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; s.write = num4; return(s.inflate_flush(z, r)); IL_424: s.bitb = num3; s.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; s.write = num4; return(s.inflate_flush(z, r)); IL_526: this.mode = 9; z.msg = "invalid distance code"; r = -3; s.bitb = num3; s.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; s.write = num4; return(s.inflate_flush(z, r)); IL_596: s.bitb = num3; s.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; s.write = num4; return(s.inflate_flush(z, r)); Block_32: s.bitb = num3; s.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; s.write = num4; return(s.inflate_flush(z, r)); Block_44: s.bitb = num3; s.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; s.write = num4; return(s.inflate_flush(z, r)); IL_8DB: if (i > 7) { i -= 8; num2++; num--; } s.write = num4; r = s.inflate_flush(z, r); num4 = s.write; int arg_92C_0 = (num4 < s.read) ? (s.read - num4 - 1) : (s.end - num4); if (s.read != s.write) { s.bitb = num3; s.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; s.write = num4; return(s.inflate_flush(z, r)); } this.mode = 8; IL_98A: r = 1; s.bitb = num3; s.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; s.write = num4; return(s.inflate_flush(z, r)); IL_9D4: r = -3; s.bitb = num3; s.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; s.write = num4; return(s.inflate_flush(z, r)); }
internal const int BMAX = 15; // maximum bit length of any code internal static int huft_build(int[] b, int bindex, int n, int s, int[] d, int[] e, int[] t, int[] m, int[] hp, int[] hn, int[] v) { // Given a list of code lengths and a maximum table size, make a set of // tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR // if the given code set is incomplete (the tables are still built in this // case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of // lengths), or Z_MEM_ERROR if not enough memory. int a; // counter for codes of length k var c = new int[BMAX + 1]; // bit length count table int f; // i repeats in table every f entries int g; // maximum code length int h; // table level int i; // counter, current code int j; // counter int k; // number of bits in current code int l; // bits per table (returned in m) int mask; // (1 << w) - 1, to avoid cc -O bug on HP int p; // pointer into c[], b[], or v[] int q; // points to current table var r = new int[3]; // table entry for structure assignment var u = new int[BMAX]; // table stack int w; // bits before this table == (l * h) var x = new int[BMAX + 1]; // bit offsets, then code stack int xp; // pointer into x int y; // number of dummy codes added int z; // number of entries in current table // Generate counts for each bit length p = 0; i = n; do { c[b[bindex + p]]++; p++; i--; // assume all entries <= BMAX }while (i != 0); if (c[0] == n) { // null input--all zero length codes t[0] = -1; m[0] = 0; return(Z_OK); } // Find minimum and maximum length, bound *m by those l = m[0]; for (j = 1; j <= BMAX; j++) { if (c[j] != 0) { break; } } k = j; // minimum code length if (l < j) { l = j; } for (i = BMAX; i != 0; i--) { if (c[i] != 0) { break; } } g = i; // maximum code length if (l > i) { l = i; } m[0] = l; // Adjust last length count to fill out codes, if needed for (y = 1 << j; j < i; j++, y <<= 1) { if ((y -= c[j]) < 0) { return(Z_DATA_ERROR); } } if ((y -= c[i]) < 0) { return(Z_DATA_ERROR); } c[i] += y; // Generate starting offsets into the value table for each length x[1] = j = 0; p = 1; xp = 2; while (--i != 0) { // note that i == g from above x[xp] = (j += c[p]); xp++; p++; } // Make a table of values in order of bit lengths i = 0; p = 0; do { if ((j = b[bindex + p]) != 0) { v[x[j]++] = i; } p++; }while (++i < n); n = x[g]; // set n to length of v // Generate the Huffman codes and for each, make the table entries x[0] = i = 0; // first Huffman code is zero p = 0; // grab values in bit order h = -1; // no tables yet--level -1 w = -l; // bits decoded == (l * h) u[0] = 0; // just to keep compilers happy q = 0; // ditto z = 0; // ditto // go through the bit lengths (k already is bits in shortest code) for (; k <= g; k++) { a = c[k]; while (a-- != 0) { // here i is the Huffman code of length k bits for value *p // make tables up to required level while (k > w + l) { h++; w += l; // previous table always l bits // compute minimum size table less than or equal to l bits z = g - w; z = (z > l)?l:z; // table size upper limit if ((f = 1 << (j = k - w)) > a + 1) { // try a k-w bit table // too few codes for k-w bit table f -= (a + 1); // deduct codes from patterns left xp = k; if (j < z) { while (++j < z) { // try smaller tables up to z bits if ((f <<= 1) <= c[++xp]) { break; // enough codes to use up j bits } f -= c[xp]; // else deduct codes from patterns } } } z = 1 << j; // table entries for j-bit table // allocate new table if (hn[0] + z > MANY) { // (note: doesn't matter for fixed) return(Z_DATA_ERROR); // overflow of MANY } u[h] = q = hn[0]; // DEBUG hn[0] += z; // connect to last table, if there is one if (h != 0) { x[h] = i; // save pattern for backing up r[0] = (byte)j; // bits in this table r[1] = (byte)l; // bits to dump before this table j = SupportClass.URShift(i, (w - l)); r[2] = (int)(q - u[h - 1] - j); // offset to this table Array.Copy(r, 0, hp, (u[h - 1] + j) * 3, 3); // connect to last table } else { t[0] = q; // first table is returned result } } // set up table entry in r r[1] = (byte)(k - w); if (p >= n) { r[0] = 128 + 64; // out of values--invalid code } else if (v[p] < s) { r[0] = (byte)(v[p] < 256?0:32 + 64); // 256 is end-of-block r[2] = v[p++]; // simple code is just the value } else { r[0] = (byte)(e[v[p] - s] + 16 + 64); // non-simple--look up in lists r[2] = d[v[p++] - s]; } // fill code-like entries with r f = 1 << (k - w); for (j = SupportClass.URShift(i, w); j < z; j += f) { Array.Copy(r, 0, hp, (q + j) * 3, 3); } // backwards increment the k-bit code i for (j = 1 << (k - 1); (i & j) != 0; j = SupportClass.URShift(j, 1)) { i ^= j; } i ^= j; // backup over finished tables mask = (1 << w) - 1; // needed on HP, cc -O bug while ((i & mask) != x[h]) { h--; // don't need to update q w -= l; mask = (1 << w) - 1; } } } // Return Z_BUF_ERROR if we were given an incomplete table return(y != 0 && g != 1?Z_BUF_ERROR:Z_OK); }
internal int proc(ZStream z, int r) { int num = z.next_in_index; int num2 = z.avail_in; int num3 = this.bitb; int i = this.bitk; int num4 = this.write; int num5 = (num4 < this.read) ? (this.read - num4 - 1) : (this.end - num4); int num6; while (true) { switch (this.mode) { case 0: while (i < 3) { if (num2 == 0) { goto IL_8C; } r = 0; num2--; num3 |= (int)(z.next_in[num++] & 255) << i; i += 8; } num6 = (num3 & 7); this.last = (num6 & 1); switch (SupportClass.URShift(num6, 1)) { case 0: num3 = SupportClass.URShift(num3, 3); i -= 3; num6 = (i & 7); num3 = SupportClass.URShift(num3, num6); i -= num6; this.mode = 1; continue; case 1: { int[] array = new int[1]; int[] array2 = new int[1]; int[][] array3 = new int[1][]; int[][] array4 = new int[1][]; InfTree.inflate_trees_fixed(array, array2, array3, array4, z); this.codes = new InfCodes(array[0], array2[0], array3[0], array4[0], z); num3 = SupportClass.URShift(num3, 3); i -= 3; this.mode = 6; continue; } case 2: num3 = SupportClass.URShift(num3, 3); i -= 3; this.mode = 3; continue; case 3: goto IL_1CD; default: continue; } break; case 1: while (i < 32) { if (num2 == 0) { goto IL_23D; } r = 0; num2--; num3 |= (int)(z.next_in[num++] & 255) << i; i += 8; } if ((SupportClass.URShift(~num3, 16) & 65535) != (num3 & 65535)) { goto Block_8; } this.left = (num3 & 65535); i = (num3 = 0); this.mode = ((this.left != 0) ? 2 : ((this.last != 0) ? 7 : 0)); continue; case 2: if (num2 == 0) { goto Block_11; } if (num5 == 0) { if (num4 == this.end && this.read != 0) { num4 = 0; num5 = ((num4 < this.read) ? (this.read - num4 - 1) : (this.end - num4)); } if (num5 == 0) { this.write = num4; r = this.inflate_flush(z, r); num4 = this.write; num5 = ((num4 < this.read) ? (this.read - num4 - 1) : (this.end - num4)); if (num4 == this.end && this.read != 0) { num4 = 0; num5 = ((num4 < this.read) ? (this.read - num4 - 1) : (this.end - num4)); } if (num5 == 0) { goto Block_21; } } } r = 0; num6 = this.left; if (num6 > num2) { num6 = num2; } if (num6 > num5) { num6 = num5; } Array.Copy(z.next_in, num, this.window, num4, num6); num += num6; num2 -= num6; num4 += num6; num5 -= num6; if ((this.left -= num6) == 0) { this.mode = ((this.last != 0) ? 7 : 0); continue; } continue; case 3: while (i < 14) { if (num2 == 0) { goto IL_515; } r = 0; num2--; num3 |= (int)(z.next_in[num++] & 255) << i; i += 8; } num6 = (this.table = (num3 & 16383)); if ((num6 & 31) > 29 || (num6 >> 5 & 31) > 29) { goto IL_5A3; } num6 = 258 + (num6 & 31) + (num6 >> 5 & 31); this.blens = new int[num6]; num3 = SupportClass.URShift(num3, 14); i -= 14; this.index = 0; this.mode = 4; goto IL_6E2; case 4: goto IL_6E2; case 5: goto IL_7BB; case 6: goto IL_B66; case 7: goto IL_C2F; case 8: goto IL_CC4; case 9: goto IL_D0B; } break; IL_6E2: while (this.index < 4 + SupportClass.URShift(this.table, 10)) { while (i < 3) { if (num2 == 0) { goto IL_646; } r = 0; num2--; num3 |= (int)(z.next_in[num++] & 255) << i; i += 8; } int[] arg_6D5_0 = this.blens; int[] arg_6D1_0 = InfBlocks.border; int num7 = this.index; this.index = num7 + 1; arg_6D5_0[arg_6D1_0[num7]] = (num3 & 7); num3 = SupportClass.URShift(num3, 3); i -= 3; } while (this.index < 19) { int[] arg_71C_0 = this.blens; int[] arg_71A_0 = InfBlocks.border; int num7 = this.index; this.index = num7 + 1; arg_71C_0[arg_71A_0[num7]] = 0; } this.bb[0] = 7; num6 = InfTree.inflate_trees_bits(this.blens, this.bb, this.tb, this.hufts, z); if (num6 != 0) { goto Block_33; } this.index = 0; this.mode = 5; IL_7BB: while (true) { num6 = this.table; if (this.index >= 258 + (num6 & 31) + (num6 >> 5 & 31)) { break; } num6 = this.bb[0]; while (i < num6) { if (num2 == 0) { goto IL_7F2; } r = 0; num2--; num3 |= (int)(z.next_in[num++] & 255) << i; i += 8; } int arg_868_0 = this.tb[0]; num6 = this.hufts[(this.tb[0] + (num3 & InfBlocks.inflate_mask[num6])) * 3 + 1]; int num8 = this.hufts[(this.tb[0] + (num3 & InfBlocks.inflate_mask[num6])) * 3 + 2]; if (num8 < 16) { num3 = SupportClass.URShift(num3, num6); i -= num6; int[] arg_8D4_0 = this.blens; int num7 = this.index; this.index = num7 + 1; arg_8D4_0[num7] = num8; } else { int num9 = (num8 == 18) ? 7 : (num8 - 14); int num10 = (num8 == 18) ? 11 : 3; while (i < num6 + num9) { if (num2 == 0) { goto IL_902; } r = 0; num2--; num3 |= (int)(z.next_in[num++] & 255) << i; i += 8; } num3 = SupportClass.URShift(num3, num6); i -= num6; num10 += (num3 & InfBlocks.inflate_mask[num9]); num3 = SupportClass.URShift(num3, num9); i -= num9; num9 = this.index; num6 = this.table; if (num9 + num10 > 258 + (num6 & 31) + (num6 >> 5 & 31) || (num8 == 16 && num9 < 1)) { goto IL_9CC; } num8 = ((num8 == 16) ? this.blens[num9 - 1] : 0); do { this.blens[num9++] = num8; }while (--num10 != 0); this.index = num9; } } this.tb[0] = -1; int[] array5 = new int[1]; int[] array6 = new int[1]; int[] array7 = new int[1]; int[] array8 = new int[1]; array5[0] = 9; array6[0] = 6; num6 = this.table; num6 = InfTree.inflate_trees_dynamic(257 + (num6 & 31), 1 + (num6 >> 5 & 31), this.blens, array5, array6, array7, array8, this.hufts, z); if (num6 != 0) { goto Block_47; } this.codes = new InfCodes(array5[0], array6[0], this.hufts, array7[0], this.hufts, array8[0], z); this.blens = null; this.mode = 6; IL_B66: this.bitb = num3; this.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; this.write = num4; if ((r = this.codes.proc(this, z, r)) != 1) { goto Block_49; } r = 0; this.codes.free(z); num = z.next_in_index; num2 = z.avail_in; num3 = this.bitb; i = this.bitk; num4 = this.write; num5 = ((num4 < this.read) ? (this.read - num4 - 1) : (this.end - num4)); if (this.last != 0) { goto IL_C28; } this.mode = 0; } r = -2; this.bitb = num3; this.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; this.write = num4; return(this.inflate_flush(z, r)); IL_8C: this.bitb = num3; this.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; this.write = num4; return(this.inflate_flush(z, r)); IL_1CD: num3 = SupportClass.URShift(num3, 3); i -= 3; this.mode = 9; z.msg = "invalid block type"; r = -3; this.bitb = num3; this.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; this.write = num4; return(this.inflate_flush(z, r)); IL_23D: this.bitb = num3; this.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; this.write = num4; return(this.inflate_flush(z, r)); Block_8: this.mode = 9; z.msg = "invalid stored block lengths"; r = -3; this.bitb = num3; this.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; this.write = num4; return(this.inflate_flush(z, r)); Block_11: this.bitb = num3; this.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; this.write = num4; return(this.inflate_flush(z, r)); Block_21: this.bitb = num3; this.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; this.write = num4; return(this.inflate_flush(z, r)); IL_515: this.bitb = num3; this.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; this.write = num4; return(this.inflate_flush(z, r)); IL_5A3: this.mode = 9; z.msg = "too many length or distance symbols"; r = -3; this.bitb = num3; this.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; this.write = num4; return(this.inflate_flush(z, r)); IL_646: this.bitb = num3; this.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; this.write = num4; return(this.inflate_flush(z, r)); Block_33: r = num6; if (r == -3) { this.blens = null; this.mode = 9; } this.bitb = num3; this.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; this.write = num4; return(this.inflate_flush(z, r)); IL_7F2: this.bitb = num3; this.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; this.write = num4; return(this.inflate_flush(z, r)); IL_902: this.bitb = num3; this.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; this.write = num4; return(this.inflate_flush(z, r)); IL_9CC: this.blens = null; this.mode = 9; z.msg = "invalid bit length repeat"; r = -3; this.bitb = num3; this.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; this.write = num4; return(this.inflate_flush(z, r)); Block_47: if (num6 == -3) { this.blens = null; this.mode = 9; } r = num6; this.bitb = num3; this.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; this.write = num4; return(this.inflate_flush(z, r)); Block_49: return(this.inflate_flush(z, r)); IL_C28: this.mode = 7; IL_C2F: this.write = num4; r = this.inflate_flush(z, r); num4 = this.write; int arg_C69_0 = (num4 < this.read) ? (this.read - num4 - 1) : (this.end - num4); if (this.read != this.write) { this.bitb = num3; this.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; this.write = num4; return(this.inflate_flush(z, r)); } this.mode = 8; IL_CC4: r = 1; this.bitb = num3; this.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; this.write = num4; return(this.inflate_flush(z, r)); IL_D0B: r = -3; this.bitb = num3; this.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; this.write = num4; return(this.inflate_flush(z, r)); }
internal void scan_tree(short[] tree, int max_code) { int num = -1; int num2 = (int)tree[1]; int num3 = 0; int num4 = 7; int num5 = 4; if (num2 == 0) { num4 = 138; num5 = 3; } tree[(max_code + 1) * 2 + 1] = (short)SupportClass.Identity(65535L); for (int i = 0; i <= max_code; i++) { int num6 = num2; num2 = (int)tree[(i + 1) * 2 + 1]; if (++num3 >= num4 || num6 != num2) { if (num3 < num5) { this.bl_tree[num6 * 2] = (short)((int)this.bl_tree[num6 * 2] + num3); } else if (num6 != 0) { if (num6 != num) { short[] expr_8B_cp_0 = this.bl_tree; int expr_8B_cp_1 = num6 * 2; expr_8B_cp_0[expr_8B_cp_1] += 1; } short[] expr_A6_cp_0 = this.bl_tree; int expr_A6_cp_1 = 32; expr_A6_cp_0[expr_A6_cp_1] += 1; } else if (num3 <= 10) { short[] expr_C9_cp_0 = this.bl_tree; int expr_C9_cp_1 = 34; expr_C9_cp_0[expr_C9_cp_1] += 1; } else { short[] expr_E6_cp_0 = this.bl_tree; int expr_E6_cp_1 = 36; expr_E6_cp_0[expr_E6_cp_1] += 1; } num3 = 0; num = num6; if (num2 == 0) { num4 = 138; num5 = 3; } else if (num6 == num2) { num4 = 6; num5 = 3; } else { num4 = 7; num5 = 4; } } } }
internal int proc(InfBlocks s, ZStream z, int r) { int j; // temporary storage //int[] t; // temporary pointer int tindex; // temporary pointer int e; // extra bits or operation int b = 0; // bit buffer int k = 0; // bits in bit buffer int p = 0; // input data pointer int n; // bytes available there int q; // output window write pointer int m; // bytes to end of window or read pointer int f; // pointer to copy strings from // copy input/output information to locals (UPDATE macro restores) p = z.next_in_index; n = z.avail_in; b = s.bitb; k = s.bitk; q = s.write; m = q < s.read?s.read - q - 1:s.end - q; // process input and output based on current state while (true) { switch (mode) { // waiting for "i:"=input, "o:"=output, "x:"=nothing case START: // x: set up for LEN if (m >= 258 && n >= 10) { s.bitb = b; s.bitk = k; z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p; s.write = q; r = inflate_fast(lbits, dbits, ltree, ltree_index, dtree, dtree_index, s, z); p = z.next_in_index; n = z.avail_in; b = s.bitb; k = s.bitk; q = s.write; m = q < s.read?s.read - q - 1:s.end - q; if (r != Z_OK) { mode = r == Z_STREAM_END?WASH:BADCODE; break; } } need = lbits; tree = ltree; tree_index = ltree_index; mode = LEN; goto case LEN; case LEN: // i: get length/literal/eob next j = need; while (k < (j)) { if (n != 0) { r = Z_OK; } else { s.bitb = b; s.bitk = k; z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p; s.write = q; return(s.inflate_flush(z, r)); } n--; b |= (z.next_in[p++] & 0xff) << k; k += 8; } tindex = (tree_index + (b & inflate_mask[j])) * 3; b = SupportClass.URShift(b, (tree[tindex + 1])); k -= (tree[tindex + 1]); e = tree[tindex]; if (e == 0) { // literal lit = tree[tindex + 2]; mode = LIT; break; } if ((e & 16) != 0) { // length get_Renamed = e & 15; len = tree[tindex + 2]; mode = LENEXT; break; } if ((e & 64) == 0) { // next table need = e; tree_index = tindex / 3 + tree[tindex + 2]; break; } if ((e & 32) != 0) { // end of block mode = WASH; break; } mode = BADCODE; // invalid code z.msg = "invalid literal/length code"; r = Z_DATA_ERROR; s.bitb = b; s.bitk = k; z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p; s.write = q; return(s.inflate_flush(z, r)); case LENEXT: // i: getting length extra (have base) j = get_Renamed; while (k < (j)) { if (n != 0) { r = Z_OK; } else { s.bitb = b; s.bitk = k; z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p; s.write = q; return(s.inflate_flush(z, r)); } n--; b |= (z.next_in[p++] & 0xff) << k; k += 8; } len += (b & inflate_mask[j]); b >>= j; k -= j; need = dbits; tree = dtree; tree_index = dtree_index; mode = DIST; goto case DIST; case DIST: // i: get distance next j = need; while (k < (j)) { if (n != 0) { r = Z_OK; } else { s.bitb = b; s.bitk = k; z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p; s.write = q; return(s.inflate_flush(z, r)); } n--; b |= (z.next_in[p++] & 0xff) << k; k += 8; } tindex = (tree_index + (b & inflate_mask[j])) * 3; b >>= tree[tindex + 1]; k -= tree[tindex + 1]; e = (tree[tindex]); if ((e & 16) != 0) { // distance get_Renamed = e & 15; dist = tree[tindex + 2]; mode = DISTEXT; break; } if ((e & 64) == 0) { // next table need = e; tree_index = tindex / 3 + tree[tindex + 2]; break; } mode = BADCODE; // invalid code z.msg = "invalid distance code"; r = Z_DATA_ERROR; s.bitb = b; s.bitk = k; z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p; s.write = q; return(s.inflate_flush(z, r)); case DISTEXT: // i: getting distance extra j = get_Renamed; while (k < (j)) { if (n != 0) { r = Z_OK; } else { s.bitb = b; s.bitk = k; z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p; s.write = q; return(s.inflate_flush(z, r)); } n--; b |= (z.next_in[p++] & 0xff) << k; k += 8; } dist += (b & inflate_mask[j]); b >>= j; k -= j; mode = COPY; goto case COPY; case COPY: // o: copying bytes in window, waiting for space f = q - dist; while (f < 0) { // modulo window size-"while" instead f += s.end; // of "if" handles invalid distances } while (len != 0) { if (m == 0) { if (q == s.end && s.read != 0) { q = 0; m = q < s.read?s.read - q - 1:s.end - q; } if (m == 0) { s.write = q; r = s.inflate_flush(z, r); q = s.write; m = q < s.read?s.read - q - 1:s.end - q; if (q == s.end && s.read != 0) { q = 0; m = q < s.read?s.read - q - 1:s.end - q; } if (m == 0) { s.bitb = b; s.bitk = k; z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p; s.write = q; return(s.inflate_flush(z, r)); } } } s.window[q++] = s.window[f++]; m--; if (f == s.end) { f = 0; } len--; } mode = START; break; case LIT: // o: got literal, waiting for output space if (m == 0) { if (q == s.end && s.read != 0) { q = 0; m = q < s.read?s.read - q - 1:s.end - q; } if (m == 0) { s.write = q; r = s.inflate_flush(z, r); q = s.write; m = q < s.read?s.read - q - 1:s.end - q; if (q == s.end && s.read != 0) { q = 0; m = q < s.read?s.read - q - 1:s.end - q; } if (m == 0) { s.bitb = b; s.bitk = k; z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p; s.write = q; return(s.inflate_flush(z, r)); } } } r = Z_OK; s.window[q++] = (byte)lit; m--; mode = START; break; case WASH: // o: got eob, possibly more output if (k > 7) { // return unused byte, if any k -= 8; n++; p--; // can always return one } s.write = q; r = s.inflate_flush(z, r); q = s.write; m = q < s.read?s.read - q - 1:s.end - q; if (s.read != s.write) { s.bitb = b; s.bitk = k; z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p; s.write = q; return(s.inflate_flush(z, r)); } mode = END; goto case END; case END: r = Z_STREAM_END; s.bitb = b; s.bitk = k; z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p; s.write = q; return(s.inflate_flush(z, r)); case BADCODE: // x: got error r = Z_DATA_ERROR; s.bitb = b; s.bitk = k; z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p; s.write = q; return(s.inflate_flush(z, r)); default: r = Z_STREAM_ERROR; s.bitb = b; s.bitk = k; z.avail_in = n; z.total_in += p - z.next_in_index; z.next_in_index = p; s.write = q; return(s.inflate_flush(z, r)); } } }
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[] numArray1 = new int[0x10]; int[] numArray2 = new int[3]; int[] numArray3 = new int[15]; int[] numArray4 = new int[0x10]; int num10 = 0; int num5 = n; do { numArray1[b[bindex + num10]]++; num10++; num5--; }while (num5 != 0); if (numArray1[0] == n) { t[0] = -1; m[0] = 0; return(0); } int num8 = m[0]; int num6 = 1; while (num6 <= 15) { if (numArray1[num6] != 0) { break; } num6++; } int num7 = num6; if (num8 < num6) { num8 = num6; } num5 = 15; while (num5 != 0) { if (numArray1[num5] != 0) { break; } num5--; } int num3 = num5; if (num8 > num5) { num8 = num5; } m[0] = num8; int num14 = 1 << (num6 & 0x1f); while (num6 < num5) { num14 -= numArray1[num6]; if (num14 < 0) { return(-3); } num6++; num14 = num14 << 1; } num14 -= numArray1[num5]; if (num14 < 0) { return(-3); } numArray1[num5] += num14; numArray4[1] = num6 = 0; num10 = 1; int num13 = 2; while (--num5 != 0) { numArray4[num13] = num6 += numArray1[num10]; num13++; num10++; } num5 = 0; num10 = 0; do { num6 = b[bindex + num10]; if (num6 != 0) { v[numArray4[num6]++] = num5; } num10++; }while (++num5 < n); n = numArray4[num3]; numArray4[0] = num5 = 0; num10 = 0; int num4 = -1; int num12 = -num8; numArray3[0] = 0; int num11 = 0; int num15 = 0; while (num7 <= num3) { int num2; int num1 = numArray1[num7]; goto Label_03BD; Label_01B2: num4++; num12 += num8; num15 = num3 - num12; num15 = (num15 > num8) ? num8 : num15; if ((num2 = 1 << ((num6 = num7 - num12) & 0x1f)) > (num1 + 1)) { num2 -= num1 + 1; num13 = num7; if (num6 < num15) { while (++num6 < num15) { if ((num2 = num2 << 1) <= numArray1[++num13]) { break; } num2 -= numArray1[num13]; } } } num15 = 1 << (num6 & 0x1f); if ((hn[0] + num15) > 0x5a0) { return(-3); } numArray3[num4] = num11 = hn[0]; hn[0] += num15; if (num4 != 0) { numArray4[num4] = num5; numArray2[0] = (byte)num6; numArray2[1] = (byte)num8; num6 = SupportClass.URShift(num5, num12 - num8); numArray2[2] = (num11 - numArray3[num4 - 1]) - num6; Array.Copy(numArray2, 0, hp, (numArray3[num4 - 1] + num6) * 3, 3); } else { t[0] = num11; } Label_02AE: if (num7 > (num12 + num8)) { goto Label_01B2; } numArray2[1] = (byte)(num7 - num12); if (num10 >= n) { numArray2[0] = 0xc0; } else if (v[num10] < s) { numArray2[0] = (v[num10] < 0x100) ? ((byte)0) : ((byte)0x60); numArray2[2] = v[num10++]; } else { numArray2[0] = (byte)((e[v[num10] - s] + 0x10) + 0x40); numArray2[2] = d[v[num10++] - s]; } num2 = 1 << ((num7 - num12) & 0x1f); num6 = SupportClass.URShift(num5, num12); while (num6 < num15) { Array.Copy(numArray2, 0, hp, (num11 + num6) * 3, 3); num6 += num2; } num6 = 1 << ((num7 - 1) & 0x1f); while ((num5 & num6) != 0) { num5 ^= num6; num6 = SupportClass.URShift(num6, 1); } num5 ^= num6; for (int num9 = (1 << (num12 & 0x1f)) - 1; (num5 & num9) != numArray4[num4]; num9 = (1 << (num12 & 0x1f)) - 1) { num4--; num12 -= num8; } Label_03BD: if (num1-- != 0) { goto Label_02AE; } num7++; } if ((num14 != 0) && (num3 != 1)) { return(-5); } return(0); }
// zlib.InfBlocks // zlib.InfBlocks internal int proc(ZStream z, int r) { int num = z.next_in_index; int num2 = z.avail_in; int num3 = this.bitb; int i = this.bitk; int num4 = this.write; int num5 = (num4 < this.read) ? (this.read - num4 - 1) : (this.end - num4); int num6; while (true) { switch (this.mode) { case 0: while (i < 3) { if (num2 == 0) { return(procRet(z, i, r, num, num2, num3, num4)); } r = 0; num2--; num3 |= (int)(z.next_in[num++] & 255) << i; i += 8; } num6 = (num3 & 7); this.last = (num6 & 1); switch (SupportClass.URShift(num6, 1)) { case 0: num3 = SupportClass.URShift(num3, 3); i -= 3; num6 = (i & 7); num3 = SupportClass.URShift(num3, num6); i -= num6; this.mode = 1; continue; case 1: { int[] array = new int[1]; int[] array2 = new int[1]; int[][] array3 = new int[1][]; int[][] array4 = new int[1][]; InfTree.inflate_trees_fixed(array, array2, array3, array4, z); this.codes = new InfCodes(array[0], array2[0], array3[0], array4[0], z); num3 = SupportClass.URShift(num3, 3); i -= 3; this.mode = 6; continue; } case 2: num3 = SupportClass.URShift(num3, 3); i -= 3; this.mode = 3; continue; case 3: num3 = SupportClass.URShift(num3, 3); i -= 3; this.mode = 9; z.msg = "invalid block type"; return(procRet(z, i, -3, num, num2, num3, num4)); default: continue; } break; case 1: { while (i < 32) { if (num2 == 0) { return(procRet(z, i, r, num, num2, num3, num4)); } r = 0; num2--; num3 |= (int)(z.next_in[num++] & 255) << i; i += 8; } if ((SupportClass.URShift(~num3, 16) & 65535) != (num3 & 65535)) { this.mode = 9; z.msg = "invalid stored block lengths"; return(procRet(z, i, -3, num, num2, num3, num4)); } this.left = (num3 & 65535); int arg_686_0 = 0; i = 0; num3 = arg_686_0; this.mode = ((this.left != 0) ? 2 : ((this.last != 0) ? 7 : 0)); continue; } case 2: if (num2 == 0) { return(procRet(z, i, r, num, num2, num3, num4)); } if (num5 == 0) { if (num4 == this.end && this.read != 0) { num4 = 0; num5 = ((0 < this.read) ? (this.read - num4 - 1) : (this.end - num4)); } if (num5 == 0) { this.write = num4; r = this.inflate_flush(z, r); num4 = this.write; num5 = ((num4 < this.read) ? (this.read - num4 - 1) : (this.end - num4)); if (num4 == this.end && this.read != 0) { num4 = 0; num5 = ((0 < this.read) ? (this.read - num4 - 1) : (this.end - num4)); } if (num5 == 0) { return(procRet(z, i, r, num, num2, num3, num4)); } } } r = 0; num6 = this.left; if (num6 > num2) { num6 = num2; } if (num6 > num5) { num6 = num5; } Array.Copy(z.next_in, num, this.window, num4, num6); num += num6; num2 -= num6; num4 += num6; num5 -= num6; if ((this.left -= num6) == 0) { this.mode = ((this.last != 0) ? 7 : 0); continue; } continue; case 3: while (i < 14) { if (num2 == 0) { return(procRet(z, i, r, num, num2, num3, num4)); } r = 0; num2--; num3 |= (int)(z.next_in[num++] & 255) << i; i += 8; } num6 = (this.table = (num3 & 16383)); if ((num6 & 31) <= 29 && (num6 >> 5 & 31) <= 29) { num6 = 258 + (num6 & 31) + (num6 >> 5 & 31); this.blens = new int[num6]; num3 = SupportClass.URShift(num3, 14); i -= 14; this.index = 0; this.mode = 4; goto case 4; } this.mode = 9; z.msg = "too many length or distance symbols"; return(procRet(z, i, -3, num, num2, num3, num4)); case 4: while (this.index < 4 + SupportClass.URShift(this.table, 10)) { while (i < 3) { if (num2 == 0) { return(procRet(z, i, r, num, num2, num3, num4)); } r = 0; num2--; num3 |= (int)(z.next_in[num++] & 255) << i; i += 8; } this.blens[InfBlocks.border[this.index++]] = (num3 & 7); num3 = SupportClass.URShift(num3, 3); i -= 3; } while (this.index < 19) { this.blens[InfBlocks.border[this.index++]] = 0; } this.bb[0] = 7; num6 = InfTree.inflate_trees_bits(this.blens, this.bb, this.tb, this.hufts, z); if (num6 == 0) { this.index = 0; this.mode = 5; goto case 5; } if (num6 == -3) { this.blens = null; this.mode = 9; } return(procRet(z, i, num6, num, num2, num3, num4)); case 5: while (true) { num6 = this.table; if (this.index >= 258 + (num6 & 31) + (num6 >> 5 & 31)) { break; } num6 = this.bb[0]; while (i < num6) { if (num2 == 0) { return(procRet(z, i, r, num, num2, num3, num4)); } r = 0; num2--; num3 |= (int)(z.next_in[num++] & 255) << i; i += 8; } num6 = this.hufts[(this.tb[0] + (num3 & InfBlocks.inflate_mask[num6])) * 3 + 1]; int num7 = this.hufts[(this.tb[0] + (num3 & InfBlocks.inflate_mask[num6])) * 3 + 2]; if (num7 < 16) { num3 = SupportClass.URShift(num3, num6); i -= num6; this.blens[this.index++] = num7; } else { int num8 = (num7 == 18) ? 7 : (num7 - 14); int num9 = (num7 == 18) ? 11 : 3; while (i < num6 + num8) { if (num2 == 0) { return(procRet(z, i, r, num, num2, num3, num4)); } r = 0; num2--; num3 |= (int)(z.next_in[num++] & 255) << i; i += 8; } num3 = SupportClass.URShift(num3, num6); i -= num6; num9 += (num3 & InfBlocks.inflate_mask[num8]); num3 = SupportClass.URShift(num3, num8); i -= num8; num8 = this.index; num6 = this.table; if (num8 + num9 > 258 + (num6 & 31) + (num6 >> 5 & 31) || (num7 == 16 && num8 < 1)) { this.blens = null; this.mode = 9; z.msg = "invalid bit length repeat"; return(procRet(z, i, -3, num, num2, num3, num4)); } num7 = ((num7 == 16) ? this.blens[num8 - 1] : 0); do { this.blens[num8++] = num7; } while (--num9 != 0); this.index = num8; } } this.tb[0] = -1; int[] array5 = new int[1]; int[] array6 = new int[1]; int[] array7 = new int[1]; int[] array8 = new int[1]; array5[0] = 9; array6[0] = 6; num6 = this.table; num6 = InfTree.inflate_trees_dynamic(257 + (num6 & 31), 1 + (num6 >> 5 & 31), this.blens, array5, array6, array7, array8, this.hufts, z); if (num6 == 0) { this.codes = new InfCodes(array5[0], array6[0], this.hufts, array7[0], this.hufts, array8[0], z); this.blens = null; this.mode = 6; goto case 6; } if (num6 == -3) { this.blens = null; this.mode = 9; } return(procRet(z, i, num6, num, num2, num3, num4)); case 6: this.bitb = num3; this.bitk = i; z.avail_in = num2; z.total_in += (long)(num - z.next_in_index); z.next_in_index = num; this.write = num4; if ((r = this.codes.proc(this, z, r)) != 1) { break; } r = 0; this.codes.free(z); num = z.next_in_index; num2 = z.avail_in; num3 = this.bitb; i = this.bitk; num4 = this.write; num5 = ((num4 < this.read) ? (this.read - num4 - 1) : (this.end - num4)); if (this.last != 0) { this.mode = 7; goto case 7; } this.mode = 0; continue; case 7: this.write = num4; r = this.inflate_flush(z, r); num4 = this.write; int arg_CC8_0 = (num4 < this.read) ? (this.read - num4 - 1) : (this.end - num4); if (this.read != this.write) { return(procRet(z, i, r, num, num2, num3, num4)); } this.mode = 8; goto case 8; case 8: return(procRet(z, i, 1, num, num2, num3, num4)); case 9: return(procRet(z, i, -3, num, num2, num3, num4)); } return(procRet(z, i, -2, num, num2, num3, num4)); } return(this.inflate_flush(z, r)); }
internal int proc(ZStream z, int r) { int num1; int num4 = z.next_in_index; int num5 = z.avail_in; int num2 = this.bitb; int num3 = this.bitk; int num6 = this.write; int num7 = (num6 < this.read) ? ((this.read - num6) - 1) : (this.end - num6); Label_0047: switch (this.mode) { case 0: while (num3 < 3) { if (num5 != 0) { r = 0; } else { this.bitb = num2; this.bitk = num3; z.avail_in = num5; z.total_in += num4 - z.next_in_index; z.next_in_index = num4; this.write = num6; return(this.inflate_flush(z, r)); } num5--; num2 |= (z.next_in[num4++] & 0xff) << (num3 & 0x1f); num3 += 8; } num1 = num2 & 7; this.last = num1 & 1; switch (SupportClass.URShift(num1, 1)) { case 0: num2 = SupportClass.URShift(num2, 3); num3 -= 3; num1 = num3 & 7; num2 = SupportClass.URShift(num2, num1); num3 -= num1; this.mode = 1; goto Label_0047; case 1: { int[] numArray1 = new int[1]; int[] numArray2 = new int[1]; int[][] numArrayArray1 = new int[1][]; int[][] numArrayArray2 = new int[1][]; InfTree.inflate_trees_fixed(numArray1, numArray2, numArrayArray1, numArrayArray2, z); this.codes = new InfCodes(numArray1[0], numArray2[0], numArrayArray1[0], numArrayArray2[0], z); num2 = SupportClass.URShift(num2, 3); num3 -= 3; this.mode = 6; goto Label_0047; } case 2: num2 = SupportClass.URShift(num2, 3); num3 -= 3; this.mode = 3; goto Label_0047; case 3: num2 = SupportClass.URShift(num2, 3); num3 -= 3; this.mode = 9; z.msg = "invalid block type"; r = -3; this.bitb = num2; this.bitk = num3; z.avail_in = num5; z.total_in += num4 - z.next_in_index; z.next_in_index = num4; this.write = num6; return(this.inflate_flush(z, r)); } goto Label_0047; case 1: while (num3 < 0x20) { if (num5 != 0) { r = 0; } else { this.bitb = num2; this.bitk = num3; z.avail_in = num5; z.total_in += num4 - z.next_in_index; z.next_in_index = num4; this.write = num6; return(this.inflate_flush(z, r)); } num5--; num2 |= (z.next_in[num4++] & 0xff) << (num3 & 0x1f); num3 += 8; } if ((SupportClass.URShift(~num2, 0x10) & 0xffff) != (num2 & 0xffff)) { this.mode = 9; z.msg = "invalid stored block lengths"; r = -3; this.bitb = num2; this.bitk = num3; z.avail_in = num5; z.total_in += num4 - z.next_in_index; z.next_in_index = num4; this.write = num6; return(this.inflate_flush(z, r)); } this.left = num2 & 0xffff; num2 = num3 = 0; this.mode = (this.left != 0) ? 2 : ((this.last != 0) ? 7 : 0); goto Label_0047; case 2: if (num5 == 0) { this.bitb = num2; this.bitk = num3; z.avail_in = num5; z.total_in += num4 - z.next_in_index; z.next_in_index = num4; this.write = num6; return(this.inflate_flush(z, r)); } if (num7 == 0) { if ((num6 == this.end) && (this.read != 0)) { num6 = 0; num7 = (num6 < this.read) ? ((this.read - num6) - 1) : (this.end - num6); } if (num7 == 0) { this.write = num6; r = this.inflate_flush(z, r); num6 = this.write; num7 = (num6 < this.read) ? ((this.read - num6) - 1) : (this.end - num6); if ((num6 == this.end) && (this.read != 0)) { num6 = 0; num7 = (num6 < this.read) ? ((this.read - num6) - 1) : (this.end - num6); } if (num7 == 0) { this.bitb = num2; this.bitk = num3; z.avail_in = num5; z.total_in += num4 - z.next_in_index; z.next_in_index = num4; this.write = num6; return(this.inflate_flush(z, r)); } } } r = 0; num1 = this.left; if (num1 > num5) { num1 = num5; } if (num1 > num7) { num1 = num7; } Array.Copy(z.next_in, num4, this.window, num6, num1); num4 += num1; num5 -= num1; num6 += num1; num7 -= num1; this.left -= num1; if (this.left == 0) { this.mode = (this.last != 0) ? 7 : 0; } goto Label_0047; case 3: while (num3 < 14) { if (num5 != 0) { r = 0; } else { this.bitb = num2; this.bitk = num3; z.avail_in = num5; z.total_in += num4 - z.next_in_index; z.next_in_index = num4; this.write = num6; return(this.inflate_flush(z, r)); } num5--; num2 |= (z.next_in[num4++] & 0xff) << (num3 & 0x1f); num3 += 8; } this.table = num1 = num2 & 0x3fff; if (((num1 & 0x1f) > 0x1d) || (((num1 >> 5) & 0x1f) > 0x1d)) { this.mode = 9; z.msg = "too many length or distance symbols"; r = -3; this.bitb = num2; this.bitk = num3; z.avail_in = num5; z.total_in += num4 - z.next_in_index; z.next_in_index = num4; this.write = num6; return(this.inflate_flush(z, r)); } num1 = (0x102 + (num1 & 0x1f)) + ((num1 >> 5) & 0x1f); this.blens = new int[num1]; num2 = SupportClass.URShift(num2, 14); num3 -= 14; this.index = 0; this.mode = 4; goto Label_06E1; case 4: goto Label_06E1; 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 = num2; this.bitk = num3; z.avail_in = num5; z.total_in += num4 - z.next_in_index; z.next_in_index = num4; this.write = num6; return(this.inflate_flush(z, r)); default: r = -2; this.bitb = num2; this.bitk = num3; z.avail_in = num5; z.total_in += num4 - z.next_in_index; z.next_in_index = num4; this.write = num6; return(this.inflate_flush(z, r)); } Label_06E1: if (this.index < (4 + SupportClass.URShift(this.table, 10))) { while (num3 < 3) { if (num5 != 0) { r = 0; } else { this.bitb = num2; this.bitk = num3; z.avail_in = num5; z.total_in += num4 - z.next_in_index; z.next_in_index = num4; this.write = num6; return(this.inflate_flush(z, r)); } num5--; num2 |= (z.next_in[num4++] & 0xff) << (num3 & 0x1f); num3 += 8; } this.blens[InfBlocks.border[this.index++]] = num2 & 7; num2 = SupportClass.URShift(num2, 3); num3 -= 3; goto Label_06E1; } while (this.index < 0x13) { this.blens[InfBlocks.border[this.index++]] = 0; } this.bb[0] = 7; num1 = InfTree.inflate_trees_bits(this.blens, this.bb, this.tb, this.hufts, z); if (num1 != 0) { r = num1; if (r == -3) { this.blens = null; this.mode = 9; } this.bitb = num2; this.bitk = num3; z.avail_in = num5; z.total_in += num4 - z.next_in_index; z.next_in_index = num4; this.write = num6; return(this.inflate_flush(z, r)); } this.index = 0; this.mode = 5; Label_07B9: num1 = this.table; if (this.index < ((0x102 + (num1 & 0x1f)) + ((num1 >> 5) & 0x1f))) { num1 = this.bb[0]; while (num3 < num1) { if (num5 != 0) { r = 0; } else { this.bitb = num2; this.bitk = num3; z.avail_in = num5; z.total_in += num4 - z.next_in_index; z.next_in_index = num4; this.write = num6; return(this.inflate_flush(z, r)); } num5--; num2 |= (z.next_in[num4++] & 0xff) << (num3 & 0x1f); num3 += 8; } int num17 = this.tb[0]; num1 = this.hufts[((this.tb[0] + (num2 & InfBlocks.inflate_mask[num1])) * 3) + 1]; int num10 = this.hufts[((this.tb[0] + (num2 & InfBlocks.inflate_mask[num1])) * 3) + 2]; if (num10 < 0x10) { num2 = SupportClass.URShift(num2, num1); num3 -= num1; this.blens[this.index++] = num10; goto Label_07B9; } int num8 = (num10 == 0x12) ? 7 : (num10 - 14); int num9 = (num10 == 0x12) ? 11 : 3; while (num3 < (num1 + num8)) { if (num5 != 0) { r = 0; } else { this.bitb = num2; this.bitk = num3; z.avail_in = num5; z.total_in += num4 - z.next_in_index; z.next_in_index = num4; this.write = num6; return(this.inflate_flush(z, r)); } num5--; num2 |= (z.next_in[num4++] & 0xff) << (num3 & 0x1f); num3 += 8; } num2 = SupportClass.URShift(num2, num1); num3 -= num1; num9 += num2 & InfBlocks.inflate_mask[num8]; num2 = SupportClass.URShift(num2, num8); num3 -= num8; num8 = this.index; num1 = this.table; if (((num8 + num9) > ((0x102 + (num1 & 0x1f)) + ((num1 >> 5) & 0x1f))) || ((num10 == 0x10) && (num8 < 1))) { this.blens = null; this.mode = 9; z.msg = "invalid bit length repeat"; r = -3; this.bitb = num2; this.bitk = num3; z.avail_in = num5; z.total_in += num4 - z.next_in_index; z.next_in_index = num4; this.write = num6; return(this.inflate_flush(z, r)); } num10 = (num10 == 0x10) ? this.blens[num8 - 1] : 0; do { this.blens[num8++] = num10; }while (--num9 != 0); this.index = num8; goto Label_07B9; } this.tb[0] = -1; int[] numArray3 = new int[1]; int[] numArray4 = new int[1]; int[] numArray5 = new int[1]; int[] numArray6 = new int[1]; numArray3[0] = 9; numArray4[0] = 6; num1 = this.table; num1 = InfTree.inflate_trees_dynamic(0x101 + (num1 & 0x1f), 1 + ((num1 >> 5) & 0x1f), this.blens, numArray3, numArray4, numArray5, numArray6, this.hufts, z); switch (num1) { case 0: this.codes = new InfCodes(numArray3[0], numArray4[0], this.hufts, numArray5[0], this.hufts, numArray6[0], z); this.blens = null; this.mode = 6; goto Label_0B63; case -3: this.blens = null; this.mode = 9; break; } r = num1; this.bitb = num2; this.bitk = num3; z.avail_in = num5; z.total_in += num4 - z.next_in_index; z.next_in_index = num4; this.write = num6; return(this.inflate_flush(z, r)); Label_0B63: this.bitb = num2; this.bitk = num3; z.avail_in = num5; z.total_in += num4 - z.next_in_index; z.next_in_index = num4; this.write = num6; if ((r = this.codes.proc(this, z, r)) != 1) { return(this.inflate_flush(z, r)); } r = 0; this.codes.free(z); num4 = z.next_in_index; num5 = z.avail_in; num2 = this.bitb; num3 = this.bitk; num6 = this.write; num7 = (num6 < this.read) ? ((this.read - num6) - 1) : (this.end - num6); if (this.last == 0) { this.mode = 0; goto Label_0047; } this.mode = 7; Label_0C2C: this.write = num6; r = this.inflate_flush(z, r); num6 = this.write; num7 = (num6 < this.read) ? ((this.read - num6) - 1) : (this.end - num6); if (this.read != this.write) { this.bitb = num2; this.bitk = num3; z.avail_in = num5; z.total_in += num4 - z.next_in_index; z.next_in_index = num4; this.write = num6; return(this.inflate_flush(z, r)); } this.mode = 8; Label_0CC1: r = 1; this.bitb = num2; this.bitk = num3; z.avail_in = num5; z.total_in += num4 - z.next_in_index; z.next_in_index = num4; this.write = num6; return(this.inflate_flush(z, r)); }
public int read(byte[] b, int off, int len) { if (len == 0) { return(0); } int err; z.next_out = b; z.next_out_index = off; z.avail_out = len; do { if ((z.avail_in == 0) && (!nomoreinput)) { // if buffer is empty and more input is avaiable, refill it z.next_in_index = 0; int inToRead = bufsize; if (maxInput > 0) { if (TotalIn < maxInput) { inToRead = (int)(Math.Min(maxInput - TotalIn, (long)bufsize)); } else { z.avail_in = -1; } } if (z.avail_in != -1) { z.avail_in = SupportClass.ReadInput(in_Renamed, buf, 0, inToRead); //(bufsize<z.avail_out ? bufsize : z.avail_out)); } if (z.avail_in == -1) { z.avail_in = 0; nomoreinput = true; } } if (compress) { err = z.deflate(flush); } else { err = z.inflate(flush); } if (nomoreinput && (err == zlibConst.Z_BUF_ERROR)) { return(-1); } if (err != zlibConst.Z_OK && err != zlibConst.Z_STREAM_END) { throw new ZStreamException((compress ? "de" : "in") + "flating: " + z.msg); } if (nomoreinput && (z.avail_out == len)) { return(-1); } }while (z.avail_out > 0 && err == zlibConst.Z_OK); //while (z.avail_out == len && err == zlibConst.Z_OK); //System.err.print("("+(len-z.avail_out)+")"); return(len - z.avail_out); }
// Mapping from a distance to a distance code. dist is the distance - 1 and // must not have side effects. _dist_code[256] and _dist_code[257] are never // used. internal static int d_code(int dist) { return((dist) < 256?_dist_code[dist]:_dist_code[256 + (SupportClass.URShift((dist), 7))]); }
internal static int huft_build(int[] b, int bindex, int n, int s, int[] d, int[] e, int[] t, int[] m, int[] hp, int[] hn, int[] v) { int[] array = new int[16]; int[] array2 = new int[3]; int[] array3 = new int[15]; int[] array4 = new int[16]; int num = 0; int num2 = n; int[] array5; IntPtr intPtr; do { (array5 = array)[(int)(intPtr = (IntPtr)b[bindex + num])] = array5[(int)intPtr] + 1; num++; num2--; }while (num2 != 0); if (array[0] == n) { t[0] = -1; m[0] = 0; return(0); } int num3 = m[0]; int i = 1; while (i <= 15 && array[i] == 0) { i++; } int j = i; if (num3 < i) { num3 = i; } num2 = 15; while (num2 != 0 && array[num2] == 0) { num2--; } int num4 = num2; if (num3 > num2) { num3 = num2; } m[0] = num3; int num5 = 1 << i; while (i < num2) { if ((num5 -= array[i]) < 0) { return(-3); } i++; num5 <<= 1; } if ((num5 -= array[num2]) < 0) { return(-3); } (array5 = array)[(int)(intPtr = (IntPtr)num2)] = array5[(int)intPtr] + num5; int[] arg_109_0 = array4; int arg_109_1 = 1; int arg_109_2 = 0; i = 0; arg_109_0[arg_109_1] = arg_109_2; num = 1; int num6 = 2; while (--num2 != 0) { i = (array4[num6] = i + array[num]); num6++; num++; } num2 = 0; num = 0; do { if ((i = b[bindex + num]) != 0) { int num7; (array5 = array4)[(int)(intPtr = (IntPtr)i)] = (num7 = array5[(int)intPtr]) + 1; v[num7] = num2; } num++; }while (++num2 < n); n = array4[num4]; int[] arg_188_0 = array4; int arg_188_1 = 0; int arg_188_2 = 0; num2 = 0; arg_188_0[arg_188_1] = arg_188_2; num = 0; int num8 = -1; int num9 = -num3; array3[0] = 0; int num10 = 0; int num11 = 0; while (j <= num4) { int num12 = array[j]; while (num12-- != 0) { int num13; while (j > num9 + num3) { num8++; num9 += num3; num11 = num4 - num9; num11 = ((num11 > num3) ? num3 : num11); if ((num13 = 1 << ((i = j - num9) & 31)) > num12 + 1) { num13 -= num12 + 1; num6 = j; if (i < num11) { while (++i < num11 && (num13 <<= 1) > array[++num6]) { num13 -= array[num6]; } } } num11 = 1 << i; if (hn[0] + num11 > 1440) { return(-3); } num10 = (array3[num8] = hn[0]); hn[0] = hn[0] + num11; if (num8 != 0) { array4[num8] = num2; array2[0] = (int)((byte)i); array2[1] = (int)((byte)num3); i = SupportClass.URShift(num2, num9 - num3); array2[2] = num10 - array3[num8 - 1] - i; Array.Copy(array2, 0, hp, (array3[num8 - 1] + i) * 3, 3); } else { t[0] = num10; } } array2[1] = (int)((byte)(j - num9)); if (num >= n) { array2[0] = 192; } else if (v[num] < s) { array2[0] = (int)((v[num] < 256) ? 0 : 96); array2[2] = v[num++]; } else { array2[0] = (int)((byte)(e[v[num] - s] + 16 + 64)); array2[2] = d[v[num++] - s]; } num13 = 1 << j - num9; for (i = SupportClass.URShift(num2, num9); i < num11; i += num13) { Array.Copy(array2, 0, hp, (num10 + i) * 3, 3); } i = 1 << j - 1; while ((num2 & i) != 0) { num2 ^= i; i = SupportClass.URShift(i, 1); } num2 ^= i; int num14 = (1 << num9) - 1; while ((num2 & num14) != array4[num8]) { num8--; num9 -= num3; num14 = (1 << num9) - 1; } } j++; } if (num5 != 0) { if (num4 != 1) { return(-5); } } return(0); }
public static long URShift(long number, long bits) { return(SupportClass.URShift(number, (int)bits)); }
public int read(byte[] b, int off, int len) { if (len == 0) { return(0); } this.z.next_out = b; this.z.next_out_index = off; this.z.avail_out = len; while (true) { if (this.z.avail_in == 0 && !this.nomoreinput) { this.z.next_in_index = 0; int count = this.bufsize; if (this.maxInput > 0L) { if (this.TotalIn < this.maxInput) { count = (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, count); } if (this.z.avail_in == -1) { this.z.avail_in = 0; this.nomoreinput = true; } } int num; if (this.compress) { num = this.z.deflate(this.flush); } else { num = this.z.inflate(this.flush); } if (this.nomoreinput && num == -5) { break; } if (num != 0 && num != 1) { goto Block_12; } if (this.nomoreinput && this.z.avail_out == len) { return(-1); } if (this.z.avail_out <= 0 || num != 0) { goto IL_184; } } return(-1); Block_12: throw new ZStreamException((this.compress ? "de" : "in") + "flating: " + this.z.msg); IL_184: return(len - this.z.avail_out); }
internal static int huft_build(int[] b, int bindex, int n, int s, int[] d, int[] e, int[] t, int[] m, int[] hp, int[] hn, int[] v) { int[] array = new int[16]; int[] array2 = new int[3]; int[] array3 = new int[15]; int[] array4 = new int[16]; int num = 0; int num2 = n; do { array[b[bindex + num]]++; num++; num2--; }while (num2 != 0); if (array[0] == n) { t[0] = -1; m[0] = 0; return(0); } int num3 = m[0]; int i = 1; while (i <= 15 && array[i] == 0) { i++; } int j = i; if (num3 < i) { num3 = i; } num2 = 15; while (num2 != 0 && array[num2] == 0) { num2--; } int num4 = num2; if (num3 > num2) { num3 = num2; } m[0] = num3; int num5 = 1 << i; while (i < num2) { if ((num5 -= array[i]) < 0) { return(-3); } i++; num5 <<= 1; } if ((num5 -= array[num2]) < 0) { return(-3); } array[num2] += num5; i = (array4[1] = 0); num = 1; int num6 = 2; while (--num2 != 0) { i = (array4[num6] = i + array[num]); num6++; num++; } num2 = 0; num = 0; do { if ((i = b[bindex + num]) != 0) { v[array4[i]++] = num2; } num++; }while (++num2 < n); n = array4[num4]; num2 = (array4[0] = 0); num = 0; int num7 = -1; int num8 = -num3; array3[0] = 0; int num9 = 0; int num10 = 0; while (j <= num4) { int num11 = array[j]; while (num11-- != 0) { int num12; while (j > num8 + num3) { num7++; num8 += num3; num10 = num4 - num8; num10 = ((num10 > num3) ? num3 : num10); if ((num12 = 1 << ((i = j - num8) & 31)) > num11 + 1) { num12 -= num11 + 1; num6 = j; if (i < num10) { while (++i < num10 && (num12 <<= 1) > array[++num6]) { num12 -= array[num6]; } } } num10 = 1 << i; if (hn[0] + num10 > 1440) { return(-3); } num9 = (array3[num7] = hn[0]); hn[0] += num10; if (num7 != 0) { array4[num7] = num2; array2[0] = (int)((byte)i); array2[1] = (int)((byte)num3); i = SupportClass.URShift(num2, num8 - num3); array2[2] = num9 - array3[num7 - 1] - i; Array.Copy(array2, 0, hp, (array3[num7 - 1] + i) * 3, 3); } else { t[0] = num9; } } array2[1] = (int)((byte)(j - num8)); if (num >= n) { array2[0] = 192; } else { if (v[num] < s) { array2[0] = (int)((v[num] < 256) ? 0 : 96); array2[2] = v[num++]; } else { array2[0] = (int)((byte)(e[v[num] - s] + 16 + 64)); array2[2] = d[v[num++] - s]; } } num12 = 1 << j - num8; for (i = SupportClass.URShift(num2, num8); i < num10; i += num12) { Array.Copy(array2, 0, hp, (num9 + i) * 3, 3); } i = 1 << j - 1; while ((num2 & i) != 0) { num2 ^= i; i = SupportClass.URShift(i, 1); } num2 ^= i; int num13 = (1 << num8) - 1; while ((num2 & num13) != array4[num7]) { num7--; num8 -= num3; num13 = (1 << num8) - 1; } } j++; } if (num5 == 0 || num4 == 1) { return(0); } return(-5); }