From 095de1441d1daafc288a5f18b874acb042756c11 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Mon, 26 Oct 2020 21:08:39 -0700 Subject: [PATCH] Add XCP content checks (thanks to Silas) --- BurnOutSharp/FileType/Executable.cs | 5 ++++ BurnOutSharp/ProtectionType/XCP.cs | 42 +++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/BurnOutSharp/FileType/Executable.cs b/BurnOutSharp/FileType/Executable.cs index 046dff8e..3c4bf43e 100644 --- a/BurnOutSharp/FileType/Executable.cs +++ b/BurnOutSharp/FileType/Executable.cs @@ -243,6 +243,11 @@ namespace BurnOutSharp.FileType if (!string.IsNullOrWhiteSpace(protection)) protections.Add(protection); + // XCP 1/2 + protection = XCP.CheckContents(fileContent, includePosition); + if (!string.IsNullOrWhiteSpace(protection)) + protections.Add(protection); + // Xtreme-Protector protection = XtremeProtector.CheckContents(fileContent, includePosition); if (!string.IsNullOrWhiteSpace(protection)) diff --git a/BurnOutSharp/ProtectionType/XCP.cs b/BurnOutSharp/ProtectionType/XCP.cs index 726e033f..e84c172a 100644 --- a/BurnOutSharp/ProtectionType/XCP.cs +++ b/BurnOutSharp/ProtectionType/XCP.cs @@ -8,18 +8,42 @@ namespace BurnOutSharp.ProtectionType { public class XCP { + public static string CheckContents(byte[] fileContent, bool includePosition = false) + { + // XCP.DAT + byte[] check = new byte[] { 0x58, 0x43, 0x50, 0x2E, 0x44, 0x41, 0x54 }; + if (fileContent.Contains(check, out int position)) + return "XCP" + (includePosition ? $" (Index {position})" : string.Empty); + + // XCPPlugins.dll + check = new byte[] { 0x58, 0x43, 0x50, 0x50, 0x6C, 0x75, 0x67, 0x69, 0x6E, 0x73, 0x2E, 0x64, 0x6C, 0x6C }; + if (fileContent.Contains(check, out position)) + return "XCP" + (includePosition ? $" (Index {position})" : string.Empty); + + // XCPPhoenix.dll + check = new byte[] { 0x58, 0x43, 0x50, 0x50, 0x68, 0x6F, 0x65, 0x6E, 0x69, 0x78, 0x2E, 0x64, 0x6C, 0x6C }; + if (fileContent.Contains(check, out position)) + return "XCP" + (includePosition ? $" (Index {position})" : string.Empty); + + return null; + } + public static string CheckPath(string path, IEnumerable files, bool isDirectory) { if (isDirectory) { // INI-like file that can be parsed out - string xcpDatPath = files.FirstOrDefault(f => Path.GetFileName(f).Equals("VERSION.DAT", StringComparison.OrdinalIgnoreCase)) - ?? files.FirstOrDefault(f => Path.GetFileName(f).Equals("XCP.DAT", StringComparison.OrdinalIgnoreCase)); + string xcpDatPath = files.FirstOrDefault(f => Path.GetFileName(f).Equals("VERSION.DAT", StringComparison.OrdinalIgnoreCase)); if (!string.IsNullOrWhiteSpace(xcpDatPath)) - return GetXCPVersion(xcpDatPath); + { + string xcpVersion = GetXCPVersion(xcpDatPath); + if (!string.IsNullOrWhiteSpace(xcpVersion)) + return xcpVersion; + } // TODO: Verify if these are OR or AND - if (files.Any(f => Path.GetFileName(f).Equals("ECDPlayerControl.ocx", StringComparison.OrdinalIgnoreCase)) + 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") { return "XCP"; @@ -28,13 +52,15 @@ namespace BurnOutSharp.ProtectionType else { // INI-like file that can be parsed out - if (Path.GetFileName(path).Equals("VERSION.DAT", StringComparison.OrdinalIgnoreCase) - || Path.GetFileName(path).Equals("XCP.DAT", StringComparison.OrdinalIgnoreCase)) + if (Path.GetFileName(path).Equals("VERSION.DAT", StringComparison.OrdinalIgnoreCase)) { - return GetXCPVersion(path); + string xcpVersion = GetXCPVersion(path); + if (!string.IsNullOrWhiteSpace(xcpVersion)) + return xcpVersion; } - if (Path.GetFileName(path).Equals("ECDPlayerControl.ocx", StringComparison.OrdinalIgnoreCase) + 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)) { return "XCP";