Exemplo n.º 1
0
 public void SetData(byte[] data, int index, int count)
 {
     using (MemoryStream stream = new MemoryStream(data, index, count, false))
     {
         using (ZipHelperStream stream2 = new ZipHelperStream(stream))
         {
             stream2.ReadLEInt();
             while (stream2.Position < stream2.Length)
             {
                 int num = stream2.ReadLEShort();
                 int num2 = stream2.ReadLEShort();
                 if (num == 1)
                 {
                     if (num2 >= 0x18)
                     {
                         long fileTime = stream2.ReadLELong();
                         this._lastModificationTime = DateTime.FromFileTime(fileTime);
                         long num4 = stream2.ReadLELong();
                         this._lastAccessTime = DateTime.FromFileTime(num4);
                         long num5 = stream2.ReadLELong();
                         this._createTime = DateTime.FromFileTime(num5);
                     }
                     return;
                 }
                 stream2.Seek((long) num2, SeekOrigin.Current);
             }
         }
     }
 }
Exemplo n.º 2
0
 public void SetData(byte[] data, int index, int count)
 {
     using (MemoryStream stream = new MemoryStream(data, index, count, false))
     {
         using (ZipHelperStream stream2 = new ZipHelperStream(stream))
         {
             int num;
             DateTime time;
             this._flags = (Flags) ((byte) stream2.ReadByte());
             if ((((byte) (this._flags & Flags.ModificationTime)) != 0) && (count >= 5))
             {
                 num = stream2.ReadLEInt();
                 time = new DateTime(0x7b2, 1, 1, 0, 0, 0);
                 time = time.ToUniversalTime() + new TimeSpan(0, 0, 0, num, 0);
                 this._modificationTime = time.ToLocalTime();
             }
             if (((byte) (this._flags & Flags.AccessTime)) != 0)
             {
                 num = stream2.ReadLEInt();
                 time = new DateTime(0x7b2, 1, 1, 0, 0, 0);
                 time = time.ToUniversalTime() + new TimeSpan(0, 0, 0, num, 0);
                 this._lastAccessTime = time.ToLocalTime();
             }
             if (((byte) (this._flags & Flags.CreateTime)) != 0)
             {
                 num = stream2.ReadLEInt();
                 time = new DateTime(0x7b2, 1, 1, 0, 0, 0);
                 this._createTime = (time.ToUniversalTime() + new TimeSpan(0, 0, 0, num, 0)).ToLocalTime();
             }
         }
     }
 }
Exemplo n.º 3
0
 public byte[] GetData()
 {
     byte[] buffer;
     using (MemoryStream stream = new MemoryStream())
     {
         using (ZipHelperStream stream2 = new ZipHelperStream(stream))
         {
             stream2.IsStreamOwner = false;
             stream2.WriteLEInt(0);
             stream2.WriteLEShort(1);
             stream2.WriteLEShort(0x18);
             stream2.WriteLELong(this._lastModificationTime.ToFileTime());
             stream2.WriteLELong(this._lastAccessTime.ToFileTime());
             stream2.WriteLELong(this._createTime.ToFileTime());
             buffer = stream.ToArray();
         }
     }
     return buffer;
 }
Exemplo n.º 4
0
 public byte[] GetData()
 {
     byte[] buffer;
     using (MemoryStream stream = new MemoryStream())
     {
         using (ZipHelperStream stream2 = new ZipHelperStream(stream))
         {
             TimeSpan span;
             int totalSeconds;
             DateTime time;
             stream2.IsStreamOwner = false;
             stream2.WriteByte((byte) this._flags);
             if (((byte) (this._flags & Flags.ModificationTime)) != 0)
             {
                 time = new DateTime(0x7b2, 1, 1, 0, 0, 0);
                 span = (TimeSpan) (this._modificationTime.ToUniversalTime() - time.ToUniversalTime());
                 totalSeconds = (int) span.TotalSeconds;
                 stream2.WriteLEInt(totalSeconds);
             }
             if (((byte) (this._flags & Flags.AccessTime)) != 0)
             {
                 time = new DateTime(0x7b2, 1, 1, 0, 0, 0);
                 span = (TimeSpan) (this._lastAccessTime.ToUniversalTime() - time.ToUniversalTime());
                 totalSeconds = (int) span.TotalSeconds;
                 stream2.WriteLEInt(totalSeconds);
             }
             if (((byte) (this._flags & Flags.CreateTime)) != 0)
             {
                 time = new DateTime(0x7b2, 1, 1, 0, 0, 0);
                 span = (TimeSpan) (this._createTime.ToUniversalTime() - time.ToUniversalTime());
                 totalSeconds = (int) span.TotalSeconds;
                 stream2.WriteLEInt(totalSeconds);
             }
             buffer = stream.ToArray();
         }
     }
     return buffer;
 }
