Esempio n. 1
0
 public RarStream(Unpack unpack, FileHeader fileHeader, Stream readStream)
 {
     this.unpack = unpack;
     this.fileHeader = fileHeader;
     this.readStream = readStream;
     fetch = true;
     unpack.doUnpack(fileHeader, readStream, this);
     fetch = false;
 }
Esempio n. 2
0
 public Unpack(FileHeader fileHeader, Stream readStream, Stream writeStream)
 {
     base.readStream = readStream;
     base.writeStream = writeStream;
     this.fileHeader = fileHeader;
     window = null;
     //externalWindow = false;
     suspended = false;
     unpAllBuf = false;
     unpSomeRead = false;
     destUnpSize = fileHeader.UncompressedSize;
     init(null);
 }
 internal FileInfoRarFilePart(FileInfoRarArchiveVolume volume, MarkHeader mh, FileHeader fh, FileInfo fi)
     : base(mh, fh, volume.Stream, volume.Password)
 {
     FileInfo = fi;
 }
 internal override RarFilePart CreateFilePart(FileHeader fileHeader, MarkHeader markHeader)
 {
     return new SeekableFilePart(markHeader, fileHeader, Stream, Password);
 }
 internal NonSeekableStreamFilePart(MarkHeader mh, FileHeader fh, bool streamOwner)
     : base(mh, fh, streamOwner)
 {
 }
Esempio n. 6
0
 internal RarFilePart(MarkHeader mh, FileHeader fh)
 {
     MarkHeader = mh;
     FileHeader = fh;
 }
Esempio n. 7
0
 internal abstract RarFilePart CreateFilePart(FileHeader fileHeader, MarkHeader markHeader);
Esempio n. 8
0
 internal override RarFilePart CreateFilePart(FileHeader fileHeader, MarkHeader markHeader)
 {
     return new NonSeekableStreamFilePart(markHeader, fileHeader);
 }
Esempio n. 9
0
 internal RarFilePart(SharpCompress.Common.Rar.Headers.MarkHeader mh, SharpCompress.Common.Rar.Headers.FileHeader fh)
 {
     this.MarkHeader = mh;
     this.FileHeader = fh;
 }
Esempio n. 10
0
        private RarHeader ReadNextHeader(Stream stream)
        {
#if !NO_CRYPTO
            var reader = new RarCryptoBinaryReader(stream, Password);

            if (IsEncrypted)
            {
                if (Password == null)
                {
                    throw new CryptographicException("Encrypted Rar archive has no password specified.");
                }
                reader.SkipQueue();
                byte[] salt = reader.ReadBytes(8);
                reader.InitializeAes(salt);
            }
#else
            var reader = new MarkingBinaryReader(stream);
#endif

            RarHeader header = RarHeader.Create(reader);
            if (header == null)
            {
                return(null);
            }
            switch (header.HeaderType)
            {
            case HeaderType.ArchiveHeader:
            {
                var ah = header.PromoteHeader <ArchiveHeader>(reader);
                IsEncrypted = ah.HasPassword;
                return(ah);
            }

            case HeaderType.MarkHeader:
            {
                return(header.PromoteHeader <MarkHeader>(reader));
            }

            case HeaderType.ProtectHeader:
            {
                ProtectHeader ph = header.PromoteHeader <ProtectHeader>(reader);

                // skip the recovery record data, we do not use it.
                switch (StreamingMode)
                {
                case StreamingMode.Seekable:
                {
                    reader.BaseStream.Position += ph.DataSize;
                }
                break;

                case StreamingMode.Streaming:
                {
                    reader.BaseStream.Skip(ph.DataSize);
                }
                break;

                default:
                {
                    throw new InvalidFormatException("Invalid StreamingMode");
                }
                }

                return(ph);
            }

            case HeaderType.NewSubHeader:
            {
                FileHeader fh = header.PromoteHeader <FileHeader>(reader);
                switch (StreamingMode)
                {
                case StreamingMode.Seekable:
                {
                    fh.DataStartPosition        = reader.BaseStream.Position;
                    reader.BaseStream.Position += fh.CompressedSize;
                }
                break;

                case StreamingMode.Streaming:
                {
                    //skip the data because it's useless?
                    reader.BaseStream.Skip(fh.CompressedSize);
                }
                break;

                default:
                {
                    throw new InvalidFormatException("Invalid StreamingMode");
                }
                }
                return(fh);
            }

            case HeaderType.FileHeader:
            {
                FileHeader fh = header.PromoteHeader <FileHeader>(reader);
                switch (StreamingMode)
                {
                case StreamingMode.Seekable:
                {
                    fh.DataStartPosition        = reader.BaseStream.Position;
                    reader.BaseStream.Position += fh.CompressedSize;
                }
                break;

                case StreamingMode.Streaming:
                {
                    var ms = new ReadOnlySubStream(reader.BaseStream, fh.CompressedSize);
                    if (fh.Salt == null)
                    {
                        fh.PackedStream = ms;
                    }
                    else
                    {
#if !NO_CRYPTO
                        fh.PackedStream = new RarCryptoWrapper(ms, Password, fh.Salt);
#else
                        throw new NotSupportedException("RarCrypto not supported");
#endif
                    }
                }
                break;

                default:
                {
                    throw new InvalidFormatException("Invalid StreamingMode");
                }
                }
                return(fh);
            }

            case HeaderType.EndArchiveHeader:
            {
                return(header.PromoteHeader <EndArchiveHeader>(reader));
            }

            default:
            {
                throw new InvalidFormatException("Invalid Rar Header: " + header.HeaderType.ToString());
            }
            }
        }
