Add third-party expansion fields for PKZIP

This commit is contained in:
Matt Nadareski
2024-04-28 02:30:46 -04:00
parent 6bc948784a
commit 00c087d8e0
9 changed files with 399 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
namespace SabreTools.Models.PKZIP
{
/// <summary>
/// (per Zbynek Vyskovsky) Defines alignment of data stream of this
/// entry within the zip archive. Additionally, indicates whether the
/// compression method should be kept when re-compressing the zip file.
///
/// The purpose of this extra field is to align specific resources to
/// word or page boundaries so they can be easily mapped into memory.
///
/// The alignment field (lower 15 bits) defines the minimal alignment
/// required by the data stream. Bit 15 of alignment field indicates
/// whether the compression method of this entry can be changed when
/// recompressing the zip file. The value 0 means the compression method
/// should not be changed. The value 1 indicates the compression method
/// may be changed. The padding field contains padding to ensure the correct
/// alignment. It can be changed at any time when the offset or required
/// alignment changes. (see https://issues.apache.org/jira/browse/COMPRESS-391)
/// </summary>
/// <remarks>Header ID = 0xa11e</remarks>
/// <see href="https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT"/>
public class DataStreamAlignment : ExtensibleDataField
{
/// <summary>
/// Required alignment and indicator
/// </summary>
public ushort Alignment { get; set; }
/// <summary>
/// 0x00-padding
/// </summary>
public byte[]? Padding { get; set; }
}
}

View File

