static InflaterHuffmanTree() { try { byte[] codeLengths = new byte[0x120]; int num = 0; while (num < 0x90) { codeLengths[num++] = 8; } while (num < 0x100) { codeLengths[num++] = 9; } while (num < 280) { codeLengths[num++] = 7; } while (num < 0x120) { codeLengths[num++] = 8; } defLitLenTree = new InflaterHuffmanTree(codeLengths); codeLengths = new byte[0x20]; num = 0; while (num < 0x20) { codeLengths[num++] = 5; } defDistTree = new InflaterHuffmanTree(codeLengths); } catch (Exception) { throw new ApplicationException("InflaterHuffmanTree: static tree length illegal"); } }
private bool DecodeHuffman() { int freeSpace = this.outputWindow.GetFreeSpace(); while (freeSpace >= 0x102) { int num2; switch (this.mode) { case 7: goto Label_0059; case 8: goto Label_00DB; case 9: goto Label_0132; case 10: goto Label_017A; default: throw new FormatException(); } Label_0039: this.outputWindow.Write(num2); if (--freeSpace < 0x102) { return true; } Label_0059: if (((num2 = this.litlenTree.GetSymbol(this.input)) & -256) == 0) { goto Label_0039; } if (num2 < 0x101) { if (num2 < 0) { return false; } this.distTree = null; this.litlenTree = null; this.mode = 2; return true; } try { this.repLength = CPLENS[num2 - 0x101]; this.neededBits = CPLEXT[num2 - 0x101]; } catch (Exception) { throw new FormatException("Illegal rep length code"); } Label_00DB: if (this.neededBits > 0) { this.mode = 8; int num3 = this.input.PeekBits(this.neededBits); if (num3 < 0) { return false; } this.input.DropBits(this.neededBits); this.repLength += num3; } this.mode = 9; Label_0132: num2 = this.distTree.GetSymbol(this.input); if (num2 < 0) { return false; } try { this.repDist = CPDIST[num2]; this.neededBits = CPDEXT[num2]; } catch (Exception) { throw new FormatException("Illegal rep dist code"); } Label_017A: if (this.neededBits > 0) { this.mode = 10; int num4 = this.input.PeekBits(this.neededBits); if (num4 < 0) { return false; } this.input.DropBits(this.neededBits); this.repDist += num4; } this.outputWindow.Repeat(this.repLength, this.repDist); freeSpace -= this.repLength; this.mode = 7; } return true; }
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 FormatException("Unknown block type " + num); } if (!this.nowrap) { 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_0193; } return false; case 4: goto Label_0193; case 5: goto Label_01DC; case 6: if (this.dynHeader.Decode(this.input)) { this.litlenTree = this.dynHeader.BuildLitLenTree(); this.distTree = this.dynHeader.BuildDistTree(); this.mode = 7; goto Label_0268; } return false; case 7: case 8: case 9: case 10: goto Label_0268; case 11: return this.DecodeChksum(); case 12: return false; default: throw new FormatException(); } return true; Label_0193: num2 = this.input.PeekBits(0x10); if (num2 < 0) { return false; } this.input.DropBits(0x10); if (num2 != (this.uncomprLen ^ 0xffff)) { throw new FormatException("broken uncompressed block"); } this.mode = 5; Label_01DC: 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_0268: return this.DecodeHuffman(); }
public void Reset() { this.mode = this.nowrap ? 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 bool Decode(StreamManipulator input) { int num2; int num3; Label_0005: switch (this.mode) { case 0: this.lnum = input.PeekBits(5); if (this.lnum >= 0) { this.lnum += 0x101; input.DropBits(5); this.mode = 1; break; } return false; case 1: break; case 2: goto Label_00D1; case 3: goto Label_0161; case 4: goto Label_01D6; case 5: goto Label_0224; default: goto Label_0005; } this.dnum = input.PeekBits(5); if (this.dnum < 0) { return false; } this.dnum++; input.DropBits(5); this.num = this.lnum + this.dnum; this.litdistLens = new byte[this.num]; this.mode = 2; Label_00D1: this.blnum = input.PeekBits(4); if (this.blnum < 0) { return false; } this.blnum += 4; input.DropBits(4); this.blLens = new byte[0x13]; this.ptr = 0; this.mode = 3; Label_0161: while (this.ptr < this.blnum) { int num = input.PeekBits(3); if (num < 0) { return false; } input.DropBits(3); this.blLens[BL_ORDER[this.ptr]] = (byte) num; this.ptr++; } this.blTree = new InflaterHuffmanTree(this.blLens); this.blLens = null; this.ptr = 0; this.mode = 4; Label_01D6: while (((num2 = this.blTree.GetSymbol(input)) & -16) == 0) { this.litdistLens[this.ptr++] = this.lastLen = (byte) num2; if (this.ptr == this.num) { return true; } } if (num2 < 0) { return false; } if (num2 >= 0x11) { this.lastLen = 0; } else if (this.ptr == 0) { throw new Exception(); } this.repSymbol = num2 - 0x10; this.mode = 5; Label_0224: num3 = repBits[this.repSymbol]; int num4 = input.PeekBits(num3); if (num4 < 0) { return false; } input.DropBits(num3); num4 += repMin[this.repSymbol]; if ((this.ptr + num4) > this.num) { throw new Exception(); } while (num4-- > 0) { this.litdistLens[this.ptr++] = this.lastLen; } if (this.ptr == this.num) { return true; } this.mode = 4; goto Label_0005; }