コード例 #1
0
 public static bool TryReadBlock(BinaryReader reader, long endExtraField, out ZipGenericExtraField field)
 {
     field = new ZipGenericExtraField();
     if ((endExtraField - reader.BaseStream.Position) < 4L)
     {
         return(false);
     }
     field._tag  = reader.ReadUInt16();
     field._size = reader.ReadUInt16();
     if ((endExtraField - reader.BaseStream.Position) < field._size)
     {
         return(false);
     }
     field._data = reader.ReadBytes(field._size);
     return(true);
 }
コード例 #2
0
        public static List <ZipGenericExtraField> GetExtraFields(BinaryReader reader)
        {
            List <ZipGenericExtraField> list;

            reader.BaseStream.Seek(0x1aL, SeekOrigin.Current);
            ushort num  = reader.ReadUInt16();
            ushort num2 = reader.ReadUInt16();

            reader.BaseStream.Seek((long)num, SeekOrigin.Current);
            using (Stream stream = new SubReadStream(reader.BaseStream, reader.BaseStream.Position, (long)num2))
            {
                list = ZipGenericExtraField.ParseExtraField(stream);
            }
            Zip64ExtraField.RemoveZip64Blocks(list);
            return(list);
        }
コード例 #3
0
        public static bool TryReadBlock(BinaryReader reader, bool saveExtraFieldsAndComments, out ZipCentralDirectoryFileHeader header)
        {
            Zip64ExtraField field;

            header = new ZipCentralDirectoryFileHeader();
            if (reader.ReadUInt32() != 0x2014b50)
            {
                return(false);
            }
            header.VersionMadeBy          = reader.ReadUInt16();
            header.VersionNeededToExtract = reader.ReadUInt16();
            header.GeneralPurposeBitFlag  = reader.ReadUInt16();
            header.CompressionMethod      = reader.ReadUInt16();
            header.LastModified           = reader.ReadUInt32();
            header.Crc32 = reader.ReadUInt32();
            uint num  = reader.ReadUInt32();
            uint num2 = reader.ReadUInt32();

            header.FilenameLength    = reader.ReadUInt16();
            header.ExtraFieldLength  = reader.ReadUInt16();
            header.FileCommentLength = reader.ReadUInt16();
            ushort num3 = reader.ReadUInt16();

            header.InternalFileAttributes = reader.ReadUInt16();
            header.ExternalFileAttributes = reader.ReadUInt32();
            uint num4 = reader.ReadUInt32();

            header.Filename = reader.ReadBytes(header.FilenameLength);
            bool readUncompressedSize  = num2 == uint.MaxValue;
            bool readCompressedSize    = num == uint.MaxValue;
            bool readLocalHeaderOffset = num4 == uint.MaxValue;
            bool readStartDiskNumber   = num3 == 0xffff;
            long position = reader.BaseStream.Position + header.ExtraFieldLength;

            using (Stream stream = new SubReadStream(reader.BaseStream, reader.BaseStream.Position, (long)header.ExtraFieldLength))
            {
                if (saveExtraFieldsAndComments)
                {
                    header.ExtraFields = ZipGenericExtraField.ParseExtraField(stream);
                    field = Zip64ExtraField.GetAndRemoveZip64Block(header.ExtraFields, readUncompressedSize, readCompressedSize, readLocalHeaderOffset, readStartDiskNumber);
                }
                else
                {
                    header.ExtraFields = null;
                    field = Zip64ExtraField.GetJustZip64Block(stream, readUncompressedSize, readCompressedSize, readLocalHeaderOffset, readStartDiskNumber);
                }
            }
            reader.BaseStream.AdvanceToPosition(position);
            if (saveExtraFieldsAndComments)
            {
                header.FileComment = reader.ReadBytes(header.FileCommentLength);
            }
            else
            {
                Stream baseStream = reader.BaseStream;
                baseStream.Position += header.FileCommentLength;
                header.FileComment   = null;
            }
            header.UncompressedSize            = !field.UncompressedSize.HasValue ? ((long)num2) : field.UncompressedSize.Value;
            header.CompressedSize              = !field.CompressedSize.HasValue ? ((long)num) : field.CompressedSize.Value;
            header.RelativeOffsetOfLocalHeader = !field.LocalHeaderOffset.HasValue ? ((long)num4) : field.LocalHeaderOffset.Value;
            header.DiskNumberStart             = !field.StartDiskNumber.HasValue ? num3 : field.StartDiskNumber.Value;
            return(true);
        }
