Exemple #1
0
            internal void ProcessExtraData(bool localHeader)
            {
                StiZipExtraData extraData = new StiZipExtraData(this.extra);

                if (extraData.Find(0x0001))
                {
                    //forceZip64_ = true;

                    if (extraData.ValueLength < 4)
                    {
                        throw new StiZipException("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();
                    }
                }

                if (method == CompressionMethod.WinZipAES)
                {
                    throw new StiZipException("Encryption is not supported");
                }
            }
Exemple #2
0
        private long LocateEntry(StiZipEntry entry)
        {
            _baseStream.Seek(offsetOfFirstEntry + entry.Offset, SeekOrigin.Begin);
            if ((int)ReadLEUint() != StiZipConstants.LocalHeaderSignature)
            {
                throw new StiZipException(string.Format("Wrong local header signature @{0:X}",
                                                        offsetOfFirstEntry + entry.Offset));
            }

            short extractVersion    = (short)ReadLEUshort();
            short localFlags        = (short)ReadLEUshort();
            short compressionMethod = (short)ReadLEUshort();
            short fileTime          = (short)ReadLEUshort();
            short fileDate          = (short)ReadLEUshort();
            uint  crcValue          = ReadLEUint();
            long  compressedSize    = ReadLEUint();
            long  size             = ReadLEUint();
            int   storedNameLength = ReadLEUshort();
            int   extraDataLength  = ReadLEUshort();

            byte[] nameData = new byte[storedNameLength];
            Utils.ReadFully(_baseStream, nameData);

            byte[] extraData = new byte[extraDataLength];
            Utils.ReadFully(_baseStream, extraData);

            StiZipExtraData localExtraData = new StiZipExtraData(extraData);

            if (entry.IsFile)
            {
                if (!entry.IsCompressionMethodSupported())
                {
                    throw new StiZipException("Compression method not supported");
                }

                if ((extractVersion > StiZipConstants.VersionMadeBy) ||
                    ((extractVersion > 20) && (extractVersion < StiZipConstants.VersionZip64)) ||
                    ((localFlags &
                      (int)
                      (GeneralBitFlags.Patched | GeneralBitFlags.StrongEncryption | GeneralBitFlags.EnhancedCompress |
                       GeneralBitFlags.HeaderMasked)) != 0))
                {
                    throw new StiZipException("The library does not support the zip version required to extract this entry");
                }
            }

            int extraLength = storedNameLength + extraDataLength;

            return(offsetOfFirstEntry + entry.Offset + StiZipConstants.LocalHeaderBaseSize + extraLength);
        }