Beispiel #1
0
 public ZipEntry(ZipEntry entry)
 {
     externalFileAttributes = -1;
     method = CompressionMethod.Deflated;
     zipFileIndex = -1L;
     if (entry == null)
     {
         throw new ArgumentNullException("entry");
     }
     known = entry.known;
     name = entry.name;
     size = entry.size;
     compressedSize = entry.compressedSize;
     crc = entry.crc;
     dosTime = entry.dosTime;
     method = entry.method;
     comment = entry.comment;
     versionToExtract = entry.versionToExtract;
     versionMadeBy = entry.versionMadeBy;
     externalFileAttributes = entry.externalFileAttributes;
     flags = entry.flags;
     zipFileIndex = entry.zipFileIndex;
     offset = entry.offset;
     forceZip64_ = entry.forceZip64_;
     if (entry.extra != null)
     {
         extra = new byte[entry.extra.Length];
         Array.Copy(entry.extra, 0, extra, 0, entry.extra.Length);
     }
 }
 public Stream GetSource(ZipEntry entry, string name)
 {
     Stream stream = null;
     if (name != null)
     {
         stream = File.Open(name, FileMode.Open, FileAccess.Read, FileShare.Read);
     }
     return stream;
 }
Beispiel #3
0
 private void WriteAESHeader(ZipEntry entry)
 {
     byte[] buffer;
     byte[] buffer2;
     InitializeAESPassword(entry, Password, out buffer, out buffer2);
     baseOutputStream_.Write(buffer, 0, buffer.Length);
     baseOutputStream_.Write(buffer2, 0, buffer2.Length);
 }
Beispiel #4
0
        public ZipEntry MakeDirectoryEntry(string directoryName, bool useFileSystem)
        {
            ZipEntry entry = new ZipEntry(nameTransform_.TransformDirectory(directoryName))
            {
                IsUnicodeText = isUnicodeText_,
                Size = 0L
            };
            int num = 0;
            DirectoryInfo info = null;
            if (useFileSystem)
            {
                info = new DirectoryInfo(directoryName);
            }
            if ((info == null) || !info.Exists)
            {
                if (timeSetting_ == TimeSetting.Fixed)
                {
                    entry.DateTime = fixedDateTime_;
                }
            }
            else
            {
                switch (timeSetting_)
                {
                    case TimeSetting.LastWriteTime:
                        entry.DateTime = info.LastWriteTime;
                        break;

                    case TimeSetting.LastWriteTimeUtc:
                        entry.DateTime = info.LastWriteTimeUtc;
                        break;

                    case TimeSetting.CreateTime:
                        entry.DateTime = info.CreationTime;
                        break;

                    case TimeSetting.CreateTimeUtc:
                        entry.DateTime = info.CreationTimeUtc;
                        break;

                    case TimeSetting.LastAccessTime:
                        entry.DateTime = info.LastAccessTime;
                        break;

                    case TimeSetting.LastAccessTimeUtc:
                        entry.DateTime = info.LastAccessTimeUtc;
                        break;

                    case TimeSetting.Fixed:
                        entry.DateTime = fixedDateTime_;
                        break;

                    default:
                        throw new ZipException("Unhandled time setting in MakeDirectoryEntry");
                }
                num = ((int)info.Attributes) & getAttributes_;
            }
            num |= setAttributes_ | 0x10;
            entry.ExternalFileAttributes = num;
            return entry;
        }
Beispiel #5
0
 public Stream GetInputStream(ZipEntry entry)
 {
     if (entry == null)
     {
         throw new ArgumentNullException("entry");
     }
     if (isDisposed_)
     {
         throw new ObjectDisposedException("ZipFile");
     }
     long zipFileIndex = entry.ZipFileIndex;
     if (((zipFileIndex < 0L) || (zipFileIndex >= entries_.Length)) || (entries_[(int)((IntPtr)zipFileIndex)].Name != entry.Name))
     {
         zipFileIndex = FindEntry(entry.Name, true);
         if (zipFileIndex < 0L)
         {
             throw new ZipException("Entry cannot be found");
         }
     }
     return GetInputStream(zipFileIndex);
 }
Beispiel #6
0
 public void Add(ZipEntry entry)
 {
     if (entry == null)
     {
         throw new ArgumentNullException("entry");
     }
     CheckUpdating();
     if ((entry.Size != 0L) || (entry.CompressedSize != 0L))
     {
         throw new ZipException("Entry cannot have any data");
     }
     AddUpdate(new ZipUpdate(UpdateCommand.Add, entry));
 }
