예제 #1
0
        private void ProcessAesExtraData(ZipExtraData extraData)
        {
            if (!extraData.Find(0x9901))
            {
                throw new ZipException("AES Extra Data missing");
            }
            _versionToExtract = 0x33;
            Flags            |= 0x40;
            int valueLength = extraData.ValueLength;

            if (valueLength < 7)
            {
                throw new ZipException("AES Extra Data Length " + valueLength + " invalid.");
            }
            extraData.ReadShort();
            extraData.ReadShort();
            int num3 = extraData.ReadByte();
            int num4 = extraData.ReadShort();

            _aesEncryptionStrength = num3;
            _method = (CompressionMethod)num4;
        }
예제 #2
0
파일: ZipEntry.cs 프로젝트: Basilid/Spheres
		/// <summary>
		/// Process extra data fields updating the entry based on the contents.
		/// </summary>
		/// <param name="localHeader">True if the extra data fields should be handled
		/// for a local header, rather than for a central header.
		/// </param>
		internal void ProcessExtraData(bool localHeader)
		{
			ZipExtraData extraData = new ZipExtraData(this.extra);

			if ( extraData.Find(0x0001) ) {
				if ( (versionToExtract & 0xff) < ZipConstants.VersionZip64 ) {
					throw new ZipException("Zip64 Extended information found but version is not valid");
				}

				// The recorded size will change but remember that this is zip64.
				forceZip64_ = true;

				if ( extraData.ValueLength < 4 ) {
					throw new ZipException("Extra data extended Zip64 information length is invalid");
				}

				if ( localHeader || (size == uint.MaxValue) ) {
					size = (ulong)extraData.ReadLong();
				}

				if ( localHeader || (compressedSize == uint.MaxValue) ) {
					compressedSize = (ulong)extraData.ReadLong();
				}

				if ( !localHeader && (offset == uint.MaxValue) ) {
					offset = extraData.ReadLong();
				}
			}
			else {
				if ( 
					((versionToExtract & 0xff) >= ZipConstants.VersionZip64) &&
					((size == uint.MaxValue) || (compressedSize == uint.MaxValue))
				) {
					throw new ZipException("Zip64 Extended information required but is missing.");
				}
			}

			if ( extraData.Find(10) ) {
				// No room for any tags.
				if ( extraData.ValueLength < 8 ) {
					throw new ZipException("NTFS Extra data invalid");
				}

				extraData.ReadInt(); // Reserved

				while ( extraData.UnreadCount >= 4 ) {
					int ntfsTag = extraData.ReadShort();
					int ntfsLength = extraData.ReadShort();
					if ( ntfsTag == 1 ) {
						if ( ntfsLength >= 24 ) {
							long lastModification = extraData.ReadLong();
							long lastAccess = extraData.ReadLong();
							long createTime = extraData.ReadLong();

							DateTime = System.DateTime.FromFileTime(lastModification);
						}
						break;
					}
					else {
						// An unknown NTFS tag so simply skip it.
						extraData.Skip(ntfsLength);
					}
				}
			}
			else if ( extraData.Find(0x5455) ) {
				int length = extraData.ValueLength;	
				int flags = extraData.ReadByte();
					
				// Can include other times but these are ignored.  Length of data should
				// actually be 1 + 4 * no of bits in flags.
				if ( ((flags & 1) != 0) && (length >= 5) ) {
					int iTime = extraData.ReadInt();

					DateTime = (new System.DateTime ( 1970, 1, 1, 0, 0, 0 ).ToUniversalTime() +
						new TimeSpan ( 0, 0, 0, iTime, 0 )).ToLocalTime();
				}
			}
		}
