public static bool TryReadBlock(BinaryReader reader, out Zip64EndOfCentralDirectoryLocator zip64EOCDLocator)
 {
     zip64EOCDLocator = new Zip64EndOfCentralDirectoryLocator();
     if (reader.ReadUInt32() != 0x7064b50)
     {
         return(false);
     }
     zip64EOCDLocator.NumberOfDiskWithZip64EOCD = reader.ReadUInt32();
     zip64EOCDLocator.OffsetOfZip64EOCD         = reader.ReadUInt64();
     zip64EOCDLocator.TotalNumberOfDisks        = reader.ReadUInt32();
     return(true);
 }
Exemplo n.º 2
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);
        }
Exemplo n.º 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);
     }
 }