Beispiel #7
0
 public ZipUpdate(IStaticDataSource dataSource, string entryName, CompressionMethod compressionMethod)
 {
     sizePatchOffset_ = -1L;
     crcPatchOffset_ = -1L;
     _offsetBasedSize = -1L;
     command_ = UpdateCommand.Add;
     entry_ = new ZipEntry(entryName);
     entry_.CompressionMethod = compressionMethod;
     dataSource_ = dataSource;
 }
Beispiel #8
0
 public ZipUpdate(UpdateCommand command, ZipEntry entry)
 {
     sizePatchOffset_ = -1L;
     crcPatchOffset_ = -1L;
     _offsetBasedSize = -1L;
     command_ = command;
     entry_ = (ZipEntry)entry.Clone();
 }
Beispiel #9
0
 private int FindExistingUpdate(ZipEntry entry)
 {
     int num = -1;
     string transformedFileName = GetTransformedFileName(entry.Name);
     if (updateIndex_.ContainsKey(transformedFileName))
     {
         num = (int)updateIndex_[transformedFileName];
     }
     return num;
 }
Beispiel #10
0
 private Stream CreateAndInitEncryptionStream(Stream baseStream, ZipEntry entry)
 {
     CryptoStream stream = null;
     if ((entry.Version < 50) || ((entry.Flags & 0x40) == 0))
     {
         PkzipClassicManaged managed = new PkzipClassicManaged();
         OnKeysRequired(entry.Name);
         if (!HaveKeys)
         {
             throw new ZipException("No password available for encrypted stream");
         }
         stream = new CryptoStream(new UncompressedStream(baseStream), managed.CreateEncryptor(key, null), CryptoStreamMode.Write);
         if ((entry.Crc < 0L) || ((entry.Flags & 8) != 0))
         {
             WriteEncryptionHeader(stream, entry.DosTime << 0x10);
             return stream;
         }
         WriteEncryptionHeader(stream, entry.Crc);
     }
     return stream;
 }
Beispiel #11
0
 private Stream CreateAndInitDecryptionStream(Stream baseStream, ZipEntry entry)
 {
     if ((entry.Version < 50) || ((entry.Flags & 0x40) == 0))
     {
         PkzipClassicManaged managed = new PkzipClassicManaged();
         OnKeysRequired(entry.Name);
         if (!HaveKeys)
         {
             throw new ZipException("No password available for encrypted stream");
         }
         CryptoStream classicCryptoStream
             = new CryptoStream(baseStream, managed.CreateDecryptor(key, null), CryptoStreamMode.Read);
         CheckClassicPassword(classicCryptoStream, entry);
         return classicCryptoStream;
     }
     if (entry.Version != 0x33)
     {
         throw new ZipException("Decryption method not supported");
     }
     OnKeysRequired(entry.Name);
     if (!HaveKeys)
     {
         throw new ZipException("No password available for AES encrypted stream");
     }
     int aESSaltLen = entry.AESSaltLen;
     byte[] buffer = new byte[aESSaltLen];
     int num2 = baseStream.Read(buffer, 0, aESSaltLen);
     if (num2 != aESSaltLen)
     {
         throw new ZipException(string.Concat(new object[] { "AES Salt expected ", aESSaltLen, " got ", num2 }));
     }
     byte[] buffer2 = new byte[2];
     baseStream.Read(buffer2, 0, 2);
     int blockSize = entry.AESKeySize / 8;
     ZipAESTransform transform = new ZipAESTransform(rawPassword_, buffer, blockSize, false);
     byte[] pwdVerifier = transform.PwdVerifier;
     if ((pwdVerifier[0] != buffer2[0]) || (pwdVerifier[1] != buffer2[1]))
     {
         throw new Exception("Invalid password for AES");
     }
     return new ZipAESStream(baseStream, transform, CryptoStreamMode.Read);
 }
Beispiel #12
0
 public int WriteDataDescriptor(ZipEntry entry)
 {
     if (entry == null)
     {
         throw new ArgumentNullException("entry");
     }
     int num = 0;
     if ((entry.Flags & 8) == 0)
     {
         return num;
     }
     WriteLEInt(0x8074b50);
     WriteLEInt((int)entry.Crc);
     num += 8;
     if (entry.LocalHeaderRequiresZip64)
     {
         WriteLELong(entry.CompressedSize);
         WriteLELong(entry.Size);
         return (num + 0x10);
     }
     WriteLEInt((int)entry.CompressedSize);
     WriteLEInt((int)entry.Size);
     return (num + 8);
 }
