2021-07-18 09:44:23 -07:00
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
|
using System.Collections.Generic;
|
2022-12-09 21:34:00 -08:00
|
|
|
|
using System.Linq;
|
2023-03-09 11:52:28 -05:00
|
|
|
|
using BinaryObjectScanner.Interfaces;
|
2023-09-16 22:08:18 -04:00
|
|
|
|
using SabreTools.Matching;
|
2023-09-16 02:04:47 -04:00
|
|
|
|
using SabreTools.Serialization.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 WTMCDProtect : IPathCheck, IPortableExecutableCheck
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
2021-09-08 00:51:25 -07:00
|
|
|
|
/// <inheritdoc/>
|
2022-05-01 17:17:15 -07:00
|
|
|
|
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
|
2021-03-23 09:52:09 -07:00
|
|
|
|
{
|
2021-09-08 00:51:25 -07:00
|
|
|
|
// Get the sections from the executable, if possible
|
2023-09-15 22:21:05 -04:00
|
|
|
|
var sections = pex?.Model.SectionTable;
|
2021-09-08 00:51:25 -07:00
|
|
|
|
if (sections == null)
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
2022-04-02 16:12:23 -07:00
|
|
|
|
string name = pex.FileDescription;
|
2022-12-08 17:06:36 -08:00
|
|
|
|
if (name?.Contains("Copy Protection Viewer") == true)
|
|
|
|
|
|
return "WTM Protection Viewer";
|
|
|
|
|
|
|
|
|
|
|
|
name = pex.LegalTrademarks;
|
|
|
|
|
|
if (name?.Contains("WTM Copy Protection") == true)
|
2022-03-14 15:00:20 -07:00
|
|
|
|
return "WTM Protection Viewer";
|
|
|
|
|
|
|
2022-04-02 16:12:23 -07:00
|
|
|
|
name = pex.ProductName;
|
2022-12-08 17:06:36 -08:00
|
|
|
|
if (name?.Contains("WTM Copy Protection Viewer") == true)
|
2022-03-14 15:00:20 -07:00
|
|
|
|
return "WTM Protection Viewer";
|
|
|
|
|
|
|
2022-12-09 21:34:00 -08:00
|
|
|
|
// Get the code/CODE section strings, if they exist
|
|
|
|
|
|
List<string> strs = pex.GetFirstSectionStrings("code") ?? pex.GetFirstSectionStrings("CODE");
|
|
|
|
|
|
if (strs != null)
|
2021-07-17 23:40:16 -07:00
|
|
|
|
{
|
2022-12-09 21:34:00 -08:00
|
|
|
|
if (strs.Any(s => s.Contains("wtmdum.imp")))
|
|
|
|
|
|
return "WTM CD Protect";
|
2021-09-08 00:51:25 -07:00
|
|
|
|
}
|
2021-06-30 10:36:02 -06:00
|
|
|
|
|
2022-12-09 21:34:00 -08:00
|
|
|
|
// Get the .text section strings, if they exist
|
|
|
|
|
|
strs = pex.GetFirstSectionStrings(".text");
|
|
|
|
|
|
if (strs != null)
|
2021-09-08 00:51:25 -07:00
|
|
|
|
{
|
2022-12-09 21:34:00 -08:00
|
|
|
|
if (strs.Any(s => s.Contains("WTM DIGITAL Photo Protect")))
|
|
|
|
|
|
return "WTM Protection Viewer";
|
|
|
|
|
|
else if (strs.Any(s => s.Contains("WTM Copy Protection Viewer")))
|
|
|
|
|
|
return "WTM Protection Viewer";
|
2021-09-08 00:51:25 -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-23 10:36:14 -07:00
|
|
|
|
var matchers = new List<PathMatchSet>
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
2021-08-16 22:58:36 -06:00
|
|
|
|
new PathMatchSet(new List<PathMatch>
|
|
|
|
|
|
{
|
2023-08-26 22:51:55 -04:00
|
|
|
|
new FilePathMatch("wtmfiles.dat"),
|
|
|
|
|
|
new FilePathMatch("Viewer.exe"),
|
2021-08-16 22:58:36 -06:00
|
|
|
|
}, "WTM Protection Viewer"),
|
2021-03-23 10:36:14 -07:00
|
|
|
|
};
|
2021-03-19 15:41:49 -07:00
|
|
|
|
|
2021-06-30 10:36:02 -06:00
|
|
|
|
return MatchUtil.GetAllMatches(files, matchers, any: false);
|
2021-03-19 15:41:49 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
public string CheckFilePath(string path)
|
|
|
|
|
|
{
|
2022-03-02 08:56:26 -08:00
|
|
|
|
// TODO: Add ImageX.imp as a wildcard, if possible
|
2021-03-23 10:36:14 -07:00
|
|
|
|
var matchers = new List<PathMatchSet>
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
2023-08-26 22:51:55 -04:00
|
|
|
|
new PathMatchSet(new FilePathMatch("Image.imp"), "WTM CD Protect"),
|
|
|
|
|
|
new PathMatchSet(new FilePathMatch("Image1.imp"), "WTM CD Protect"),
|
|
|
|
|
|
new PathMatchSet(new FilePathMatch("imp.dat"), "WTM CD Protect"),
|
|
|
|
|
|
new PathMatchSet(new FilePathMatch("wtmfiles.dat"), "WTM Protection Viewer"),
|
2021-03-23 10:36:14 -07:00
|
|
|
|
};
|
2019-09-27 23:52:24 -07:00
|
|
|
|
|
2021-03-23 10:36:14 -07:00
|
|
|
|
return MatchUtil.GetFirstMatch(path, matchers, any: true);
|
2019-09-27 23:52:24 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|