Files
BinaryObjectScanner/BurnOutSharp/ProtectionType/WTMCDProtect.cs
2022-05-13 21:03:13 -07:00

110 lines
4.4 KiB
C#

using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using BurnOutSharp.ExecutableType.Microsoft.PE;
using BurnOutSharp.Interfaces;
using BurnOutSharp.Matching;
namespace BurnOutSharp.ProtectionType
{
public class WTMCDProtect : IPathCheck, IPortableExecutableCheck
{
/// <inheritdoc/>
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
{
// Get the sections from the executable, if possible
var sections = pex?.SectionTable;
if (sections == null)
return null;
string name = pex.FileDescription;
if (!string.IsNullOrEmpty(name) && name.Contains("Copy Protection Viewer"))
return "WTM Protection Viewer";
name = pex.ProductName;
if (!string.IsNullOrEmpty(name) && name.Contains("WTM Copy Protection Viewer"))
return "WTM Protection Viewer";
// Get the CODE section, if it exists
var codeSectionRaw = pex.ReadRawSection("CODE", first: true);
if (codeSectionRaw != null)
{
var matchers = new List<ContentMatchSet>
{
// wtmdum.imp
new ContentMatchSet(new byte?[]
{
0x77, 0x74, 0x6D, 0x64, 0x75, 0x6D, 0x2E, 0x69,
0x6D, 0x70
}, "WTM CD Protect"),
};
string match = MatchUtil.GetFirstMatch(file, codeSectionRaw, matchers, includeDebug);
if (!string.IsNullOrWhiteSpace(match))
return match;
}
// Get the .text section, if it exists
if (pex.TextSectionRaw != null)
{
var matchers = new List<ContentMatchSet>
{
// 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"),
// 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"),
};
string match = MatchUtil.GetFirstMatch(file, pex.TextSectionRaw, matchers, includeDebug);
if (!string.IsNullOrWhiteSpace(match))
return match;
}
return null;
}
/// <inheritdoc/>
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string> files)
{
var matchers = new List<PathMatchSet>
{
new PathMatchSet(new List<PathMatch>
{
new PathMatch($"{Path.DirectorySeparatorChar}wtmfiles.dat", useEndsWith: true),
new PathMatch($"{Path.DirectorySeparatorChar}Viewer.exe", useEndsWith: true),
}, "WTM Protection Viewer"),
};
return MatchUtil.GetAllMatches(files, matchers, any: false);
}
/// <inheritdoc/>
public string CheckFilePath(string path)
{
// TODO: Add ImageX.imp as a wildcard, if possible
var matchers = new List<PathMatchSet>
{
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);
}
}
}