Example #1
0
 protected override void ReadFromReader(MarkingBinaryReader reader)
 {
     Version = reader.ReadByte();
     RecSectors = reader.ReadUInt16();
     TotalBlocks = reader.ReadUInt32();
     Mark = reader.ReadBytes(8);
 }
Example #2
0
 protected override void ReadFromReader(MarkingBinaryReader reader)
 {
     UnpSize = reader.ReadInt16();
     UnpVersion = reader.ReadByte();
     UnpMethod = reader.ReadByte();
     CommCRC = reader.ReadInt16();
 }
 protected override void ReadFromReader(MarkingBinaryReader reader)
 {
     UnpackVersion = reader.ReadByte();
     Method = reader.ReadByte();
     AVVersion = reader.ReadByte();
     AVInfoCRC = reader.ReadInt32();
 }
Example #4
0
 protected override void ReadFromReader(MarkingBinaryReader reader)
 {
     HighPosAv = reader.ReadInt16();
     PosAv = reader.ReadInt32();
     if (ArchiveHeaderFlags.HasFlag(ArchiveFlags.ENCRYPTVER))
     {
         EncryptionVersion = reader.ReadByte();
     }
 }
 protected override void ReadFromReader(MarkingBinaryReader reader)
 {
     if (EndArchiveFlags_HasFlag( EndArchiveFlags.EARC_DATACRC))
     {
         ArchiveCRC = reader.ReadInt32();
     }
     if (EndArchiveFlags_HasFlag(EndArchiveFlags.EARC_VOLNUMBER))
     {
         VolumeNumber = reader.ReadInt16();
     }
 }
 internal override void Read(MarkingBinaryReader reader)
 {
     VolumeNumber = reader.ReadUInt16();
     FirstVolumeWithDirectory = reader.ReadUInt16();
     TotalNumberOfEntriesInDisk = reader.ReadUInt16();
     TotalNumberOfEntries = reader.ReadUInt16();
     DirectorySize = reader.ReadUInt32();
     DirectoryStartOffsetRelativeToDisk = reader.ReadUInt32();
     CommentLength = reader.ReadUInt16();
     Comment = reader.ReadBytes(CommentLength);
 }
        internal static IEnumerable<ZipHeader> ReadHeaderNonseekable(Stream stream)
        {
            while (true)
            {
                ZipHeader header = null;
                try
                {
                    MarkingBinaryReader reader = new MarkingBinaryReader(stream);

                    uint headerBytes = reader.ReadUInt32();
                    switch (headerBytes)
                    {
                        case ENTRY_HEADER_BYTES:
                            {
                                var entry = new LocalEntryHeader();
                                entry.Read(reader);
                                if (entry.CompressedSize > 0)
                                {
                                    entry.PackedStream = new ReadOnlySubStream(stream, entry.CompressedSize, true);
                                }
                                header = entry;
                            }
                            break;
                        case DIRECTORY_START_HEADER_BYTES:
                            {
                                var entry = new DirectoryEntryHeader();
                                entry.Read(reader);
                                header = entry;
                            }
                            break;
                        case POST_DATA_DESCRIPTOR:
                        case DIGITAL_SIGNATURE:
                            break;
                        case DIRECTORY_END_HEADER_BYTES:
                            {
                                var entry = new DirectoryEndHeader();
                                entry.Read(reader);
                                header = entry;
                            }
                            break;
                        case ZIP64_END_OF_CENTRAL_DIRECTORY:
                        default:
                            break;
                    }
                }
                catch
                {
                    header = null;
                }
                yield return header;
            }
        }
 internal override void Read(MarkingBinaryReader reader)
 {
     Version = reader.ReadUInt16();
     Flags = reader.ReadUInt16();
     CompressionMethod = reader.ReadUInt16();
     LastModifiedTime = reader.ReadUInt16();
     LastModifiedDate = reader.ReadUInt16();
     Crc = reader.ReadUInt32();
     CompressedSize = reader.ReadUInt32();
     UncompressedSize = reader.ReadUInt32();
     ushort nameLength = reader.ReadUInt16();
     ushort extraLength = reader.ReadUInt16();
     byte[] name = reader.ReadBytes(nameLength);
     Extra = reader.ReadBytes(extraLength);
     Name = DefaultEncoding.GetString(name, 0, name.Length);
 }
 protected override void ReadFromReader(MarkingBinaryReader reader)
 {
     CreationTime = reader.ReadInt32();
     ArcNameSize = reader.ReadInt16();
     UserNameSize = reader.ReadInt16();
 }
Example #10
0
 protected override void ReadFromReader(MarkingBinaryReader reader)
 {
 }
Example #11
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());
             }
     }
 }
