From fe5f114290c198be8362fd075e309077e494f63d Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Thu, 31 Jul 2025 12:45:07 -0400 Subject: [PATCH] General cleanup --- BinaryObjectScanner/FileType/Executable.cs | 12 ++----- BinaryObjectScanner/Protection/CDDVDCops.cs | 36 ++++++------------- .../Protection/ImpulseReactor.cs | 2 +- BinaryObjectScanner/Protection/LaserLok.cs | 2 +- .../Macrovision.CactusDataShield.cs | 19 ++-------- .../Protection/Macrovision.SafeDisc.cs | 12 +++---- BinaryObjectScanner/Protection/Macrovision.cs | 11 ++---- 7 files changed, 25 insertions(+), 69 deletions(-) diff --git a/BinaryObjectScanner/FileType/Executable.cs b/BinaryObjectScanner/FileType/Executable.cs index be569a31..8b866d89 100644 --- a/BinaryObjectScanner/FileType/Executable.cs +++ b/BinaryObjectScanner/FileType/Executable.cs @@ -1,9 +1,6 @@ using System; using System.Collections.Generic; using System.IO; -#if NET35_OR_GREATER || NETCOREAPP -using System.Linq; -#endif using BinaryObjectScanner.Data; using BinaryObjectScanner.Interfaces; using SabreTools.IO.Extensions; @@ -239,20 +236,15 @@ namespace BinaryObjectScanner.FileType return protections; // If we have any extractable packers -#if NET20 var extractables = new List>(); foreach (var check in checks) { - if (check == null || check is not IExtractableExecutable extractable) + if (check is not IExtractableExecutable extractable) continue; extractables.Add(extractable); } -#else - var extractables = checks - .Where(c => c is IExtractableExecutable) - .Select(c => c as IExtractableExecutable); -#endif + extractables.IterateWithAction(extractable => { var subProtections = PerformExtractableCheck(extractable!, file, exe, getProtections, includeDebug); diff --git a/BinaryObjectScanner/Protection/CDDVDCops.cs b/BinaryObjectScanner/Protection/CDDVDCops.cs index 08cc291c..a7fa19da 100644 --- a/BinaryObjectScanner/Protection/CDDVDCops.cs +++ b/BinaryObjectScanner/Protection/CDDVDCops.cs @@ -1,11 +1,9 @@ using System; using System.Collections.Generic; -#if NET35_OR_GREATER || NETCOREAPP -using System.Linq; -#endif using System.Text; using System.Text.RegularExpressions; using BinaryObjectScanner.Interfaces; +using SabreTools.IO.Extensions; using SabreTools.Matching; using SabreTools.Matching.Content; using SabreTools.Matching.Paths; @@ -68,7 +66,7 @@ namespace BinaryObjectScanner.Protection // TODO: Investigate reference to "CD32COPS.DLL" in "WETFLIPP.QZ_" in IA item "Triada_Russian_DVD_Complete_Collection_of_Erotic_Games". // TODO: Investigate cdcode.key for redump ID 108167, may be key-less cd-cops? // TODO: Document update 12 for redump ID 108167 bumping version, adding key, adding vista(?) support - + public class CDDVDCops : IExecutableCheck, IExecutableCheck, IPathCheck { /// @@ -127,30 +125,18 @@ namespace BinaryObjectScanner.Protection // Check the imported-name table // Found in "h3blade.exe" in Redump entry 85077. -#if NET20 - bool intMatch = false; - if (nex.Model.ImportedNameTable?.Values != null) + if (nex.Model.ImportedNameTable != null) { foreach (var inte in nex.Model.ImportedNameTable.Values) { - if (inte?.NameString == null || inte.NameString.Length == 0) + if (inte.NameString.IsNullOrEmpty()) continue; - string ns = Encoding.ASCII.GetString(inte.NameString); + string ns = Encoding.ASCII.GetString(inte.NameString!); if (ns.Contains("CDCOPS")) - { - intMatch = true; - break; - } + return "CD-Cops"; } } -#else - bool intMatch = nex.Model.ImportedNameTable?.Values? - .Select(inte => inte?.NameString == null ? string.Empty : Encoding.ASCII.GetString(inte.NameString)) - .Any(s => s.Contains("CDCOPS")) ?? false; -#endif - if (intMatch) - return "CD-Cops"; // Check the nonresident-name table // Found in "CDCOPS.DLL" in Redump entry 85077. @@ -190,7 +176,7 @@ namespace BinaryObjectScanner.Protection // Found in "FGP.exe" in IA item "flaklypa-grand-prix-dvd"/Redump entry 108169. if (pex.ContainsSection("UNICops", exact: true)) return "UNI-Cops"; - + // Get the DATA section, if it exists // Found in "bib.dll" in IA item "https://archive.org/details/cover_202501" // This contains the version section that the Content Check looked for. There are likely other sections @@ -198,14 +184,14 @@ namespace BinaryObjectScanner.Protection var strs = pex.GetFirstSectionStrings("DATA"); if (strs != null) { - var match = strs.Find(s => s.Contains(" ver. ") && (s.Contains("CD-Cops, ") || s.Contains("DVD-Cops, "))); + var match = strs.Find(s => s.Contains(" ver. ") && (s.Contains("CD-Cops, ") || s.Contains("DVD-Cops, "))); if (match != null) if (match.Contains("CD-Cops")) return $"CD-Cops {GetVersionString(match)}"; else if (match.Contains("DVD-Cops")) return $"DVD-Cops {GetVersionString(match)}"; } - + return null; } @@ -281,7 +267,7 @@ namespace BinaryObjectScanner.Protection return version; } - + private static string GetVersionString(string match) { // Full string ends with # (i.e. "CD-Cops, ver. 1.72, #"), use that to compensate for comma in version @@ -290,7 +276,7 @@ namespace BinaryObjectScanner.Protection var versionMatch = Regex.Match(match, @"(?<=D-Cops,\s{1,}ver. )(.*?)(?=,\s{1,}#)"); if (versionMatch.Success) return versionMatch.Value; - + return "(Unknown Version - Please report to us on GitHub)"; } } diff --git a/BinaryObjectScanner/Protection/ImpulseReactor.cs b/BinaryObjectScanner/Protection/ImpulseReactor.cs index 8c7e87ed..b018b312 100644 --- a/BinaryObjectScanner/Protection/ImpulseReactor.cs +++ b/BinaryObjectScanner/Protection/ImpulseReactor.cs @@ -74,7 +74,7 @@ namespace BinaryObjectScanner.Protection return MatchUtil.GetFirstMatch(path, matchers, any: true); } - private string? GetInternalVersion(string firstMatchedString, IEnumerable? files) + private string? GetInternalVersion(string firstMatchedString, List? files) { try { diff --git a/BinaryObjectScanner/Protection/LaserLok.cs b/BinaryObjectScanner/Protection/LaserLok.cs index b180a5e5..8a4dad5c 100644 --- a/BinaryObjectScanner/Protection/LaserLok.cs +++ b/BinaryObjectScanner/Protection/LaserLok.cs @@ -183,7 +183,7 @@ namespace BinaryObjectScanner.Protection return Encoding.ASCII.GetString(sectionContent, position + 76, 4); } - private static string? GetVersion16Bit(string firstMatchedString, IEnumerable? files) + private static string? GetVersion16Bit(string firstMatchedString, List? files) { if (!File.Exists(firstMatchedString)) return string.Empty; diff --git a/BinaryObjectScanner/Protection/Macrovision.CactusDataShield.cs b/BinaryObjectScanner/Protection/Macrovision.CactusDataShield.cs index 6309b7ab..27de3c46 100644 --- a/BinaryObjectScanner/Protection/Macrovision.CactusDataShield.cs +++ b/BinaryObjectScanner/Protection/Macrovision.CactusDataShield.cs @@ -1,9 +1,6 @@ using System; using System.Collections.Generic; using System.IO; -#if NET35_OR_GREATER || NETCOREAPP -using System.Linq; -#endif using System.Text; using SabreTools.Matching; using SabreTools.Matching.Paths; @@ -111,26 +108,14 @@ namespace BinaryObjectScanner.Protection return MatchUtil.GetFirstMatch(path, matchers, any: true); } - public static string GetCactusDataShieldVersion(string firstMatchedString, IEnumerable? files) + public static string GetCactusDataShieldVersion(string firstMatchedString, List? files) { // If we have no files if (files == null) return string.Empty; // Find the version.txt file first -#if NET20 - string? versionPath = null; - foreach (string file in files) - { - if (Path.GetFileName(file).Equals("version.txt", StringComparison.OrdinalIgnoreCase)) - { - versionPath = file; - break; - } - } -#else - var versionPath = files.FirstOrDefault(f => Path.GetFileName(f).Equals("version.txt", StringComparison.OrdinalIgnoreCase)); -#endif + var versionPath = files.Find(f => Path.GetFileName(f).Equals("version.txt", StringComparison.OrdinalIgnoreCase)); if (!string.IsNullOrEmpty(versionPath)) { var version = GetCactusDataShieldInternalVersion(versionPath!); diff --git a/BinaryObjectScanner/Protection/Macrovision.SafeDisc.cs b/BinaryObjectScanner/Protection/Macrovision.SafeDisc.cs index 6b71d6b9..24d62740 100644 --- a/BinaryObjectScanner/Protection/Macrovision.SafeDisc.cs +++ b/BinaryObjectScanner/Protection/Macrovision.SafeDisc.cs @@ -462,7 +462,7 @@ namespace BinaryObjectScanner.Protection return "Unknown Version (Report this to us on GitHub)"; } - internal static string GetSafeDiscCLCD16Version(string firstMatchedString, IEnumerable? files) + internal static string GetSafeDiscCLCD16Version(string firstMatchedString, List? files) { if (string.IsNullOrEmpty(firstMatchedString) || !File.Exists(firstMatchedString)) return string.Empty; @@ -495,7 +495,7 @@ namespace BinaryObjectScanner.Protection }; } - internal static string GetSafeDiscCLCD32Version(string firstMatchedString, IEnumerable? files) + internal static string GetSafeDiscCLCD32Version(string firstMatchedString, List? files) { if (string.IsNullOrEmpty(firstMatchedString) || !File.Exists(firstMatchedString)) return string.Empty; @@ -693,7 +693,7 @@ namespace BinaryObjectScanner.Protection }; } - internal static string GetSafeDiscCLOKSPLVersion(string firstMatchedString, IEnumerable? files) + internal static string GetSafeDiscCLOKSPLVersion(string firstMatchedString, List? files) { if (string.IsNullOrEmpty(firstMatchedString) || !File.Exists(firstMatchedString)) return string.Empty; @@ -786,7 +786,7 @@ namespace BinaryObjectScanner.Protection }; } - internal static string GetSafeDiscDPlayerXVersion(string firstMatchedString, IEnumerable? files) + internal static string GetSafeDiscDPlayerXVersion(string firstMatchedString, List? files) { if (string.IsNullOrEmpty(firstMatchedString) || !File.Exists(firstMatchedString)) return string.Empty; @@ -857,7 +857,7 @@ namespace BinaryObjectScanner.Protection }; } - internal static string GetSafeDiscDrvmgtVersion(string firstMatchedString, IEnumerable? files) + internal static string GetSafeDiscDrvmgtVersion(string firstMatchedString, List? files) { if (string.IsNullOrEmpty(firstMatchedString) || !File.Exists(firstMatchedString)) return string.Empty; @@ -1023,7 +1023,7 @@ namespace BinaryObjectScanner.Protection }; } - internal static string? GetSafeDiscSplshVersion(string firstMatchedString, IEnumerable? files) + internal static string? GetSafeDiscSplshVersion(string firstMatchedString, List? files) { // Special thanks to TheMechasaur for combing through known SafeDisc games and cataloging the splash-screens used in them, making these detections possible. diff --git a/BinaryObjectScanner/Protection/Macrovision.cs b/BinaryObjectScanner/Protection/Macrovision.cs index 371486d2..858eeb42 100644 --- a/BinaryObjectScanner/Protection/Macrovision.cs +++ b/BinaryObjectScanner/Protection/Macrovision.cs @@ -1,9 +1,6 @@ using System; using System.Collections.Generic; using System.IO; -#if NET35_OR_GREATER || NETCOREAPP -using System.Linq; -#endif using BinaryObjectScanner.Interfaces; using SabreTools.IO.Extensions; using SabreTools.Matching; @@ -271,7 +268,7 @@ namespace BinaryObjectScanner.Protection return MatchUtil.GetFirstMatch(path, matchers, any: true); } - internal static string? Get00000001TMPVersion(string firstMatchedString, IEnumerable? files) + internal static string? Get00000001TMPVersion(string firstMatchedString, List? files) { if (string.IsNullOrEmpty(firstMatchedString) || !File.Exists(firstMatchedString)) return string.Empty; @@ -296,7 +293,7 @@ namespace BinaryObjectScanner.Protection } // TODO: Verify these checks and remove any that may not be needed, file version checks should remove the need for any checks for 2.80+. - internal static string? GetSecdrvFileSizeVersion(string firstMatchedString, IEnumerable? files) + internal static string? GetSecdrvFileSizeVersion(string firstMatchedString, List? files) { if (string.IsNullOrEmpty(firstMatchedString) || !File.Exists(firstMatchedString)) return string.Empty; @@ -787,7 +784,6 @@ namespace BinaryObjectScanner.Protection } // Get distinct and order -#if NET20 var distinct = new List(); foreach (string result in resultsList) { @@ -797,9 +793,6 @@ namespace BinaryObjectScanner.Protection distinct.Sort(); return distinct; -#else - return [.. resultsList.Distinct().OrderBy(s => s)]; -#endif } } }