Files
BinaryObjectScanner/BurnOutSharp/ProtectionType/WTMCDProtect.cs

110 lines
4.4 KiB
C#
Raw Normal View History

using System.Collections.Concurrent;
using System.Collections.Generic;
2022-05-13 21:03:13 -07:00
using System.IO;
using BurnOutSharp.ExecutableType.Microsoft.PE;
2022-05-01 17:41:50 -07:00
using BurnOutSharp.Interfaces;
2021-03-21 15:34:19 -07:00
using BurnOutSharp.Matching;
namespace BurnOutSharp.ProtectionType
{
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?.SectionTable;
if (sections == null)
return null;
2022-04-02 16:12:23 -07:00
string name = pex.FileDescription;
2022-03-14 15:00:20 -07:00
if (!string.IsNullOrEmpty(name) && name.Contains("Copy Protection Viewer"))
return "WTM Protection Viewer";
2022-04-02 16:12:23 -07:00
name = pex.ProductName;
2022-03-14 15:00:20 -07:00
if (!string.IsNullOrEmpty(name) && name.Contains("WTM Copy Protection Viewer"))
return "WTM Protection Viewer";
2021-09-08 00:51:25 -07:00
// Get the CODE section, if it exists
var codeSectionRaw = pex.ReadRawSection("CODE", first: true);
if (codeSectionRaw != null)
{
2021-09-08 00:51:25 -07:00
var matchers = new List<ContentMatchSet>
{
// wtmdum.imp
new ContentMatchSet(new byte?[]
{
0x77, 0x74, 0x6D, 0x64, 0x75, 0x6D, 0x2E, 0x69,
0x6D, 0x70
}, "WTM CD Protect"),
2021-09-08 00:51:25 -07:00
};
string match = MatchUtil.GetFirstMatch(file, codeSectionRaw, matchers, includeDebug);
2021-09-08 00:51:25 -07:00
if (!string.IsNullOrWhiteSpace(match))
return match;
}
2021-09-08 00:51:25 -07:00
// Get the .text section, if it exists
if (pex.TextSectionRaw != null)
2021-09-08 00:51:25 -07:00
{
var matchers = new List<ContentMatchSet>
{
2021-09-08 00:51:25 -07:00
// WTM DIGITAL Photo Protect
new ContentMatchSet(new byte?[]
{
0x57, 0x54, 0x4D, 0x20, 0x44, 0x49, 0x47, 0x49,
0x54, 0x41, 0x4C, 0x20, 0x50, 0x68, 0x6F, 0x74,
0x6F, 0x20, 0x50, 0x72, 0x6F, 0x74, 0x65, 0x63,
0x74
}, "WTM Protection Viewer"),
2021-09-08 00:51:25 -07:00
// WTM Copy Protection Viewer
new ContentMatchSet(new byte?[]
{
0x57, 0x54, 0x4D, 0x20, 0x43, 0x6F, 0x70, 0x79,
0x20, 0x50, 0x72, 0x6F, 0x74, 0x65, 0x63, 0x74,
0x69, 0x6F, 0x6E, 0x20, 0x56, 0x69, 0x65, 0x77,
0x65, 0x72
}, "WTM Protection Viewer"),
2021-09-08 00:51:25 -07:00
};
string match = MatchUtil.GetFirstMatch(file, pex.TextSectionRaw, matchers, includeDebug);
2021-09-08 00:51:25 -07:00
if (!string.IsNullOrWhiteSpace(match))
return match;
}
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>
{
2022-05-13 21:03:13 -07:00
new PathMatch($"{Path.DirectorySeparatorChar}wtmfiles.dat", useEndsWith: true),
new PathMatch($"{Path.DirectorySeparatorChar}Viewer.exe", useEndsWith: true),
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>
{
2022-05-13 21:03:13 -07:00
new PathMatchSet(new PathMatch($"{Path.DirectorySeparatorChar}Image.imp", useEndsWith: true), "WTM CD Protect"),
new PathMatchSet(new PathMatch($"{Path.DirectorySeparatorChar}Image1.imp", useEndsWith: true), "WTM CD Protect"),
new PathMatchSet(new PathMatch($"{Path.DirectorySeparatorChar}imp.dat", useEndsWith: true), "WTM CD Protect"),
new PathMatchSet(new PathMatch($"{Path.DirectorySeparatorChar}wtmfiles.dat", useEndsWith: true), "WTM Protection Viewer"),
};
return MatchUtil.GetFirstMatch(path, matchers, any: true);
}
}
}