Skip to content

Commit fe5f114

Browse files
committed
General cleanup
1 parent 8f2d20d commit fe5f114

File tree

7 files changed

+25
-69
lines changed

7 files changed

+25
-69
lines changed

BinaryObjectScanner/FileType/Executable.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4-
#if NET35_OR_GREATER || NETCOREAPP
5-
using System.Linq;
6-
#endif
74
using BinaryObjectScanner.Data;
85
using BinaryObjectScanner.Interfaces;
96
using SabreTools.IO.Extensions;
@@ -239,20 +236,15 @@ private static ProtectionDictionary HandleExtractableProtections<T, U>(string fi
239236
return protections;
240237

241238
// If we have any extractable packers
242-
#if NET20
243239
var extractables = new List<IExtractableExecutable<T>>();
244240
foreach (var check in checks)
245241
{
246-
if (check == null || check is not IExtractableExecutable<T> extractable)
242+
if (check is not IExtractableExecutable<T> extractable)
247243
continue;
248244

249245
extractables.Add(extractable);
250246
}
251-
#else
252-
var extractables = checks
253-
.Where(c => c is IExtractableExecutable<T>)
254-
.Select(c => c as IExtractableExecutable<T>);
255-
#endif
247+
256248
extractables.IterateWithAction(extractable =>
257249
{
258250
var subProtections = PerformExtractableCheck(extractable!, file, exe, getProtections, includeDebug);

BinaryObjectScanner/Protection/CDDVDCops.cs

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
using System;
22
using System.Collections.Generic;
3-
#if NET35_OR_GREATER || NETCOREAPP
4-
using System.Linq;
5-
#endif
63
using System.Text;
74
using System.Text.RegularExpressions;
85
using BinaryObjectScanner.Interfaces;
6+
using SabreTools.IO.Extensions;
97
using SabreTools.Matching;
108
using SabreTools.Matching.Content;
119
using SabreTools.Matching.Paths;
@@ -68,7 +66,7 @@ namespace BinaryObjectScanner.Protection
6866
// TODO: Investigate reference to "CD32COPS.DLL" in "WETFLIPP.QZ_" in IA item "Triada_Russian_DVD_Complete_Collection_of_Erotic_Games".
6967
// TODO: Investigate cdcode.key for redump ID 108167, may be key-less cd-cops?
7068
// TODO: Document update 12 for redump ID 108167 bumping version, adding key, adding vista(?) support
71-
69+
7270
public class CDDVDCops : IExecutableCheck<NewExecutable>, IExecutableCheck<PortableExecutable>, IPathCheck
7371
{
7472
/// <inheritdoc/>
@@ -127,30 +125,18 @@ public class CDDVDCops : IExecutableCheck<NewExecutable>, IExecutableCheck<Porta
127125

128126
// Check the imported-name table
129127
// Found in "h3blade.exe" in Redump entry 85077.
130-
#if NET20
131-
bool intMatch = false;
132-
if (nex.Model.ImportedNameTable?.Values != null)
128+
if (nex.Model.ImportedNameTable != null)
133129
{
134130
foreach (var inte in nex.Model.ImportedNameTable.Values)
135131
{
136-
if (inte?.NameString == null || inte.NameString.Length == 0)
132+
if (inte.NameString.IsNullOrEmpty())
137133
continue;
138134

139-
string ns = Encoding.ASCII.GetString(inte.NameString);
135+
string ns = Encoding.ASCII.GetString(inte.NameString!);
140136
if (ns.Contains("CDCOPS"))
141-
{
142-
intMatch = true;
143-
break;
144-
}
137+
return "CD-Cops";
145138
}
146139
}
147-
#else
148-
bool intMatch = nex.Model.ImportedNameTable?.Values?
149-
.Select(inte => inte?.NameString == null ? string.Empty : Encoding.ASCII.GetString(inte.NameString))
150-
.Any(s => s.Contains("CDCOPS")) ?? false;
151-
#endif
152-
if (intMatch)
153-
return "CD-Cops";
154140

155141
// Check the nonresident-name table
156142
// Found in "CDCOPS.DLL" in Redump entry 85077.
@@ -190,22 +176,22 @@ public class CDDVDCops : IExecutableCheck<NewExecutable>, IExecutableCheck<Porta
190176
// Found in "FGP.exe" in IA item "flaklypa-grand-prix-dvd"/Redump entry 108169.
191177
if (pex.ContainsSection("UNICops", exact: true))
192178
return "UNI-Cops";
193-
179+
194180
// Get the DATA section, if it exists
195181
// Found in "bib.dll" in IA item "https://archive.org/details/cover_202501"
196182
// This contains the version section that the Content Check looked for. There are likely other sections
197183
// that may contain it. Update when more are found.
198184
var strs = pex.GetFirstSectionStrings("DATA");
199185
if (strs != null)
200186
{
201-
var match = strs.Find(s => s.Contains(" ver. ") && (s.Contains("CD-Cops, ") || s.Contains("DVD-Cops, ")));
187+
var match = strs.Find(s => s.Contains(" ver. ") && (s.Contains("CD-Cops, ") || s.Contains("DVD-Cops, ")));
202188
if (match != null)
203189
if (match.Contains("CD-Cops"))
204190
return $"CD-Cops {GetVersionString(match)}";
205191
else if (match.Contains("DVD-Cops"))
206192
return $"DVD-Cops {GetVersionString(match)}";
207193
}
208-
194+
209195
return null;
210196
}
211197

@@ -281,7 +267,7 @@ public List<string> CheckDirectoryPath(string path, List<string>? files)
281267

282268
return version;
283269
}
284-
270+
285271
private static string GetVersionString(string match)
286272
{
287273
// Full string ends with # (i.e. "CD-Cops, ver. 1.72, #"), use that to compensate for comma in version
@@ -290,7 +276,7 @@ private static string GetVersionString(string match)
290276
var versionMatch = Regex.Match(match, @"(?<=D-Cops,\s{1,}ver. )(.*?)(?=,\s{1,}#)");
291277
if (versionMatch.Success)
292278
return versionMatch.Value;
293-
279+
294280
return "(Unknown Version - Please report to us on GitHub)";
295281
}
296282
}

BinaryObjectScanner/Protection/ImpulseReactor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public List<string> CheckDirectoryPath(string path, List<string>? files)
7474
return MatchUtil.GetFirstMatch(path, matchers, any: true);
7575
}
7676

