From ebe4ff742633f9e22f812dc73effc8f33d9b25b0 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Thu, 5 Mar 2026 11:27:45 -0500 Subject: [PATCH] Update packages --- ExtractionTool/ExtractionTool.csproj | 4 +- InfoPrint/InfoPrint.csproj | 4 +- .../SabreTools.Serialization.Test.csproj | 4 +- .../Readers/PortableExecutable.cs | 76 ++++++------------- .../SabreTools.Serialization.csproj | 8 +- .../Wrappers/PKZIP.Extraction.cs | 12 ++- .../Wrappers/RAR.Extraction.cs | 19 ++--- .../Wrappers/SevenZip.Extraction.cs | 12 ++- 8 files changed, 60 insertions(+), 79 deletions(-) diff --git a/ExtractionTool/ExtractionTool.csproj b/ExtractionTool/ExtractionTool.csproj index 88a70401..c56448bd 100644 --- a/ExtractionTool/ExtractionTool.csproj +++ b/ExtractionTool/ExtractionTool.csproj @@ -49,8 +49,8 @@ - - + + \ No newline at end of file diff --git a/InfoPrint/InfoPrint.csproj b/InfoPrint/InfoPrint.csproj index 61ce57e8..f1529398 100644 --- a/InfoPrint/InfoPrint.csproj +++ b/InfoPrint/InfoPrint.csproj @@ -33,8 +33,8 @@ - - + + \ No newline at end of file diff --git a/SabreTools.Serialization.Test/SabreTools.Serialization.Test.csproj b/SabreTools.Serialization.Test/SabreTools.Serialization.Test.csproj index 88200d35..a5fa8f62 100644 --- a/SabreTools.Serialization.Test/SabreTools.Serialization.Test.csproj +++ b/SabreTools.Serialization.Test/SabreTools.Serialization.Test.csproj @@ -22,12 +22,12 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/SabreTools.Serialization/Readers/PortableExecutable.cs b/SabreTools.Serialization/Readers/PortableExecutable.cs index 93c4edd3..629fd4da 100644 --- a/SabreTools.Serialization/Readers/PortableExecutable.cs +++ b/SabreTools.Serialization/Readers/PortableExecutable.cs @@ -905,7 +905,7 @@ namespace SabreTools.Serialization.Readers obj.ClassResource = data.ReadNullTerminatedUnicodeString(ref offset) ?? string.Empty; // Align to the WORD boundary if we're not at the end - AlignToBoundary(data, ref offset, 2); + data.AlignToBoundary(ref offset, 2); } #endregion @@ -931,7 +931,7 @@ namespace SabreTools.Serialization.Readers obj.TitleResource = data.ReadNullTerminatedUnicodeString(ref offset) ?? string.Empty; // Align to the WORD boundary if we're not at the end - AlignToBoundary(data, ref offset, 2); + data.AlignToBoundary(ref offset, 2); } #endregion @@ -945,7 +945,7 @@ namespace SabreTools.Serialization.Readers #endregion // Align to the DWORD boundary if we're not at the end - AlignToBoundary(data, ref offset, 4); + data.AlignToBoundary(ref offset, 4); return obj; } @@ -995,7 +995,7 @@ namespace SabreTools.Serialization.Readers obj.ClassResource = data.ReadNullTerminatedUnicodeString(ref offset) ?? string.Empty; // Align to the WORD boundary if we're not at the end - AlignToBoundary(data, ref offset, 2); + data.AlignToBoundary(ref offset, 2); } #endregion @@ -1021,7 +1021,7 @@ namespace SabreTools.Serialization.Readers obj.TitleResource = data.ReadNullTerminatedUnicodeString(ref offset) ?? string.Empty; // Align to the WORD boundary if we're not at the end - AlignToBoundary(data, ref offset, 2); + data.AlignToBoundary(ref offset, 2); } #endregion @@ -1035,7 +1035,7 @@ namespace SabreTools.Serialization.Readers #endregion // Align to the DWORD boundary if we're not at the end - AlignToBoundary(data, ref offset, 4); + data.AlignToBoundary(ref offset, 4); return obj; } @@ -1081,7 +1081,7 @@ namespace SabreTools.Serialization.Readers obj.MenuResource = data.ReadNullTerminatedUnicodeString(ref offset) ?? string.Empty; // Align to the WORD boundary if we're not at the end - AlignToBoundary(data, ref offset, 2); + data.AlignToBoundary(ref offset, 2); // Read the ordinal if we have the flag set if (menuResourceHasOrdinal) @@ -1117,7 +1117,7 @@ namespace SabreTools.Serialization.Readers obj.ClassResource = data.ReadNullTerminatedUnicodeString(ref offset) ?? string.Empty; // Align to the WORD boundary if we're not at the end - AlignToBoundary(data, ref offset, 2); + data.AlignToBoundary(ref offset, 2); // Read the ordinal if we have the flag set if (classResourcehasOrdinal) @@ -1148,7 +1148,7 @@ namespace SabreTools.Serialization.Readers obj.TitleResource = data.ReadNullTerminatedUnicodeString(ref offset) ?? string.Empty; // Align to the WORD boundary if we're not at the end - AlignToBoundary(data, ref offset, 2); + data.AlignToBoundary(ref offset, 2); } #endregion @@ -1169,7 +1169,7 @@ namespace SabreTools.Serialization.Readers } // Align to the DWORD boundary if we're not at the end - AlignToBoundary(data, ref offset, 4); + data.AlignToBoundary(ref offset, 4); #endregion @@ -1220,7 +1220,7 @@ namespace SabreTools.Serialization.Readers obj.MenuResource = data.ReadNullTerminatedUnicodeString(ref offset) ?? string.Empty; // Align to the WORD boundary if we're not at the end - AlignToBoundary(data, ref offset, 2); + data.AlignToBoundary(ref offset, 2); // Read the ordinal if we have the flag set if (menuResourceHasOrdinal) @@ -1252,7 +1252,7 @@ namespace SabreTools.Serialization.Readers obj.ClassResource = data.ReadNullTerminatedUnicodeString(ref offset) ?? string.Empty; // Align to the WORD boundary if we're not at the end - AlignToBoundary(data, ref offset, 2); + data.AlignToBoundary(ref offset, 2); // Read the ordinal if we have the flag set if (classResourcehasOrdinal) @@ -1279,7 +1279,7 @@ namespace SabreTools.Serialization.Readers obj.TitleResource = data.ReadNullTerminatedUnicodeString(ref offset) ?? string.Empty; // Align to the WORD boundary if we're not at the end - AlignToBoundary(data, ref offset, 2); + data.AlignToBoundary(ref offset, 2); } #endregion @@ -1301,7 +1301,7 @@ namespace SabreTools.Serialization.Readers } // Align to the DWORD boundary if we're not at the end - AlignToBoundary(data, ref offset, 4); + data.AlignToBoundary(ref offset, 4); #endregion @@ -2079,7 +2079,7 @@ namespace SabreTools.Serialization.Readers extendedMenuItems.Add(extendedMenuItem); // Align to the DWORD boundary if we're not at the end - AlignToBoundary(data, ref offset, 4); + data.AlignToBoundary(ref offset, 4); } } @@ -2110,7 +2110,7 @@ namespace SabreTools.Serialization.Readers menuItem = ParseNormalMenuItem(data, ref offset); // Align to the DWORD boundary if we're not at the end - AlignToBoundary(data, ref offset, 4); + data.AlignToBoundary(ref offset, 4); if (menuItem is null) return null; @@ -2817,7 +2817,7 @@ namespace SabreTools.Serialization.Readers } // Align to the DWORD boundary if we're not at the end - AlignToBoundary(data, ref offset, 4); + data.AlignToBoundary(ref offset, 4); var stringFileInfoChildren = new List(); while ((offset - currentOffset) < obj.Length) @@ -2848,7 +2848,7 @@ namespace SabreTools.Serialization.Readers obj.Key = data.ReadNullTerminatedUnicodeString(ref offset) ?? string.Empty; // Align to the DWORD boundary if we're not at the end - AlignToBoundary(data, ref offset, 4); + data.AlignToBoundary(ref offset, 4); if (obj.ValueLength > 0) { @@ -2858,7 +2858,7 @@ namespace SabreTools.Serialization.Readers } // Align to the DWORD boundary if we're not at the end - AlignToBoundary(data, ref offset, 4); + data.AlignToBoundary(ref offset, 4); return obj; } @@ -2908,7 +2908,7 @@ namespace SabreTools.Serialization.Readers obj.Key = data.ReadNullTerminatedUnicodeString(ref offset) ?? string.Empty; // Align to the DWORD boundary if we're not at the end - AlignToBoundary(data, ref offset, 4); + data.AlignToBoundary(ref offset, 4); var stringTableChildren = new List(); while ((offset - initialOffset) < obj.Length) @@ -3053,7 +3053,7 @@ namespace SabreTools.Serialization.Readers return null; // Align to the DWORD boundary if we're not at the end - AlignToBoundary(data, ref offset, 4); + data.AlignToBoundary(ref offset, 4); var varFileInfoChildren = new List(); while ((offset - initialOffset) < obj.Length) @@ -3071,7 +3071,7 @@ namespace SabreTools.Serialization.Readers } // Align to the DWORD boundary if we're not at the end - AlignToBoundary(data, ref offset, 4); + data.AlignToBoundary(ref offset, 4); // Cache the current offset int currentOffset = offset; @@ -3152,37 +3152,5 @@ namespace SabreTools.Serialization.Readers return obj; } - - #region Helpers - - /// - /// Align the array position to a byte-size boundary - /// - /// Input array to try aligning - /// Offset into the byte array - /// Number of bytes to align on - /// True if the array could be aligned, false otherwise - /// TODO: Remove when IO is updated - private static bool AlignToBoundary(byte[]? input, ref int offset, byte alignment) - { - // If the array is invalid - if (input is null || input.Length == 0) - return false; - - // If already at the end of the array - if (offset >= input.Length) - return false; - - // Align the stream position - while (offset % alignment != 0 && offset < input.Length) - { - _ = input.ReadByteValue(ref offset); - } - - // Return if the alignment completed - return offset % alignment == 0; - } - - #endregion } } diff --git a/SabreTools.Serialization/SabreTools.Serialization.csproj b/SabreTools.Serialization/SabreTools.Serialization.csproj index 90a4de67..ff964735 100644 --- a/SabreTools.Serialization/SabreTools.Serialization.csproj +++ b/SabreTools.Serialization/SabreTools.Serialization.csproj @@ -43,12 +43,12 @@ - - + + - - + + \ No newline at end of file diff --git a/SabreTools.Serialization/Wrappers/PKZIP.Extraction.cs b/SabreTools.Serialization/Wrappers/PKZIP.Extraction.cs index d803c8c4..34507d50 100644 --- a/SabreTools.Serialization/Wrappers/PKZIP.Extraction.cs +++ b/SabreTools.Serialization/Wrappers/PKZIP.Extraction.cs @@ -27,7 +27,9 @@ namespace SabreTools.Serialization.Wrappers try { var readerOptions = new ReaderOptions() { LookForHeader = lookForHeader }; - var zipFile = ZipArchive.Open(_dataSource, readerOptions); + var zipFile = ZipArchive.OpenArchive(_dataSource, readerOptions) as ZipArchive; + if (zipFile is null) + return false; // If the file exists if (!string.IsNullOrEmpty(Filename) && File.Exists(Filename!)) @@ -37,11 +39,15 @@ namespace SabreTools.Serialization.Wrappers // If there are multiple parts if (parts.Length > 1) - zipFile = ZipArchive.Open(parts, readerOptions); + zipFile = ZipArchive.OpenArchive(parts, readerOptions) as ZipArchive; // Try to read the file path if no entries are found else if (zipFile.Entries.Count == 0) - zipFile = ZipArchive.Open(parts, readerOptions); + zipFile = ZipArchive.OpenArchive(parts, readerOptions) as ZipArchive; + + // If the archive is somehow null + if (zipFile is null) + return false; } foreach (var entry in zipFile.Entries) diff --git a/SabreTools.Serialization/Wrappers/RAR.Extraction.cs b/SabreTools.Serialization/Wrappers/RAR.Extraction.cs index 13617c52..7107d9ff 100644 --- a/SabreTools.Serialization/Wrappers/RAR.Extraction.cs +++ b/SabreTools.Serialization/Wrappers/RAR.Extraction.cs @@ -5,7 +5,6 @@ using System.Text.RegularExpressions; #if NET462_OR_GREATER || NETCOREAPP || NETSTANDARD2_0_OR_GREATER using SharpCompress.Archives; using SharpCompress.Archives.Rar; -using SharpCompress.Common; using SharpCompress.Readers; #endif @@ -33,7 +32,9 @@ namespace SabreTools.Serialization.Wrappers try { var readerOptions = new ReaderOptions() { LookForHeader = lookForHeader }; - RarArchive rarFile = RarArchive.Open(_dataSource, readerOptions); + var rarFile = RarArchive.OpenArchive(_dataSource, readerOptions) as RarArchive; + if (rarFile is null) + return false; // If the file exists if (!string.IsNullOrEmpty(Filename) && File.Exists(Filename!)) @@ -43,11 +44,15 @@ namespace SabreTools.Serialization.Wrappers // If there are multiple parts if (parts.Length > 1) - rarFile = RarArchive.Open(parts, readerOptions); + rarFile = RarArchive.OpenArchive(parts, readerOptions) as RarArchive; // Try to read the file path if no entries are found else if (rarFile.Entries.Count == 0) - rarFile = RarArchive.Open(parts, readerOptions); + rarFile = RarArchive.OpenArchive(parts, readerOptions) as RarArchive; + + // If the archive is somehow null + if (rarFile is null) + return false; } // Explained in https://github.com/adamhathcock/sharpcompress/pull/661. in order to determine whether @@ -273,11 +278,7 @@ namespace SabreTools.Serialization.Wrappers if (!Directory.Exists(outDir)) Directory.CreateDirectory(outDir); - rarFile.WriteToDirectory(outDir, new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true, - }); + rarFile.WriteToDirectory(outDir); } catch (Exception ex) diff --git a/SabreTools.Serialization/Wrappers/SevenZip.Extraction.cs b/SabreTools.Serialization/Wrappers/SevenZip.Extraction.cs index c42e3c7d..947c3755 100644 --- a/SabreTools.Serialization/Wrappers/SevenZip.Extraction.cs +++ b/SabreTools.Serialization/Wrappers/SevenZip.Extraction.cs @@ -32,7 +32,9 @@ namespace SabreTools.Serialization.Wrappers try { var readerOptions = new ReaderOptions() { LookForHeader = lookForHeader }; - var sevenZip = SevenZipArchive.Open(_dataSource, readerOptions); + var sevenZip = SevenZipArchive.OpenArchive(_dataSource, readerOptions) as SevenZipArchive; + if (sevenZip is null) + return false; // If the file exists if (!string.IsNullOrEmpty(Filename) && File.Exists(Filename!)) @@ -42,11 +44,15 @@ namespace SabreTools.Serialization.Wrappers // If there are multiple parts if (parts.Length > 1) - sevenZip = SevenZipArchive.Open(parts, readerOptions); + sevenZip = SevenZipArchive.OpenArchive(parts, readerOptions) as SevenZipArchive; // Try to read the file path if no entries are found else if (sevenZip.Entries.Count == 0) - sevenZip = SevenZipArchive.Open(parts, readerOptions); + sevenZip = SevenZipArchive.OpenArchive(parts, readerOptions) as SevenZipArchive; + + // If the archive is somehow null + if (sevenZip is null) + return false; } // Explained in https://github.com/adamhathcock/sharpcompress/pull/661. in order to determine whether