/// <summary> /// Creates a new inflater. /// </summary> /// <param name="noHeader"> /// True if no RFC1950/Zlib header and footer fields are expected in the input data /// /// This is used for GZIPed/Zipped input. /// /// For compatibility with /// Sun JDK you should provide one byte of input more than needed in /// this case. /// </param> public Inflater(bool noHeader) { this.noHeader = noHeader; this.adler = new Adler32(); input = new StreamManipulator(); outputWindow = new OutputWindow(); dynHeader = new InflaterDynHeader(); mode = noHeader ? DECODE_BLOCKS : DECODE_HEADER; }
/// <summary> /// Resets the inflater so that a new stream can be decompressed. All /// pending input and output will be discarded. /// </summary> public void Reset() { mode = noHeader ? DECODE_BLOCKS : DECODE_HEADER; totalIn = totalOut = 0; input.Reset(); outputWindow.Reset(); dynHeader = null; litlenTree = null; distTree = null; isLastBlock = false; adler.Reset(); }
public void Reset() { this.mode = this.noHeader ? 2 : 0; this.totalIn = this.totalOut = 0; this.input.Reset(); this.outputWindow.Reset(); this.dynHeader = null; this.litlenTree = null; this.distTree = null; this.isLastBlock = false; this.adler.Reset(); }
public void Reset() { mode = (noHeader ? 2 : 0); totalIn = 0L; totalOut = 0L; input.Reset(); outputWindow.Reset(); dynHeader = null; litlenTree = null; distTree = null; isLastBlock = false; adler.Reset(); }
/// <summary> /// Decodes the deflated stream. /// </summary> /// <returns> /// false if more input is needed, or if finished. /// </returns> /// <exception cref="SharpZipBaseException"> /// if deflated stream is invalid. /// </exception> private bool Decode() { switch (mode) { case DECODE_HEADER: return(DecodeHeader()); case DECODE_DICT: return(DecodeDict()); case DECODE_CHKSUM: return(DecodeChksum()); case DECODE_BLOCKS: if (isLastBlock) { if (noHeader) { mode = FINISHED; return(false); } else { input.SkipToByteBoundary(); neededBits = 32; mode = DECODE_CHKSUM; return(true); } } int type = input.PeekBits(3); if (type < 0) { return(false); } input.DropBits(3); isLastBlock |= (type & 1) != 0; switch (type >> 1) { case DeflaterConstants.STORED_BLOCK: input.SkipToByteBoundary(); mode = DECODE_STORED_LEN1; break; case DeflaterConstants.STATIC_TREES: litlenTree = InflaterHuffmanTree.defLitLenTree; distTree = InflaterHuffmanTree.defDistTree; mode = DECODE_HUFFMAN; break; case DeflaterConstants.DYN_TREES: dynHeader = new InflaterDynHeader(input); mode = DECODE_DYN_HEADER; break; default: throw new SharpZipBaseException("Unknown block type " + type); } return(true); case DECODE_STORED_LEN1: { if ((uncomprLen = input.PeekBits(16)) < 0) { return(false); } input.DropBits(16); mode = DECODE_STORED_LEN2; } goto case DECODE_STORED_LEN2; // fall through case DECODE_STORED_LEN2: { int nlen = input.PeekBits(16); if (nlen < 0) { return(false); } input.DropBits(16); if (nlen != (uncomprLen ^ 0xffff)) { throw new SharpZipBaseException("broken uncompressed block"); } mode = DECODE_STORED; } goto case DECODE_STORED; // fall through case DECODE_STORED: { int more = outputWindow.CopyStored(input, uncomprLen); uncomprLen -= more; if (uncomprLen == 0) { mode = DECODE_BLOCKS; return(true); } return(!input.IsNeedingInput); } case DECODE_DYN_HEADER: if (!dynHeader.AttemptRead()) { return(false); } litlenTree = dynHeader.LiteralLengthTree; distTree = dynHeader.DistanceTree; mode = DECODE_HUFFMAN; goto case DECODE_HUFFMAN; // fall through case DECODE_HUFFMAN: case DECODE_HUFFMAN_LENBITS: case DECODE_HUFFMAN_DIST: case DECODE_HUFFMAN_DISTBITS: return(DecodeHuffman()); case FINISHED: return(false); default: throw new SharpZipBaseException("Inflater.Decode unknown mode"); } }
private bool Decode() { switch (mode) { case 0: return(DecodeHeader()); case 1: return(DecodeDict()); case 11: return(DecodeChksum()); case 2: { if (isLastBlock) { if (noHeader) { mode = 12; return(false); } input.SkipToByteBoundary(); neededBits = 32; mode = 11; return(true); } int num = input.PeekBits(3); if (num < 0) { return(false); } input.DropBits(3); if (((uint)num & (true ? 1u : 0u)) != 0) { isLastBlock = true; } switch (num >> 1) { case 0: input.SkipToByteBoundary(); mode = 3; break; case 1: litlenTree = InflaterHuffmanTree.defLitLenTree; distTree = InflaterHuffmanTree.defDistTree; mode = 7; break; case 2: dynHeader = new InflaterDynHeader(); mode = 6; break; default: throw new SharpZipBaseException(string.Concat((object)"Unknown block type ", (object)num)); } return(true); } case 3: if ((uncomprLen = input.PeekBits(16)) < 0) { return(false); } input.DropBits(16); mode = 4; goto case 4; case 4: { int num3 = input.PeekBits(16); if (num3 < 0) { return(false); } input.DropBits(16); if (num3 != (uncomprLen ^ 0xFFFF)) { throw new SharpZipBaseException("broken uncompressed block"); } mode = 5; goto case 5; } case 5: { int num2 = outputWindow.CopyStored(input, uncomprLen); uncomprLen -= num2; if (uncomprLen == 0) { mode = 2; return(true); } return(!input.IsNeedingInput); } case 6: if (!dynHeader.Decode(input)) { return(false); } litlenTree = dynHeader.BuildLitLenTree(); distTree = dynHeader.BuildDistTree(); mode = 7; goto case 7; case 7: case 8: case 9: case 10: return(DecodeHuffman()); case 12: return(false); default: throw new SharpZipBaseException("Inflater.Decode unknown mode"); } }
/// <summary> /// Decodes the deflated stream. /// </summary> /// <returns> /// false if more input is needed, or if finished. /// </returns> /// <exception cref="SharpZipBaseException"> /// if deflated stream is invalid. /// </exception> private bool Decode() { switch (mode) { case DECODE_HEADER: return DecodeHeader(); case DECODE_DICT: return DecodeDict(); case DECODE_CHKSUM: return DecodeChksum(); case DECODE_BLOCKS: if (isLastBlock) { if (noHeader) { mode = FINISHED; return false; } else { input.SkipToByteBoundary(); neededBits = 32; mode = DECODE_CHKSUM; return true; } } int type = input.PeekBits(3); if (type < 0) { return false; } input.DropBits(3); if ((type & 1) != 0) { isLastBlock = true; } switch (type >> 1){ case DeflaterConstants.STORED_BLOCK: input.SkipToByteBoundary(); mode = DECODE_STORED_LEN1; break; case DeflaterConstants.STATIC_TREES: litlenTree = InflaterHuffmanTree.defLitLenTree; distTree = InflaterHuffmanTree.defDistTree; mode = DECODE_HUFFMAN; break; case DeflaterConstants.DYN_TREES: dynHeader = new InflaterDynHeader(); mode = DECODE_DYN_HEADER; break; default: throw new SharpZipBaseException("Unknown block type " + type); } return true; case DECODE_STORED_LEN1: { if ((uncomprLen = input.PeekBits(16)) < 0) { return false; } input.DropBits(16); mode = DECODE_STORED_LEN2; } goto case DECODE_STORED_LEN2; // fall through case DECODE_STORED_LEN2: { int nlen = input.PeekBits(16); if (nlen < 0) { return false; } input.DropBits(16); if (nlen != (uncomprLen ^ 0xffff)) { throw new SharpZipBaseException("broken uncompressed block"); } mode = DECODE_STORED; } goto case DECODE_STORED; // fall through case DECODE_STORED: { int more = outputWindow.CopyStored(input, uncomprLen); uncomprLen -= more; if (uncomprLen == 0) { mode = DECODE_BLOCKS; return true; } return !input.IsNeedingInput; } case DECODE_DYN_HEADER: if (!dynHeader.Decode(input)) { return false; } litlenTree = dynHeader.BuildLitLenTree(); distTree = dynHeader.BuildDistTree(); mode = DECODE_HUFFMAN; goto case DECODE_HUFFMAN; // fall through case DECODE_HUFFMAN: case DECODE_HUFFMAN_LENBITS: case DECODE_HUFFMAN_DIST: case DECODE_HUFFMAN_DISTBITS: return DecodeHuffman(); case FINISHED: return false; default: throw new SharpZipBaseException("Inflater.Decode unknown mode"); } }
/// <summary> /// Resets the inflater so that a new stream can be decompressed. All /// pending input and output will be discarded. /// </summary> public void Reset() { mode = noHeader ? DECODE_BLOCKS : DECODE_HEADER; totalIn = 0; totalOut = 0; input.Reset(); outputWindow.Reset(); dynHeader = null; litlenTree = null; distTree = null; isLastBlock = false; adler.Reset(); }
private bool Decode() { switch (this.mode) { case 0: return(this.DecodeHeader()); case 1: return(this.DecodeDict()); case 2: if (this.isLastBlock) { if (this.noHeader) { this.mode = 12; return(false); } this.input.SkipToByteBoundary(); this.neededBits = 32; this.mode = 11; return(true); } else { int num = this.input.PeekBits(3); if (num < 0) { return(false); } this.input.DropBits(3); if ((num & 1) != 0) { this.isLastBlock = true; } switch (num >> 1) { case 0: this.input.SkipToByteBoundary(); this.mode = 3; break; case 1: this.litlenTree = InflaterHuffmanTree.defLitLenTree; this.distTree = InflaterHuffmanTree.defDistTree; this.mode = 7; break; case 2: this.dynHeader = new InflaterDynHeader(); this.mode = 6; break; default: throw new SharpZipBaseException("Unknown block type " + num); } return(true); } break; case 3: if ((this.uncomprLen = this.input.PeekBits(16)) < 0) { return(false); } this.input.DropBits(16); this.mode = 4; break; case 4: break; case 5: goto IL_1D4; case 6: if (!this.dynHeader.Decode(this.input)) { return(false); } this.litlenTree = this.dynHeader.BuildLitLenTree(); this.distTree = this.dynHeader.BuildDistTree(); this.mode = 7; goto IL_263; case 7: case 8: case 9: case 10: goto IL_263; case 11: return(this.DecodeChksum()); case 12: return(false); default: throw new SharpZipBaseException("Inflater.Decode unknown mode"); } int num2 = this.input.PeekBits(16); if (num2 < 0) { return(false); } this.input.DropBits(16); if (num2 != (this.uncomprLen ^ 65535)) { throw new SharpZipBaseException("broken uncompressed block"); } this.mode = 5; IL_1D4: int num3 = this.outputWindow.CopyStored(this.input, this.uncomprLen); this.uncomprLen -= num3; if (this.uncomprLen == 0) { this.mode = 2; return(true); } return(!this.input.IsNeedingInput); IL_263: return(this.DecodeHuffman()); }
private bool Decode() { int num2; int num3; switch (this.mode) { case 0: return(this.DecodeHeader()); case 1: return(this.DecodeDict()); case 2: if (!this.isLastBlock) { int num = this.input.PeekBits(3); if (num < 0) { return(false); } this.input.DropBits(3); if ((num & 1) != 0) { this.isLastBlock = true; } switch ((num >> 1)) { case 0: this.input.SkipToByteBoundary(); this.mode = 3; goto Label_0134; case 1: this.litlenTree = InflaterHuffmanTree.defLitLenTree; this.distTree = InflaterHuffmanTree.defDistTree; this.mode = 7; goto Label_0134; case 2: this.dynHeader = new InflaterDynHeader(); this.mode = 6; goto Label_0134; } throw new SharpZipBaseException("Unknown block type " + num); } if (!this.noHeader) { this.input.SkipToByteBoundary(); this.neededBits = 0x20; this.mode = 11; return(true); } this.mode = 12; return(false); case 3: this.uncomprLen = this.input.PeekBits(0x10); if (this.uncomprLen >= 0) { this.input.DropBits(0x10); this.mode = 4; goto Label_0167; } return(false); case 4: goto Label_0167; case 5: goto Label_01A9; case 6: if (this.dynHeader.Decode(this.input)) { this.litlenTree = this.dynHeader.BuildLitLenTree(); this.distTree = this.dynHeader.BuildDistTree(); this.mode = 7; goto Label_022D; } return(false); case 7: case 8: case 9: case 10: goto Label_022D; case 11: return(this.DecodeChksum()); case 12: return(false); default: throw new SharpZipBaseException("Inflater.Decode unknown mode"); } Label_0134: return(true); Label_0167: num2 = this.input.PeekBits(0x10); if (num2 < 0) { return(false); } this.input.DropBits(0x10); if (num2 != (this.uncomprLen ^ 0xffff)) { throw new SharpZipBaseException("broken uncompressed block"); } this.mode = 5; Label_01A9: num3 = this.outputWindow.CopyStored(this.input, this.uncomprLen); this.uncomprLen -= num3; if (this.uncomprLen == 0) { this.mode = 2; return(true); } return(!this.input.IsNeedingInput); Label_022D: return(this.DecodeHuffman()); }
/// <summary> /// Decodes the deflated stream. /// </summary> /// <returns> /// false if more input is needed, or if finished. /// </returns> /// <exception cref="SharpZipBaseException"> /// if deflated stream is invalid. /// </exception> private bool Decode() { switch (mode) { case DECODE_HEADER: return(DecodeHeader()); case DECODE_DICT: return(DecodeDict()); case DECODE_CHKSUM: return(DecodeChksum()); case DECODE_BLOCKS: if (isLastBlock) { if (noHeader) { mode = FINISHED; return(false); } else { input.SkipToByteBoundary(); neededBits = 32; mode = DECODE_CHKSUM; return(true); } } int blockType; if (!ReadHeader(ref isLastBlock, out blockType)) { return(false); } switch (blockType) { case STORED_BLOCK: input.SkipToByteBoundary(); mode = DECODE_STORED_LEN1; break; case STATIC_TREES: litlenTree = InflaterHuffmanTree.defLitLenTree; distTree = InflaterHuffmanTree.defDistTree; mode = DECODE_HUFFMAN; break; case DYN_TREES: dynHeader = new InflaterDynHeader(); mode = DECODE_DYN_HEADER; break; default: throw new SharpZipBaseException("Unknown block type " + blockType); } return(true); case DECODE_STORED_LEN1: if (!DecodeStoredLength()) { return(false); } mode = DECODE_STORED; goto case DECODE_STORED; // fall through case DECODE_STORED: { int more = outputWindow.CopyStored(input, uncomprLen); uncomprLen -= more; if (uncomprLen == 0) { mode = DECODE_BLOCKS; return(true); } return(!input.IsNeedingInput); } case DECODE_DYN_HEADER: if (!dynHeader.Decode(input)) { return(false); } litlenTree = dynHeader.BuildLitLenTree(); distTree = dynHeader.BuildDistTree(); mode = DECODE_HUFFMAN; goto case DECODE_HUFFMAN; // fall through case DECODE_HUFFMAN: case DECODE_HUFFMAN_LENBITS: case DECODE_HUFFMAN_DIST: case DECODE_HUFFMAN_DISTBITS: return(DecodeHuffman()); case FINISHED: return(false); default: throw new SharpZipBaseException("Inflater.Decode unknown mode"); } }
/// <summary> /// Decodes the deflated stream. /// </summary> /// <returns> /// false if more input is needed, or if finished. /// </returns> /// <exception cref="SharpZipBaseException"> /// if deflated stream is invalid. /// </exception> private bool Decode() { switch (mode) { case DECODE_HEADER: return DecodeHeader(); case DECODE_DICT: return DecodeDict(); case DECODE_CHKSUM: return DecodeChksum(); case DECODE_BLOCKS: if (isLastBlock) { if (noHeader) { mode = FINISHED; return false; } else { input.SkipToByteBoundary(); neededBits = 32; mode = DECODE_CHKSUM; return true; } } int blockType; if (!ReadHeader(ref isLastBlock, out blockType)) { return false; } switch (blockType){ case STORED_BLOCK: input.SkipToByteBoundary(); mode = DECODE_STORED_LEN1; break; case STATIC_TREES: litlenTree = InflaterHuffmanTree.defLitLenTree; distTree = InflaterHuffmanTree.defDistTree; mode = DECODE_HUFFMAN; break; case DYN_TREES: dynHeader = new InflaterDynHeader(); mode = DECODE_DYN_HEADER; break; default: throw new SharpZipBaseException("Unknown block type " + blockType); } return true; case DECODE_STORED_LEN1: if (!DecodeStoredLength()) { return false; } mode = DECODE_STORED; goto case DECODE_STORED; // fall through case DECODE_STORED: { int more = outputWindow.CopyStored(input, uncomprLen); uncomprLen -= more; if (uncomprLen == 0) { mode = DECODE_BLOCKS; return true; } return !input.IsNeedingInput; } case DECODE_DYN_HEADER: if (!dynHeader.Decode(input)) { return false; } litlenTree = dynHeader.BuildLitLenTree(); distTree = dynHeader.BuildDistTree(); mode = DECODE_HUFFMAN; goto case DECODE_HUFFMAN; // fall through case DECODE_HUFFMAN: case DECODE_HUFFMAN_LENBITS: case DECODE_HUFFMAN_DIST: case DECODE_HUFFMAN_DISTBITS: return DecodeHuffman(); case FINISHED: return false; default: throw new SharpZipBaseException("Inflater.Decode unknown mode"); } }
private bool Decode() { int num2; int num3; switch (this.mode) { case 0: return this.DecodeHeader(); case 1: return this.DecodeDict(); case 2: if (!this.isLastBlock) { int num = this.input.PeekBits(3); if (num < 0) { return false; } this.input.DropBits(3); if ((num & 1) != 0) { this.isLastBlock = true; } switch ((num >> 1)) { case 0: this.input.SkipToByteBoundary(); this.mode = 3; break; case 1: this.litlenTree = InflaterHuffmanTree.defLitLenTree; this.distTree = InflaterHuffmanTree.defDistTree; this.mode = 7; break; case 2: this.dynHeader = new InflaterDynHeader(); this.mode = 6; break; } throw new SharpZipBaseException("Unknown block type " + num); } if (!this.noHeader) { this.input.SkipToByteBoundary(); this.neededBits = 0x20; this.mode = 11; return true; } this.mode = 12; return false; case 3: this.uncomprLen = this.input.PeekBits(0x10); if (this.uncomprLen >= 0) { this.input.DropBits(0x10); this.mode = 4; goto Label_0167; } return false; case 4: goto Label_0167; case 5: goto Label_01A9; case 6: if (this.dynHeader.Decode(this.input)) { this.litlenTree = this.dynHeader.BuildLitLenTree(); this.distTree = this.dynHeader.BuildDistTree(); this.mode = 7; goto Label_022D; } return false; case 7: case 8: case 9: case 10: goto Label_022D; case 11: return this.DecodeChksum(); case 12: return false; default: throw new SharpZipBaseException("Inflater.Decode unknown mode"); } return true; Label_0167: num2 = this.input.PeekBits(0x10); if (num2 < 0) { return false; } this.input.DropBits(0x10); if (num2 != (this.uncomprLen ^ 0xffff)) { throw new SharpZipBaseException("broken uncompressed block"); } this.mode = 5; Label_01A9: num3 = this.outputWindow.CopyStored(this.input, this.uncomprLen); this.uncomprLen -= num3; if (this.uncomprLen == 0) { this.mode = 2; return true; } return !this.input.IsNeedingInput; Label_022D: return this.DecodeHuffman(); }
public void Reset() { this.mode = this.noHeader ? 2 : 0; this.totalIn = 0L; this.totalOut = 0L; this.input.Reset(); this.outputWindow.Reset(); this.dynHeader = null; this.litlenTree = null; this.distTree = null; this.isLastBlock = false; this.adler.Reset(); }