Beispiel #13
0
 private void ExtractFileEntry(ZipEntry entry, string targetName)
 {
     bool flag = true;
     if ((overwrite_ != Overwrite.Always) && File.Exists(targetName))
     {
         if ((overwrite_ == Overwrite.Prompt) && (confirmDelegate_ != null))
         {
             flag = confirmDelegate_(targetName);
         }
         else
         {
             flag = false;
         }
     }
     if (flag)
     {
         if (events_ != null)
         {
             continueRunning_ = events_.OnProcessFile(entry.Name);
         }
         if (continueRunning_)
         {
             try
             {
                 using (FileStream stream = File.Create(targetName))
                 {
                     if (buffer_ == null)
                     {
                         buffer_ = new byte[0x1000];
                     }
                     if ((events_ != null) && (events_.Progress != null))
                     {
                         StreamUtils.Copy(zipFile_.GetInputStream(entry), stream, buffer_, events_.Progress, events_.ProgressInterval, this, entry.Name, entry.Size);
                     }
                     else
                     {
                         StreamUtils.Copy(zipFile_.GetInputStream(entry), stream, buffer_);
                     }
                     if (events_ != null)
                     {
                         continueRunning_ = events_.OnCompletedFile(entry.Name);
                     }
                 }
                 if (restoreDateTimeOnExtract_)
                 {
                     File.SetLastWriteTime(targetName, entry.DateTime);
                 }
                 if ((RestoreAttributesOnExtract && entry.IsDOSEntry) && (entry.ExternalFileAttributes != -1))
                 {
                     FileAttributes fileAttributes = ((FileAttributes)entry.ExternalFileAttributes) & (FileAttributes.Normal | FileAttributes.Archive | FileAttributes.Hidden | FileAttributes.ReadOnly);
                     File.SetAttributes(targetName, fileAttributes);
                 }
             }
             catch (Exception exception)
             {
                 if (events_ == null)
                 {
                     continueRunning_ = false;
                     throw;
                 }
                 continueRunning_ = events_.OnFileFailure(targetName, exception);
             }
         }
     }
 }
Beispiel #14
0
 private void ExtractEntry(ZipEntry entry)
 {
     bool flag = entry.IsCompressionMethodSupported();
     string name = entry.Name;
     if (flag)
     {
         if (entry.IsFile)
         {
             name = extractNameTransform_.TransformFile(name);
         }
         else if (entry.IsDirectory)
         {
             name = extractNameTransform_.TransformDirectory(name);
         }
         flag = (name != null) && (name.Length != 0);
     }
     string path = null;
     if (flag)
     {
         if (entry.IsDirectory)
         {
             path = name;
         }
         else
         {
             path = Path.GetDirectoryName(Path.GetFullPath(name));
         }
     }
     if ((flag && !Directory.Exists(path)) && (!entry.IsDirectory || CreateEmptyDirectories))
     {
         try
         {
             Directory.CreateDirectory(path);
         }
         catch (Exception exception)
         {
             flag = false;
             if (events_ != null)
             {
                 if (entry.IsDirectory)
                 {
                     continueRunning_ = events_.OnDirectoryFailure(name, exception);
                 }
                 else
                 {
                     continueRunning_ = events_.OnFileFailure(name, exception);
                 }
             }
             else
             {
                 continueRunning_ = false;
                 throw;
             }
         }
     }
     if (flag && entry.IsFile)
     {
         ExtractFileEntry(entry, name);
     }
 }
