2019-09-27 23:52:24 -07:00
|
|
|
|
using System;
|
2021-07-18 09:44:23 -07:00
|
|
|
|
using System.Collections.Concurrent;
|
2019-09-27 23:52:24 -07:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
2023-03-09 11:52:28 -05:00
|
|
|
|
using BinaryObjectScanner.Interfaces;
|
2023-03-07 16:59:14 -05:00
|
|
|
|
using BinaryObjectScanner.Wrappers;
|
2023-09-08 12:19:31 -04:00
|
|
|
|
using SabreTools.IO;
|
2019-09-27 23:52:24 -07:00
|
|
|
|
|
2023-03-09 23:19:27 -05:00
|
|
|
|
namespace BinaryObjectScanner.Protection
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
2021-03-23 10:36:14 -07:00
|
|
|
|
// TODO: Figure out how to use path check framework here
|
2022-05-01 17:23:00 -07:00
|
|
|
|
public class XCP : IPathCheck, IPortableExecutableCheck
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
2021-08-25 19:37:32 -07:00
|
|
|
|
/// <inheritdoc/>
|
2022-05-01 17:17:15 -07:00
|
|
|
|
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
|
2021-09-08 09:58:11 -07:00
|
|
|
|
{
|
|
|
|
|
|
// Get the sections from the executable, if possible
|
|
|
|
|
|
var sections = pex?.SectionTable;
|
|
|
|
|
|
if (sections == null)
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
2022-12-09 12:33:12 -08:00
|
|
|
|
// Get the .rdata section strings, if they exist
|
|
|
|
|
|
List<string> strs = pex.GetFirstSectionStrings(".rdata");
|
|
|
|
|
|
if (strs != null)
|
2021-09-08 09:58:11 -07:00
|
|
|
|
{
|
2022-12-09 12:33:12 -08:00
|
|
|
|
if (strs.Any(s => s.Contains("XCP.DAT")))
|
|
|
|
|
|
return "XCP";
|
2021-09-14 11:51:01 -07:00
|
|
|
|
|
2022-12-09 12:33:12 -08:00
|
|
|
|
if (strs.Any(s => s.Contains("xcpdrive")))
|
|
|
|
|
|
return "XCP";
|
2021-09-08 09:58:11 -07:00
|
|
|
|
|
2022-12-09 12:33:12 -08:00
|
|
|
|
if (strs.Any(s => s.Contains("XCPPlugins.dll")))
|
|
|
|
|
|
return "XCP";
|
2021-09-08 09:58:11 -07:00
|
|
|
|
|
2022-12-09 12:33:12 -08:00
|
|
|
|
if (strs.Any(s => s.Contains("XCPPhoenix.dll")))
|
|
|
|
|
|
return "XCP";
|
2021-09-08 09:58:11 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-09-14 11:51:01 -07:00
|
|
|
|
return null;
|
2021-09-08 09:58:11 -07:00
|
|
|
|
}
|
2020-10-26 21:08:39 -07:00
|
|
|
|
|
2021-02-26 00:32:09 -08:00
|
|
|
|
/// <inheritdoc/>
|
2021-07-18 09:44:23 -07:00
|
|
|
|
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string> files)
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
2021-07-18 09:44:23 -07:00
|
|
|
|
var protections = new ConcurrentQueue<string>();
|
|
|
|
|
|
|
2021-03-19 15:41:49 -07:00
|
|
|
|
// TODO: Verify if these are OR or AND
|
|
|
|
|
|
if (files.Any(f => Path.GetFileName(f).Equals("XCP.DAT", StringComparison.OrdinalIgnoreCase))
|
2021-07-01 21:51:40 -06:00
|
|
|
|
|| files.Any(f => Path.GetFileName(f).Equals("ECDPlayerControl.ocx", StringComparison.OrdinalIgnoreCase)))
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
2021-03-19 15:41:49 -07:00
|
|
|
|
string versionDatPath = files.FirstOrDefault(f => Path.GetFileName(f).Equals("VERSION.DAT", StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(versionDatPath))
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
2021-03-19 15:41:49 -07:00
|
|
|
|
string xcpVersion = GetDatVersion(versionDatPath);
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(xcpVersion))
|
2021-07-18 09:44:23 -07:00
|
|
|
|
protections.Enqueue(xcpVersion);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
protections.Enqueue("XCP");
|
2019-09-27 23:52:24 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-03-19 15:41:49 -07:00
|
|
|
|
|
2021-07-18 09:44:23 -07:00
|
|
|
|
return protections;
|
2021-03-19 15:41:49 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
public string CheckFilePath(string path)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Path.GetFileName(path).Equals("XCP.DAT", StringComparison.OrdinalIgnoreCase)
|
2021-07-01 21:51:40 -06:00
|
|
|
|
|| Path.GetFileName(path).Equals("ECDPlayerControl.ocx", StringComparison.OrdinalIgnoreCase))
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
2021-03-19 15:41:49 -07:00
|
|
|
|
return "XCP";
|
2019-09-27 23:52:24 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2020-10-26 20:34:47 -07:00
|
|
|
|
|
2020-10-26 22:22:46 -07:00
|
|
|
|
private static string GetDatVersion(string path)
|
2020-10-26 20:34:47 -07:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var xcpIni = new IniFile(path);
|
|
|
|
|
|
return xcpIni["XCP.VERSION"];
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-09-27 23:52:24 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|