Exemplo n.º 5
0
 private long LocateBlockWithSignature(int signature, long endLocation, int minimumBlockSize, int maximumVariableData)
 {
     using (ZipHelperStream stream = new ZipHelperStream(this.baseStream_))
     {
         return stream.LocateBlockWithSignature(signature, endLocation, minimumBlockSize, maximumVariableData);
     }
 }
Exemplo n.º 6
0
 public void CommitUpdate()
 {
     if (this.isDisposed_)
     {
         throw new ObjectDisposedException("ZipFile");
     }
     this.CheckUpdating();
     try
     {
         this.updateIndex_.Clear();
         this.updateIndex_ = null;
         if (this.contentsEdited_)
         {
             this.RunUpdates();
         }
         else if (this.commentEdited_)
         {
             this.UpdateCommentOnly();
         }
         else if (this.entries_.Length == 0)
         {
             byte[] comment = (this.newComment_ != null) ? this.newComment_.RawComment : ZipConstants.ConvertToArray(this.comment_);
             using (ZipHelperStream stream = new ZipHelperStream(this.baseStream_))
             {
                 stream.WriteEndOfCentralDirectory(0L, 0L, 0L, comment);
             }
         }
     }
     finally
     {
         this.PostUpdateCleanup();
     }
 }
Exemplo n.º 7
0
 private void UpdateCommentOnly()
 {
     long length = this.baseStream_.Length;
     ZipHelperStream stream = null;
     if (this.archiveStorage_.UpdateMode == FileUpdateMode.Safe)
     {
         stream = new ZipHelperStream(this.archiveStorage_.MakeTemporaryCopy(this.baseStream_)) {
             IsStreamOwner = true
         };
         this.baseStream_.Close();
         this.baseStream_ = null;
     }
     else if (this.archiveStorage_.UpdateMode == FileUpdateMode.Direct)
     {
         this.baseStream_ = this.archiveStorage_.OpenForDirectUpdate(this.baseStream_);
         stream = new ZipHelperStream(this.baseStream_);
     }
     else
     {
         this.baseStream_.Close();
         this.baseStream_ = null;
         stream = new ZipHelperStream(this.Name);
     }
     using (stream)
     {
         if (stream.LocateBlockWithSignature(0x6054b50, length, 0x16, 0xffff) < 0L)
         {
             throw new ZipException("Cannot find central directory");
         }
         stream.Position += 0x10L;
         byte[] rawComment = this.newComment_.RawComment;
         stream.WriteLEShort(rawComment.Length);
         stream.Write(rawComment, 0, rawComment.Length);
         stream.SetLength(stream.Position);
     }
     if (this.archiveStorage_.UpdateMode == FileUpdateMode.Safe)
     {
         this.Reopen(this.archiveStorage_.ConvertTemporaryToFinal());
     }
     else
     {
         this.ReadEntries();
     }
 }
Exemplo n.º 8
0
 public bool TestArchive(bool testData, TestStrategy strategy, ZipTestResultHandler resultHandler)
 {
     if (this.isDisposed_)
     {
         throw new ObjectDisposedException("ZipFile");
     }
     TestStatus status = new TestStatus(this);
     if (resultHandler != null)
     {
         resultHandler(status, null);
     }
     HeaderTest tests = testData ? (HeaderTest.Header | HeaderTest.Extract) : HeaderTest.Header;
     bool flag = true;
     try
     {
         for (int i = 0; flag && (i < this.Count); i++)
         {
             if (resultHandler != null)
             {
                 status.SetEntry(this[i]);
                 status.SetOperation(TestOperation.EntryHeader);
                 resultHandler(status, null);
             }
             try
             {
                 this.TestLocalHeader(this[i], tests);
             }
             catch (ZipException exception)
             {
                 status.AddError();
                 if (resultHandler != null)
                 {
                     resultHandler(status, string.Format("Exception during test - '{0}'", exception.Message));
                 }
                 if (strategy == TestStrategy.FindFirstError)
                 {
                     flag = false;
                 }
             }
             if ((flag && testData) && this[i].IsFile)
             {
                 if (resultHandler != null)
                 {
                     status.SetOperation(TestOperation.EntryData);
                     resultHandler(status, null);
                 }
                 Crc32 crc = new Crc32();
                 using (Stream stream = this.GetInputStream(this[i]))
                 {
                     int num3;
                     byte[] buffer = new byte[0x1000];
                     long num2 = 0L;
                     while ((num3 = stream.Read(buffer, 0, buffer.Length)) > 0)
                     {
                         crc.Update(buffer, 0, num3);
                         if (resultHandler != null)
                         {
                             num2 += num3;
                             status.SetBytesTested(num2);
                             resultHandler(status, null);
                         }
                     }
                 }
                 if (this[i].Crc != crc.Value)
                 {
                     status.AddError();
                     if (resultHandler != null)
                     {
                         resultHandler(status, "CRC mismatch");
                     }
                     if (strategy == TestStrategy.FindFirstError)
                     {
                         flag = false;
                     }
                 }
                 if ((this[i].Flags & 8) != 0)
                 {
                     ZipHelperStream stream2 = new ZipHelperStream(this.baseStream_);
                     DescriptorData data = new DescriptorData();
                     stream2.ReadDataDescriptor(this[i].LocalHeaderRequiresZip64, data);
                     if (this[i].Crc != data.Crc)
                     {
                         status.AddError();
                     }
                     if (this[i].CompressedSize != data.CompressedSize)
                     {
                         status.AddError();
                     }
                     if (this[i].Size != data.Size)
                     {
                         status.AddError();
                     }
                 }
             }
             if (resultHandler != null)
             {
                 status.SetOperation(TestOperation.EntryComplete);
                 resultHandler(status, null);
             }
         }
         if (resultHandler != null)
         {
             status.SetOperation(TestOperation.MiscellaneousTests);
             resultHandler(status, null);
         }
     }
     catch (Exception exception2)
     {
         status.AddError();
         if (resultHandler != null)
         {
             resultHandler(status, string.Format("Exception during test - '{0}'", exception2.Message));
         }
     }
     if (resultHandler != null)
     {
         status.SetOperation(TestOperation.Complete);
         status.SetEntry(null);
         resultHandler(status, null);
     }
     return (status.ErrorCount == 0);
 }