Beispiel #15
0
 public void CloseEntry()
 {
     if (curEntry == null)
     {
         throw new InvalidOperationException("No open entry");
     }
     long compressedSize = size;
     if (curMethod == CompressionMethod.Deflated)
     {
         if (size >= 0L)
         {
             Finish();
             compressedSize = deflater_.TotalOut;
         }
         else
         {
             deflater_.Reset();
         }
     }
     if (curEntry.AESKeySize > 0)
     {
         baseOutputStream_.Write(AESAuthCode, 0, 10);
     }
     if (curEntry.Size < 0L)
     {
         curEntry.Size = size;
     }
     else if (curEntry.Size != size)
     {
         throw new ZipException(string.Concat(new object[] { "size was ", size, ", but I expected ", curEntry.Size }));
     }
     if (curEntry.CompressedSize < 0L)
     {
         curEntry.CompressedSize = compressedSize;
     }
     else if (curEntry.CompressedSize != compressedSize)
     {
         throw new ZipException(string.Concat(new object[] { "compressed size was ", compressedSize, ", but I expected ", curEntry.CompressedSize }));
     }
     if (curEntry.Crc < 0L)
     {
         curEntry.Crc = crc.Value;
     }
     else if (curEntry.Crc != crc.Value)
     {
         throw new ZipException(string.Concat(new object[] { "crc was ", crc.Value, ", but I expected ", curEntry.Crc }));
     }
     offset += compressedSize;
     if (curEntry.IsCrypted)
     {
         if (curEntry.AESKeySize > 0)
         {
             curEntry.CompressedSize += curEntry.AESOverheadSize;
         }
         else
         {
             curEntry.CompressedSize += 12L;
         }
     }
     if (patchEntryHeader)
     {
         patchEntryHeader = false;
         long position = baseOutputStream_.Position;
         baseOutputStream_.Seek(crcPatchPos, SeekOrigin.Begin);
         WriteLeInt((int)curEntry.Crc);
         if (curEntry.LocalHeaderRequiresZip64)
         {
             if (sizePatchPos == -1L)
             {
                 throw new ZipException("Entry requires zip64 but this has been turned off");
             }
             baseOutputStream_.Seek(sizePatchPos, SeekOrigin.Begin);
             WriteLeLong(curEntry.Size);
             WriteLeLong(curEntry.CompressedSize);
         }
         else
         {
             WriteLeInt((int)curEntry.CompressedSize);
             WriteLeInt((int)curEntry.Size);
         }
         baseOutputStream_.Seek(position, SeekOrigin.Begin);
     }
     if ((curEntry.Flags & 8) != 0)
     {
         WriteLeInt(0x8074b50);
         WriteLeInt((int)curEntry.Crc);
         if (curEntry.LocalHeaderRequiresZip64)
         {
             WriteLeLong(curEntry.CompressedSize);
             WriteLeLong(curEntry.Size);
             offset += 0x18L;
         }
         else
         {
             WriteLeInt((int)curEntry.CompressedSize);
             WriteLeInt((int)curEntry.Size);
             offset += 0x10L;
         }
     }
     entries.Add(curEntry);
     curEntry = null;
 }
Beispiel #16
0
 public ZipUpdate(IStaticDataSource dataSource, ZipEntry entry)
 {
     sizePatchOffset_ = -1L;
     crcPatchOffset_ = -1L;
     _offsetBasedSize = -1L;
     command_ = UpdateCommand.Add;
     entry_ = entry;
     dataSource_ = dataSource;
 }
Beispiel #17
0
 public ZipUpdate(ZipEntry original, ZipEntry updated)
 {
     sizePatchOffset_ = -1L;
     crcPatchOffset_ = -1L;
     _offsetBasedSize = -1L;
     throw new ZipException("Modify not currently supported");
 }
Beispiel #18
0
 private Stream GetOutputStream(ZipEntry entry)
 {
     Stream baseStream = baseStream_;
     if (entry.IsCrypted)
     {
         baseStream = CreateAndInitEncryptionStream(baseStream, entry);
     }
     CompressionMethod compressionMethod = entry.CompressionMethod;
     if (compressionMethod != CompressionMethod.Stored)
     {
         if (compressionMethod != CompressionMethod.Deflated)
         {
             throw new ZipException("Unknown compression method " + entry.CompressionMethod);
         }
     }
     else
     {
         return new UncompressedStream(baseStream);
     }
     return new DeflaterOutputStream(baseStream, new Deflater(9, true)) { IsStreamOwner = false };
 }
Beispiel #19
0
 public ZipUpdate(string fileName, ZipEntry entry)
 {
     sizePatchOffset_ = -1L;
     crcPatchOffset_ = -1L;
     _offsetBasedSize = -1L;
     command_ = UpdateCommand.Add;
     entry_ = entry;
     filename_ = fileName;
 }
Beispiel #20
0
 private long LocateEntry(ZipEntry entry)
 {
     return TestLocalHeader(entry, HeaderTest.Extract);
 }
Beispiel #21
0
 public ZipUpdate(string fileName, string entryName, CompressionMethod compressionMethod)
 {
     sizePatchOffset_ = -1L;
     crcPatchOffset_ = -1L;
     _offsetBasedSize = -1L;
     command_ = UpdateCommand.Add;
     entry_ = new ZipEntry(entryName);
     entry_.CompressionMethod = compressionMethod;
     filename_ = fileName;
 }
