Start adding PKZIP models

This commit is contained in:
Matt Nadareski
2024-04-17 15:47:41 -04:00
parent 594fec923a
commit aba02663e5
12 changed files with 1266 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
namespace SabreTools.Models.PKZIP
{
/// <summary>
/// Archive extra data record
/// </summary>
/// <see href="https://pkwaredownloads.blob.core.windows.net/pkware-general/Documentation/APPNOTE-6.3.9.TXT"/>
public class ArchiveExtraDataRecord
{
/// <summary>
/// Archive extra data signature (0x08064B50)
/// </summary>
public uint Signature { get; set; }
/// <summary>
/// Extra field length
/// </summary>
public uint ExtraFieldLength { get; set; }
/// <summary>
/// Extra field data (variable size)
/// </summary>
public byte[]? ExtraFieldData { get; set; }
}
}

View File

@@ -0,0 +1,119 @@
namespace SabreTools.Models.PKZIP
{
/// <summary>
/// Central directory file header
/// </summary>
/// <see href="https://pkwaredownloads.blob.core.windows.net/pkware-general/Documentation/APPNOTE-6.3.9.TXT"/>
public class CentralDirectoryFileHeader
{
/// <summary>
/// Central file header signature (0x02014B50)
/// </summary>
public uint Signature { get; set; }
/// <summary>
/// Host system on which the file attributes are compatible
/// </summary>
public HostSystem HostSystem { get; set; }
/// <summary>
/// ZIP specification version
/// </summary>
public byte VersionMadeBy { get; set; }
/// <summary>
/// Version needed to extract
/// </summary>
/// <remarks>TODO: Add mapping of versions</remarks>
public ushort VersionNeededToExtract { get; set; }
/// <summary>
/// General purpose bit flag
/// </summary>
public GeneralPurposeBitFlags Flags { get; set; }
/// <summary>
/// Compression method
/// </summary>
public CompressionMethod CompressionMethod { get; set; }
/// <summary>
/// Last modified file time
/// </summary>
public ushort LastModifedFileTime { get; set; }
/// <summary>
/// Last modified file date
/// </summary>
public ushort LastModifiedFileDate { get; set; }
/// <summary>
/// CRC-32
/// </summary>
public uint CRC32 { get; set; }
/// <summary>
/// Compressed size
/// </summary>
public uint CompressedSize { get; set; }
/// <summary>
/// Uncompressed size
/// </summary>
public uint UncompressedSize { get; set; }
/// <summary>
/// File name length
/// </summary>
public ushort FileNameLength { get; set; }
/// <summary>
/// Extra field length
/// </summary>
public ushort ExtraFieldLength { get; set; }
/// <summary>
/// File comment length
/// </summary>
public ushort FileCommentLength { get; set; }
/// <summary>
/// Disk number start
/// </summary>
public ushort DiskNumberStart { get; set; }
/// <summary>
/// Internal file attributes
/// </summary>
public InternalFileAttributes InternalFileAttributes { get; set; }
/// <summary>
/// External file attributes
/// </summary>
public uint ExternalFileAttributes { get; set; }
/// <summary>
/// Relative offset of local header
/// </summary>
/// <remarks>
/// If ZIP64 and value is 0xFFFFFFFF, size will be in the
/// extended information extra field
/// </remarks>
public uint RelativeOffsetOfLocalHeader { get; set; }
/// <summary>
/// File name (variable size)
/// </summary>
public string? FileName { get; set; }
/// <summary>
/// Extra field (variable size)
/// </summary>
public byte[]? ExtraField { get; set; }
/// <summary>
/// File comment (variable size)
/// </summary>
public string? FileComment { get; set; }
}
}

85
PKZIP/Constants.cs Normal file
View File

@@ -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
}
}

29
PKZIP/DataDescriptor.cs Normal file
View File