77-
private string? GetInternalVersion(string firstMatchedString, IEnumerable<string>? files)
77+
private string? GetInternalVersion(string firstMatchedString, List<string>? files)
7878
{
7979
try
8080
{

BinaryObjectScanner/Protection/LaserLok.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ private static string GetBuild(byte[]? sectionContent, bool versionTwo)
183183
return Encoding.ASCII.GetString(sectionContent, position + 76, 4);
184184
}
185185

186-
private static string? GetVersion16Bit(string firstMatchedString, IEnumerable<string>? files)
186+
private static string? GetVersion16Bit(string firstMatchedString, List<string>? files)
187187
{
188188
if (!File.Exists(firstMatchedString))
189189
return string.Empty;

BinaryObjectScanner/Protection/Macrovision.CactusDataShield.cs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4-
#if NET35_OR_GREATER || NETCOREAPP
5-
using System.Linq;
6-
#endif
74
using System.Text;
85
using SabreTools.Matching;
96
using SabreTools.Matching.Paths;
@@ -111,26 +108,14 @@ internal static List<string> CactusDataShieldCheckDirectoryPath(string path, Lis
111108
return MatchUtil.GetFirstMatch(path, matchers, any: true);
112109
}
113110

114-
public static string GetCactusDataShieldVersion(string firstMatchedString, IEnumerable<string>? files)
111+
public static string GetCactusDataShieldVersion(string firstMatchedString, List<string>? files)
115112
{
116113
// If we have no files
117114
if (files == null)
118115
return string.Empty;
119116

120117
// Find the version.txt file first
121-
#if NET20
122-
string? versionPath = null;
123-
foreach (string file in files)
124-
{
125-
if (Path.GetFileName(file).Equals("version.txt", StringComparison.OrdinalIgnoreCase))
126-
{
127-
versionPath = file;
128-
break;
129-
}
130-
}
131-
#else
132-
var versionPath = files.FirstOrDefault(f => Path.GetFileName(f).Equals("version.txt", StringComparison.OrdinalIgnoreCase));
133-
#endif
118+
var versionPath = files.Find(f => Path.GetFileName(f).Equals("version.txt", StringComparison.OrdinalIgnoreCase));
134119
if (!string.IsNullOrEmpty(versionPath))
135120
{
136121
var version = GetCactusDataShieldInternalVersion(versionPath!);

BinaryObjectScanner/Protection/Macrovision.SafeDisc.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ private static string GetSafeDiscAuthServVersion(PortableExecutable pex)
462462
return "Unknown Version (Report this to us on GitHub)";
463463
}
464464

465-
internal static string GetSafeDiscCLCD16Version(string firstMatchedString, IEnumerable<string>? files)
465+
internal static string GetSafeDiscCLCD16Version(string firstMatchedString, List<string>? files)
466466
{
467467
if (string.IsNullOrEmpty(firstMatchedString) || !File.Exists(firstMatchedString))
468468
return string.Empty;
@@ -495,7 +495,7 @@ internal static string GetSafeDiscCLCD16Version(string firstMatchedString, IEnum
495495
};
496496
}
497497

498-
internal static string GetSafeDiscCLCD32Version(string firstMatchedString, IEnumerable<string>? files)
498+
internal static string GetSafeDiscCLCD32Version(string firstMatchedString, List<string>? files)
499499
{
500500
if (string.IsNullOrEmpty(firstMatchedString) || !File.Exists(firstMatchedString))
501501
return string.Empty;
@@ -693,7 +693,7 @@ internal static string GetSafeDiscCLCD32Version(string firstMatchedString, IEnum
693693
};
694694
}
695695

696-
internal static string GetSafeDiscCLOKSPLVersion(string firstMatchedString, IEnumerable<string>? files)
696+
internal static string GetSafeDiscCLOKSPLVersion(string firstMatchedString, List<string>? files)
697697
{
698698
if (string.IsNullOrEmpty(firstMatchedString) || !File.Exists(firstMatchedString))
699699
return string.Empty;
@@ -786,7 +786,7 @@ internal static string GetSafeDiscCLOKSPLVersion(string firstMatchedString, IEnu
786786
};
787787
}
788788

789-
internal static string GetSafeDiscDPlayerXVersion(string firstMatchedString, IEnumerable<string>? files)
789+
internal static string GetSafeDiscDPlayerXVersion(string firstMatchedString, List<string>? files)
790790
{
791791
if (string.IsNullOrEmpty(firstMatchedString) || !File.Exists(firstMatchedString))
792792
return string.Empty;
@@ -857,7 +857,7 @@ internal static string GetSafeDiscDPlayerXVersion(string firstMatchedString, IEn
857857
};
858858
}
859859

860-
internal static string GetSafeDiscDrvmgtVersion(string firstMatchedString, IEnumerable<string>? files)
860+
internal static string GetSafeDiscDrvmgtVersion(string firstMatchedString, List<string>? files)
861861
{
862862
if (string.IsNullOrEmpty(firstMatchedString) || !File.Exists(firstMatchedString))
863863
return string.Empty;
@@ -1023,7 +1023,7 @@ internal static string GetSafeDiscDrvmgtVersion(string firstMatchedString, IEnum
10231023
};
10241024
}
10251025

1026-
internal static string? GetSafeDiscSplshVersion(string firstMatchedString, IEnumerable<string>? files)
1026+
internal static string? GetSafeDiscSplshVersion(string firstMatchedString, List<string>? files)
10271027
{
10281028
// Special thanks to TheMechasaur for combing through known SafeDisc games and cataloging the splash-screens used in them, making these detections possible.
10291029

BinaryObjectScanner/Protection/Macrovision.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4-
#if NET35_OR_GREATER || NETCOREAPP
5-
using System.Linq;
6-
#endif
74
using BinaryObjectScanner.Interfaces;
85
using SabreTools.IO.Extensions;
96
using SabreTools.Matching;
@@ -271,7 +268,7 @@ internal static List<string> MacrovisionCheckDirectoryPath(string path, List<str
271268
return MatchUtil.GetFirstMatch(path, matchers, any: true);
272269
}
273270

274-
internal static string? Get00000001TMPVersion(string firstMatchedString, IEnumerable<string>? files)
271+
internal static string? Get00000001TMPVersion(string firstMatchedString, List<string>? files)
275272
{
276273
if (string.IsNullOrEmpty(firstMatchedString) || !File.Exists(firstMatchedString))
277274
return string.Empty;
@@ -296,7 +293,7 @@ internal static List<string> MacrovisionCheckDirectoryPath(string path, List<str
296293
}
297294

298295
// 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+.
299-
internal static string? GetSecdrvFileSizeVersion(string firstMatchedString, IEnumerable<string>? files)
296+
internal static string? GetSecdrvFileSizeVersion(string firstMatchedString, List<string>? files)
300297
{
301298
if (string.IsNullOrEmpty(firstMatchedString) || !File.Exists(firstMatchedString))
302299
return string.Empty;
@@ -787,7 +784,6 @@ private static string MacrovisionVersionToProductName(string version)
787784
}
788785

789786
// Get distinct and order
790-
#if NET20
791787
var distinct = new List<string>();
792788
foreach (string result in resultsList)
793789
{
@@ -797,9 +793,6 @@ private static string MacrovisionVersionToProductName(string version)
797793

798794
distinct.Sort();
799795
return distinct;
800-
#else
801-
return [.. resultsList.Distinct().OrderBy(s => s)];
802-
#endif
803796
}
804797
}
805798
}

0 commit comments

Comments
 (0)