Пример #1
0
 public override void Close()
 {
     this.internalReader = new ZipInputStream.ReadDataHandler(this.ReadingNotAvailable);
     this.crc            = null;
     this.entry          = null;
     base.Close();
 }
Пример #2
0
 private int InitialRead(byte[] destination, int offset, int count)
 {
     if (!this.CanDecompressEntry)
     {
         throw new ZipException("Library cannot extract this entry. Version required is (" + this.entry.Version + ")");
     }
     if (this.entry.IsCrypted)
     {
         if (this.password == null)
         {
             throw new ZipException("No password set.");
         }
         PkzipClassicManaged pkzipClassicManaged = new PkzipClassicManaged();
         byte[] rgbKey = PkzipClassic.GenerateKeys(ZipConstants.ConvertToArray(this.password));
         this.inputBuffer.CryptoTransform = pkzipClassicManaged.CreateDecryptor(rgbKey, null);
         byte[] array = new byte[12];
         this.inputBuffer.ReadClearTextBuffer(array, 0, 12);
         if (array[11] != this.entry.CryptoCheckValue)
         {
             throw new ZipException("Invalid password");
         }
         if (this.csize >= 12L)
         {
             this.csize -= 12L;
         }
         else if ((this.entry.Flags & 8) == 0)
         {
             throw new ZipException(string.Format("Entry compressed size {0} too small for encryption", this.csize));
         }
     }
     else
     {
         this.inputBuffer.CryptoTransform = null;
     }
     if (this.csize > 0L || (this.flags & 8) != 0)
     {
         if (this.method == 8 && this.inputBuffer.Available > 0)
         {
             this.inputBuffer.SetInflaterInput(this.inf);
         }
         this.internalReader = new ZipInputStream.ReadDataHandler(this.BodyRead);
         return(this.BodyRead(destination, offset, count));
     }
     this.internalReader = new ZipInputStream.ReadDataHandler(this.ReadingNotAvailable);
     return(0);
 }
Пример #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 & (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);
        }
Пример #4
0
 public ZipInputStream(Stream baseInputStream, int bufferSize) : base(baseInputStream, new Inflater(true), bufferSize)
 {
     this.internalReader = new ZipInputStream.ReadDataHandler(this.ReadingNotAvailable);
 }