ConvertToStringExt() public static method

Convert a byte array to string
public static ConvertToStringExt ( int flags, byte data ) : string
flags int The applicable general purpose bits flags
data byte /// Byte array to convert ///
return string
Example #1
0
        /// <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
#if NET45
                Close();
#endif
#if NETSTANDARD1_3
                Dispose();
#endif
                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));
            }

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

            flags  = inputBuffer.ReadLeShort();
            method = inputBuffer.ReadLeShort();
            var 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) & 0xff);
            }
            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 ReadDataHandler(InitialRead);
            }
            else
            {
                internalReader = new ReadDataHandler(ReadingNotSupported);
            }

            return(entry);
        }
        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 & (long)((ulong)-1));
                this.entry.Size             = (this.size & (long)((ulong)-1));
                this.entry.CompressedSize   = (this.csize & (long)((ulong)-1));
                this.entry.CryptoCheckValue = (byte)(num3 >> 24 & 255);
            }
            else
            {
                if (num3 != 0)
                {
                    this.entry.Crc = ((long)num3 & (long)((ulong)-1));
                }
                if (this.size != 0L)
                {
                    this.entry.Size = (this.size & (long)((ulong)-1));
                }
                if (this.csize != 0L)
                {
                    this.entry.CompressedSize = (this.csize & (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.ReadDataHandler(this.InitialRead);
            }
            else
            {
                this.internalReader = new ZipInputStream.ReadDataHandler(this.ReadingNotSupported);
            }
            return(this.entry);
        }
Example #3
0
        public ZipEntry GetNextEntry()
        {
            //IL_000d: Unknown result type (might be due to invalid IL or missing references)
            if (crc == null)
            {
                throw new InvalidOperationException("Closed.");
            }
            if (entry != null)
            {
                CloseEntry();
            }
            int num = inputBuffer.ReadLeInt();

            switch (num)
            {
            case 33639248:
            case 84233040:
            case 101010256:
            case 101075792:
            case 117853008:
                ((Stream)this).Close();
                return(null);

            case 134695760:
            case 808471376:
                num = inputBuffer.ReadLeInt();
                break;
            }
            if (num != 67324752)
            {
                throw new ZipException("Wrong Local header signature: 0x" + $"{num:X}");
            }
            short versionRequiredToExtract = (short)inputBuffer.ReadLeShort();

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

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

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

            entry                   = new ZipEntry(name, versionRequiredToExtract);
            entry.Flags             = flags;
            entry.CompressionMethod = (CompressionMethod)method;
            if ((flags & 8) == 0)
            {
                entry.Crc              = num3 & 0xFFFFFFFFu;
                entry.Size             = size & 0xFFFFFFFFu;
                entry.CompressedSize   = csize & 0xFFFFFFFFu;
                entry.CryptoCheckValue = (byte)((uint)(num3 >> 24) & 0xFFu);
            }
            else
            {
                if (num3 != 0)
                {
                    entry.Crc = num3 & 0xFFFFFFFFu;
                }
                if (size != 0)
                {
                    entry.Size = size & 0xFFFFFFFFu;
                }
                if (csize != 0)
                {
                    entry.CompressedSize = csize & 0xFFFFFFFFu;
                }
                entry.CryptoCheckValue = (byte)((num2 >> 8) & 0xFFu);
            }
            entry.DosTime = num2;
            if (num5 > 0)
            {
                byte[] array2 = new byte[num5];
                inputBuffer.ReadRawBuffer(array2);
                entry.ExtraData = array2;
            }
            entry.ProcessExtraData(localHeader: true);
            if (entry.CompressedSize >= 0)
            {
                csize = entry.CompressedSize;
            }
            if (entry.Size >= 0)
            {
                size = entry.Size;
            }
            if (method == 0 && ((!flag && csize != size) || (flag && csize - 12 != size)))
            {
                throw new ZipException("Stored, but compressed != uncompressed");
            }
            if (entry.IsCompressionMethodSupported())
            {
                internalReader = InitialRead;
            }
            else
            {
                internalReader = ReadingNotSupported;
            }
            return(entry);
        }
Example #4
0
        public ZipEntry GetNextEntry()
        {
            if (this.crc == null)
            {
                throw new InvalidOperationException("Closed.");
            }
            if (this.entry != null)
            {
                this.CloseEntry();
            }
            int num = base.inputBuffer.ReadLeInt();

            switch (num)
            {
            case 0x2014b50:
            case 0x6054b50:
            case 0x5054b50:
            case 0x7064b50:
            case 0x6064b50:
                this.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();

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

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

            byte[] buffer = new byte[num5];
            base.inputBuffer.ReadRawBuffer(buffer);
            string name = ZipConstants.ConvertToStringExt(this.flags, buffer);

            this.entry                   = new ZipEntry(name, versionRequiredToExtract);
            this.entry.Flags             = this.flags;
            this.entry.CompressionMethod = (CompressionMethod)this.method;
            if ((this.flags & 8) == 0)
            {
                this.entry.Crc              = num4 & ((long)0xffffffffL);
                this.entry.Size             = this.size & ((long)0xffffffffL);
                this.entry.CompressedSize   = base.csize & ((long)0xffffffffL);
                this.entry.CryptoCheckValue = (byte)((num4 >> 0x18) & 0xff);
            }
            else
            {
                if (num4 != 0)
                {
                    this.entry.Crc = num4 & ((long)0xffffffffL);
                }
                if (this.size != 0L)
                {
                    this.entry.Size = this.size & ((long)0xffffffffL);
                }
                if (base.csize != 0L)
                {
                    this.entry.CompressedSize = base.csize & ((long)0xffffffffL);
                }
                this.entry.CryptoCheckValue = (byte)((num3 >> 8) & 0xff);
            }
            this.entry.DosTime = num3;
            if (num6 > 0)
            {
                byte[] buffer2 = new byte[num6];
                base.inputBuffer.ReadRawBuffer(buffer2);
                this.entry.ExtraData = buffer2;
            }
            this.entry.ProcessExtraData(true);
            if (this.entry.CompressedSize >= 0L)
            {
                base.csize = this.entry.CompressedSize;
            }
            if (this.entry.Size >= 0L)
            {
                this.size = this.entry.Size;
            }
            if ((this.method == 0) && ((!flag && (base.csize != this.size)) || (flag && ((base.csize - 12L) != this.size))))
            {
                throw new ZipException("Stored, but compressed != uncompressed");
            }
            if (this.entry.IsCompressionMethodSupported())
            {
                this.internalReader = new ReadDataHandler(this.InitialRead);
            }
            else
            {
                this.internalReader = new ReadDataHandler(this.ReadingNotSupported);
            }
            return(this.entry);
        }
        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)
            {
                Close();
                return(null);
            }


            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) & 0xff);
            }
            else
            {
                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 (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");
            }

            if (entry.IsCompressionMethodSupported())
            {
                internalReader = new ReadDataHandler(InitialRead);
            }
            else
            {
                internalReader = new ReadDataHandler(ReadingNotSupported);
            }

            return(entry);
        }