コード例 #1
0
ファイル: ExtendedUnixData.cs プロジェクト: ouyh18/LteTools
 public void SetData(byte[] data, int index, int count)
 {
     using (MemoryStream stream = new MemoryStream(data, index, count, false))
     {
         using (ZipHelperStream stream2 = new ZipHelperStream(stream))
         {
             _flags = (Flags)((byte)stream2.ReadByte());
             if ((((byte)(_flags & Flags.ModificationTime)) != 0) && (count >= 5))
             {
                 int seconds = stream2.ReadLEInt();
                 DateTime time = new DateTime(0x7b2, 1, 1, 0, 0, 0);
                 _modificationTime = (time.ToUniversalTime() + new TimeSpan(0, 0, 0, seconds, 0)).ToLocalTime();
             }
             if (((byte)(_flags & Flags.AccessTime)) != 0)
             {
                 int num2 = stream2.ReadLEInt();
                 DateTime time3 = new DateTime(0x7b2, 1, 1, 0, 0, 0);
                 _lastAccessTime = (time3.ToUniversalTime() + new TimeSpan(0, 0, 0, num2, 0)).ToLocalTime();
             }
             if (((byte)(_flags & Flags.CreateTime)) != 0)
             {
                 int num3 = stream2.ReadLEInt();
                 DateTime time5 = new DateTime(0x7b2, 1, 1, 0, 0, 0);
                 _createTime = (time5.ToUniversalTime() + new TimeSpan(0, 0, 0, num3, 0)).ToLocalTime();
             }
         }
     }
 }
