Ejemplo n.º 1
0
        // Token: 0x06000D7E RID: 3454 RVA: 0x000388CC File Offset: 0x00036ACC
        public static OABCompressedBlock ReadFrom(BinaryReader reader)
        {
            OABCompressedBlock oabcompressedBlock = new OABCompressedBlock();

            oabcompressedBlock.Flags              = (CompressionBlockFlags)reader.ReadUInt32("Flags");
            oabcompressedBlock.CompressedLength   = (int)reader.ReadUInt32("CompressedLength");
            oabcompressedBlock.UncompressedLength = (int)reader.ReadUInt32("UncompressedLength");
            oabcompressedBlock.CRC  = reader.ReadUInt32("CRC");
            oabcompressedBlock.Data = reader.ReadBytes(oabcompressedBlock.CompressedLength, "Data");
            return(oabcompressedBlock);
        }
Ejemplo n.º 2
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);
        }