Beispiel #1
0
        // Token: 0x06000D9E RID: 3486 RVA: 0x00038E54 File Offset: 0x00037054
        private void WriteBlock(CompressionBlockFlags compressionBlockFlags, byte[] uncompressedData, byte[] compressedData)
        {
            OABCompressedBlock oabcompressedBlock = new OABCompressedBlock
            {
                Flags              = compressionBlockFlags,
                CompressedLength   = compressedData.Length,
                UncompressedLength = uncompressedData.Length,
                CRC  = OABCRC.ComputeCRC(OABCRC.DefaultSeed, uncompressedData),
                Data = compressedData
            };

            OABCompressStream.Tracer.TraceDebug <long, OABCompressedBlock>((long)this.GetHashCode(), "OABCompressStream: writing block at stream position {0}:\n\r{1}", this.stream.Position, oabcompressedBlock);
            oabcompressedBlock.WriteTo(this.writer);
        }
        // Token: 0x06000DAE RID: 3502 RVA: 0x00039128 File Offset: 0x00037328
        private byte[] ReadBlock()
        {
            long num = this.reader.BaseStream.Position;
            OABCompressedBlock oabcompressedBlock = OABCompressedBlock.ReadFrom(this.reader);

            OABDecompressStream.Tracer.TraceDebug <long, OABCompressedBlock>((long)this.GetHashCode(), "OABDecompressStream: read OABCompressedBlock at position {0}:\r\n{1}", num, oabcompressedBlock);
            if (oabcompressedBlock.CompressedLength > this.header.MaximumCompressionBlockSize)
            {
                throw new InvalidDataException(string.Format("Compressed block starting at position {0}: data is larger than header stated. MaximumCompressionBlockSize={1}, CompressedLength={2}", num, this.header.MaximumCompressionBlockSize, oabcompressedBlock.CompressedLength));
            }
            if (oabcompressedBlock.UncompressedLength > this.header.MaximumCompressionBlockSize)
            {
                throw new InvalidDataException(string.Format("Compressed block starting at position {0}: data is larger than header stated. MaximumCompressionBlockSize={1}, UncompressedLength={2}", num, this.header.MaximumCompressionBlockSize, oabcompressedBlock.UncompressedLength));
            }
            byte[] array;
            if (oabcompressedBlock.Flags == CompressionBlockFlags.Compressed)
            {
                try
                {
                    array = this.decompressor.Decompress(oabcompressedBlock.Data, oabcompressedBlock.UncompressedLength);
                    goto IL_FF;
                }
                catch (Win32Exception innerException)
                {
                    throw new InvalidDataException(string.Format("Compressed block starting at position {0}: unable to decompress data", num), innerException);
                }
            }
            array = oabcompressedBlock.Data;
IL_FF:
            uint num2 = OABCRC.ComputeCRC(OABCRC.DefaultSeed, array);

            if (num2 != oabcompressedBlock.CRC)
            {
                throw new InvalidDataException(string.Format("Compressed block starting at position {0}: invalid CRC. Expected: {1:X8}, actual: {2:X8}", num, num2, oabcompressedBlock.CRC));
            }
            this.uncompressedLength += (uint)array.Length;
            if (this.uncompressedLength > this.header.UncompressedFileSize)
            {
                throw new InvalidDataException(string.Format("Compressed block starting at position {0}: decompressed data so far is already longer than header stated. Header size: {1}, so far: {2}.", num, this.header.UncompressedFileSize, this.uncompressedLength));
            }
            return(array);
        }
Beispiel #3
0
 // Token: 0x06000DB0 RID: 3504 RVA: 0x000392E4 File Offset: 0x000374E4
 public static uint ComputeCRC(uint seed, byte[] buffer)
 {
     return(OABCRC.ComputeCRC(seed, buffer, 0, buffer.Length));
 }