2021-07-18 09:44:23 -07:00
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
|
using System.Collections.Generic;
|
2023-03-09 23:19:27 -05:00
|
|
|
|
using System.IO;
|
2022-12-08 15:24:53 -08:00
|
|
|
|
using System.Linq;
|
2023-03-09 11:52:28 -05:00
|
|
|
|
using BinaryObjectScanner.Interfaces;
|
2023-03-07 16:59:14 -05:00
|
|
|
|
using BinaryObjectScanner.Matching;
|
|
|
|
|
|
using BinaryObjectScanner.Wrappers;
|
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-09-01 10:27:16 -07:00
|
|
|
|
// Note that this set of checks also contains "Stardock Product Activation"
|
|
|
|
|
|
// This is intentional, as that protection is highly related to Impulse Reactor
|
2022-05-01 17:23:00 -07:00
|
|
|
|
public class ImpulseReactor : IPathCheck, IPortableExecutableCheck
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
2021-09-01 10:27:16 -07:00
|
|
|
|
/// <inheritdoc/>
|
2022-05-01 17:17:15 -07:00
|
|
|
|
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
2021-09-01 10:27:16 -07:00
|
|
|
|
// Get the sections from the executable, if possible
|
|
|
|
|
|
var sections = pex?.SectionTable;
|
|
|
|
|
|
if (sections == null)
|
|
|
|
|
|
return null;
|
2021-07-17 23:40:16 -07:00
|
|
|
|
|
2022-04-02 16:12:23 -07:00
|
|
|
|
string name = pex.FileDescription;
|
2022-08-21 20:34:59 -07:00
|
|
|
|
if (name?.Contains("ImpulseReactor Dynamic Link Library") == true)
|
2023-03-09 23:19:27 -05:00
|
|
|
|
return $"Impulse Reactor Core Module {pex.GetInternalVersion()}";
|
2022-03-14 11:56:18 -07:00
|
|
|
|
|
2022-04-02 16:12:23 -07:00
|
|
|
|
name = pex.ProductName;
|
2022-08-21 20:34:59 -07:00
|
|
|
|
if (name?.Contains("ImpulseReactor Dynamic Link Library") == true)
|
2023-03-09 23:19:27 -05:00
|
|
|
|
return $"Impulse Reactor Core Module {pex.GetInternalVersion()}";
|
2022-03-14 11:56:18 -07:00
|
|
|
|
|
2022-12-03 22:17:48 -08:00
|
|
|
|
name = pex.OriginalFilename;
|
2022-08-21 20:34:59 -07:00
|
|
|
|
if (name?.Contains("ReactorActivate.exe") == true)
|
2023-03-09 23:19:27 -05:00
|
|
|
|
return $"Stardock Product Activation {pex.GetInternalVersion()}";
|
2022-03-14 11:56:18 -07:00
|
|
|
|
|
2022-12-08 15:24:53 -08:00
|
|
|
|
// TODO: Check for CVP* instead?
|
2023-01-05 22:30:56 -08:00
|
|
|
|
bool containsCheck = pex.ExportNameTable?.Any(s => s?.StartsWith("CVPInitializeClient") ?? false) ?? false;
|
2022-12-09 14:36:43 -08:00
|
|
|
|
bool containsCheck2 = false;
|
2022-12-08 15:24:53 -08:00
|
|
|
|
|
2022-12-09 14:36:43 -08:00
|
|
|
|
// Get the .rdata section strings, if they exist
|
|
|
|
|
|
List<string> strs = pex.GetFirstSectionStrings(".rdata");
|
|
|
|
|
|
if (strs != null)
|
2021-09-01 10:27:16 -07:00
|
|
|
|
{
|
2022-12-09 14:36:43 -08:00
|
|
|
|
containsCheck2 = strs.Any(s => s.EndsWith("ATTLIST"))
|
|
|
|
|
|
&& strs.Any(s => s.Equals("ELEMENT"))
|
|
|
|
|
|
&& strs.Any(s => s.StartsWith("NOTATION"));
|
2021-09-01 10:27:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-09 14:36:43 -08:00
|
|
|
|
if (containsCheck && containsCheck2)
|
2023-03-09 23:19:27 -05:00
|
|
|
|
return $"Impulse Reactor Core Module {pex.GetInternalVersion()}";
|
2022-12-09 14:36:43 -08:00
|
|
|
|
else if (containsCheck && !containsCheck2)
|
|
|
|
|
|
return $"Impulse Reactor";
|
|
|
|
|
|
|
2021-09-01 10:27:16 -07:00
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2019-09-27 23:52:24 -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-03-22 23:02:01 -07:00
|
|
|
|
var matchers = new List<PathMatchSet>
|
|
|
|
|
|
{
|
2023-03-09 23:19:27 -05:00
|
|
|
|
new PathMatchSet(new PathMatch("ImpulseReactor.dll", useEndsWith: true), GetInternalVersion, "Impulse Reactor Core Module"),
|
|
|
|
|
|
new PathMatchSet(new PathMatch("ReactorActivate.exe", useEndsWith: true), GetInternalVersion, "Stardock Product Activation"),
|
2021-03-22 23:02:01 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
2021-03-23 13:35:12 -07:00
|
|
|
|
return MatchUtil.GetAllMatches(files, matchers, any: true);
|
2021-03-19 15:41:49 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
public string CheckFilePath(string path)
|
|
|
|
|
|
{
|
2021-03-22 23:02:01 -07:00
|
|
|
|
var matchers = new List<PathMatchSet>
|
|
|
|
|
|
{
|
2023-03-09 23:19:27 -05:00
|
|
|
|
new PathMatchSet(new PathMatch("ImpulseReactor.dll", useEndsWith: true), GetInternalVersion, "Impulse Reactor Core Module"),
|
|
|
|
|
|
new PathMatchSet(new PathMatch("ReactorActivate.exe", useEndsWith: true), GetInternalVersion, "Stardock Product Activation"),
|
2021-03-22 23:02:01 -07:00
|
|
|
|
};
|
2019-09-27 23:52:24 -07:00
|
|
|
|
|
2021-03-22 23:02:01 -07:00
|
|
|
|
return MatchUtil.GetFirstMatch(path, matchers, any: true);
|
2019-09-27 23:52:24 -07:00
|
|
|
|
}
|
2023-03-09 23:19:27 -05:00
|
|
|
|
|
|
|
|
|
|
private string GetInternalVersion(string firstMatchedString, IEnumerable<string> files)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
using (Stream fileStream = File.Open(firstMatchedString, FileMode.Open, FileAccess.Read, FileShare.Read))
|
|
|
|
|
|
{
|
|
|
|
|
|
var pex = PortableExecutable.Create(fileStream);
|
|
|
|
|
|
return pex.GetInternalVersion();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
return string.Empty;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-09-27 23:52:24 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|