Exemplo n.º 9
0
        private void RunUpdates()
        {
            ZipFile file;
            long sizeEntries = 0L;
            long num2 = 0L;
            bool flag = false;
            long destinationPosition = 0L;
            if (this.IsNewArchive)
            {
                file = this;
                file.baseStream_.Position = 0L;
                flag = true;
            }
            else if (this.archiveStorage_.UpdateMode == FileUpdateMode.Direct)
            {
                file = this;
                file.baseStream_.Position = 0L;
                flag = true;
                this.updates_.Sort(new UpdateComparer());
            }
            else
            {
                file = Create(this.archiveStorage_.GetTemporaryOutput());
                file.UseZip64 = this.UseZip64;
                if (this.key != null)
                {
                    file.key = (byte[]) this.key.Clone();
                }
            }
            try
            {
                foreach (ZipUpdate update in this.updates_)
                {
                    if (update != null)
                    {
                        switch (update.Command)
                        {
                            case UpdateCommand.Copy:
                                if (!flag)
                                {
                                    goto Label_012E;
                                }
                                this.CopyEntryDirect(file, update, ref destinationPosition);
                                goto Label_0196;

                            case UpdateCommand.Modify:
                                this.ModifyEntry(file, update);
                                goto Label_0196;

                            case UpdateCommand.Add:
                                if (!(this.IsNewArchive || !flag))
                                {
                                    file.baseStream_.Position = destinationPosition;
                                }
                                this.AddEntry(file, update);
                                if (flag)
                                {
                                    destinationPosition = file.baseStream_.Position;
                                }
                                goto Label_0196;
                        }
                    }
                    goto Label_0196;
                Label_012E:
                    this.CopyEntry(file, update);
                Label_0196:;
                }
                if (!(this.IsNewArchive || !flag))
                {
                    file.baseStream_.Position = destinationPosition;
                }
                long position = file.baseStream_.Position;
                foreach (ZipUpdate update in this.updates_)
                {
                    if (update != null)
                    {
                        sizeEntries += file.WriteCentralDirectoryHeader(update.OutEntry);
                    }
                }
                byte[] comment = (this.newComment_ != null) ? this.newComment_.RawComment : ZipConstants.ConvertToArray(this.comment_);
                using (ZipHelperStream stream = new ZipHelperStream(file.baseStream_))
                {
                    stream.WriteEndOfCentralDirectory(this.updateCount_, sizeEntries, position, comment);
                }
                num2 = file.baseStream_.Position;
                foreach (ZipUpdate update in this.updates_)
                {
                    if (update != null)
                    {
                        if ((update.CrcPatchOffset > 0L) && (update.OutEntry.CompressedSize > 0L))
                        {
                            file.baseStream_.Position = update.CrcPatchOffset;
                            file.WriteLEInt((int) update.OutEntry.Crc);
                        }
                        if (update.SizePatchOffset > 0L)
                        {
                            file.baseStream_.Position = update.SizePatchOffset;
                            if (update.OutEntry.LocalHeaderRequiresZip64)
                            {
                                file.WriteLeLong(update.OutEntry.Size);
                                file.WriteLeLong(update.OutEntry.CompressedSize);
                            }
                            else
                            {
                                file.WriteLEInt((int) update.OutEntry.CompressedSize);
                                file.WriteLEInt((int) update.OutEntry.Size);
                            }
                        }
                    }
                }
            }
            catch
            {
                file.Close();
                if (!(flag || (file.Name == null)))
                {
                    File.Delete(file.Name);
                }
                throw;
            }
            if (flag)
            {
                file.baseStream_.SetLength(num2);
                file.baseStream_.Flush();
                this.isNewArchive_ = false;
                this.ReadEntries();
            }
            else
            {
                this.baseStream_.Close();
                this.Reopen(this.archiveStorage_.ConvertTemporaryToFinal());
            }
        }