@@ -0,0 +1,29 @@
namespace SabreTools.Models.PKZIP
{
/// <summary>
/// Data descriptor
/// </summary>
/// <see href="https://pkwaredownloads.blob.core.windows.net/pkware-general/Documentation/APPNOTE-6.3.9.TXT"/>
public class DataDescriptor
{
/// <summary>
/// Recommended, but optional, signature (0x08074B50)
/// </summary>
public uint? Signature { get; set; }
/// <summary>
/// CRC-32
/// </summary>
public uint CRC32 { get; set; }
/// <summary>
/// Compressed size
/// </summary>
public uint CompressedSize { get; set; }
/// <summary>
/// Uncompressed size
/// </summary>
public uint UncompressedSize { get; set; }
}
}

29
PKZIP/DataDescriptor64.cs Normal file
View File

@@ -0,0 +1,29 @@
namespace SabreTools.Models.PKZIP
{
/// <summary>
/// Data descriptor (ZIP64)
/// </summary>
/// <see href="https://pkwaredownloads.blob.core.windows.net/pkware-general/Documentation/APPNOTE-6.3.9.TXT"/>
public class DataDescriptor64
{
/// <summary>
/// Recommended, but optional, signature (0x08074B50)
/// </summary>
public uint? Signature { get; set; }
/// <summary>
/// CRC-32
/// </summary>
public uint CRC32 { get; set; }
/// <summary>
/// Compressed size
/// </summary>
public ulong CompressedSize { get; set; }
/// <summary>
/// Uncompressed size
/// </summary>
public ulong UncompressedSize { get; set; }
}
}

24
PKZIP/DigitalSignature.cs Normal file
View File

@@ -0,0 +1,24 @@
namespace SabreTools.Models.PKZIP
{
/// <summary>
/// Digital signature
/// </summary>
/// <see href="https://pkwaredownloads.blob.core.windows.net/pkware-general/Documentation/APPNOTE-6.3.9.TXT"/>
public class DigitalSignature
{
/// <summary>
/// Header signature (0x05054B50)
/// </summary>
public uint Signature { get; set; }
/// <summary>
/// Data length
/// </summary>
public ushort DataLength { get; set; }
/// <summary>
/// Signature data (variable size)
/// </summary>
public byte[]? SignatureData { get; set; }
}
}

View File

@@ -0,0 +1,29 @@
namespace SabreTools.Models.PKZIP
{
/// <summary>
/// Zip64 end of central directory locator
/// </summary>
/// <see href="https://pkwaredownloads.blob.core.windows.net/pkware-general/Documentation/APPNOTE-6.3.9.TXT"/>
public class EndOfCentralDirectoryLocator64
{
/// <summary>
/// ZIP64 end of central directory locator signature (0x07064B50)
/// </summary>
public uint Signature { get; set; }
/// <summary>
/// Number of the disk with the start of the end of central directory
/// </summary>
public uint StartDiskNumber { get; set; }
/// <summary>
/// Relative offset of start of central directory record
/// </summary>
public ulong CentralDirectoryOffset { get; set; }
/// <summary>
/// Total number of disks
/// </summary>
public uint TotalDisks { get; set; }
}
}

View File

@@ -0,0 +1,79 @@
namespace SabreTools.Models.PKZIP
{
/// <summary>
/// End of central directory record
/// </summary>
/// <see href="https://pkwaredownloads.blob.core.windows.net/pkware-general/Documentation/APPNOTE-6.3.9.TXT"/>
public class EndOfCentralDirectoryRecord
{
/// <summary>
/// End of central directory signature (0x06054B50)
/// </summary>
public uint Signature { get; set; }
/// <summary>
/// Number of this disk
/// </summary>
/// <remarks>
/// If ZIP64 and value is 0xFFFF, size will be in the
/// extended information extra field
/// </remarks>
public ushort DiskNumber { get; set; }
/// <summary>
/// Number of the disk with the start of the central directory
/// </summary>
/// <remarks>
/// If ZIP64 and value is 0xFFFF, size will be in the
/// extended information extra field
/// </remarks>
public ushort StartDiskNumber { get; set; }
/// <summary>
/// Total number of entries in the central directory on this disk
/// </summary>
/// <remarks>
/// If ZIP64 and value is 0xFFFF, size will be in the
/// extended information extra field
/// </remarks>
public ushort TotalEntriesOnDisk { get; set; }
/// <summary>
/// Total number of entries in the central directory
/// </summary>
/// <remarks>
/// If ZIP64 and value is 0xFFFF, size will be in the
/// extended information extra field
/// </remarks>
public ushort TotalEntries { get; set; }
/// <summary>
/// Size of the central directory
/// </summary>
/// <remarks>
/// If ZIP64 and value is 0xFFFFFFFF, size will be in the
/// extended information extra field
/// </remarks>
public uint CentralDirectorySize { get; set; }
/// <summary>
/// Offset of start of central directory with respect to the
/// starting disk number
/// </summary>
/// <remarks>
/// If ZIP64 and value is 0xFFFFFFFF, size will be in the
/// extended information extra field
/// </remarks>
public uint CentralDirectoryOffset { get; set; }
/// <summary>
/// .ZIP file comment length
/// </summary>
public ushort FileCommentLength { get; set; }
/// <summary>
/// .ZIP file comment
/// </summary>
public string? FileComment { get; set; }
}
}

