Files
BinaryObjectScanner/BinaryObjectScanner.Protection/XCP.cs

94 lines
3.0 KiB
C#
Raw Normal View History

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
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;
namespace BinaryObjectScanner.Protection
{
// TODO: Figure out how to use path check framework here
2022-05-01 17:23:00 -07:00
public class XCP : IPathCheck, IPortableExecutableCheck
{
/// <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";
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
}
return null;
2021-09-08 09:58:11 -07:00
}
2021-02-26 00:32:09 -08:00
/// <inheritdoc/>
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string> files)
{
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))
|| files.Any(f => Path.GetFileName(f).Equals("ECDPlayerControl.ocx", StringComparison.OrdinalIgnoreCase)))
{
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))
{
2021-03-19 15:41:49 -07:00
string xcpVersion = GetDatVersion(versionDatPath);
if (!string.IsNullOrWhiteSpace(xcpVersion))
protections.Enqueue(xcpVersion);
}
else
{
protections.Enqueue("XCP");
}
}
2021-03-19 15:41:49 -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)
|| Path.GetFileName(path).Equals("ECDPlayerControl.ocx", StringComparison.OrdinalIgnoreCase))
{
2021-03-19 15:41:49 -07:00
return "XCP";
}
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;
}
}
}
}