Beispiel #22
0
 private void ReadEntries()
 {
     if (!baseStream_.CanSeek)
     {
         throw new ZipException("ZipFile stream must be seekable");
     }
     long endLocation = LocateBlockWithSignature(0x6054b50, baseStream_.Length, 0x16, 0xffff);
     if (endLocation < 0L)
     {
         throw new ZipException("Cannot find central directory");
     }
     ushort num2 = ReadLEUshort();
     ushort num3 = ReadLEUshort();
     ulong num4 = ReadLEUshort();
     ulong num5 = ReadLEUshort();
     ulong num6 = ReadLEUint();
     long num7 = ReadLEUint();
     uint num8 = ReadLEUshort();
     if (num8 > 0)
     {
         byte[] buffer = new byte[num8];
         StreamUtils.ReadFully(baseStream_, buffer);
         comment_ = ZipConstants.ConvertToString(buffer);
     }
     else
     {
         comment_ = string.Empty;
     }
     bool flag = false;
     if ((((num2 == 0xffff) || (num3 == 0xffff)) || ((num4 == 0xffffL)
         || (num5 == 0xffffL))) || ((num6 == 0xffffffffL) || (num7 == 0xffffffffL)))
     {
         flag = true;
         if (LocateBlockWithSignature(0x7064b50, endLocation, 0, DefaultBufferSize) < 0L)
         {
             throw new ZipException("Cannot find Zip64 locator");
         }
         ReadLEUint();
         ulong num10 = ReadLEUlong();
         ReadLEUint();
         baseStream_.Position = (long)num10;
         long num11 = ReadLEUint();
         if (num11 != 0x6064b50L)
         {
             throw new ZipException(string.Format("Invalid Zip64 Central directory signature at {0:X}", num10));
         }
         ReadLEUlong();
         ReadLEUshort();
         ReadLEUshort();
         ReadLEUint();
         ReadLEUint();
         num4 = ReadLEUlong();
         num5 = ReadLEUlong();
         num6 = ReadLEUlong();
         num7 = (long)ReadLEUlong();
     }
     entries_ = new ZipEntry[num4];
     if (!flag && (num7 < (long)(((ulong)endLocation) - (4L + num6))))
     {
         offsetOfFirstEntry = endLocation - ((4L + ((long)num6)) + num7);
         if (offsetOfFirstEntry <= 0L)
         {
             throw new ZipException("Invalid embedded zip archive");
         }
     }
     baseStream_.Seek(offsetOfFirstEntry + num7, SeekOrigin.Begin);
     for (ulong i = 0L; i < num4; i += (ulong)1L)
     {
         if (ReadLEUint() != 0x2014b50)
         {
             throw new ZipException("Wrong Central Directory signature");
         }
         int madeByInfo = ReadLEUshort();
         int versionRequiredToExtract = ReadLEUshort();
         int flags = ReadLEUshort();
         int num16 = ReadLEUshort();
         uint num17 = ReadLEUint();
         uint num18 = ReadLEUint();
         long num19 = ReadLEUint();
         long num20 = ReadLEUint();
         int num21 = ReadLEUshort();
         int num22 = ReadLEUshort();
         int num23 = ReadLEUshort();
         ReadLEUshort();
         ReadLEUshort();
         uint num24 = ReadLEUint();
         long num25 = ReadLEUint();
         byte[] buffer2 = new byte[Math.Max(num21, num23)];
         StreamUtils.ReadFully(baseStream_, buffer2, 0, num21);
         ZipEntry entry = new ZipEntry(ZipConstants.ConvertToStringExt(flags, buffer2, num21), versionRequiredToExtract, madeByInfo, (CompressionMethod)num16)
         {
             Crc = num18 & 0xffffffffL,
             Size = num20 & 0xffffffffL,
             CompressedSize = num19 & 0xffffffffL,
             Flags = flags,
             DosTime = num17,
             ZipFileIndex = (long)i,
             Offset = num25,
             ExternalFileAttributes = (int)num24
         };
         if ((flags & 8) == 0)
         {
             entry.CryptoCheckValue = (byte)(num18 >> 0x18);
         }
         else
         {
             entry.CryptoCheckValue = (byte)((num17 >> 8) & 0xff);
         }
         if (num22 > 0)
         {
             byte[] buffer3 = new byte[num22];
             StreamUtils.ReadFully(baseStream_, buffer3);
             entry.ExtraData = buffer3;
         }
         entry.ProcessExtraData(false);
         if (num23 > 0)
         {
             StreamUtils.ReadFully(baseStream_, buffer2, 0, num23);
             entry.Comment = ZipConstants.ConvertToStringExt(flags, buffer2, num23);
         }
         entries_[(int)((IntPtr)i)] = entry;
     }
 }
