diff --git a/SabreTools.Core/Constants.cs b/SabreTools.Core/Constants.cs index 8f9f3747..7e540b5a 100644 --- a/SabreTools.Core/Constants.cs +++ b/SabreTools.Core/Constants.cs @@ -96,71 +96,5 @@ namespace SabreTools.Core public const int SHA512Length = 128; #endregion - - #region TorrentZip, T7z, and TGZ headers - - /* TorrentZip Header Format - https://pkware.cachefly.net/webdocs/APPNOTE/APPNOTE_6.2.0.txt - http://www.romvault.com/trrntzip_explained.doc - - 00-03 Local file header signature (0x50, 0x4B, 0x03, 0x04) ZipSignature - 04-05 Version needed to extract (0x14, 0x00) - 06-07 General purpose bit flag (0x02, 0x00) - 08-09 Compression method (0x08, 0x00) - 0A-0B Last mod file time (0x00, 0xBC) - 0C-0D Last mod file date (0x98, 0x21) - */ - public readonly static byte[] TorrentZipHeader = new byte[] { 0x50, 0x4b, 0x03, 0x04, 0x14, 0x00, 0x02, 0x00, 0x08, 0x00, 0x00, 0xbc, 0x98, 0x21 }; - - /* Torrent7z Header Format - http://cpansearch.perl.org/src/BJOERN/Compress-Deflate7-1.0/7zip/DOC/7zFormat.txt - - 00-05 Local file header signature (0x37, 0x7A, 0xBC, 0xAF, 0x27, 0x1C) SevenZipSignature - 06-07 ArchiveVersion (0x00, 0x03) - The rest is unknown - */ - public readonly static byte[] Torrent7ZipHeader = new byte[] { 0x37, 0x7a, 0xbc, 0xaf, 0x27, 0x1c, 0x00, 0x03 }; - public readonly static byte[] Torrent7ZipSignature = new byte[] { 0xa9, 0xa9, 0x9f, 0xd1, 0x57, 0x08, 0xa9, 0xd7, 0xea, 0x29, 0x64, 0xb2, - 0x36, 0x1b, 0x83, 0x52, 0x33, 0x00, 0x74, 0x6f, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x37, 0x7a, 0x5f, 0x30, 0x2e, 0x39, 0x62, 0x65, 0x74, 0x61 }; - - /* (Torrent)GZ Header Format - https://tools.ietf.org/html/rfc1952 - - 00-01 Identification (0x1F, 0x8B) GzSignature - 02 Compression Method (0-7 reserved, 8 deflate; 0x08) - 03 Flags (0 FTEXT, 1 FHCRC, 2 FEXTRA, 3 FNAME, 4 FCOMMENT, 5 reserved, 6 reserved, 7 reserved; 0x04) - 04-07 Modification time (Unix format; 0x00, 0x00, 0x00, 0x00) - 08 Extra Flags (2 maximum compression, 4 fastest algorithm; 0x00) - 09 OS (See list on https://tools.ietf.org/html/rfc1952; 0x00) - 0A-0B Length of extra field (mirrored; 0x1C, 0x00) - 0C-27 Extra field - 0C-1B MD5 Hash - 1C-1F CRC hash - 20-27 Int64 size (mirrored) - */ - public readonly static byte[] TorrentGZHeader = new byte[] { 0x1f, 0x8b, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00 }; - - /* (Torrent)XZ Header Format - https://tukaani.org/xz/xz-file-format.txt - - 00-05 Identification (0xFD, '7', 'z', 'X', 'Z', 0x00) XzSignature - 06 Flags (0x01 - CRC32, 0x04 - CRC64, 0x0A - SHA-256) - 07-0A Flags CRC32 (uint, little-endian) - */ - public readonly static byte[] TorrentXZHeader = new byte[] { 0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00, 0x01, 0x69, 0x22, 0xde, 0x36 }; - - #endregion - - #region ZIP internal signatures - - public const uint LocalFileHeaderSignature = 0x04034b50; - public const uint EndOfLocalFileHeaderSignature = 0x08074b50; - public const uint CentralDirectoryHeaderSignature = 0x02014b50; - public const uint EndOfCentralDirSignature = 0x06054b50; - public const uint Zip64EndOfCentralDirSignature = 0x06064b50; - public const uint Zip64EndOfCentralDirectoryLocator = 0x07064b50; - public const uint TorrentZipFileDateTime = 0x2198BC00; - - #endregion } } diff --git a/SabreTools.FileTypes/GZipArchive.cs b/SabreTools.FileTypes/GZipArchive.cs index f739ec07..776a6989 100644 --- a/SabreTools.FileTypes/GZipArchive.cs +++ b/SabreTools.FileTypes/GZipArchive.cs @@ -18,6 +18,27 @@ namespace SabreTools.FileTypes /// public class GZipArchive : BaseArchive { + #region Constants + + /* (Torrent)GZ Header Format + https://tools.ietf.org/html/rfc1952 + + 00-01 Identification (0x1F, 0x8B) GzSignature + 02 Compression Method (0-7 reserved, 8 deflate; 0x08) + 03 Flags (0 FTEXT, 1 FHCRC, 2 FEXTRA, 3 FNAME, 4 FCOMMENT, 5 reserved, 6 reserved, 7 reserved; 0x04) + 04-07 Modification time (Unix format; 0x00, 0x00, 0x00, 0x00) + 08 Extra Flags (2 maximum compression, 4 fastest algorithm; 0x00) + 09 OS (See list on https://tools.ietf.org/html/rfc1952; 0x00) + 0A-0B Length of extra field (mirrored; 0x1C, 0x00) + 0C-27 Extra field + 0C-1B MD5 Hash + 1C-1F CRC hash + 20-27 Int64 size (mirrored) + */ + private readonly static byte[] TorrentGZHeader = new byte[] { 0x1f, 0x8b, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00 }; + + #endregion + #region Fields /// @@ -295,7 +316,7 @@ namespace SabreTools.FileTypes if (i == 4 || i == 5 || i == 6 || i == 7 || i == 9) continue; - correct &= (header[i] == Constants.TorrentGZHeader[i]); + correct &= (header[i] == TorrentGZHeader[i]); } if (!correct) @@ -361,7 +382,7 @@ namespace SabreTools.FileTypes { continue; } - correct &= (header[i] == Constants.TorrentGZHeader[i]); + correct &= (header[i] == TorrentGZHeader[i]); } if (!correct) { @@ -440,7 +461,7 @@ namespace SabreTools.FileTypes BinaryWriter sw = new BinaryWriter(outputStream); // Write standard header and TGZ info - byte[] data = Constants.TorrentGZHeader + byte[] data = TorrentGZHeader .Concat(baseFile.MD5) // MD5 .Concat(baseFile.CRC) // CRC .ToArray(); diff --git a/SabreTools.FileTypes/SevenZipArchive.cs b/SabreTools.FileTypes/SevenZipArchive.cs index 23ec5bff..d5e7655d 100644 --- a/SabreTools.FileTypes/SevenZipArchive.cs +++ b/SabreTools.FileTypes/SevenZipArchive.cs @@ -17,6 +17,21 @@ namespace SabreTools.FileTypes /// public class SevenZipArchive : BaseArchive { + #region Constants + + /* Torrent7z Header Format + http://cpansearch.perl.org/src/BJOERN/Compress-Deflate7-1.0/7zip/DOC/7zFormat.txt + + 00-05 Local file header signature (0x37, 0x7A, 0xBC, 0xAF, 0x27, 0x1C) SevenZipSignature + 06-07 ArchiveVersion (0x00, 0x03) + The rest is unknown + */ + private readonly static byte[] Torrent7ZipHeader = new byte[] { 0x37, 0x7a, 0xbc, 0xaf, 0x27, 0x1c, 0x00, 0x03 }; + private readonly static byte[] Torrent7ZipSignature = new byte[] { 0xa9, 0xa9, 0x9f, 0xd1, 0x57, 0x08, 0xa9, 0xd7, 0xea, 0x29, 0x64, 0xb2, + 0x36, 0x1b, 0x83, 0x52, 0x33, 0x00, 0x74, 0x6f, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x37, 0x7a, 0x5f, 0x30, 0x2e, 0x39, 0x62, 0x65, 0x74, 0x61 }; + + #endregion + #region Constructors /// diff --git a/SabreTools.FileTypes/XZArchive.cs b/SabreTools.FileTypes/XZArchive.cs index beb8df05..38fcaefe 100644 --- a/SabreTools.FileTypes/XZArchive.cs +++ b/SabreTools.FileTypes/XZArchive.cs @@ -15,6 +15,19 @@ namespace SabreTools.FileTypes /// public class XZArchive : BaseArchive { + #region Constants + + /* (Torrent)XZ Header Format + https://tukaani.org/xz/xz-file-format.txt + + 00-05 Identification (0xFD, '7', 'z', 'X', 'Z', 0x00) XzSignature + 06 Flags (0x01 - CRC32, 0x04 - CRC64, 0x0A - SHA-256) + 07-0A Flags CRC32 (uint, little-endian) + */ + private readonly static byte[] TorrentXZHeader = new byte[] { 0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00, 0x01, 0x69, 0x22, 0xde, 0x36 }; + + #endregion + #region Fields /// diff --git a/SabreTools.FileTypes/ZipArchive.cs b/SabreTools.FileTypes/ZipArchive.cs index fa866c2d..d8b2b6ee 100644 --- a/SabreTools.FileTypes/ZipArchive.cs +++ b/SabreTools.FileTypes/ZipArchive.cs @@ -16,6 +16,31 @@ namespace SabreTools.FileTypes /// public class ZipArchive : BaseArchive { + #region Constants + + private const uint LocalFileHeaderSignature = 0x04034b50; + private const uint EndOfLocalFileHeaderSignature = 0x08074b50; + private const uint CentralDirectoryHeaderSignature = 0x02014b50; + private const uint EndOfCentralDirSignature = 0x06054b50; + private const uint Zip64EndOfCentralDirSignature = 0x06064b50; + private const uint Zip64EndOfCentralDirectoryLocator = 0x07064b50; + private const uint TorrentZipFileDateTime = 0x2198BC00; + + /* TorrentZip Header Format + https://pkware.cachefly.net/webdocs/APPNOTE/APPNOTE_6.2.0.txt + http://www.romvault.com/trrntzip_explained.doc + + 00-03 Local file header signature (0x50, 0x4B, 0x03, 0x04) ZipSignature + 04-05 Version needed to extract (0x14, 0x00) + 06-07 General purpose bit flag (0x02, 0x00) + 08-09 Compression method (0x08, 0x00) + 0A-0B Last mod file time (0x00, 0xBC) + 0C-0D Last mod file date (0x98, 0x21) + */ + private readonly static byte[] TorrentZipHeader = new byte[] { 0x50, 0x4b, 0x03, 0x04, 0x14, 0x00, 0x02, 0x00, 0x08, 0x00, 0x00, 0xbc, 0x98, 0x21 }; + + #endregion + #region Constructors ///