Esempio n. 11
0
        private RarHeader TryReadNextHeader(Stream stream)
        {
            RarCrcBinaryReader reader;

            if (!IsEncrypted)
            {
                reader = new RarCrcBinaryReader(stream);
            }
            else
            {
#if !NO_CRYPTO
                if (Options.Password == null)
                {
                    throw new CryptographicException("Encrypted Rar archive has no password specified.");
                }
                reader = new RarCryptoBinaryReader(stream, Options.Password);
#else
                throw new CryptographicException("Rar encryption unsupported on this platform");
#endif
            }

            var header = RarHeader.TryReadBase(reader, _isRar5, Options.ArchiveEncoding);
            if (header == null)
            {
                return(null);
            }
            switch (header.HeaderCode)
            {
            case HeaderCodeV.RAR5_ARCHIVE_HEADER:
            case HeaderCodeV.RAR4_ARCHIVE_HEADER:
            {
                var ah = new ArchiveHeader(header, reader);
                if (ah.IsEncrypted == true)
                {
                    //!!! rar5 we don't know yet
                    IsEncrypted = true;
                }
                return(ah);
            }

            case HeaderCodeV.RAR4_PROTECT_HEADER:
            {
                var ph = new ProtectHeader(header, reader);
                // skip the recovery record data, we do not use it.
                switch (StreamingMode)
                {
                case StreamingMode.Seekable:
                {
                    reader.BaseStream.Position += ph.DataSize;
                }
                break;

                case StreamingMode.Streaming:
                {
                    reader.BaseStream.Skip(ph.DataSize);
                }
                break;

                default:
                {
                    throw new InvalidFormatException("Invalid StreamingMode");
                }
                }

                return(ph);
            }

            case HeaderCodeV.RAR5_SERVICE_HEADER:
            {
                var fh = new FileHeader(header, reader, HeaderType.Service);
                SkipData(fh, reader);
                return(fh);
            }

            case HeaderCodeV.RAR4_NEW_SUB_HEADER:
            {
                var fh = new FileHeader(header, reader, HeaderType.NewSub);
                SkipData(fh, reader);
                return(fh);
            }

            case HeaderCodeV.RAR5_FILE_HEADER:
            case HeaderCodeV.RAR4_FILE_HEADER:
            {
                var fh = new FileHeader(header, reader, HeaderType.File);
                switch (StreamingMode)
                {
                case StreamingMode.Seekable:
                {
                    fh.DataStartPosition        = reader.BaseStream.Position;
                    reader.BaseStream.Position += fh.CompressedSize;
                }
                break;

                case StreamingMode.Streaming:
                {
                    var ms = new ReadOnlySubStream(reader.BaseStream, fh.CompressedSize);
                    if (fh.R4Salt == null)
                    {
                        fh.PackedStream = ms;
                    }
                    else
                    {
#if !NO_CRYPTO
                        fh.PackedStream = new RarCryptoWrapper(ms, Options.Password, fh.R4Salt);
#else
                        throw new NotSupportedException("RarCrypto not supported");
#endif
                    }
                }
                break;

                default:
                {
                    throw new InvalidFormatException("Invalid StreamingMode");
                }
                }
                return(fh);
            }

            case HeaderCodeV.RAR5_END_ARCHIVE_HEADER:
            case HeaderCodeV.RAR4_END_ARCHIVE_HEADER:
            {
                return(new EndArchiveHeader(header, reader));
            }

            case HeaderCodeV.RAR5_ARCHIVE_ENCRYPTION_HEADER:
            {
                var ch = new ArchiveCryptHeader(header, reader);
                IsEncrypted = true;
                return(ch);
            }

            default:
            {
                throw new InvalidFormatException("Unknown Rar Header: " + header.HeaderCode);
            }
            }
        }
