Static list of content matchers

This also includes some more path matcher conversions that I couldn't reasonably split out
This commit is contained in:
Matt Nadareski
2021-03-23 09:52:09 -07:00
parent c3e7f0b99f
commit 921292e077
53 changed files with 1174 additions and 1025 deletions

View File

@@ -1,48 +1,53 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using BurnOutSharp.Matching;
namespace BurnOutSharp.ProtectionType
{
public class MediaMaxCD3 : IContentCheck, IPathCheck
{
/// <summary>
/// Set of all ContentMatchSets for this protection
/// </summary>
private static List<ContentMatchSet> contentMatchers = new List<ContentMatchSet>
{
// Cd3Ctl
new ContentMatchSet(new byte?[] { 0x43, 0x64, 0x33, 0x43, 0x74, 0x6C }, "MediaMax CD-3"),
// DllInstallSbcp
new ContentMatchSet(new byte?[]
{
0x44, 0x6C, 0x6C, 0x49, 0x6E, 0x73, 0x74, 0x61,
0x6C, 0x6C, 0x53, 0x62, 0x63, 0x70
}, "MediaMax CD-3"),
};
/// <inheritdoc/>
public string CheckContents(string file, byte[] fileContent, bool includePosition = false)
{
var matchers = new List<ContentMatchSet>
{
// Cd3Ctl
new ContentMatchSet(new byte?[] { 0x43, 0x64, 0x33, 0x43, 0x74, 0x6C }, "MediaMax CD-3"),
// DllInstallSbcp
new ContentMatchSet(new byte?[]
{
0x44, 0x6C, 0x6C, 0x49, 0x6E, 0x73, 0x74, 0x61,
0x6C, 0x6C, 0x53, 0x62, 0x63, 0x70
}, "MediaMax CD-3"),
};
return MatchUtil.GetFirstMatch(file, fileContent, matchers, includePosition);
return MatchUtil.GetFirstMatch(file, fileContent, contentMatchers, includePosition);
}
/// <inheritdoc/>
public string CheckDirectoryPath(string path, IEnumerable<string> files)
{
if (files.Any(f => Path.GetFileName(f).Equals("LaunchCd.exe", StringComparison.OrdinalIgnoreCase)))
return "MediaMax CD-3";
return null;
var matchers = new List<PathMatchSet>
{
new PathMatchSet(new PathMatch("LaunchCd.exe", useEndsWith: true), "MediaMax CD-3"),
};
var matches = MatchUtil.GetAllMatches(files, matchers, any: true);
return string.Join(", ", matches);
}
/// <inheritdoc/>
public string CheckFilePath(string path)
{
if (Path.GetFileName(path).Equals("LaunchCd.exe", StringComparison.OrdinalIgnoreCase))
return "MediaMax CD-3";
var matchers = new List<PathMatchSet>
{
new PathMatchSet(new PathMatch("LaunchCd.exe", useEndsWith: true), "MediaMax CD-3"),
};
return null;
return MatchUtil.GetFirstMatch(path, matchers, any: true);
}
}
}