protected override void ReadFinish(MarkingBinaryReader reader) { var cryptVersion = reader.ReadRarVIntUInt32(); if (cryptVersion > CRYPT_VERSION) { //error? return; } var encryptionFlags = reader.ReadRarVIntUInt32(); _usePswCheck = FlagUtility.HasFlag(encryptionFlags, EncryptionFlagsV5.CHFL_CRYPT_PSWCHECK); _lg2Count = reader.ReadRarVIntByte(1); //UsePswCheck = HasHeaderFlag(EncryptionFlagsV5.CHFL_CRYPT_PSWCHECK); if (_lg2Count > CRYPT5_KDF_LG2_COUNT_MAX) { //error? return; } _salt = reader.ReadBytes(SIZE_SALT50); if (_usePswCheck) { _pswCheck = reader.ReadBytes(SIZE_PSWCHECK); _pswCheckCsm = reader.ReadBytes(SIZE_PSWCHECK_CSUM); } }
private void ReadLocator(MarkingBinaryReader reader) { var size = reader.ReadRarVIntUInt16(); var type = reader.ReadRarVIntUInt16(); if (type != 1) { throw new InvalidFormatException("expected locator record"); } var flags = reader.ReadRarVIntUInt16(); const ushort hasQuickOpenOffset = 0x01; const ushort hasRecoveryOffset = 0x02; ulong quickOpenOffset = 0; if ((flags & hasQuickOpenOffset) == hasQuickOpenOffset) { quickOpenOffset = reader.ReadRarVInt(); } ulong recoveryOffset = 0; if ((flags & hasRecoveryOffset) == hasRecoveryOffset) { recoveryOffset = reader.ReadRarVInt(); } }
protected override void ReadFromReader(MarkingBinaryReader reader) { UnpackVersion = reader.ReadByte(); Method = reader.ReadByte(); AVVersion = reader.ReadByte(); AVInfoCRC = reader.ReadInt32(); }
protected override void ReadFromReader(MarkingBinaryReader reader) { Version = reader.ReadByte(); RecSectors = reader.ReadUInt16(); TotalBlocks = reader.ReadUInt32(); Mark = reader.ReadBytes(8); }
protected override void ReadFinish(MarkingBinaryReader reader) { UnpackVersion = reader.ReadByte(); Method = reader.ReadByte(); AvVersion = reader.ReadByte(); AvInfoCrc = reader.ReadInt32(); }
protected override void ReadFinish(MarkingBinaryReader reader) { if (IsRar5) { Flags = reader.ReadRarVIntUInt16(); if (HasFlag(ArchiveFlagsV5.HAS_VOLUME_NUMBER)) { VolumeNumber = (int)reader.ReadRarVIntUInt32(); } // later: we may have a locator record if we need it //if (ExtraSize != 0) { // ReadLocator(reader); //} } else { Flags = HeaderFlags; HighPosAv = reader.ReadInt16(); PosAv = reader.ReadInt32(); if (HasFlag(ArchiveFlagsV4.ENCRYPT_VER)) { EncryptionVersion = reader.ReadByte(); } } }
protected override void ReadFromReader(MarkingBinaryReader reader) { UnpSize = reader.ReadInt16(); UnpVersion = reader.ReadByte(); UnpMethod = reader.ReadByte(); CommCRC = reader.ReadInt16(); }
protected override void ReadFromReader(MarkingBinaryReader reader) { ArchiveHeaderFlag = (ArchiveFlags)reader.ReadVInt(); if (ArchiveHeaderFlag.HasFlag(ArchiveFlags.VolumeNumberFieldIsPresented)) { VolumeNumber = reader.ReadVInt(); } }
protected override void ReadFromReader(MarkingBinaryReader reader) { HighPosAv = reader.ReadInt16(); PosAv = reader.ReadInt32(); if (ArchiveHeaderFlags.HasFlag(ArchiveFlags.ENCRYPTVER)) { EncryptionVersion = reader.ReadByte(); } }
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); } }
protected override void ReadFromReader(MarkingBinaryReader reader) { if (EndArchiveFlags.HasFlag(EndArchiveFlags.EARC_DATACRC)) { ArchiveCRC = reader.ReadInt32(); } if (EndArchiveFlags.HasFlag(EndArchiveFlags.EARC_VOLNUMBER)) { VolumeNumber = reader.ReadInt16(); } }
protected override void ReadFromReader(MarkingBinaryReader reader) { if (this.EndArchiveFlags_HasFlag(SharpCompress.Common.Rar.Headers.EndArchiveFlags.EARC_DATACRC)) { this.ArchiveCRC = new int?(reader.ReadInt32()); } if (this.EndArchiveFlags_HasFlag(SharpCompress.Common.Rar.Headers.EndArchiveFlags.EARC_VOLNUMBER)) { this.VolumeNumber = new short?(reader.ReadInt16()); } }
protected override void ReadFinish(MarkingBinaryReader reader) { if (IsRar5) { ReadFromReaderV5(reader); } else { ReadFromReaderV4(reader); } }
private static DateTime ReadExtendedTimeV5(MarkingBinaryReader reader, bool isWindowsTime) { if (isWindowsTime) { return(DateTime.FromFileTime(reader.ReadInt64())); } else { return(Utility.UnixTimeToDateTime(reader.ReadUInt32())); } }
protected override void ReadFromReader(MarkingBinaryReader reader) { EncriptionVersion = reader.ReadVInt(); EncriptionFlags = reader.ReadVInt(); KdfCount = reader.ReadByte(); Salt = reader.ReadBytes(16); if (PasswordCheckDataIsPresent) { CheckValue = reader.ReadBytes(12); } }
protected virtual void ReadFromReader(MarkingBinaryReader reader) { HeadCRC = reader.ReadInt16(); HeaderType = (HeaderType)(int)(reader.ReadByte() & 0xff); Flags = reader.ReadInt16(); HeaderSize = reader.ReadInt16(); if (FlagUtility.HasFlag(Flags, LONG_BLOCK)) { AdditionalSize = reader.ReadUInt32(); } }
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); }
protected virtual void ReadFromReader(MarkingBinaryReader reader) { this.HeadCRC = reader.ReadInt16(); this.HeaderType = ((SharpCompress.Common.Rar.Headers.HeaderType)reader.ReadByte()) & ((SharpCompress.Common.Rar.Headers.HeaderType) 0xff); this.Flags = reader.ReadInt16(); this.HeaderSize = reader.ReadInt16(); if (FlagUtility.HasFlag((short)this.Flags, (short)-32768)) { this.AdditionalSize = reader.ReadUInt32(); } }
internal static RarHeader Create(MarkingBinaryReader reader) { try { RarHeader header = new RarHeader(); reader.Mark(); header.ReadFromReader(reader); header.ReadBytes += reader.CurrentReadByteCount; return(header); } catch (EndOfStreamException) { return(null); } }
internal T PromoteHeader <T>(MarkingBinaryReader reader) where T : RarHeader, new() { T local = Activator.CreateInstance <T>(); local.FillBase(this); reader.Mark(); local.ReadFromReader(reader); local.ReadBytes += reader.CurrentReadByteCount; int count = local.HeaderSize - ((int)local.ReadBytes); if (count > 0) { reader.ReadBytes(count); } return(local); }
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 ReadFinish(MarkingBinaryReader reader) { if (IsRar5) { Flags = reader.ReadRarVIntUInt16(); } else { Flags = HeaderFlags; if (HasFlag(EndArchiveFlagsV4.DATA_CRC)) { ArchiveCrc = reader.ReadInt32(); } if (HasFlag(EndArchiveFlagsV4.VOLUME_NUMBER)) { VolumeNumber = reader.ReadInt16(); } } }
internal T PromoteHeader <T>(MarkingBinaryReader reader) where T : RarHeader, new() { T header = new T(); header.FillBase(this); reader.Mark(); header.ReadFromReader(reader); header.ReadBytes += reader.CurrentReadByteCount; int headerSizeDiff = header.HeaderSize - (int)header.ReadBytes; if (headerSizeDiff > 0) { reader.ReadBytes(headerSizeDiff); } return(header); }
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); }
protected virtual void PostReadingBytes(MarkingBinaryReader reader) { }
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))); }
protected override void ReadFromReader(MarkingBinaryReader reader) { uint lowUncompressedSize = reader.ReadUInt32(); HostOS = (HostOS)(int)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)) { 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); } }
protected override void ReadFromReader(MarkingBinaryReader reader) { CreationTime = reader.ReadInt32(); ArcNameSize = reader.ReadInt16(); UserNameSize = reader.ReadInt16(); }
private RarHeader ReadNextHeader(Stream stream) { #if !NO_CRYPTO var reader = new RarCryptoBinaryReader(stream, Options.Password); if (IsEncrypted) { if (Options.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, Options.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); } } }
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); } }