internal int Sync() { int n; // number of bytes to look at int p; // pointer to bytes int m; // number of marker bytes found in a row long r, w; // temporaries to save total_in and total_out // set up if (mode != InflateManagerMode.BAD) { mode = InflateManagerMode.BAD; marker = 0; } if ((n = _codec.AvailableBytesIn) == 0) { return(ZlibConstants.Z_BUF_ERROR); } p = _codec.NextIn; m = marker; // search while (n != 0 && m < 4) { if (_codec.InputBuffer[p] == mark[m]) { m++; } else if (_codec.InputBuffer[p] != 0) { m = 0; } else { m = 4 - m; } p++; n--; } // restore _codec.TotalBytesIn += p - _codec.NextIn; _codec.NextIn = p; _codec.AvailableBytesIn = n; marker = m; // return no joy or set up to restart on a new block if (m != 4) { return(ZlibConstants.Z_DATA_ERROR); } r = _codec.TotalBytesIn; w = _codec.TotalBytesOut; Reset(); _codec.TotalBytesIn = r; _codec.TotalBytesOut = w; mode = InflateManagerMode.BLOCKS; return(ZlibConstants.Z_OK); }
internal int Reset() { _codec.TotalBytesIn = _codec.TotalBytesOut = 0; _codec.Message = null; mode = HandleRfc1950HeaderBytes ? InflateManagerMode.METHOD : InflateManagerMode.BLOCKS; blocks.Reset(); return ZlibConstants.Z_OK; }
internal int Reset() { this._codec.TotalBytesIn = (this._codec.TotalBytesOut = 0L); this._codec.Message = null; this.mode = (InflateManagerMode)((!this.HandleRfc1950HeaderBytes) ? 7 : 0); this.blocks.Reset(); return(0); }
internal int Sync() { if (mode != InflateManagerMode.BAD) { mode = InflateManagerMode.BAD; marker = 0; } int j; if ((j = _codec.AvailableBytesIn) == 0) { return(-5); } int p = _codec.NextIn; int i = marker; while (j != 0 && i < 4) { i = ((_codec.InputBuffer[p] != mark[i]) ? ((_codec.InputBuffer[p] == 0) ? (4 - i) : 0) : (i + 1)); p++; j--; } _codec.TotalBytesIn += p - _codec.NextIn; _codec.NextIn = p; _codec.AvailableBytesIn = j; marker = i; if (i != 4) { return(-3); } long r = _codec.TotalBytesIn; long w = _codec.TotalBytesOut; Reset(); _codec.TotalBytesIn = r; _codec.TotalBytesOut = w; mode = InflateManagerMode.BLOCKS; return(0); }
internal int Sync() { int n; // number of bytes to look at int p; // pointer to bytes int m; // number of marker bytes found in a row long r, w; // temporaries to save total_in and total_out // set up if (mode != InflateManagerMode.BAD) { mode = InflateManagerMode.BAD; marker = 0; } if ((n = _codec.AvailableBytesIn) == 0) return ZlibConstants.Z_BUF_ERROR; p = _codec.NextIn; m = marker; // search while (n != 0 && m < 4) { if (_codec.InputBuffer[p] == mark[m]) { m++; } else if (_codec.InputBuffer[p] != 0) { m = 0; } else { m = 4 - m; } p++; n--; } // restore _codec.TotalBytesIn += p - _codec.NextIn; _codec.NextIn = p; _codec.AvailableBytesIn = n; marker = m; // return no joy or set up to restart on a new block if (m != 4) { return ZlibConstants.Z_DATA_ERROR; } r = _codec.TotalBytesIn; w = _codec.TotalBytesOut; Reset(); _codec.TotalBytesIn = r; _codec.TotalBytesOut = w; mode = InflateManagerMode.BLOCKS; return ZlibConstants.Z_OK; }
internal int SetDictionary(byte[] dictionary) { int index = 0; int length = dictionary.Length; if (mode != InflateManagerMode.DICT0) throw new ZlibException("Stream error."); if (Adler.Adler32(1, dictionary, 0, dictionary.Length) != _codec._Adler32) { return ZlibConstants.Z_DATA_ERROR; } _codec._Adler32 = Adler.Adler32(0, null, 0, 0); if (length >= (1 << wbits)) { length = (1 << wbits) - 1; index = dictionary.Length - length; } blocks.SetDictionary(dictionary, index, length); mode = InflateManagerMode.BLOCKS; return ZlibConstants.Z_OK; }
internal int Inflate(FlushType flush) { int b; if (_codec.InputBuffer == null) throw new ZlibException("InputBuffer is null. "); // int f = (flush == FlushType.Finish) // ? ZlibConstants.Z_BUF_ERROR // : ZlibConstants.Z_OK; // workitem 8870 int f = ZlibConstants.Z_OK; int r = ZlibConstants.Z_BUF_ERROR; while (true) { switch (mode) { case InflateManagerMode.METHOD: if (_codec.AvailableBytesIn == 0) return r; r = f; _codec.AvailableBytesIn--; _codec.TotalBytesIn++; if (((method = _codec.InputBuffer[_codec.NextIn++]) & 0xf) != Z_DEFLATED) { mode = InflateManagerMode.BAD; _codec.Message = String.Format("unknown compression method (0x{0:X2})", method); marker = 5; // can't try inflateSync break; } if ((method >> 4) + 8 > wbits) { mode = InflateManagerMode.BAD; _codec.Message = String.Format("invalid window size ({0})", (method >> 4) + 8); marker = 5; // can't try inflateSync break; } mode = InflateManagerMode.FLAG; break; case InflateManagerMode.FLAG: if (_codec.AvailableBytesIn == 0) return r; r = f; _codec.AvailableBytesIn--; _codec.TotalBytesIn++; b = (_codec.InputBuffer[_codec.NextIn++]) & 0xff; if ((((method << 8) + b) % 31) != 0) { mode = InflateManagerMode.BAD; _codec.Message = "incorrect header check"; marker = 5; // can't try inflateSync break; } mode = ((b & PRESET_DICT) == 0) ? InflateManagerMode.BLOCKS : InflateManagerMode.DICT4; break; case InflateManagerMode.DICT4: if (_codec.AvailableBytesIn == 0) return r; r = f; _codec.AvailableBytesIn--; _codec.TotalBytesIn++; expectedCheck = (uint)((_codec.InputBuffer[_codec.NextIn++] << 24) & 0xff000000); mode = InflateManagerMode.DICT3; break; case InflateManagerMode.DICT3: if (_codec.AvailableBytesIn == 0) return r; r = f; _codec.AvailableBytesIn--; _codec.TotalBytesIn++; expectedCheck += (uint)((_codec.InputBuffer[_codec.NextIn++] << 16) & 0x00ff0000); mode = InflateManagerMode.DICT2; break; case InflateManagerMode.DICT2: if (_codec.AvailableBytesIn == 0) return r; r = f; _codec.AvailableBytesIn--; _codec.TotalBytesIn++; expectedCheck += (uint)((_codec.InputBuffer[_codec.NextIn++] << 8) & 0x0000ff00); mode = InflateManagerMode.DICT1; break; case InflateManagerMode.DICT1: if (_codec.AvailableBytesIn == 0) return r; r = f; _codec.AvailableBytesIn--; _codec.TotalBytesIn++; expectedCheck += (uint)(_codec.InputBuffer[_codec.NextIn++] & 0x000000ff); _codec._Adler32 = expectedCheck; mode = InflateManagerMode.DICT0; return ZlibConstants.Z_NEED_DICT; case InflateManagerMode.DICT0: mode = InflateManagerMode.BAD; _codec.Message = "need dictionary"; marker = 0; // can try inflateSync return ZlibConstants.Z_STREAM_ERROR; case InflateManagerMode.BLOCKS: r = blocks.Process(r); if (r == ZlibConstants.Z_DATA_ERROR) { mode = InflateManagerMode.BAD; marker = 0; // can try inflateSync break; } if (r == ZlibConstants.Z_OK) r = f; if (r != ZlibConstants.Z_STREAM_END) return r; r = f; computedCheck = blocks.Reset(); if (!HandleRfc1950HeaderBytes) { mode = InflateManagerMode.DONE; return ZlibConstants.Z_STREAM_END; } mode = InflateManagerMode.CHECK4; break; case InflateManagerMode.CHECK4: if (_codec.AvailableBytesIn == 0) return r; r = f; _codec.AvailableBytesIn--; _codec.TotalBytesIn++; expectedCheck = (uint)((_codec.InputBuffer[_codec.NextIn++] << 24) & 0xff000000); mode = InflateManagerMode.CHECK3; break; case InflateManagerMode.CHECK3: if (_codec.AvailableBytesIn == 0) return r; r = f; _codec.AvailableBytesIn--; _codec.TotalBytesIn++; expectedCheck += (uint)((_codec.InputBuffer[_codec.NextIn++] << 16) & 0x00ff0000); mode = InflateManagerMode.CHECK2; break; case InflateManagerMode.CHECK2: if (_codec.AvailableBytesIn == 0) return r; r = f; _codec.AvailableBytesIn--; _codec.TotalBytesIn++; expectedCheck += (uint)((_codec.InputBuffer[_codec.NextIn++] << 8) & 0x0000ff00); mode = InflateManagerMode.CHECK1; break; case InflateManagerMode.CHECK1: if (_codec.AvailableBytesIn == 0) return r; r = f; _codec.AvailableBytesIn--; _codec.TotalBytesIn++; expectedCheck += (uint)(_codec.InputBuffer[_codec.NextIn++] & 0x000000ff); if (computedCheck != expectedCheck) { mode = InflateManagerMode.BAD; _codec.Message = "incorrect data check"; marker = 5; // can't try inflateSync break; } mode = InflateManagerMode.DONE; return ZlibConstants.Z_STREAM_END; case InflateManagerMode.DONE: return ZlibConstants.Z_STREAM_END; case InflateManagerMode.BAD: throw new ZlibException(String.Format("Bad state ({0})", _codec.Message)); default: throw new ZlibException("Stream error."); } } }
/// <returns> /// </returns> private int Reset() { this.codec.TotalBytesIn = this.codec.TotalBytesOut = 0; this.codec.Message = null; this.mode = this.HandleRfc1950HeaderBytes ? InflateManagerMode.Method : InflateManagerMode.Blocks; this.blocks.Reset(); return ZlibConstants.Zok; }
/// <returns></returns> <exception cref = "ZlibException"></exception><exception cref = "ZlibException"></exception><exception cref = "ZlibException"></exception> internal int Inflate() { if (this.codec.InputBuffer == null) { throw new ZlibException("InputBuffer is null. "); } // int f = (flush == FlushType.Finish) ? ZlibConstants.Z_BUF_ERROR : ZlibConstants.Z_OK; // workitem 8870 const int f = ZlibConstants.Zok; int r = ZlibConstants.ZBufError; while (true) { switch (this.mode) { case InflateManagerMode.Method: if (this.codec.AvailableBytesIn == 0) { return r; } r = f; this.codec.AvailableBytesIn--; this.codec.TotalBytesIn++; if (((this.method = this.codec.InputBuffer[this.codec.NextIn++]) & 0xf) != ZDeflated) { this.mode = InflateManagerMode.Bad; this.codec.Message = string.Format( CultureInfo.CurrentCulture, "unknown compression method (0x{0:X2})", this.method); break; } if ((this.method >> 4) + 8 > this.wbits) { this.mode = InflateManagerMode.Bad; this.codec.Message = string.Format( CultureInfo.CurrentCulture, "invalid window size ({0})", (this.method >> 4) + 8); break; } this.mode = InflateManagerMode.Flag; break; case InflateManagerMode.Flag: if (this.codec.AvailableBytesIn == 0) { return r; } r = f; this.codec.AvailableBytesIn--; this.codec.TotalBytesIn++; int b = this.codec.InputBuffer[this.codec.NextIn++] & 0xff; if ((((this.method << 8) + b) % 31) != 0) { this.mode = InflateManagerMode.Bad; this.codec.Message = "incorrect header check"; break; } this.mode = ((b & PresetDict) == 0) ? InflateManagerMode.Blocks : InflateManagerMode.DicT4; break; case InflateManagerMode.DicT4: if (this.codec.AvailableBytesIn == 0) { return r; } r = f; this.codec.AvailableBytesIn--; this.codec.TotalBytesIn++; this.expectedCheck = (uint)((this.codec.InputBuffer[this.codec.NextIn++] << 24) & 0xff000000); this.mode = InflateManagerMode.DicT3; break; case InflateManagerMode.DicT3: if (this.codec.AvailableBytesIn == 0) { return r; } r = f; this.codec.AvailableBytesIn--; this.codec.TotalBytesIn++; this.expectedCheck += (uint)((this.codec.InputBuffer[this.codec.NextIn++] << 16) & 0x00ff0000); this.mode = InflateManagerMode.DicT2; break; case InflateManagerMode.DicT2: if (this.codec.AvailableBytesIn == 0) { return r; } r = f; this.codec.AvailableBytesIn--; this.codec.TotalBytesIn++; this.expectedCheck += (uint)((this.codec.InputBuffer[this.codec.NextIn++] << 8) & 0x0000ff00); this.mode = InflateManagerMode.DicT1; break; case InflateManagerMode.DicT1: if (this.codec.AvailableBytesIn == 0) { return r; } this.codec.AvailableBytesIn--; this.codec.TotalBytesIn++; this.expectedCheck += (uint)(this.codec.InputBuffer[this.codec.NextIn++] & 0x000000ff); this.codec.Adler32 = this.expectedCheck; this.mode = InflateManagerMode.DicT0; return ZlibConstants.ZNeedDict; case InflateManagerMode.DicT0: this.mode = InflateManagerMode.Bad; this.codec.Message = "need dictionary"; return ZlibConstants.ZStreamError; case InflateManagerMode.Blocks: r = this.blocks.Process(r); if (r == ZlibConstants.ZDataError) { this.mode = InflateManagerMode.Bad; break; } if (r == ZlibConstants.Zok) { r = f; } if (r != ZlibConstants.ZStreamEnd) { return r; } r = f; this.computedCheck = this.blocks.Reset(); if (!this.HandleRfc1950HeaderBytes) { this.mode = InflateManagerMode.Done; return ZlibConstants.ZStreamEnd; } this.mode = InflateManagerMode.ChecK4; break; case InflateManagerMode.ChecK4: if (this.codec.AvailableBytesIn == 0) { return r; } r = f; this.codec.AvailableBytesIn--; this.codec.TotalBytesIn++; this.expectedCheck = (uint)((this.codec.InputBuffer[this.codec.NextIn++] << 24) & 0xff000000); this.mode = InflateManagerMode.ChecK3; break; case InflateManagerMode.ChecK3: if (this.codec.AvailableBytesIn == 0) { return r; } r = f; this.codec.AvailableBytesIn--; this.codec.TotalBytesIn++; this.expectedCheck += (uint)((this.codec.InputBuffer[this.codec.NextIn++] << 16) & 0x00ff0000); this.mode = InflateManagerMode.ChecK2; break; case InflateManagerMode.ChecK2: if (this.codec.AvailableBytesIn == 0) { return r; } r = f; this.codec.AvailableBytesIn--; this.codec.TotalBytesIn++; this.expectedCheck += (uint)((this.codec.InputBuffer[this.codec.NextIn++] << 8) & 0x0000ff00); this.mode = InflateManagerMode.ChecK1; break; case InflateManagerMode.ChecK1: if (this.codec.AvailableBytesIn == 0) { return r; } r = f; this.codec.AvailableBytesIn--; this.codec.TotalBytesIn++; this.expectedCheck += (uint)(this.codec.InputBuffer[this.codec.NextIn++] & 0x000000ff); if (this.computedCheck != this.expectedCheck) { this.mode = InflateManagerMode.Bad; this.codec.Message = "incorrect data check"; break; } this.mode = InflateManagerMode.Done; return ZlibConstants.ZStreamEnd; case InflateManagerMode.Done: return ZlibConstants.ZStreamEnd; case InflateManagerMode.Bad: throw new ZlibException( string.Format(CultureInfo.CurrentCulture, "Bad state ({0})", this.codec.Message)); default: throw new ZlibException("Stream error."); } } }
internal int Sync() { int n; int p; int m; long r, w; if ( mode != InflateManagerMode.BAD ) { mode = InflateManagerMode.BAD; marker = 0; } if ( ( n = _codec.AvailableBytesIn ) == 0 ) return ZlibConstants.Z_BUF_ERROR; p = _codec.NextIn; m = marker; while ( n != 0 && m < 4 ) { if ( _codec.InputBuffer [ p ] == mark [ m ] ) { m++; } else if ( _codec.InputBuffer [ p ] != 0 ) { m = 0; } else { m = 4 - m; } p++; n--; } _codec.TotalBytesIn += p - _codec.NextIn; _codec.NextIn = p; _codec.AvailableBytesIn = n; marker = m; if ( m != 4 ) { return ZlibConstants.Z_DATA_ERROR; } r = _codec.TotalBytesIn; w = _codec.TotalBytesOut; Reset (); _codec.TotalBytesIn = r; _codec.TotalBytesOut = w; mode = InflateManagerMode.BLOCKS; return ZlibConstants.Z_OK; }
/// <returns></returns> <exception cref = "ZlibException"></exception><exception cref = "ZlibException"></exception><exception cref = "ZlibException"></exception> internal int Inflate() { if (this.codec.InputBuffer == null) { throw new ZlibException("InputBuffer is null. "); } // int f = (flush == FlushType.Finish) ? ZlibConstants.Z_BUF_ERROR : ZlibConstants.Z_OK; // workitem 8870 const int f = ZlibConstants.Zok; int r = ZlibConstants.ZBufError; while (true) { switch (this.mode) { case InflateManagerMode.Method: if (this.codec.AvailableBytesIn == 0) { return(r); } r = f; this.codec.AvailableBytesIn--; this.codec.TotalBytesIn++; if (((this.method = this.codec.InputBuffer[this.codec.NextIn++]) & 0xf) != ZDeflated) { this.mode = InflateManagerMode.Bad; this.codec.Message = string.Format( CultureInfo.CurrentCulture, "unknown compression method (0x{0:X2})", this.method); break; } if ((this.method >> 4) + 8 > this.wbits) { this.mode = InflateManagerMode.Bad; this.codec.Message = string.Format( CultureInfo.CurrentCulture, "invalid window size ({0})", (this.method >> 4) + 8); break; } this.mode = InflateManagerMode.Flag; break; case InflateManagerMode.Flag: if (this.codec.AvailableBytesIn == 0) { return(r); } r = f; this.codec.AvailableBytesIn--; this.codec.TotalBytesIn++; int b = this.codec.InputBuffer[this.codec.NextIn++] & 0xff; if ((((this.method << 8) + b) % 31) != 0) { this.mode = InflateManagerMode.Bad; this.codec.Message = "incorrect header check"; break; } this.mode = ((b & PresetDict) == 0) ? InflateManagerMode.Blocks : InflateManagerMode.DicT4; break; case InflateManagerMode.DicT4: if (this.codec.AvailableBytesIn == 0) { return(r); } r = f; this.codec.AvailableBytesIn--; this.codec.TotalBytesIn++; this.expectedCheck = (uint)((this.codec.InputBuffer[this.codec.NextIn++] << 24) & 0xff000000); this.mode = InflateManagerMode.DicT3; break; case InflateManagerMode.DicT3: if (this.codec.AvailableBytesIn == 0) { return(r); } r = f; this.codec.AvailableBytesIn--; this.codec.TotalBytesIn++; this.expectedCheck += (uint)((this.codec.InputBuffer[this.codec.NextIn++] << 16) & 0x00ff0000); this.mode = InflateManagerMode.DicT2; break; case InflateManagerMode.DicT2: if (this.codec.AvailableBytesIn == 0) { return(r); } r = f; this.codec.AvailableBytesIn--; this.codec.TotalBytesIn++; this.expectedCheck += (uint)((this.codec.InputBuffer[this.codec.NextIn++] << 8) & 0x0000ff00); this.mode = InflateManagerMode.DicT1; break; case InflateManagerMode.DicT1: if (this.codec.AvailableBytesIn == 0) { return(r); } this.codec.AvailableBytesIn--; this.codec.TotalBytesIn++; this.expectedCheck += (uint)(this.codec.InputBuffer[this.codec.NextIn++] & 0x000000ff); this.codec.Adler32 = this.expectedCheck; this.mode = InflateManagerMode.DicT0; return(ZlibConstants.ZNeedDict); case InflateManagerMode.DicT0: this.mode = InflateManagerMode.Bad; this.codec.Message = "need dictionary"; return(ZlibConstants.ZStreamError); case InflateManagerMode.Blocks: r = this.blocks.Process(r); if (r == ZlibConstants.ZDataError) { this.mode = InflateManagerMode.Bad; break; } if (r == ZlibConstants.Zok) { r = f; } if (r != ZlibConstants.ZStreamEnd) { return(r); } r = f; this.computedCheck = this.blocks.Reset(); if (!this.HandleRfc1950HeaderBytes) { this.mode = InflateManagerMode.Done; return(ZlibConstants.ZStreamEnd); } this.mode = InflateManagerMode.ChecK4; break; case InflateManagerMode.ChecK4: if (this.codec.AvailableBytesIn == 0) { return(r); } r = f; this.codec.AvailableBytesIn--; this.codec.TotalBytesIn++; this.expectedCheck = (uint)((this.codec.InputBuffer[this.codec.NextIn++] << 24) & 0xff000000); this.mode = InflateManagerMode.ChecK3; break; case InflateManagerMode.ChecK3: if (this.codec.AvailableBytesIn == 0) { return(r); } r = f; this.codec.AvailableBytesIn--; this.codec.TotalBytesIn++; this.expectedCheck += (uint)((this.codec.InputBuffer[this.codec.NextIn++] << 16) & 0x00ff0000); this.mode = InflateManagerMode.ChecK2; break; case InflateManagerMode.ChecK2: if (this.codec.AvailableBytesIn == 0) { return(r); } r = f; this.codec.AvailableBytesIn--; this.codec.TotalBytesIn++; this.expectedCheck += (uint)((this.codec.InputBuffer[this.codec.NextIn++] << 8) & 0x0000ff00); this.mode = InflateManagerMode.ChecK1; break; case InflateManagerMode.ChecK1: if (this.codec.AvailableBytesIn == 0) { return(r); } r = f; this.codec.AvailableBytesIn--; this.codec.TotalBytesIn++; this.expectedCheck += (uint)(this.codec.InputBuffer[this.codec.NextIn++] & 0x000000ff); if (this.computedCheck != this.expectedCheck) { this.mode = InflateManagerMode.Bad; this.codec.Message = "incorrect data check"; break; } this.mode = InflateManagerMode.Done; return(ZlibConstants.ZStreamEnd); case InflateManagerMode.Done: return(ZlibConstants.ZStreamEnd); case InflateManagerMode.Bad: throw new ZlibException( string.Format(CultureInfo.CurrentCulture, "Bad state ({0})", this.codec.Message)); default: throw new ZlibException("Stream error."); } } }
internal int Inflate(FlushType flush) { if (this._codec.InputBuffer == null) { throw new ZlibException("InputBuffer is null. "); } int num = 0; int num2 = -5; while (true) { switch (this.mode) { case InflateManagerMode.METHOD: break; case InflateManagerMode.FLAG: goto IL_016a; case InflateManagerMode.DICT4: goto IL_0221; case InflateManagerMode.DICT3: goto IL_029e; case InflateManagerMode.DICT2: goto IL_031f; case InflateManagerMode.DICT1: goto IL_039f; case InflateManagerMode.DICT0: this.mode = InflateManagerMode.BAD; this._codec.Message = "need dictionary"; this.marker = 0; return(-2); case InflateManagerMode.BLOCKS: goto IL_044d; case InflateManagerMode.CHECK4: goto IL_04bb; case InflateManagerMode.CHECK3: goto IL_0539; case InflateManagerMode.CHECK2: goto IL_05bb; case InflateManagerMode.CHECK1: goto IL_063c; case InflateManagerMode.DONE: return(1); case InflateManagerMode.BAD: throw new ZlibException(string.Format("Bad state ({0})", this._codec.Message)); default: throw new ZlibException("Stream error."); } if (this._codec.AvailableBytesIn == 0) { return(num2); } num2 = num; this._codec.AvailableBytesIn--; this._codec.TotalBytesIn += 1L; if (((this.method = this._codec.InputBuffer[this._codec.NextIn++]) & 0xF) != 8) { this.mode = InflateManagerMode.BAD; this._codec.Message = string.Format("unknown compression method (0x{0:X2})", this.method); this.marker = 5; } else if ((this.method >> 4) + 8 > this.wbits) { this.mode = InflateManagerMode.BAD; this._codec.Message = string.Format("invalid window size ({0})", (this.method >> 4) + 8); this.marker = 5; } else { this.mode = InflateManagerMode.FLAG; } continue; IL_063c: if (this._codec.AvailableBytesIn == 0) { return(num2); } num2 = num; this._codec.AvailableBytesIn--; this._codec.TotalBytesIn += 1L; this.expectedCheck += (uint)(this._codec.InputBuffer[this._codec.NextIn++] & 0xFF); if (this.computedCheck == this.expectedCheck) { break; } this.mode = InflateManagerMode.BAD; this._codec.Message = "incorrect data check"; this.marker = 5; continue; IL_044d: num2 = this.blocks.Process(num2); switch (num2) { case -3: break; case 0: num2 = num; goto default; default: if (num2 != 1) { return(num2); } goto IL_0487; } this.mode = InflateManagerMode.BAD; this.marker = 0; continue; IL_039f: if (this._codec.AvailableBytesIn == 0) { return(num2); } num2 = num; this._codec.AvailableBytesIn--; this._codec.TotalBytesIn += 1L; this.expectedCheck += (uint)(this._codec.InputBuffer[this._codec.NextIn++] & 0xFF); this._codec._Adler32 = this.expectedCheck; this.mode = InflateManagerMode.DICT0; return(2); IL_016a: if (this._codec.AvailableBytesIn == 0) { return(num2); } num2 = num; this._codec.AvailableBytesIn--; this._codec.TotalBytesIn += 1L; int num3 = this._codec.InputBuffer[this._codec.NextIn++] & 0xFF; if (((this.method << 8) + num3) % 31 != 0) { this.mode = InflateManagerMode.BAD; this._codec.Message = "incorrect header check"; this.marker = 5; } else { this.mode = (InflateManagerMode)(((num3 & 0x20) != 0) ? 2 : 7); } continue; IL_05bb: if (this._codec.AvailableBytesIn == 0) { return(num2); } num2 = num; this._codec.AvailableBytesIn--; this._codec.TotalBytesIn += 1L; this.expectedCheck += (uint)(this._codec.InputBuffer[this._codec.NextIn++] << 8 & 65280); this.mode = InflateManagerMode.CHECK1; continue; IL_0221: if (this._codec.AvailableBytesIn == 0) { return(num2); } num2 = num; this._codec.AvailableBytesIn--; this._codec.TotalBytesIn += 1L; this.expectedCheck = (uint)(this._codec.InputBuffer[this._codec.NextIn++] << 24 & 4278190080u); this.mode = InflateManagerMode.DICT3; continue; IL_031f: if (this._codec.AvailableBytesIn == 0) { return(num2); } num2 = num; this._codec.AvailableBytesIn--; this._codec.TotalBytesIn += 1L; this.expectedCheck += (uint)(this._codec.InputBuffer[this._codec.NextIn++] << 8 & 65280); this.mode = InflateManagerMode.DICT1; continue; IL_0539: if (this._codec.AvailableBytesIn == 0) { return(num2); } num2 = num; this._codec.AvailableBytesIn--; this._codec.TotalBytesIn += 1L; this.expectedCheck += (uint)(this._codec.InputBuffer[this._codec.NextIn++] << 16 & 16711680); this.mode = InflateManagerMode.CHECK2; continue; IL_029e: if (this._codec.AvailableBytesIn == 0) { return(num2); } num2 = num; this._codec.AvailableBytesIn--; this._codec.TotalBytesIn += 1L; this.expectedCheck += (uint)(this._codec.InputBuffer[this._codec.NextIn++] << 16 & 16711680); this.mode = InflateManagerMode.DICT2; continue; IL_0487: num2 = num; this.computedCheck = this.blocks.Reset(); if (!this.HandleRfc1950HeaderBytes) { this.mode = InflateManagerMode.DONE; return(1); } this.mode = InflateManagerMode.CHECK4; continue; IL_04bb: if (this._codec.AvailableBytesIn == 0) { return(num2); } num2 = num; this._codec.AvailableBytesIn--; this._codec.TotalBytesIn += 1L; this.expectedCheck = (uint)(this._codec.InputBuffer[this._codec.NextIn++] << 24 & 4278190080u); this.mode = InflateManagerMode.CHECK3; } this.mode = InflateManagerMode.DONE; return(1); }
internal int Inflate(FlushType flush) { if (this._codec.InputBuffer == null) { throw new ZlibException("InputBuffer is null. "); } int num2 = 0; int r = -5; while (true) { int num4; InflateManagerMode mode = this.mode; switch (mode) { case InflateManagerMode.METHOD: { if (this._codec.AvailableBytesIn == 0) { return(r); } r = num2; this._codec.AvailableBytesIn--; this._codec.TotalBytesIn += 1L; this._codec.NextIn = (num4 = this._codec.NextIn) + 1; byte num1 = this._codec.InputBuffer[num4]; this.method = num4 = num1; if ((num4 & 15) != 8) { this.mode = InflateManagerMode.BAD; this._codec.Message = $"unknown compression method (0x{this.method:X2})"; this.marker = 5; continue; } if (((this.method >> 4) + 8) <= this.wbits) { this.mode = InflateManagerMode.FLAG; continue; } this.mode = InflateManagerMode.BAD; this._codec.Message = $"invalid window size ({(this.method >> 4) + 8})"; this.marker = 5; continue; } case InflateManagerMode.FLAG: { if (this._codec.AvailableBytesIn == 0) { return(r); } r = num2; this._codec.AvailableBytesIn--; this._codec.TotalBytesIn += 1L; this._codec.NextIn = (num4 = this._codec.NextIn) + 1; int num = this._codec.InputBuffer[num4] & 0xff; if ((((this.method << 8) + num) % 0x1f) == 0) { this.mode = ((num & 0x20) != 0) ? InflateManagerMode.DICT4 : InflateManagerMode.BLOCKS; continue; } this.mode = InflateManagerMode.BAD; this._codec.Message = "incorrect header check"; this.marker = 5; continue; } case InflateManagerMode.DICT4: { if (this._codec.AvailableBytesIn == 0) { return(r); } r = num2; this._codec.AvailableBytesIn--; this._codec.TotalBytesIn += 1L; this._codec.NextIn = (num4 = this._codec.NextIn) + 1; this.expectedCheck = (uint)((this._codec.InputBuffer[num4] << 0x18) & 0xff000000UL); this.mode = InflateManagerMode.DICT3; continue; } case InflateManagerMode.DICT3: { if (this._codec.AvailableBytesIn == 0) { return(r); } r = num2; this._codec.AvailableBytesIn--; this._codec.TotalBytesIn += 1L; this._codec.NextIn = (num4 = this._codec.NextIn) + 1; this.expectedCheck += (uint)((this._codec.InputBuffer[num4] << 0x10) & 0xff0000); this.mode = InflateManagerMode.DICT2; continue; } case InflateManagerMode.DICT2: { if (this._codec.AvailableBytesIn == 0) { return(r); } r = num2; this._codec.AvailableBytesIn--; this._codec.TotalBytesIn += 1L; this._codec.NextIn = (num4 = this._codec.NextIn) + 1; this.expectedCheck += (uint)((this._codec.InputBuffer[num4] << 8) & 0xff00); this.mode = InflateManagerMode.DICT1; continue; } case InflateManagerMode.DICT1: if (this._codec.AvailableBytesIn == 0) { return(r); } r = num2; this._codec.AvailableBytesIn--; this._codec.TotalBytesIn += 1L; this._codec.NextIn = (num4 = this._codec.NextIn) + 1; this.expectedCheck += (uint)(this._codec.InputBuffer[num4] & 0xff); this._codec._Adler32 = this.expectedCheck; this.mode = InflateManagerMode.DICT0; return(2); case InflateManagerMode.DICT0: this.mode = InflateManagerMode.BAD; this._codec.Message = "need dictionary"; this.marker = 0; return(-2); case InflateManagerMode.BLOCKS: { r = this.blocks.Process(r); if (r == -3) { this.mode = InflateManagerMode.BAD; this.marker = 0; continue; } r ??= num2; if (r != 1) { return(r); } r = num2; this.computedCheck = this.blocks.Reset(); if (!this.HandleRfc1950HeaderBytes) { this.mode = InflateManagerMode.DONE; return(1); } this.mode = InflateManagerMode.CHECK4; continue; } case InflateManagerMode.CHECK4: { if (this._codec.AvailableBytesIn == 0) { return(r); } r = num2; this._codec.AvailableBytesIn--; this._codec.TotalBytesIn += 1L; this._codec.NextIn = (num4 = this._codec.NextIn) + 1; this.expectedCheck = (uint)((this._codec.InputBuffer[num4] << 0x18) & 0xff000000UL); this.mode = InflateManagerMode.CHECK3; continue; } case InflateManagerMode.CHECK3: { if (this._codec.AvailableBytesIn == 0) { return(r); } r = num2; this._codec.AvailableBytesIn--; this._codec.TotalBytesIn += 1L; this._codec.NextIn = (num4 = this._codec.NextIn) + 1; this.expectedCheck += (uint)((this._codec.InputBuffer[num4] << 0x10) & 0xff0000); this.mode = InflateManagerMode.CHECK2; continue; } case InflateManagerMode.CHECK2: { if (this._codec.AvailableBytesIn == 0) { return(r); } r = num2; this._codec.AvailableBytesIn--; this._codec.TotalBytesIn += 1L; this._codec.NextIn = (num4 = this._codec.NextIn) + 1; this.expectedCheck += (uint)((this._codec.InputBuffer[num4] << 8) & 0xff00); this.mode = InflateManagerMode.CHECK1; continue; } case InflateManagerMode.CHECK1: { if (this._codec.AvailableBytesIn == 0) { return(r); } r = num2; this._codec.AvailableBytesIn--; this._codec.TotalBytesIn += 1L; this._codec.NextIn = (num4 = this._codec.NextIn) + 1; this.expectedCheck += (uint)(this._codec.InputBuffer[num4] & 0xff); if (this.computedCheck == this.expectedCheck) { this.mode = InflateManagerMode.DONE; return(1); } this.mode = InflateManagerMode.BAD; this._codec.Message = "incorrect data check"; this.marker = 5; continue; } case InflateManagerMode.DONE: return(1); case InflateManagerMode.BAD: throw new ZlibException($"Bad state ({this._codec.Message})"); } throw new ZlibException("Stream error."); } }