Example #12
0
		protected override void ReadFromReader(MarkingBinaryReader reader)
		{
			uint lowUncompressedSize = reader.ReadUInt32();

			HostOS = (HostOS)reader.ReadByte();

			FileCRC = reader.ReadUInt32();

			FileLastModifiedTime = Utility.DosDateToDateTime(reader.ReadInt32());

			RarVersion = reader.ReadByte();
			PackingMethod = reader.ReadByte();

			short nameSize = reader.ReadInt16();

			FileAttributes = reader.ReadInt32();

			uint highCompressedSize = 0;
			uint highUncompressedkSize = 0;
			if (FileFlags.HasFlag(FileFlags.LARGE))
			{
				highCompressedSize = reader.ReadUInt32();
				highUncompressedkSize = reader.ReadUInt32();
			}
			else
			{
				if (lowUncompressedSize == 0xffffffff)
				{
					lowUncompressedSize = 0xffffffff;
					highUncompressedkSize = int.MaxValue;
				}
			}
			CompressedSize = UInt32To64(highCompressedSize, AdditionalSize);
			UncompressedSize = UInt32To64(highUncompressedkSize, lowUncompressedSize);

			nameSize = nameSize > 4 * 1024 ? (short)(4 * 1024) : nameSize;

			byte[] fileNameBytes = reader.ReadBytes(nameSize);

			switch (HeaderType)
			{
				case HeaderType.FileHeader:
					{
						if (FileFlags.HasFlag(FileFlags.UNICODE))
						{
							int length = 0;
							while (length < fileNameBytes.Length
                                   && fileNameBytes[length] != 0)
							{
								length++;
							}
							if (length != nameSize)
							{
								length++;
								FileName = FileNameDecoder.Decode(fileNameBytes, length);
							}
							else
							{
								FileName = DecodeDefault(fileNameBytes);
							}
						}
						else
						{
							FileName = DecodeDefault(fileNameBytes);
						}
						FileName = ConvertPath(FileName, HostOS);
					}
					break;
				case HeaderType.NewSubHeader:
					{
						int datasize = HeaderSize - NEWLHD_SIZE - nameSize;
						if (FileFlags.HasFlag(FileFlags.SALT))
						{
							datasize -= SALT_SIZE;
						}
						if (datasize > 0)
						{
							SubData = reader.ReadBytes(datasize);
						}

						if (NewSubHeaderType.SUBHEAD_TYPE_RR.Equals(fileNameBytes))
						{
							RecoverySectors = SubData[8] + (SubData[9] << 8)
								+ (SubData[10] << 16) + (SubData[11] << 24);
						}
					}
					break;
			}

			if (FileFlags.HasFlag(FileFlags.SALT))
			{
				Salt = reader.ReadBytes(SALT_SIZE);
			}
			if (FileFlags.HasFlag(FileFlags.EXTTIME))
			{
				// verify that the end of the header hasn't been reached before reading the Extended Time.
				//  some tools incorrectly omit Extended Time despite specifying FileFlags.EXTTIME, which most parsers tolerate.
				if (ReadBytes + reader.CurrentReadByteCount <= HeaderSize - 2)
				{
					ushort extendedFlags = reader.ReadUInt16();
					FileLastModifiedTime = ProcessExtendedTime(extendedFlags, FileLastModifiedTime, reader, 0);
					FileCreatedTime = ProcessExtendedTime(extendedFlags, null, reader, 1);
					FileLastAccessedTime = ProcessExtendedTime(extendedFlags, null, reader, 2);
					FileArchivedTime = ProcessExtendedTime(extendedFlags, null, reader, 3);
				}
			}
		}
Example #13
0
 private static DateTime? ProcessExtendedTime(ushort extendedFlags, DateTime? time, MarkingBinaryReader reader, int i)
 {
     uint num = (uint) (extendedFlags >> ((3 - i) * 4));
     if ((num & 8) == 0)
     {
         return null;
     }
     if (i != 0)
     {
         uint iTime = reader.ReadUInt32();
         time = new DateTime?(Utility.DosDateToDateTime(iTime));
     }
     if ((num & 4) == 0)
     {
         time = new DateTime?(time.Value.AddSeconds(1.0));
     }
     uint num3 = 0;
     int num4 = ((int) num) & 3;
     for (int j = 0; j < num4; j++)
     {
         byte num6 = reader.ReadByte();
         num3 |= (uint) (num6 << (((j + 3) - num4) * 8));
     }
     return new DateTime?(time.Value.AddMilliseconds(num3 * Math.Pow(10.0, -4.0)));
 }
