Files
BinaryObjectScanner/BinaryObjectScanner.Protection/WTMCDProtect.cs

84 lines
3.0 KiB
C#
Raw Normal View History

using System.Collections.Concurrent;
using System.Collections.Generic;
2022-12-09 21:34:00 -08:00
using System.Linq;
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;
namespace BinaryObjectScanner.Protection
{
2022-05-01 17:23:00 -07:00
public class WTMCDProtect : IPathCheck, IPortableExecutableCheck
{
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-09-08 00:51:25 -07:00
// Get the sections from the executable, if possible
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)
{
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
}
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;
}
2021-02-26 00:32:09 -08:00
/// <inheritdoc/>
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string> files)
{
var matchers = new List<PathMatchSet>
{
2021-08-16 22:58:36 -06:00
new PathMatchSet(new List<PathMatch>
{
new FilePathMatch("wtmfiles.dat"),
new FilePathMatch("Viewer.exe"),
2021-08-16 22:58:36 -06:00
}, "WTM Protection Viewer"),
};
2021-03-19 15:41:49 -07:00
return MatchUtil.GetAllMatches(files, matchers, any: false);
2021-03-19 15:41:49 -07:00
}
/// <inheritdoc/>
public string CheckFilePath(string path)
{
// TODO: Add ImageX.imp as a wildcard, if possible
var matchers = new List<PathMatchSet>
{
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"),
};
return MatchUtil.GetFirstMatch(path, matchers, any: true);
}
}
}