General cleanup

This commit is contained in:
Matt Nadareski
2025-07-31 12:45:07 -04:00
parent 8f2d20dcfa
commit fe5f114290
7 changed files with 25 additions and 69 deletions

View File

@@ -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<IExtractableExecutable<T>>();
foreach (var check in checks)
{
if (check == null || check is not IExtractableExecutable<T> extractable)
if (check is not IExtractableExecutable<T> extractable)
continue;
extractables.Add(extractable);
}
#else
var extractables = checks
.Where(c => c is IExtractableExecutable<T>)
.Select(c => c as IExtractableExecutable<T>);
#endif
extractables.IterateWithAction(extractable =>
{
var subProtections = PerformExtractableCheck(extractable!, file, exe, getProtections, includeDebug);

View File

@@ -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<NewExecutable>, IExecutableCheck<PortableExecutable>, IPathCheck
{
/// <inheritdoc/>
@@ -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)";
}
}

View File

@@ -74,7 +74,7 @@ namespace BinaryObjectScanner.Protection
return MatchUtil.GetFirstMatch(path, matchers, any: true);
}
private string? GetInternalVersion(string firstMatchedString, IEnumerable<string>? files)
private string? GetInternalVersion(string firstMatchedString, List<string>? files)
{
try
{

View File

@@ -183,7 +183,7 @@ namespace BinaryObjectScanner.Protection
return Encoding.ASCII.GetString(sectionContent, position + 76, 4);
}
private static string? GetVersion16Bit(string firstMatchedString, IEnumerable<string>? files)
private static string? GetVersion16Bit(string firstMatchedString, List<string>? files)
{
if (!File.Exists(firstMatchedString))
return string.Empty;

View File

@@ -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<string>? files)
public static string GetCactusDataShieldVersion(string firstMatchedString, List<string>? 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!);

View File

@@ -462,7 +462,7 @@ namespace BinaryObjectScanner.Protection
return "Unknown Version (Report this to us on GitHub)";
}
internal static string GetSafeDiscCLCD16Version(string firstMatchedString, IEnumerable<string>? files)
internal static string GetSafeDiscCLCD16Version(string firstMatchedString, List<string>? 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<string>? files)
internal static string GetSafeDiscCLCD32Version(string firstMatchedString, List<string>? 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<string>? files)
internal static string GetSafeDiscCLOKSPLVersion(string firstMatchedString, List<string>? 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<string>? files)
internal static string GetSafeDiscDPlayerXVersion(string firstMatchedString, List<string>? 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<string>? files)
internal static string GetSafeDiscDrvmgtVersion(string firstMatchedString, List<string>? 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<string>? files)
internal static string? GetSafeDiscSplshVersion(string firstMatchedString, List<string>? files)
{
// Special thanks to TheMechasaur for combing through known SafeDisc games and cataloging the splash-screens used in them, making these detections possible.

View File

@@ -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<string>? files)
internal static string? Get00000001TMPVersion(string firstMatchedString, List<string>? 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<string>? files)
internal static string? GetSecdrvFileSizeVersion(string firstMatchedString, List<string>? 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<string>();
foreach (string result in resultsList)
{
@@ -797,9 +793,6 @@ namespace BinaryObjectScanner.Protection
distinct.Sort();
return distinct;
#else
return [.. resultsList.Distinct().OrderBy(s => s)];
#endif
}
}
}