Esempio n. 12
0
 public void doUnpack(FileHeader fileHeader, Stream readStream, Stream writeStream)
 {
     base.destUnpSize = fileHeader.UncompressedSize;
     this.fileHeader = fileHeader;
     base.writeStream = writeStream;
     base.readStream = readStream;
     if (!FlagUtility.HasFlag<FileFlags>(fileHeader.FileFlags, FileFlags.SOLID))
     {
         this.init(null);
     }
     base.suspended = false;
     this.doUnpack();
 }
 internal FileInfoRarFilePart(MarkHeader mh, FileHeader fh, FileInfo fi)
     : base(mh, fh, true)
 {
     FileInfo = fi;
 }
Esempio n. 14
0
        private RarHeader ReadNextHeader(Stream stream)
        {
#if PORTABLE
            var reader = new MarkingBinaryReader(stream);
#else
            var reader = new RarCryptoBinaryReader(stream, Password);

            if (IsEncrypted)
            {
                reader.SkipQueue();
                byte[] salt = reader.ReadBytes(8);
                reader.InitializeAes(salt);
            }
#endif

            RarHeader header = RarHeader.Create(reader);
            if (header == null)
            {
                return(null);
            }
            switch (header.HeaderType)
            {
            case HeaderType.ArchiveHeader:
            {
                var ah = header.PromoteHeader <ArchiveHeader>(reader);
                IsEncrypted = ah.HasPassword;
                return(ah);
            }

            case HeaderType.MarkHeader:
            {
                return(header.PromoteHeader <MarkHeader>(reader));
            }

            case HeaderType.NewSubHeader:
            {
                FileHeader fh = header.PromoteHeader <FileHeader>(reader);
                switch (StreamingMode)
                {
                case StreamingMode.Seekable:
                {
                    fh.DataStartPosition        = reader.BaseStream.Position;
                    reader.BaseStream.Position += fh.CompressedSize;
                }
                break;

                case StreamingMode.Streaming:
                {
                    //skip the data because it's useless?
                    reader.BaseStream.Skip(fh.CompressedSize);
                }
                break;

                default:
                {
                    throw new InvalidFormatException("Invalid StreamingMode");
                }
                }
                return(fh);
            }

            case HeaderType.FileHeader:
            {
                FileHeader fh = header.PromoteHeader <FileHeader>(reader);
                switch (StreamingMode)
                {
                case StreamingMode.Seekable:
                {
                    fh.DataStartPosition        = reader.BaseStream.Position;
                    reader.BaseStream.Position += fh.CompressedSize;
                }
                break;

                case StreamingMode.Streaming:
                {
                    var ms = new ReadOnlySubStream(reader.BaseStream, fh.CompressedSize);
                    if (fh.Salt == null)
                    {
                        fh.PackedStream = ms;
                    }
                    else
                    {
#if PORTABLE
                        throw new NotSupportedException("Encrypted Rar files aren't supported in portable distro.");
#else
                        fh.PackedStream = new RarCryptoWrapper(ms, Password, fh.Salt);
#endif
                    }
                }
                break;

                default:
                {
                    throw new InvalidFormatException("Invalid StreamingMode");
                }
                }
                return(fh);
            }

            case HeaderType.EndArchiveHeader:
            {
                return(header.PromoteHeader <EndArchiveHeader>(reader));
            }

            default:
            {
                throw new InvalidFormatException("Invalid Rar Header: " + header.HeaderType.ToString());
            }
            }
        }
