diff --git a/SabreTools.Helper/Data/Enums.cs b/SabreTools.Helper/Data/Enums.cs index 2b558bff..adff4f8e 100644 --- a/SabreTools.Helper/Data/Enums.cs +++ b/SabreTools.Helper/Data/Enums.cs @@ -164,4 +164,66 @@ } #endregion + + #region Archival + + /// + /// Version of tool archive made by + /// + public enum ArchiveVersion + { + MSDOSandOS2 = 0, + Amiga = 1, + OpenVMS = 2, + UNIX = 3, + VMCMS = 4, + AtariST = 5, + OS2HPFS = 6, + Macintosh = 7, + ZSystem = 8, + CPM = 9, + WindowsNTFS = 10, + MVS = 11, + VSE = 12, + AcornRisc = 13, + VFAT = 14, + AlternateMVS = 15, + BeOS = 16, + Tandem = 17, + OS400 = 18, + OSXDarwin = 19, + } + + /// + /// Compression method based on flag + /// + public enum CompressionMethod + { + Stored = 0, + Shrunk = 1, + ReducedCompressionFactor1 = 2, + ReducedCompressionFactor2 = 3, + ReducedCompressionFactor3 = 4, + ReducedCompressionFactor4 = 5, + Imploded = 6, + Tokenizing = 7, + Deflated = 8, + Delfate64 = 9, + PKWAREDataCompressionLibrary = 10, + BZIP2 = 12, + LZMA = 14, + IBMTERSE = 18, + IBMLZ77 = 19, + WavPak = 97, + PPMdVersionIRev1 = 98, + + // Reserved and unused (SHOULD NOT BE USED) + Type11 = 11, + Type13 = 13, + Type15 = 15, + Type16 = 16, + Type17 = 17, + } + + #endregion } diff --git a/SabreTools.Helper/Data/Flags.cs b/SabreTools.Helper/Data/Flags.cs index 64f98888..67ee155a 100644 --- a/SabreTools.Helper/Data/Flags.cs +++ b/SabreTools.Helper/Data/Flags.cs @@ -30,4 +30,54 @@ namespace SabreTools.Helper RedumpSHA1 = 0x080, RedumpSFV = 0x100, } + + /// + /// Determines the archive general bit flags + /// + [Flags] + public enum GeneralPurposeBitFlag + { + Encrypted = 0x0001, + ZeroedCRCAndSize = 0x0008, + CompressedPatchedData = 0x0020, + StrongEncryption = 0x0040, + LanguageEncodingFlag = 0x0800, + EncryptedCentralDirectory = 0x2000, + + // For Method 6 - Imploding + Imploding8KSlidingDictionary = 0x0002, + Imploding3ShannonFanoTrees = 0x0004, + + // For Methods 8 and 9 - Deflating + DeflatingMaximumCompression = 0x0002, + DeflatingFastCompression = 0x0004, + DeflatingSuperFastCompression = 0x0006, + EnhancedDeflating = 0x0010, + + // For Method 14 - LZMA + LZMAEOSMarkerUsed = 0x0002, + + // Reserved and unused (SHOULD NOT BE USED) + Bit7 = 0x0080, + Bit8 = 0x0100, + Bit9 = 0x0200, + Bit10 = 0x0400, + Bit12 = 0x1000, // Reserved by PKWARE for enhanced compression + Bit14 = 0x4000, // Reserved by PKWARE + Bit15 = 0x8000, // Reserved by PKWARE + } + + /// + /// Internal file attributes used by archives + /// + [Flags] + public enum InternalFileAttributes + { + ASCIIOrTextFile = 0x0001, + RecordLengthControl = 0x0002, + + // Reserved and unused (SHOULD NOT BE USED) + Bit1 = 0x0002, + Bit2 = 0x0004, + } } diff --git a/SabreTools.Helper/Data/Structs.cs b/SabreTools.Helper/Data/Structs.cs index b040f72c..f1596991 100644 --- a/SabreTools.Helper/Data/Structs.cs +++ b/SabreTools.Helper/Data/Structs.cs @@ -495,19 +495,19 @@ namespace SabreTools.Helper /// public struct ZipArchiveEntryStruct { - public short VersionMadeBy; - public short VersionNeeded; - public short GeneralPurposeFlag; - public short CompressionMethod; - public short LastModFileTime; - public short LastModFileDate; - public int CRC; - public int CompressedSize; - public int UncompressedSize; + public ArchiveVersion VersionMadeBy; + public ArchiveVersion VersionNeeded; + public GeneralPurposeBitFlag GeneralPurposeBitFlag; + public CompressionMethod CompressionMethod; + public ushort LastModFileTime; + public ushort LastModFileDate; + public uint CRC; + public uint CompressedSize; + public uint UncompressedSize; public string FileName; public string ExtraField; public string Comment; - public short InternalFileAttributes; + public InternalFileAttributes InternalFileAttributes; public int ExternalFileAttributes; public int RelativeOffset; } diff --git a/SabreTools.Helper/Tools/FileTools.cs b/SabreTools.Helper/Tools/FileTools.cs index d4e5c6a0..5645855c 100644 --- a/SabreTools.Helper/Tools/FileTools.cs +++ b/SabreTools.Helper/Tools/FileTools.cs @@ -440,7 +440,7 @@ namespace SabreTools.Helper Console.WriteLine("Entry CRC: " + zaes.CRC.ToString("X8")); Console.WriteLine("Entry External File Attributes: " + zaes.ExternalFileAttributes); Console.WriteLine("Entry Extra Field: " + zaes.ExtraField.Length + " " + zaes.ExtraField); - Console.WriteLine("Entry General Purpose Flag: " + zaes.GeneralPurposeFlag); + Console.WriteLine("Entry General Purpose Flag: " + zaes.GeneralPurposeBitFlag); Console.WriteLine("Entry Internal File Attributes: " + zaes.InternalFileAttributes); Console.WriteLine("Entry Last Modification File Date: " + zaes.LastModFileDate); Console.WriteLine("Entry Last Modification File Time: " + zaes.LastModFileTime); @@ -956,20 +956,20 @@ namespace SabreTools.Helper br.BaseStream.Seek(position, SeekOrigin.Begin); br.ReadInt32(); // central file header signature - zaes.VersionMadeBy = br.ReadInt16(); - zaes.VersionNeeded = br.ReadInt16(); - zaes.GeneralPurposeFlag = br.ReadInt16(); - zaes.CompressionMethod = br.ReadInt16(); - zaes.LastModFileTime = br.ReadInt16(); - zaes.LastModFileDate = br.ReadInt16(); - zaes.CRC = br.ReadInt32(); - zaes.CompressedSize = br.ReadInt32(); - zaes.UncompressedSize = br.ReadInt32(); + zaes.VersionMadeBy = (ArchiveVersion)br.ReadInt16(); + zaes.VersionNeeded = (ArchiveVersion)br.ReadInt16(); + zaes.GeneralPurposeBitFlag = (GeneralPurposeBitFlag)br.ReadInt16(); + zaes.CompressionMethod = (CompressionMethod)br.ReadInt16(); + zaes.LastModFileTime = br.ReadUInt16(); + zaes.LastModFileDate = br.ReadUInt16(); + zaes.CRC = br.ReadUInt32(); + zaes.CompressedSize = br.ReadUInt32(); + zaes.UncompressedSize = br.ReadUInt32(); int fileNameLength = br.ReadInt16(); int extraFieldLength = br.ReadInt16(); int fileCommentLength = br.ReadInt16(); br.ReadInt16(); // disk number start - zaes.InternalFileAttributes = br.ReadInt16(); + zaes.InternalFileAttributes = (InternalFileAttributes)br.ReadInt16(); zaes.ExternalFileAttributes = br.ReadInt32(); zaes.RelativeOffset = br.ReadInt32(); zaes.FileName = Style.ConvertHex(BitConverter.ToString(br.ReadBytes(fileNameLength)));