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); } }
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); } }
public ZipEntry GetNextEntry() { if (crc == null) { throw new InvalidOperationException("Closed."); } if (entry != null) { CloseEntry(); } int num = base.inputBuffer.ReadLeInt(); switch (num) { case 0x2014b50: case 0x6054b50: case 0x5054b50: case 0x7064b50: case 0x6064b50: Close(); return null; case 0x30304b50: case 0x8074b50: num = base.inputBuffer.ReadLeInt(); break; } if (num != 0x4034b50) { throw new ZipException("Wrong Local header signature: 0x" + string.Format("{0:X}", num)); } short versionRequiredToExtract = (short)base.inputBuffer.ReadLeShort(); flags = base.inputBuffer.ReadLeShort(); method = base.inputBuffer.ReadLeShort(); uint num3 = (uint)base.inputBuffer.ReadLeInt(); int num4 = base.inputBuffer.ReadLeInt(); base.csize = base.inputBuffer.ReadLeInt(); size = base.inputBuffer.ReadLeInt(); int num5 = base.inputBuffer.ReadLeShort(); int num6 = base.inputBuffer.ReadLeShort(); bool flag = (flags & 1) == 1; byte[] buffer = new byte[num5]; base.inputBuffer.ReadRawBuffer(buffer); string name = ZipConstants.ConvertToStringExt(flags, buffer); entry = new ZipEntry(name, versionRequiredToExtract); entry.Flags = flags; entry.CompressionMethod = (CompressionMethod)method; if ((flags & 8) == 0) { entry.Crc = num4 & 0xffffffffL; entry.Size = size & 0xffffffffL; entry.CompressedSize = base.csize & 0xffffffffL; entry.CryptoCheckValue = (byte)((num4 >> 0x18) & 0xff); } else { if (num4 != 0) { entry.Crc = num4 & 0xffffffffL; } if (size != 0L) { entry.Size = size & 0xffffffffL; } if (csize != 0L) { entry.CompressedSize = csize & 0xffffffffL; } entry.CryptoCheckValue = (byte)((num3 >> 8) & 0xff); } entry.DosTime = num3; if (num6 > 0) { byte[] buffer2 = new byte[num6]; inputBuffer.ReadRawBuffer(buffer2); entry.ExtraData = buffer2; } entry.ProcessExtraData(true); if (entry.CompressedSize >= 0L) { base.csize = entry.CompressedSize; } if (entry.Size >= 0L) { size = entry.Size; } if ((method == 0) && ((!flag && (base.csize != size)) || (flag && ((base.csize - 12L) != size)))) { throw new ZipException("Stored, but compressed != uncompressed"); } if (entry.IsCompressionMethodSupported()) { internalReader = InitialRead; } else { internalReader = ReadingNotSupported; } return entry; }