コード例 #1
0
ファイル: ZipInputStream.cs プロジェクト: xuhaoa/LtePlatform
        public ZipEntry GetNextEntry()
        {
            if (_crc == null)
            {
                throw new InvalidOperationException("Closed.");
            }
            if (_entry != null)
            {
                CloseEntry();
            }
            var num = InputBuffer.ReadLeInt();

            switch (num)
            {
            case ZipConstants.CentralHeaderSignature:
            case ZipConstants.EndOfCentralDirectorySignature:
            case ZipConstants.CentralHeaderDigitalSignature:
            case ZipConstants.ArchiveExtraDataSignature:
            case 0x6064b50:
                Close();
                return(null);

            case 0x30304b50:
            case ZipConstants.SpanningSignature:
                num = InputBuffer.ReadLeInt();
                break;
            }
            if (num != ZipConstants.LocalHeaderSignature)
            {
                throw new ZipException("Wrong Local header signature: 0x" + $"{num:X}");
            }
            var versionRequiredToExtract = (short)InputBuffer.ReadLeShort();

            _flags  = InputBuffer.ReadLeShort();
            _method = InputBuffer.ReadLeShort();
            var num3 = (uint)InputBuffer.ReadLeInt();
            var num4 = InputBuffer.ReadLeInt();

            Csize = InputBuffer.ReadLeInt();
            _size = InputBuffer.ReadLeInt();
            var num5   = InputBuffer.ReadLeShort();
            var num6   = InputBuffer.ReadLeShort();
            var flag   = (_flags & 1) == 1;
            var buffer = new byte[num5];

            InputBuffer.ReadRawBuffer(buffer);
            var name = ZipConstants.ConvertToStringExt(_flags, buffer);

            _entry = new ZipEntry(name, versionRequiredToExtract)
            {
                Flags             = _flags,
                CompressionMethod = (CompressionMethod)_method
            };
            if ((_flags & 8) == 0)
            {
                _entry.Crc              = num4 & 0xffffffffL;
                _entry.Size             = _size & 0xffffffffL;
                _entry.CompressedSize   = 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)
            {
                var buffer2 = new byte[num6];
                InputBuffer.ReadRawBuffer(buffer2);
                _entry.ExtraData = buffer2;
            }
            _entry.ProcessExtraData(true);
            if (_entry.CompressedSize >= 0L)
            {
                Csize = _entry.CompressedSize;
            }
            if (_entry.Size >= 0L)
            {
                _size = _entry.Size;
            }
            if ((_method == 0) && ((!flag && (Csize != _size)) || (flag && ((Csize - 12L) != _size))))
            {
                throw new ZipException("Stored, but compressed != uncompressed");
            }
            if (_entry.IsCompressionMethodSupported())
            {
                _internalReader = InitialRead;
            }
            else
            {
                _internalReader = ReadingNotSupported;
            }
            return(_entry);
        }
コード例 #2
0
ファイル: ZipInputStream.cs プロジェクト: alfishe/ZXMAK2
        /// <summary>
        /// Advances to the next entry in the archive
        /// </summary>
        /// <returns>
        /// The next <see cref="ZipEntry">entry</see> in the archive or null if there are no more entries.
        /// </returns>
        /// <remarks>
        /// If the previous entry is still open <see cref="CloseEntry">CloseEntry</see> is called.
        /// </remarks>
        /// <exception cref="InvalidOperationException">
        /// Input stream is closed
        /// </exception>
        /// <exception cref="ZipException">
        /// Password is not set, password is invalid, compression method is invalid,
        /// version required to extract is not supported
        /// </exception>
        public ZipEntry GetNextEntry()
        {
            if (crc == null)
            {
                throw new InvalidOperationException("Closed.");
            }

            if (entry != null)
            {
                CloseEntry();
            }

            int header = inputBuffer.ReadLeInt();

            if (header == ZipConstants.CentralHeaderSignature ||
                header == ZipConstants.EndOfCentralDirectorySignature ||
                header == ZipConstants.CentralHeaderDigitalSignature ||
                header == ZipConstants.ArchiveExtraDataSignature ||
                header == ZipConstants.Zip64CentralFileHeaderSignature)
            {
                // No more individual entries exist
                Close();
                return(null);
            }

            // -jr- 07-Dec-2003 Ignore spanning temporary signatures if found
            // Spanning signature is same as descriptor signature and is untested as yet.
            if ((header == ZipConstants.SpanningTempSignature) || (header == ZipConstants.SpanningSignature))
            {
                header = inputBuffer.ReadLeInt();
            }

            if (header != ZipConstants.LocalHeaderSignature)
            {
                throw new ZipException("Wrong Local header signature: 0x" + String.Format("{0:X}", header));
            }

            short versionRequiredToExtract = (short)inputBuffer.ReadLeShort();

            flags  = inputBuffer.ReadLeShort();
            method = inputBuffer.ReadLeShort();
            uint dostime = (uint)inputBuffer.ReadLeInt();
            int  crc2    = inputBuffer.ReadLeInt();

            csize = inputBuffer.ReadLeInt();
            size  = inputBuffer.ReadLeInt();
            int nameLen  = inputBuffer.ReadLeShort();
            int extraLen = inputBuffer.ReadLeShort();

            bool isCrypted = (flags & 1) == 1;

            byte[] buffer = new byte[nameLen];
            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            = crc2 & 0xFFFFFFFFL;
                entry.Size           = size & 0xFFFFFFFFL;
                entry.CompressedSize = csize & 0xFFFFFFFFL;

                entry.CryptoCheckValue = (byte)(crc2 >> 24);
            }
            else
            {
                // This allows for GNU, WinZip and possibly other archives, the PKZIP spec
                // says these values are zero under these circumstances.
                if (crc2 != 0)
                {
                    entry.Crc = crc2 & 0xFFFFFFFFL;
                }

                if (size != 0)
                {
                    entry.Size = size & 0xFFFFFFFFL;
                }

                if (csize != 0)
                {
                    entry.CompressedSize = csize & 0xFFFFFFFFL;
                }

                entry.CryptoCheckValue = (byte)((dostime >> 8) & 0xff);
            }

            entry.DosTime = dostime;

            // If local header requires Zip64 is true then the extended header should contain
            // both values.

            // Handle extra data if present.  This can set/alter some fields of the entry.
            if (extraLen > 0)
            {
                byte[] extra = new byte[extraLen];
                inputBuffer.ReadRawBuffer(extra);
                entry.ExtraData = extra;
            }

            entry.ProcessExtraData(true);
            if (entry.CompressedSize >= 0)
            {
                csize = entry.CompressedSize;
            }

            if (entry.Size >= 0)
            {
                size = entry.Size;
            }

            if (method == (int)CompressionMethod.Stored && (!isCrypted && csize != size || (isCrypted && csize - ZipConstants.CryptoHeaderSize != size)))
            {
                throw new ZipException("Stored, but compressed != uncompressed");
            }

            // Determine how to handle reading of data if this is attempted.
            if (entry.IsCompressionMethodSupported())
            {
                internalReader = new ReaderDelegate(InitialRead);
            }
            else
            {
                internalReader = new ReaderDelegate(ReadingNotSupported);
            }

            return(entry);
        }