View File

@@ -0,0 +1,72 @@
namespace SabreTools.Models.PKZIP
{
/// <summary>
/// Zip64 end of central directory record
/// </summary>
/// <see href="https://pkwaredownloads.blob.core.windows.net/pkware-general/Documentation/APPNOTE-6.3.9.TXT"/>
public class EndOfCentralDirectoryRecord64
{
/// <summary>
/// ZIP64 end of central directory signature (0x06064B50)
/// </summary>
public uint Signature { get; set; }
/// <summary>
/// Size of ZIP64 end of central directory record
/// </summary>
/// <remarks>SizeOfFixedFields + SizeOfVariableData - 12</remarks>
public ulong DirectoryRecordSize { get; set; }
/// <summary>
/// Host system on which the file attributes are compatible
/// </summary>
public HostSystem HostSystem { get; set; }
/// <summary>
/// ZIP specification version
/// </summary>
public byte VersionMadeBy { get; set; }
/// <summary>
/// Version needed to extract
/// </summary>
/// <remarks>TODO: Add mapping of versions</remarks>
public ushort VersionNeededToExtract { get; set; }
/// <summary>
/// Number of this disk
/// </summary>
public uint DiskNumber { get; set; }
/// <summary>
/// Number of the disk with the start of the central directory
/// </summary>
public uint StartDiskNumber { get; set; }
/// <summary>
/// Total number of entries in the central directory on this disk
/// </summary>
public ulong TotalEntriesOnDisk { get; set; }
/// <summary>
/// Total number of entries in the central directory
/// </summary>
public ulong TotalEntries { get; set; }
/// <summary>
/// Size of the central directory
/// </summary>
public ulong CentralDirectorySize { get; set; }
/// <summary>
/// Offset of start of central directory with respect to the
/// starting disk number
/// </summary>
public ulong CentralDirectoryOffset { get; set; }
/// <summary>
/// ZIP64 extensible data sector
/// </summary>
public byte[]? ExtensibleDataSector { get; set; }
}
}

674
PKZIP/Enums.cs Normal file
View File