Beispiel #23
0
 public void Delete(ZipEntry entry)
 {
     if (entry == null)
     {
         throw new ArgumentNullException("entry");
     }
     CheckUpdating();
     int num = FindExistingUpdate(entry);
     if (num < 0)
     {
         throw new ZipException("Cannot find entry to delete");
     }
     contentsEdited_ = true;
     updates_[num] = null;
     updateCount_ -= 1L;
 }
Beispiel #24
0
 private long TestLocalHeader(ZipEntry entry, HeaderTest tests)
 {
     lock (baseStream_)
     {
         bool flag = (tests & HeaderTest.Header) != 0;
         bool flag2 = (tests & HeaderTest.Extract) != 0;
         baseStream_.Seek(offsetOfFirstEntry + entry.Offset, SeekOrigin.Begin);
         if (ReadLEUint() != 0x4034b50)
         {
             throw new ZipException(string.Format("Wrong local header signature @{0:X}", offsetOfFirstEntry + entry.Offset));
         }
         short num = (short)ReadLEUshort();
         short flags = (short)ReadLEUshort();
         short num3 = (short)ReadLEUshort();
         short num4 = (short)ReadLEUshort();
         short num5 = (short)ReadLEUshort();
         uint num6 = ReadLEUint();
         long num7 = ReadLEUint();
         long num8 = ReadLEUint();
         int num9 = ReadLEUshort();
         int num10 = ReadLEUshort();
         byte[] buffer = new byte[num9];
         StreamUtils.ReadFully(baseStream_, buffer);
         byte[] buffer2 = new byte[num10];
         StreamUtils.ReadFully(baseStream_, buffer2);
         ZipExtraData data = new ZipExtraData(buffer2);
         if (data.Find(1))
         {
             num8 = data.ReadLong();
             num7 = data.ReadLong();
             if ((flags & 8) != 0)
             {
                 if ((num8 != -1L) && (num8 != entry.Size))
                 {
                     throw new ZipException("Size invalid for descriptor");
                 }
                 if ((num7 != -1L) && (num7 != entry.CompressedSize))
                 {
                     throw new ZipException("Compressed size invalid for descriptor");
                 }
             }
         }
         else if ((num >= 0x2d) && ((((uint)num8) == uint.MaxValue) || (((uint)num7) == uint.MaxValue)))
         {
             throw new ZipException("Required Zip64 extended information missing");
         }
         if (flag2 && entry.IsFile)
         {
             if (!entry.IsCompressionMethodSupported())
             {
                 throw new ZipException("Compression method not supported");
             }
             if ((num > 0x33) || ((num > 20) && (num < 0x2d)))
             {
                 throw new ZipException(string.Format("Version required to extract this entry not supported ({0})", num));
             }
             if ((flags & 0x3060) != 0)
             {
                 throw new ZipException("The library does not support the zip version required to extract this entry");
             }
         }
         if (flag)
         {
             if (((((num <= 0x3f) && (num != 10)) && ((num != 11) && (num != 20))) && (((num != 0x15) && (num != 0x19)) && ((num != 0x1b) && (num != 0x2d)))) && ((((num != 0x2e) && (num != 50)) && ((num != 0x33) && (num != 0x34))) && (((num != 0x3d) && (num != 0x3e)) && (num != 0x3f))))
             {
                 throw new ZipException(string.Format("Version required to extract this entry is invalid ({0})", num));
             }
             if ((flags & 0xc010) != 0)
             {
                 throw new ZipException("Reserved bit flags cannot be set.");
             }
             if (((flags & 1) != 0) && (num < 20))
             {
                 throw new ZipException(string.Format("Version required to extract this entry is too low for encryption ({0})", num));
             }
             if ((flags & 0x40) != 0)
             {
                 if ((flags & 1) == 0)
                 {
                     throw new ZipException("Strong encryption flag set but encryption flag is not set");
                 }
                 if (num < 50)
                 {
                     throw new ZipException(string.Format("Version required to extract this entry is too low for encryption ({0})", num));
                 }
             }
             if (((flags & 0x20) != 0) && (num < 0x1b))
             {
                 throw new ZipException(string.Format("Patched data requires higher version than ({0})", num));
             }
             if (flags != entry.Flags)
             {
                 throw new ZipException("Central header/local header flags mismatch");
             }
             if (entry.CompressionMethod != ((CompressionMethod)num3))
             {
                 throw new ZipException("Central header/local header compression method mismatch");
             }
             if (entry.Version != num)
             {
                 throw new ZipException("Extract version mismatch");
             }
             if (((flags & 0x40) != 0) && (num < 0x3e))
             {
                 throw new ZipException("Strong encryption flag set but version not high enough");
             }
             if (((flags & 0x2000) != 0) && ((num4 != 0) || (num5 != 0)))
             {
                 throw new ZipException("Header masked set but date/time values non-zero");
             }
             if (((flags & 8) == 0) && (num6 != ((uint)entry.Crc)))
             {
                 throw new ZipException("Central header/local header crc mismatch");
             }
             if (((num8 == 0L) && (num7 == 0L)) && (num6 != 0))
             {
                 throw new ZipException("Invalid CRC for empty entry");
             }
             if (entry.Name.Length > num9)
             {
                 throw new ZipException("File name length mismatch");
             }
             string name = ZipConstants.ConvertToStringExt(flags, buffer);
             if (name != entry.Name)
             {
                 throw new ZipException("Central header and local header file name mismatch");
             }
             if (entry.IsDirectory)
             {
                 if (num8 > 0L)
                 {
                     throw new ZipException("Directory cannot have size");
                 }
                 if (entry.IsCrypted)
                 {
                     if (num7 > 14L)
                     {
                         throw new ZipException("Directory compressed size invalid");
                     }
                 }
                 else if (num7 > 2L)
                 {
                     throw new ZipException("Directory compressed size invalid");
                 }
             }
             if (!ZipNameTransform.IsValidName(name, true))
             {
                 throw new ZipException("Name is invalid");
             }
         }
         if ((((flags & 8) == 0) || (num8 > 0L)) || (num7 > 0L))
         {
             if (num8 != entry.Size)
             {
                 throw new ZipException(string.Format("Size mismatch between central header({0}) and local header({1})", entry.Size, num8));
             }
             if (((num7 != entry.CompressedSize) && (num7 != 0xffffffffL)) && (num7 != -1L))
             {
                 throw new ZipException(string.Format("Compressed size mismatch between central header({0}) and local header({1})", entry.CompressedSize, num7));
             }
         }
         int num11 = num9 + num10;
         return (((offsetOfFirstEntry + entry.Offset) + 30L) + num11);
     }
 }
