From 28dbe8542b12c5d44a5c28f0a8c6d18a5f1737d9 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 27 Oct 2020 17:01:33 -0700 Subject: [PATCH] Add CDS content checks, fix XCP over-detection --- BurnOutSharp/FileType/Executable.cs | 5 ++ .../ProtectionType/CactusDataShield.cs | 48 +++++++++++-------- BurnOutSharp/ProtectionType/XCP.cs | 25 ++++------ 3 files changed, 41 insertions(+), 37 deletions(-) diff --git a/BurnOutSharp/FileType/Executable.cs b/BurnOutSharp/FileType/Executable.cs index 1c53d2f6..8cbc12ee 100644 --- a/BurnOutSharp/FileType/Executable.cs +++ b/BurnOutSharp/FileType/Executable.cs @@ -78,6 +78,11 @@ namespace BurnOutSharp.FileType if (!string.IsNullOrWhiteSpace(protection)) protections.Add(protection); + // Cactus Data Shield + protection = CactusDataShield.CheckContents(fileContent, includePosition); + if (!string.IsNullOrWhiteSpace(protection)) + protections.Add(protection); + // CD-Cops protection = CDCops.CheckContents(fileContent, includePosition); if (!string.IsNullOrWhiteSpace(protection)) diff --git a/BurnOutSharp/ProtectionType/CactusDataShield.cs b/BurnOutSharp/ProtectionType/CactusDataShield.cs index ad18df07..9132ad50 100644 --- a/BurnOutSharp/ProtectionType/CactusDataShield.cs +++ b/BurnOutSharp/ProtectionType/CactusDataShield.cs @@ -10,6 +10,21 @@ namespace BurnOutSharp.ProtectionType { public static string CheckContents(byte[] fileContent, bool includePosition = false) { + // DATA.CDS + byte[] check = new byte[] { 0x44, 0x41, 0x54, 0x41, 0x2E, 0x43, 0x44, 0x53 }; + if (fileContent.Contains(check, out int position)) + return "Cactus Data Shield 200" + (includePosition ? $" (Index {position})" : string.Empty); + + // \*.CDS + check = new byte[] { 0x5C, 0x2A, 0x2E, 0x43, 0x44, 0x53 }; + if (fileContent.Contains(check, out position)) + return "Cactus Data Shield 200" + (includePosition ? $" (Index {position})" : string.Empty); + + // CDSPlayer + check = new byte[] { 0x43, 0x44, 0x53, 0x50, 0x6C, 0x61, 0x79, 0x65, 0x72 }; + if (fileContent.Contains(check, out position)) + return "Cactus Data Shield 200" + (includePosition ? $" (Index {position})" : string.Empty); + return null; } @@ -17,36 +32,30 @@ namespace BurnOutSharp.ProtectionType { if (isDirectory) { - // TODO: Verify if these are OR or AND - string appPath = files.FirstOrDefault(f => Path.GetFileName(f).Equals("CDSPlayer.app", StringComparison.OrdinalIgnoreCase)); - if (!string.IsNullOrWhiteSpace(appPath)) - { - string version = GetVersion(appPath); - if (!string.IsNullOrWhiteSpace(version)) - return $"Cactus Data Shield {version}"; - } - if (files.Any(f => Path.GetFileName(f).Equals("yucca.cds", StringComparison.OrdinalIgnoreCase)) || files.Any(f => Path.GetFileName(f).Equals("wmmp.exe", StringComparison.OrdinalIgnoreCase)) || files.Any(f => Path.GetFileName(f).Equals("PJSTREAM.DLL", StringComparison.OrdinalIgnoreCase)) - || files.Any(f => Path.GetFileName(f).Equals("CACTUSPJ.exe", StringComparison.OrdinalIgnoreCase))) + || files.Any(f => Path.GetFileName(f).Equals("CACTUSPJ.exe", StringComparison.OrdinalIgnoreCase)) + || files.Any(f => Path.GetFileName(f).Equals("CDSPlayer.app", StringComparison.OrdinalIgnoreCase))) { + string versionPath = files.FirstOrDefault(f => Path.GetFileName(f).Equals("version.txt", StringComparison.OrdinalIgnoreCase)); + if (!string.IsNullOrWhiteSpace(versionPath)) + { + string version = GetVersion(versionPath); + if (!string.IsNullOrWhiteSpace(version)) + return $"Cactus Data Shield {version}"; + } + return "Cactus Data Shield 200"; } } else { - if (Path.GetFileName(path).Equals("CDSPlayer.app", StringComparison.OrdinalIgnoreCase)) - { - string version = GetVersion(path); - if (!string.IsNullOrWhiteSpace(version)) - return $"Cactus Data Shield {version}"; - } - if (Path.GetFileName(path).Equals("yucca.cds", StringComparison.OrdinalIgnoreCase) || Path.GetFileName(path).Equals("wmmp.exe", StringComparison.OrdinalIgnoreCase) || Path.GetFileName(path).Equals("PJSTREAM.DLL", StringComparison.OrdinalIgnoreCase) - || Path.GetFileName(path).Equals("CACTUSPJ.exe", StringComparison.OrdinalIgnoreCase)) + || Path.GetFileName(path).Equals("CACTUSPJ.exe", StringComparison.OrdinalIgnoreCase) + || Path.GetFileName(path).Equals("CDSPlayer.app", StringComparison.OrdinalIgnoreCase)) { return "Cactus Data Shield 200"; } @@ -62,10 +71,9 @@ namespace BurnOutSharp.ProtectionType try { - // TODO: Can we do anything with the contents? Take a look at CDSPlayer.app using (var sr = new StreamReader(path, Encoding.Default)) { - return sr.ReadLine().Substring(3) + "(" + sr.ReadLine() + ")"; + return $"{sr.ReadLine().Substring(3)} ({sr.ReadLine()})"; } } catch diff --git a/BurnOutSharp/ProtectionType/XCP.cs b/BurnOutSharp/ProtectionType/XCP.cs index 2120230f..e2d0ee37 100644 --- a/BurnOutSharp/ProtectionType/XCP.cs +++ b/BurnOutSharp/ProtectionType/XCP.cs @@ -32,33 +32,24 @@ namespace BurnOutSharp.ProtectionType { if (isDirectory) { - // INI-like file that can be parsed out - string versionDatPath = files.FirstOrDefault(f => Path.GetFileName(f).Equals("VERSION.DAT", StringComparison.OrdinalIgnoreCase)); - if (!string.IsNullOrWhiteSpace(versionDatPath)) - { - string xcpVersion = GetDatVersion(versionDatPath); - if (!string.IsNullOrWhiteSpace(xcpVersion)) - return xcpVersion; - } - // 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)) || files.Any(f => Path.GetFileName(f).Equals("go.exe", StringComparison.OrdinalIgnoreCase))) // Path.Combine("contents", "go.exe") { + string versionDatPath = files.FirstOrDefault(f => Path.GetFileName(f).Equals("VERSION.DAT", StringComparison.OrdinalIgnoreCase)); + if (!string.IsNullOrWhiteSpace(versionDatPath)) + { + string xcpVersion = GetDatVersion(versionDatPath); + if (!string.IsNullOrWhiteSpace(xcpVersion)) + return xcpVersion; + } + return "XCP"; } } else { - // INI-like file that can be parsed out - if (Path.GetFileName(path).Equals("VERSION.DAT", StringComparison.OrdinalIgnoreCase)) - { - string xcpVersion = GetDatVersion(path); - if (!string.IsNullOrWhiteSpace(xcpVersion)) - return xcpVersion; - } - if (Path.GetFileName(path).Equals("XCP.DAT", StringComparison.OrdinalIgnoreCase) || Path.GetFileName(path).Equals("ECDPlayerControl.ocx", StringComparison.OrdinalIgnoreCase) || Path.GetFileName(path).Equals("go.exe", StringComparison.OrdinalIgnoreCase))