@@ -0,0 +1,674 @@
using System;
/// <see href="https://pkwaredownloads.blob.core.windows.net/pkware-general/Documentation/APPNOTE-6.3.9.TXT"/>
namespace SabreTools.Models.PKZIP
{
public enum CompressionMethod : ushort
{
/// <summary>
/// The file is stored (no compression)
/// </summary>
Stored = 0,
/// <summary>
/// The file is Shrunk
/// </summary>
Shrunk = 1,
/// <summary>
/// The file is Reduced with compression factor 1
/// </summary>
ReducedCompressionFactor1 = 2,
/// <summary>
/// The file is Reduced with compression factor 2
/// </summary>
ReducedCompressionFactor2 = 3,
/// <summary>
/// The file is Reduced with compression factor 3
/// </summary>
ReducedCompressionFactor3 = 4,
/// <summary>
/// The file is Reduced with compression factor 4
/// </summary>
ReducedCompressionFactor4 = 5,
/// <summary>
/// The file is Imploded
/// </summary>
Implode = 6,
/// <summary>
/// Reserved for Tokenizing compression algorithm
/// </summary>
TokenizingCompressionAlgorithm = 7,
/// <summary>
/// The file is Deflated
/// </summary>
Deflate = 8,
/// <summary>
/// Enhanced Deflating using Deflate64(tm)
/// </summary>
Deflate64 = 9,
/// <summary>
/// PKWARE Data Compression Library Imploding (old IBM TERSE)
/// </summary>
PKWAREDataCompressionLibraryImplode = 10,
/// <summary>
/// Reserved by PKWARE
/// </summary>
CompressionMethod11 = 11,
/// <summary>
/// File is compressed using BZIP2 algorithm
/// </summary>
BZIP2 = 12,
/// <summary>
/// Reserved by PKWARE
/// </summary>
CompressionMethod13 = 13,
/// <summary>
/// LZMA
/// </summary>
LZMA = 14,
/// <summary>
/// Reserved by PKWARE
/// </summary>
CompressionMethod15 = 15,
/// <summary>
/// IBM z/OS CMPSC Compression
/// </summary>
IBMzOSCMPSC = 16,
/// <summary>
/// Reserved by PKWARE
/// </summary>
CompressionMethod17 = 17,
/// <summary>
/// File is compressed using IBM TERSE (new)
/// </summary>
IBMTERSE = 18,
/// <summary>
/// IBM LZ77 z Architecture
/// </summary>
IBMLZ77 = 19,
/// <summary>
/// deprecated (use method 93 for zstd)
/// </summary>
[Obsolete]
OldZstandard = 20,
/// <summary>
/// Zstandard (zstd) Compression
/// </summary>
Zstandard = 93,
/// <summary>
/// MP3 Compression
/// </summary>
MP3 = 94,
/// <summary>
/// XZ Compression
/// </summary>
XZ = 95,
/// <summary>
/// JPEG variant
/// </summary>
JPEGVariant = 96,
/// <summary>
/// WavPack compressed data
/// </summary>
WavPack = 97,
/// <summary>
/// PPMd version I, Rev 1
/// </summary>
PPMdVersionIRev1 = 98,
/// <summary>
/// AE-x encryption marker
/// </summary>
AExEncryption = 99,
}
[Flags]
public enum GeneralPurposeBitFlags : ushort
{
/// <summary>
/// Indicates that the file is encrypted
/// </summary>
FileEncrypted = 0b0000_0000_0000_0001,
#region Compression Method 6 (Implode)
/// <summary>
/// Set - 8K sliding dictionary
/// Clear - 4K sliding dictionary
/// </summary>
LargeSlidingDictionary = 0b0000_0000_0000_0010,
/// <summary>
/// Set - 3 Shannon-Fano trees were used
/// Clear - 2 Shannon-Fano trees were used
/// </summary>
ThreeTrees = 0b0000_0000_0000_0100,
#endregion
#region Compression Method 8 (Deflate)
/// <summary>
/// Normal (-en) compression
/// </summary>
NormalCompression = 0b0000_0000_0000_0000,
/// <summary>
/// Maximum (-ex) compression
/// </summary>
MaximumCompression = 0b0000_0000_0000_0010,
/// <summary>
/// Fast (-ef) compression
/// </summary>
FastCompression = 0b0000_0000_0000_0100,
/// <summary>
/// Super Fast (-es) compression
/// </summary>
SuperFastCompression = 0b0000_0000_0000_0110,
#endregion
#region Compression Method 14 (LZMA)
/// <summary>
/// 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.
/// </summary>
EndOfStreamMarker = 0b0000_0000_0000_0010,
#endregion
/// <summary>
/// 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.
/// </summary>
NoCRC = 0b0000_0000_0000_1000,
/// <summary>
/// Reserved for use with method 8, for enhanced deflating.
/// </summary>
EnhancedDeflateReserved = 0b0000_0000_0001_0000,
/// <summary>
/// Indicates that the file is compressed patched data.
/// </summary>
/// <remarks>Requires PKZIP version 2.70 or greater</remarks>
CompressedPatchedData = 0b0000_0000_0010_0000,
/// <summary>
/// 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.
/// </summary>
StrongEncryption = 0b0000_0000_0100_0000,
/// <summary>
/// Currently unused
/// </summary>
Bit7 = 0b0000_0000_1000_0000,
/// <summary>
/// Currently unused
/// </summary>
Bit8 = 0b0000_0001_0000_0000,
/// <summary>
/// Currently unused
/// </summary>
Bit9 = 0b0000_0010_0000_0000,
/// <summary>
/// Currently unused
/// </summary>
Bit10 = 0b0000_0100_0000_0000,
/// <summary>
/// Set - the filename and comment fields for this
/// file MUST be encoded using UTF-8.
/// </summary>
LanguageEncodingFlag = 0b0000_1000_0000_0000,
/// <summary>
/// Reserved by PKWARE for enhanced compression
/// </summary>
PKWAREEnhancedCompression = 0b0001_0000_0000_0000,
/// <summary>
/// Set - Set when encrypting the Central Directory to
/// indicate selected data values in the Local
/// Header are masked to hide their actual values
/// </summary>
LocalHeaderValuesMasked = 0b0010_0000_0000_0000,
/// <summary>
/// Reserved by PKWARE for alternate streams
/// </summary>
PKWAREAlternateStreams = 0b0100_0000_0000_0000,
/// <summary>
/// Reserved by PKWARE
/// </summary>
PKWAREReserved = 0b1000_0000_0000_0000,
}
public enum HeaderID : ushort
{
/// <summary>
/// Zip64 extended information extra field
/// </summary>
Zip64ExtendedInformation = 0x0001,
/// <summary>
/// AV Info
/// </summary>
AVInfo = 0x0007,
/// <summary>
/// Reserved for extended language encoding data (PFS)
/// </summary>
ExtendedLanguageEncodingData = 0x0008,
/// <summary>
/// OS/2
/// </summary>
OS2 = 0x0009,
/// <summary>
/// NTFS
/// </summary>
NTFS = 0x000A,
/// <summary>
/// OpenVMS
/// </summary>
OpenVMS = 0x000C,
/// <summary>
/// UNIX
/// </summary>
UNIX = 0x000D,
/// <summary>
/// Reserved for file stream and fork descriptors
/// </summary>
FileStreamFork = 0x000E,
/// <summary>
/// Patch Descriptor
/// </summary>
PatchDescriptor = 0x000F,
/// <summary>
/// PKCS#7 Store for X.509 Certificates
/// </summary>
PKCSStore = 0x0014,
/// <summary>
/// X.509 Certificate ID and Signature for individual file
/// </summary>
X509IndividualFile = 0x0015,
/// <summary>
/// X.509 Certificate ID for Central Directory
/// </summary>
X509CentralDirectory = 0x0016,
/// <summary>
/// Strong Encryption Header
/// </summary>
StrongEncryptionHeader = 0x0017,
/// <summary>
/// Record Management Controls
/// </summary>
RecordManagementControls = 0x0018,
/// <summary>
/// PKCS#7 Encryption Recipient Certificate List
/// </summary>
PKCSCertificateList = 0x0019,
/// <summary>
/// Reserved for Timestamp record
/// </summary>
Timestamp = 0x0020,
/// <summary>
/// Policy Decryption Key Record
/// </summary>
PolicyDecryptionKey = 0x0021,
/// <summary>
/// Smartcrypt Key Provider Record
/// </summary>
SmartcryptKeyProvider = 0x0022,
/// <summary>
/// Smartcrypt Policy Key Data Record
/// </summary>
SmartcryptPolicyKeyData = 0x0023,
/// <summary>
/// IBM S/390 (Z390), AS/400 (I400) attributes - uncompressed
/// </summary>
IBMS390AttributesUncompressed = 0x0065,
/// <summary>
/// Reserved for IBM S/390 (Z390), AS/400 (I400) attributes - compressed
/// </summary>
IBMS390AttributesCompressed = 0x0066,
/// <summary>
/// POSZIP 4690 (reserved)
/// </summary>
POSZIP4690 = 0x4690,
#region Third-Party
/// <summary>
/// Macintosh
/// </summary>
Macintosh = 0x07C8,
/// <summary>
/// ZipIt Macintosh
/// </summary>
ZipItMacintosh = 0x2605,
/// <summary>
/// ZipIt Macintosh 1.3.5+
/// </summary>
ZipItMacintosh135Plus = 0x2705,
/// <summary>
/// ZipIt Macintosh 1.3.5+
/// </summary>
ZipItMacintosh135PlusAlt = 0x2805,
/// <summary>
/// Info-ZIP Macintosh
/// </summary>
InfoZIPMacintosh = 0x334D,
/// <summary>
/// Acorn/SparkFS
/// </summary>
AcornSparkFS = 0x4341,
/// <summary>
/// Windows NT security descriptor (binary ACL)
/// </summary>
WindowsNTSecurityDescriptor = 0x4453,
/// <summary>
/// VM/CMS
/// </summary>
VMCMS = 0x4704,
/// <summary>
/// MVS
/// </summary>
MVS = 0x470F,
/// <summary>
/// FWKCS MD5
/// </summary>
FWKCSMD5 = 0x4B46,
/// <summary>
/// OS/2 access control list (text ACL)
/// </summary>
OS2AccessControlList = 0x4C41,
/// <summary>
/// Info-ZIP OpenVMS
/// </summary>
InfoZIPOpenVMS = 0x4D49,
/// <summary>
/// Xceed original location extra field
/// </summary>
XceedOriginalLocation = 0x4F4C,
/// <summary>
/// AOS/VS (ACL)
/// </summary>
ADSVS = 0x5356,
/// <summary>
/// extended timestamp
/// </summary>
ExtendedTimestamp = 0x5455,
/// <summary>
/// Xceed unicode extra field
/// </summary>
XceedUnicode = 0x554E,
/// <summary>
/// Info-ZIP UNIX (original, also OS/2, NT, etc)
/// </summary>
InfoZIPUNIX = 0x5855,
/// <summary>
/// Info-ZIP Unicode Comment Extra Field
/// </summary>
InfoZIPUnicodeComment = 0x6375,
/// <summary>
/// BeOS/BeBox
/// </summary>
BeOSBeBox = 0x6542,
/// <summary>
/// Info-ZIP Unicode Path Extra Field
/// </summary>
InfoZIPUnicodePath = 0x7075,
/// <summary>
/// ASi UNIX
/// </summary>
ASiUnix = 0x756E,
/// <summary>
/// Info-ZIP UNIX (new)
/// </summary>
InfoZIPUnixNew = 0x7855,
/// <summary>
/// Data Stream Alignment (Apache Commons-Compress)
/// </summary>
DataStreamAlignment = 0xA11E,
/// <summary>
/// Microsoft Open Packaging Growth Hint
/// </summary>
MicrosoftOpenPackagingGrowthHint = 0xA220,
/// <summary>
/// SMS/QDOS
/// </summary>
SMSQDOS = 0xFD4A,
/// <summary>
/// AE-x encryption structure
/// </summary>
AExEncryptionStructure = 0x9901,
/// <summary>
/// Unknown
/// </summary>
Unknown = 0x9902,
#endregion
}
public enum HostSystem : byte
{
/// <summary>
/// MS-DOS and OS/2 (FAT / VFAT / FAT32 file systems)
/// </summary>
MSDOS = 0,
/// <summary>
/// Amiga
/// </summary>
Amiga = 1,
/// <summary>
/// OpenVMS
/// </summary>
OpenVMS = 2,
/// <summary>
/// UNIX
/// </summary>
UNIX = 3,
/// <summary>
/// VM/CMS
/// </summary>
VMCMS = 4,
/// <summary>
/// Atari ST
/// </summary>
AtariST = 5,
/// <summary>
/// OS/2 H.P.F.S.
/// </summary>
OS2HPFS = 6,
/// <summary>
/// Macintosh
/// </summary>
Macintosh = 7,
/// <summary>
/// Z-System
/// </summary>
ZSystem = 8,
/// <summary>
/// CP/M
/// </summary>
CPM = 9,
/// <summary>
/// Windows NTFS
/// </summary>
WindowsNTFS = 10,
/// <summary>
/// MVS (OS/390 - Z/OS)
/// </summary>
MVS = 11,
/// <summary>
/// VSE
/// </summary>
VSE = 12,
/// <summary>
/// Acorn Risc
/// </summary>
AcornRisc = 13,
/// <summary>
/// VFAT
/// </summary>
VFAT = 14,
/// <summary>
/// alternate MVS
/// </summary>
AlternateVMS = 15,
/// <summary>
/// BeOS
/// </summary>
BeOS = 16,
/// <summary>
/// Tandem
/// </summary>
Tandem = 17,
/// <summary>
/// OS/400
/// </summary>
OS400 = 18,
/// <summary>
/// OS X (Darwin)
/// </summary>
OSX = 19,
// 20 thru 255 - unused
}
[Flags]
public enum InternalFileAttributes : ushort
{
/// <summary>
/// Set - The file is apparently an ASCII or text file
/// Clear - The file is apparently binary data
/// </summary>
ASCII = 0b0000_0000_0000_0001,
/// <summary>
/// Reserved for use by PKWARE
/// </summary>
Bit1 = 0b0000_0000_0000_0010,
/// <summary>
/// Reserved for use by PKWARE
/// </summary>
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.
*/
}
}