Beispiel #25
0
 private static void CheckClassicPassword(CryptoStream classicCryptoStream, ZipEntry entry)
 {
     byte[] buffer = new byte[12];
     StreamUtils.ReadFully(classicCryptoStream, buffer);
     if (buffer[11] != entry.CryptoCheckValue)
     {
         throw new ZipException("Invalid password");
     }
 }
Beispiel #26
0
 private int WriteCentralDirectoryHeader(ZipEntry entry)
 {
     if (entry.CompressedSize < 0L)
     {
         throw new ZipException("Attempt to write central directory entry with unknown csize");
     }
     if (entry.Size < 0L)
     {
         throw new ZipException("Attempt to write central directory entry with unknown size");
     }
     if (entry.Crc < 0L)
     {
         throw new ZipException("Attempt to write central directory entry with unknown crc");
     }
     WriteLEInt(0x2014b50);
     WriteLEShort(0x33);
     WriteLEShort(entry.Version);
     WriteLEShort(entry.Flags);
     WriteLEShort((byte)entry.CompressionMethod);
     WriteLEInt((int)entry.DosTime);
     WriteLEInt((int)entry.Crc);
     if (entry.IsZip64Forced() || (entry.CompressedSize >= 0xffffffffL))
     {
         WriteLEInt(-1);
     }
     else
     {
         WriteLEInt((int)(((ulong)entry.CompressedSize) & 0xffffffffL));
     }
     if (entry.IsZip64Forced() || (entry.Size >= 0xffffffffL))
     {
         WriteLEInt(-1);
     }
     else
     {
         WriteLEInt((int)entry.Size);
     }
     byte[] buffer = ZipConstants.ConvertToArray(entry.Flags, entry.Name);
     if (buffer.Length > 0xffff)
     {
         throw new ZipException("Entry name is too long.");
     }
     WriteLEShort(buffer.Length);
     ZipExtraData data = new ZipExtraData(entry.ExtraData);
     if (entry.CentralHeaderRequiresZip64)
     {
         data.StartNewEntry();
         if ((entry.Size >= 0xffffffffL) || (useZip64_ == UseZip64.On))
         {
             data.AddLeLong(entry.Size);
         }
         if ((entry.CompressedSize >= 0xffffffffL) || (useZip64_ == UseZip64.On))
         {
             data.AddLeLong(entry.CompressedSize);
         }
         if (entry.Offset >= 0xffffffffL)
         {
             data.AddLeLong(entry.Offset);
         }
         data.AddNewEntry(1);
     }
     else
     {
         data.Delete(1);
     }
     byte[] entryData = data.GetEntryData();
     WriteLEShort(entryData.Length);
     WriteLEShort((entry.Comment != null) ? entry.Comment.Length : 0);
     WriteLEShort(0);
     WriteLEShort(0);
     if (entry.ExternalFileAttributes != -1)
     {
         WriteLEInt(entry.ExternalFileAttributes);
     }
     else if (entry.IsDirectory)
     {
         WriteLEUint(0x10);
     }
     else
     {
         WriteLEUint(0);
     }
     if (entry.Offset >= 0xffffffffL)
     {
         WriteLEUint(uint.MaxValue);
     }
     else
     {
         WriteLEUint((uint)((int)entry.Offset));
     }
     if (buffer.Length > 0)
     {
         baseStream_.Write(buffer, 0, buffer.Length);
     }
     if (entryData.Length > 0)
     {
         baseStream_.Write(entryData, 0, entryData.Length);
     }
     byte[] buffer3 = (entry.Comment != null) ? Encoding.ASCII.GetBytes(entry.Comment) : new byte[0];
     if (buffer3.Length > 0)
     {
         baseStream_.Write(buffer3, 0, buffer3.Length);
     }
     return (((0x2e + buffer.Length) + entryData.Length) + buffer3.Length);
 }
