Esempio n. 1
0
            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;
            }
Esempio n. 2
0
            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);
                }
            }