示例#1
0
        private void WriteArchiveEpilogue(long startOfCentralDirectory, long sizeOfCentralDirectory)
        {
            bool flag = false;

            if (((startOfCentralDirectory >= 0xffffffffL) || (sizeOfCentralDirectory >= 0xffffffffL)) || (_entries.Count >= 0xffff))
            {
                flag = true;
            }
            if (flag)
            {
                long position = ArchiveStream1.Position;
                Zip64EndOfCentralDirectoryRecord.WriteBlock(ArchiveStream1, (long)_entries.Count, startOfCentralDirectory, sizeOfCentralDirectory);
                Zip64EndOfCentralDirectoryLocator.WriteBlock(ArchiveStream1, position);
            }
            ZipEndOfCentralDirectoryBlock.WriteBlock(ArchiveStream1, (long)_entries.Count, startOfCentralDirectory, sizeOfCentralDirectory, _archiveComment);
        }
        public static bool TryReadBlock(BinaryReader reader, out ZipEndOfCentralDirectoryBlock eocdBlock)
        {
            eocdBlock = new ZipEndOfCentralDirectoryBlock();
            if (reader.ReadUInt32() != 0x6054b50)
            {
                return(false);
            }
            eocdBlock.Signature        = 0x6054b50;
            eocdBlock.NumberOfThisDisk = reader.ReadUInt16();
            eocdBlock.NumberOfTheDiskWithTheStartOfTheCentralDirectory = reader.ReadUInt16();
            eocdBlock.NumberOfEntriesInTheCentralDirectoryOnThisDisk   = reader.ReadUInt16();
            eocdBlock.NumberOfEntriesInTheCentralDirectory             = reader.ReadUInt16();
            eocdBlock.SizeOfCentralDirectory = reader.ReadUInt32();
            eocdBlock.OffsetOfStartOfCentralDirectoryWithRespectToTheStartingDiskNumber = reader.ReadUInt32();
            ushort count = reader.ReadUInt16();

            eocdBlock.ArchiveComment = reader.ReadBytes(count);
            return(true);
        }
示例#3
0
 private void ReadEndOfCentralDirectory()
 {
     try
     {
         ZipEndOfCentralDirectoryBlock block;
         ArchiveStream1.Seek(-18L, SeekOrigin.End);
         if (!ZipHelper.SeekBackwardsToSignature(ArchiveStream1, 0x6054b50))
         {
             throw new InvalidDataException(Messages.EOCDNotFound);
         }
         long position = ArchiveStream1.Position;
         ZipEndOfCentralDirectoryBlock.TryReadBlock(_archiveReader, out block);
         if (block.NumberOfThisDisk != block.NumberOfTheDiskWithTheStartOfTheCentralDirectory)
         {
             throw new InvalidDataException(Messages.SplitSpanned);
         }
         _numberOfThisDisk      = block.NumberOfThisDisk;
         _centralDirectoryStart = block.OffsetOfStartOfCentralDirectoryWithRespectToTheStartingDiskNumber;
         if (block.NumberOfEntriesInTheCentralDirectory != block.NumberOfEntriesInTheCentralDirectoryOnThisDisk)
         {
             throw new InvalidDataException(Messages.SplitSpanned);
         }
         _expectedNumberOfEntries = block.NumberOfEntriesInTheCentralDirectory;
         if (_mode == ZipArchiveMode.Update)
         {
             _archiveComment = block.ArchiveComment;
         }
         if (((block.NumberOfThisDisk == 0xffff) || (block.OffsetOfStartOfCentralDirectoryWithRespectToTheStartingDiskNumber == uint.MaxValue)) || (block.NumberOfEntriesInTheCentralDirectory == 0xffff))
         {
             ArchiveStream1.Seek(position - 0x10L, SeekOrigin.Begin);
             if (ZipHelper.SeekBackwardsToSignature(ArchiveStream1, 0x7064b50))
             {
                 Zip64EndOfCentralDirectoryLocator locator;
                 Zip64EndOfCentralDirectoryRecord  record;
                 Zip64EndOfCentralDirectoryLocator.TryReadBlock(_archiveReader, out locator);
                 if (locator.OffsetOfZip64EOCD > 0x7fffffffffffffffL)
                 {
                     throw new InvalidDataException(Messages.FieldTooBigOffsetToZip64EOCD);
                 }
                 long offset = (long)locator.OffsetOfZip64EOCD;
                 ArchiveStream1.Seek(offset, SeekOrigin.Begin);
                 if (!Zip64EndOfCentralDirectoryRecord.TryReadBlock(_archiveReader, out record))
                 {
                     throw new InvalidDataException(Messages.Zip64EOCDNotWhereExpected);
                 }
                 _numberOfThisDisk = record.NumberOfThisDisk;
                 if (record.NumberOfEntriesTotal > 0x7fffffffffffffffL)
                 {
                     throw new InvalidDataException(Messages.FieldTooBigNumEntries);
                 }
                 if (record.OffsetOfCentralDirectory > 0x7fffffffffffffffL)
                 {
                     throw new InvalidDataException(Messages.FieldTooBigOffsetToCD);
                 }
                 if (record.NumberOfEntriesTotal != record.NumberOfEntriesOnThisDisk)
                 {
                     throw new InvalidDataException(Messages.SplitSpanned);
                 }
                 _expectedNumberOfEntries = (long)record.NumberOfEntriesTotal;
                 _centralDirectoryStart   = (long)record.OffsetOfCentralDirectory;
             }
         }
         if (_centralDirectoryStart > ArchiveStream1.Length)
         {
             throw new InvalidDataException(Messages.FieldTooBigOffsetToCD);
         }
     }
     catch (EndOfStreamException exception)
     {
         throw new InvalidDataException(Messages.CDCorrupt, exception);
     }
     catch (IOException exception2)
     {
         throw new InvalidDataException(Messages.CDCorrupt, exception2);
     }
 }