Example #14
0
        protected override void ReadFromReader(MarkingBinaryReader reader)
        {
            uint y = reader.ReadUInt32();
            this.HostOS = (SharpCompress.Common.Rar.Headers.HostOS) reader.ReadByte();
            this.FileCRC = reader.ReadUInt32();
            this.FileLastModifiedTime = new DateTime?(Utility.DosDateToDateTime(reader.ReadInt32()));
            this.RarVersion = reader.ReadByte();
            this.PackingMethod = reader.ReadByte();
            short count = reader.ReadInt16();
            this.FileAttributes = reader.ReadInt32();
            uint x = 0;
            uint num4 = 0;
            if (this.FileFlags_HasFlag(SharpCompress.Common.Rar.Headers.FileFlags.LARGE))
            {
                x = reader.ReadUInt32();
                num4 = reader.ReadUInt32();
            }
            else if (y == uint.MaxValue)
            {
                y = uint.MaxValue;
                num4 = 0x7fffffff;
            }
            this.CompressedSize = this.UInt32To64(x, base.AdditionalSize);
            this.UncompressedSize = this.UInt32To64(num4, y);
            count = (count > 0x1000) ? ((short) 0x1000) : count;
            byte[] name = reader.ReadBytes(count);
            switch (base.HeaderType)
            {
                case HeaderType.FileHeader:
                    if (this.FileFlags_HasFlag(SharpCompress.Common.Rar.Headers.FileFlags.UNICODE))
                    {
                        int index = 0;
                        while ((index < name.Length) && (name[index] != 0))
                        {
                            index++;
                        }
                        if (index != count)
                        {
                            index++;
                            this.FileName = FileNameDecoder.Decode(name, index);
                        }
                        else
                        {
                            this.FileName = this.DecodeDefault(name);
                        }
                    }
                    else
                    {
                        this.FileName = this.DecodeDefault(name);
                    }
                    this.FileName = ConvertPath(this.FileName, this.HostOS);
                    break;

                case HeaderType.NewSubHeader:
                {
                    int num6 = (base.HeaderSize - 0x20) - count;
                    if (this.FileFlags_HasFlag(SharpCompress.Common.Rar.Headers.FileFlags.SALT))
                    {
                        num6 -= 8;
                    }
                    if (num6 > 0)
                    {
                        this.SubData = reader.ReadBytes(num6);
                    }
                    if (NewSubHeaderType.SUBHEAD_TYPE_RR.Equals(name))
                    {
                        this.RecoverySectors = ((this.SubData[8] + (this.SubData[9] << 8)) + (this.SubData[10] << 0x10)) + (this.SubData[11] << 0x18);
                    }
                    break;
                }
            }
            if (this.FileFlags_HasFlag(SharpCompress.Common.Rar.Headers.FileFlags.SALT))
            {
                this.Salt = reader.ReadBytes(8);
            }
            if (this.FileFlags_HasFlag(SharpCompress.Common.Rar.Headers.FileFlags.EXTTIME) && ((base.ReadBytes + reader.CurrentReadByteCount) <= (base.HeaderSize - 2)))
            {
                ushort extendedFlags = reader.ReadUInt16();
                this.FileLastModifiedTime = ProcessExtendedTime(extendedFlags, this.FileLastModifiedTime, reader, 0);
                DateTime? time = null;
                this.FileCreatedTime = ProcessExtendedTime(extendedFlags, time, reader, 1);
                time = null;
                this.FileLastAccessedTime = ProcessExtendedTime(extendedFlags, time, reader, 2);
                this.FileArchivedTime = ProcessExtendedTime(extendedFlags, null, reader, 3);
            }
        }
        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());
                    }
            }
        }
Example #16
0
 internal abstract void Read(MarkingBinaryReader reader);
        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());
                    }
            }
        }
Example #18
0
		private static DateTime? ProcessExtendedTime(ushort extendedFlags, DateTime? time, MarkingBinaryReader reader,
		                                                   int i)
		{
			uint rmode = (uint)extendedFlags >> (3 - i) * 4;
			if ((rmode & 8) == 0)
			{
				return null;
			}
			if (i != 0)
			{
				uint DosTime = reader.ReadUInt32();
				time = Utility.DosDateToDateTime(DosTime);
			}
			if ((rmode & 4) == 0)
			{
				time = time.Value.AddSeconds(1);
			}
			uint nanosecondHundreds = 0;
			int count = (int)rmode & 3;
			for (int j = 0; j < count; j++)
			{
				byte b = reader.ReadByte();
				nanosecondHundreds |= (((uint)b) << ((j + 3 - count) * 8));
			}
			//10^-7 to 10^-3
			return time.Value.AddMilliseconds(nanosecondHundreds * Math.Pow(10, -4));
		}
        internal override void Read(MarkingBinaryReader reader)
        {
            Version = reader.ReadUInt16();
            VersionNeededToExtract = reader.ReadUInt16();
            Flags = reader.ReadUInt16();
            CompressionMethod = reader.ReadUInt16();
            LastModifiedTime = reader.ReadUInt16();
            LastModifiedDate = reader.ReadUInt16();
            Crc = reader.ReadUInt32();
            CompressedSize = reader.ReadUInt32();
            UncompressedSize = reader.ReadUInt32();
            ushort nameLength = reader.ReadUInt16();
            ushort extraLength = reader.ReadUInt16();
            ushort commentLength = reader.ReadUInt16();
            DiskNumberStart = reader.ReadUInt16();
            InternalFileAttributes = reader.ReadUInt16();
            ExternalFileAttributes = reader.ReadUInt32();
            RelativeOffsetOfEntryHeader = reader.ReadUInt32();

            Name = DefaultEncoding.GetString(reader.ReadBytes(nameLength));
            Extra = reader.ReadBytes(extraLength);
            Comment = reader.ReadBytes(commentLength);
        }