예제 #3
0
        internal void ProcessExtraData(bool localHeader)
        {
            ZipExtraData extraData = new ZipExtraData(_extra);

            if (extraData.Find(1))
            {
                _forceZip64 = true;
                if (extraData.ValueLength < 4)
                {
                    throw new ZipException("Extra data extended Zip64 information length is invalid");
                }
                if (localHeader || (_size == 0xffffffffL))
                {
                    _size = (ulong)extraData.ReadLong();
                }
                if (localHeader || (_compressedSize == 0xffffffffL))
                {
                    _compressedSize = (ulong)extraData.ReadLong();
                }
                if (!localHeader && (Offset == 0xffffffffL))
                {
                    Offset = extraData.ReadLong();
                }
            }
            else if (((_versionToExtract & 0xff) >= 0x2d) && ((_size == 0xffffffffL) || (_compressedSize == 0xffffffffL)))
            {
                throw new ZipException("Zip64 Extended information required but is missing.");
            }
            if (extraData.Find(10))
            {
                if (extraData.ValueLength < 4)
                {
                    throw new ZipException("NTFS Extra data invalid");
                }
                extraData.ReadInt();
                while (extraData.UnreadCount >= 4)
                {
                    int num    = extraData.ReadShort();
                    int amount = extraData.ReadShort();
                    if (num == 1)
                    {
                        if (amount >= 0x18)
                        {
                            long fileTime = extraData.ReadLong();
                            extraData.ReadLong();
                            extraData.ReadLong();
                            DateTime = DateTime.FromFileTime(fileTime);
                        }
                        break;
                    }
                    extraData.Skip(amount);
                }
            }
            else if (extraData.Find(0x5455))
            {
                int valueLength = extraData.ValueLength;
                if (((extraData.ReadByte() & 1) != 0) && (valueLength >= 5))
                {
                    int      seconds = extraData.ReadInt();
                    DateTime time    = new DateTime(0x7b2, 1, 1, 0, 0, 0);
                    DateTime = (time.ToUniversalTime() + new TimeSpan(0, 0, 0, seconds, 0)).ToLocalTime();
                }
            }
            if (_method == CompressionMethod.WinZipAes)
            {
                ProcessAesExtraData(extraData);
            }
        }
예제 #4
0
 internal void ProcessExtraData(bool localHeader)
 {
     ZipExtraData extraData = new ZipExtraData(_extra);
     if (extraData.Find(1))
     {
         _forceZip64 = true;
         if (extraData.ValueLength < 4)
         {
             throw new ZipException("Extra data extended Zip64 information length is invalid");
         }
         if (localHeader || (_size == 0xffffffffL))
         {
             _size = (ulong)extraData.ReadLong();
         }
         if (localHeader || (_compressedSize == 0xffffffffL))
         {
             _compressedSize = (ulong)extraData.ReadLong();
         }
         if (!localHeader && (Offset == 0xffffffffL))
         {
             Offset = extraData.ReadLong();
         }
     }
     else if (((_versionToExtract & 0xff) >= 0x2d) && ((_size == 0xffffffffL) || (_compressedSize == 0xffffffffL)))
     {
         throw new ZipException("Zip64 Extended information required but is missing.");
     }
     if (extraData.Find(10))
     {
         if (extraData.ValueLength < 4)
         {
             throw new ZipException("NTFS Extra data invalid");
         }
         extraData.ReadInt();
         while (extraData.UnreadCount >= 4)
         {
             int num = extraData.ReadShort();
             int amount = extraData.ReadShort();
             if (num == 1)
             {
                 if (amount >= 0x18)
                 {
                     long fileTime = extraData.ReadLong();
                     extraData.ReadLong();
                     extraData.ReadLong();
                     DateTime = DateTime.FromFileTime(fileTime);
                 }
                 break;
             }
             extraData.Skip(amount);
         }
     }
     else if (extraData.Find(0x5455))
     {
         int valueLength = extraData.ValueLength;
         if (((extraData.ReadByte() & 1) != 0) && (valueLength >= 5))
         {
             int seconds = extraData.ReadInt();
             DateTime time = new DateTime(0x7b2, 1, 1, 0, 0, 0);
             DateTime = (time.ToUniversalTime() + new TimeSpan(0, 0, 0, seconds, 0)).ToLocalTime();
         }
     }
     if (_method == CompressionMethod.WinZipAes)
     {
         ProcessAesExtraData(extraData);
     }
 }
예제 #5
0
 private void ProcessAesExtraData(ZipExtraData extraData)
 {
     if (!extraData.Find(0x9901))
     {
         throw new ZipException("AES Extra Data missing");
     }
     _versionToExtract = 0x33;
     Flags |= 0x40;
     int valueLength = extraData.ValueLength;
     if (valueLength < 7)
     {
         throw new ZipException("AES Extra Data Length " + valueLength + " invalid.");
     }
     extraData.ReadShort();
     extraData.ReadShort();
     int num3 = extraData.ReadByte();
     int num4 = extraData.ReadShort();
     _aesEncryptionStrength = num3;
     _method = (CompressionMethod)num4;
 }