static private BuffXOR ( Stream buffstream, int count ) : byte[] | ||
buffstream | Stream | The stream to read. It should already be at the position to read from. |
count | int | The number of bytes to read. |
return | byte[] |
public byte[] Extract(bool Preview, String outname = null) { byte[] databuff; int dataoff = 30; if (Filename != null) { dataoff += Filename.Length; } if (Extra != null) { dataoff += Extra.Length; } using (FileStream tpf = new FileStream(_par._filename, FileMode.Open, FileAccess.Read)) { tpf.Seek(FileOffset, SeekOrigin.Begin); databuff = ZipReader.BuffXOR(tpf, dataoff + (int)ComprSize + 16); // XOR the whole data block as well as the footer } // Check for correct header data and such ZipEntry fileentry = new ZipEntry(databuff); if (!fileentry.Compare(this)) { throw new InvalidDataException("File header not as expected"); } if (BitConverter.ToUInt32(databuff, (int)ComprSize + dataoff) != datadescriptormagic) { throw new InvalidDataException("Footer not as expected"); } //ZipCrypto.DecryptData(this, databuff, dataoff, (int)ComprSize); KFreonZipCrypto crypto = new KFreonZipCrypto(this, databuff, dataoff, (int)ComprSize); databuff = crypto.GetBlocks(); databuff = Deflate(databuff, 12 + dataoff, (int)ComprSize - 12); if (databuff.Length != UncomprSize) { throw new InvalidDataException("Deflation resulted in incorrect file size"); } CRC32 crcgen = new CRC32(); if (crcgen.BlockChecksum(databuff, 0, (int)UncomprSize) != CRC) { throw new InvalidDataException("Checksums don't match"); } if (!Preview) { outname = outname ?? Filename; using (FileStream fs = new FileStream(outname, FileMode.Create, FileAccess.Write)) { fs.Write(databuff, 0, (int)UncomprSize); } return(null); } else { return(databuff); } }
public byte[] Extract(bool Preview, String outname = null) { byte[] databuff; int dataoff = 30; // For ZipEntry header - not the above one if (Filename != null) { dataoff += Filename.Length; } if (Extra != null) { dataoff += Extra.Length; } // KFreon: Use stored MemoryStream if possible. Stream tpf = null; if (_par.FileData == null) { tpf = new FileStream(_par._filename, FileMode.Open, FileAccess.Read); } else { tpf = new MemoryStream(_par.FileData); } tpf.Seek(FileOffset, SeekOrigin.Begin); databuff = ZipReader.BuffXOR(tpf, dataoff + (int)ComprSize + 16); // XOR the whole data block as well as the footer // KFreon: Dispose of stream IF it was a FileStream if (_par.FileData == null) { tpf.Dispose(); } // Check for correct header data and such ZipEntry fileentry = new ZipEntry(databuff); if (!fileentry.Compare(this)) { throw new InvalidDataException("File header not as expected"); } // KFreon: Apparently not necessary. Some TPF's fail to load with this, but when commented out, they load fine, so... /*if (BitConverter.ToUInt32(databuff, (int)ComprSize + dataoff) != datadescriptormagic) * Console.WriteLine("Footer not as expected");*/ ZipDecrypto crypto = new ZipDecrypto(this, databuff, dataoff, (int)ComprSize); databuff = crypto.GetBlocks(); databuff = Deflate(databuff, 12 + dataoff, (int)ComprSize - 12); if (databuff.Length != UncomprSize) { throw new InvalidDataException("Deflation resulted in incorrect file size"); } CRC32 crcgen = new CRC32(); if (crcgen.BlockChecksum(databuff, 0, (int)UncomprSize) != CRC) { throw new InvalidDataException("Checksums don't match"); } if (!Preview) { outname = outname ?? Filename; using (FileStream fs = new FileStream(outname, FileMode.Create, FileAccess.Write)) { fs.Write(databuff, 0, (int)UncomprSize); } return(null); } else { return(databuff); } }