diff --git a/PKZIP/DataStreamAlignment.cs b/PKZIP/DataStreamAlignment.cs new file mode 100644 index 0000000..dc68932 --- /dev/null +++ b/PKZIP/DataStreamAlignment.cs @@ -0,0 +1,34 @@ +namespace SabreTools.Models.PKZIP +{ + /// + /// (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) + /// + /// Header ID = 0xa11e + /// + public class DataStreamAlignment : ExtensibleDataField + { + /// + /// Required alignment and indicator + /// + public ushort Alignment { get; set; } + + /// + /// 0x00-padding + /// + public byte[]? Padding { get; set; } + } +} \ No newline at end of file diff --git a/PKZIP/Enums.cs b/PKZIP/Enums.cs index 720b8f2..f93445e 100644 --- a/PKZIP/Enums.cs +++ b/PKZIP/Enums.cs @@ -1002,6 +1002,91 @@ namespace SabreTools.Models.PKZIP */ } + [Flags] + public enum ZipItInternalSettings : ushort + { + /// + /// If set, the folder is shown expanded (open) + /// when the archive contents are viewed in ZipIt. + /// + ShowExpanded = 0b0000_0000_0000_0001, + + /// + /// Reserved, zero + /// + Reserved1 = 0b0000_0000_0000_0010, + + /// + /// Reserved, zero + /// + Reserved2 = 0b0000_0000_0000_0100, + + /// + /// Reserved, zero + /// + Reserved3 = 0b0000_0000_0000_1000, + + /// + /// Reserved, zero + /// + Reserved4 = 0b0000_0000_0001_0000, + + /// + /// Reserved, zero + /// + Reserved5 = 0b0000_0000_0010_0000, + + /// + /// Reserved, zero + /// + Reserved6 = 0b0000_0000_0100_0000, + + /// + /// Reserved, zero + /// + Reserved7 = 0b0000_0000_1000_0000, + + /// + /// Reserved, zero + /// + Reserved8 = 0b0000_0001_0000_0000, + + /// + /// Reserved, zero + /// + Reserved9 = 0b0000_0010_0000_0000, + + /// + /// Reserved, zero + /// + Reserved10 = 0b0000_0100_0000_0000, + + /// + /// Reserved, zero + /// + Reserved11 = 0b0000_1000_0000_0000, + + /// + /// Reserved, zero + /// + Reserved12 = 0b0001_0000_0000_0000, + + /// + /// Reserved, zero + /// + Reserved13 = 0b0010_0000_0000_0000, + + /// + /// Reserved, zero + /// + Reserved14 = 0b0100_0000_0000_0000, + + /// + /// Reserved, zero + /// + Reserved15 = 0b1000_0000_0000_0000, + } + public enum ZOSExtraFieldAttributeFieldCode : ushort { /// diff --git a/PKZIP/FWKCSMD5ExtraField.cs b/PKZIP/FWKCSMD5ExtraField.cs new file mode 100644 index 0000000..87f4c4c --- /dev/null +++ b/PKZIP/FWKCSMD5ExtraField.cs @@ -0,0 +1,39 @@ +namespace SabreTools.Models.PKZIP +{ + /// + /// 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. + /// + /// Header ID = 0x4b46 + /// + public class FWKCSMD5ExtraField : ExtensibleDataField + { + /// + /// "MD5" + /// + /// 3 bytes + public byte[]? Preface { get; set; } + + /// + /// Uncompressed file's MD5 hash, low byte first + /// + /// 16 bytes + public byte[]? MD5 { get; set; } + } +} \ No newline at end of file diff --git a/PKZIP/InfoZIPUnicodeCommentExtraField.cs b/PKZIP/InfoZIPUnicodeCommentExtraField.cs new file mode 100644 index 0000000..1b76165 --- /dev/null +++ b/PKZIP/InfoZIPUnicodeCommentExtraField.cs @@ -0,0 +1,54 @@ +namespace SabreTools.Models.PKZIP +{ + /// + /// 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. + /// + /// Header ID = 0x6375 + /// + public class InfoZIPUnicodeCommentExtraField : ExtensibleDataField + { + /// + /// Version of this extra field, currently 1 + /// + public byte Version { get; set; } + + /// + /// Comment Field CRC32 Checksum + /// + public uint ComCRC32 { get; set; } + + /// + /// UTF-8 version of the entry comment + /// + public string? UnicodeCom { get; set; } + } +} \ No newline at end of file diff --git a/PKZIP/InfoZIPUnicodePathExtraField.cs b/PKZIP/InfoZIPUnicodePathExtraField.cs new file mode 100644 index 0000000..d3558ac --- /dev/null +++ b/PKZIP/InfoZIPUnicodePathExtraField.cs @@ -0,0 +1,54 @@ +namespace SabreTools.Models.PKZIP +{ + /// + /// 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. + /// + /// Header ID = 0x7075 + /// + public class InfoZIPUnicodePathExtraField : ExtensibleDataField + { + /// + /// Version of this extra field, currently 1 + /// + public byte Version { get; set; } + + /// + /// File Name Field CRC32 Checksum + /// + public uint NameCRC32 { get; set; } + + /// + /// UTF-8 version of the entry File Name + /// + public string? UnicodeName { get; set; } + } +} \ No newline at end of file diff --git a/PKZIP/MicrosoftOpenPackagingGrowthHint.cs b/PKZIP/MicrosoftOpenPackagingGrowthHint.cs new file mode 100644 index 0000000..7cc3c7f --- /dev/null +++ b/PKZIP/MicrosoftOpenPackagingGrowthHint.cs @@ -0,0 +1,22 @@ +namespace SabreTools.Models.PKZIP +{ + /// Header ID = 0xa220 + /// + public class MicrosoftOpenPackagingGrowthHint : ExtensibleDataField + { + /// + /// Verification signature (A028) + /// + public ushort Sig { get; set; } + + /// + /// Initial padding value + /// + public ushort PadVal { get; set; } + + /// + /// Filled with NULL characters + /// + public byte[]? Padding { get; set; } + } +} \ No newline at end of file diff --git a/PKZIP/ZipItMacintoshExtraField.cs b/PKZIP/ZipItMacintoshExtraField.cs new file mode 100644 index 0000000..1fec17c --- /dev/null +++ b/PKZIP/ZipItMacintoshExtraField.cs @@ -0,0 +1,41 @@ +namespace SabreTools.Models.PKZIP +{ + /// + /// 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. + /// + /// Header ID = 0x2605 + /// + public class ZipItMacintoshExtraField : ExtensibleDataField + { + /// + /// "ZPIT" - extra-field signature + /// + public uint ExtraFieldSignature { get; set; } + + /// + /// Length of FileName + /// + public byte FnLen { get; set; } + + /// + /// Full Macintosh filename + /// + public string? FileName { get; set; } + + /// + /// Four-byte Mac file type string + /// + /// 4 bytes + public byte[]? FileType { get; set; } + + /// + /// Four-byte Mac creator string + /// + /// 4 bytes + public byte[]? Creator { get; set; } + } +} \ No newline at end of file diff --git a/PKZIP/ZipItMacintoshShortDirectoryExtraField.cs b/PKZIP/ZipItMacintoshShortDirectoryExtraField.cs new file mode 100644 index 0000000..1a759dd --- /dev/null +++ b/PKZIP/ZipItMacintoshShortDirectoryExtraField.cs @@ -0,0 +1,29 @@ +namespace SabreTools.Models.PKZIP +{ + /// + /// 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. + /// + /// Header ID = 0x2805 + /// + public class ZipItMacintoshShortDirectoryExtraField : ExtensibleDataField + { + /// + /// "ZPIT" - extra-field signature + /// + public uint ExtraFieldSignature { get; set; } + + /// + /// attributes from DInfo.frFlags, MAY be omitted + /// + public ushort? FrFlags { get; set; } + + /// + /// ZipIt view flag, MAY be omitted + /// + public ZipItInternalSettings? View { get; set; } + } +} \ No newline at end of file diff --git a/PKZIP/ZipItMacintoshShortFileExtraField.cs b/PKZIP/ZipItMacintoshShortFileExtraField.cs new file mode 100644 index 0000000..02fa3bd --- /dev/null +++ b/PKZIP/ZipItMacintoshShortFileExtraField.cs @@ -0,0 +1,41 @@ +namespace SabreTools.Models.PKZIP +{ + /// + /// 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. + /// + /// Header ID = 0x2705 + /// + public class ZipItMacintoshShortFileExtraField : ExtensibleDataField + { + /// + /// "ZPIT" - extra-field signature + /// + public uint ExtraFieldSignature { get; set; } + + /// + /// Four-byte Mac file type string + /// + /// 4 bytes + public byte[]? FileType { get; set; } + + /// + /// Four-byte Mac creator string + /// + /// 4 bytes + public byte[]? Creator { get; set; } + + /// + /// Attributes from FInfo.frFlags, MAY be omitted + /// + public ushort? FdFlags { get; set; } + + /// + /// Reserved, MAY be omitted + /// + public ushort? Reserved { get; set; } + } +} \ No newline at end of file