Files
BinaryObjectScanner/BinaryObjectScanner.Protection/Origin.cs
Matt Nadareski e118418a23 Move protection scans to their own library
This change also removes a couple of things from `BurnOutSharp.Tools.Utilities` that are no longer needed there. Linear executables are included in the scanning classes. Update the guides accordingly.
2023-03-09 23:19:27 -05:00

54 lines
1.7 KiB
C#

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using BinaryObjectScanner.Interfaces;
using BinaryObjectScanner.Matching;
using BinaryObjectScanner.Wrappers;
namespace BinaryObjectScanner.Protection
{
public class Origin : 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 (name?.Equals("Origin", StringComparison.OrdinalIgnoreCase) == true)
return "Origin";
name = pex.ProductName;
if (name?.Equals("Origin", StringComparison.OrdinalIgnoreCase) == true)
return "Origin";
return null;
}
/// <inheritdoc/>
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string> files)
{
var matchers = new List<PathMatchSet>
{
new PathMatchSet(new PathMatch("OriginSetup.exe", useEndsWith: true), "Origin"),
};
return MatchUtil.GetAllMatches(files, matchers, any: true);
}
/// <inheritdoc/>
public string CheckFilePath(string path)
{
var matchers = new List<PathMatchSet>
{
new PathMatchSet(new PathMatch("OriginSetup.exe", useEndsWith: true), "Origin"),
};
return MatchUtil.GetFirstMatch(path, matchers, any: true);
}
}
}