コード例 #4
0
ファイル: ZipArchiveEntry.cs プロジェクト: wise0704/SwcBuild
        private bool WriteLocalFileHeader(bool isEmptyFile)
        {
            uint            maxValue;
            uint            num2;
            ushort          num4;
            BinaryWriter    writer = new BinaryWriter(_archive.ArchiveStream);
            Zip64ExtraField field  = new Zip64ExtraField();
            bool            flag   = false;

            if (isEmptyFile)
            {
                CompressionMethod = CompressionMethodValues.Stored;
                maxValue          = 0;
                num2 = 0;
            }
            else if (((_archive.Mode == ZipArchiveMode.Create) && !_archive.ArchiveStream.CanSeek) && !isEmptyFile)
            {
                _generalPurposeBitFlag |= BitFlagValues.DataDescriptor;
                flag     = false;
                maxValue = 0;
                num2     = 0;
            }
            else if (SizesTooLarge())
            {
                flag                   = true;
                maxValue               = uint.MaxValue;
                num2                   = uint.MaxValue;
                field.CompressedSize   = new long?(_compressedSize);
                field.UncompressedSize = new long?(_uncompressedSize);
                VersionToExtractAtLeast(ZipVersionNeededValues.Zip64);
            }
            else
            {
                flag     = false;
                maxValue = (uint)_compressedSize;
                num2     = (uint)_uncompressedSize;
            }
            _offsetOfLocalHeader = writer.BaseStream.Position;
            int num3 = (flag ? field.TotalSize : 0) + ((_lhUnknownExtraFields != null) ? ZipGenericExtraField.TotalSize(_lhUnknownExtraFields) : 0);

            if (num3 > 0xffff)
            {
                num4 = flag ? field.TotalSize : ((ushort)0);
                _lhUnknownExtraFields = null;
            }
            else
            {
                num4 = (ushort)num3;
            }
            writer.Write((uint)0x4034b50);
            writer.Write((ushort)_versionToExtract);
            writer.Write((ushort)_generalPurposeBitFlag);
            writer.Write((ushort)CompressionMethod);
            writer.Write(ZipHelper.DateTimeToDosTime(_lastModified.DateTime));
            writer.Write(_crc32);
            writer.Write(maxValue);
            writer.Write(num2);
            writer.Write((ushort)_storedEntryNameBytes.Length);
            writer.Write(num4);
            writer.Write(_storedEntryNameBytes);
            if (flag)
            {
                field.WriteBlock(_archive.ArchiveStream);
            }
            if (_lhUnknownExtraFields != null)
            {
                ZipGenericExtraField.WriteAllBlocks(_lhUnknownExtraFields, _archive.ArchiveStream);
            }
            return(flag);
        }
コード例 #5
0
ファイル: ZipArchiveEntry.cs プロジェクト: wise0704/SwcBuild
        internal void WriteCentralDirectoryFileHeader()
        {
            uint            maxValue;
            uint            num2;
            uint            num3;
            ushort          num5;
            BinaryWriter    writer = new BinaryWriter(_archive.ArchiveStream);
            Zip64ExtraField field  = new Zip64ExtraField();
            bool            flag   = false;

            if (SizesTooLarge())
            {
                flag                   = true;
                maxValue               = uint.MaxValue;
                num2                   = uint.MaxValue;
                field.CompressedSize   = new long?(_compressedSize);
                field.UncompressedSize = new long?(_uncompressedSize);
            }
            else
            {
                maxValue = (uint)_compressedSize;
                num2     = (uint)_uncompressedSize;
            }
            if (_offsetOfLocalHeader > 0xffffffffL)
            {
                flag = true;
                num3 = uint.MaxValue;
                field.LocalHeaderOffset = new long?(_offsetOfLocalHeader);
            }
            else
            {
                num3 = (uint)_offsetOfLocalHeader;
            }
            if (flag)
            {
                VersionToExtractAtLeast(ZipVersionNeededValues.Zip64);
            }
            int num4 = (flag ? field.TotalSize : 0) + ((_cdUnknownExtraFields != null) ? ZipGenericExtraField.TotalSize(_cdUnknownExtraFields) : 0);

            if (num4 > 0xffff)
            {
                num5 = flag ? field.TotalSize : ((ushort)0);
                _cdUnknownExtraFields = null;
            }
            else
            {
                num5 = (ushort)num4;
            }
            writer.Write((uint)0x2014b50);
            writer.Write((ushort)_versionToExtract);
            writer.Write((ushort)_versionToExtract);
            writer.Write((ushort)_generalPurposeBitFlag);
            writer.Write((ushort)CompressionMethod);
            writer.Write(ZipHelper.DateTimeToDosTime(_lastModified.DateTime));
            writer.Write(_crc32);
            writer.Write(maxValue);
            writer.Write(num2);
            writer.Write((ushort)_storedEntryNameBytes.Length);
            writer.Write(num5);
            writer.Write((_fileComment != null) ? ((ushort)_fileComment.Length) : ((ushort)0));
            writer.Write((ushort)0);
            writer.Write((ushort)0);
            writer.Write((uint)0);
            writer.Write(num3);
            writer.Write(_storedEntryNameBytes);
            if (flag)
            {
                field.WriteBlock(_archive.ArchiveStream);
            }
            if (_cdUnknownExtraFields != null)
            {
                ZipGenericExtraField.WriteAllBlocks(_cdUnknownExtraFields, _archive.ArchiveStream);
            }
            if (_fileComment != null)
            {
                writer.Write(_fileComment);
            }
        }