예제 #1
0
        private static ExtraFieldBase GetExtraField(
            FileHeaderInfoBase headerInfo,
            BinaryReader reader)
        {
            ushort         num1           = reader.ReadUInt16();
            ExtraFieldType extraFieldType = ExtraFieldBase.GetExtraFieldType(num1);
            ushort         num2           = reader.ReadUInt16();

            byte[]         extraData = reader.ReadBytes((int)num2);
            ExtraFieldBase extraFieldBase;

            switch (extraFieldType)
            {
            case ExtraFieldType.Zip64:
                extraFieldBase = (ExtraFieldBase) new Zip64ExtraField(headerInfo);
                break;

            case ExtraFieldType.AesEncryption:
                extraFieldBase = (ExtraFieldBase) new AesEncryptionExtraField();
                break;

            default:
                extraFieldBase = (ExtraFieldBase) new UnknownExtraField(num1);
                break;
            }
            extraFieldBase.ParseBlock(extraData);
            return(extraFieldBase);
        }
예제 #2
0
        public static IEnumerable <ExtraFieldBase> GetExtraFields(
            FileHeaderInfoBase headerInfo)
        {
            MemoryStream stream = new MemoryStream(headerInfo.ExtraFieldsData);

            using (BinaryReader reader = new BinaryReader((Stream)stream))
            {
                while (stream.Position < stream.Length)
                {
                    ExtraFieldBase field = ExtraFieldBase.GetExtraField(headerInfo, reader);
                    yield return(field);
                }
            }
        }
예제 #3
0
 protected override void WriteFields(BinaryWriter writer)
 {
     writer.Write(this.VersionNeededToExtract);
     writer.Write(this.GeneralPurposeBitFlag);
     writer.Write(this.CompressionMethod);
     writer.Write(this.FileTime);
     base.WriteFields(writer);
     writer.Write((ushort)this.FileName.Length);
     if (this.ExtraFields != null)
     {
         this.ExtraFieldsData = ExtraFieldBase.GetExtraFieldsData((IEnumerable <ExtraFieldBase>) this.ExtraFields);
         writer.Write((ushort)this.ExtraFieldsData.Length);
     }
     else
     {
         writer.Write((ushort)0);
     }
 }
예제 #4
0
 internal void FromFileHeader(FileHeaderBase fileHeader)
 {
     this.CompressedSize    = fileHeader.CompressedSize;
     this.CompressionMethod = fileHeader.CompressionMethod;
     this.UncompressedSize  = fileHeader.UncompressedSize;
     this.Crc = fileHeader.Crc;
     if (fileHeader.ExtraFieldsData != null)
     {
         this.ExtraFieldsData = new byte[fileHeader.ExtraFieldsData.Length];
         Array.Copy((Array)fileHeader.ExtraFieldsData, (Array)this.ExtraFieldsData, fileHeader.ExtraFieldsData.Length);
         this.ExtraFields = new List <ExtraFieldBase>(ExtraFieldBase.GetExtraFields(this.GetHeaderInfo()));
     }
     if (fileHeader.FileName != null)
     {
         this.FileName = new byte[fileHeader.FileName.Length];
         Array.Copy((Array)fileHeader.FileName, (Array)this.FileName, fileHeader.FileName.Length);
     }
     this.FileTime = fileHeader.FileTime;
     this.GeneralPurposeBitFlag  = fileHeader.GeneralPurposeBitFlag;
     this.VersionNeededToExtract = fileHeader.VersionNeededToExtract;
 }
예제 #5
0
 protected void ReadExtraData(BinaryReader reader)
 {
     this.FileName        = reader.ReadBytes((int)this.fileNameLength);
     this.ExtraFieldsData = reader.ReadBytes((int)this.extraFieldLength);
     this.ExtraFields     = new List <ExtraFieldBase>(ExtraFieldBase.GetExtraFields(this.GetHeaderInfo()));
 }