Beispiel #27
0
        public ZipEntry MakeFileEntry(string fileName, bool useFileSystem)
        {
            ZipEntry entry = new ZipEntry(nameTransform_.TransformFile(fileName))
            {
                IsUnicodeText = isUnicodeText_
            };
            int num = 0;
            bool flag = setAttributes_ != 0;
            FileInfo info = null;
            if (useFileSystem)
            {
                info = new FileInfo(fileName);
            }
            if ((info == null) || !info.Exists)
            {
                if (timeSetting_ == TimeSetting.Fixed)
                {
                    entry.DateTime = fixedDateTime_;
                }
            }
            else
            {
                switch (timeSetting_)
                {
                    case TimeSetting.LastWriteTime:
                        entry.DateTime = info.LastWriteTime;
                        break;

                    case TimeSetting.LastWriteTimeUtc:
                        entry.DateTime = info.LastWriteTimeUtc;
                        break;

                    case TimeSetting.CreateTime:
                        entry.DateTime = info.CreationTime;
                        break;

                    case TimeSetting.CreateTimeUtc:
                        entry.DateTime = info.CreationTimeUtc;
                        break;

                    case TimeSetting.LastAccessTime:
                        entry.DateTime = info.LastAccessTime;
                        break;

                    case TimeSetting.LastAccessTimeUtc:
                        entry.DateTime = info.LastAccessTimeUtc;
                        break;

                    case TimeSetting.Fixed:
                        entry.DateTime = fixedDateTime_;
                        break;

                    default:
                        throw new ZipException("Unhandled time setting in MakeFileEntry");
                }
                entry.Size = info.Length;
                flag = true;
                num = ((int)info.Attributes) & getAttributes_;
            }
            if (flag)
            {
                num |= setAttributes_;
                entry.ExternalFileAttributes = num;
            }
            return entry;
        }
Beispiel #28
0
 public ZipEntryEnumerator(ZipEntry[] entries)
 {
     array = entries;
 }
Beispiel #29
0
 public ZipUpdate(ZipEntry entry)
     : this(UpdateCommand.Copy, entry)
 {
 }
Beispiel #30
0
 private static void AddExtraDataAES(ZipEntry entry, ZipExtraData extraData)
 {
     extraData.StartNewEntry();
     extraData.AddLeShort(2);
     extraData.AddLeShort(0x4541);
     extraData.AddData(entry.AESEncryptionStrength);
     extraData.AddLeShort((int)entry.CompressionMethod);
     extraData.AddNewEntry(0x9901);
 }