From aba02663e5804efa3cc91bbbd6101c0a6e9717bc Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 17 Apr 2024 15:47:41 -0400 Subject: [PATCH] Start adding PKZIP models --- PKZIP/ArchiveExtraDataRecord.cs | 24 + PKZIP/CentralDirectoryFileHeader.cs | 119 +++++ PKZIP/Constants.cs | 85 +++ PKZIP/DataDescriptor.cs | 29 + PKZIP/DataDescriptor64.cs | 29 + PKZIP/DigitalSignature.cs | 24 + PKZIP/EndOfCentralDirectoryLocator64.cs | 29 + PKZIP/EndOfCentralDirectoryRecord.cs | 79 +++ PKZIP/EndOfCentralDirectoryRecord64.cs | 72 +++ PKZIP/Enums.cs | 674 ++++++++++++++++++++++++ PKZIP/LocalFileHeader.cs | 77 +++ PKZIP/SpecialPurposeDataHeader.cs | 25 + 12 files changed, 1266 insertions(+) create mode 100644 PKZIP/ArchiveExtraDataRecord.cs create mode 100644 PKZIP/CentralDirectoryFileHeader.cs create mode 100644 PKZIP/Constants.cs create mode 100644 PKZIP/DataDescriptor.cs create mode 100644 PKZIP/DataDescriptor64.cs create mode 100644 PKZIP/DigitalSignature.cs create mode 100644 PKZIP/EndOfCentralDirectoryLocator64.cs create mode 100644 PKZIP/EndOfCentralDirectoryRecord.cs create mode 100644 PKZIP/EndOfCentralDirectoryRecord64.cs create mode 100644 PKZIP/Enums.cs create mode 100644 PKZIP/LocalFileHeader.cs create mode 100644 PKZIP/SpecialPurposeDataHeader.cs diff --git a/PKZIP/ArchiveExtraDataRecord.cs b/PKZIP/ArchiveExtraDataRecord.cs new file mode 100644 index 0000000..5bf79be --- /dev/null +++ b/PKZIP/ArchiveExtraDataRecord.cs @@ -0,0 +1,24 @@ +namespace SabreTools.Models.PKZIP +{ + /// + /// Archive extra data record + /// + /// + public class ArchiveExtraDataRecord + { + /// + /// Archive extra data signature (0x08064B50) + /// + public uint Signature { get; set; } + + /// + /// Extra field length + /// + public uint ExtraFieldLength { get; set; } + + /// + /// Extra field data (variable size) + /// + public byte[]? ExtraFieldData { get; set; } + } +} \ No newline at end of file diff --git a/PKZIP/CentralDirectoryFileHeader.cs b/PKZIP/CentralDirectoryFileHeader.cs new file mode 100644 index 0000000..0cc424b --- /dev/null +++ b/PKZIP/CentralDirectoryFileHeader.cs @@ -0,0 +1,119 @@ +namespace SabreTools.Models.PKZIP +{ + /// + /// Central directory file header + /// + /// + public class CentralDirectoryFileHeader + { + /// + /// Central file header signature (0x02014B50) + /// + public uint Signature { get; set; } + + /// + /// Host system on which the file attributes are compatible + /// + public HostSystem HostSystem { get; set; } + + /// + /// ZIP specification version + /// + public byte VersionMadeBy { get; set; } + + /// + /// Version needed to extract + /// + /// TODO: Add mapping of versions + public ushort VersionNeededToExtract { get; set; } + + /// + /// General purpose bit flag + /// + public GeneralPurposeBitFlags Flags { get; set; } + + /// + /// Compression method + /// + public CompressionMethod CompressionMethod { get; set; } + + /// + /// Last modified file time + /// + public ushort LastModifedFileTime { get; set; } + + /// + /// Last modified file date + /// + public ushort LastModifiedFileDate { get; set; } + + /// + /// CRC-32 + /// + public uint CRC32 { get; set; } + + /// + /// Compressed size + /// + public uint CompressedSize { get; set; } + + /// + /// Uncompressed size + /// + public uint UncompressedSize { get; set; } + + /// + /// File name length + /// + public ushort FileNameLength { get; set; } + + /// + /// Extra field length + /// + public ushort ExtraFieldLength { get; set; } + + /// + /// File comment length + /// + public ushort FileCommentLength { get; set; } + + /// + /// Disk number start + /// + public ushort DiskNumberStart { get; set; } + + /// + /// Internal file attributes + /// + public InternalFileAttributes InternalFileAttributes { get; set; } + + /// + /// External file attributes + /// + public uint ExternalFileAttributes { get; set; } + + /// + /// Relative offset of local header + /// + /// + /// If ZIP64 and value is 0xFFFFFFFF, size will be in the + /// extended information extra field + /// + public uint RelativeOffsetOfLocalHeader { get; set; } + + /// + /// File name (variable size) + /// + public string? FileName { get; set; } + + /// + /// Extra field (variable size) + /// + public byte[]? ExtraField { get; set; } + + /// + /// File comment (variable size) + /// + public string? FileComment { get; set; } + } +} \ No newline at end of file diff --git a/PKZIP/Constants.cs b/PKZIP/Constants.cs new file mode 100644 index 0000000..0310804 --- /dev/null +++ b/PKZIP/Constants.cs @@ -0,0 +1,85 @@ +namespace SabreTools.Models.PKZIP +{ + public static class Constants + { + #region Archive Extra Data Record + + public const uint ArchiveExtraDataRecordSignature = 0x08064B50; + + public static readonly byte[] ArchiveExtraDataRecordSignatureBytes = [0x50, 0x4B, 0x06, 0x08]; + + public static readonly string ArchiveExtraDataRecordSignatureString = "PK" + (char)0x06 + (char)0x08; + + #endregion + + #region Central Directory File Header + + public const uint CentralDirectoryFileHeaderSignature = 0x02014B50; + + public static readonly byte[] CentralDirectoryFileHeaderSignatureBytes = [0x50, 0x4B, 0x01, 0x02]; + + public static readonly string CentralDirectoryFileHeaderSignatureString = "PK" + (char)0x01 + (char)0x02; + + #endregion + + #region Data Descriptor + + public const uint DataDescriptorSignature = 0x08074B50; + + public static readonly byte[] DataDescriptorSignatureBytes = [0x50, 0x4B, 0x07, 0x08]; + + public static readonly string DataDescriptorSignatureString = "PK" + (char)0x07 + (char)0x08; + + #endregion + + #region Digital Signature + + public const uint DigitalSignatureSignature = 0x05054B50; + + public static readonly byte[] DigitalSignatureSignatureBytes = [0x50, 0x4B, 0x05, 0x05]; + + public static readonly string DigitalSignatureSignatureString = "PK" + (char)0x05 + (char)0x05; + + #endregion + + #region End of Central Directory Locator (ZIP64) + + public const uint EndOfCentralDirectoryLocator64Signature = 0x07064B50; + + public static readonly byte[] EndOfCentralDirectoryLocator64SignatureBytes = [0x50, 0x4B, 0x06, 0x07]; + + public static readonly string EndOfCentralDirectoryLocator64SignatureString = "PK" + (char)0x06 + (char)0x07; + + #endregion + + #region End of Central Directory Record + + public const uint EndOfCentralDirectoryRecordSignature = 0x06054B50; + + public static readonly byte[] EndOfCentralDirectoryRecordSignatureBytes = [0x50, 0x4B, 0x05, 0x06]; + + public static readonly string EndOfCentralDirectoryRecordSignatureString = "PK" + (char)0x05 + (char)0x06; + + #endregion + + #region End of Central Directory Record (ZIP64) + + public const uint EndOfCentralDirectoryRecord64Signature = 0x06064B50; + + public static readonly byte[] EndOfCentralDirectoryRecord64SignatureBytes = [0x50, 0x4B, 0x06, 0x06]; + + public static readonly string EndOfCentralDirectoryRecord64SignatureString = "PK" + (char)0x06 + (char)0x06; + + #endregion + + #region Local File Header + + public const uint LocalFileHeaderSignature = 0x04034B50; + + public static readonly byte[] LocalFileHeaderSignatureBytes = [0x50, 0x4B, 0x03, 0x04]; + + public static readonly string LocalFileHeaderSignatureString = "PK" + (char)0x03 + (char)0x04; + + #endregion + } +} \ No newline at end of file diff --git a/PKZIP/DataDescriptor.cs b/PKZIP/DataDescriptor.cs new file mode 100644 index 0000000..67e5938 --- /dev/null +++ b/PKZIP/DataDescriptor.cs @@ -0,0 +1,29 @@ +namespace SabreTools.Models.PKZIP +{ + /// + /// Data descriptor + /// + /// + public class DataDescriptor + { + /// + /// Recommended, but optional, signature (0x08074B50) + /// + public uint? Signature { get; set; } + + /// + /// CRC-32 + /// + public uint CRC32 { get; set; } + + /// + /// Compressed size + /// + public uint CompressedSize { get; set; } + + /// + /// Uncompressed size + /// + public uint UncompressedSize { get; set; } + } +} \ No newline at end of file diff --git a/PKZIP/DataDescriptor64.cs b/PKZIP/DataDescriptor64.cs new file mode 100644 index 0000000..f33c3be --- /dev/null +++ b/PKZIP/DataDescriptor64.cs @@ -0,0 +1,29 @@ +namespace SabreTools.Models.PKZIP +{ + /// + /// Data descriptor (ZIP64) + /// + /// + public class DataDescriptor64 + { + /// + /// Recommended, but optional, signature (0x08074B50) + /// + public uint? Signature { get; set; } + + /// + /// CRC-32 + /// + public uint CRC32 { get; set; } + + /// + /// Compressed size + /// + public ulong CompressedSize { get; set; } + + /// + /// Uncompressed size + /// + public ulong UncompressedSize { get; set; } + } +} \ No newline at end of file diff --git a/PKZIP/DigitalSignature.cs b/PKZIP/DigitalSignature.cs new file mode 100644 index 0000000..68d5949 --- /dev/null +++ b/PKZIP/DigitalSignature.cs @@ -0,0 +1,24 @@ +namespace SabreTools.Models.PKZIP +{ + /// + /// Digital signature + /// + /// + public class DigitalSignature + { + /// + /// Header signature (0x05054B50) + /// + public uint Signature { get; set; } + + /// + /// Data length + /// + public ushort DataLength { get; set; } + + /// + /// Signature data (variable size) + /// + public byte[]? SignatureData { get; set; } + } +} \ No newline at end of file diff --git a/PKZIP/EndOfCentralDirectoryLocator64.cs b/PKZIP/EndOfCentralDirectoryLocator64.cs new file mode 100644 index 0000000..6204b02 --- /dev/null +++ b/PKZIP/EndOfCentralDirectoryLocator64.cs @@ -0,0 +1,29 @@ +namespace SabreTools.Models.PKZIP +{ + /// + /// Zip64 end of central directory locator + /// + /// + public class EndOfCentralDirectoryLocator64 + { + /// + /// ZIP64 end of central directory locator signature (0x07064B50) + /// + public uint Signature { get; set; } + + /// + /// Number of the disk with the start of the end of central directory + /// + public uint StartDiskNumber { get; set; } + + /// + /// Relative offset of start of central directory record + /// + public ulong CentralDirectoryOffset { get; set; } + + /// + /// Total number of disks + /// + public uint TotalDisks { get; set; } + } +} \ No newline at end of file diff --git a/PKZIP/EndOfCentralDirectoryRecord.cs b/PKZIP/EndOfCentralDirectoryRecord.cs new file mode 100644 index 0000000..561a081 --- /dev/null +++ b/PKZIP/EndOfCentralDirectoryRecord.cs @@ -0,0 +1,79 @@ +namespace SabreTools.Models.PKZIP +{ + /// + /// End of central directory record + /// + /// + public class EndOfCentralDirectoryRecord + { + /// + /// End of central directory signature (0x06054B50) + /// + public uint Signature { get; set; } + + /// + /// Number of this disk + /// + /// + /// If ZIP64 and value is 0xFFFF, size will be in the + /// extended information extra field + /// + public ushort DiskNumber { get; set; } + + /// + /// Number of the disk with the start of the central directory + /// + /// + /// If ZIP64 and value is 0xFFFF, size will be in the + /// extended information extra field + /// + public ushort StartDiskNumber { get; set; } + + /// + /// Total number of entries in the central directory on this disk + /// + /// + /// If ZIP64 and value is 0xFFFF, size will be in the + /// extended information extra field + /// + public ushort TotalEntriesOnDisk { get; set; } + + /// + /// Total number of entries in the central directory + /// + /// + /// If ZIP64 and value is 0xFFFF, size will be in the + /// extended information extra field + /// + public ushort TotalEntries { get; set; } + + /// + /// Size of the central directory + /// + /// + /// If ZIP64 and value is 0xFFFFFFFF, size will be in the + /// extended information extra field + /// + public uint CentralDirectorySize { get; set; } + + /// + /// Offset of start of central directory with respect to the + /// starting disk number + /// + /// + /// If ZIP64 and value is 0xFFFFFFFF, size will be in the + /// extended information extra field + /// + public uint CentralDirectoryOffset { get; set; } + + /// + /// .ZIP file comment length + /// + public ushort FileCommentLength { get; set; } + + /// + /// .ZIP file comment + /// + public string? FileComment { get; set; } + } +} \ No newline at end of file diff --git a/PKZIP/EndOfCentralDirectoryRecord64.cs b/PKZIP/EndOfCentralDirectoryRecord64.cs new file mode 100644 index 0000000..731d95b --- /dev/null +++ b/PKZIP/EndOfCentralDirectoryRecord64.cs @@ -0,0 +1,72 @@ +namespace SabreTools.Models.PKZIP +{ + /// + /// Zip64 end of central directory record + /// + /// + public class EndOfCentralDirectoryRecord64 + { + /// + /// ZIP64 end of central directory signature (0x06064B50) + /// + public uint Signature { get; set; } + + /// + /// Size of ZIP64 end of central directory record + /// + /// SizeOfFixedFields + SizeOfVariableData - 12 + public ulong DirectoryRecordSize { get; set; } + + /// + /// Host system on which the file attributes are compatible + /// + public HostSystem HostSystem { get; set; } + + /// + /// ZIP specification version + /// + public byte VersionMadeBy { get; set; } + + /// + /// Version needed to extract + /// + /// TODO: Add mapping of versions + public ushort VersionNeededToExtract { get; set; } + + /// + /// Number of this disk + /// + public uint DiskNumber { get; set; } + + /// + /// Number of the disk with the start of the central directory + /// + public uint StartDiskNumber { get; set; } + + /// + /// Total number of entries in the central directory on this disk + /// + public ulong TotalEntriesOnDisk { get; set; } + + /// + /// Total number of entries in the central directory + /// + public ulong TotalEntries { get; set; } + + /// + /// Size of the central directory + /// + public ulong CentralDirectorySize { get; set; } + + /// + /// Offset of start of central directory with respect to the + /// starting disk number + /// + public ulong CentralDirectoryOffset { get; set; } + + /// + /// ZIP64 extensible data sector + /// + public byte[]? ExtensibleDataSector { get; set; } + } +} \ No newline at end of file diff --git a/PKZIP/Enums.cs b/PKZIP/Enums.cs new file mode 100644 index 0000000..8410200 --- /dev/null +++ b/PKZIP/Enums.cs @@ -0,0 +1,674 @@ +using System; + +/// +namespace SabreTools.Models.PKZIP +{ + public enum CompressionMethod : ushort + { + /// + /// The file is stored (no compression) + /// + Stored = 0, + + /// + /// The file is Shrunk + /// + Shrunk = 1, + + /// + /// The file is Reduced with compression factor 1 + /// + ReducedCompressionFactor1 = 2, + + /// + /// The file is Reduced with compression factor 2 + /// + ReducedCompressionFactor2 = 3, + + /// + /// The file is Reduced with compression factor 3 + /// + ReducedCompressionFactor3 = 4, + + /// + /// The file is Reduced with compression factor 4 + /// + ReducedCompressionFactor4 = 5, + + /// + /// The file is Imploded + /// + Implode = 6, + + /// + /// Reserved for Tokenizing compression algorithm + /// + TokenizingCompressionAlgorithm = 7, + + /// + /// The file is Deflated + /// + Deflate = 8, + + /// + /// Enhanced Deflating using Deflate64(tm) + /// + Deflate64 = 9, + + /// + /// PKWARE Data Compression Library Imploding (old IBM TERSE) + /// + PKWAREDataCompressionLibraryImplode = 10, + + /// + /// Reserved by PKWARE + /// + CompressionMethod11 = 11, + + /// + /// File is compressed using BZIP2 algorithm + /// + BZIP2 = 12, + + /// + /// Reserved by PKWARE + /// + CompressionMethod13 = 13, + + /// + /// LZMA + /// + LZMA = 14, + + /// + /// Reserved by PKWARE + /// + CompressionMethod15 = 15, + + /// + /// IBM z/OS CMPSC Compression + /// + IBMzOSCMPSC = 16, + + /// + /// Reserved by PKWARE + /// + CompressionMethod17 = 17, + + /// + /// File is compressed using IBM TERSE (new) + /// + IBMTERSE = 18, + + /// + /// IBM LZ77 z Architecture + /// + IBMLZ77 = 19, + + /// + /// deprecated (use method 93 for zstd) + /// + [Obsolete] + OldZstandard = 20, + + /// + /// Zstandard (zstd) Compression + /// + Zstandard = 93, + + /// + /// MP3 Compression + /// + MP3 = 94, + + /// + /// XZ Compression + /// + XZ = 95, + + /// + /// JPEG variant + /// + JPEGVariant = 96, + + /// + /// WavPack compressed data + /// + WavPack = 97, + + /// + /// PPMd version I, Rev 1 + /// + PPMdVersionIRev1 = 98, + + /// + /// AE-x encryption marker + /// + AExEncryption = 99, + } + + [Flags] + public enum GeneralPurposeBitFlags : ushort + { + /// + /// Indicates that the file is encrypted + /// + FileEncrypted = 0b0000_0000_0000_0001, + + #region Compression Method 6 (Implode) + + /// + /// Set - 8K sliding dictionary + /// Clear - 4K sliding dictionary + /// + LargeSlidingDictionary = 0b0000_0000_0000_0010, + + /// + /// Set - 3 Shannon-Fano trees were used + /// Clear - 2 Shannon-Fano trees were used + /// + ThreeTrees = 0b0000_0000_0000_0100, + + #endregion + + #region Compression Method 8 (Deflate) + + /// + /// Normal (-en) compression + /// + NormalCompression = 0b0000_0000_0000_0000, + + /// + /// Maximum (-ex) compression + /// + MaximumCompression = 0b0000_0000_0000_0010, + + /// + /// Fast (-ef) compression + /// + FastCompression = 0b0000_0000_0000_0100, + + /// + /// Super Fast (-es) compression + /// + SuperFastCompression = 0b0000_0000_0000_0110, + + #endregion + + #region Compression Method 14 (LZMA) + + /// + /// Set - indicates an end-of-stream (EOS) marker is used to + /// mark the end of the compressed data stream. + /// Clear - an EOS marker is not present and the compressed data + /// size must be known to extract. + /// + EndOfStreamMarker = 0b0000_0000_0000_0010, + + #endregion + + /// + /// set - the fields crc-32, compressed size and + /// uncompressed size are set to zero in the + /// local header. The correct values are put + /// in the data descriptor immediately + /// following the compressed data. + /// + NoCRC = 0b0000_0000_0000_1000, + + /// + /// Reserved for use with method 8, for enhanced deflating. + /// + EnhancedDeflateReserved = 0b0000_0000_0001_0000, + + /// + /// Indicates that the file is compressed patched data. + /// + /// Requires PKZIP version 2.70 or greater + CompressedPatchedData = 0b0000_0000_0010_0000, + + /// + /// Set - you MUST set the version needed to extract value + /// to at least 50 and you MUST also set bit 0. If AES + /// encryption is used, the version needed to extract + /// value MUST be at least 51. + /// + StrongEncryption = 0b0000_0000_0100_0000, + + /// + /// Currently unused + /// + Bit7 = 0b0000_0000_1000_0000, + + /// + /// Currently unused + /// + Bit8 = 0b0000_0001_0000_0000, + + /// + /// Currently unused + /// + Bit9 = 0b0000_0010_0000_0000, + + /// + /// Currently unused + /// + Bit10 = 0b0000_0100_0000_0000, + + /// + /// Set - the filename and comment fields for this + /// file MUST be encoded using UTF-8. + /// + LanguageEncodingFlag = 0b0000_1000_0000_0000, + + /// + /// Reserved by PKWARE for enhanced compression + /// + PKWAREEnhancedCompression = 0b0001_0000_0000_0000, + + /// + /// Set - Set when encrypting the Central Directory to + /// indicate selected data values in the Local + /// Header are masked to hide their actual values + /// + LocalHeaderValuesMasked = 0b0010_0000_0000_0000, + + /// + /// Reserved by PKWARE for alternate streams + /// + PKWAREAlternateStreams = 0b0100_0000_0000_0000, + + /// + /// Reserved by PKWARE + /// + PKWAREReserved = 0b1000_0000_0000_0000, + } + + public enum HeaderID : ushort + { + /// + /// Zip64 extended information extra field + /// + Zip64ExtendedInformation = 0x0001, + + /// + /// AV Info + /// + AVInfo = 0x0007, + + /// + /// Reserved for extended language encoding data (PFS) + /// + ExtendedLanguageEncodingData = 0x0008, + + /// + /// OS/2 + /// + OS2 = 0x0009, + + /// + /// NTFS + /// + NTFS = 0x000A, + + /// + /// OpenVMS + /// + OpenVMS = 0x000C, + + /// + /// UNIX + /// + UNIX = 0x000D, + + /// + /// Reserved for file stream and fork descriptors + /// + FileStreamFork = 0x000E, + + /// + /// Patch Descriptor + /// + PatchDescriptor = 0x000F, + + /// + /// PKCS#7 Store for X.509 Certificates + /// + PKCSStore = 0x0014, + + /// + /// X.509 Certificate ID and Signature for individual file + /// + X509IndividualFile = 0x0015, + + /// + /// X.509 Certificate ID for Central Directory + /// + X509CentralDirectory = 0x0016, + + /// + /// Strong Encryption Header + /// + StrongEncryptionHeader = 0x0017, + + /// + /// Record Management Controls + /// + RecordManagementControls = 0x0018, + + /// + /// PKCS#7 Encryption Recipient Certificate List + /// + PKCSCertificateList = 0x0019, + + /// + /// Reserved for Timestamp record + /// + Timestamp = 0x0020, + + /// + /// Policy Decryption Key Record + /// + PolicyDecryptionKey = 0x0021, + + /// + /// Smartcrypt Key Provider Record + /// + SmartcryptKeyProvider = 0x0022, + + /// + /// Smartcrypt Policy Key Data Record + /// + SmartcryptPolicyKeyData = 0x0023, + + /// + /// IBM S/390 (Z390), AS/400 (I400) attributes - uncompressed + /// + IBMS390AttributesUncompressed = 0x0065, + + /// + /// Reserved for IBM S/390 (Z390), AS/400 (I400) attributes - compressed + /// + IBMS390AttributesCompressed = 0x0066, + + /// + /// POSZIP 4690 (reserved) + /// + POSZIP4690 = 0x4690, + + #region Third-Party + + /// + /// Macintosh + /// + Macintosh = 0x07C8, + + /// + /// ZipIt Macintosh + /// + ZipItMacintosh = 0x2605, + + /// + /// ZipIt Macintosh 1.3.5+ + /// + ZipItMacintosh135Plus = 0x2705, + + /// + /// ZipIt Macintosh 1.3.5+ + /// + ZipItMacintosh135PlusAlt = 0x2805, + + /// + /// Info-ZIP Macintosh + /// + InfoZIPMacintosh = 0x334D, + + /// + /// Acorn/SparkFS + /// + AcornSparkFS = 0x4341, + + /// + /// Windows NT security descriptor (binary ACL) + /// + WindowsNTSecurityDescriptor = 0x4453, + + /// + /// VM/CMS + /// + VMCMS = 0x4704, + + /// + /// MVS + /// + MVS = 0x470F, + + /// + /// FWKCS MD5 + /// + FWKCSMD5 = 0x4B46, + + /// + /// OS/2 access control list (text ACL) + /// + OS2AccessControlList = 0x4C41, + + /// + /// Info-ZIP OpenVMS + /// + InfoZIPOpenVMS = 0x4D49, + + /// + /// Xceed original location extra field + /// + XceedOriginalLocation = 0x4F4C, + + /// + /// AOS/VS (ACL) + /// + ADSVS = 0x5356, + + /// + /// extended timestamp + /// + ExtendedTimestamp = 0x5455, + + /// + /// Xceed unicode extra field + /// + XceedUnicode = 0x554E, + + /// + /// Info-ZIP UNIX (original, also OS/2, NT, etc) + /// + InfoZIPUNIX = 0x5855, + + /// + /// Info-ZIP Unicode Comment Extra Field + /// + InfoZIPUnicodeComment = 0x6375, + + /// + /// BeOS/BeBox + /// + BeOSBeBox = 0x6542, + + /// + /// Info-ZIP Unicode Path Extra Field + /// + InfoZIPUnicodePath = 0x7075, + + /// + /// ASi UNIX + /// + ASiUnix = 0x756E, + + /// + /// Info-ZIP UNIX (new) + /// + InfoZIPUnixNew = 0x7855, + + /// + /// Data Stream Alignment (Apache Commons-Compress) + /// + DataStreamAlignment = 0xA11E, + + /// + /// Microsoft Open Packaging Growth Hint + /// + MicrosoftOpenPackagingGrowthHint = 0xA220, + + /// + /// SMS/QDOS + /// + SMSQDOS = 0xFD4A, + + /// + /// AE-x encryption structure + /// + AExEncryptionStructure = 0x9901, + + /// + /// Unknown + /// + Unknown = 0x9902, + + #endregion + } + + public enum HostSystem : byte + { + /// + /// MS-DOS and OS/2 (FAT / VFAT / FAT32 file systems) + /// + MSDOS = 0, + + /// + /// Amiga + /// + Amiga = 1, + + /// + /// OpenVMS + /// + OpenVMS = 2, + + /// + /// UNIX + /// + UNIX = 3, + + /// + /// VM/CMS + /// + VMCMS = 4, + + /// + /// Atari ST + /// + AtariST = 5, + + /// + /// OS/2 H.P.F.S. + /// + OS2HPFS = 6, + + /// + /// Macintosh + /// + Macintosh = 7, + + /// + /// Z-System + /// + ZSystem = 8, + + /// + /// CP/M + /// + CPM = 9, + + /// + /// Windows NTFS + /// + WindowsNTFS = 10, + + /// + /// MVS (OS/390 - Z/OS) + /// + MVS = 11, + + /// + /// VSE + /// + VSE = 12, + + /// + /// Acorn Risc + /// + AcornRisc = 13, + + /// + /// VFAT + /// + VFAT = 14, + + /// + /// alternate MVS + /// + AlternateVMS = 15, + + /// + /// BeOS + /// + BeOS = 16, + + /// + /// Tandem + /// + Tandem = 17, + + /// + /// OS/400 + /// + OS400 = 18, + + /// + /// OS X (Darwin) + /// + OSX = 19, + + // 20 thru 255 - unused + } + + [Flags] + public enum InternalFileAttributes : ushort + { + /// + /// Set - The file is apparently an ASCII or text file + /// Clear - The file is apparently binary data + /// + ASCII = 0b0000_0000_0000_0001, + + /// + /// Reserved for use by PKWARE + /// + Bit1 = 0b0000_0000_0000_0010, + + /// + /// Reserved for use by PKWARE + /// + Bit2 = 0b0000_0000_0000_0100, + + /* + 4.4.14.2 The 0x0002 bit of this field indicates, if set, that + a 4 byte variable record length control field precedes each + logical record indicating the length of the record. The + record length control field is stored in little-endian byte + order. This flag is independent of text control characters, + and if used in conjunction with text data, includes any + control characters in the total length of the record. This + value is provided for mainframe data transfer support. + */ + } +} \ No newline at end of file diff --git a/PKZIP/LocalFileHeader.cs b/PKZIP/LocalFileHeader.cs new file mode 100644 index 0000000..87f6730 --- /dev/null +++ b/PKZIP/LocalFileHeader.cs @@ -0,0 +1,77 @@ +namespace SabreTools.Models.PKZIP +{ + /// + /// PKZIP local file header + /// + /// + /// + public class LocalFileHeader + { + /// + /// Signature (0x04034B50) + /// + public uint Signature { get; set; } + + /// + /// Version needed to extract + /// decimal value/10 = major version # + /// decimal value%10 = minor version # + /// + public ushort Version { get; set; } + + /// + /// General purpose bit flag + /// + public GeneralPurposeBitFlags Flags { get; set; } + + /// + /// Compression method + /// + public CompressionMethod CompressionMethod { get; set; } + + /// + /// Last modified file time + /// + public ushort LastModifedFileTime { get; set; } + + /// + /// Last modified file date + /// + public ushort LastModifiedFileDate { get; set; } + + /// + /// CRC-32 + /// + public uint CRC32 { get; set; } + + /// + /// Compressed size + /// + public uint CompressedSize { get; set; } + + /// + /// Uncompressed size + /// + public uint UncompressedSize { get; set; } + + /// + /// File name length + /// + public ushort FileNameLength { get; set; } + + /// + /// Extra field length + /// + public ushort ExtraFieldLength { get; set; } + + /// + /// File name (variable size) + /// + public string? FileName { get; set; } + + /// + /// Extra field (variable size) + /// + public byte[]? ExtraField { get; set; } + } +} \ No newline at end of file diff --git a/PKZIP/SpecialPurposeDataHeader.cs b/PKZIP/SpecialPurposeDataHeader.cs new file mode 100644 index 0000000..e885f5b --- /dev/null +++ b/PKZIP/SpecialPurposeDataHeader.cs @@ -0,0 +1,25 @@ +namespace SabreTools.Models.PKZIP +{ + /// + /// Special purpose data for ZIP64 extensible data field + /// + /// + public class SpecialPurposeDataHeader + { + /// + /// Header ID (data type) + /// + public HeaderID HeaderID { get; set; } + + /// + /// Data size + /// + public uint DataSize { get; set; } + + /// + /// Data (variable size) + /// + /// TODO: Implement models for all extra field types - 4.5.3 + public byte[]? Data { get; set; } + } +} \ No newline at end of file