Exemple #1
0
 internal void UpdatePadding(long size)
 {
     if (Math.Abs(size) <= 0xffffL)
     {
         if ((size > 0L) && (this._paddingElement != null))
         {
             if (this._paddingElement.PaddingSize >= size)
             {
                 this._paddingElement.PaddingSize = (ushort)(this._paddingElement.PaddingSize - ((ushort)size));
             }
             else if (this._paddingElement.Size == size)
             {
                 this._paddingElement = null;
             }
         }
         else if (size < 0L)
         {
             if (this._paddingElement == null)
             {
                 size += ZipIOExtraFieldPaddingElement.MinimumFieldDataSize + ZipIOExtraFieldElement.MinimumSize;
                 if (size >= 0L)
                 {
                     this._paddingElement             = new ZipIOExtraFieldPaddingElement();
                     this._paddingElement.PaddingSize = (ushort)size;
                 }
             }
             else if ((this._paddingElement.PaddingSize - size) <= 0xffffL)
             {
                 this._paddingElement.PaddingSize = (ushort)(this._paddingElement.PaddingSize - size);
             }
         }
     }
 }
Exemple #2
0
        internal static ZipIOExtraField ParseRecord(BinaryReader reader, ZipIOZip64ExtraFieldUsage zip64extraFieldUsage, ushort expectedExtraFieldSize)
        {
            if (expectedExtraFieldSize == 0)
            {
                if (zip64extraFieldUsage != ZipIOZip64ExtraFieldUsage.None)
                {
                    throw new FileFormatException(SR.Get("CorruptedData"));
                }
                return(CreateNew(false));
            }
            ZipIOExtraField field = new ZipIOExtraField();

            while (expectedExtraFieldSize > 0)
            {
                if (expectedExtraFieldSize < ZipIOExtraFieldElement.MinimumSize)
                {
                    throw new FileFormatException(SR.Get("CorruptedData"));
                }
                ZipIOExtraFieldElement        element  = ZipIOExtraFieldElement.Parse(reader, zip64extraFieldUsage);
                ZipIOExtraFieldZip64Element   element3 = element as ZipIOExtraFieldZip64Element;
                ZipIOExtraFieldPaddingElement element2 = element as ZipIOExtraFieldPaddingElement;
                if (element3 != null)
                {
                    if (field._zip64Element != null)
                    {
                        throw new FileFormatException(SR.Get("CorruptedData"));
                    }
                    field._zip64Element = element3;
                }
                else if (element2 != null)
                {
                    if (field._paddingElement != null)
                    {
                        throw new FileFormatException(SR.Get("CorruptedData"));
                    }
                    field._paddingElement = element2;
                }
                else
                {
                    if (field._extraFieldElements == null)
                    {
                        field._extraFieldElements = new ArrayList(3);
                    }
                    field._extraFieldElements.Add(element);
                }
                expectedExtraFieldSize = (ushort)(expectedExtraFieldSize - element.Size);
            }
            if (expectedExtraFieldSize != 0)
            {
                throw new FileFormatException(SR.Get("CorruptedData"));
            }
            if (field._zip64Element == null)
            {
                field._zip64Element = ZipIOExtraFieldZip64Element.CreateNew();
            }
            return(field);
        }
Exemple #3
0
        internal static ZipIOExtraField CreateNew(bool createPadding)
        {
            ZipIOExtraField field = new ZipIOExtraField();

            field._zip64Element = ZipIOExtraFieldZip64Element.CreateNew();
            if (createPadding)
            {
                field._paddingElement = ZipIOExtraFieldPaddingElement.CreateNew();
            }
            return(field);
        }
Exemple #4
0
        internal static ZipIOExtraFieldElement Parse(BinaryReader reader, ZipIOZip64ExtraFieldUsage zip64extraFieldUsage)
        {
            ZipIOExtraFieldElement element;
            ushort id   = reader.ReadUInt16();
            ushort size = reader.ReadUInt16();

            if (id == ZipIOExtraFieldZip64Element.ConstantFieldId)
            {
                element = new ZipIOExtraFieldZip64Element();
                ((ZipIOExtraFieldZip64Element)element).Zip64ExtraFieldUsage = zip64extraFieldUsage;
            }
            else if (id == ZipIOExtraFieldPaddingElement.ConstantFieldId)
            {
                if (size < ZipIOExtraFieldPaddingElement.MinimumFieldDataSize)
                {
                    element = new ZipIOExtraFieldElement(id);
                }
                else
                {
                    byte[] sniffiedBytes = reader.ReadBytes(ZipIOExtraFieldPaddingElement.SignatureSize);
                    if (ZipIOExtraFieldPaddingElement.MatchesPaddingSignature(sniffiedBytes))
                    {
                        element = new ZipIOExtraFieldPaddingElement();
                    }
                    else
                    {
                        element = new ZipIOExtraFieldElement(id, sniffiedBytes);
                    }
                }
            }
            else
            {
                element = new ZipIOExtraFieldElement(id);
            }
            element.ParseDataField(reader, size);
            return(element);
        }