Esempio n. 15
0
 internal SeekableFilePart(MarkHeader mh, FileHeader fh, Stream stream, string password)
     : base(mh, fh)
 {
     this.stream = stream;
     this.password = password;
 }
Esempio n. 16
0
 internal RarFilePart(MarkHeader mh, FileHeader fh, bool streamOwner)
 {
     MarkHeader = mh;
     FileHeader = fh;
     StreamOwner = streamOwner;
 }
 internal NonSeekableStreamFilePart(MarkHeader mh, FileHeader fh)
     : base(mh, fh)
 {
 }
 internal FileInfoRarFilePart(FileInfoRarArchiveVolume volume, MarkHeader mh, FileHeader fh, System.IO.FileInfo fi)
     : base(mh, fh, volume.Stream, volume.Password)
 {
     this.volume = volume;
     this.FileInfo = fi;
 }
Esempio n. 19
0
 public void doUnpack(FileHeader fileHeader, Stream readStream, Stream writeStream)
 {
     destUnpSize = fileHeader.UncompressedSize;
     this.fileHeader = fileHeader;
     base.writeStream = writeStream;
     base.readStream = readStream;
     bool solid = FlagUtility.HasFlag(fileHeader.FileFlags, FileFlags.SOLID);
     if (!solid)
     {
         init(null);
     }
     suspended = false;
     doUnpack();
 }
 internal override RarFilePart CreateFilePart(FileHeader fileHeader, MarkHeader markHeader)
 {
     return new FileInfoRarFilePart(this, markHeader, fileHeader, FileInfo);
 }
 internal FileInfoRarFilePart(FileInfoRarArchiveVolume volume, MarkHeader mh, FileHeader fh, FileInfo fi)
     : base(mh, fh)
 {
     this.volume = volume;
     FileInfo = fi;
 }
 internal SeekableStreamFilePart(MarkHeader mh, FileHeader fh, Stream stream, bool streamOwner)
     : base(mh, fh, streamOwner)
 {
     Stream = stream;
 }
Esempio n. 23
0
 internal SeekableStreamFilePart(MarkHeader mh, FileHeader fh, Stream stream)
     : base(mh, fh)
 {
     Stream = stream;
 }
Esempio n. 24
0
        private RarHeader ReadNextHeader(Stream stream)
        {
            MarkingBinaryReader reader = new MarkingBinaryReader(stream);
            RarHeader           header = RarHeader.Create(reader);

            if (header == null)
            {
                return(null);
            }
            switch (header.HeaderType)
            {
            case HeaderType.ArchiveHeader:
            {
                return(header.PromoteHeader <ArchiveHeader>(reader));
            }

            case HeaderType.MarkHeader:
            {
                return(header.PromoteHeader <MarkHeader>(reader));
            }

            case HeaderType.NewSubHeader:
            {
                FileHeader fh = header.PromoteHeader <FileHeader>(reader);
                switch (StreamingMode)
                {
                case StreamingMode.Seekable:
                {
                    fh.DataStartPosition        = reader.BaseStream.Position;
                    reader.BaseStream.Position += fh.CompressedSize;
                }
                break;

                case StreamingMode.Streaming:
                {
                    //skip the data because it's useless?
                    reader.BaseStream.Skip(fh.CompressedSize);
                }
                break;

                default:
                {
                    throw new InvalidFormatException("Invalid StreamingMode");
                }
                }
                return(fh);
            }

            case HeaderType.FileHeader:
            {
                FileHeader fh = header.PromoteHeader <FileHeader>(reader);
                switch (StreamingMode)
                {
                case StreamingMode.Seekable:
                {
                    fh.DataStartPosition        = reader.BaseStream.Position;
                    reader.BaseStream.Position += fh.CompressedSize;
                }
                break;

                case StreamingMode.Streaming:
                {
                    ReadOnlySubStream ms
                                    = new ReadOnlySubStream(reader.BaseStream, fh.CompressedSize);
                    fh.PackedStream = ms;
                }
                break;

                default:
                {
                    throw new InvalidFormatException("Invalid StreamingMode");
                }
                }
                return(fh);
            }

            case HeaderType.EndArchiveHeader:
            {
                return(header.PromoteHeader <EndArchiveHeader>(reader));
            }

            default:
            {
                throw new InvalidFormatException("Invalid Rar Header: " + header.HeaderType.ToString());
            }
            }
        }