コード例 #2
0
ファイル: ZipFile.cs プロジェクト: ouyh18/LteTools
 public bool TestArchive(bool testData, 
     TestStrategy strategy = TestStrategy.FindFirstError, 
     ZipTestResultHandler resultHandler = null)
 {
     if (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 < Count); i++)
         {
             if (resultHandler != null)
             {
                 status.SetEntry(this[i]);
                 status.SetOperation(TestOperation.EntryHeader);
                 resultHandler(status, null);
             }
             try
             {
                 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 = GetInputStream(this[i]))
                 {
                     int num3;
                     byte[] buffer = new byte[DefaultBufferSize];
                     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(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);
 }
コード例 #3
0
ファイル: ExtendedUnixData.cs プロジェクト: ouyh18/LteTools
 public byte[] GetData()
 {
     byte[] buffer;
     using (MemoryStream stream = new MemoryStream())
     {
         using (ZipHelperStream stream2 = new ZipHelperStream(stream))
         {
             stream2.IsStreamOwner = false;
             stream2.WriteByte((byte)_flags);
             if (((byte)(_flags & Flags.ModificationTime)) != 0)
             {
                 DateTime time = new DateTime(0x7b2, 1, 1, 0, 0, 0);
                 TimeSpan span = _modificationTime.ToUniversalTime() - time.ToUniversalTime();
                 int totalSeconds = (int)span.TotalSeconds;
                 stream2.WriteLEInt(totalSeconds);
             }
             if (((byte)(_flags & Flags.AccessTime)) != 0)
             {
                 DateTime time2 = new DateTime(0x7b2, 1, 1, 0, 0, 0);
                 TimeSpan span2 = _lastAccessTime.ToUniversalTime() - time2.ToUniversalTime();
                 int num2 = (int)span2.TotalSeconds;
                 stream2.WriteLEInt(num2);
             }
             if (((byte)(_flags & Flags.CreateTime)) != 0)
             {
                 DateTime time3 = new DateTime(0x7b2, 1, 1, 0, 0, 0);
                 TimeSpan span3 = _createTime.ToUniversalTime() - time3.ToUniversalTime();
                 int num3 = (int)span3.TotalSeconds;
                 stream2.WriteLEInt(num3);
             }
             buffer = stream.ToArray();
         }
     }
     return buffer;
 }
コード例 #4
0
ファイル: ZipFile.cs プロジェクト: ouyh18/LteTools
 public void CommitUpdate()
 {
     if (isDisposed_)
     {
         throw new ObjectDisposedException("ZipFile");
     }
     CheckUpdating();
     try
     {
         updateIndex_.Clear();
         updateIndex_ = null;
         if (contentsEdited_)
         {
             RunUpdates();
         }
         else if (commentEdited_)
         {
             UpdateCommentOnly();
         }
         else if (entries_.Length == 0)
         {
             byte[] comment = (newComment_ != null) ? newComment_.RawComment : ZipConstants.ConvertToArray(comment_);
             using (ZipHelperStream stream = new ZipHelperStream(baseStream_))
             {
                 stream.WriteEndOfCentralDirectory(0L, 0L, 0L, comment);
             }
         }
     }
     finally
     {
         PostUpdateCleanup();
     }
 }
コード例 #5
0
ファイル: ZipFile.cs プロジェクト: ouyh18/LteTools
 private void UpdateCommentOnly()
 {
     long length = baseStream_.Length;
     ZipHelperStream stream;
     if (archiveStorage_.UpdateMode == FileUpdateMode.Safe)
     {
         stream = new ZipHelperStream(archiveStorage_.MakeTemporaryCopy(baseStream_))
         {
             IsStreamOwner = true
         };
         baseStream_.Close();
         baseStream_ = null;
     }
     else if (archiveStorage_.UpdateMode == FileUpdateMode.Direct)
     {
         baseStream_ = archiveStorage_.OpenForDirectUpdate(baseStream_);
         stream = new ZipHelperStream(baseStream_);
     }
     else
     {
         baseStream_.Close();
         baseStream_ = null;
         stream = new ZipHelperStream(Name);
     }
     using (stream)
     {
         if (stream.LocateBlockWithSignature(0x6054b50, length, 0x16, 0xffff) < 0L)
         {
             throw new ZipException("Cannot find central directory");
         }
         stream.Position += 0x10L;
         byte[] rawComment = newComment_.RawComment;
         stream.WriteLEShort(rawComment.Length);
         stream.Write(rawComment, 0, rawComment.Length);
         stream.SetLength(stream.Position);
     }
     if (archiveStorage_.UpdateMode == FileUpdateMode.Safe)
     {
         Reopen(archiveStorage_.ConvertTemporaryToFinal());
     }
     else
     {
         ReadEntries();
     }
 }
コード例 #6
0
ファイル: ZipFile.cs プロジェクト: ouyh18/LteTools
        private void RunUpdates()
        {
            ZipFile file;
            long sizeEntries = 0L;
            long num2;
            bool flag = false;
            long destinationPosition = 0L;
            if (IsNewArchive)
            {
                file = this;
                file.baseStream_.Position = 0L;
                flag = true;
            }
            else if (archiveStorage_.UpdateMode == FileUpdateMode.Direct)
            {
                file = this;
                file.baseStream_.Position = 0L;
                flag = true;
                updates_.Sort(new UpdateComparer());
            }
            else
            {
                file = Create(archiveStorage_.GetTemporaryOutput());
                file.UseZip64 = UseZip64;
                if (key != null)
                {
                    file.key = (byte[])key.Clone();
                }
            }
            try
            {
                foreach (ZipUpdate update in updates_)
                {
                    if (update != null)
                    {
                        switch (update.Command)
                        {
                            case UpdateCommand.Copy:
                                if (!flag)
                                {
                                    goto Label_00EC;
                                }
                                CopyEntryDirect(file, update, ref destinationPosition);
                                break;

                            case UpdateCommand.Modify:
                                ModifyEntry(file, update);
                                break;

                            case UpdateCommand.Add:
                                goto Label_0104;
                        }
                    }
                    continue;
                Label_00EC:
                    CopyEntry(file, update);
                    continue;
                Label_0104:
                    if (!IsNewArchive && flag)
                    {
                        file.baseStream_.Position = destinationPosition;
                    }
                    AddEntry(file, update);
                    if (flag)
                    {
                        destinationPosition = file.baseStream_.Position;
                    }
                }
                if (!IsNewArchive && flag)
                {
                    file.baseStream_.Position = destinationPosition;
                }
                long position = file.baseStream_.Position;
                foreach (ZipUpdate update2 in updates_)
                {
                    if (update2 != null)
                    {
                        sizeEntries += file.WriteCentralDirectoryHeader(update2.OutEntry);
                    }
                }
                byte[] comment = (newComment_ != null) ? newComment_.RawComment : ZipConstants.ConvertToArray(comment_);
                using (ZipHelperStream stream = new ZipHelperStream(file.baseStream_))
                {
                    stream.WriteEndOfCentralDirectory(updateCount_, sizeEntries, position, comment);
                }
                num2 = file.baseStream_.Position;
                foreach (ZipUpdate update3 in updates_)
                {
                    if (update3 != null)
                    {
                        if ((update3.CrcPatchOffset > 0L) && (update3.OutEntry.CompressedSize > 0L))
                        {
                            file.baseStream_.Position = update3.CrcPatchOffset;
                            file.WriteLEInt((int)update3.OutEntry.Crc);
                        }
                        if (update3.SizePatchOffset > 0L)
                        {
                            file.baseStream_.Position = update3.SizePatchOffset;
                            if (update3.OutEntry.LocalHeaderRequiresZip64)
                            {
                                file.WriteLeLong(update3.OutEntry.Size);
                                file.WriteLeLong(update3.OutEntry.CompressedSize);
                            }
                            else
                            {
                                file.WriteLEInt((int)update3.OutEntry.CompressedSize);
                                file.WriteLEInt((int)update3.OutEntry.Size);
                            }
                        }
                    }
                }
            }
            catch
            {
                file.Close();
                if (!flag && (file.Name != null))
                {
                    File.Delete(file.Name);
                }
                throw;
            }
            if (flag)
            {
                file.baseStream_.SetLength(num2);
                file.baseStream_.Flush();
                isNewArchive_ = false;
                ReadEntries();
            }
            else
            {
                baseStream_.Close();
                Reopen(archiveStorage_.ConvertTemporaryToFinal());
            }
        }
コード例 #7
0
ファイル: ZipFile.cs プロジェクト: ouyh18/LteTools
 private long LocateBlockWithSignature(int signature, long endLocation, int minimumBlockSize, int maximumVariableData)
 {
     using (ZipHelperStream stream = new ZipHelperStream(baseStream_))
     {
         return stream.LocateBlockWithSignature(signature, endLocation, minimumBlockSize, maximumVariableData);
     }
 }
コード例 #8
0
ファイル: ZipOutputStream.cs プロジェクト: ouyh18/LteTools
 public override void Finish()
 {
     if (entries != null)
     {
         if (curEntry != null)
         {
             CloseEntry();
         }
         long count = entries.Count;
         long sizeEntries = 0L;
         foreach (ZipEntry entry in entries)
         {
             WriteLeInt(0x2014b50);
             WriteLeShort(0x33);
             WriteLeShort(entry.Version);
             WriteLeShort(entry.Flags);
             WriteLeShort((short)entry.CompressionMethodForHeader);
             WriteLeInt((int)entry.DosTime);
             WriteLeInt((int)entry.Crc);
             if (entry.IsZip64Forced() || (entry.CompressedSize >= 0xffffffffL))
             {
                 WriteLeInt(-1);
             }
             else
             {
                 WriteLeInt((int)entry.CompressedSize);
             }
             if (entry.IsZip64Forced() || (entry.Size >= 0xffffffffL))
             {
                 WriteLeInt(-1);
             }
             else
             {
                 WriteLeInt((int)entry.Size);
             }
             byte[] buffer = ZipConstants.ConvertToArray(entry.Flags, entry.Name);
             if (buffer.Length > 0xffff)
             {
                 throw new ZipException("Name too long.");
             }
             ZipExtraData extraData = new ZipExtraData(entry.ExtraData);
             if (entry.CentralHeaderRequiresZip64)
             {
                 extraData.StartNewEntry();
                 if (entry.IsZip64Forced() || (entry.Size >= 0xffffffffL))
                 {
                     extraData.AddLeLong(entry.Size);
                 }
                 if (entry.IsZip64Forced() || (entry.CompressedSize >= 0xffffffffL))
                 {
                     extraData.AddLeLong(entry.CompressedSize);
                 }
                 if (entry.Offset >= 0xffffffffL)
                 {
                     extraData.AddLeLong(entry.Offset);
                 }
                 extraData.AddNewEntry(1);
             }
             else
             {
                 extraData.Delete(1);
             }
             if (entry.AESKeySize > 0)
             {
                 AddExtraDataAES(entry, extraData);
             }
             byte[] entryData = extraData.GetEntryData();
             byte[] buffer3 = (entry.Comment != null) ? ZipConstants.ConvertToArray(entry.Flags, entry.Comment) : new byte[0];
             if (buffer3.Length > 0xffff)
             {
                 throw new ZipException("Comment too long.");
             }
             WriteLeShort(buffer.Length);
             WriteLeShort(entryData.Length);
             WriteLeShort(buffer3.Length);
             WriteLeShort(0);
             WriteLeShort(0);
             if (entry.ExternalFileAttributes != -1)
             {
                 WriteLeInt(entry.ExternalFileAttributes);
             }
             else if (entry.IsDirectory)
             {
                 WriteLeInt(0x10);
             }
             else
             {
                 WriteLeInt(0);
             }
             if (entry.Offset >= 0xffffffffL)
             {
                 WriteLeInt(-1);
             }
             else
             {
                 WriteLeInt((int)entry.Offset);
             }
             if (buffer.Length > 0)
             {
                 baseOutputStream_.Write(buffer, 0, buffer.Length);
             }
             if (entryData.Length > 0)
             {
                 baseOutputStream_.Write(entryData, 0, entryData.Length);
             }
             if (buffer3.Length > 0)
             {
                 baseOutputStream_.Write(buffer3, 0, buffer3.Length);
             }
             sizeEntries += ((0x2e + buffer.Length) + entryData.Length) + buffer3.Length;
         }
         using (ZipHelperStream stream = new ZipHelperStream(baseOutputStream_))
         {
             stream.WriteEndOfCentralDirectory(count, sizeEntries, offset, zipComment);
         }
         entries = null;
     }
 }