예제 #1
0
파일: ZipEntry.cs 프로젝트: vjmira/fomm
        /// <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)
        {
            var extraData = new ZipExtraData(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)
                {
                    var ntfsTag    = extraData.ReadShort();
                    var ntfsLength = extraData.ReadShort();
                    if (ntfsTag == 1)
                    {
                        if (ntfsLength >= 24)
                        {
                            var lastModification = extraData.ReadLong();
                            //long lastAccess = extraData.ReadLong();
                            //long createTime = extraData.ReadLong();
                            extraData.Skip(16);

                            DateTime = DateTime.FromFileTime(lastModification);
                        }
                        break;
                    }
                    // An unknown NTFS tag so simply skip it.
                    extraData.Skip(ntfsLength);
                }
            }
            else if (extraData.Find(0x5455))
            {
                var length = extraData.ValueLength;
                var 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))
                {
                    var iTime = extraData.ReadInt();

                    DateTime = (new DateTime(1970, 1, 1, 0, 0, 0).ToUniversalTime() +
                                new TimeSpan(0, 0, 0, iTime, 0)).ToLocalTime();
                }
            }
        }
예제 #2
0
    /// <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)
    {
      var extraData = new ZipExtraData(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)
        {
          var ntfsTag = extraData.ReadShort();
          var ntfsLength = extraData.ReadShort();
          if (ntfsTag == 1)
          {
            if (ntfsLength >= 24)
            {
              var lastModification = extraData.ReadLong();
              //long lastAccess = extraData.ReadLong();
              //long createTime = extraData.ReadLong();
              extraData.Skip(16);

              DateTime = DateTime.FromFileTime(lastModification);
            }
            break;
          }
          // An unknown NTFS tag so simply skip it.
          extraData.Skip(ntfsLength);
        }
      }
      else if (extraData.Find(0x5455))
      {
        var length = extraData.ValueLength;
        var 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))
        {
          var iTime = extraData.ReadInt();

          DateTime = (new DateTime(1970, 1, 1, 0, 0, 0).ToUniversalTime() +
                      new TimeSpan(0, 0, 0, iTime, 0)).ToLocalTime();
        }
      }
    }