77
PKZIP/LocalFileHeader.cs Normal file
View File

@@ -0,0 +1,77 @@
namespace SabreTools.Models.PKZIP
{
/// <summary>
/// PKZIP local file header
/// </summary>
/// <see href="https://petlibrary.tripod.com/ZIP.HTM"/>
/// <see href="https://pkwaredownloads.blob.core.windows.net/pkware-general/Documentation/APPNOTE-6.3.9.TXT"/>
public class LocalFileHeader
{
/// <summary>
/// Signature (0x04034B50)
/// </summary>
public uint Signature { get; set; }
/// <summary>
/// Version needed to extract
/// decimal value/10 = major version #
/// decimal value%10 = minor version #
/// </summary>
public ushort Version { get; set; }
/// <summary>
/// General purpose bit flag
/// </summary>
public GeneralPurposeBitFlags Flags { get; set; }
/// <summary>
/// Compression method
/// </summary>
public CompressionMethod CompressionMethod { get; set; }
/// <summary>
/// Last modified file time
/// </summary>
public ushort LastModifedFileTime { get; set; }
/// <summary>
/// Last modified file date
/// </summary>
public ushort LastModifiedFileDate { get; set; }
/// <summary>
/// CRC-32
/// </summary>
public uint CRC32 { get; set; }
/// <summary>
/// Compressed size
/// </summary>
public uint CompressedSize { get; set; }
/// <summary>
/// Uncompressed size
/// </summary>
public uint UncompressedSize { get; set; }
/// <summary>
/// File name length
/// </summary>
public ushort FileNameLength { get; set; }
/// <summary>
/// Extra field length
/// </summary>
public ushort ExtraFieldLength { get; set; }
/// <summary>
/// File name (variable size)
/// </summary>
public string? FileName { get; set; }
/// <summary>
/// Extra field (variable size)
/// </summary>
public byte[]? ExtraField { get; set; }
}
}

View File

@@ -0,0 +1,25 @@
namespace SabreTools.Models.PKZIP
{
/// <summary>
/// Special purpose data for ZIP64 extensible data field
/// </summary>
/// <see href="https://pkwaredownloads.blob.core.windows.net/pkware-general/Documentation/APPNOTE-6.3.9.TXT"/>
public class SpecialPurposeDataHeader
{
/// <summary>
/// Header ID (data type)
/// </summary>
public HeaderID HeaderID { get; set; }
/// <summary>
/// Data size
/// </summary>
public uint DataSize { get; set; }
/// <summary>
/// Data (variable size)
/// </summary>
/// TODO: Implement models for all extra field types - 4.5.3
public byte[]? Data { get; set; }
}
}