예제 #1
0
파일: ZipFile.cs 프로젝트: ouyh18/LteTools
 private void ReadEntries()
 {
     if (!baseStream_.CanSeek)
     {
         throw new ZipException("ZipFile stream must be seekable");
     }
     long endLocation = LocateBlockWithSignature(0x6054b50, baseStream_.Length, 0x16, 0xffff);
     if (endLocation < 0L)
     {
         throw new ZipException("Cannot find central directory");
     }
     ushort num2 = ReadLEUshort();
     ushort num3 = ReadLEUshort();
     ulong num4 = ReadLEUshort();
     ulong num5 = ReadLEUshort();
     ulong num6 = ReadLEUint();
     long num7 = ReadLEUint();
     uint num8 = ReadLEUshort();
     if (num8 > 0)
     {
         byte[] buffer = new byte[num8];
         StreamUtils.ReadFully(baseStream_, buffer);
         comment_ = ZipConstants.ConvertToString(buffer);
     }
     else
     {
         comment_ = string.Empty;
     }
     bool flag = false;
     if ((((num2 == 0xffff) || (num3 == 0xffff)) || ((num4 == 0xffffL)
         || (num5 == 0xffffL))) || ((num6 == 0xffffffffL) || (num7 == 0xffffffffL)))
     {
         flag = true;
         if (LocateBlockWithSignature(0x7064b50, endLocation, 0, DefaultBufferSize) < 0L)
         {
             throw new ZipException("Cannot find Zip64 locator");
         }
         ReadLEUint();
         ulong num10 = ReadLEUlong();
         ReadLEUint();
         baseStream_.Position = (long)num10;
         long num11 = ReadLEUint();
         if (num11 != 0x6064b50L)
         {
             throw new ZipException(string.Format("Invalid Zip64 Central directory signature at {0:X}", num10));
         }
         ReadLEUlong();
         ReadLEUshort();
         ReadLEUshort();
         ReadLEUint();
         ReadLEUint();
         num4 = ReadLEUlong();
         num5 = ReadLEUlong();
         num6 = ReadLEUlong();
         num7 = (long)ReadLEUlong();
     }
     entries_ = new ZipEntry[num4];
     if (!flag && (num7 < (long)(((ulong)endLocation) - (4L + num6))))
     {
         offsetOfFirstEntry = endLocation - ((4L + ((long)num6)) + num7);
         if (offsetOfFirstEntry <= 0L)
         {
             throw new ZipException("Invalid embedded zip archive");
         }
     }
     baseStream_.Seek(offsetOfFirstEntry + num7, SeekOrigin.Begin);
     for (ulong i = 0L; i < num4; i += (ulong)1L)
     {
         if (ReadLEUint() != 0x2014b50)
         {
             throw new ZipException("Wrong Central Directory signature");
         }
         int madeByInfo = ReadLEUshort();
         int versionRequiredToExtract = ReadLEUshort();
         int flags = ReadLEUshort();
         int num16 = ReadLEUshort();
         uint num17 = ReadLEUint();
         uint num18 = ReadLEUint();
         long num19 = ReadLEUint();
         long num20 = ReadLEUint();
         int num21 = ReadLEUshort();
         int num22 = ReadLEUshort();
         int num23 = ReadLEUshort();
         ReadLEUshort();
         ReadLEUshort();
         uint num24 = ReadLEUint();
         long num25 = ReadLEUint();
         byte[] buffer2 = new byte[Math.Max(num21, num23)];
         StreamUtils.ReadFully(baseStream_, buffer2, 0, num21);
         ZipEntry entry = new ZipEntry(ZipConstants.ConvertToStringExt(flags, buffer2, num21), versionRequiredToExtract, madeByInfo, (CompressionMethod)num16)
         {
             Crc = num18 & 0xffffffffL,
             Size = num20 & 0xffffffffL,
             CompressedSize = num19 & 0xffffffffL,
             Flags = flags,
             DosTime = num17,
             ZipFileIndex = (long)i,
             Offset = num25,
             ExternalFileAttributes = (int)num24
         };
         if ((flags & 8) == 0)
         {
             entry.CryptoCheckValue = (byte)(num18 >> 0x18);
         }
         else
         {
             entry.CryptoCheckValue = (byte)((num17 >> 8) & 0xff);
         }
         if (num22 > 0)
         {
             byte[] buffer3 = new byte[num22];
             StreamUtils.ReadFully(baseStream_, buffer3);
             entry.ExtraData = buffer3;
         }
         entry.ProcessExtraData(false);
         if (num23 > 0)
         {
             StreamUtils.ReadFully(baseStream_, buffer2, 0, num23);
             entry.Comment = ZipConstants.ConvertToStringExt(flags, buffer2, num23);
         }
         entries_[(int)((IntPtr)i)] = entry;
     }
 }
예제 #2
0
        public ZipEntry GetNextEntry()
        {
            if (crc == null)
            {
                throw new InvalidOperationException("Closed.");
            }
            if (entry != null)
            {
                CloseEntry();
            }
            int num = base.inputBuffer.ReadLeInt();
            switch (num)
            {
                case 0x2014b50:
                case 0x6054b50:
                case 0x5054b50:
                case 0x7064b50:
                case 0x6064b50:
                    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();
            flags = base.inputBuffer.ReadLeShort();
            method = base.inputBuffer.ReadLeShort();
            uint num3 = (uint)base.inputBuffer.ReadLeInt();
            int num4 = base.inputBuffer.ReadLeInt();
            base.csize = base.inputBuffer.ReadLeInt();
            size = base.inputBuffer.ReadLeInt();
            int num5 = base.inputBuffer.ReadLeShort();
            int num6 = base.inputBuffer.ReadLeShort();
            bool flag = (flags & 1) == 1;
            byte[] buffer = new byte[num5];
            base.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 = num4 & 0xffffffffL;
                entry.Size = size & 0xffffffffL;
                entry.CompressedSize = base.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)
            {
                byte[] buffer2 = new byte[num6];
                inputBuffer.ReadRawBuffer(buffer2);
                entry.ExtraData = buffer2;
            }
            entry.ProcessExtraData(true);
            if (entry.CompressedSize >= 0L)
            {
                base.csize = entry.CompressedSize;
            }
            if (entry.Size >= 0L)
            {
                size = entry.Size;
            }
            if ((method == 0) && ((!flag && (base.csize != size)) || (flag && ((base.csize - 12L) != size))))
            {
                throw new ZipException("Stored, but compressed != uncompressed");
            }
            if (entry.IsCompressionMethodSupported())
            {
                internalReader = InitialRead;
            }
            else
            {
                internalReader = ReadingNotSupported;
            }
            return entry;
        }