コード例 #3
0
        public ZipEntry GetNextEntry()
        {
            if (this.crc == null)
            {
                throw new InvalidOperationException("Closed.");
            }
            if (this.entry != null)
            {
                this.CloseEntry();
            }
            int num = this.inputBuffer.ReadLeInt();

            if (num == 33639248 || num == 101010256 || num == 84233040 || num == 117853008 || num == 101075792)
            {
                this.Close();
                return(null);
            }
            if (num == 808471376 || num == 134695760)
            {
                num = this.inputBuffer.ReadLeInt();
            }
            if (num != 67324752)
            {
                throw new ZipException("Wrong Local header signature: 0x" + string.Format("{0:X}", num));
            }
            short versionRequiredToExtract = (short)this.inputBuffer.ReadLeShort();

            this.flags  = this.inputBuffer.ReadLeShort();
            this.method = this.inputBuffer.ReadLeShort();
            uint num2 = (uint)this.inputBuffer.ReadLeInt();
            int  num3 = this.inputBuffer.ReadLeInt();

            this.csize = (long)this.inputBuffer.ReadLeInt();
            this.size  = (long)this.inputBuffer.ReadLeInt();
            int  num4 = this.inputBuffer.ReadLeShort();
            int  num5 = this.inputBuffer.ReadLeShort();
            bool flag = (this.flags & 1) == 1;

            byte[] array = new byte[num4];
            this.inputBuffer.ReadRawBuffer(array);
            string name = ZipConstants.ConvertToStringExt(this.flags, array);

            this.entry                   = new ZipEntry(name, (int)versionRequiredToExtract);
            this.entry.Flags             = this.flags;
            this.entry.CompressionMethod = (CompressionMethod)this.method;
            if ((this.flags & 8) == 0)
            {
                this.entry.Crc              = ((long)num3 & unchecked ((long)((ulong)-1)));
                this.entry.Size             = (this.size & unchecked ((long)((ulong)-1)));
                this.entry.CompressedSize   = (this.csize & unchecked ((long)((ulong)-1)));
                this.entry.CryptoCheckValue = (byte)(num3 >> 24);
            }
            else
            {
                if (num3 != 0)
                {
                    this.entry.Crc = ((long)num3 & unchecked ((long)((ulong)-1)));
                }
                if (this.size != 0L)
                {
                    this.entry.Size = (this.size & unchecked ((long)((ulong)-1)));
                }
                if (this.csize != 0L)
                {
                    this.entry.CompressedSize = (this.csize & unchecked ((long)((ulong)-1)));
                }
                this.entry.CryptoCheckValue = (byte)(num2 >> 8 & 255U);
            }
            this.entry.DosTime = (long)((ulong)num2);
            if (num5 > 0)
            {
                byte[] array2 = new byte[num5];
                this.inputBuffer.ReadRawBuffer(array2);
                this.entry.ExtraData = array2;
            }
            this.entry.ProcessExtraData(true);
            if (this.entry.CompressedSize >= 0L)
            {
                this.csize = this.entry.CompressedSize;
            }
            if (this.entry.Size >= 0L)
            {
                this.size = this.entry.Size;
            }
            if (this.method == 0 && ((!flag && this.csize != this.size) || (flag && this.csize - 12L != this.size)))
            {
                throw new ZipException("Stored, but compressed != uncompressed");
            }
            if (this.entry.IsCompressionMethodSupported())
            {
                this.internalReader = new ZipInputStream.ReaderDelegate(this.InitialRead);
            }
            else
            {
                this.internalReader = new ZipInputStream.ReaderDelegate(this.ReadingNotSupported);
            }
            return(this.entry);
        }