2022-02-10 11:06:35 -08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Concurrent;
|
2021-07-18 09:44:23 -07:00
|
|
|
|
using System.Collections.Generic;
|
2022-12-08 14:01:12 -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
|
|
|
|
{
|
2022-05-01 17:23:00 -07:00
|
|
|
|
public class StarForce : IPathCheck, IPortableExecutableCheck
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
2022-12-13 12:42:55 -07:00
|
|
|
|
// TODO: Bring up to par with PiD.
|
|
|
|
|
|
// Known issues:
|
|
|
|
|
|
// "Game.exe" not detected, "SF Crypto" not found in protect.* files (Redump entry 96137).
|
|
|
|
|
|
// "HR.exe" Themida not detected, doesn't detect "[Builder]" (Is that the default StarForce?) (Redump entry 94805).
|
|
|
|
|
|
// "ChromeEngine3.dll" and "SGP4.dll" not detected, doesn't detect "[FL Disc]" (Redump entry 93098).
|
|
|
|
|
|
// "Replay.exe" not detected, doesn't detect "[FL Disc]" (Redump entry 81756).
|
|
|
|
|
|
// Doesn't detect "[Pro]" (Redump entry 91336).
|
2021-09-05 23:22:48 -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-10 13:51:32 -07:00
|
|
|
|
// Get the sections from the executable, if possible
|
|
|
|
|
|
var sections = pex?.SectionTable;
|
|
|
|
|
|
if (sections == null)
|
|
|
|
|
|
return null;
|
2021-09-05 23:22:48 -07:00
|
|
|
|
|
2022-04-02 16:12:23 -07:00
|
|
|
|
string name = pex.LegalCopyright;
|
2022-12-08 14:01:12 -08:00
|
|
|
|
if (name?.StartsWith("(c) Protection Technology") == true) // (c) Protection Technology (StarForce)?
|
2023-03-09 23:19:27 -05:00
|
|
|
|
return $"StarForce {pex.GetInternalVersion()}";
|
2022-12-08 14:01:12 -08:00
|
|
|
|
else if (name?.Contains("Protection Technology") == true) // Protection Technology (StarForce)?
|
2023-03-09 23:19:27 -05:00
|
|
|
|
return $"StarForce {pex.GetInternalVersion()}";
|
2022-02-10 11:06:35 -08:00
|
|
|
|
|
2022-12-13 12:42:55 -07:00
|
|
|
|
// TODO: Decide if internal name checks are safe to use.
|
2022-04-02 16:12:23 -07:00
|
|
|
|
name = pex.InternalName;
|
2022-12-13 12:42:55 -07:00
|
|
|
|
|
|
|
|
|
|
// Found in "protect.x64" and "protect.x86" in Redump entry 94805.
|
|
|
|
|
|
if (name?.Equals("CORE.ADMIN", StringComparison.Ordinal) == true)
|
2023-03-09 23:19:27 -05:00
|
|
|
|
return $"StarForce {pex.GetInternalVersion()}";
|
2021-09-05 23:22:48 -07:00
|
|
|
|
|
2022-12-13 12:42:55 -07:00
|
|
|
|
|
|
|
|
|
|
// These checks currently disabled due being possibly too generic:
|
|
|
|
|
|
// Found in "protect.dll" in Redump entry 94805.
|
|
|
|
|
|
// if (name?.Equals("CORE.DLL", StringComparison.Ordinal) == true)
|
2022-12-15 00:13:24 -08:00
|
|
|
|
// return $"StarForce {Tools.Utilities.GetInternalVersion(pex)}";
|
2022-12-13 12:42:55 -07:00
|
|
|
|
//
|
|
|
|
|
|
// Found in "protect.exe" in Redump entry 94805.
|
|
|
|
|
|
// if (name?.Equals("CORE.EXE", StringComparison.Ordinal) == true)
|
2022-12-15 00:13:24 -08:00
|
|
|
|
// return $"StarForce {Tools.Utilities.GetInternalVersion(pex)}";
|
2022-12-13 12:42:55 -07:00
|
|
|
|
//
|
|
|
|
|
|
// else if (name?.Equals("protect.exe", StringComparison.Ordinal) == true)
|
2022-12-15 00:13:24 -08:00
|
|
|
|
// return $"StarForce {Tools.Utilities.GetInternalVersion(pex)}";
|
2022-12-13 12:42:55 -07:00
|
|
|
|
|
2022-12-08 14:01:12 -08:00
|
|
|
|
// Check the export name table
|
|
|
|
|
|
if (pex.ExportNameTable != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
// TODO: Should we just check for "PSA_*" instead of a single entry?
|
|
|
|
|
|
if (pex.ExportNameTable.Any(s => s == "PSA_GetDiscLabel"))
|
2023-03-09 23:19:27 -05:00
|
|
|
|
return $"StarForce {pex.GetInternalVersion()}";
|
2022-12-08 14:01:12 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-09-05 23:22:48 -07:00
|
|
|
|
// TODO: Find what fvinfo field actually maps to this
|
2022-04-02 16:12:23 -07:00
|
|
|
|
name = pex.FileDescription;
|
2022-12-13 12:42:55 -07:00
|
|
|
|
|
|
|
|
|
|
// There are some File Description checks that are currently too generic to use.
|
|
|
|
|
|
// "Host Library" - Found in "protect.dll" in Redump entry 81756.
|
|
|
|
|
|
// "User Interface Application" - Found in "protect.exe" in Redump entry 81756.
|
|
|
|
|
|
// "Helper Application" - Found in "protect.x64" and "protect.x86" in Redump entry 81756.
|
|
|
|
|
|
|
|
|
|
|
|
// Found in "protect.exe" in Redump entry 94805.
|
|
|
|
|
|
if (name?.Contains("FrontLine Protection GUI Application") == true)
|
2023-03-09 23:19:27 -05:00
|
|
|
|
return $"StarForce {pex.GetInternalVersion()}";
|
2022-12-13 12:42:55 -07:00
|
|
|
|
|
|
|
|
|
|
// Found in "protect.dll" in Redump entry 94805.
|
|
|
|
|
|
if (name?.Contains("FrontLine Protection Library") == true)
|
2023-03-09 23:19:27 -05:00
|
|
|
|
return $"StarForce {pex.GetInternalVersion()}";
|
2022-12-13 12:42:55 -07:00
|
|
|
|
|
|
|
|
|
|
// Found in "protect.x64" and "protect.x86" in Redump entry 94805.
|
|
|
|
|
|
if (name?.Contains("FrontLine Helper") == true)
|
2023-03-09 23:19:27 -05:00
|
|
|
|
return $"StarForce {pex.GetInternalVersion()}";
|
2022-12-13 12:42:55 -07:00
|
|
|
|
|
|
|
|
|
|
// TODO: Find a sample of this check.
|
2022-08-21 20:34:59 -07:00
|
|
|
|
if (name?.Contains("Protected Module") == true)
|
2021-09-05 23:22:48 -07:00
|
|
|
|
return $"StarForce 5";
|
|
|
|
|
|
|
2022-06-22 10:00:35 -07:00
|
|
|
|
// TODO: Check to see if there are any missing checks
|
|
|
|
|
|
// https://github.com/horsicq/Detect-It-Easy/blob/master/db/PE/StarForce.2.sg
|
|
|
|
|
|
|
2021-09-05 23:22:48 -07:00
|
|
|
|
// Get the .brick section, if it exists
|
2021-09-11 21:03:36 -07:00
|
|
|
|
bool brickSection = pex.ContainsSection(".brick", exact: true);
|
|
|
|
|
|
if (brickSection)
|
2021-09-05 23:22:48 -07:00
|
|
|
|
return "StarForce 3-5";
|
|
|
|
|
|
|
|
|
|
|
|
// Get the .sforce* section, if it exists
|
2021-09-11 21:03:36 -07:00
|
|
|
|
bool sforceSection = pex.ContainsSection(".sforce", exact: false);
|
|
|
|
|
|
if (sforceSection)
|
2021-09-05 23:22:48 -07:00
|
|
|
|
return "StarForce 3-5";
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2022-12-13 12:42:55 -07:00
|
|
|
|
var matchers = new List<PathMatchSet>
|
|
|
|
|
|
{
|
|
|
|
|
|
// This file combination is found in Redump entry 21136.
|
|
|
|
|
|
new PathMatchSet(new List<PathMatch>
|
|
|
|
|
|
{
|
|
|
|
|
|
new PathMatch("protect.x86", useEndsWith: true),
|
|
|
|
|
|
new PathMatch("protect.x64", useEndsWith: true),
|
|
|
|
|
|
new PathMatch("protect.dll", useEndsWith: true),
|
|
|
|
|
|
new PathMatch("protect.exe", useEndsWith: true),
|
|
|
|
|
|
new PathMatch("protect.msg", useEndsWith: true),
|
|
|
|
|
|
}, "StarForce"),
|
|
|
|
|
|
|
|
|
|
|
|
// This file combination is found in multiple games, such as Redump entries 81756, 91336, and 93657.
|
|
|
|
|
|
new PathMatchSet(new List<PathMatch>
|
|
|
|
|
|
{
|
|
|
|
|
|
new PathMatch("protect.x86", useEndsWith: true),
|
|
|
|
|
|
new PathMatch("protect.x64", useEndsWith: true),
|
|
|
|
|
|
new PathMatch("protect.dll", useEndsWith: true),
|
|
|
|
|
|
new PathMatch("protect.exe", useEndsWith: true),
|
|
|
|
|
|
}, "StarForce"),
|
|
|
|
|
|
|
|
|
|
|
|
// This file combination is found in Redump entry 96137.
|
|
|
|
|
|
new PathMatchSet(new List<PathMatch>
|
|
|
|
|
|
{
|
|
|
|
|
|
new PathMatch("protect.x86", useEndsWith: true),
|
|
|
|
|
|
new PathMatch("protect.dll", useEndsWith: true),
|
|
|
|
|
|
new PathMatch("protect.exe", useEndsWith: true),
|
|
|
|
|
|
}, "StarForce"),
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return MatchUtil.GetAllMatches(files, matchers, any: false);
|
2021-03-19 15:41:49 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
public string CheckFilePath(string path)
|
|
|
|
|
|
{
|
2022-12-13 12:42:55 -07:00
|
|
|
|
// TODO: Determine if there are any file name checks that aren't too generic to use on their own.
|
2021-08-27 21:12:09 -07:00
|
|
|
|
return null;
|
2019-09-27 23:52:24 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|