internal int Initialize(ZlibCodec codec, int w) { _codec = codec; _codec.Message = null; blocks = null; // handle undocumented nowrap option (no zlib header or check) //nowrap = 0; //if (w < 0) //{ // w = - w; // nowrap = 1; //} // set window size if (w < 8 || w > 15) { End(); throw new ZlibException("Bad window size."); //return ZlibConstants.Z_STREAM_ERROR; } wbits = w; blocks = new InflateBlocks(codec, HandleRfc1950HeaderBytes ? this : null, 1 << w); // reset state Reset(); return ZlibConstants.Z_OK; }
internal int Initialize(ZlibCodec codec, int w) { _codec = codec; _codec.Message = null; blocks = null; // handle undocumented nowrap option (no zlib header or check) //nowrap = 0; //if (w < 0) //{ // w = - w; // nowrap = 1; //} // set window size if (w < 8 || w > 15) { End(); throw new ZlibException("Bad window size."); //return ZlibConstants.Z_STREAM_ERROR; } wbits = w; blocks = new InflateBlocks(codec, HandleRfc1950HeaderBytes ? this : null, 1 << w); // reset state Reset(); return(ZlibConstants.Z_OK); }
internal int End() { if (blocks != null) blocks.Free(); blocks = null; return ZlibConstants.Z_OK; }
internal void End() { if (blocks != null) { blocks.Free(); } blocks = null; }
internal int End() { if (blocks != null) { blocks.Free(); } blocks = null; return(ZlibConstants.Z_OK); }
internal void Initialize( ZlibCodec codec, int w ) { _codec = codec; blocks = null; wbits = w; blocks = new InflateBlocks( codec, 1 << w ); Reset(); }
internal int End() { if (this.blocks != null) { this.blocks.Free(); } this.blocks = null; return(0); }
internal void Initialize(ZlibCodec codec, int w) { _codec = codec; blocks = null; wbits = w; blocks = new InflateBlocks(codec, 1 << w); Reset(); }
internal int Initialize(ZlibCodec codec, int w) { this._codec = codec; this._codec.Message = null; this.blocks = null; if (w < 8 || w > 15) { this.End(); throw new ZlibException("Bad window size."); } this.wbits = w; this.blocks = new InflateBlocks(codec, this.HandleRfc1950HeaderBytes ? this : null, 1 << w); this.Reset(); return(0); }
internal int InflateFast(int bl, int bd, int[] tl, int tl_index, int[] td, int td_index, InflateBlocks s, ZlibCodec z) { int num1 = z.NextIn; int num2 = z.AvailableBytesIn; int num3 = s.bitb; int num4 = s.bitk; int destinationIndex = s.writeAt; int num5 = destinationIndex < s.readAt ? s.readAt - destinationIndex - 1 : s.end - destinationIndex; int num6 = InternalInflateConstants.InflateMask[bl]; int num7 = InternalInflateConstants.InflateMask[bd]; do { while (num4 < 20) { --num2; num3 |= ((int)z.InputBuffer[num1++] & (int)byte.MaxValue) << num4; num4 += 8; } int num8 = num3 & num6; int[] numArray1 = tl; int num9 = tl_index; int index1 = (num9 + num8) * 3; int index2; if ((index2 = numArray1[index1]) == 0) { num3 >>= numArray1[index1 + 1]; num4 -= numArray1[index1 + 1]; s.window[destinationIndex++] = (byte)numArray1[index1 + 2]; --num5; } else { bool flag; while (true) { num3 >>= numArray1[index1 + 1]; num4 -= numArray1[index1 + 1]; if ((index2 & 16) == 0) { if ((index2 & 64) == 0) { num8 = num8 + numArray1[index1 + 2] + (num3 & InternalInflateConstants.InflateMask[index2]); index1 = (num9 + num8) * 3; if ((index2 = numArray1[index1]) != 0) { flag = true; } else { goto label_34; } } else { goto label_35; } } else { break; } } int index3 = index2 & 15; int length1 = numArray1[index1 + 2] + (num3 & InternalInflateConstants.InflateMask[index3]); int num10 = num3 >> index3; int num11 = num4 - index3; while (num11 < 15) { --num2; num10 |= ((int)z.InputBuffer[num1++] & (int)byte.MaxValue) << num11; num11 += 8; } int num12 = num10 & num7; int[] numArray2 = td; int num13 = td_index; int index4 = (num13 + num12) * 3; int index5 = numArray2[index4]; while (true) { num10 >>= numArray2[index4 + 1]; num11 -= numArray2[index4 + 1]; if ((index5 & 16) == 0) { if ((index5 & 64) == 0) { num12 = num12 + numArray2[index4 + 2] + (num10 & InternalInflateConstants.InflateMask[index5]); index4 = (num13 + num12) * 3; index5 = numArray2[index4]; flag = true; } else { goto label_31; } } else { break; } } int index6 = index5 & 15; while (num11 < index6) { --num2; num10 |= ((int)z.InputBuffer[num1++] & (int)byte.MaxValue) << num11; num11 += 8; } int num14 = numArray2[index4 + 2] + (num10 & InternalInflateConstants.InflateMask[index6]); num3 = num10 >> index6; num4 = num11 - index6; num5 -= length1; int sourceIndex1; int num15; if (destinationIndex >= num14) { int sourceIndex2 = destinationIndex - num14; if (destinationIndex - sourceIndex2 > 0 && 2 > destinationIndex - sourceIndex2) { byte[] numArray3 = s.window; int index7 = destinationIndex; int num16 = 1; int num17 = index7 + num16; byte[] numArray4 = s.window; int index8 = sourceIndex2; int num18 = 1; int num19 = index8 + num18; int num20 = (int)numArray4[index8]; numArray3[index7] = (byte)num20; byte[] numArray5 = s.window; int index9 = num17; int num21 = 1; destinationIndex = index9 + num21; byte[] numArray6 = s.window; int index10 = num19; int num22 = 1; sourceIndex1 = index10 + num22; int num23 = (int)numArray6[index10]; numArray5[index9] = (byte)num23; length1 -= 2; } else { Array.Copy((Array)s.window, sourceIndex2, (Array)s.window, destinationIndex, 2); destinationIndex += 2; sourceIndex1 = sourceIndex2 + 2; length1 -= 2; } } else { sourceIndex1 = destinationIndex - num14; do { sourceIndex1 += s.end; }while (sourceIndex1 < 0); int length2 = s.end - sourceIndex1; if (length1 > length2) { length1 -= length2; if (destinationIndex - sourceIndex1 > 0 && length2 > destinationIndex - sourceIndex1) { do { s.window[destinationIndex++] = s.window[sourceIndex1++]; }while (--length2 != 0); } else { Array.Copy((Array)s.window, sourceIndex1, (Array)s.window, destinationIndex, length2); destinationIndex += length2; num15 = sourceIndex1 + length2; } sourceIndex1 = 0; } } if (destinationIndex - sourceIndex1 > 0 && length1 > destinationIndex - sourceIndex1) { do { s.window[destinationIndex++] = s.window[sourceIndex1++]; }while (--length1 != 0); goto label_39; } else { Array.Copy((Array)s.window, sourceIndex1, (Array)s.window, destinationIndex, length1); destinationIndex += length1; num15 = sourceIndex1 + length1; goto label_39; } label_31: z.Message = "invalid distance code"; int num24 = z.AvailableBytesIn - num2; int num25 = num11 >> 3 < num24 ? num11 >> 3 : num24; int num26 = num2 + num25; int num27 = num1 - num25; int num28 = num11 - (num25 << 3); s.bitb = num10; s.bitk = num28; z.AvailableBytesIn = num26; z.TotalBytesIn += (long)(num27 - z.NextIn); z.NextIn = num27; s.writeAt = destinationIndex; return(-3); label_34: num3 >>= numArray1[index1 + 1]; num4 -= numArray1[index1 + 1]; s.window[destinationIndex++] = (byte)numArray1[index1 + 2]; --num5; goto label_39; label_35: if ((index2 & 32) != 0) { int num16 = z.AvailableBytesIn - num2; int num17 = num4 >> 3 < num16 ? num4 >> 3 : num16; int num18 = num2 + num17; int num19 = num1 - num17; int num20 = num4 - (num17 << 3); s.bitb = num3; s.bitk = num20; z.AvailableBytesIn = num18; z.TotalBytesIn += (long)(num19 - z.NextIn); z.NextIn = num19; s.writeAt = destinationIndex; return(1); } z.Message = "invalid literal/length code"; int num29 = z.AvailableBytesIn - num2; int num30 = num4 >> 3 < num29 ? num4 >> 3 : num29; int num31 = num2 + num30; int num32 = num1 - num30; int num33 = num4 - (num30 << 3); s.bitb = num3; s.bitk = num33; z.AvailableBytesIn = num31; z.TotalBytesIn += (long)(num32 - z.NextIn); z.NextIn = num32; s.writeAt = destinationIndex; return(-3); label_39 :; } }while (num5 >= 258 && num2 >= 10); int num34 = z.AvailableBytesIn - num2; int num35 = num4 >> 3 < num34 ? num4 >> 3 : num34; int num36 = num2 + num35; int num37 = num1 - num35; int num38 = num4 - (num35 << 3); s.bitb = num3; s.bitk = num38; z.AvailableBytesIn = num36; z.TotalBytesIn += (long)(num37 - z.NextIn); z.NextIn = num37; s.writeAt = destinationIndex; return(0); }
internal int InflateFast(int bl, int bd, int[] tl, int tl_index, int[] td, int td_index, InflateBlocks s, ZlibCodec z) { int nextIn = z.NextIn; int num = z.AvailableBytesIn; int num2 = s.bitb; int num3 = s.bitk; int num4 = s.writeAt; int num5 = (num4 < s.readAt) ? (s.readAt - num4 - 1) : (s.end - num4); int num6 = InternalInflateConstants.InflateMask[bl]; int num7 = InternalInflateConstants.InflateMask[bd]; int num11; while (true) { if (num3 < 20) { num--; num2 |= (z.InputBuffer[nextIn++] & 0xFF) << num3; num3 += 8; continue; } int num8 = num2 & num6; int num9 = (tl_index + num8) * 3; int num10; if ((num10 = tl[num9]) == 0) { num2 >>= tl[num9 + 1]; num3 -= tl[num9 + 1]; s.window[num4++] = (byte)tl[num9 + 2]; num5--; } else { while (true) { num2 >>= tl[num9 + 1]; num3 -= tl[num9 + 1]; if ((num10 & 0x10) != 0) { num10 &= 0xF; num11 = tl[num9 + 2] + (num2 & InternalInflateConstants.InflateMask[num10]); num2 >>= num10; for (num3 -= num10; num3 < 15; num3 += 8) { num--; num2 |= (z.InputBuffer[nextIn++] & 0xFF) << num3; } num8 = (num2 & num7); num9 = (td_index + num8) * 3; num10 = td[num9]; while (true) { num2 >>= td[num9 + 1]; num3 -= td[num9 + 1]; if ((num10 & 0x10) != 0) { break; } if ((num10 & 0x40) == 0) { num8 += td[num9 + 2]; num8 += (num2 & InternalInflateConstants.InflateMask[num10]); num9 = (td_index + num8) * 3; num10 = td[num9]; continue; } z.Message = "invalid distance code"; num11 = z.AvailableBytesIn - num; num11 = ((num3 >> 3 < num11) ? (num3 >> 3) : num11); num += num11; nextIn -= num11; num3 -= num11 << 3; s.bitb = num2; s.bitk = num3; z.AvailableBytesIn = num; z.TotalBytesIn += nextIn - z.NextIn; z.NextIn = nextIn; s.writeAt = num4; return(-3); } for (num10 &= 0xF; num3 < num10; num3 += 8) { num--; num2 |= (z.InputBuffer[nextIn++] & 0xFF) << num3; } int num12 = td[num9 + 2] + (num2 & InternalInflateConstants.InflateMask[num10]); num2 >>= num10; num3 -= num10; num5 -= num11; int num13; if (num4 >= num12) { num13 = num4 - num12; if (num4 - num13 > 0 && 2 > num4 - num13) { s.window[num4++] = s.window[num13++]; s.window[num4++] = s.window[num13++]; num11 -= 2; } else { Array.Copy(s.window, num13, s.window, num4, 2); num4 += 2; num13 += 2; num11 -= 2; } } else { num13 = num4 - num12; do { num13 += s.end; }while (num13 < 0); num10 = s.end - num13; if (num11 > num10) { num11 -= num10; if (num4 - num13 > 0 && num10 > num4 - num13) { do { s.window[num4++] = s.window[num13++]; }while (--num10 != 0); } else { Array.Copy(s.window, num13, s.window, num4, num10); num4 += num10; num13 += num10; num10 = 0; } num13 = 0; } } if (num4 - num13 > 0 && num11 > num4 - num13) { do { s.window[num4++] = s.window[num13++]; }while (--num11 != 0); } else { Array.Copy(s.window, num13, s.window, num4, num11); num4 += num11; num13 += num11; num11 = 0; } break; } if ((num10 & 0x40) == 0) { num8 += tl[num9 + 2]; num8 += (num2 & InternalInflateConstants.InflateMask[num10]); num9 = (tl_index + num8) * 3; if ((num10 = tl[num9]) == 0) { num2 >>= tl[num9 + 1]; num3 -= tl[num9 + 1]; s.window[num4++] = (byte)tl[num9 + 2]; num5--; break; } continue; } if ((num10 & 0x20) != 0) { num11 = z.AvailableBytesIn - num; num11 = ((num3 >> 3 < num11) ? (num3 >> 3) : num11); num += num11; nextIn -= num11; num3 -= num11 << 3; s.bitb = num2; s.bitk = num3; z.AvailableBytesIn = num; z.TotalBytesIn += nextIn - z.NextIn; z.NextIn = nextIn; s.writeAt = num4; return(1); } z.Message = "invalid literal/length code"; num11 = z.AvailableBytesIn - num; num11 = ((num3 >> 3 < num11) ? (num3 >> 3) : num11); num += num11; nextIn -= num11; num3 -= num11 << 3; s.bitb = num2; s.bitk = num3; z.AvailableBytesIn = num; z.TotalBytesIn += nextIn - z.NextIn; z.NextIn = nextIn; s.writeAt = num4; return(-3); } } if (num5 < 258 || num < 10) { break; } } num11 = z.AvailableBytesIn - num; num11 = ((num3 >> 3 < num11) ? (num3 >> 3) : num11); num += num11; nextIn -= num11; num3 -= num11 << 3; s.bitb = num2; s.bitk = num3; z.AvailableBytesIn = num; z.TotalBytesIn += nextIn - z.NextIn; z.NextIn = nextIn; s.writeAt = num4; return(0); }
public override void Close() { z.Free(); z = null; _stream = null; }
// Called with number of bytes left to write in window at least 258 // (the maximum string length) and number of input bytes available // at least ten. The ten bytes are six bytes for the longest length/ // distance pair plus four bytes for overloading the bit buffer. internal int InflateFast(int bl, int bd, int[] tl, int tl_index, int[] td, int td_index, InflateBlocks s, ZlibCodec z) { int t; // temporary pointer int[] tp; // temporary pointer int tp_index; // temporary pointer int e; // extra bits or operation 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 int ml; // mask for literal/length tree int md; // mask for distance tree int c; // bytes to copy int d; // distance back to copy from int r; // copy source pointer int tp_index_t_3; // (tp_index+t)*3 // load input, output, bit values p = z.NextIn; n = z.AvailableBytesIn; b = s.bitb; k = s.bitk; q = s.writeAt; m = q < s.readAt ? s.readAt - q - 1 : s.end - q; // initialize masks ml = InternalInflateConstants.InflateMask[bl]; md = InternalInflateConstants.InflateMask[bd]; // do until not enough input or output space for fast loop do { // assume called with m >= 258 && n >= 10 // get literal/length code while (k < (20)) { // max bits for literal/length code n--; b |= (z.InputBuffer[p++] & 0xff) << k; k += 8; } t = b & ml; tp = tl; tp_index = tl_index; tp_index_t_3 = (tp_index + t) * 3; if ((e = tp[tp_index_t_3]) == 0) { b >>= (tp[tp_index_t_3 + 1]); k -= (tp[tp_index_t_3 + 1]); s.window[q++] = (byte)tp[tp_index_t_3 + 2]; m--; continue; } do { b >>= (tp[tp_index_t_3 + 1]); k -= (tp[tp_index_t_3 + 1]); if ((e & 16) != 0) { e &= 15; c = tp[tp_index_t_3 + 2] + ((int)b & InternalInflateConstants.InflateMask[e]); b >>= e; k -= e; // decode distance base of block to copy while (k < 15) { // max bits for distance code n--; b |= (z.InputBuffer[p++] & 0xff) << k; k += 8; } t = b & md; tp = td; tp_index = td_index; tp_index_t_3 = (tp_index + t) * 3; e = tp[tp_index_t_3]; do { b >>= (tp[tp_index_t_3 + 1]); k -= (tp[tp_index_t_3 + 1]); if ((e & 16) != 0) { // get extra bits to add to distance base e &= 15; while (k < e) { // get extra bits (up to 13) n--; b |= (z.InputBuffer[p++] & 0xff) << k; k += 8; } d = tp[tp_index_t_3 + 2] + (b & InternalInflateConstants.InflateMask[e]); b >>= e; k -= e; // do the copy m -= c; if (q >= d) { // offset before dest // just copy r = q - d; if (q - r > 0 && 2 > (q - r)) { s.window[q++] = s.window[r++]; // minimum count is three, s.window[q++] = s.window[r++]; // so unroll loop a little c -= 2; } else { Array.Copy(s.window, r, s.window, q, 2); q += 2; r += 2; c -= 2; } } else { // else offset after destination r = q - d; do { r += s.end; // force pointer in window } while (r < 0); // covers invalid distances e = s.end - r; if (c > e) { // if source crosses, c -= e; // wrapped copy if (q - r > 0 && e > (q - r)) { do { s.window[q++] = s.window[r++]; } while (--e != 0); } else { Array.Copy(s.window, r, s.window, q, e); q += e; r += e; e = 0; } r = 0; // copy rest from start of window } } // copy all or what's left if (q - r > 0 && c > (q - r)) { do { s.window[q++] = s.window[r++]; } while (--c != 0); } else { Array.Copy(s.window, r, s.window, q, c); q += c; r += c; c = 0; } break; } else if ((e & 64) == 0) { t += tp[tp_index_t_3 + 2]; t += (b & InternalInflateConstants.InflateMask[e]); tp_index_t_3 = (tp_index + t) * 3; e = tp[tp_index_t_3]; } else { z.Message = "invalid distance code"; c = z.AvailableBytesIn - n; c = (k >> 3) < c ? k >> 3 : c; n += c; p -= c; k -= (c << 3); s.bitb = b; s.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; s.writeAt = q; return ZlibConstants.Z_DATA_ERROR; } } while (true); break; } if ((e & 64) == 0) { t += tp[tp_index_t_3 + 2]; t += (b & InternalInflateConstants.InflateMask[e]); tp_index_t_3 = (tp_index + t) * 3; if ((e = tp[tp_index_t_3]) == 0) { b >>= (tp[tp_index_t_3 + 1]); k -= (tp[tp_index_t_3 + 1]); s.window[q++] = (byte)tp[tp_index_t_3 + 2]; m--; break; } } else if ((e & 32) != 0) { c = z.AvailableBytesIn - n; c = (k >> 3) < c ? k >> 3 : c; n += c; p -= c; k -= (c << 3); s.bitb = b; s.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; s.writeAt = q; return ZlibConstants.Z_STREAM_END; } else { z.Message = "invalid literal/length code"; c = z.AvailableBytesIn - n; c = (k >> 3) < c ? k >> 3 : c; n += c; p -= c; k -= (c << 3); s.bitb = b; s.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; s.writeAt = q; return ZlibConstants.Z_DATA_ERROR; } } while (true); } while (m >= 258 && n >= 10); // not enough input or output--restore pointers and return c = z.AvailableBytesIn - n; c = (k >> 3) < c ? k >> 3 : c; n += c; p -= c; k -= (c << 3); s.bitb = b; s.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; s.writeAt = q; return ZlibConstants.Z_OK; }
internal int Process(InflateBlocks blocks, int r) { int num; int num10; bool flag; int number = 0; int bitk = 0; int nextIn = 0; ZlibCodec z = blocks._codec; nextIn = z.NextIn; int availableBytesIn = z.AvailableBytesIn; number = blocks.bitb; bitk = blocks.bitk; int write = blocks.write; int num9 = (write < blocks.read) ? ((blocks.read - write) - 1) : (blocks.end - write); goto Label_0C3A; Label_0196: this.need = this.lbits; this.tree = this.ltree; this.tree_index = this.ltree_index; this.mode = 1; Label_01C3: num = this.need; while (bitk < num) { if (availableBytesIn != 0) { r = 0; } else { blocks.bitb = number; blocks.bitk = bitk; z.AvailableBytesIn = availableBytesIn; z.TotalBytesIn += nextIn - z.NextIn; z.NextIn = nextIn; blocks.write = write; return(blocks.Flush(r)); } availableBytesIn--; number |= (z.InputBuffer[nextIn++] & 0xff) << bitk; bitk += 8; } int index = (this.tree_index + (number & inflate_mask[num])) * 3; number = SharedUtils.URShift(number, this.tree[index + 1]); bitk -= this.tree[index + 1]; int num3 = this.tree[index]; if (num3 == 0) { this.lit = this.tree[index + 2]; this.mode = 6; goto Label_0C3A; } if ((num3 & 0x10) != 0) { this.get_Renamed = num3 & 15; this.len = this.tree[index + 2]; this.mode = 2; goto Label_0C3A; } if ((num3 & 0x40) == 0) { this.need = num3; this.tree_index = (index / 3) + this.tree[index + 2]; goto Label_0C3A; } if ((num3 & 0x20) != 0) { this.mode = 7; goto Label_0C3A; } this.mode = 9; z.Message = "invalid literal/length code"; r = -3; blocks.bitb = number; blocks.bitk = bitk; z.AvailableBytesIn = availableBytesIn; z.TotalBytesIn += nextIn - z.NextIn; z.NextIn = nextIn; blocks.write = write; return(blocks.Flush(r)); Label_04AE: num = this.need; while (bitk < num) { if (availableBytesIn != 0) { r = 0; } else { blocks.bitb = number; blocks.bitk = bitk; z.AvailableBytesIn = availableBytesIn; z.TotalBytesIn += nextIn - z.NextIn; z.NextIn = nextIn; blocks.write = write; return(blocks.Flush(r)); } availableBytesIn--; number |= (z.InputBuffer[nextIn++] & 0xff) << bitk; bitk += 8; } index = (this.tree_index + (number & inflate_mask[num])) * 3; number = number >> this.tree[index + 1]; bitk -= this.tree[index + 1]; num3 = this.tree[index]; if ((num3 & 0x10) != 0) { this.get_Renamed = num3 & 15; this.dist = this.tree[index + 2]; this.mode = 4; goto Label_0C3A; } if ((num3 & 0x40) == 0) { this.need = num3; this.tree_index = (index / 3) + this.tree[index + 2]; goto Label_0C3A; } this.mode = 9; z.Message = "invalid distance code"; r = -3; blocks.bitb = number; blocks.bitk = bitk; z.AvailableBytesIn = availableBytesIn; z.TotalBytesIn += nextIn - z.NextIn; z.NextIn = nextIn; blocks.write = write; return(blocks.Flush(r)); Label_0730: num10 = write - this.dist; while (num10 < 0) { num10 += blocks.end; } while (this.len != 0) { if (num9 == 0) { if ((write == blocks.end) && (blocks.read != 0)) { write = 0; num9 = (write < blocks.read) ? ((blocks.read - write) - 1) : (blocks.end - write); } if (num9 == 0) { blocks.write = write; r = blocks.Flush(r); write = blocks.write; num9 = (write < blocks.read) ? ((blocks.read - write) - 1) : (blocks.end - write); if ((write == blocks.end) && (blocks.read != 0)) { write = 0; num9 = (write < blocks.read) ? ((blocks.read - write) - 1) : (blocks.end - write); } if (num9 == 0) { blocks.bitb = number; blocks.bitk = bitk; z.AvailableBytesIn = availableBytesIn; z.TotalBytesIn += nextIn - z.NextIn; z.NextIn = nextIn; blocks.write = write; return(blocks.Flush(r)); } } } blocks.window[write++] = blocks.window[num10++]; num9--; if (num10 == blocks.end) { num10 = 0; } this.len--; } this.mode = 0; goto Label_0C3A; Label_0B44: r = 1; blocks.bitb = number; blocks.bitk = bitk; z.AvailableBytesIn = availableBytesIn; z.TotalBytesIn += nextIn - z.NextIn; z.NextIn = nextIn; blocks.write = write; return(blocks.Flush(r)); Label_0C3A: flag = true; switch (this.mode) { case 0: if ((num9 < 0x102) || (availableBytesIn < 10)) { goto Label_0196; } blocks.bitb = number; blocks.bitk = bitk; z.AvailableBytesIn = availableBytesIn; z.TotalBytesIn += nextIn - z.NextIn; z.NextIn = nextIn; blocks.write = write; r = this.InflateFast(this.lbits, this.dbits, this.ltree, this.ltree_index, this.dtree, this.dtree_index, blocks, z); nextIn = z.NextIn; availableBytesIn = z.AvailableBytesIn; number = blocks.bitb; bitk = blocks.bitk; write = blocks.write; num9 = (write < blocks.read) ? ((blocks.read - write) - 1) : (blocks.end - write); if (r == 0) { goto Label_0196; } this.mode = (r == 1) ? 7 : 9; goto Label_0C3A; case 1: goto Label_01C3; case 2: num = this.get_Renamed; while (bitk < num) { if (availableBytesIn != 0) { r = 0; } else { blocks.bitb = number; blocks.bitk = bitk; z.AvailableBytesIn = availableBytesIn; z.TotalBytesIn += nextIn - z.NextIn; z.NextIn = nextIn; blocks.write = write; return(blocks.Flush(r)); } availableBytesIn--; number |= (z.InputBuffer[nextIn++] & 0xff) << bitk; bitk += 8; } this.len += number & inflate_mask[num]; number = number >> num; bitk -= num; this.need = this.dbits; this.tree = this.dtree; this.tree_index = this.dtree_index; this.mode = 3; goto Label_04AE; case 3: goto Label_04AE; case 4: num = this.get_Renamed; while (bitk < num) { if (availableBytesIn != 0) { r = 0; } else { blocks.bitb = number; blocks.bitk = bitk; z.AvailableBytesIn = availableBytesIn; z.TotalBytesIn += nextIn - z.NextIn; z.NextIn = nextIn; blocks.write = write; return(blocks.Flush(r)); } availableBytesIn--; number |= (z.InputBuffer[nextIn++] & 0xff) << bitk; bitk += 8; } this.dist += number & inflate_mask[num]; number = number >> num; bitk -= num; this.mode = 5; goto Label_0730; case 5: goto Label_0730; case 6: if (num9 == 0) { if ((write == blocks.end) && (blocks.read != 0)) { write = 0; num9 = (write < blocks.read) ? ((blocks.read - write) - 1) : (blocks.end - write); } if (num9 == 0) { blocks.write = write; r = blocks.Flush(r); write = blocks.write; num9 = (write < blocks.read) ? ((blocks.read - write) - 1) : (blocks.end - write); if ((write == blocks.end) && (blocks.read != 0)) { write = 0; num9 = (write < blocks.read) ? ((blocks.read - write) - 1) : (blocks.end - write); } if (num9 == 0) { blocks.bitb = number; blocks.bitk = bitk; z.AvailableBytesIn = availableBytesIn; z.TotalBytesIn += nextIn - z.NextIn; z.NextIn = nextIn; blocks.write = write; return(blocks.Flush(r)); } } } r = 0; blocks.window[write++] = (byte)this.lit; num9--; this.mode = 0; goto Label_0C3A; case 7: if (bitk > 7) { bitk -= 8; availableBytesIn++; nextIn--; } blocks.write = write; r = blocks.Flush(r); write = blocks.write; num9 = (write < blocks.read) ? ((blocks.read - write) - 1) : (blocks.end - write); if (blocks.read != blocks.write) { blocks.bitb = number; blocks.bitk = bitk; z.AvailableBytesIn = availableBytesIn; z.TotalBytesIn += nextIn - z.NextIn; z.NextIn = nextIn; blocks.write = write; return(blocks.Flush(r)); } this.mode = 8; goto Label_0B44; case 8: goto Label_0B44; case 9: r = -3; blocks.bitb = number; blocks.bitk = bitk; z.AvailableBytesIn = availableBytesIn; z.TotalBytesIn += nextIn - z.NextIn; z.NextIn = nextIn; blocks.write = write; return(blocks.Flush(r)); } r = -2; blocks.bitb = number; blocks.bitk = bitk; z.AvailableBytesIn = availableBytesIn; z.TotalBytesIn += nextIn - z.NextIn; z.NextIn = nextIn; blocks.write = write; return(blocks.Flush(r)); }
internal int InflateFast(int bl, int bd, int[] tl, int tl_index, int[] td, int td_index, InflateBlocks s, ZlibCodec z) { int num = z.NextIn; int num2 = z.AvailableBytesIn; int num3 = s.bitb; int i = s.bitk; int num4 = s.writeAt; int num5 = (num4 >= s.readAt) ? (s.end - num4) : (s.readAt - num4 - 1); int num6 = InternalInflateConstants.InflateMask[bl]; int num7 = InternalInflateConstants.InflateMask[bd]; int num10; int num11; for (;;) { while (i < 20) { num2--; num3 |= (int)(z.InputBuffer[num++] & byte.MaxValue) << i; i += 8; } int num8 = num3 & num6; int num9 = (tl_index + num8) * 3; if ((num10 = tl[num9]) == 0) { num3 >>= tl[num9 + 1]; i -= tl[num9 + 1]; s.window[num4++] = (byte)tl[num9 + 2]; num5--; } else { for (;;) { num3 >>= tl[num9 + 1]; i -= tl[num9 + 1]; if ((num10 & 16) != 0) { break; } if ((num10 & 64) != 0) { goto IL_50A; } num8 += tl[num9 + 2]; num8 += (num3 & InternalInflateConstants.InflateMask[num10]); num9 = (tl_index + num8) * 3; if ((num10 = tl[num9]) == 0) { goto Block_20; } } num10 &= 15; num11 = tl[num9 + 2] + (num3 & InternalInflateConstants.InflateMask[num10]); num3 >>= num10; for (i -= num10; i < 15; i += 8) { num2--; num3 |= (int)(z.InputBuffer[num++] & byte.MaxValue) << i; } num8 = (num3 & num7); num9 = (td_index + num8) * 3; num10 = td[num9]; for (;;) { num3 >>= td[num9 + 1]; i -= td[num9 + 1]; if ((num10 & 16) != 0) { break; } if ((num10 & 64) != 0) { goto IL_400; } num8 += td[num9 + 2]; num8 += (num3 & InternalInflateConstants.InflateMask[num10]); num9 = (td_index + num8) * 3; num10 = td[num9]; } num10 &= 15; while (i < num10) { num2--; num3 |= (int)(z.InputBuffer[num++] & byte.MaxValue) << i; i += 8; } int num12 = td[num9 + 2] + (num3 & InternalInflateConstants.InflateMask[num10]); num3 >>= num10; i -= num10; num5 -= num11; int num13; if (num4 >= num12) { num13 = num4 - num12; if (num4 - num13 > 0 && 2 > num4 - num13) { s.window[num4++] = s.window[num13++]; s.window[num4++] = s.window[num13++]; num11 -= 2; } else { Array.Copy(s.window, num13, s.window, num4, 2); num4 += 2; num13 += 2; num11 -= 2; } } else { num13 = num4 - num12; do { num13 += s.end; }while (num13 < 0); num10 = s.end - num13; if (num11 > num10) { num11 -= num10; if (num4 - num13 > 0 && num10 > num4 - num13) { do { s.window[num4++] = s.window[num13++]; }while (--num10 != 0); } else { Array.Copy(s.window, num13, s.window, num4, num10); num4 += num10; num13 += num10; } num13 = 0; } } if (num4 - num13 > 0 && num11 > num4 - num13) { do { s.window[num4++] = s.window[num13++]; }while (--num11 != 0); } else { Array.Copy(s.window, num13, s.window, num4, num11); num4 += num11; num13 += num11; } goto IL_62B; Block_20: num3 >>= tl[num9 + 1]; i -= tl[num9 + 1]; s.window[num4++] = (byte)tl[num9 + 2]; num5--; } IL_62B: if (num5 < 258 || num2 < 10) { goto IL_640; } } IL_400: z.Message = "invalid distance code"; num11 = z.AvailableBytesIn - num2; num11 = ((i >> 3 >= num11) ? num11 : (i >> 3)); num2 += num11; num -= num11; i -= num11 << 3; s.bitb = num3; s.bitk = i; z.AvailableBytesIn = num2; z.TotalBytesIn += (long)(num - z.NextIn); z.NextIn = num; s.writeAt = num4; return(-3); IL_50A: if ((num10 & 32) != 0) { num11 = z.AvailableBytesIn - num2; num11 = ((i >> 3 >= num11) ? num11 : (i >> 3)); num2 += num11; num -= num11; i -= num11 << 3; s.bitb = num3; s.bitk = i; z.AvailableBytesIn = num2; z.TotalBytesIn += (long)(num - z.NextIn); z.NextIn = num; s.writeAt = num4; return(1); } z.Message = "invalid literal/length code"; num11 = z.AvailableBytesIn - num2; num11 = ((i >> 3 >= num11) ? num11 : (i >> 3)); num2 += num11; num -= num11; i -= num11 << 3; s.bitb = num3; s.bitk = i; z.AvailableBytesIn = num2; z.TotalBytesIn += (long)(num - z.NextIn); z.NextIn = num; s.writeAt = num4; return(-3); IL_640: num11 = z.AvailableBytesIn - num2; num11 = ((i >> 3 >= num11) ? num11 : (i >> 3)); num2 += num11; num -= num11; i -= num11 << 3; s.bitb = num3; s.bitk = i; z.AvailableBytesIn = num2; z.TotalBytesIn += (long)(num - z.NextIn); z.NextIn = num; s.writeAt = num4; return(0); }
internal int Process(InflateBlocks blocks, int r) { int b2 = 0; int k3 = 0; int p2 = 0; ZlibCodec z = blocks._codec; p2 = z.NextIn; int n2 = z.AvailableBytesIn; b2 = blocks.bitb; k3 = blocks.bitk; int q = blocks.writeAt; int n = (q < blocks.readAt) ? (blocks.readAt - q - 1) : (blocks.end - q); while (true) { switch (mode) { case 0: if (n >= 258 && n2 >= 10) { blocks.bitb = b2; blocks.bitk = k3; z.AvailableBytesIn = n2; z.TotalBytesIn += p2 - z.NextIn; z.NextIn = p2; blocks.writeAt = q; r = InflateFast(lbits, dbits, ltree, ltree_index, dtree, dtree_index, blocks, z); p2 = z.NextIn; n2 = z.AvailableBytesIn; b2 = blocks.bitb; k3 = blocks.bitk; q = blocks.writeAt; n = ((q < blocks.readAt) ? (blocks.readAt - q - 1) : (blocks.end - q)); if (r != 0) { mode = ((r == 1) ? 7 : 9); break; } } need = lbits; tree = ltree; tree_index = ltree_index; mode = 1; goto case 1; case 1: { int k; for (k = need; k3 < k; k3 += 8) { if (n2 != 0) { r = 0; n2--; b2 |= (z.InputBuffer[p2++] & 0xFF) << k3; continue; } blocks.bitb = b2; blocks.bitk = k3; z.AvailableBytesIn = n2; z.TotalBytesIn += p2 - z.NextIn; z.NextIn = p2; blocks.writeAt = q; return(blocks.Flush(r)); } int tindex2 = (tree_index + (b2 & InternalInflateConstants.InflateMask[k])) * 3; b2 >>= tree[tindex2 + 1]; k3 -= tree[tindex2 + 1]; int e2 = tree[tindex2]; if (e2 == 0) { lit = tree[tindex2 + 2]; mode = 6; break; } if ((e2 & 0x10) != 0) { bitsToGet = (e2 & 0xF); len = tree[tindex2 + 2]; mode = 2; break; } if ((e2 & 0x40) == 0) { need = e2; tree_index = tindex2 / 3 + tree[tindex2 + 2]; break; } if ((e2 & 0x20) != 0) { mode = 7; break; } mode = 9; z.Message = "invalid literal/length code"; r = -3; blocks.bitb = b2; blocks.bitk = k3; z.AvailableBytesIn = n2; z.TotalBytesIn += p2 - z.NextIn; z.NextIn = p2; blocks.writeAt = q; return(blocks.Flush(r)); } case 2: { int k; for (k = bitsToGet; k3 < k; k3 += 8) { if (n2 != 0) { r = 0; n2--; b2 |= (z.InputBuffer[p2++] & 0xFF) << k3; continue; } blocks.bitb = b2; blocks.bitk = k3; z.AvailableBytesIn = n2; z.TotalBytesIn += p2 - z.NextIn; z.NextIn = p2; blocks.writeAt = q; return(blocks.Flush(r)); } len += (b2 & InternalInflateConstants.InflateMask[k]); b2 >>= k; k3 -= k; need = dbits; tree = dtree; tree_index = dtree_index; mode = 3; goto case 3; } case 3: { int k; for (k = need; k3 < k; k3 += 8) { if (n2 != 0) { r = 0; n2--; b2 |= (z.InputBuffer[p2++] & 0xFF) << k3; continue; } blocks.bitb = b2; blocks.bitk = k3; z.AvailableBytesIn = n2; z.TotalBytesIn += p2 - z.NextIn; z.NextIn = p2; blocks.writeAt = q; return(blocks.Flush(r)); } int tindex2 = (tree_index + (b2 & InternalInflateConstants.InflateMask[k])) * 3; b2 >>= tree[tindex2 + 1]; k3 -= tree[tindex2 + 1]; int e2 = tree[tindex2]; if ((e2 & 0x10) != 0) { bitsToGet = (e2 & 0xF); dist = tree[tindex2 + 2]; mode = 4; break; } if ((e2 & 0x40) == 0) { need = e2; tree_index = tindex2 / 3 + tree[tindex2 + 2]; break; } mode = 9; z.Message = "invalid distance code"; r = -3; blocks.bitb = b2; blocks.bitk = k3; z.AvailableBytesIn = n2; z.TotalBytesIn += p2 - z.NextIn; z.NextIn = p2; blocks.writeAt = q; return(blocks.Flush(r)); } case 4: { int k; for (k = bitsToGet; k3 < k; k3 += 8) { if (n2 != 0) { r = 0; n2--; b2 |= (z.InputBuffer[p2++] & 0xFF) << k3; continue; } blocks.bitb = b2; blocks.bitk = k3; z.AvailableBytesIn = n2; z.TotalBytesIn += p2 - z.NextIn; z.NextIn = p2; blocks.writeAt = q; return(blocks.Flush(r)); } dist += (b2 & InternalInflateConstants.InflateMask[k]); b2 >>= k; k3 -= k; mode = 5; goto case 5; } case 5: { int f; for (f = q - dist; f < 0; f += blocks.end) { } while (len != 0) { if (n == 0) { if (q == blocks.end && blocks.readAt != 0) { q = 0; n = ((q < blocks.readAt) ? (blocks.readAt - q - 1) : (blocks.end - q)); } if (n == 0) { blocks.writeAt = q; r = blocks.Flush(r); q = blocks.writeAt; n = ((q < blocks.readAt) ? (blocks.readAt - q - 1) : (blocks.end - q)); if (q == blocks.end && blocks.readAt != 0) { q = 0; n = ((q < blocks.readAt) ? (blocks.readAt - q - 1) : (blocks.end - q)); } if (n == 0) { blocks.bitb = b2; blocks.bitk = k3; z.AvailableBytesIn = n2; z.TotalBytesIn += p2 - z.NextIn; z.NextIn = p2; blocks.writeAt = q; return(blocks.Flush(r)); } } } blocks.window[q++] = blocks.window[f++]; n--; if (f == blocks.end) { f = 0; } len--; } mode = 0; break; } case 6: if (n == 0) { if (q == blocks.end && blocks.readAt != 0) { q = 0; n = ((q < blocks.readAt) ? (blocks.readAt - q - 1) : (blocks.end - q)); } if (n == 0) { blocks.writeAt = q; r = blocks.Flush(r); q = blocks.writeAt; n = ((q < blocks.readAt) ? (blocks.readAt - q - 1) : (blocks.end - q)); if (q == blocks.end && blocks.readAt != 0) { q = 0; n = ((q < blocks.readAt) ? (blocks.readAt - q - 1) : (blocks.end - q)); } if (n == 0) { blocks.bitb = b2; blocks.bitk = k3; z.AvailableBytesIn = n2; z.TotalBytesIn += p2 - z.NextIn; z.NextIn = p2; blocks.writeAt = q; return(blocks.Flush(r)); } } } r = 0; blocks.window[q++] = (byte)lit; n--; mode = 0; break; case 7: if (k3 > 7) { k3 -= 8; n2++; p2--; } blocks.writeAt = q; r = blocks.Flush(r); q = blocks.writeAt; n = ((q < blocks.readAt) ? (blocks.readAt - q - 1) : (blocks.end - q)); if (blocks.readAt != blocks.writeAt) { blocks.bitb = b2; blocks.bitk = k3; z.AvailableBytesIn = n2; z.TotalBytesIn += p2 - z.NextIn; z.NextIn = p2; blocks.writeAt = q; return(blocks.Flush(r)); } mode = 8; goto case 8; case 8: r = 1; blocks.bitb = b2; blocks.bitk = k3; z.AvailableBytesIn = n2; z.TotalBytesIn += p2 - z.NextIn; z.NextIn = p2; blocks.writeAt = q; return(blocks.Flush(r)); case 9: r = -3; blocks.bitb = b2; blocks.bitk = k3; z.AvailableBytesIn = n2; z.TotalBytesIn += p2 - z.NextIn; z.NextIn = p2; blocks.writeAt = q; return(blocks.Flush(r)); default: r = -2; blocks.bitb = b2; blocks.bitk = k3; z.AvailableBytesIn = n2; z.TotalBytesIn += p2 - z.NextIn; z.NextIn = p2; blocks.writeAt = q; return(blocks.Flush(r)); } } }
internal int InflateFast(int bl, int bd, int[] tl, int tl_index, int[] td, int td_index, InflateBlocks s, ZlibCodec z) { int nextIn = z.NextIn; int num = z.AvailableBytesIn; int num2 = s.bitb; int num3 = s.bitk; int num4 = s.writeAt; int num5 = ((num4 < s.readAt) ? (s.readAt - num4 - 1) : (s.end - num4)); int num6 = InternalInflateConstants.InflateMask[bl]; int num7 = InternalInflateConstants.InflateMask[bd]; int num12; while (true) { if (num3 < 20) { num--; num2 |= (z.InputBuffer[nextIn++] & 0xFF) << num3; num3 += 8; continue; } int num8 = num2 & num6; int[] array = tl; int num9 = tl_index; int num10 = (num9 + num8) * 3; int num11; if ((num11 = array[num10]) == 0) { num2 >>= array[num10 + 1]; num3 -= array[num10 + 1]; s.window[num4++] = (byte)array[num10 + 2]; num5--; } else { while (true) { num2 >>= array[num10 + 1]; num3 -= array[num10 + 1]; if (((uint)num11 & 0x10u) != 0) { num11 &= 0xF; num12 = array[num10 + 2] + (num2 & InternalInflateConstants.InflateMask[num11]); num2 >>= num11; for (num3 -= num11; num3 < 15; num3 += 8) { num--; num2 |= (z.InputBuffer[nextIn++] & 0xFF) << num3; } num8 = num2 & num7; array = td; num9 = td_index; num10 = (num9 + num8) * 3; num11 = array[num10]; while (true) { num2 >>= array[num10 + 1]; num3 -= array[num10 + 1]; if (((uint)num11 & 0x10u) != 0) { break; } if ((num11 & 0x40) == 0) { num8 += array[num10 + 2]; num8 += num2 & InternalInflateConstants.InflateMask[num11]; num10 = (num9 + num8) * 3; num11 = array[num10]; bool flag = true; continue; } z.Message = "invalid distance code"; num12 = z.AvailableBytesIn - num; num12 = ((num3 >> 3 < num12) ? (num3 >> 3) : num12); num += num12; nextIn -= num12; num3 -= num12 << 3; s.bitb = num2; s.bitk = num3; z.AvailableBytesIn = num; z.TotalBytesIn += nextIn - z.NextIn; z.NextIn = nextIn; s.writeAt = num4; return(-3); } for (num11 &= 0xF; num3 < num11; num3 += 8) { num--; num2 |= (z.InputBuffer[nextIn++] & 0xFF) << num3; } int num13 = array[num10 + 2] + (num2 & InternalInflateConstants.InflateMask[num11]); num2 >>= num11; num3 -= num11; num5 -= num12; int num14; if (num4 >= num13) { num14 = num4 - num13; if (num4 - num14 > 0 && 2 > num4 - num14) { s.window[num4++] = s.window[num14++]; s.window[num4++] = s.window[num14++]; num12 -= 2; } else { Array.Copy(s.window, num14, s.window, num4, 2); num4 += 2; num14 += 2; num12 -= 2; } } else { num14 = num4 - num13; do { num14 += s.end; }while (num14 < 0); num11 = s.end - num14; if (num12 > num11) { num12 -= num11; if (num4 - num14 > 0 && num11 > num4 - num14) { do { s.window[num4++] = s.window[num14++]; }while (--num11 != 0); } else { Array.Copy(s.window, num14, s.window, num4, num11); num4 += num11; num14 += num11; num11 = 0; } num14 = 0; } } if (num4 - num14 > 0 && num12 > num4 - num14) { do { s.window[num4++] = s.window[num14++]; }while (--num12 != 0); break; } Array.Copy(s.window, num14, s.window, num4, num12); num4 += num12; num14 += num12; num12 = 0; break; } if ((num11 & 0x40) == 0) { num8 += array[num10 + 2]; num8 += num2 & InternalInflateConstants.InflateMask[num11]; num10 = (num9 + num8) * 3; if ((num11 = array[num10]) == 0) { num2 >>= array[num10 + 1]; num3 -= array[num10 + 1]; s.window[num4++] = (byte)array[num10 + 2]; num5--; break; } bool flag = true; continue; } if (((uint)num11 & 0x20u) != 0) { num12 = z.AvailableBytesIn - num; num12 = ((num3 >> 3 < num12) ? (num3 >> 3) : num12); num += num12; nextIn -= num12; num3 -= num12 << 3; s.bitb = num2; s.bitk = num3; z.AvailableBytesIn = num; z.TotalBytesIn += nextIn - z.NextIn; z.NextIn = nextIn; s.writeAt = num4; return(1); } z.Message = "invalid literal/length code"; num12 = z.AvailableBytesIn - num; num12 = ((num3 >> 3 < num12) ? (num3 >> 3) : num12); num += num12; nextIn -= num12; num3 -= num12 << 3; s.bitb = num2; s.bitk = num3; z.AvailableBytesIn = num; z.TotalBytesIn += nextIn - z.NextIn; z.NextIn = nextIn; s.writeAt = num4; return(-3); } } if (num5 < 258 || num < 10) { break; } } num12 = z.AvailableBytesIn - num; num12 = ((num3 >> 3 < num12) ? (num3 >> 3) : num12); num += num12; nextIn -= num12; num3 -= num12 << 3; s.bitb = num2; s.bitk = num3; z.AvailableBytesIn = num; z.TotalBytesIn += nextIn - z.NextIn; z.NextIn = nextIn; s.writeAt = num4; return(0); }
internal int Process(InflateBlocks blocks, int r) { int num = 0; int num2 = 0; int num3 = 0; ZlibCodec codec = blocks._codec; num3 = codec.NextIn; int num4 = codec.AvailableBytesIn; num = blocks.bitb; num2 = blocks.bitk; int num5 = blocks.writeAt; int num6 = (num5 >= blocks.readAt) ? (blocks.end - num5) : (blocks.readAt - num5 - 1); while (true) { switch (this.mode) { case 0: break; case 1: goto IL_01c4; case 2: goto IL_0387; case 3: goto IL_0471; case 4: goto IL_05fd; case 5: goto IL_06c3; case 6: goto IL_0868; case 7: if (num2 > 7) { num2 -= 8; num4++; num3--; } blocks.writeAt = num5; r = blocks.Flush(r); num5 = blocks.writeAt; num6 = ((num5 >= blocks.readAt) ? (blocks.end - num5) : (blocks.readAt - num5 - 1)); if (blocks.readAt != blocks.writeAt) { blocks.bitb = num; blocks.bitk = num2; codec.AvailableBytesIn = num4; codec.TotalBytesIn += num3 - codec.NextIn; codec.NextIn = num3; blocks.writeAt = num5; return(blocks.Flush(r)); } this.mode = 8; goto case 8; case 8: r = 1; blocks.bitb = num; blocks.bitk = num2; codec.AvailableBytesIn = num4; codec.TotalBytesIn += num3 - codec.NextIn; codec.NextIn = num3; blocks.writeAt = num5; return(blocks.Flush(r)); case 9: r = -3; blocks.bitb = num; blocks.bitk = num2; codec.AvailableBytesIn = num4; codec.TotalBytesIn += num3 - codec.NextIn; codec.NextIn = num3; blocks.writeAt = num5; return(blocks.Flush(r)); default: r = -2; blocks.bitb = num; blocks.bitk = num2; codec.AvailableBytesIn = num4; codec.TotalBytesIn += num3 - codec.NextIn; codec.NextIn = num3; blocks.writeAt = num5; return(blocks.Flush(r)); } if (num6 >= 258 && num4 >= 10) { blocks.bitb = num; blocks.bitk = num2; codec.AvailableBytesIn = num4; codec.TotalBytesIn += num3 - codec.NextIn; codec.NextIn = num3; blocks.writeAt = num5; r = this.InflateFast(this.lbits, this.dbits, this.ltree, this.ltree_index, this.dtree, this.dtree_index, blocks, codec); num3 = codec.NextIn; num4 = codec.AvailableBytesIn; num = blocks.bitb; num2 = blocks.bitk; num5 = blocks.writeAt; num6 = ((num5 >= blocks.readAt) ? (blocks.end - num5) : (blocks.readAt - num5 - 1)); if (r != 0) { this.mode = ((r != 1) ? 9 : 7); continue; } } this.need = this.lbits; this.tree = this.ltree; this.tree_index = this.ltree_index; this.mode = 1; goto IL_01c4; IL_0868: if (num6 == 0) { if (num5 == blocks.end && blocks.readAt != 0) { num5 = 0; num6 = ((num5 >= blocks.readAt) ? (blocks.end - num5) : (blocks.readAt - num5 - 1)); } if (num6 == 0) { blocks.writeAt = num5; r = blocks.Flush(r); num5 = blocks.writeAt; num6 = ((num5 >= blocks.readAt) ? (blocks.end - num5) : (blocks.readAt - num5 - 1)); if (num5 == blocks.end && blocks.readAt != 0) { num5 = 0; num6 = ((num5 >= blocks.readAt) ? (blocks.end - num5) : (blocks.readAt - num5 - 1)); } if (num6 == 0) { break; } } } r = 0; blocks.window[num5++] = (byte)this.lit; num6--; this.mode = 0; continue; IL_0471: int num8 = this.need; while (num2 < num8) { if (num4 != 0) { r = 0; num4--; num |= (codec.InputBuffer[num3++] & 0xFF) << num2; num2 += 8; continue; } blocks.bitb = num; blocks.bitk = num2; codec.AvailableBytesIn = num4; codec.TotalBytesIn += num3 - codec.NextIn; codec.NextIn = num3; blocks.writeAt = num5; return(blocks.Flush(r)); } int num10 = (this.tree_index + (num & InternalInflateConstants.InflateMask[num8])) * 3; num >>= this.tree[num10 + 1]; num2 -= this.tree[num10 + 1]; int num11 = this.tree[num10]; if ((num11 & 0x10) != 0) { this.bitsToGet = (num11 & 0xF); this.dist = this.tree[num10 + 2]; this.mode = 4; continue; } if ((num11 & 0x40) == 0) { this.need = num11; this.tree_index = num10 / 3 + this.tree[num10 + 2]; continue; } this.mode = 9; codec.Message = "invalid distance code"; r = -3; blocks.bitb = num; blocks.bitk = num2; codec.AvailableBytesIn = num4; codec.TotalBytesIn += num3 - codec.NextIn; codec.NextIn = num3; blocks.writeAt = num5; return(blocks.Flush(r)); IL_05fd: num8 = this.bitsToGet; while (num2 < num8) { if (num4 != 0) { r = 0; num4--; num |= (codec.InputBuffer[num3++] & 0xFF) << num2; num2 += 8; continue; } blocks.bitb = num; blocks.bitk = num2; codec.AvailableBytesIn = num4; codec.TotalBytesIn += num3 - codec.NextIn; codec.NextIn = num3; blocks.writeAt = num5; return(blocks.Flush(r)); } this.dist += (num & InternalInflateConstants.InflateMask[num8]); num >>= num8; num2 -= num8; this.mode = 5; goto IL_06c3; IL_06c3: int i; for (i = num5 - this.dist; i < 0; i += blocks.end) { } while (this.len != 0) { if (num6 == 0) { if (num5 == blocks.end && blocks.readAt != 0) { num5 = 0; num6 = ((num5 >= blocks.readAt) ? (blocks.end - num5) : (blocks.readAt - num5 - 1)); } if (num6 == 0) { blocks.writeAt = num5; r = blocks.Flush(r); num5 = blocks.writeAt; num6 = ((num5 >= blocks.readAt) ? (blocks.end - num5) : (blocks.readAt - num5 - 1)); if (num5 == blocks.end && blocks.readAt != 0) { num5 = 0; num6 = ((num5 >= blocks.readAt) ? (blocks.end - num5) : (blocks.readAt - num5 - 1)); } if (num6 == 0) { blocks.bitb = num; blocks.bitk = num2; codec.AvailableBytesIn = num4; codec.TotalBytesIn += num3 - codec.NextIn; codec.NextIn = num3; blocks.writeAt = num5; return(blocks.Flush(r)); } } } blocks.window[num5++] = blocks.window[i++]; num6--; if (i == blocks.end) { i = 0; } this.len--; } this.mode = 0; continue; IL_0387: num8 = this.bitsToGet; while (num2 < num8) { if (num4 != 0) { r = 0; num4--; num |= (codec.InputBuffer[num3++] & 0xFF) << num2; num2 += 8; continue; } blocks.bitb = num; blocks.bitk = num2; codec.AvailableBytesIn = num4; codec.TotalBytesIn += num3 - codec.NextIn; codec.NextIn = num3; blocks.writeAt = num5; return(blocks.Flush(r)); } this.len += (num & InternalInflateConstants.InflateMask[num8]); num >>= num8; num2 -= num8; this.need = this.dbits; this.tree = this.dtree; this.tree_index = this.dtree_index; this.mode = 3; goto IL_0471; IL_01c4: num8 = this.need; while (num2 < num8) { if (num4 != 0) { r = 0; num4--; num |= (codec.InputBuffer[num3++] & 0xFF) << num2; num2 += 8; continue; } blocks.bitb = num; blocks.bitk = num2; codec.AvailableBytesIn = num4; codec.TotalBytesIn += num3 - codec.NextIn; codec.NextIn = num3; blocks.writeAt = num5; return(blocks.Flush(r)); } num10 = (this.tree_index + (num & InternalInflateConstants.InflateMask[num8])) * 3; num >>= this.tree[num10 + 1]; num2 -= this.tree[num10 + 1]; num11 = this.tree[num10]; if (num11 == 0) { this.lit = this.tree[num10 + 2]; this.mode = 6; continue; } if ((num11 & 0x10) != 0) { this.bitsToGet = (num11 & 0xF); this.len = this.tree[num10 + 2]; this.mode = 2; continue; } if ((num11 & 0x40) == 0) { this.need = num11; this.tree_index = num10 / 3 + this.tree[num10 + 2]; continue; } if ((num11 & 0x20) != 0) { this.mode = 7; continue; } this.mode = 9; codec.Message = "invalid literal/length code"; r = -3; blocks.bitb = num; blocks.bitk = num2; codec.AvailableBytesIn = num4; codec.TotalBytesIn += num3 - codec.NextIn; codec.NextIn = num3; blocks.writeAt = num5; return(blocks.Flush(r)); } blocks.bitb = num; blocks.bitk = num2; codec.AvailableBytesIn = num4; codec.TotalBytesIn += num3 - codec.NextIn; codec.NextIn = num3; blocks.writeAt = num5; return(blocks.Flush(r)); }
internal int InflateFast(int bl, int bd, int[] tl, int tl_index, int[] td, int td_index, InflateBlocks s, ZlibCodec z) { int num = z.NextIn; int num2 = z.AvailableBytesIn; int num3 = s.bitb; int num4 = s.bitk; int num5 = s.writeAt; int num6 = (num5 >= s.readAt) ? (s.end - num5) : (s.readAt - num5 - 1); int num7 = InternalInflateConstants.InflateMask[bl]; int num8 = InternalInflateConstants.InflateMask[bd]; int num14; while (true) { if (num4 < 20) { num2--; num3 |= (z.InputBuffer[num++] & 0xFF) << num4; num4 += 8; continue; } int num10 = num3 & num7; int num11 = (tl_index + num10) * 3; int num12; if ((num12 = tl[num11]) == 0) { num3 >>= tl[num11 + 1]; num4 -= tl[num11 + 1]; s.window[num5++] = (byte)tl[num11 + 2]; num6--; } else { while (true) { num3 >>= tl[num11 + 1]; num4 -= tl[num11 + 1]; if ((num12 & 0x10) == 0) { if ((num12 & 0x40) == 0) { num10 += tl[num11 + 2]; num10 += (num3 & InternalInflateConstants.InflateMask[num12]); num11 = (tl_index + num10) * 3; if ((num12 = tl[num11]) != 0) { continue; } goto IL_04cb; } goto IL_050a; } break; } num12 &= 0xF; num14 = tl[num11 + 2] + (num3 & InternalInflateConstants.InflateMask[num12]); num3 >>= num12; for (num4 -= num12; num4 < 15; num4 += 8) { num2--; num3 |= (z.InputBuffer[num++] & 0xFF) << num4; } num10 = (num3 & num8); num11 = (td_index + num10) * 3; num12 = td[num11]; while (true) { num3 >>= td[num11 + 1]; num4 -= td[num11 + 1]; if ((num12 & 0x10) == 0) { if ((num12 & 0x40) == 0) { num10 += td[num11 + 2]; num10 += (num3 & InternalInflateConstants.InflateMask[num12]); num11 = (td_index + num10) * 3; num12 = td[num11]; continue; } z.Message = "invalid distance code"; num14 = z.AvailableBytesIn - num2; num14 = ((num4 >> 3 >= num14) ? num14 : (num4 >> 3)); num2 += num14; num -= num14; num4 -= num14 << 3; s.bitb = num3; s.bitk = num4; z.AvailableBytesIn = num2; z.TotalBytesIn += num - z.NextIn; z.NextIn = num; s.writeAt = num5; return(-3); } break; } num12 &= 0xF; for (; num4 < num12; num4 += 8) { num2--; num3 |= (z.InputBuffer[num++] & 0xFF) << num4; } int num17 = td[num11 + 2] + (num3 & InternalInflateConstants.InflateMask[num12]); num3 >>= num12; num4 -= num12; num6 -= num14; int num18; if (num5 >= num17) { num18 = num5 - num17; if (num5 - num18 > 0 && 2 > num5 - num18) { s.window[num5++] = s.window[num18++]; s.window[num5++] = s.window[num18++]; num14 -= 2; } else { Array.Copy(s.window, num18, s.window, num5, 2); num5 += 2; num18 += 2; num14 -= 2; } } else { num18 = num5 - num17; while (true) { num18 += s.end; if (num18 >= 0) { break; } } num12 = s.end - num18; if (num14 > num12) { num14 -= num12; if (num5 - num18 > 0 && num12 > num5 - num18) { while (true) { s.window[num5++] = s.window[num18++]; if (--num12 == 0) { break; } } } else { Array.Copy(s.window, num18, s.window, num5, num12); num5 += num12; num18 += num12; num12 = 0; } num18 = 0; } } if (num5 - num18 > 0 && num14 > num5 - num18) { while (true) { s.window[num5++] = s.window[num18++]; if (--num14 == 0) { break; } } } else { Array.Copy(s.window, num18, s.window, num5, num14); num5 += num14; num18 += num14; num14 = 0; } } goto IL_062b; IL_062b: if (num6 < 258) { break; } if (num2 < 10) { break; } continue; IL_04cb: num3 >>= tl[num11 + 1]; num4 -= tl[num11 + 1]; s.window[num5++] = (byte)tl[num11 + 2]; num6--; goto IL_062b; IL_050a: if ((num12 & 0x20) != 0) { num14 = z.AvailableBytesIn - num2; num14 = ((num4 >> 3 >= num14) ? num14 : (num4 >> 3)); num2 += num14; num -= num14; num4 -= num14 << 3; s.bitb = num3; s.bitk = num4; z.AvailableBytesIn = num2; z.TotalBytesIn += num - z.NextIn; z.NextIn = num; s.writeAt = num5; return(1); } z.Message = "invalid literal/length code"; num14 = z.AvailableBytesIn - num2; num14 = ((num4 >> 3 >= num14) ? num14 : (num4 >> 3)); num2 += num14; num -= num14; num4 -= num14 << 3; s.bitb = num3; s.bitk = num4; z.AvailableBytesIn = num2; z.TotalBytesIn += num - z.NextIn; z.NextIn = num; s.writeAt = num5; return(-3); } num14 = z.AvailableBytesIn - num2; num14 = ((num4 >> 3 >= num14) ? num14 : (num4 >> 3)); num2 += num14; num -= num14; num4 -= num14 << 3; s.bitb = num3; s.bitk = num4; z.AvailableBytesIn = num2; z.TotalBytesIn += num - z.NextIn; z.NextIn = num; s.writeAt = num5; return(0); }
// Token: 0x0600079B RID: 1947 RVA: 0x00042D40 File Offset: 0x00040F40 internal int Process(InflateBlocks blocks, int r) { ZlibCodec codec = blocks._codec; int num = codec.NextIn; int num2 = codec.AvailableBytesIn; int num3 = blocks.bitb; int i = blocks.bitk; int num4 = blocks.writeAt; int num5 = (num4 < blocks.readAt) ? (blocks.readAt - num4 - 1) : (blocks.end - num4); for (;;) { int num6; switch (this.mode) { case 0: if (num5 >= 258 && num2 >= 10) { blocks.bitb = num3; blocks.bitk = i; codec.AvailableBytesIn = num2; codec.TotalBytesIn += (long)(num - codec.NextIn); codec.NextIn = num; blocks.writeAt = num4; r = this.InflateFast((int)this.lbits, (int)this.dbits, this.ltree, this.ltree_index, this.dtree, this.dtree_index, blocks, codec); num = codec.NextIn; num2 = codec.AvailableBytesIn; num3 = blocks.bitb; i = blocks.bitk; num4 = blocks.writeAt; num5 = ((num4 < blocks.readAt) ? (blocks.readAt - num4 - 1) : (blocks.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_441; case 1: goto IL_441; case 2: num6 = this.bitsToGet; while (i < num6) { if (num2 == 0) { goto IL_773; } r = 0; num2--; num3 |= (int)(codec.InputBuffer[num++] & byte.MaxValue) << i; i += 8; } this.len += (num3 & InternalInflateConstants.InflateMask[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_2D8; case 3: goto IL_2D8; case 4: num6 = this.bitsToGet; while (i < num6) { if (num2 == 0) { goto IL_854; } r = 0; num2--; num3 |= (int)(codec.InputBuffer[num++] & byte.MaxValue) << i; i += 8; } this.dist += (num3 & InternalInflateConstants.InflateMask[num6]); num3 >>= num6; i -= num6; this.mode = 5; goto IL_13C; case 5: goto IL_13C; case 6: if (num5 == 0) { if (num4 == blocks.end && blocks.readAt != 0) { num4 = 0; num5 = ((0 < blocks.readAt) ? (blocks.readAt - num4 - 1) : (blocks.end - num4)); } if (num5 == 0) { blocks.writeAt = num4; r = blocks.Flush(r); num4 = blocks.writeAt; num5 = ((num4 < blocks.readAt) ? (blocks.readAt - num4 - 1) : (blocks.end - num4)); if (num4 == blocks.end && blocks.readAt != 0) { num4 = 0; num5 = ((0 < blocks.readAt) ? (blocks.readAt - num4 - 1) : (blocks.end - num4)); } if (num5 == 0) { goto IL_8DA; } } } r = 0; blocks.window[num4++] = (byte)this.lit; num5--; this.mode = 0; continue; case 7: goto IL_91D; case 8: goto IL_9C2; case 9: goto IL_A08; } break; IL_13C: int j; for (j = num4 - this.dist; j < 0; j += blocks.end) { } while (this.len != 0) { if (num5 == 0) { if (num4 == blocks.end && blocks.readAt != 0) { num4 = 0; num5 = ((0 < blocks.readAt) ? (blocks.readAt - num4 - 1) : (blocks.end - num4)); } if (num5 == 0) { blocks.writeAt = num4; r = blocks.Flush(r); num4 = blocks.writeAt; num5 = ((num4 < blocks.readAt) ? (blocks.readAt - num4 - 1) : (blocks.end - num4)); if (num4 == blocks.end && blocks.readAt != 0) { num4 = 0; num5 = ((0 < blocks.readAt) ? (blocks.readAt - num4 - 1) : (blocks.end - num4)); } if (num5 == 0) { goto IL_897; } } } blocks.window[num4++] = blocks.window[j++]; num5--; if (j == blocks.end) { j = 0; } this.len--; } this.mode = 0; continue; IL_2D8: num6 = this.need; while (i < num6) { if (num2 == 0) { goto IL_811; } r = 0; num2--; num3 |= (int)(codec.InputBuffer[num++] & byte.MaxValue) << i; i += 8; } int num7 = (this.tree_index + (num3 & InternalInflateConstants.InflateMask[num6])) * 3; num3 >>= this.tree[num7 + 1]; i -= this.tree[num7 + 1]; int num8 = this.tree[num7]; if ((num8 & 16) != 0) { this.bitsToGet = (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_7B6; IL_441: num6 = this.need; while (i < num6) { if (num2 == 0) { goto IL_730; } r = 0; num2--; num3 |= (int)(codec.InputBuffer[num++] & byte.MaxValue) << i; i += 8; } num7 = (this.tree_index + (num3 & InternalInflateConstants.InflateMask[num6])) * 3; num3 >>= this.tree[num7 + 1]; i -= this.tree[num7 + 1]; num8 = this.tree[num7]; if (num8 == 0) { this.lit = this.tree[num7 + 2]; this.mode = 6; } else if ((num8 & 16) != 0) { this.bitsToGet = (num8 & 15); this.len = this.tree[num7 + 2]; this.mode = 2; } else if ((num8 & 64) == 0) { this.need = num8; this.tree_index = num7 / 3 + this.tree[num7 + 2]; } else { if ((num8 & 32) == 0) { goto IL_6D5; } this.mode = 7; } } r = -2; blocks.bitb = num3; blocks.bitk = i; codec.AvailableBytesIn = num2; codec.TotalBytesIn += (long)(num - codec.NextIn); codec.NextIn = num; blocks.writeAt = num4; return(blocks.Flush(-2)); IL_6D5: this.mode = 9; codec.Message = "invalid literal/length code"; r = -3; blocks.bitb = num3; blocks.bitk = i; codec.AvailableBytesIn = num2; codec.TotalBytesIn += (long)(num - codec.NextIn); codec.NextIn = num; blocks.writeAt = num4; return(blocks.Flush(-3)); IL_730: blocks.bitb = num3; blocks.bitk = i; codec.AvailableBytesIn = num2; codec.TotalBytesIn += (long)(num - codec.NextIn); codec.NextIn = num; blocks.writeAt = num4; return(blocks.Flush(r)); IL_773: blocks.bitb = num3; blocks.bitk = i; codec.AvailableBytesIn = num2; codec.TotalBytesIn += (long)(num - codec.NextIn); codec.NextIn = num; blocks.writeAt = num4; return(blocks.Flush(r)); IL_7B6: this.mode = 9; codec.Message = "invalid distance code"; r = -3; blocks.bitb = num3; blocks.bitk = i; codec.AvailableBytesIn = num2; codec.TotalBytesIn += (long)(num - codec.NextIn); codec.NextIn = num; blocks.writeAt = num4; return(blocks.Flush(-3)); IL_811: blocks.bitb = num3; blocks.bitk = i; codec.AvailableBytesIn = num2; codec.TotalBytesIn += (long)(num - codec.NextIn); codec.NextIn = num; blocks.writeAt = num4; return(blocks.Flush(r)); IL_854: blocks.bitb = num3; blocks.bitk = i; codec.AvailableBytesIn = num2; codec.TotalBytesIn += (long)(num - codec.NextIn); codec.NextIn = num; blocks.writeAt = num4; return(blocks.Flush(r)); IL_897: blocks.bitb = num3; blocks.bitk = i; codec.AvailableBytesIn = num2; codec.TotalBytesIn += (long)(num - codec.NextIn); codec.NextIn = num; blocks.writeAt = num4; return(blocks.Flush(r)); IL_8DA: blocks.bitb = num3; blocks.bitk = i; codec.AvailableBytesIn = num2; codec.TotalBytesIn += (long)(num - codec.NextIn); codec.NextIn = num; blocks.writeAt = num4; return(blocks.Flush(r)); IL_91D: if (i > 7) { i -= 8; num2++; num--; } blocks.writeAt = num4; r = blocks.Flush(r); num4 = blocks.writeAt; int num9 = (num4 < blocks.readAt) ? (blocks.readAt - num4 - 1) : (blocks.end - num4); if (blocks.readAt != blocks.writeAt) { blocks.bitb = num3; blocks.bitk = i; codec.AvailableBytesIn = num2; codec.TotalBytesIn += (long)(num - codec.NextIn); codec.NextIn = num; blocks.writeAt = num4; return(blocks.Flush(r)); } this.mode = 8; IL_9C2: r = 1; blocks.bitb = num3; blocks.bitk = i; codec.AvailableBytesIn = num2; codec.TotalBytesIn += (long)(num - codec.NextIn); codec.NextIn = num; blocks.writeAt = num4; return(blocks.Flush(1)); IL_A08: r = -3; blocks.bitb = num3; blocks.bitk = i; codec.AvailableBytesIn = num2; codec.TotalBytesIn += (long)(num - codec.NextIn); codec.NextIn = num; blocks.writeAt = num4; return(blocks.Flush(-3)); }
internal int Process(InflateBlocks blocks, int r) { ZlibCodec z = blocks._codec; int num1 = z.NextIn; int num2 = z.AvailableBytesIn; int num3 = blocks.bitb; int num4 = blocks.bitk; int num5 = blocks.writeAt; int num6 = num5 < blocks.readAt ? blocks.readAt - num5 - 1 : blocks.end - num5; while (true) { switch (this.mode) { case 0: if (num6 >= 258 && num2 >= 10) { blocks.bitb = num3; blocks.bitk = num4; z.AvailableBytesIn = num2; z.TotalBytesIn += (long)(num1 - z.NextIn); z.NextIn = num1; blocks.writeAt = num5; r = this.InflateFast((int)this.lbits, (int)this.dbits, this.ltree, this.ltree_index, this.dtree, this.dtree_index, blocks, z); num1 = z.NextIn; num2 = z.AvailableBytesIn; num3 = blocks.bitb; num4 = blocks.bitk; num5 = blocks.writeAt; num6 = num5 < blocks.readAt ? blocks.readAt - num5 - 1 : blocks.end - num5; if (r != 0) { this.mode = r == 1 ? 7 : 9; break; } } this.need = (int)this.lbits; this.tree = this.ltree; this.tree_index = this.ltree_index; this.mode = 1; goto case 1; case 1: int index1 = this.need; while (num4 < index1) { if (num2 != 0) { r = 0; --num2; num3 |= ((int)z.InputBuffer[num1++] & (int)byte.MaxValue) << num4; num4 += 8; } else { blocks.bitb = num3; blocks.bitk = num4; z.AvailableBytesIn = num2; z.TotalBytesIn += (long)(num1 - z.NextIn); z.NextIn = num1; blocks.writeAt = num5; return(blocks.Flush(r)); } } int index2 = (this.tree_index + (num3 & InternalInflateConstants.InflateMask[index1])) * 3; num3 >>= this.tree[index2 + 1]; num4 -= this.tree[index2 + 1]; int num7 = this.tree[index2]; if (num7 == 0) { this.lit = this.tree[index2 + 2]; this.mode = 6; break; } if ((num7 & 16) != 0) { this.bitsToGet = num7 & 15; this.len = this.tree[index2 + 2]; this.mode = 2; break; } if ((num7 & 64) == 0) { this.need = num7; this.tree_index = index2 / 3 + this.tree[index2 + 2]; break; } if ((num7 & 32) != 0) { this.mode = 7; break; } goto label_18; case 2: int index3 = this.bitsToGet; while (num4 < index3) { if (num2 != 0) { r = 0; --num2; num3 |= ((int)z.InputBuffer[num1++] & (int)byte.MaxValue) << num4; num4 += 8; } else { blocks.bitb = num3; blocks.bitk = num4; z.AvailableBytesIn = num2; z.TotalBytesIn += (long)(num1 - z.NextIn); z.NextIn = num1; blocks.writeAt = num5; return(blocks.Flush(r)); } } this.len += num3 & InternalInflateConstants.InflateMask[index3]; num3 >>= index3; num4 -= index3; this.need = (int)this.dbits; this.tree = this.dtree; this.tree_index = this.dtree_index; this.mode = 3; goto case 3; case 3: int index4 = this.need; while (num4 < index4) { if (num2 != 0) { r = 0; --num2; num3 |= ((int)z.InputBuffer[num1++] & (int)byte.MaxValue) << num4; num4 += 8; } else { blocks.bitb = num3; blocks.bitk = num4; z.AvailableBytesIn = num2; z.TotalBytesIn += (long)(num1 - z.NextIn); z.NextIn = num1; blocks.writeAt = num5; return(blocks.Flush(r)); } } int index5 = (this.tree_index + (num3 & InternalInflateConstants.InflateMask[index4])) * 3; num3 >>= this.tree[index5 + 1]; num4 -= this.tree[index5 + 1]; int num8 = this.tree[index5]; if ((num8 & 16) != 0) { this.bitsToGet = num8 & 15; this.dist = this.tree[index5 + 2]; this.mode = 4; break; } if ((num8 & 64) == 0) { this.need = num8; this.tree_index = index5 / 3 + this.tree[index5 + 2]; break; } goto label_34; case 4: int index6 = this.bitsToGet; while (num4 < index6) { if (num2 != 0) { r = 0; --num2; num3 |= ((int)z.InputBuffer[num1++] & (int)byte.MaxValue) << num4; num4 += 8; } else { blocks.bitb = num3; blocks.bitk = num4; z.AvailableBytesIn = num2; z.TotalBytesIn += (long)(num1 - z.NextIn); z.NextIn = num1; blocks.writeAt = num5; return(blocks.Flush(r)); } } this.dist += num3 & InternalInflateConstants.InflateMask[index6]; num3 >>= index6; num4 -= index6; this.mode = 5; goto case 5; case 5: int num9 = num5 - this.dist; while (num9 < 0) { num9 += blocks.end; } for (; this.len != 0; --this.len) { if (num6 == 0) { if (num5 == blocks.end && blocks.readAt != 0) { num5 = 0; num6 = num5 < blocks.readAt ? blocks.readAt - num5 - 1 : blocks.end - num5; } if (num6 == 0) { blocks.writeAt = num5; r = blocks.Flush(r); num5 = blocks.writeAt; num6 = num5 < blocks.readAt ? blocks.readAt - num5 - 1 : blocks.end - num5; if (num5 == blocks.end && blocks.readAt != 0) { num5 = 0; num6 = num5 < blocks.readAt ? blocks.readAt - num5 - 1 : blocks.end - num5; } if (num6 == 0) { blocks.bitb = num3; blocks.bitk = num4; z.AvailableBytesIn = num2; z.TotalBytesIn += (long)(num1 - z.NextIn); z.NextIn = num1; blocks.writeAt = num5; return(blocks.Flush(r)); } } } blocks.window[num5++] = blocks.window[num9++]; --num6; if (num9 == blocks.end) { num9 = 0; } } this.mode = 0; break; case 6: if (num6 == 0) { if (num5 == blocks.end && blocks.readAt != 0) { num5 = 0; num6 = num5 < blocks.readAt ? blocks.readAt - num5 - 1 : blocks.end - num5; } if (num6 == 0) { blocks.writeAt = num5; r = blocks.Flush(r); num5 = blocks.writeAt; num6 = num5 < blocks.readAt ? blocks.readAt - num5 - 1 : blocks.end - num5; if (num5 == blocks.end && blocks.readAt != 0) { num5 = 0; num6 = num5 < blocks.readAt ? blocks.readAt - num5 - 1 : blocks.end - num5; } if (num6 == 0) { goto label_65; } } } r = 0; blocks.window[num5++] = (byte)this.lit; --num6; this.mode = 0; break; case 7: goto label_68; case 8: goto label_73; case 9: goto label_74; default: goto label_75; } } label_18: this.mode = 9; z.Message = "invalid literal/length code"; r = -3; blocks.bitb = num3; blocks.bitk = num4; z.AvailableBytesIn = num2; z.TotalBytesIn += (long)(num1 - z.NextIn); z.NextIn = num1; blocks.writeAt = num5; return(blocks.Flush(r)); label_34: this.mode = 9; z.Message = "invalid distance code"; r = -3; blocks.bitb = num3; blocks.bitk = num4; z.AvailableBytesIn = num2; z.TotalBytesIn += (long)(num1 - z.NextIn); z.NextIn = num1; blocks.writeAt = num5; return(blocks.Flush(r)); label_65: blocks.bitb = num3; blocks.bitk = num4; z.AvailableBytesIn = num2; z.TotalBytesIn += (long)(num1 - z.NextIn); z.NextIn = num1; blocks.writeAt = num5; return(blocks.Flush(r)); label_68: if (num4 > 7) { num4 -= 8; ++num2; --num1; } blocks.writeAt = num5; r = blocks.Flush(r); num5 = blocks.writeAt; int num10 = num5 < blocks.readAt ? blocks.readAt - num5 - 1 : blocks.end - num5; if (blocks.readAt != blocks.writeAt) { blocks.bitb = num3; blocks.bitk = num4; z.AvailableBytesIn = num2; z.TotalBytesIn += (long)(num1 - z.NextIn); z.NextIn = num1; blocks.writeAt = num5; return(blocks.Flush(r)); } this.mode = 8; label_73: r = 1; blocks.bitb = num3; blocks.bitk = num4; z.AvailableBytesIn = num2; z.TotalBytesIn += (long)(num1 - z.NextIn); z.NextIn = num1; blocks.writeAt = num5; return(blocks.Flush(r)); label_74: r = -3; blocks.bitb = num3; blocks.bitk = num4; z.AvailableBytesIn = num2; z.TotalBytesIn += (long)(num1 - z.NextIn); z.NextIn = num1; blocks.writeAt = num5; return(blocks.Flush(r)); label_75: r = -2; blocks.bitb = num3; blocks.bitk = num4; z.AvailableBytesIn = num2; z.TotalBytesIn += (long)(num1 - z.NextIn); z.NextIn = num1; blocks.writeAt = num5; return(blocks.Flush(r)); }
internal int Process(InflateBlocks blocks, int r) { int tindex; // temporary pointer int e; // extra bits or operation int nextIn = blocks._NextIn; // input data pointer int availIn = blocks._AvailIn; // bytes available there int bits = blocks.bitb; // bit buffer int bitsNum = blocks.bitk; // bits in bit buffer int q = blocks.writeAt; // output window write pointer int m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; // bytes to end of window or read pointer // 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 && availIn >= 10) { blocks.UpdateState(bits, bitsNum, availIn, nextIn, q); r = InflateFast(lbits, dbits, ltree, ltree_index, dtree, dtree_index, blocks); nextIn = blocks._NextIn; availIn = blocks._AvailIn; bits = blocks.bitb; bitsNum = blocks.bitk; q = blocks.writeAt; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; if (r != RCode.Okay) { mode = (r == RCode.StreamEnd) ? WASH : BADCODE; break; } } need = lbits; tree = ltree; tree_index = ltree_index; mode = LEN; goto case LEN; case LEN: // i: get length/literal/eob next while (bitsNum < need) { if (availIn != 0) { r = RCode.Okay; } else { return(blocks.RanOutOfInput(bits, bitsNum, availIn, nextIn, q, r)); } availIn--; bits |= blocks.InputBuffer[nextIn++] << bitsNum; bitsNum += 8; } tindex = (tree_index + (bits & Constants.InflateMask[need])) * 3; bits >>= (tree[tindex + 1]); bitsNum -= (tree[tindex + 1]); e = tree[tindex]; if (e == 0) { // literal lit = tree[tindex + 2]; mode = LIT; break; } if ((e & 16) != 0) { // length bitsToGet = 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; } throw new InvalidDataException("invalid literal/length code"); case LENEXT: // i: getting length extra (have base) while (bitsNum < bitsToGet) { if (availIn != 0) { r = RCode.Okay; } else { return(blocks.RanOutOfInput(bits, bitsNum, availIn, nextIn, q, r)); } availIn--; bits |= blocks.InputBuffer[nextIn++] << bitsNum; bitsNum += 8; } len += (bits & Constants.InflateMask[bitsToGet]); bits >>= bitsToGet; bitsNum -= bitsToGet; need = dbits; tree = dtree; tree_index = dtree_index; mode = DIST; goto case DIST; case DIST: // i: get distance next while (bitsNum < need) { if (availIn != 0) { r = RCode.Okay; } else { return(blocks.RanOutOfInput(bits, bitsNum, availIn, nextIn, q, r)); } availIn--; bits |= blocks.InputBuffer[nextIn++] << bitsNum; bitsNum += 8; } tindex = (tree_index + (bits & Constants.InflateMask[need])) * 3; bits >>= tree[tindex + 1]; bitsNum -= tree[tindex + 1]; e = tree[tindex]; if ((e & 0x10) != 0) { // distance bitsToGet = 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; } throw new InvalidDataException("invalid distance code"); case DISTEXT: // i: getting distance extra while (bitsNum < bitsToGet) { if (availIn != 0) { r = RCode.Okay; } else { return(blocks.RanOutOfInput(bits, bitsNum, availIn, nextIn, q, r)); } availIn--; bits |= blocks.InputBuffer[nextIn++] << bitsNum; bitsNum += 8; } dist += (bits & Constants.InflateMask[bitsToGet]); bits >>= bitsToGet; bitsNum -= bitsToGet; mode = COPY; goto case COPY; case COPY: // o: copying bytes in window, waiting for space int f = q - dist; // pointer to copy strings from while (f < 0) { // modulo window size-"while" instead f += blocks.end; // of "if" handles invalid distances } while (len != 0) { if (m == 0) { if (q == blocks.end && blocks.readAt != 0) { q = 0; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; } if (m == 0) { blocks.writeAt = q; r = blocks.Flush(r); q = blocks.writeAt; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; if (q == blocks.end && blocks.readAt != 0) { q = 0; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; } if (m == 0) { return(blocks.RanOutOfInput(bits, bitsNum, availIn, nextIn, q, r)); } } } blocks.window[q++] = blocks.window[f++]; m--; if (f == blocks.end) { f = 0; } len--; } mode = START; break; case LIT: // o: got literal, waiting for output space if (m == 0) { if (q == blocks.end && blocks.readAt != 0) { q = 0; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; } if (m == 0) { blocks.writeAt = q; r = blocks.Flush(r); q = blocks.writeAt; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; if (q == blocks.end && blocks.readAt != 0) { q = 0; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; } if (m == 0) { return(blocks.RanOutOfInput(bits, bitsNum, availIn, nextIn, q, r)); } } } r = RCode.Okay; blocks.window[q++] = (byte)lit; m--; mode = START; break; case WASH: // o: got eob, possibly more output if (bitsNum > 7) { // return unused byte, if any bitsNum -= 8; availIn++; nextIn--; // can always return one } blocks.writeAt = q; r = blocks.Flush(r); q = blocks.writeAt; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; if (blocks.readAt != blocks.writeAt) { return(blocks.RanOutOfInput(bits, bitsNum, availIn, nextIn, q, r)); } mode = END; goto case END; case END: r = RCode.StreamEnd; return(blocks.RanOutOfInput(bits, bitsNum, availIn, nextIn, q, r)); default: throw new InvalidDataException("Encountered error: " + mode); } } }
internal int Process(InflateBlocks blocks, int r) { ZlibCodec codec = blocks._codec; int num = codec.NextIn; int num2 = codec.AvailableBytesIn; int num3 = blocks.bitb; int i = blocks.bitk; int num4 = blocks.writeAt; int num5 = (num4 >= blocks.readAt) ? (blocks.end - num4) : (blocks.readAt - num4 - 1); for (;;) { int num6; switch (this.mode) { case 0: if (num5 >= 258 && num2 >= 10) { blocks.bitb = num3; blocks.bitk = i; codec.AvailableBytesIn = num2; codec.TotalBytesIn += (long)(num - codec.NextIn); codec.NextIn = num; blocks.writeAt = num4; r = this.InflateFast((int)this.lbits, (int)this.dbits, this.ltree, this.ltree_index, this.dtree, this.dtree_index, blocks, codec); num = codec.NextIn; num2 = codec.AvailableBytesIn; num3 = blocks.bitb; i = blocks.bitk; num4 = blocks.writeAt; num5 = ((num4 >= blocks.readAt) ? (blocks.end - num4) : (blocks.readAt - num4 - 1)); if (r != 0) { this.mode = ((r != 1) ? 9 : 7); continue; } } this.need = (int)this.lbits; this.tree = this.ltree; this.tree_index = this.ltree_index; this.mode = 1; goto IL_1C4; case 1: goto IL_1C4; case 2: num6 = this.bitsToGet; while (i < num6) { if (num2 == 0) { goto IL_3A2; } r = 0; num2--; num3 |= (int)(codec.InputBuffer[num++] & byte.MaxValue) << i; i += 8; } this.len += (num3 & InternalInflateConstants.InflateMask[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_471; case 3: goto IL_471; case 4: num6 = this.bitsToGet; while (i < num6) { if (num2 == 0) { goto IL_618; } r = 0; num2--; num3 |= (int)(codec.InputBuffer[num++] & byte.MaxValue) << i; i += 8; } this.dist += (num3 & InternalInflateConstants.InflateMask[num6]); num3 >>= num6; i -= num6; this.mode = 5; goto IL_6C3; case 5: goto IL_6C3; case 6: if (num5 == 0) { if (num4 == blocks.end && blocks.readAt != 0) { num4 = 0; num5 = ((num4 >= blocks.readAt) ? (blocks.end - num4) : (blocks.readAt - num4 - 1)); } if (num5 == 0) { blocks.writeAt = num4; r = blocks.Flush(r); num4 = blocks.writeAt; num5 = ((num4 >= blocks.readAt) ? (blocks.end - num4) : (blocks.readAt - num4 - 1)); if (num4 == blocks.end && blocks.readAt != 0) { num4 = 0; num5 = ((num4 >= blocks.readAt) ? (blocks.end - num4) : (blocks.readAt - num4 - 1)); } if (num5 == 0) { goto Block_44; } } } r = 0; blocks.window[num4++] = (byte)this.lit; num5--; this.mode = 0; continue; case 7: goto IL_9B8; case 8: goto IL_A7A; case 9: goto IL_AC7; } break; continue; IL_1C4: num6 = this.need; while (i < num6) { if (num2 == 0) { goto IL_1DF; } r = 0; num2--; num3 |= (int)(codec.InputBuffer[num++] & byte.MaxValue) << i; i += 8; } int num7 = (this.tree_index + (num3 & InternalInflateConstants.InflateMask[num6])) * 3; num3 >>= this.tree[num7 + 1]; i -= this.tree[num7 + 1]; int num8 = this.tree[num7]; if (num8 == 0) { this.lit = this.tree[num7 + 2]; this.mode = 6; continue; } if ((num8 & 16) != 0) { this.bitsToGet = (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_325; IL_471: num6 = this.need; while (i < num6) { if (num2 == 0) { goto IL_48C; } r = 0; num2--; num3 |= (int)(codec.InputBuffer[num++] & byte.MaxValue) << i; i += 8; } num7 = (this.tree_index + (num3 & InternalInflateConstants.InflateMask[num6])) * 3; num3 >>= this.tree[num7 + 1]; i -= this.tree[num7 + 1]; num8 = this.tree[num7]; if ((num8 & 16) != 0) { this.bitsToGet = (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_59B; IL_6C3: int j; for (j = num4 - this.dist; j < 0; j += blocks.end) { } while (this.len != 0) { if (num5 == 0) { if (num4 == blocks.end && blocks.readAt != 0) { num4 = 0; num5 = ((num4 >= blocks.readAt) ? (blocks.end - num4) : (blocks.readAt - num4 - 1)); } if (num5 == 0) { blocks.writeAt = num4; r = blocks.Flush(r); num4 = blocks.writeAt; num5 = ((num4 >= blocks.readAt) ? (blocks.end - num4) : (blocks.readAt - num4 - 1)); if (num4 == blocks.end && blocks.readAt != 0) { num4 = 0; num5 = ((num4 >= blocks.readAt) ? (blocks.end - num4) : (blocks.readAt - num4 - 1)); } if (num5 == 0) { goto Block_32; } } } blocks.window[num4++] = blocks.window[j++]; num5--; if (j == blocks.end) { j = 0; } this.len--; } this.mode = 0; } r = -2; blocks.bitb = num3; blocks.bitk = i; codec.AvailableBytesIn = num2; codec.TotalBytesIn += (long)(num - codec.NextIn); codec.NextIn = num; blocks.writeAt = num4; return(blocks.Flush(r)); IL_1DF: blocks.bitb = num3; blocks.bitk = i; codec.AvailableBytesIn = num2; codec.TotalBytesIn += (long)(num - codec.NextIn); codec.NextIn = num; blocks.writeAt = num4; return(blocks.Flush(r)); IL_325: this.mode = 9; codec.Message = "invalid literal/length code"; r = -3; blocks.bitb = num3; blocks.bitk = i; codec.AvailableBytesIn = num2; codec.TotalBytesIn += (long)(num - codec.NextIn); codec.NextIn = num; blocks.writeAt = num4; return(blocks.Flush(r)); IL_3A2: blocks.bitb = num3; blocks.bitk = i; codec.AvailableBytesIn = num2; codec.TotalBytesIn += (long)(num - codec.NextIn); codec.NextIn = num; blocks.writeAt = num4; return(blocks.Flush(r)); IL_48C: blocks.bitb = num3; blocks.bitk = i; codec.AvailableBytesIn = num2; codec.TotalBytesIn += (long)(num - codec.NextIn); codec.NextIn = num; blocks.writeAt = num4; return(blocks.Flush(r)); IL_59B: this.mode = 9; codec.Message = "invalid distance code"; r = -3; blocks.bitb = num3; blocks.bitk = i; codec.AvailableBytesIn = num2; codec.TotalBytesIn += (long)(num - codec.NextIn); codec.NextIn = num; blocks.writeAt = num4; return(blocks.Flush(r)); IL_618: blocks.bitb = num3; blocks.bitk = i; codec.AvailableBytesIn = num2; codec.TotalBytesIn += (long)(num - codec.NextIn); codec.NextIn = num; blocks.writeAt = num4; return(blocks.Flush(r)); Block_32: blocks.bitb = num3; blocks.bitk = i; codec.AvailableBytesIn = num2; codec.TotalBytesIn += (long)(num - codec.NextIn); codec.NextIn = num; blocks.writeAt = num4; return(blocks.Flush(r)); Block_44: blocks.bitb = num3; blocks.bitk = i; codec.AvailableBytesIn = num2; codec.TotalBytesIn += (long)(num - codec.NextIn); codec.NextIn = num; blocks.writeAt = num4; return(blocks.Flush(r)); IL_9B8: if (i > 7) { i -= 8; num2++; num--; } blocks.writeAt = num4; r = blocks.Flush(r); num4 = blocks.writeAt; int num9 = (num4 >= blocks.readAt) ? (blocks.end - num4) : (blocks.readAt - num4 - 1); if (blocks.readAt != blocks.writeAt) { blocks.bitb = num3; blocks.bitk = i; codec.AvailableBytesIn = num2; codec.TotalBytesIn += (long)(num - codec.NextIn); codec.NextIn = num; blocks.writeAt = num4; return(blocks.Flush(r)); } this.mode = 8; IL_A7A: r = 1; blocks.bitb = num3; blocks.bitk = i; codec.AvailableBytesIn = num2; codec.TotalBytesIn += (long)(num - codec.NextIn); codec.NextIn = num; blocks.writeAt = num4; return(blocks.Flush(r)); IL_AC7: r = -3; blocks.bitb = num3; blocks.bitk = i; codec.AvailableBytesIn = num2; codec.TotalBytesIn += (long)(num - codec.NextIn); codec.NextIn = num; blocks.writeAt = num4; return(blocks.Flush(r)); }
internal int InflateFast(int bl, int bd, int[] tl, int tl_index, int[] td, int td_index, InflateBlocks s, ZlibCodec z) { int num = z.NextIn; int num2 = z.AvailableBytesIn; int num3 = s.bitb; int num4 = s.bitk; int num5 = s.writeAt; int num6 = (num5 >= s.readAt) ? (s.end - num5) : (s.readAt - num5 - 1); int num7 = InternalInflateConstants.InflateMask[bl]; int num8 = InternalInflateConstants.InflateMask[bd]; int num13; while (true) { if (num4 < 20) { num2--; num3 |= (z.InputBuffer[num++] & 0xFF) << num4; num4 += 8; } else { int num10 = num3 & num7; int num11 = (tl_index + num10) * 3; int num12; if ((num12 = tl[num11]) != 0) { while (true) { num3 >>= tl[num11 + 1]; num4 -= tl[num11 + 1]; if ((num12 & 0x10) != 0) { num12 &= 0xF; num13 = tl[num11 + 2] + (num3 & InternalInflateConstants.InflateMask[num12]); num3 >>= num12; for (num4 -= num12; num4 < 15; num4 += 8) { num2--; num3 |= (z.InputBuffer[num++] & 0xFF) << num4; } num10 = (num3 & num8); num11 = (td_index + num10) * 3; num12 = td[num11]; while (true) { num3 >>= td[num11 + 1]; num4 -= td[num11 + 1]; if ((num12 & 0x10) != 0) { break; } if ((num12 & 0x40) != 0) { z.Message = "invalid distance code"; num13 = z.AvailableBytesIn - num2; num13 = ((num4 >> 3 >= num13) ? num13 : (num4 >> 3)); num2 += num13; num -= num13; num4 -= num13 << 3; s.bitb = num3; s.bitk = num4; z.AvailableBytesIn = num2; z.TotalBytesIn += num - z.NextIn; z.NextIn = num; s.writeAt = num5; return(-3); } num10 += td[num11 + 2]; num10 += (num3 & InternalInflateConstants.InflateMask[num12]); num11 = (td_index + num10) * 3; num12 = td[num11]; } for (num12 &= 0xF; num4 < num12; num4 += 8) { num2--; num3 |= (z.InputBuffer[num++] & 0xFF) << num4; } int num16 = td[num11 + 2] + (num3 & InternalInflateConstants.InflateMask[num12]); num3 >>= num12; num4 -= num12; num6 -= num13; int num17; if (num5 >= num16) { num17 = num5 - num16; if (num5 - num17 > 0 && 2 > num5 - num17) { s.window[num5++] = s.window[num17++]; s.window[num5++] = s.window[num17++]; num13 -= 2; } else { Array.Copy(s.window, num17, s.window, num5, 2); num5 += 2; num17 += 2; num13 -= 2; } } else { num17 = num5 - num16; do { num17 += s.end; }while (num17 < 0); num12 = s.end - num17; if (num13 > num12) { num13 -= num12; if (num5 - num17 > 0 && num12 > num5 - num17) { do { s.window[num5++] = s.window[num17++]; }while (--num12 != 0); } else { Array.Copy(s.window, num17, s.window, num5, num12); num5 += num12; num17 += num12; num12 = 0; } num17 = 0; } } if (num5 - num17 > 0 && num13 > num5 - num17) { do { s.window[num5++] = s.window[num17++]; }while (--num13 != 0); } else { Array.Copy(s.window, num17, s.window, num5, num13); num5 += num13; num17 += num13; num13 = 0; } break; } if ((num12 & 0x40) != 0) { if ((num12 & 0x20) != 0) { num13 = z.AvailableBytesIn - num2; num13 = ((num4 >> 3 >= num13) ? num13 : (num4 >> 3)); num2 += num13; num -= num13; num4 -= num13 << 3; s.bitb = num3; s.bitk = num4; z.AvailableBytesIn = num2; z.TotalBytesIn += num - z.NextIn; z.NextIn = num; s.writeAt = num5; return(1); } z.Message = "invalid literal/length code"; num13 = z.AvailableBytesIn - num2; num13 = ((num4 >> 3 >= num13) ? num13 : (num4 >> 3)); num2 += num13; num -= num13; num4 -= num13 << 3; s.bitb = num3; s.bitk = num4; z.AvailableBytesIn = num2; z.TotalBytesIn += num - z.NextIn; z.NextIn = num; s.writeAt = num5; return(-3); } num10 += tl[num11 + 2]; num10 += (num3 & InternalInflateConstants.InflateMask[num12]); num11 = (tl_index + num10) * 3; if ((num12 = tl[num11]) == 0) { num3 >>= tl[num11 + 1]; num4 -= tl[num11 + 1]; s.window[num5++] = (byte)tl[num11 + 2]; num6--; break; } } } else { num3 >>= tl[num11 + 1]; num4 -= tl[num11 + 1]; s.window[num5++] = (byte)tl[num11 + 2]; num6--; } if (num6 < 258 || num2 < 10) { break; } } } num13 = z.AvailableBytesIn - num2; num13 = ((num4 >> 3 >= num13) ? num13 : (num4 >> 3)); num2 += num13; num -= num13; num4 -= num13 << 3; s.bitb = num3; s.bitk = num4; z.AvailableBytesIn = num2; z.TotalBytesIn += num - z.NextIn; z.NextIn = num; s.writeAt = num5; return(0); }
internal int InflateFast(int bl, int bd, int[] tl, int tl_index, int[] td, int td_index, InflateBlocks s, ZlibCodec z) { int p5 = z.NextIn; int n3 = z.AvailableBytesIn; int b = s.bitb; int k4 = s.bitk; int q = s.writeAt; int m2 = (q < s.readAt) ? (s.readAt - q - 1) : (s.end - q); int ml = InternalInflateConstants.InflateMask[bl]; int md = InternalInflateConstants.InflateMask[bd]; int c10; while (true) { if (k4 < 20) { n3--; b |= (z.InputBuffer[p5++] & 0xFF) << k4; k4 += 8; continue; } int t4 = b & ml; int[] tp2 = tl; int tp_index2 = tl_index; int tp_index_t_4 = (tp_index2 + t4) * 3; int e6; if ((e6 = tp2[tp_index_t_4]) == 0) { b >>= tp2[tp_index_t_4 + 1]; k4 -= tp2[tp_index_t_4 + 1]; s.window[q++] = (byte)tp2[tp_index_t_4 + 2]; m2--; } else { while (true) { b >>= tp2[tp_index_t_4 + 1]; k4 -= tp2[tp_index_t_4 + 1]; if ((e6 & 0x10) != 0) { e6 &= 0xF; c10 = tp2[tp_index_t_4 + 2] + (b & InternalInflateConstants.InflateMask[e6]); b >>= e6; for (k4 -= e6; k4 < 15; k4 += 8) { n3--; b |= (z.InputBuffer[p5++] & 0xFF) << k4; } t4 = (b & md); tp2 = td; tp_index2 = td_index; tp_index_t_4 = (tp_index2 + t4) * 3; e6 = tp2[tp_index_t_4]; while (true) { b >>= tp2[tp_index_t_4 + 1]; k4 -= tp2[tp_index_t_4 + 1]; if ((e6 & 0x10) != 0) { break; } if ((e6 & 0x40) == 0) { t4 += tp2[tp_index_t_4 + 2]; t4 += (b & InternalInflateConstants.InflateMask[e6]); tp_index_t_4 = (tp_index2 + t4) * 3; e6 = tp2[tp_index_t_4]; continue; } z.Message = "invalid distance code"; c10 = z.AvailableBytesIn - n3; c10 = ((k4 >> 3 < c10) ? (k4 >> 3) : c10); n3 += c10; p5 -= c10; k4 -= c10 << 3; s.bitb = b; s.bitk = k4; z.AvailableBytesIn = n3; z.TotalBytesIn += p5 - z.NextIn; z.NextIn = p5; s.writeAt = q; return(-3); } for (e6 &= 0xF; k4 < e6; k4 += 8) { n3--; b |= (z.InputBuffer[p5++] & 0xFF) << k4; } int d = tp2[tp_index_t_4 + 2] + (b & InternalInflateConstants.InflateMask[e6]); b >>= e6; k4 -= e6; m2 -= c10; int r3; if (q >= d) { r3 = q - d; if (q - r3 > 0 && 2 > q - r3) { s.window[q++] = s.window[r3++]; s.window[q++] = s.window[r3++]; c10 -= 2; } else { Array.Copy(s.window, r3, s.window, q, 2); q += 2; r3 += 2; c10 -= 2; } } else { r3 = q - d; do { r3 += s.end; }while (r3 < 0); e6 = s.end - r3; if (c10 > e6) { c10 -= e6; if (q - r3 > 0 && e6 > q - r3) { do { s.window[q++] = s.window[r3++]; }while (--e6 != 0); } else { Array.Copy(s.window, r3, s.window, q, e6); q += e6; r3 += e6; e6 = 0; } r3 = 0; } } if (q - r3 > 0 && c10 > q - r3) { do { s.window[q++] = s.window[r3++]; }while (--c10 != 0); } else { Array.Copy(s.window, r3, s.window, q, c10); q += c10; r3 += c10; c10 = 0; } break; } if ((e6 & 0x40) == 0) { t4 += tp2[tp_index_t_4 + 2]; t4 += (b & InternalInflateConstants.InflateMask[e6]); tp_index_t_4 = (tp_index2 + t4) * 3; if ((e6 = tp2[tp_index_t_4]) == 0) { b >>= tp2[tp_index_t_4 + 1]; k4 -= tp2[tp_index_t_4 + 1]; s.window[q++] = (byte)tp2[tp_index_t_4 + 2]; m2--; break; } continue; } if ((e6 & 0x20) != 0) { c10 = z.AvailableBytesIn - n3; c10 = ((k4 >> 3 < c10) ? (k4 >> 3) : c10); n3 += c10; p5 -= c10; k4 -= c10 << 3; s.bitb = b; s.bitk = k4; z.AvailableBytesIn = n3; z.TotalBytesIn += p5 - z.NextIn; z.NextIn = p5; s.writeAt = q; return(1); } z.Message = "invalid literal/length code"; c10 = z.AvailableBytesIn - n3; c10 = ((k4 >> 3 < c10) ? (k4 >> 3) : c10); n3 += c10; p5 -= c10; k4 -= c10 << 3; s.bitb = b; s.bitk = k4; z.AvailableBytesIn = n3; z.TotalBytesIn += p5 - z.NextIn; z.NextIn = p5; s.writeAt = q; return(-3); } } if (m2 < 258 || n3 < 10) { break; } } c10 = z.AvailableBytesIn - n3; c10 = ((k4 >> 3 < c10) ? (k4 >> 3) : c10); n3 += c10; p5 -= c10; k4 -= c10 << 3; s.bitb = b; s.bitk = k4; z.AvailableBytesIn = n3; z.TotalBytesIn += p5 - z.NextIn; z.NextIn = p5; s.writeAt = q; return(0); }
internal int InflateFast(int bl, int bd, int[] tl, int tl_index, int[] td, int td_index, InflateBlocks s, ZlibCodec z) { int p = z.NextIn; int k = z.AvailableBytesIn; int b = s.bitb; int i = s.bitk; int q = s.writeAt; int j = ((q < s.readAt) ? (s.readAt - q - 1) : (s.end - q)); int ml = InternalInflateConstants.InflateMask[bl]; int md = InternalInflateConstants.InflateMask[bd]; int c; while (true) { if (i < 20) { k--; b |= (z.InputBuffer[p++] & 0xFF) << i; i += 8; continue; } int t = b & ml; int[] tp = tl; int tp_index = tl_index; int tp_index_t_3 = (tp_index + t) * 3; int e; if ((e = tp[tp_index_t_3]) == 0) { b >>= tp[tp_index_t_3 + 1]; i -= tp[tp_index_t_3 + 1]; s.window[q++] = (byte)tp[tp_index_t_3 + 2]; j--; } else { while (true) { b >>= tp[tp_index_t_3 + 1]; i -= tp[tp_index_t_3 + 1]; if (((uint)e & 0x10u) != 0) { e &= 0xF; c = tp[tp_index_t_3 + 2] + (b & InternalInflateConstants.InflateMask[e]); b >>= e; for (i -= e; i < 15; i += 8) { k--; b |= (z.InputBuffer[p++] & 0xFF) << i; } t = b & md; tp = td; tp_index = td_index; tp_index_t_3 = (tp_index + t) * 3; e = tp[tp_index_t_3]; while (true) { b >>= tp[tp_index_t_3 + 1]; i -= tp[tp_index_t_3 + 1]; if (((uint)e & 0x10u) != 0) { break; } if ((e & 0x40) == 0) { t += tp[tp_index_t_3 + 2]; t += b & InternalInflateConstants.InflateMask[e]; tp_index_t_3 = (tp_index + t) * 3; e = tp[tp_index_t_3]; continue; } z.Message = "invalid distance code"; c = z.AvailableBytesIn - k; c = ((i >> 3 < c) ? (i >> 3) : c); k += c; p -= c; i -= c << 3; s.bitb = b; s.bitk = i; z.AvailableBytesIn = k; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; s.writeAt = q; return(-3); } for (e &= 0xF; i < e; i += 8) { k--; b |= (z.InputBuffer[p++] & 0xFF) << i; } int d = tp[tp_index_t_3 + 2] + (b & InternalInflateConstants.InflateMask[e]); b >>= e; i -= e; j -= c; int r; if (q >= d) { r = q - d; if (q - r > 0 && 2 > q - r) { s.window[q++] = s.window[r++]; s.window[q++] = s.window[r++]; c -= 2; } else { Array.Copy(s.window, r, s.window, q, 2); q += 2; r += 2; c -= 2; } } else { r = q - d; do { r += s.end; }while (r < 0); e = s.end - r; if (c > e) { c -= e; if (q - r > 0 && e > q - r) { do { s.window[q++] = s.window[r++]; }while (--e != 0); } else { Array.Copy(s.window, r, s.window, q, e); q += e; r += e; e = 0; } r = 0; } } if (q - r > 0 && c > q - r) { do { s.window[q++] = s.window[r++]; }while (--c != 0); break; } Array.Copy(s.window, r, s.window, q, c); q += c; r += c; c = 0; break; } if ((e & 0x40) == 0) { t += tp[tp_index_t_3 + 2]; t += b & InternalInflateConstants.InflateMask[e]; tp_index_t_3 = (tp_index + t) * 3; if ((e = tp[tp_index_t_3]) == 0) { b >>= tp[tp_index_t_3 + 1]; i -= tp[tp_index_t_3 + 1]; s.window[q++] = (byte)tp[tp_index_t_3 + 2]; j--; break; } continue; } if (((uint)e & 0x20u) != 0) { c = z.AvailableBytesIn - k; c = ((i >> 3 < c) ? (i >> 3) : c); k += c; p -= c; i -= c << 3; s.bitb = b; s.bitk = i; z.AvailableBytesIn = k; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; s.writeAt = q; return(1); } z.Message = "invalid literal/length code"; c = z.AvailableBytesIn - k; c = ((i >> 3 < c) ? (i >> 3) : c); k += c; p -= c; i -= c << 3; s.bitb = b; s.bitk = i; z.AvailableBytesIn = k; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; s.writeAt = q; return(-3); } } if (j < 258 || k < 10) { break; } } c = z.AvailableBytesIn - k; c = ((i >> 3 < c) ? (i >> 3) : c); k += c; p -= c; i -= c << 3; s.bitb = b; s.bitk = i; z.AvailableBytesIn = k; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; s.writeAt = q; return(0); }
// Called with number of bytes left to write in window at least 258 // (the maximum string length) and number of input bytes available // at least ten. The ten bytes are six bytes for the longest length/ // distance pair plus four bytes for overloading the bit buffer. internal int InflateFast(int bl, int bd, int[] tl, int tl_index, int[] td, int td_index, InflateBlocks s, ZlibCodec z) { int t; // temporary pointer int[] tp; // temporary pointer int tp_index; // temporary pointer int e; // extra bits or operation 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 int ml; // mask for literal/length tree int md; // mask for distance tree int c; // bytes to copy int d; // distance back to copy from int r; // copy source pointer int tp_index_t_3; // (tp_index+t)*3 // load input, output, bit values p = z.NextIn; n = z.AvailableBytesIn; b = s.bitb; k = s.bitk; q = s.writeAt; m = q < s.readAt ? s.readAt - q - 1 : s.end - q; // initialize masks ml = InternalInflateConstants.InflateMask[bl]; md = InternalInflateConstants.InflateMask[bd]; // do until not enough input or output space for fast loop do { // assume called with m >= 258 && n >= 10 // get literal/length code while (k < (20)) { // max bits for literal/length code n--; b |= (z.InputBuffer[p++] & 0xff) << k; k += 8; } t = b & ml; tp = tl; tp_index = tl_index; tp_index_t_3 = (tp_index + t) * 3; if ((e = tp[tp_index_t_3]) == 0) { b >>= (tp[tp_index_t_3 + 1]); k -= (tp[tp_index_t_3 + 1]); s.window[q++] = (byte)tp[tp_index_t_3 + 2]; m--; continue; } do { b >>= (tp[tp_index_t_3 + 1]); k -= (tp[tp_index_t_3 + 1]); if ((e & 16) != 0) { e &= 15; c = tp[tp_index_t_3 + 2] + ((int)b & InternalInflateConstants.InflateMask[e]); b >>= e; k -= e; // decode distance base of block to copy while (k < 15) { // max bits for distance code n--; b |= (z.InputBuffer[p++] & 0xff) << k; k += 8; } t = b & md; tp = td; tp_index = td_index; tp_index_t_3 = (tp_index + t) * 3; e = tp[tp_index_t_3]; do { b >>= (tp[tp_index_t_3 + 1]); k -= (tp[tp_index_t_3 + 1]); if ((e & 16) != 0) { // get extra bits to add to distance base e &= 15; while (k < e) { // get extra bits (up to 13) n--; b |= (z.InputBuffer[p++] & 0xff) << k; k += 8; } d = tp[tp_index_t_3 + 2] + (b & InternalInflateConstants.InflateMask[e]); b >>= e; k -= e; // do the copy m -= c; if (q >= d) { // offset before dest // just copy r = q - d; if (q - r > 0 && 2 > (q - r)) { s.window[q++] = s.window[r++]; // minimum count is three, s.window[q++] = s.window[r++]; // so unroll loop a little c -= 2; } else { Array.Copy(s.window, r, s.window, q, 2); q += 2; r += 2; c -= 2; } } else { // else offset after destination r = q - d; do { r += s.end; // force pointer in window }while (r < 0); // covers invalid distances e = s.end - r; if (c > e) { // if source crosses, c -= e; // wrapped copy if (q - r > 0 && e > (q - r)) { do { s.window[q++] = s.window[r++]; }while (--e != 0); } else { Array.Copy(s.window, r, s.window, q, e); q += e; r += e; e = 0; } r = 0; // copy rest from start of window } } // copy all or what's left if (q - r > 0 && c > (q - r)) { do { s.window[q++] = s.window[r++]; }while (--c != 0); } else { Array.Copy(s.window, r, s.window, q, c); q += c; r += c; c = 0; } break; } else if ((e & 64) == 0) { t += tp[tp_index_t_3 + 2]; t += (b & InternalInflateConstants.InflateMask[e]); tp_index_t_3 = (tp_index + t) * 3; e = tp[tp_index_t_3]; } else { z.Message = "invalid distance code"; c = z.AvailableBytesIn - n; c = (k >> 3) < c ? k >> 3 : c; n += c; p -= c; k -= (c << 3); s.bitb = b; s.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; s.writeAt = q; return(ZlibConstants.Z_DATA_ERROR); } }while (true); break; } if ((e & 64) == 0) { t += tp[tp_index_t_3 + 2]; t += (b & InternalInflateConstants.InflateMask[e]); tp_index_t_3 = (tp_index + t) * 3; if ((e = tp[tp_index_t_3]) == 0) { b >>= (tp[tp_index_t_3 + 1]); k -= (tp[tp_index_t_3 + 1]); s.window[q++] = (byte)tp[tp_index_t_3 + 2]; m--; break; } } else if ((e & 32) != 0) { c = z.AvailableBytesIn - n; c = (k >> 3) < c ? k >> 3 : c; n += c; p -= c; k -= (c << 3); s.bitb = b; s.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; s.writeAt = q; return(ZlibConstants.Z_STREAM_END); } else { z.Message = "invalid literal/length code"; c = z.AvailableBytesIn - n; c = (k >> 3) < c ? k >> 3 : c; n += c; p -= c; k -= (c << 3); s.bitb = b; s.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; s.writeAt = q; return(ZlibConstants.Z_DATA_ERROR); } }while (true); }while (m >= 258 && n >= 10); // not enough input or output--restore pointers and return c = z.AvailableBytesIn - n; c = (k >> 3) < c ? k >> 3 : c; n += c; p -= c; k -= (c << 3); s.bitb = b; s.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; s.writeAt = q; return(ZlibConstants.Z_OK); }
internal int InflateFast(int bl, int bd, int[] tl, int tl_index, int[] td, int td_index, InflateBlocks s, ZlibCodec z) { int num12; int nextIn = z.NextIn; int availableBytesIn = z.AvailableBytesIn; int bitb = s.bitb; int bitk = s.bitk; int write = s.write; int num9 = (write < s.read) ? ((s.read - write) - 1) : (s.end - write); int num10 = inflate_mask[bl]; int num11 = inflate_mask[bd]; Label_0096: while (bitk < 20) { availableBytesIn--; bitb |= (z.InputBuffer[nextIn++] & 0xff) << bitk; bitk += 8; } int num = bitb & num10; int[] numArray = tl; int num2 = tl_index; int index = (num2 + num) * 3; int num3 = numArray[index]; if (num3 == 0) { bitb = bitb >> numArray[index + 1]; bitk -= numArray[index + 1]; s.window[write++] = (byte)numArray[index + 2]; num9--; } else { while (true) { bool flag; bitb = bitb >> numArray[index + 1]; bitk -= numArray[index + 1]; if ((num3 & 0x10) != 0) { num3 &= 15; num12 = numArray[index + 2] + (bitb & inflate_mask[num3]); bitb = bitb >> num3; bitk -= num3; while (bitk < 15) { availableBytesIn--; bitb |= (z.InputBuffer[nextIn++] & 0xff) << bitk; bitk += 8; } num = bitb & num11; numArray = td; num2 = td_index; index = (num2 + num) * 3; num3 = numArray[index]; while (true) { bitb = bitb >> numArray[index + 1]; bitk -= numArray[index + 1]; if ((num3 & 0x10) != 0) { int num14; num3 &= 15; while (bitk < num3) { availableBytesIn--; bitb |= (z.InputBuffer[nextIn++] & 0xff) << bitk; bitk += 8; } int num13 = numArray[index + 2] + (bitb & inflate_mask[num3]); bitb = bitb >> num3; bitk -= num3; num9 -= num12; if (write >= num13) { num14 = write - num13; if (((write - num14) > 0) && (2 > (write - num14))) { s.window[write++] = s.window[num14++]; s.window[write++] = s.window[num14++]; num12 -= 2; } else { Array.Copy(s.window, num14, s.window, write, 2); write += 2; num14 += 2; num12 -= 2; } } else { num14 = write - num13; do { num14 += s.end; }while (num14 < 0); num3 = s.end - num14; if (num12 > num3) { num12 -= num3; if (((write - num14) > 0) && (num3 > (write - num14))) { do { s.window[write++] = s.window[num14++]; }while (--num3 != 0); } else { Array.Copy(s.window, num14, s.window, write, num3); write += num3; num14 += num3; num3 = 0; } num14 = 0; } } if (((write - num14) > 0) && (num12 > (write - num14))) { do { s.window[write++] = s.window[num14++]; }while (--num12 != 0); } else { Array.Copy(s.window, num14, s.window, write, num12); write += num12; num14 += num12; num12 = 0; } goto Label_06B8; } if ((num3 & 0x40) == 0) { num += numArray[index + 2]; num += bitb & inflate_mask[num3]; index = (num2 + num) * 3; num3 = numArray[index]; } else { z.Message = "invalid distance code"; num12 = z.AvailableBytesIn - availableBytesIn; num12 = ((bitk >> 3) < num12) ? (bitk >> 3) : num12; availableBytesIn += num12; nextIn -= num12; bitk -= num12 << 3; s.bitb = bitb; s.bitk = bitk; z.AvailableBytesIn = availableBytesIn; z.TotalBytesIn += nextIn - z.NextIn; z.NextIn = nextIn; s.write = write; return(-3); } flag = true; } } if ((num3 & 0x40) == 0) { num += numArray[index + 2]; num += bitb & inflate_mask[num3]; index = (num2 + num) * 3; num3 = numArray[index]; if (num3 == 0) { bitb = bitb >> numArray[index + 1]; bitk -= numArray[index + 1]; s.window[write++] = (byte)numArray[index + 2]; num9--; break; } } else { if ((num3 & 0x20) != 0) { num12 = z.AvailableBytesIn - availableBytesIn; num12 = ((bitk >> 3) < num12) ? (bitk >> 3) : num12; availableBytesIn += num12; nextIn -= num12; bitk -= num12 << 3; s.bitb = bitb; s.bitk = bitk; z.AvailableBytesIn = availableBytesIn; z.TotalBytesIn += nextIn - z.NextIn; z.NextIn = nextIn; s.write = write; return(1); } z.Message = "invalid literal/length code"; num12 = z.AvailableBytesIn - availableBytesIn; num12 = ((bitk >> 3) < num12) ? (bitk >> 3) : num12; availableBytesIn += num12; nextIn -= num12; bitk -= num12 << 3; s.bitb = bitb; s.bitk = bitk; z.AvailableBytesIn = availableBytesIn; z.TotalBytesIn += nextIn - z.NextIn; z.NextIn = nextIn; s.write = write; return(-3); } flag = true; } } Label_06B8: if ((num9 >= 0x102) && (availableBytesIn >= 10)) { goto Label_0096; } num12 = z.AvailableBytesIn - availableBytesIn; num12 = ((bitk >> 3) < num12) ? (bitk >> 3) : num12; availableBytesIn += num12; nextIn -= num12; bitk -= num12 << 3; s.bitb = bitb; s.bitk = bitk; z.AvailableBytesIn = availableBytesIn; z.TotalBytesIn += nextIn - z.NextIn; z.NextIn = nextIn; s.write = write; return(0); }
internal int End(ZlibCodec z) { if (blocks != null) blocks.Free(z); blocks = null; // ZFREE(z, z->state); return ZlibConstants.Z_OK; }
internal int Process(InflateBlocks blocks, int r) { int j; // temporary storage int tindex; // temporary pointer int e; // extra bits or operation int b = 0; // bit buffer int k = 0; // bits in bit buffer int p = 0; // input data pointer int n; // bytes available there int q; // output window write pointer int m; // bytes to end of window or read pointer int f; // pointer to copy strings from ZlibCodec z = blocks._codec; // copy input/output information to locals (UPDATE macro restores) p = z.NextIn; n = z.AvailableBytesIn; b = blocks.bitb; k = blocks.bitk; q = blocks.writeAt; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.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) { blocks.bitb = b; blocks.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; r = InflateFast(lbits, dbits, ltree, ltree_index, dtree, dtree_index, blocks, z); p = z.NextIn; n = z.AvailableBytesIn; b = blocks.bitb; k = blocks.bitk; q = blocks.writeAt; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; if (r != ZlibConstants.Z_OK) { mode = (r == ZlibConstants.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 = ZlibConstants.Z_OK; } else { blocks.bitb = b; blocks.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return(blocks.Flush(r)); } n--; b |= (z.InputBuffer[p++] & 0xff) << k; k += 8; } tindex = (tree_index + (b & InternalInflateConstants.InflateMask[j])) * 3; b >>= (tree[tindex + 1]); k -= (tree[tindex + 1]); e = tree[tindex]; if (e == 0) { // literal lit = tree[tindex + 2]; mode = LIT; break; } if ((e & 16) != 0) { // length bitsToGet = 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.Message = "invalid literal/length code"; r = ZlibConstants.Z_DATA_ERROR; blocks.bitb = b; blocks.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return(blocks.Flush(r)); case LENEXT: // i: getting length extra (have base) j = bitsToGet; while (k < j) { if (n != 0) { r = ZlibConstants.Z_OK; } else { blocks.bitb = b; blocks.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return(blocks.Flush(r)); } n--; b |= (z.InputBuffer[p++] & 0xff) << k; k += 8; } len += (b & InternalInflateConstants.InflateMask[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 = ZlibConstants.Z_OK; } else { blocks.bitb = b; blocks.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return(blocks.Flush(r)); } n--; b |= (z.InputBuffer[p++] & 0xff) << k; k += 8; } tindex = (tree_index + (b & InternalInflateConstants.InflateMask[j])) * 3; b >>= tree[tindex + 1]; k -= tree[tindex + 1]; e = (tree[tindex]); if ((e & 0x10) != 0) { // distance bitsToGet = 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.Message = "invalid distance code"; r = ZlibConstants.Z_DATA_ERROR; blocks.bitb = b; blocks.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return(blocks.Flush(r)); case DISTEXT: // i: getting distance extra j = bitsToGet; while (k < j) { if (n != 0) { r = ZlibConstants.Z_OK; } else { blocks.bitb = b; blocks.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return(blocks.Flush(r)); } n--; b |= (z.InputBuffer[p++] & 0xff) << k; k += 8; } dist += (b & InternalInflateConstants.InflateMask[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 += blocks.end; // of "if" handles invalid distances } while (len != 0) { if (m == 0) { if (q == blocks.end && blocks.readAt != 0) { q = 0; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; } if (m == 0) { blocks.writeAt = q; r = blocks.Flush(r); q = blocks.writeAt; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; if (q == blocks.end && blocks.readAt != 0) { q = 0; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; } if (m == 0) { blocks.bitb = b; blocks.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return(blocks.Flush(r)); } } } blocks.window[q++] = blocks.window[f++]; m--; if (f == blocks.end) { f = 0; } len--; } mode = START; break; case LIT: // o: got literal, waiting for output space if (m == 0) { if (q == blocks.end && blocks.readAt != 0) { q = 0; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; } if (m == 0) { blocks.writeAt = q; r = blocks.Flush(r); q = blocks.writeAt; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; if (q == blocks.end && blocks.readAt != 0) { q = 0; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; } if (m == 0) { blocks.bitb = b; blocks.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return(blocks.Flush(r)); } } } r = ZlibConstants.Z_OK; blocks.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 } blocks.writeAt = q; r = blocks.Flush(r); q = blocks.writeAt; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; if (blocks.readAt != blocks.writeAt) { blocks.bitb = b; blocks.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return(blocks.Flush(r)); } mode = END; goto case END; case END: r = ZlibConstants.Z_STREAM_END; blocks.bitb = b; blocks.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return(blocks.Flush(r)); case BADCODE: // x: got error r = ZlibConstants.Z_DATA_ERROR; blocks.bitb = b; blocks.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return(blocks.Flush(r)); default: r = ZlibConstants.Z_STREAM_ERROR; blocks.bitb = b; blocks.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return(blocks.Flush(r)); } } }
// Called with number of bytes left to write in window at least 258 // (the maximum string length) and number of input bytes available // at least ten. The ten bytes are six bytes for the longest length/ // distance pair plus four bytes for overloading the bit buffer. internal int InflateFast(int bl, int bd, int[] tl, int tl_index, int[] td, int td_index, InflateBlocks s) { int e; // extra bits or operation int c; // bytes to copy int nextIn = s._NextIn; // input data pointer int availIn = s._AvailIn; // bytes available there int bits = s.bitb; // bit buffer int bitsNum = s.bitk; // bits in bit buffer int q = s.writeAt; // output window write pointer int m = q < s.readAt ? s.readAt - q - 1 : s.end - q; // bytes to end of window or read pointer int ml = Constants.InflateMask[bl]; // mask for literal/length tree int md = Constants.InflateMask[bd]; // mask for distance tree // do until not enough input or output space for fast loop do { // assume called with m >= 258 && n >= 10 // get literal/length code while (bitsNum < 20) { // max bits for literal/length code availIn--; bits |= s.InputBuffer[nextIn++] << bitsNum; bitsNum += 8; } int t = bits & ml; // temporary pointer int[] tp = tl; // temporary pointer int tp_index = tl_index; // temporary pointer int tp_index_t_3 = (tp_index + t) * 3; if ((e = tp[tp_index_t_3]) == 0) { bits >>= tp[tp_index_t_3 + 1]; bitsNum -= tp[tp_index_t_3 + 1]; s.window[q++] = (byte)tp[tp_index_t_3 + 2]; m--; continue; } do { bits >>= tp[tp_index_t_3 + 1]; bitsNum -= tp[tp_index_t_3 + 1]; if ((e & 16) != 0) { e &= 15; c = tp[tp_index_t_3 + 2] + (bits & Constants.InflateMask[e]); bits >>= e; bitsNum -= e; // decode distance base of block to copy while (bitsNum < 15) { // max bits for distance code availIn--; bits |= s.InputBuffer[nextIn++] << bitsNum; bitsNum += 8; } t = bits & md; tp = td; tp_index = td_index; tp_index_t_3 = (tp_index + t) * 3; e = tp[tp_index_t_3]; do { bits >>= (tp[tp_index_t_3 + 1]); bitsNum -= (tp[tp_index_t_3 + 1]); if ((e & 16) != 0) { // get extra bits to add to distance base e &= 15; while (bitsNum < e) { // get extra bits (up to 13) availIn--; bits |= s.InputBuffer[nextIn++] << bitsNum; bitsNum += 8; } int d = tp[tp_index_t_3 + 2] + (bits & Constants.InflateMask[e]); // distance back to copy from bits >>= e; bitsNum -= e; // do the copy int r = q - d; // copy source pointer m -= c; if (q >= d) { // offset before dest, just copy if (q - r > 0 && 2 > (q - r)) { s.window[q++] = s.window[r++]; // minimum count is three, s.window[q++] = s.window[r++]; // so unroll loop a little } else { Array.Copy(s.window, r, s.window, q, 2); q += 2; r += 2; } c -= 2; } else { // else offset after destination do { r += s.end; // force pointer in window } while (r < 0); // covers invalid distances e = s.end - r; if (c > e) { // if source crosses, c -= e; // wrapped copy if (q - r > 0 && e > (q - r)) { do { s.window[q++] = s.window[r++]; } while (--e != 0); } else { Array.Copy(s.window, r, s.window, q, e); q += e; r += e; e = 0; } r = 0; // copy rest from start of window } } // copy all or what's left if (q - r > 0 && c > (q - r)) { do { s.window[q++] = s.window[r++]; } while (--c != 0); } else { Array.Copy(s.window, r, s.window, q, c); q += c; r += c; c = 0; } break; } else if ((e & 64) == 0) { t += tp[tp_index_t_3 + 2]; t += (bits & Constants.InflateMask[e]); tp_index_t_3 = (tp_index + t) * 3; e = tp[tp_index_t_3]; } else { throw new InvalidDataException("invalid distance code"); } } while (true); break; } if ((e & 64) == 0) { t += tp[tp_index_t_3 + 2]; t += (bits & Constants.InflateMask[e]); tp_index_t_3 = (tp_index + t) * 3; if ((e = tp[tp_index_t_3]) == 0) { bits >>= (tp[tp_index_t_3 + 1]); bitsNum -= (tp[tp_index_t_3 + 1]); s.window[q++] = (byte)tp[tp_index_t_3 + 2]; m--; break; } } else if ((e & 32) != 0) { c = s._AvailIn - availIn; c = (bitsNum >> 3) < c ? bitsNum >> 3 : c; availIn += c; nextIn -= c; bitsNum -= (c << 3); s.UpdateState(bits, bitsNum, availIn, nextIn, q); return(RCode.StreamEnd); } else { throw new InvalidDataException("invalid literal/length code"); } } while (true); } while (m >= 258 && availIn >= 10); // not enough input or output--restore pointers and return c = s._AvailIn - availIn; c = (bitsNum >> 3) < c ? bitsNum >> 3 : c; availIn += c; nextIn -= c; bitsNum -= (c << 3); s.UpdateState(bits, bitsNum, availIn, nextIn, q); return(RCode.Okay); }
ZlibCodec _codec; // pointer back to this zlib stream #endregion Fields #region Methods internal void End() { if (blocks != null) blocks.Free(); blocks = null; }
internal int Process(InflateBlocks blocks, int r) { int num = 0; int num2 = 0; int num3 = 0; ZlibCodec codec = blocks._codec; num3 = codec.NextIn; int num4 = codec.AvailableBytesIn; num = blocks.bitb; num2 = blocks.bitk; int num5 = blocks.writeAt; int num6 = (num5 >= blocks.readAt) ? (blocks.end - num5) : (blocks.readAt - num5 - 1); while (true) { switch (mode) { case 0: if (num6 >= 258 && num4 >= 10) { blocks.bitb = num; blocks.bitk = num2; codec.AvailableBytesIn = num4; codec.TotalBytesIn += num3 - codec.NextIn; codec.NextIn = num3; blocks.writeAt = num5; r = InflateFast(lbits, dbits, ltree, ltree_index, dtree, dtree_index, blocks, codec); num3 = codec.NextIn; num4 = codec.AvailableBytesIn; num = blocks.bitb; num2 = blocks.bitk; num5 = blocks.writeAt; num6 = ((num5 >= blocks.readAt) ? (blocks.end - num5) : (blocks.readAt - num5 - 1)); if (r != 0) { mode = ((r != 1) ? 9 : 7); break; } } need = lbits; tree = ltree; tree_index = ltree_index; mode = 1; goto case 1; case 1: { int num8; for (num8 = need; num2 < num8; num2 += 8) { if (num4 == 0) { blocks.bitb = num; blocks.bitk = num2; codec.AvailableBytesIn = num4; codec.TotalBytesIn += num3 - codec.NextIn; codec.NextIn = num3; blocks.writeAt = num5; return(blocks.Flush(r)); } r = 0; num4--; num |= (codec.InputBuffer[num3++] & 0xFF) << num2; } int num11 = (tree_index + (num & InternalInflateConstants.InflateMask[num8])) * 3; num >>= tree[num11 + 1]; num2 -= tree[num11 + 1]; int num12 = tree[num11]; if (num12 == 0) { lit = tree[num11 + 2]; mode = 6; } else if ((num12 & 0x10) != 0) { bitsToGet = (num12 & 0xF); len = tree[num11 + 2]; mode = 2; } else if ((num12 & 0x40) == 0) { need = num12; tree_index = num11 / 3 + tree[num11 + 2]; } else { if ((num12 & 0x20) == 0) { mode = 9; codec.Message = "invalid literal/length code"; r = -3; blocks.bitb = num; blocks.bitk = num2; codec.AvailableBytesIn = num4; codec.TotalBytesIn += num3 - codec.NextIn; codec.NextIn = num3; blocks.writeAt = num5; return(blocks.Flush(r)); } mode = 7; } break; } case 2: { int num8; for (num8 = bitsToGet; num2 < num8; num2 += 8) { if (num4 == 0) { blocks.bitb = num; blocks.bitk = num2; codec.AvailableBytesIn = num4; codec.TotalBytesIn += num3 - codec.NextIn; codec.NextIn = num3; blocks.writeAt = num5; return(blocks.Flush(r)); } r = 0; num4--; num |= (codec.InputBuffer[num3++] & 0xFF) << num2; } len += (num & InternalInflateConstants.InflateMask[num8]); num >>= num8; num2 -= num8; need = dbits; tree = dtree; tree_index = dtree_index; mode = 3; goto case 3; } case 3: { int num8; for (num8 = need; num2 < num8; num2 += 8) { if (num4 == 0) { blocks.bitb = num; blocks.bitk = num2; codec.AvailableBytesIn = num4; codec.TotalBytesIn += num3 - codec.NextIn; codec.NextIn = num3; blocks.writeAt = num5; return(blocks.Flush(r)); } r = 0; num4--; num |= (codec.InputBuffer[num3++] & 0xFF) << num2; } int num11 = (tree_index + (num & InternalInflateConstants.InflateMask[num8])) * 3; num >>= tree[num11 + 1]; num2 -= tree[num11 + 1]; int num12 = tree[num11]; if ((num12 & 0x10) != 0) { bitsToGet = (num12 & 0xF); dist = tree[num11 + 2]; mode = 4; } else { if ((num12 & 0x40) != 0) { mode = 9; codec.Message = "invalid distance code"; r = -3; blocks.bitb = num; blocks.bitk = num2; codec.AvailableBytesIn = num4; codec.TotalBytesIn += num3 - codec.NextIn; codec.NextIn = num3; blocks.writeAt = num5; return(blocks.Flush(r)); } need = num12; tree_index = num11 / 3 + tree[num11 + 2]; } break; } case 4: { int num8; for (num8 = bitsToGet; num2 < num8; num2 += 8) { if (num4 == 0) { blocks.bitb = num; blocks.bitk = num2; codec.AvailableBytesIn = num4; codec.TotalBytesIn += num3 - codec.NextIn; codec.NextIn = num3; blocks.writeAt = num5; return(blocks.Flush(r)); } r = 0; num4--; num |= (codec.InputBuffer[num3++] & 0xFF) << num2; } dist += (num & InternalInflateConstants.InflateMask[num8]); num >>= num8; num2 -= num8; mode = 5; goto case 5; } case 5: { int i; for (i = num5 - dist; i < 0; i += blocks.end) { } while (len != 0) { if (num6 == 0) { if (num5 == blocks.end && blocks.readAt != 0) { num5 = 0; num6 = ((num5 >= blocks.readAt) ? (blocks.end - num5) : (blocks.readAt - num5 - 1)); } if (num6 == 0) { blocks.writeAt = num5; r = blocks.Flush(r); num5 = blocks.writeAt; num6 = ((num5 >= blocks.readAt) ? (blocks.end - num5) : (blocks.readAt - num5 - 1)); if (num5 == blocks.end && blocks.readAt != 0) { num5 = 0; num6 = ((num5 >= blocks.readAt) ? (blocks.end - num5) : (blocks.readAt - num5 - 1)); } if (num6 == 0) { blocks.bitb = num; blocks.bitk = num2; codec.AvailableBytesIn = num4; codec.TotalBytesIn += num3 - codec.NextIn; codec.NextIn = num3; blocks.writeAt = num5; return(blocks.Flush(r)); } } } blocks.window[num5++] = blocks.window[i++]; num6--; if (i == blocks.end) { i = 0; } len--; } mode = 0; break; } case 6: if (num6 == 0) { if (num5 == blocks.end && blocks.readAt != 0) { num5 = 0; num6 = ((num5 >= blocks.readAt) ? (blocks.end - num5) : (blocks.readAt - num5 - 1)); } if (num6 == 0) { blocks.writeAt = num5; r = blocks.Flush(r); num5 = blocks.writeAt; num6 = ((num5 >= blocks.readAt) ? (blocks.end - num5) : (blocks.readAt - num5 - 1)); if (num5 == blocks.end && blocks.readAt != 0) { num5 = 0; num6 = ((num5 >= blocks.readAt) ? (blocks.end - num5) : (blocks.readAt - num5 - 1)); } if (num6 == 0) { blocks.bitb = num; blocks.bitk = num2; codec.AvailableBytesIn = num4; codec.TotalBytesIn += num3 - codec.NextIn; codec.NextIn = num3; blocks.writeAt = num5; return(blocks.Flush(r)); } } } r = 0; blocks.window[num5++] = (byte)lit; num6--; mode = 0; break; case 7: if (num2 > 7) { num2 -= 8; num4++; num3--; } blocks.writeAt = num5; r = blocks.Flush(r); num5 = blocks.writeAt; num6 = ((num5 >= blocks.readAt) ? (blocks.end - num5) : (blocks.readAt - num5 - 1)); if (blocks.readAt != blocks.writeAt) { blocks.bitb = num; blocks.bitk = num2; codec.AvailableBytesIn = num4; codec.TotalBytesIn += num3 - codec.NextIn; codec.NextIn = num3; blocks.writeAt = num5; return(blocks.Flush(r)); } mode = 8; goto case 8; case 8: r = 1; blocks.bitb = num; blocks.bitk = num2; codec.AvailableBytesIn = num4; codec.TotalBytesIn += num3 - codec.NextIn; codec.NextIn = num3; blocks.writeAt = num5; return(blocks.Flush(r)); case 9: r = -3; blocks.bitb = num; blocks.bitk = num2; codec.AvailableBytesIn = num4; codec.TotalBytesIn += num3 - codec.NextIn; codec.NextIn = num3; blocks.writeAt = num5; return(blocks.Flush(r)); default: r = -2; blocks.bitb = num; blocks.bitk = num2; codec.AvailableBytesIn = num4; codec.TotalBytesIn += num3 - codec.NextIn; codec.NextIn = num3; blocks.writeAt = num5; return(blocks.Flush(r)); } } }
// Called with number of bytes left to write in window at least 258 // (the maximum string length) and number of input bytes available // at least ten. The ten bytes are six bytes for the longest length/ // distance pair plus four bytes for overloading the bit buffer. internal int InflateFast(int bl, int bd, int[] tl, int tl_index, int[] td, int td_index, InflateBlocks s, ZlibCodec z) { int e; // extra bits or operation int c; // bytes to copy int nextIn = z.NextIn; // input data pointer int availIn = z.AvailableBytesIn; // bytes available there int bits = s.bitb; // bit buffer int bitsNum = s.bitk; // bits in bit buffer int q = s.writeAt; // output window write pointer int m = q < s.readAt ? s.readAt - q - 1 : s.end - q; // bytes to end of window or read pointer int ml = Constants.InflateMask[bl]; // mask for literal/length tree int md = Constants.InflateMask[bd]; // mask for distance tree // do until not enough input or output space for fast loop do { // assume called with m >= 258 && n >= 10 // get literal/length code while (bitsNum < 20) { // max bits for literal/length code availIn--; bits |= z.InputBuffer[nextIn++] << bitsNum; bitsNum += 8; } int t = bits & ml; // temporary pointer int[] tp = tl;// temporary pointer int tp_index = tl_index;// temporary pointer int tp_index_t_3 = (tp_index + t) * 3; if ((e = tp[tp_index_t_3]) == 0) { bits >>= tp[tp_index_t_3 + 1]; bitsNum -= tp[tp_index_t_3 + 1]; s.window[q++] = (byte)tp[tp_index_t_3 + 2]; m--; continue; } do { bits >>= tp[tp_index_t_3 + 1]; bitsNum -= tp[tp_index_t_3 + 1]; if ((e & 16) != 0) { e &= 15; c = tp[tp_index_t_3 + 2] + (bits & Constants.InflateMask[e]); bits >>= e; bitsNum -= e; // decode distance base of block to copy while (bitsNum < 15) { // max bits for distance code availIn--; bits |= z.InputBuffer[nextIn++] << bitsNum; bitsNum += 8; } t = bits & md; tp = td; tp_index = td_index; tp_index_t_3 = (tp_index + t) * 3; e = tp[tp_index_t_3]; do { bits >>= (tp[tp_index_t_3 + 1]); bitsNum -= (tp[tp_index_t_3 + 1]); if ((e & 16) != 0) { // get extra bits to add to distance base e &= 15; while (bitsNum < e) { // get extra bits (up to 13) availIn--; bits |= z.InputBuffer[nextIn++] << bitsNum; bitsNum += 8; } int d = tp[tp_index_t_3 + 2] + (bits & Constants.InflateMask[e]); // distance back to copy from bits >>= e; bitsNum -= e; // do the copy int r = q - d; // copy source pointer m -= c; if (q >= d) { // offset before dest, just copy if (q - r > 0 && 2 > (q - r)) { s.window[q++] = s.window[r++]; // minimum count is three, s.window[q++] = s.window[r++]; // so unroll loop a little } else { Array.Copy(s.window, r, s.window, q, 2); q += 2; r += 2; } c -= 2; } else { // else offset after destination do { r += s.end; // force pointer in window } while (r < 0); // covers invalid distances e = s.end - r; if (c > e) { // if source crosses, c -= e; // wrapped copy if (q - r > 0 && e > (q - r)) { do { s.window[q++] = s.window[r++]; } while (--e != 0); } else { Array.Copy(s.window, r, s.window, q, e); q += e; r += e; e = 0; } r = 0; // copy rest from start of window } } // copy all or what's left if( q - r > 0 && c > ( q - r ) ) { do { s.window[q++] = s.window[r++]; } while ( --c != 0 ); } else { Array.Copy( s.window, r, s.window, q, c ); q += c; r += c; c = 0; } break; } else if ( ( e & 64 ) == 0 ) { t += tp[tp_index_t_3 + 2]; t += (bits & Constants.InflateMask[e]); tp_index_t_3 = (tp_index + t) * 3; e = tp[tp_index_t_3]; } else { throw new InvalidDataException( "invalid distance code" ); } } while (true); break; } if ( ( e & 64 ) == 0 ) { t += tp[tp_index_t_3 + 2]; t += (bits & Constants.InflateMask[e]); tp_index_t_3 = (tp_index + t) * 3; if ((e = tp[tp_index_t_3]) == 0) { bits >>= (tp[tp_index_t_3 + 1]); bitsNum -= (tp[tp_index_t_3 + 1]); s.window[q++] = (byte)tp[tp_index_t_3 + 2]; m--; break; } } else if ( ( e & 32 ) != 0 ) { c = z.AvailableBytesIn - availIn; c = (bitsNum >> 3) < c ? bitsNum >> 3 : c; availIn += c; nextIn -= c; bitsNum -= (c << 3); s.UpdateState( bits, bitsNum, availIn, nextIn, q ); return RCode.StreamEnd; } else { throw new InvalidDataException( "invalid literal/length code" ); } } while (true); } while (m >= 258 && availIn >= 10); // not enough input or output--restore pointers and return c = z.AvailableBytesIn - availIn; c = (bitsNum >> 3) < c ? bitsNum >> 3 : c; availIn += c; nextIn -= c; bitsNum -= (c << 3); s.UpdateState( bits, bitsNum, availIn, nextIn, q ); return RCode.Okay; }
internal int Process(InflateBlocks blocks, int r) { int b = 0; int j = 0; int p = 0; ZlibCodec z = blocks._codec; p = z.NextIn; int l = z.AvailableBytesIn; b = blocks.bitb; j = blocks.bitk; int q = blocks.writeAt; int k = ((q < blocks.readAt) ? (blocks.readAt - q - 1) : (blocks.end - q)); while (true) { switch (mode) { case 0: if (k >= 258 && l >= 10) { blocks.bitb = b; blocks.bitk = j; z.AvailableBytesIn = l; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; r = InflateFast(lbits, dbits, ltree, ltree_index, dtree, dtree_index, blocks, z); p = z.NextIn; l = z.AvailableBytesIn; b = blocks.bitb; j = blocks.bitk; q = blocks.writeAt; k = ((q < blocks.readAt) ? (blocks.readAt - q - 1) : (blocks.end - q)); if (r != 0) { mode = ((r == 1) ? 7 : 9); break; } } need = lbits; tree = ltree; tree_index = ltree_index; mode = 1; goto case 1; case 1: { int i; for (i = need; j < i; j += 8) { if (l != 0) { r = 0; l--; b |= (z.InputBuffer[p++] & 0xFF) << j; continue; } blocks.bitb = b; blocks.bitk = j; z.AvailableBytesIn = l; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return(blocks.Flush(r)); } int tindex = (tree_index + (b & InternalInflateConstants.InflateMask[i])) * 3; b >>= tree[tindex + 1]; j -= tree[tindex + 1]; int e = tree[tindex]; if (e == 0) { lit = tree[tindex + 2]; mode = 6; break; } if (((uint)e & 0x10u) != 0) { bitsToGet = e & 0xF; len = tree[tindex + 2]; mode = 2; break; } if ((e & 0x40) == 0) { need = e; tree_index = tindex / 3 + tree[tindex + 2]; break; } if (((uint)e & 0x20u) != 0) { mode = 7; break; } mode = 9; z.Message = "invalid literal/length code"; r = -3; blocks.bitb = b; blocks.bitk = j; z.AvailableBytesIn = l; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return(blocks.Flush(r)); } case 2: { int i; for (i = bitsToGet; j < i; j += 8) { if (l != 0) { r = 0; l--; b |= (z.InputBuffer[p++] & 0xFF) << j; continue; } blocks.bitb = b; blocks.bitk = j; z.AvailableBytesIn = l; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return(blocks.Flush(r)); } len += b & InternalInflateConstants.InflateMask[i]; b >>= i; j -= i; need = dbits; tree = dtree; tree_index = dtree_index; mode = 3; goto case 3; } case 3: { int i; for (i = need; j < i; j += 8) { if (l != 0) { r = 0; l--; b |= (z.InputBuffer[p++] & 0xFF) << j; continue; } blocks.bitb = b; blocks.bitk = j; z.AvailableBytesIn = l; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return(blocks.Flush(r)); } int tindex = (tree_index + (b & InternalInflateConstants.InflateMask[i])) * 3; b >>= tree[tindex + 1]; j -= tree[tindex + 1]; int e = tree[tindex]; if (((uint)e & 0x10u) != 0) { bitsToGet = e & 0xF; dist = tree[tindex + 2]; mode = 4; break; } if ((e & 0x40) == 0) { need = e; tree_index = tindex / 3 + tree[tindex + 2]; break; } mode = 9; z.Message = "invalid distance code"; r = -3; blocks.bitb = b; blocks.bitk = j; z.AvailableBytesIn = l; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return(blocks.Flush(r)); } case 4: { int i; for (i = bitsToGet; j < i; j += 8) { if (l != 0) { r = 0; l--; b |= (z.InputBuffer[p++] & 0xFF) << j; continue; } blocks.bitb = b; blocks.bitk = j; z.AvailableBytesIn = l; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return(blocks.Flush(r)); } dist += b & InternalInflateConstants.InflateMask[i]; b >>= i; j -= i; mode = 5; goto case 5; } case 5: { int f; for (f = q - dist; f < 0; f += blocks.end) { } while (len != 0) { if (k == 0) { if (q == blocks.end && blocks.readAt != 0) { q = 0; k = ((q < blocks.readAt) ? (blocks.readAt - q - 1) : (blocks.end - q)); } if (k == 0) { blocks.writeAt = q; r = blocks.Flush(r); q = blocks.writeAt; k = ((q < blocks.readAt) ? (blocks.readAt - q - 1) : (blocks.end - q)); if (q == blocks.end && blocks.readAt != 0) { q = 0; k = ((q < blocks.readAt) ? (blocks.readAt - q - 1) : (blocks.end - q)); } if (k == 0) { blocks.bitb = b; blocks.bitk = j; z.AvailableBytesIn = l; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return(blocks.Flush(r)); } } } blocks.window[q++] = blocks.window[f++]; k--; if (f == blocks.end) { f = 0; } len--; } mode = 0; break; } case 6: if (k == 0) { if (q == blocks.end && blocks.readAt != 0) { q = 0; k = ((q < blocks.readAt) ? (blocks.readAt - q - 1) : (blocks.end - q)); } if (k == 0) { blocks.writeAt = q; r = blocks.Flush(r); q = blocks.writeAt; k = ((q < blocks.readAt) ? (blocks.readAt - q - 1) : (blocks.end - q)); if (q == blocks.end && blocks.readAt != 0) { q = 0; k = ((q < blocks.readAt) ? (blocks.readAt - q - 1) : (blocks.end - q)); } if (k == 0) { blocks.bitb = b; blocks.bitk = j; z.AvailableBytesIn = l; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return(blocks.Flush(r)); } } } r = 0; blocks.window[q++] = (byte)lit; k--; mode = 0; break; case 7: if (j > 7) { j -= 8; l++; p--; } blocks.writeAt = q; r = blocks.Flush(r); q = blocks.writeAt; k = ((q < blocks.readAt) ? (blocks.readAt - q - 1) : (blocks.end - q)); if (blocks.readAt != blocks.writeAt) { blocks.bitb = b; blocks.bitk = j; z.AvailableBytesIn = l; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return(blocks.Flush(r)); } mode = 8; goto case 8; case 8: r = 1; blocks.bitb = b; blocks.bitk = j; z.AvailableBytesIn = l; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return(blocks.Flush(r)); case 9: r = -3; blocks.bitb = b; blocks.bitk = j; z.AvailableBytesIn = l; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return(blocks.Flush(r)); default: r = -2; blocks.bitb = b; blocks.bitk = j; z.AvailableBytesIn = l; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return(blocks.Flush(r)); } } }
internal int Process(InflateBlocks blocks, int r) { int tindex; // temporary pointer int e; // extra bits or operation ZlibCodec z = blocks.codec; int nextIn = z.NextIn;// input data pointer int availIn = z.AvailableBytesIn; // bytes available there int bits = blocks.bitb; // bit buffer int bitsNum = blocks.bitk; // bits in bit buffer int q = blocks.writeAt; // output window write pointer int m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; // bytes to end of window or read pointer // 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 && availIn >= 10) { blocks.UpdateState( bits, bitsNum, availIn, nextIn, q ); r = InflateFast(lbits, dbits, ltree, ltree_index, dtree, dtree_index, blocks, z); nextIn = z.NextIn; availIn = z.AvailableBytesIn; bits = blocks.bitb; bitsNum = blocks.bitk; q = blocks.writeAt; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; if (r != RCode.Okay) { mode = (r == RCode.StreamEnd) ? WASH : BADCODE; break; } } need = lbits; tree = ltree; tree_index = ltree_index; mode = LEN; goto case LEN; case LEN: // i: get length/literal/eob next while (bitsNum < need) { if (availIn != 0) { r = RCode.Okay; } else { return blocks.RanOutOfInput( bits, bitsNum, availIn, nextIn, q, r ); } availIn--; bits |= z.InputBuffer[nextIn++] << bitsNum; bitsNum += 8; } tindex = (tree_index + (bits & Constants.InflateMask[need])) * 3; bits >>= (tree[tindex + 1]); bitsNum -= (tree[tindex + 1]); e = tree[tindex]; if (e == 0) { // literal lit = tree[tindex + 2]; mode = LIT; break; } if ((e & 16) != 0) { // length bitsToGet = 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; } throw new InvalidDataException( "invalid literal/length code" ); case LENEXT: // i: getting length extra (have base) while (bitsNum < bitsToGet) { if (availIn != 0) { r = RCode.Okay; } else { return blocks.RanOutOfInput( bits, bitsNum, availIn, nextIn, q, r ); } availIn--; bits |= z.InputBuffer[nextIn++] << bitsNum; bitsNum += 8; } len += (bits & Constants.InflateMask[bitsToGet]); bits >>= bitsToGet; bitsNum -= bitsToGet; need = dbits; tree = dtree; tree_index = dtree_index; mode = DIST; goto case DIST; case DIST: // i: get distance next while (bitsNum < need) { if (availIn != 0) { r = RCode.Okay; } else { return blocks.RanOutOfInput( bits, bitsNum, availIn, nextIn, q, r ); } availIn--; bits |= z.InputBuffer[nextIn++] << bitsNum; bitsNum += 8; } tindex = (tree_index + (bits & Constants.InflateMask[need])) * 3; bits >>= tree[tindex + 1]; bitsNum -= tree[tindex + 1]; e = tree[tindex]; if ((e & 0x10) != 0) { // distance bitsToGet = 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; } throw new InvalidDataException( "invalid distance code" ); case DISTEXT: // i: getting distance extra while (bitsNum < bitsToGet) { if (availIn != 0) { r = RCode.Okay; } else { return blocks.RanOutOfInput( bits, bitsNum, availIn, nextIn, q, r ); } availIn--; bits |= z.InputBuffer[nextIn++] << bitsNum; bitsNum += 8; } dist += (bits & Constants.InflateMask[bitsToGet]); bits >>= bitsToGet; bitsNum -= bitsToGet; mode = COPY; goto case COPY; case COPY: // o: copying bytes in window, waiting for space int f = q - dist; // pointer to copy strings from while (f < 0) { // modulo window size-"while" instead f += blocks.end; // of "if" handles invalid distances } while (len != 0) { if (m == 0) { if (q == blocks.end && blocks.readAt != 0) { q = 0; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; } if (m == 0) { blocks.writeAt = q; r = blocks.Flush(r); q = blocks.writeAt; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; if (q == blocks.end && blocks.readAt != 0) { q = 0; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; } if (m == 0) { return blocks.RanOutOfInput( bits, bitsNum, availIn, nextIn, q, r ); } } } blocks.window[q++] = blocks.window[f++]; m--; if (f == blocks.end) f = 0; len--; } mode = START; break; case LIT: // o: got literal, waiting for output space if (m == 0) { if (q == blocks.end && blocks.readAt != 0) { q = 0; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; } if (m == 0) { blocks.writeAt = q; r = blocks.Flush(r); q = blocks.writeAt; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; if (q == blocks.end && blocks.readAt != 0) { q = 0; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; } if (m == 0) { return blocks.RanOutOfInput( bits, bitsNum, availIn, nextIn, q, r ); } } } r = RCode.Okay; blocks.window[q++] = (byte)lit; m--; mode = START; break; case WASH: // o: got eob, possibly more output if (bitsNum > 7) { // return unused byte, if any bitsNum -= 8; availIn++; nextIn--; // can always return one } blocks.writeAt = q; r = blocks.Flush(r); q = blocks.writeAt; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; if (blocks.readAt != blocks.writeAt) { return blocks.RanOutOfInput( bits, bitsNum, availIn, nextIn, q, r ); } mode = END; goto case END; case END: r = RCode.StreamEnd; return blocks.RanOutOfInput( bits, bitsNum, availIn, nextIn, q, r ); default: throw new InvalidDataException( "Encountered error: " + mode ); } } }
internal int Process(InflateBlocks blocks, int r) { int j; // temporary storage int tindex; // temporary pointer int e; // extra bits or operation int b = 0; // bit buffer int k = 0; // bits in bit buffer int p = 0; // input data pointer int n; // bytes available there int q; // output window write pointer int m; // bytes to end of window or read pointer int f; // pointer to copy strings from ZlibCodec z = blocks._codec; // copy input/output information to locals (UPDATE macro restores) p = z.NextIn; n = z.AvailableBytesIn; b = blocks.bitb; k = blocks.bitk; q = blocks.writeAt; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.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) { blocks.bitb = b; blocks.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; r = InflateFast(lbits, dbits, ltree, ltree_index, dtree, dtree_index, blocks, z); p = z.NextIn; n = z.AvailableBytesIn; b = blocks.bitb; k = blocks.bitk; q = blocks.writeAt; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; if (r != ZlibConstants.Z_OK) { mode = (r == ZlibConstants.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 = ZlibConstants.Z_OK; else { blocks.bitb = b; blocks.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return blocks.Flush(r); } n--; b |= (z.InputBuffer[p++] & 0xff) << k; k += 8; } tindex = (tree_index + (b & InternalInflateConstants.InflateMask[j])) * 3; b >>= (tree[tindex + 1]); k -= (tree[tindex + 1]); e = tree[tindex]; if (e == 0) { // literal lit = tree[tindex + 2]; mode = LIT; break; } if ((e & 16) != 0) { // length bitsToGet = 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.Message = "invalid literal/length code"; r = ZlibConstants.Z_DATA_ERROR; blocks.bitb = b; blocks.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return blocks.Flush(r); case LENEXT: // i: getting length extra (have base) j = bitsToGet; while (k < j) { if (n != 0) r = ZlibConstants.Z_OK; else { blocks.bitb = b; blocks.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return blocks.Flush(r); } n--; b |= (z.InputBuffer[p++] & 0xff) << k; k += 8; } len += (b & InternalInflateConstants.InflateMask[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 = ZlibConstants.Z_OK; else { blocks.bitb = b; blocks.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return blocks.Flush(r); } n--; b |= (z.InputBuffer[p++] & 0xff) << k; k += 8; } tindex = (tree_index + (b & InternalInflateConstants.InflateMask[j])) * 3; b >>= tree[tindex + 1]; k -= tree[tindex + 1]; e = (tree[tindex]); if ((e & 0x10) != 0) { // distance bitsToGet = 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.Message = "invalid distance code"; r = ZlibConstants.Z_DATA_ERROR; blocks.bitb = b; blocks.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return blocks.Flush(r); case DISTEXT: // i: getting distance extra j = bitsToGet; while (k < j) { if (n != 0) r = ZlibConstants.Z_OK; else { blocks.bitb = b; blocks.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return blocks.Flush(r); } n--; b |= (z.InputBuffer[p++] & 0xff) << k; k += 8; } dist += (b & InternalInflateConstants.InflateMask[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 += blocks.end; // of "if" handles invalid distances } while (len != 0) { if (m == 0) { if (q == blocks.end && blocks.readAt != 0) { q = 0; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; } if (m == 0) { blocks.writeAt = q; r = blocks.Flush(r); q = blocks.writeAt; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; if (q == blocks.end && blocks.readAt != 0) { q = 0; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; } if (m == 0) { blocks.bitb = b; blocks.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return blocks.Flush(r); } } } blocks.window[q++] = blocks.window[f++]; m--; if (f == blocks.end) f = 0; len--; } mode = START; break; case LIT: // o: got literal, waiting for output space if (m == 0) { if (q == blocks.end && blocks.readAt != 0) { q = 0; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; } if (m == 0) { blocks.writeAt = q; r = blocks.Flush(r); q = blocks.writeAt; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; if (q == blocks.end && blocks.readAt != 0) { q = 0; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; } if (m == 0) { blocks.bitb = b; blocks.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return blocks.Flush(r); } } } r = ZlibConstants.Z_OK; blocks.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 } blocks.writeAt = q; r = blocks.Flush(r); q = blocks.writeAt; m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; if (blocks.readAt != blocks.writeAt) { blocks.bitb = b; blocks.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return blocks.Flush(r); } mode = END; goto case END; case END: r = ZlibConstants.Z_STREAM_END; blocks.bitb = b; blocks.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return blocks.Flush(r); case BADCODE: // x: got error r = ZlibConstants.Z_DATA_ERROR; blocks.bitb = b; blocks.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return blocks.Flush(r); default: r = ZlibConstants.Z_STREAM_ERROR; blocks.bitb = b; blocks.bitk = k; z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; return blocks.Flush(r); } } }
public DeflateStream(Stream stream) { _stream = stream; workBuffer = new byte[16384]; // TODO: 1024 bytes? z = new InflateBlocks(); }