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;
|
2022-03-14 10:40:44 -07:00
|
|
|
|
using BurnOutSharp.ExecutableType.Microsoft.PE;
|
2020-10-26 20:34:47 -07:00
|
|
|
|
using BurnOutSharp.FileType;
|
2022-05-01 17:41:50 -07:00
|
|
|
|
using BurnOutSharp.Interfaces;
|
2021-03-21 15:34:19 -07:00
|
|
|
|
using BurnOutSharp.Matching;
|
2019-09-27 23:52:24 -07:00
|
|
|
|
|
|
|
|
|
|
namespace BurnOutSharp.ProtectionType
|
|
|
|
|
|
{
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
// Get the .rdata section, if it exists
|
2021-09-11 16:47:25 -07:00
|
|
|
|
if (pex.ResourceDataSectionRaw != null)
|
2021-09-08 09:58:11 -07:00
|
|
|
|
{
|
|
|
|
|
|
var matchers = new List<ContentMatchSet>
|
|
|
|
|
|
{
|
|
|
|
|
|
// XCP.DAT
|
2021-09-11 16:47:25 -07:00
|
|
|
|
new ContentMatchSet(new byte?[] { 0x58, 0x43, 0x50, 0x2E, 0x44, 0x41, 0x54 }, "XCP"),
|
2021-09-08 09:58:11 -07:00
|
|
|
|
|
2021-09-14 11:51:01 -07:00
|
|
|
|
// xcpdrive
|
2021-09-14 13:53:30 -07:00
|
|
|
|
new ContentMatchSet(new byte?[] { 0x78, 0x63, 0x70, 0x64, 0x72, 0x69, 0x76, 0x65 }, "XCP"),
|
2021-09-14 11:51:01 -07:00
|
|
|
|
|
2021-09-08 09:58:11 -07:00
|
|
|
|
// XCPPlugins.dll
|
2021-09-11 16:47:25 -07:00
|
|
|
|
new ContentMatchSet(new byte?[]
|
|
|
|
|
|
{
|
|
|
|
|
|
0x58, 0x43, 0x50, 0x50, 0x6C, 0x75, 0x67, 0x69,
|
|
|
|
|
|
0x6E, 0x73, 0x2E, 0x64, 0x6C, 0x6C
|
|
|
|
|
|
}, "XCP"),
|
2021-09-08 09:58:11 -07:00
|
|
|
|
|
|
|
|
|
|
// XCPPhoenix.dll
|
2021-09-11 16:47:25 -07:00
|
|
|
|
new ContentMatchSet(new byte?[]
|
|
|
|
|
|
{
|
|
|
|
|
|
0x58, 0x43, 0x50, 0x50, 0x68, 0x6F, 0x65, 0x6E,
|
|
|
|
|
|
0x69, 0x78, 0x2E, 0x64, 0x6C, 0x6C
|
|
|
|
|
|
}, "XCP"),
|
2021-09-08 09:58:11 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
2021-09-11 16:47:25 -07:00
|
|
|
|
string match = MatchUtil.GetFirstMatch(file, pex.ResourceDataSectionRaw, matchers, includeDebug);
|
2021-09-08 09:58:11 -07:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(match))
|
|
|
|
|
|
return match;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
}
|