private void complete() { this.storedCombinedCRC = bsGetInt(); this.currentState = CState.EOF; this.data = null; if (this.storedCombinedCRC != this.computedCombinedCRC) { var msg = String.Format("BZip2 CRC error (expected {0:X8}, computed {1:X8})", this.storedCombinedCRC, this.computedCombinedCRC); throw new IOException(msg); } }
void InitBlock() { char magic0 = bsGetUByte(); char magic1 = bsGetUByte(); char magic2 = bsGetUByte(); char magic3 = bsGetUByte(); char magic4 = bsGetUByte(); char magic5 = bsGetUByte(); if (magic0 == 0x17 && magic1 == 0x72 && magic2 == 0x45 && magic3 == 0x38 && magic4 == 0x50 && magic5 == 0x90) { complete(); // end of file } else if (magic0 != 0x31 || magic1 != 0x41 || magic2 != 0x59 || magic3 != 0x26 || magic4 != 0x53 || magic5 != 0x59) { this.currentState = CState.EOF; var msg = String.Format("bad block header at offset 0x{0:X}", this.input.Position); throw new IOException(msg); } else { this.storedBlockCRC = bsGetInt(); // Console.WriteLine(" stored block CRC : {0:X8}", this.storedBlockCRC); this.blockRandomised = (GetBits(1) == 1); // Lazily allocate data if (this.data == null) { this.data = new DecompressionState(this.blockSize100k); } // currBlockNo++; getAndMoveToFrontDecode(); this.crc.Reset(); this.currentState = CState.START_BLOCK; } }
/// <summary> /// Close the stream. /// </summary> public override void Close() { Stream inShadow = this.input; if (inShadow != null) { try { if (!this._leaveOpen) { inShadow.Close(); } } finally { this.data = null; this.input = null; } } }
// Token: 0x060006E2 RID: 1762 RVA: 0x0003DA6C File Offset: 0x0003BC6C private void SetupBlock() { if (this.data == null) { return; } BZip2InputStream.DecompressionState decompressionState = this.data; int[] array = decompressionState.initTT(this.last + 1); int i; for (i = 0; i <= 255; i++) { if (decompressionState.unzftab[i] < 0 || decompressionState.unzftab[i] > this.last) { throw new Exception("BZ_DATA_ERROR"); } } decompressionState.cftab[0] = 0; for (i = 1; i <= 256; i++) { decompressionState.cftab[i] = decompressionState.unzftab[i - 1]; } for (i = 1; i <= 256; i++) { decompressionState.cftab[i] += decompressionState.cftab[i - 1]; } for (i = 0; i <= 256; i++) { if (decompressionState.cftab[i] < 0 || decompressionState.cftab[i] > this.last + 1) { string message = string.Format("BZ_DATA_ERROR: cftab[{0}]={1} last={2}", i, decompressionState.cftab[i], this.last); throw new Exception(message); } } for (i = 1; i <= 256; i++) { if (decompressionState.cftab[i - 1] > decompressionState.cftab[i]) { throw new Exception("BZ_DATA_ERROR"); } } i = 0; int num = this.last; while (i <= num) { array[decompressionState.cftab[(int)(decompressionState.ll8[i] & byte.MaxValue)]++] = i; i++; } if (this.origPtr < 0 || this.origPtr >= array.Length) { throw new IOException("stream corrupted"); } this.su_tPos = array[this.origPtr]; this.su_count = 0; this.su_i2 = 0; this.su_ch2 = 256; if (this.blockRandomised) { this.su_rNToGo = 0; this.su_rTPos = 0; this.SetupRandPartA(); return; } this.SetupNoRandPartA(); }
// Token: 0x060006E0 RID: 1760 RVA: 0x0003D4D4 File Offset: 0x0003B6D4 private void getAndMoveToFrontDecode() { BZip2InputStream.DecompressionState decompressionState = this.data; this.origPtr = this.GetBits(24); if (this.origPtr < 0) { throw new IOException("BZ_DATA_ERROR"); } if (this.origPtr > 10 + BZip2.BlockSizeMultiple * this.blockSize100k) { throw new IOException("BZ_DATA_ERROR"); } this.recvDecodingTables(); byte[] getAndMoveToFrontDecode_yy = decompressionState.getAndMoveToFrontDecode_yy; int num = this.blockSize100k * BZip2.BlockSizeMultiple; int num2 = 256; while (--num2 >= 0) { getAndMoveToFrontDecode_yy[num2] = (byte)num2; decompressionState.unzftab[num2] = 0; } int num3 = 0; int num4 = BZip2.G_SIZE - 1; int num5 = this.nInUse + 1; int num6 = this.getAndMoveToFrontDecode0(0); int num7 = this.bsBuff; int i = this.bsLive; int num8 = -1; int num9 = (int)(decompressionState.selector[0] & byte.MaxValue); int[] array = decompressionState.gBase[num9]; int[] array2 = decompressionState.gLimit[num9]; int[] array3 = decompressionState.gPerm[num9]; int num10 = decompressionState.gMinlen[num9]; while (num6 != num5) { if (num6 != (int)BZip2.RUNA) { if (num6 != (int)BZip2.RUNB) { if (++num8 < num) { byte b = getAndMoveToFrontDecode_yy[num6 - 1]; decompressionState.unzftab[(int)(decompressionState.seqToUnseq[(int)b] & byte.MaxValue)]++; decompressionState.ll8[num8] = decompressionState.seqToUnseq[(int)b]; if (num6 <= 16) { int j = num6 - 1; while (j > 0) { getAndMoveToFrontDecode_yy[j] = getAndMoveToFrontDecode_yy[--j]; } } else { Buffer.BlockCopy(getAndMoveToFrontDecode_yy, 0, getAndMoveToFrontDecode_yy, 1, num6 - 1); } getAndMoveToFrontDecode_yy[0] = b; if (num4 == 0) { num4 = BZip2.G_SIZE - 1; num9 = (int)(decompressionState.selector[++num3] & byte.MaxValue); array = decompressionState.gBase[num9]; array2 = decompressionState.gLimit[num9]; array3 = decompressionState.gPerm[num9]; num10 = decompressionState.gMinlen[num9]; } else { num4--; } int num11 = num10; while (i < num11) { int num12 = this.input.ReadByte(); if (num12 < 0) { throw new IOException("unexpected end of stream"); } num7 = (num7 << 8 | num12); i += 8; } int k = num7 >> i - num11 & (1 << num11) - 1; i -= num11; while (k > array2[num11]) { num11++; while (i < 1) { int num13 = this.input.ReadByte(); if (num13 < 0) { throw new IOException("unexpected end of stream"); } num7 = (num7 << 8 | num13); i += 8; } i--; k = (k << 1 | (num7 >> i & 1)); } num6 = array3[k - array[num11]]; continue; } throw new IOException("block overrun"); } } int num14 = -1; int num15 = 1; for (;;) { if (num6 == (int)BZip2.RUNA) { num14 += num15; } else { if (num6 != (int)BZip2.RUNB) { break; } num14 += num15 << 1; } if (num4 == 0) { num4 = BZip2.G_SIZE - 1; num9 = (int)(decompressionState.selector[++num3] & byte.MaxValue); array = decompressionState.gBase[num9]; array2 = decompressionState.gLimit[num9]; array3 = decompressionState.gPerm[num9]; num10 = decompressionState.gMinlen[num9]; } else { num4--; } int num16 = num10; while (i < num16) { int num17 = this.input.ReadByte(); if (num17 < 0) { goto IL_47E; } num7 = (num7 << 8 | num17); i += 8; } int l = num7 >> i - num16 & (1 << num16) - 1; i -= num16; while (l > array2[num16]) { num16++; while (i < 1) { int num18 = this.input.ReadByte(); if (num18 < 0) { goto IL_473; } num7 = (num7 << 8 | num18); i += 8; } i--; l = (l << 1 | (num7 >> i & 1)); } num6 = array3[l - array[num16]]; num15 <<= 1; } byte b2 = decompressionState.seqToUnseq[(int)getAndMoveToFrontDecode_yy[0]]; decompressionState.unzftab[(int)(b2 & byte.MaxValue)] += num14 + 1; while (num14-- >= 0) { decompressionState.ll8[++num8] = b2; } if (num8 < num) { continue; } throw new IOException("block overrun"); IL_473: throw new IOException("unexpected end of stream"); IL_47E: throw new IOException("unexpected end of stream"); } this.last = num8; this.bsLive = i; this.bsBuff = num7; }
// Token: 0x060006DE RID: 1758 RVA: 0x0003D278 File Offset: 0x0003B478 private void recvDecodingTables() { BZip2InputStream.DecompressionState decompressionState = this.data; bool[] inUse = decompressionState.inUse; byte[] recvDecodingTables_pos = decompressionState.recvDecodingTables_pos; int num = 0; for (int i = 0; i < 16; i++) { if (this.bsGetBit()) { num |= 1 << i; } } int num2 = 256; while (--num2 >= 0) { inUse[num2] = false; } for (int j = 0; j < 16; j++) { if ((num & 1 << j) != 0) { int num3 = j << 4; for (int k = 0; k < 16; k++) { if (this.bsGetBit()) { inUse[num3 + k] = true; } } } } this.MakeMaps(); int num4 = this.nInUse + 2; int bits = this.GetBits(3); int bits2 = this.GetBits(15); for (int l = 0; l < bits2; l++) { int num5 = 0; while (this.bsGetBit()) { num5++; } decompressionState.selectorMtf[l] = (byte)num5; } int num6 = bits; while (--num6 >= 0) { recvDecodingTables_pos[num6] = (byte)num6; } for (int m = 0; m < bits2; m++) { int n = (int)decompressionState.selectorMtf[m]; byte b = recvDecodingTables_pos[n]; while (n > 0) { recvDecodingTables_pos[n] = recvDecodingTables_pos[n - 1]; n--; } recvDecodingTables_pos[0] = b; decompressionState.selector[m] = b; } char[][] temp_charArray2d = decompressionState.temp_charArray2d; for (int num7 = 0; num7 < bits; num7++) { int num8 = this.GetBits(5); char[] array = temp_charArray2d[num7]; for (int num9 = 0; num9 < num4; num9++) { while (this.bsGetBit()) { num8 += (this.bsGetBit() ? -1 : 1); } array[num9] = (char)num8; } } this.createHuffmanDecodingTables(num4, bits); }