diff --git a/BinaryObjectScanner/Packer/CExe.cs b/BinaryObjectScanner/Packer/CExe.cs index e73ea800..4adc5ed5 100644 --- a/BinaryObjectScanner/Packer/CExe.cs +++ b/BinaryObjectScanner/Packer/CExe.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using BinaryObjectScanner.Interfaces; using SabreTools.Compression.zlib; using SabreTools.Matching; @@ -24,7 +23,7 @@ namespace BinaryObjectScanner.Packer return null; // If there are exactly 2 resources with type 99 - if (pex.FindResourceByNamedType("99, ").Count() == 2) + if (pex.FindResourceByNamedType("99, ").Count == 2) return "CExe"; if (pex.StubExecutableData != null) @@ -55,13 +54,18 @@ namespace BinaryObjectScanner.Packer { try { + // Get all resources of type 99 with index 2 + var resources = pex.FindResourceByNamedType("99, 2"); + if (resources == null || resources.Count == 0) + return false; + // Get the first resource of type 99 with index 2 - var payload = pex.FindResourceByNamedType("99, 2").FirstOrDefault(); + var payload = resources[0]; if (payload == null || payload.Length == 0) return false; // Determine which compression was used - bool zlib = pex.FindResourceByNamedType("99, 1").Any(); + bool zlib = pex.FindResourceByNamedType("99, 1").Count > 0; // Create the output data buffer var data = new byte[0]; diff --git a/BinaryObjectScanner/Packer/EmbeddedArchive.cs b/BinaryObjectScanner/Packer/EmbeddedArchive.cs index 9857faaa..fe48a7ff 100644 --- a/BinaryObjectScanner/Packer/EmbeddedArchive.cs +++ b/BinaryObjectScanner/Packer/EmbeddedArchive.cs @@ -41,9 +41,9 @@ namespace BinaryObjectScanner.Packer return false; // Get the resources that have a PKZIP signature - var resources = pex.ResourceData - .Where(kvp => kvp.Value != null && kvp.Value is byte[]) - .Select(kvp => kvp.Value as byte[]) + var resources = pex.ResourceData.Values + .Where(v => v != null && v is byte[]) + .Select(v => v as byte[]) .Where(b => b != null && b.StartsWith(SabreTools.Models.PKZIP.Constants.LocalFileHeaderSignatureBytes)) .ToList(); diff --git a/BinaryObjectScanner/Packer/EmbeddedExecutable.cs b/BinaryObjectScanner/Packer/EmbeddedExecutable.cs index 43cd11f0..1fc41fb5 100644 --- a/BinaryObjectScanner/Packer/EmbeddedExecutable.cs +++ b/BinaryObjectScanner/Packer/EmbeddedExecutable.cs @@ -41,9 +41,9 @@ namespace BinaryObjectScanner.Packer return false; // Get the resources that have an executable signature - var resources = pex.ResourceData - .Where(kvp => kvp.Value != null && kvp.Value is byte[]) - .Select(kvp => kvp.Value as byte[]) + var resources = pex.ResourceData.Values + .Where(v => v != null && v is byte[]) + .Select(v => v as byte[]) .Where(b => b != null && b.StartsWith(SabreTools.Models.MSDOS.Constants.SignatureBytes)) .ToList(); diff --git a/BinaryObjectScanner/Packer/SevenZipSFX.cs b/BinaryObjectScanner/Packer/SevenZipSFX.cs index 6d440208..da0da068 100644 --- a/BinaryObjectScanner/Packer/SevenZipSFX.cs +++ b/BinaryObjectScanner/Packer/SevenZipSFX.cs @@ -1,4 +1,3 @@ -using System.Linq; using BinaryObjectScanner.Interfaces; using SabreTools.Serialization.Wrappers; @@ -37,7 +36,7 @@ namespace BinaryObjectScanner.Packer return "7-Zip SFX"; // If any dialog boxes match - if (pex.FindDialogByTitle("7-Zip self-extracting archive").Any()) + if (pex.FindDialogByTitle("7-Zip self-extracting archive").Count > 0) return "7-Zip SFX"; return null; diff --git a/BinaryObjectScanner/Packer/WinRARSFX.cs b/BinaryObjectScanner/Packer/WinRARSFX.cs index b9a25eee..e7a60a37 100644 --- a/BinaryObjectScanner/Packer/WinRARSFX.cs +++ b/BinaryObjectScanner/Packer/WinRARSFX.cs @@ -1,4 +1,3 @@ -using System.Linq; using BinaryObjectScanner.Interfaces; using SabreTools.Serialization.Wrappers; @@ -18,8 +17,7 @@ namespace BinaryObjectScanner.Packer if (name?.Contains("WinRAR archiver") == true) return "WinRAR SFX"; - var resources = pex.FindDialogByTitle("WinRAR self-extracting archive"); - if (resources.Any()) + if (pex.FindDialogByTitle("WinRAR self-extracting archive").Count > 0) return "WinRAR SFX"; return null; diff --git a/BinaryObjectScanner/Packer/WinZipSFX.cs b/BinaryObjectScanner/Packer/WinZipSFX.cs index 75e86273..455a9a6f 100644 --- a/BinaryObjectScanner/Packer/WinZipSFX.cs +++ b/BinaryObjectScanner/Packer/WinZipSFX.cs @@ -1,4 +1,4 @@ -using System.Linq; +using System; using System.Text; using BinaryObjectScanner.Interfaces; using SabreTools.Serialization.Wrappers; @@ -14,13 +14,15 @@ namespace BinaryObjectScanner.Packer if (nex.Model.ResidentNameTable == null) return null; + // Get the resident and non-resident name table strings + var rntStrs = Array.ConvertAll(nex.Model.ResidentNameTable, + rnte => rnte?.NameString == null ? string.Empty : Encoding.ASCII.GetString(rnte.NameString)); + var nrntStrs = Array.ConvertAll(nex.Model.NonResidentNameTable ?? [], + nrnte => nrnte?.NameString == null ? string.Empty : Encoding.ASCII.GetString(nrnte.NameString)); + // Check for the WinZip name strings - bool winZipNameFound = nex.Model.ResidentNameTable - .Select(rnte => rnte?.NameString == null ? string.Empty : Encoding.ASCII.GetString(rnte.NameString)) - .Any(s => s.Contains("WZ-SE-01")); - winZipNameFound |= nex.Model.NonResidentNameTable? - .Select(nrnte => nrnte?.NameString == null ? string.Empty : Encoding.ASCII.GetString(nrnte.NameString)) - .Any(s => s.Contains("WinZip(R) Self-Extractor")) ?? false; + bool winZipNameFound = Array.Exists(rntStrs, s => s.Contains("WZ-SE-01")); + winZipNameFound |= Array.Exists(nrntStrs, s => s.Contains("WinZip(R) Self-Extractor")); // If we didn't find it if (!winZipNameFound) diff --git a/BinaryObjectScanner/Protection/ActiveMARK.cs b/BinaryObjectScanner/Protection/ActiveMARK.cs index 03f06691..d3822b8b 100644 --- a/BinaryObjectScanner/Protection/ActiveMARK.cs +++ b/BinaryObjectScanner/Protection/ActiveMARK.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; using System.Text; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; @@ -79,11 +78,11 @@ namespace BinaryObjectScanner.Protection // Get "REGISTRY, AMINTERNETPROTOCOL" resource items var resources = pex.FindResourceByNamedType("REGISTRY, AMINTERNETPROTOCOL"); - if (resources.Any()) + if (resources.Count > 0) { bool match = resources - .Select(r => r == null ? string.Empty : Encoding.ASCII.GetString(r)) - .Any(r => r.Contains("ActiveMARK")); + .ConvertAll(r => r == null ? string.Empty : Encoding.ASCII.GetString(r)) + .FindIndex(r => r.Contains("ActiveMARK")) > -1; if (match) return "ActiveMARK"; } diff --git a/BinaryObjectScanner/Protection/AegiSoft.cs b/BinaryObjectScanner/Protection/AegiSoft.cs index 5af55f39..74ee7b51 100644 --- a/BinaryObjectScanner/Protection/AegiSoft.cs +++ b/BinaryObjectScanner/Protection/AegiSoft.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; using SabreTools.Matching.Content; @@ -41,7 +40,7 @@ namespace BinaryObjectScanner.Protection // Get string table resources var resource = pex.FindStringTableByEntry("AegiSoft License Manager"); - if (resource.Any()) + if (resource.Count > 0) return "AegiSoft License Manager"; // Get the .data/DATA section, if it exists diff --git a/BinaryObjectScanner/Protection/ByteShield.cs b/BinaryObjectScanner/Protection/ByteShield.cs index 77ee0554..9f5a28a5 100644 --- a/BinaryObjectScanner/Protection/ByteShield.cs +++ b/BinaryObjectScanner/Protection/ByteShield.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; using SabreTools.Matching.Paths; @@ -74,20 +73,17 @@ namespace BinaryObjectScanner.Protection return "ByteShield Component Module"; // Found in "LineRider2.exe" in Redump entry 6236 - var stMatch = pex.FindStringTableByEntry("ByteShield"); - if (stMatch.Any()) + if (pex.FindStringTableByEntry("ByteShield").Count > 0) return $"ByteShield Activation Client {pex.GetInternalVersion()}"; // Found in "LineRider2.exe" in Redump entry 6236 - var dbMatch = pex.FindDialogByTitle("About ByteShield"); - if (dbMatch.Any()) + if (pex.FindDialogByTitle("About ByteShield").Count > 0) return "ByteShield"; // TODO: See if the version number is anywhere else // TODO: Parse the version number out of the dialog box item // Found in "LineRider2.exe" in Redump entry 6236 - dbMatch = pex.FindDialogBoxByItemTitle("ByteShield Version 1.0"); - if (dbMatch.Any()) + if (pex.FindDialogBoxByItemTitle("ByteShield Version 1.0").Count > 0) return "ByteShield"; // Get the .data/DATA section strings, if they exist diff --git a/BinaryObjectScanner/Protection/CDDVDCops.cs b/BinaryObjectScanner/Protection/CDDVDCops.cs index ac2b3227..853eadf0 100644 --- a/BinaryObjectScanner/Protection/CDDVDCops.cs +++ b/BinaryObjectScanner/Protection/CDDVDCops.cs @@ -122,19 +122,18 @@ namespace BinaryObjectScanner.Protection // Check the imported-name table // Found in "h3blade.exe" in Redump entry 85077. - bool importedNameTableEntries = nex.Model.ImportedNameTable? - .Select(kvp => kvp.Value) + bool intMatch = nex.Model.ImportedNameTable?.Values? .Select(inte => inte?.NameString == null ? string.Empty : Encoding.ASCII.GetString(inte.NameString)) .Any(s => s.Contains("CDCOPS")) ?? false; - if (importedNameTableEntries) + if (intMatch) return "CD-Cops"; // Check the nonresident-name table // Found in "CDCOPS.DLL" in Redump entry 85077. - bool nonresidentNameTableEntries = nex.Model.NonResidentNameTable? + bool nrntMatch = nex.Model.NonResidentNameTable? .Select(nrnte => nrnte?.NameString == null ? string.Empty : Encoding.ASCII.GetString(nrnte.NameString)) .Any(s => s.Contains("CDcops assembly-language DLL")) ?? false; - if (nonresidentNameTableEntries) + if (nrntMatch) return "CD-Cops"; return null; diff --git a/BinaryObjectScanner/Protection/CopyX.cs b/BinaryObjectScanner/Protection/CopyX.cs index 95d4358c..0d76e1d3 100644 --- a/BinaryObjectScanner/Protection/CopyX.cs +++ b/BinaryObjectScanner/Protection/CopyX.cs @@ -111,17 +111,17 @@ namespace BinaryObjectScanner.Protection List? lightFiles = null; // TODO: Compensate for the check being run a directory or more higher - var fileList = files.Where(f => !f.EndsWith(".x64", StringComparison.OrdinalIgnoreCase)); + var fileList = files.FindAll(f => !f.EndsWith(".x64", StringComparison.OrdinalIgnoreCase)); foreach (var dir in dirs) { - lightFiles = fileList.Where(f => + lightFiles = fileList.FindAll(f => { f = f.Remove(0, path.Length); f = f.TrimStart('/', '\\'); return f.StartsWith(dir + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase); - }) - .OrderBy(f => f) - .ToList(); + }); + lightFiles.Sort(); + if (lightFiles.Count > 0) break; } diff --git a/BinaryObjectScanner/Protection/DVDMoviePROTECT.cs b/BinaryObjectScanner/Protection/DVDMoviePROTECT.cs index 14c618ce..805c2b34 100644 --- a/BinaryObjectScanner/Protection/DVDMoviePROTECT.cs +++ b/BinaryObjectScanner/Protection/DVDMoviePROTECT.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.IO; -using System.Linq; using BinaryObjectScanner.Interfaces; namespace BinaryObjectScanner.Protection @@ -17,8 +16,8 @@ namespace BinaryObjectScanner.Protection if (Directory.Exists(Path.Combine(path, "VIDEO_TS"))) { - string[] bupfiles = files.Where(s => s.EndsWith(".bup")).ToArray(); - for (int i = 0; i < bupfiles.Length; i++) + var bupfiles = files.FindAll(s => s.EndsWith(".bup")); + for (int i = 0; i < bupfiles.Count; i++) { var bupfile = new FileInfo(bupfiles[i]); if (bupfile.DirectoryName == null) diff --git a/BinaryObjectScanner/Protection/DiscGuard.cs b/BinaryObjectScanner/Protection/DiscGuard.cs index 0130e909..e37af4ee 100644 --- a/BinaryObjectScanner/Protection/DiscGuard.cs +++ b/BinaryObjectScanner/Protection/DiscGuard.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; using SabreTools.Matching.Content; @@ -66,11 +65,14 @@ namespace BinaryObjectScanner.Protection return "DiscGuard"; // Found in "Alternate.exe" (Redump entry 31914) and "Alt.exe" (Redump entries 46743, 46961, 79284, and 79374). - var resources = pex.FindStringTableByEntry("DiscGuard") - .Concat(pex.FindStringTableByEntry("The file Dg.vbn was not found.")) - .Concat(pex.FindStringTableByEntry("The file IosLink.VxD was not found.")) - .Concat(pex.FindStringTableByEntry("The file IosLink.sys was not found.")); - if (resources.Any()) + List?> resources = + [ + .. pex.FindStringTableByEntry("DiscGuard"), + .. pex.FindStringTableByEntry("The file Dg.vbn was not found."), + .. pex.FindStringTableByEntry("The file IosLink.VxD was not found."), + .. pex.FindStringTableByEntry("The file IosLink.sys was not found."), + ]; + if (resources.Count > 0) return "DiscGuard"; // Get the .vbn section, if it exists diff --git a/BinaryObjectScanner/Protection/ElectronicArts.cs b/BinaryObjectScanner/Protection/ElectronicArts.cs index 82d91e34..61691ab0 100644 --- a/BinaryObjectScanner/Protection/ElectronicArts.cs +++ b/BinaryObjectScanner/Protection/ElectronicArts.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using BinaryObjectScanner.Interfaces; using SabreTools.Serialization.Wrappers; @@ -27,9 +26,9 @@ namespace BinaryObjectScanner.Protection if (name?.Equals("CDCode", StringComparison.Ordinal) == true) return $"EA CdKey Registration Module {pex.GetInternalVersion()}"; - if (pex.FindDialogByTitle("About CDKey").Any()) + if (pex.FindDialogByTitle("About CDKey").Count > 0) return $"EA CdKey Registration Module {pex.GetInternalVersion()}"; - else if (pex.FindGenericResource("About CDKey").Any()) + else if (pex.FindGenericResource("About CDKey").Count > 0) return $"EA CdKey Registration Module {pex.GetInternalVersion()}"; // Get the .data/DATA section strings, if they exist diff --git a/BinaryObjectScanner/Protection/Intenium.cs b/BinaryObjectScanner/Protection/Intenium.cs index 7f42ae4d..9786a916 100644 --- a/BinaryObjectScanner/Protection/Intenium.cs +++ b/BinaryObjectScanner/Protection/Intenium.cs @@ -1,5 +1,4 @@ -using System.Linq; -using BinaryObjectScanner.Interfaces; +using BinaryObjectScanner.Interfaces; using SabreTools.Serialization.Wrappers; namespace BinaryObjectScanner.Protection @@ -30,8 +29,7 @@ namespace BinaryObjectScanner.Protection if (sections == null) return null; - var fileNameResource = pex.FindGenericResource("NO NESTED PRMS SUPPORTED"); - if (fileNameResource.Any()) + if (pex.FindGenericResource("NO NESTED PRMS SUPPORTED").Count > 0) return "INTENIUM Trial & Buy Protection"; return null; diff --git a/BinaryObjectScanner/Protection/MGIRegistration.cs b/BinaryObjectScanner/Protection/MGIRegistration.cs index 97e4c0aa..33343a39 100644 --- a/BinaryObjectScanner/Protection/MGIRegistration.cs +++ b/BinaryObjectScanner/Protection/MGIRegistration.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using BinaryObjectScanner.Interfaces; using SabreTools.Serialization.Wrappers; @@ -22,13 +21,11 @@ namespace BinaryObjectScanner.Protection return $"MGI Registration {pex.GetInternalVersion()}"; // Found in "Register.dll" from "VideoWaveIII" in IA item "mgi-videowave-iii-version-3.00-mgi-software-2000". - var resources = pex.FindStringTableByEntry("MGI Registration"); - if (resources.Any()) + if (pex.FindStringTableByEntry("MGI Registration").Count > 0) return "MGI Registration"; // Found in "Register.dll" in IA item "MGIPhotoSuite4.0AndPhotoVista2.02001". - resources = pex.FindStringTableByEntry("Register@register.mgisoft.com"); - if (resources.Any()) + if (pex.FindStringTableByEntry("Register@register.mgisoft.com").Count > 0) return "MGI Registration"; return null; diff --git a/BinaryObjectScanner/Protection/Macrovision.CDilla.cs b/BinaryObjectScanner/Protection/Macrovision.CDilla.cs index 21fb861b..ac47ad20 100644 --- a/BinaryObjectScanner/Protection/Macrovision.CDilla.cs +++ b/BinaryObjectScanner/Protection/Macrovision.CDilla.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using SabreTools.Matching; using SabreTools.Matching.Paths; using SabreTools.Serialization.Wrappers; @@ -101,36 +100,21 @@ namespace BinaryObjectScanner.Protection return $"C-Dilla License Management System Version {pex.ProductVersion}"; // Get string table resources - var resource = pex.FindStringTableByEntry("C-Dilla Licence Management System"); - if (resource.Any()) + if (pex.FindStringTableByEntry("C-Dilla Licence Management System").Count > 0) return $"C-Dilla License Management System"; - - resource = pex.FindStringTableByEntry("C-DiIla Licence Management System"); - if (resource.Any()) + if (pex.FindStringTableByEntry("C-DiIla Licence Management System").Count > 0) return $"C-Dilla License Management System"; - - resource = pex.FindStringTableByEntry("C-DILLA_BITMAP_NAMES_TAG"); - if (resource.Any()) + if (pex.FindStringTableByEntry("C-DILLA_BITMAP_NAMES_TAG").Count > 0) return $"C-Dilla License Management System"; - - resource = pex.FindStringTableByEntry("C-DILLA_EDITABLE_STRINGS_TAG"); - if (resource.Any()) + if (pex.FindStringTableByEntry("C-DILLA_EDITABLE_STRINGS_TAG").Count > 0) return $"C-Dilla License Management System"; - - resource = pex.FindStringTableByEntry("CdaLMS.exe"); - if (resource.Any()) + if (pex.FindStringTableByEntry("CdaLMS.exe").Count > 0) return $"C-Dilla License Management System"; - - resource = pex.FindStringTableByEntry("cdilla51.dll"); - if (resource.Any()) + if (pex.FindStringTableByEntry("cdilla51.dll").Count > 0) return $"C-Dilla License Management System"; - - resource = pex.FindStringTableByEntry("cdilla52.dll"); - if (resource.Any()) + if (pex.FindStringTableByEntry("cdilla52.dll").Count > 0) return $"C-Dilla License Management System"; - - resource = pex.FindStringTableByEntry("http://www.c-dilla.com/support/lms.html"); - if (resource.Any()) + if (pex.FindStringTableByEntry("http://www.c-dilla.com/support/lms.html").Count > 0) return $"C-Dilla License Management System"; // Get the .data/DATA section strings, if they exist diff --git a/BinaryObjectScanner/Protection/Macrovision.CactusDataShield.cs b/BinaryObjectScanner/Protection/Macrovision.CactusDataShield.cs index 3b89dd00..59cc12a4 100644 --- a/BinaryObjectScanner/Protection/Macrovision.CactusDataShield.cs +++ b/BinaryObjectScanner/Protection/Macrovision.CactusDataShield.cs @@ -44,15 +44,13 @@ namespace BinaryObjectScanner.Protection { if (strs.Exists(s => s.Contains("\\*.CDS"))) return "Cactus Data Shield 200"; - if (strs.Exists(s => s.Contains("DATA.CDS"))) return "Cactus Data Shield 200"; } // Found in "Volumia!" by Puur (Barcode 7 43218 63282 2) (Discogs Release Code [r795427]). // Modified version of the PlayJ Music Player specificaly for CDS, as indicated by the About page present when running the executable. - var resources = pex.FindGenericResource("CactusPJ"); - if (resources != null && resources.Any()) + if (pex.FindGenericResource("CactusPJ").Count > 0) return "PlayJ Music Player (Cactus Data Shield 200)"; // Found in various files in "Les Paul & Friends" (Barcode 4 98806 834170). diff --git a/BinaryObjectScanner/Protection/Macrovision.SafeCast.cs b/BinaryObjectScanner/Protection/Macrovision.SafeCast.cs index 6eaf0c34..8d4e8bbc 100644 --- a/BinaryObjectScanner/Protection/Macrovision.SafeCast.cs +++ b/BinaryObjectScanner/Protection/Macrovision.SafeCast.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Text; using SabreTools.Matching; using SabreTools.Matching.Content; @@ -91,8 +90,7 @@ namespace BinaryObjectScanner.Protection // Get the dialog box resources // Found in "CDAC21BA.DLL" in Redump entry 95524. - var resource = pex.FindDialogByTitle("SafeCast API"); - if (resource.Any()) + if (pex.FindDialogByTitle("SafeCast API").Count > 0) return "SafeCast"; // Get the .data/DATA section strings, if they exist diff --git a/BinaryObjectScanner/Protection/Macrovision.SafeDisc.cs b/BinaryObjectScanner/Protection/Macrovision.SafeDisc.cs index 8c2b5e29..cbdbc250 100644 --- a/BinaryObjectScanner/Protection/Macrovision.SafeDisc.cs +++ b/BinaryObjectScanner/Protection/Macrovision.SafeDisc.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using SabreTools.Hashing; using SabreTools.Matching; using SabreTools.Matching.Paths; @@ -106,7 +105,9 @@ namespace BinaryObjectScanner.Protection // Get the debug data try { - if (pex.FindCodeViewDebugTableByPath("SafeDisc").Any() || pex.FindCodeViewDebugTableByPath("Safedisk").Any()) + if (pex.FindCodeViewDebugTableByPath("SafeDisc").Count > 0) + return "SafeDisc"; + if (pex.FindCodeViewDebugTableByPath("Safedisk").Count > 0) return "SafeDisc"; } catch { } diff --git a/BinaryObjectScanner/Protection/MediaMax.cs b/BinaryObjectScanner/Protection/MediaMax.cs index 9f333e6e..25df04cc 100644 --- a/BinaryObjectScanner/Protection/MediaMax.cs +++ b/BinaryObjectScanner/Protection/MediaMax.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; using SabreTools.Matching.Paths; @@ -33,12 +32,10 @@ namespace BinaryObjectScanner.Protection if (name?.StartsWith("LicGen Module", StringComparison.OrdinalIgnoreCase) == true) return $"MediaMax CD-3"; - var cd3CtrlResources = pex.FindGenericResource("Cd3Ctl"); - if (cd3CtrlResources.Any()) + if (pex.FindGenericResource("Cd3Ctl").Count > 0) return $"MediaMax CD-3"; - var limitedProductionResources = pex.FindDialogBoxByItemTitle("This limited production advanced CD is not playable on your computer. It is solely intended for playback on standard CD players."); - if (limitedProductionResources.Any()) + if (pex.FindDialogBoxByItemTitle("This limited production advanced CD is not playable on your computer. It is solely intended for playback on standard CD players.").Count > 0) return $"MediaMax CD-3"; // TODO: Investigate the following dialog item title resource diff --git a/BinaryObjectScanner/Protection/ProtectDVDVideo.cs b/BinaryObjectScanner/Protection/ProtectDVDVideo.cs index c8813fb4..aac5398c 100644 --- a/BinaryObjectScanner/Protection/ProtectDVDVideo.cs +++ b/BinaryObjectScanner/Protection/ProtectDVDVideo.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.IO; -using System.Linq; using BinaryObjectScanner.Interfaces; namespace BinaryObjectScanner.Protection @@ -17,8 +16,8 @@ namespace BinaryObjectScanner.Protection if (Directory.Exists(Path.Combine(path, "VIDEO_TS"))) { - string[] ifofiles = files.Where(s => s.EndsWith(".ifo")).ToArray(); - for (int i = 0; i < ifofiles.Length; i++) + var ifofiles = files.FindAll(s => s.EndsWith(".ifo")); + for (int i = 0; i < ifofiles.Count; i++) { var ifofile = new FileInfo(ifofiles[i]); if (ifofile.Length == 0) diff --git a/BinaryObjectScanner/Protection/ProtectDisc.cs b/BinaryObjectScanner/Protection/ProtectDisc.cs index c5e2f701..69fae39c 100644 --- a/BinaryObjectScanner/Protection/ProtectDisc.cs +++ b/BinaryObjectScanner/Protection/ProtectDisc.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; using SabreTools.Matching.Content; @@ -174,13 +175,7 @@ namespace BinaryObjectScanner.Protection index = positions[0] - 12 - 6; // Version 7 -#if NET20 || NET35 || NET40 - temp = new byte[6]; - Array.Copy(fileContent, index, temp, 0, 6); - if (new string(Array.ConvertAll(temp, b => (char)b)) == "Henrik") -#else - if (new string(new ArraySegment(fileContent, index, 6).Select(b => (char)b).ToArray()) == "Henrik") -#endif + if (Encoding.ASCII.GetString(fileContent, index, 6) == "Henrik") { version = "7.1-7.5"; index = positions[0] - 12 - 6 - 6; @@ -194,7 +189,7 @@ namespace BinaryObjectScanner.Protection index = positions[0] - 12 - 10; while (true) //search for e.g. "Build 050913 - September 2005" { - if (Char.IsNumber((char)fileContent[index])) + if (char.IsNumber((char)fileContent[index])) break; index--; // Search upwards @@ -203,15 +198,9 @@ namespace BinaryObjectScanner.Protection index -= 5; } -#if NET20 || NET35 || NET40 - temp = new byte[6]; - Array.Copy(fileContent, index, temp, 0, 6); - char[] arrBuild = Array.ConvertAll(temp, b => (char)b); -#else - char[] arrBuild = new ArraySegment(fileContent, index, 6).Select(b => (char)b).ToArray(); -#endif - if (!Int32.TryParse(new string(arrBuild), out int intBuild)) - strBuild = $"[Build {new string(arrBuild).Trim()}]"; + strBuild = Encoding.ASCII.GetString(fileContent, index, 6).Trim(); + if (!int.TryParse(strBuild, out int intBuild)) + strBuild = $"[Build {strBuild}]"; else strBuild = $"[Build 0x{intBuild:X} / {intBuild}]"; diff --git a/BinaryObjectScanner/Protection/RainbowSentinel.cs b/BinaryObjectScanner/Protection/RainbowSentinel.cs index 8470c23f..aa0f2199 100644 --- a/BinaryObjectScanner/Protection/RainbowSentinel.cs +++ b/BinaryObjectScanner/Protection/RainbowSentinel.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Text; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; @@ -105,26 +104,21 @@ namespace BinaryObjectScanner.Protection if (!string.IsNullOrEmpty(match)) return match; + // Get the resident and non-resident name table strings + var nrntStrs = Array.ConvertAll(nex.Model.NonResidentNameTable ?? [], + rnte => rnte?.NameString == null ? string.Empty : Encoding.ASCII.GetString(rnte.NameString)); + // Check the nonresident-name table // Found in "SSWIN.dll" in IA item "pcwkcd-1296". - bool nonresidentNameTableEntries = nex.Model.NonResidentNameTable? - .Select(nrnte => nrnte?.NameString == null ? string.Empty : Encoding.ASCII.GetString(nrnte.NameString)) - .Any(s => s.Contains("SentinelPro Windows Driver DLL")) ?? false; - if (nonresidentNameTableEntries) + if (Array.Exists(nrntStrs, s => s.Contains("SentinelPro Windows Driver DLL"))) return "Rainbow SentinelPro"; // Found in "INSTALL.EXE" in IA item "czchip199707cd". - nonresidentNameTableEntries = nex.Model.NonResidentNameTable? - .Select(nrnte => nrnte?.NameString == null ? string.Empty : Encoding.ASCII.GetString(nrnte.NameString)) - .Any(s => s.Contains("Rainbow Technologies Installation Program")) ?? false; - if (nonresidentNameTableEntries) + if (Array.Exists(nrntStrs, s => s.Contains("Rainbow Technologies Installation Program"))) return "Rainbow Sentinel"; // Found in "WNCEDITD.EXE" and "WNCEDITO.EXE" in IA item "czchip199707cd". - nonresidentNameTableEntries = nex.Model.NonResidentNameTable? - .Select(nrnte => nrnte?.NameString == null ? string.Empty : Encoding.ASCII.GetString(nrnte.NameString)) - .Any(s => s.Contains("NetSentinel-C Editor for Windows")) ?? false; - if (nonresidentNameTableEntries) + if (Array.Exists(nrntStrs, s => s.Contains("NetSentinel-C Editor for Windows"))) return "NetSentinel-C Editor for Windows"; // TODO: Investigate "SentinelScribe Windows Driver DLL" found in "NKWIN.DLL" in IA item "czchip199707cd". diff --git a/BinaryObjectScanner/Protection/Roxxe.cs b/BinaryObjectScanner/Protection/Roxxe.cs index de82921c..de0ab231 100644 --- a/BinaryObjectScanner/Protection/Roxxe.cs +++ b/BinaryObjectScanner/Protection/Roxxe.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; using SabreTools.Matching.Paths; @@ -51,10 +50,10 @@ namespace BinaryObjectScanner.Protection // If any dialog boxes match // Found in "Data6.OWP" in IA item "game4u-22-cd". - if (pex.FindDialogBoxByItemTitle("SharpTiny Version 1.0").Any()) + if (pex.FindDialogBoxByItemTitle("SharpTiny Version 1.0").Count > 0) return "Roxxe"; // Found in "Data8.OWP" in IA item "game4u-22-cd". - else if (pex.FindDialogBoxByItemTitle("T32xWin Version 1.0").Any()) + else if (pex.FindDialogBoxByItemTitle("T32xWin Version 1.0").Count > 0) return "Roxxe"; return null; diff --git a/BinaryObjectScanner/Protection/SoftLock.cs b/BinaryObjectScanner/Protection/SoftLock.cs index e8367738..1a35fe3b 100644 --- a/BinaryObjectScanner/Protection/SoftLock.cs +++ b/BinaryObjectScanner/Protection/SoftLock.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; using SabreTools.Matching.Paths; @@ -33,48 +32,38 @@ namespace BinaryObjectScanner.Protection return "SoftLock"; // Found in "IALib.DLL" in IA item "TAFSEERVER4SETUP" - var stMatch = pex.FindStringTableByEntry("Softlock CD"); - if (stMatch.Any()) + if (pex.FindStringTableByEntry("Softlock CD").Count > 0) return "SoftLock"; // Found in "IALib.DLL" in IA item "TAFSEERVER4SETUP" - stMatch = pex.FindStringTableByEntry("Softlock USB Key"); - if (stMatch.Any()) + if (pex.FindStringTableByEntry("Softlock USB Key").Count > 0) return "SoftLock"; // Found in "IALib.DLL" in IA item "TAFSEERVER4SETUP" - var dbMatch = pex.FindDialogByTitle("Softlock Protection Kit"); - if (dbMatch.Any()) + if (pex.FindDialogByTitle("Softlock Protection Kit").Count > 0) return "SoftLock"; // Found in "IALib.DLL" in IA item "TAFSEERVER4SETUP" - dbMatch = pex.FindDialogByTitle("About Softlock Protected Application"); - if (dbMatch.Any()) + if (pex.FindDialogByTitle("About Softlock Protected Application").Count > 0) return "SoftLock"; // Found in "IALib.DLL" in IA item "TAFSEERVER4SETUP" - dbMatch = pex.FindDialogBoxByItemTitle("www.softlock.net"); - if (dbMatch.Any()) + if (pex.FindDialogBoxByItemTitle("www.softlock.net").Count > 0) return "SoftLock"; // TODO: See if the version number is anywhere else // TODO: Parse the version number out of the dialog box item // Found in "IALib.DLL" in IA item "TAFSEERVER4SETUP" - dbMatch = pex.FindDialogBoxByItemTitle("Softlock Protected Application Version 1.0"); - if (dbMatch.Any()) + if (pex.FindDialogBoxByItemTitle("Softlock Protected Application Version 1.0").Count > 0) return "SoftLock"; // There are many mentions of USB dongle and CD protection in the various string tables // and dialog boxes. See if any of those are unique to SoftLock. - // Get strings from .section, if possible - var strings = pex.GetFirstSectionStrings(".section"); - if (strings != null && strings.Count > 0) - { - // Found in "TafseerVer4.exe" in IA item "TAFSEERVER4SETUP" - if (strings.Exists(s => s?.Contains("SOFTLOCKPROTECTION") == true)) - return "SoftLock"; - } + // Found in "TafseerVer4.exe" in IA item "TAFSEERVER4SETUP" + var strings = pex.GetFirstSectionStrings(".section") ?? []; + if (strings.Exists(s => s?.Contains("SOFTLOCKPROTECTION") == true)) + return "SoftLock"; // Investigate if the ".section" section is an indicator of SoftLock diff --git a/BinaryObjectScanner/Protection/SolidShield.cs b/BinaryObjectScanner/Protection/SolidShield.cs index bbd8a6f8..edd95f46 100644 --- a/BinaryObjectScanner/Protection/SolidShield.cs +++ b/BinaryObjectScanner/Protection/SolidShield.cs @@ -73,8 +73,7 @@ namespace BinaryObjectScanner.Protection } // Get the wrapper resource, if it exists - var wrapperResources = pex.FindResourceByNamedType("BIN, IDR_SGT"); - if (wrapperResources != null && wrapperResources.Any()) + if (pex.FindResourceByNamedType("BIN, IDR_SGT").Count > 0) return "SolidShield EXE Wrapper v1"; // Search the last two available sections diff --git a/BinaryObjectScanner/Protection/ThreeTwoOneStudios.cs b/BinaryObjectScanner/Protection/ThreeTwoOneStudios.cs index 88465cac..6a6ac5ce 100644 --- a/BinaryObjectScanner/Protection/ThreeTwoOneStudios.cs +++ b/BinaryObjectScanner/Protection/ThreeTwoOneStudios.cs @@ -1,5 +1,4 @@ -using System.Linq; -using BinaryObjectScanner.Interfaces; +using BinaryObjectScanner.Interfaces; using SabreTools.Serialization.Wrappers; namespace BinaryObjectScanner.Protection @@ -15,9 +14,9 @@ namespace BinaryObjectScanner.Protection return null; // Check the dialog box resources - if (pex.FindDialogByTitle("321Studios Activation").Any()) + if (pex.FindDialogByTitle("321Studios Activation").Count > 0) return $"321Studios Online Activation"; - else if (pex.FindDialogByTitle("321Studios Phone Activation").Any()) + else if (pex.FindDialogByTitle("321Studios Phone Activation").Count > 0) return $"321Studios Online Activation"; return null; diff --git a/BinaryObjectScanner/Protection/WMDS.cs b/BinaryObjectScanner/Protection/WMDS.cs index ebc48ecc..741a5a01 100644 --- a/BinaryObjectScanner/Protection/WMDS.cs +++ b/BinaryObjectScanner/Protection/WMDS.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using BinaryObjectScanner.Interfaces; using SabreTools.Matching; using SabreTools.Matching.Paths; @@ -30,13 +29,11 @@ namespace BinaryObjectScanner.Protection return "Windows Media Data Session DRM"; // Found in "autorun.exe" ("Touch" by Amerie). - var resource = pex.FindDialogBoxByItemTitle("If you attempt to play this content on a computer without a license, you will first have to acquire a license before it will play."); - if (resource.Any()) + if (pex.FindDialogBoxByItemTitle("If you attempt to play this content on a computer without a license, you will first have to acquire a license before it will play.").Count > 0) return "Windows Media Data Session DRM"; // Found in "autorun.exe" ("Touch" by Amerie). - resource = pex.FindDialogBoxByItemTitle("You cannot generate a licence to play the protected Windows Media files without an original disc."); - if (resource.Any()) + if (pex.FindDialogBoxByItemTitle("You cannot generate a licence to play the protected Windows Media files without an original disc.").Count > 0) return "Windows Media Data Session DRM"; return null; diff --git a/BinaryObjectScanner/Protection/XCP.cs b/BinaryObjectScanner/Protection/XCP.cs index d5455337..4b099198 100644 --- a/BinaryObjectScanner/Protection/XCP.cs +++ b/BinaryObjectScanner/Protection/XCP.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using BinaryObjectScanner.Interfaces; using SabreTools.IO; using SabreTools.Serialization.Wrappers; @@ -47,10 +46,10 @@ namespace BinaryObjectScanner.Protection return protections; // TODO: Verify if these are OR or AND - if (files.Any(f => Path.GetFileName(f).Equals("XCP.DAT", StringComparison.OrdinalIgnoreCase)) - || files.Any(f => Path.GetFileName(f).Equals("ECDPlayerControl.ocx", StringComparison.OrdinalIgnoreCase))) + if (files.Exists(f => Path.GetFileName(f).Equals("XCP.DAT", StringComparison.OrdinalIgnoreCase)) + || files.Exists(f => Path.GetFileName(f).Equals("ECDPlayerControl.ocx", StringComparison.OrdinalIgnoreCase))) { - var versionDatPath = files.FirstOrDefault(f => Path.GetFileName(f).Equals("VERSION.DAT", StringComparison.OrdinalIgnoreCase)); + var versionDatPath = files.Find(f => Path.GetFileName(f).Equals("VERSION.DAT", StringComparison.OrdinalIgnoreCase)); if (!string.IsNullOrEmpty(versionDatPath)) { var xcpVersion = GetDatVersion(versionDatPath);