@@ -1002,6 +1002,91 @@ namespace SabreTools.Models.PKZIP
*/
}
[Flags]
public enum ZipItInternalSettings : ushort
{
/// <summary>
/// If set, the folder is shown expanded (open)
/// when the archive contents are viewed in ZipIt.
/// </summary>
ShowExpanded = 0b0000_0000_0000_0001,
/// <summary>
/// Reserved, zero
/// </summary>
Reserved1 = 0b0000_0000_0000_0010,
/// <summary>
/// Reserved, zero
/// </summary>
Reserved2 = 0b0000_0000_0000_0100,
/// <summary>
/// Reserved, zero
/// </summary>
Reserved3 = 0b0000_0000_0000_1000,
/// <summary>
/// Reserved, zero
/// </summary>
Reserved4 = 0b0000_0000_0001_0000,
/// <summary>
/// Reserved, zero
/// </summary>
Reserved5 = 0b0000_0000_0010_0000,
/// <summary>
/// Reserved, zero
/// </summary>
Reserved6 = 0b0000_0000_0100_0000,
/// <summary>
/// Reserved, zero
/// </summary>
Reserved7 = 0b0000_0000_1000_0000,
/// <summary>
/// Reserved, zero
/// </summary>
Reserved8 = 0b0000_0001_0000_0000,
/// <summary>
/// Reserved, zero
/// </summary>
Reserved9 = 0b0000_0010_0000_0000,
/// <summary>
/// Reserved, zero
/// </summary>
Reserved10 = 0b0000_0100_0000_0000,
/// <summary>
/// Reserved, zero
/// </summary>
Reserved11 = 0b0000_1000_0000_0000,
/// <summary>
/// Reserved, zero
/// </summary>
Reserved12 = 0b0001_0000_0000_0000,
/// <summary>
/// Reserved, zero
/// </summary>
Reserved13 = 0b0010_0000_0000_0000,
/// <summary>
/// Reserved, zero
/// </summary>
Reserved14 = 0b0100_0000_0000_0000,
/// <summary>
/// Reserved, zero
/// </summary>
Reserved15 = 0b1000_0000_0000_0000,
}
public enum ZOSExtraFieldAttributeFieldCode : ushort
{
/// <summary>

View File

@@ -0,0 +1,39 @@
namespace SabreTools.Models.PKZIP
{
/// <summary>
/// The FWKCS Contents_Signature System, used in
/// automatically identifying files independent of file name,
/// optionally adds and uses an extra field to support the
/// rapid creation of an enhanced contents_signature.
///
/// When FWKCS revises a .ZIP file central directory to add
/// this extra field for a file, it also replaces the
/// central directory entry for that file's uncompressed
/// file length with a measured value.
///
/// FWKCS provides an option to strip this extra field, if
/// present, from a .ZIP file central directory. In adding
/// this extra field, FWKCS preserves .ZIP file Authenticity
/// Verification; if stripping this extra field, FWKCS
/// preserves all versions of AV through PKZIP version 2.04g.
///
/// FWKCS, and FWKCS Contents_Signature System, are
/// trademarks of Frederick W. Kantor.
/// </summary>
/// <remarks>Header ID = 0x4b46</remarks>
/// <see href="https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT"/>
public class FWKCSMD5ExtraField : ExtensibleDataField
{
/// <summary>
/// "MD5"
/// </summary>
/// <remarks>3 bytes</remarks>
public byte[]? Preface { get; set; }
/// <summary>
/// Uncompressed file's MD5 hash, low byte first
/// </summary>
/// <remarks>16 bytes</remarks>
public byte[]? MD5 { get; set; }
}
}

View File

@@ -0,0 +1,54 @@
namespace SabreTools.Models.PKZIP
{
/// <summary>
/// Stores the UTF-8 version of the file comment as stored in the
/// central directory header. (Last Revision 20070912)
///
/// Currently Version is set to the number 1. If there is a need
/// to change this field, the version will be incremented. Changes
/// MAY NOT be backward compatible so this extra field SHOULD NOT be
/// used if the version is not recognized.
///
/// The ComCRC32 is the standard zip CRC32 checksum of the File Comment
/// field in the central directory header. This is used to verify that
/// the comment field has not changed since the Unicode Comment extra field
/// was created. This can happen if a utility changes the File Comment
/// field but does not update the UTF-8 Comment extra field. If the CRC
/// check fails, this Unicode Comment extra field SHOULD be ignored and
/// the File Comment field in the header SHOULD be used instead.
///
/// The UnicodeCom field is the UTF-8 version of the File Comment field
/// in the header. As UnicodeCom is defined to be UTF-8, no UTF-8 byte
/// order mark (BOM) is used. The length of this field is determined by
/// subtracting the size of the previous fields from TSize. If both the
/// File Name and Comment fields are UTF-8, the new General Purpose Bit
/// Flag, bit 11 (Language encoding flag (EFS)), can be used to indicate
/// both the header File Name and Comment fields are UTF-8 and, in this
/// case, the Unicode Path and Unicode Comment extra fields are not
/// needed and SHOULD NOT be created. Note that, for backward
/// compatibility, bit 11 SHOULD only be used if the native character set
/// of the paths and comments being zipped up are already in UTF-8. It is
/// expected that the same file comment storage method, either general
/// purpose bit 11 or extra fields, be used in both the Local and Central
/// Directory Header for a file.
/// </summary>
/// <remarks>Header ID = 0x6375</remarks>
/// <see href="https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT"/>
public class InfoZIPUnicodeCommentExtraField : ExtensibleDataField
{
/// <summary>
/// Version of this extra field, currently 1
/// </summary>
public byte Version { get; set; }
/// <summary>
/// Comment Field CRC32 Checksum
/// </summary>
public uint ComCRC32 { get; set; }
/// <summary>
/// UTF-8 version of the entry comment
/// </summary>
public string? UnicodeCom { get; set; }
}
}

View File

@@ -0,0 +1,54 @@
namespace SabreTools.Models.PKZIP
{
/// <summary>
/// Stores the UTF-8 version of the file name field as stored in the
/// local header and central directory header. (Last Revision 20070912)
///
/// Currently Version is set to the number 1. If there is a need
/// to change this field, the version will be incremented. Changes
/// MAY NOT be backward compatible so this extra field SHOULD NOT be
/// used if the version is not recognized.
///
/// The NameCRC32 is the standard zip CRC32 checksum of the File Name
/// field in the header. This is used to verify that the header
/// File Name field has not changed since the Unicode Path extra field
/// was created. This can happen if a utility renames the File Name but
/// does not update the UTF-8 path extra field. If the CRC check fails,
/// this UTF-8 Path Extra Field SHOULD be ignored and the File Name field
/// in the header SHOULD be used instead.
///
/// The UnicodeName is the UTF-8 version of the contents of the File Name
/// field in the header. As UnicodeName is defined to be UTF-8, no UTF-8
/// byte order mark (BOM) is used. The length of this field is determined
/// by subtracting the size of the previous fields from TSize. If both
/// the File Name and Comment fields are UTF-8, the new General Purpose
/// Bit Flag, bit 11 (Language encoding flag (EFS)), can be used to
/// indicate that both the header File Name and Comment fields are UTF-8
/// and, in this case, the Unicode Path and Unicode Comment extra fields
/// are not needed and SHOULD NOT be created. Note that, for backward
/// compatibility, bit 11 SHOULD only be used if the native character set
/// of the paths and comments being zipped up are already in UTF-8. It is
/// expected that the same file name storage method, either general
/// purpose bit 11 or extra fields, be used in both the Local and Central
/// Directory Header for a file.
/// </summary>
/// <remarks>Header ID = 0x7075</remarks>
/// <see href="https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT"/>
public class InfoZIPUnicodePathExtraField : ExtensibleDataField
{
/// <summary>
/// Version of this extra field, currently 1
/// </summary>
public byte Version { get; set; }
/// <summary>
/// File Name Field CRC32 Checksum
/// </summary>
public uint NameCRC32 { get; set; }
/// <summary>
/// UTF-8 version of the entry File Name
/// </summary>
public string? UnicodeName { get; set; }
}
}

View File

@@ -0,0 +1,22 @@
namespace SabreTools.Models.PKZIP
{
/// <remarks>Header ID = 0xa220</remarks>
/// <see href="https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT"/>
public class MicrosoftOpenPackagingGrowthHint : ExtensibleDataField
{
/// <summary>
/// Verification signature (A028)
/// </summary>
public ushort Sig { get; set; }
/// <summary>
/// Initial padding value
/// </summary>
public ushort PadVal { get; set; }
/// <summary>
/// Filled with NULL characters
/// </summary>
public byte[]? Padding { get; set; }
}
}

View File

@@ -0,0 +1,41 @@
namespace SabreTools.Models.PKZIP
{
/// <summary>
/// The following is the layout of the ZipIt extra block
/// for Macintosh. The local-header and central-header versions
/// are identical. This block MUST be present if the file is
/// stored MacBinary-encoded and it SHOULD NOT be used if the file
/// is not stored MacBinary-encoded.
/// </summary>
/// <remarks>Header ID = 0x2605</remarks>
/// <see href="https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT"/>
public class ZipItMacintoshExtraField : ExtensibleDataField
{
/// <summary>
/// "ZPIT" - extra-field signature
/// </summary>
public uint ExtraFieldSignature { get; set; }
/// <summary>
/// Length of FileName
/// </summary>
public byte FnLen { get; set; }
/// <summary>
/// Full Macintosh filename
/// </summary>
public string? FileName { get; set; }
/// <summary>
/// Four-byte Mac file type string
/// </summary>
/// <remarks>4 bytes</remarks>
public byte[]? FileType { get; set; }
/// <summary>
/// Four-byte Mac creator string
/// </summary>
/// <remarks>4 bytes</remarks>
public byte[]? Creator { get; set; }
}
}

View File

@@ -0,0 +1,29 @@
namespace SabreTools.Models.PKZIP
{
/// <summary>
/// The following is the layout of a shortened variant of the
/// ZipIt extra block for Macintosh used only for directory
/// entries. This variant is used by ZipIt 1.3.5 and newer to
/// save some optional Mac-specific information about directories.
/// The local-header and central-header versions are identical.
/// </summary>
/// <remarks>Header ID = 0x2805</remarks>
/// <see href="https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT"/>
public class ZipItMacintoshShortDirectoryExtraField : ExtensibleDataField
{
/// <summary>
/// "ZPIT" - extra-field signature
/// </summary>
public uint ExtraFieldSignature { get; set; }
/// <summary>
/// attributes from DInfo.frFlags, MAY be omitted
/// </summary>
public ushort? FrFlags { get; set; }
/// <summary>
/// ZipIt view flag, MAY be omitted
/// </summary>
public ZipItInternalSettings? View { get; set; }
}
}

View File

@@ -0,0 +1,41 @@
namespace SabreTools.Models.PKZIP
{
/// <summary>
/// The following is the layout of a shortened variant of the
/// ZipIt extra block for Macintosh (without "full name" entry).
/// This variant is used by ZipIt 1.3.5 and newer for entries of
/// files (not directories) that do not have a MacBinary encoded
/// file. The local-header and central-header versions are identical.
/// </summary>
/// <remarks>Header ID = 0x2705</remarks>
/// <see href="https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT"/>
public class ZipItMacintoshShortFileExtraField : ExtensibleDataField
{
/// <summary>
/// "ZPIT" - extra-field signature
/// </summary>
public uint ExtraFieldSignature { get; set; }
/// <summary>
/// Four-byte Mac file type string
/// </summary>
/// <remarks>4 bytes</remarks>
public byte[]? FileType { get; set; }
/// <summary>
/// Four-byte Mac creator string
/// </summary>
/// <remarks>4 bytes</remarks>
public byte[]? Creator { get; set; }
/// <summary>
/// Attributes from FInfo.frFlags, MAY be omitted
/// </summary>
public ushort? FdFlags { get; set; }
/// <summary>
/// Reserved, MAY be omitted
/// </summary>
public ushort? Reserved { get; set; }
}
}