Esempio n. 1
0
 protected override void ReadFromReader(MarkingBinaryReader reader)
 {
     UnpSize    = reader.ReadInt16();
     UnpVersion = reader.ReadByte();
     UnpMethod  = reader.ReadByte();
     CommCRC    = reader.ReadInt16();
 }
Esempio n. 2
0
 protected override void ReadFromReader(MarkingBinaryReader reader)
 {
     UnpackVersion = reader.ReadByte();
     Method        = reader.ReadByte();
     AVVersion     = reader.ReadByte();
     AVInfoCRC     = reader.ReadInt32();
 }
Esempio n. 3
0
 protected override void ReadFinish(MarkingBinaryReader reader)
 {
     UnpackVersion = reader.ReadByte();
     Method        = reader.ReadByte();
     AvVersion     = reader.ReadByte();
     AvInfoCrc     = reader.ReadInt32();
 }
Esempio n. 4
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)));
        }
Esempio n. 5
0
 protected override void ReadFromReader(MarkingBinaryReader reader)
 {
     Version     = reader.ReadByte();
     RecSectors  = reader.ReadUInt16();
     TotalBlocks = reader.ReadUInt32();
     Mark        = reader.ReadBytes(8);
 }
Esempio n. 6
0
 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();
         }
     }
 }
Esempio n. 7
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))));
        }
Esempio n. 8
0
 protected override void ReadFromReader(MarkingBinaryReader reader)
 {
     HighPosAv = reader.ReadInt16();
     PosAv     = reader.ReadInt32();
     if (ArchiveHeaderFlags.HasFlag(ArchiveFlags.ENCRYPTVER))
     {
         EncryptionVersion = reader.ReadByte();
     }
 }
Esempio n. 9
0
 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();
     }
 }
Esempio n. 10
0
 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();
     }
 }
Esempio n. 11
0
 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);
     }
 }
Esempio n. 12
0
        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);
            }
        }
Esempio n. 13
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);
            }
        }
Esempio n. 14
0
        private void ReadFromReaderV4(MarkingBinaryReader reader)
        {
            Flags      = HeaderFlags;
            IsSolid    = HasFlag(FileFlagsV4.SOLID);
            WindowSize = IsDirectory ? 0U : ((size_t)0x10000) << ((Flags & FileFlagsV4.WINDOW_MASK) >> 5);

            uint lowUncompressedSize = reader.ReadUInt32();

            HostOs = reader.ReadByte();

            FileCrc = reader.ReadUInt32();

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

            CompressionAlgorithm = reader.ReadByte();
            CompressionMethod    = (byte)(reader.ReadByte() - 0x30);

            short nameSize = reader.ReadInt16();

            FileAttributes = reader.ReadUInt32();

            uint highCompressedSize    = 0;
            uint highUncompressedkSize = 0;

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

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

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

            const int saltSize   = 8;
            const int newLhdSize = 32;

            switch (HeaderCode)
            {
            case HeaderCodeV.RAR4_FILE_HEADER:
            {
                if (HasFlag(FileFlagsV4.UNICODE))
                {
                    int length = 0;
                    while (length < fileNameBytes.Length &&
                           fileNameBytes[length] != 0)
                    {
                        length++;
                    }
                    if (length != nameSize)
                    {
                        length++;
                        FileName = FileNameDecoder.Decode(fileNameBytes, length);
                    }
                    else
                    {
                        FileName = ArchiveEncoding.Decode(fileNameBytes);
                    }
                }
                else
                {
                    FileName = ArchiveEncoding.Decode(fileNameBytes);
                }
                FileName = ConvertPathV4(FileName);
            }
            break;

            case HeaderCodeV.RAR4_NEW_SUB_HEADER:
            {
                int datasize = HeaderSize - newLhdSize - nameSize;
                if (HasFlag(FileFlagsV4.SALT))
                {
                    datasize -= saltSize;
                }
                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 (HasFlag(FileFlagsV4.SALT))
            {
                R4Salt = reader.ReadBytes(saltSize);
            }
            if (HasFlag(FileFlagsV4.EXT_TIME))
            {
                // 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 (RemainingHeaderBytes(reader) >= 2)
                {
                    ushort extendedFlags = reader.ReadUInt16();
                    FileLastModifiedTime = ProcessExtendedTimeV4(extendedFlags, FileLastModifiedTime, reader, 0);
                    FileCreatedTime      = ProcessExtendedTimeV4(extendedFlags, null, reader, 1);
                    FileLastAccessedTime = ProcessExtendedTimeV4(extendedFlags, null, reader, 2);
                    FileArchivedTime     = ProcessExtendedTimeV4(extendedFlags, null, reader, 3);
                }
            }
        }