2021-07-18 09:44:23 -07:00
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
|
using System.Collections.Generic;
|
2022-12-09 21:40:25 -08:00
|
|
|
|
using System.Linq;
|
2023-03-09 11:52:28 -05:00
|
|
|
|
using BinaryObjectScanner.Interfaces;
|
2023-03-07 16:59:14 -05:00
|
|
|
|
using BinaryObjectScanner.Matching;
|
|
|
|
|
|
using BinaryObjectScanner.Wrappers;
|
2019-09-27 23:52:24 -07:00
|
|
|
|
|
2023-03-09 23:19:27 -05:00
|
|
|
|
namespace BinaryObjectScanner.Protection
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
2022-05-01 17:23:00 -07:00
|
|
|
|
public class SmartE : IPathCheck, IPortableExecutableCheck
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
2021-08-25 19:37:32 -07:00
|
|
|
|
/// <inheritdoc/>
|
2022-05-01 17:17:15 -07:00
|
|
|
|
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
|
2021-09-03 13:26:52 -07:00
|
|
|
|
{
|
|
|
|
|
|
// Get the sections from the executable, if possible
|
|
|
|
|
|
var sections = pex?.SectionTable;
|
|
|
|
|
|
if (sections == null)
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
2022-12-09 21:40:25 -08:00
|
|
|
|
// Get the last section strings, if they exist
|
|
|
|
|
|
List<string> strs = pex.GetSectionStrings(sections.Length - 1);
|
|
|
|
|
|
if (strs != null)
|
2022-12-05 10:21:15 -08:00
|
|
|
|
{
|
2022-12-09 21:40:25 -08:00
|
|
|
|
if (strs.Any(s => s.Contains("BITARTS")))
|
|
|
|
|
|
return "SmartE";
|
2022-12-05 10:21:15 -08:00
|
|
|
|
}
|
2021-09-03 13:26:52 -07:00
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2019-09-27 23:52:24 -07:00
|
|
|
|
|
2021-02-26 00:32:09 -08:00
|
|
|
|
/// <inheritdoc/>
|
2021-07-18 09:44:23 -07:00
|
|
|
|
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string> files)
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
2021-03-23 10:36:14 -07:00
|
|
|
|
var matchers = new List<PathMatchSet>
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
2021-09-03 13:26:52 -07:00
|
|
|
|
new PathMatchSet(new List<PathMatch>
|
|
|
|
|
|
{
|
2023-08-26 22:51:55 -04:00
|
|
|
|
new FilePathMatch("00001.TMP"),
|
|
|
|
|
|
new FilePathMatch("00002.TMP")
|
2021-09-03 13:26:52 -07:00
|
|
|
|
}, "SmartE"),
|
2021-03-23 10:36:14 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
2021-03-23 13:35:12 -07:00
|
|
|
|
return MatchUtil.GetAllMatches(files, matchers, any: true);
|
2021-03-19 15:41:49 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
public string CheckFilePath(string path)
|
|
|
|
|
|
{
|
2021-03-23 10:36:14 -07:00
|
|
|
|
var matchers = new List<PathMatchSet>
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
2023-08-26 22:51:55 -04:00
|
|
|
|
new PathMatchSet(new FilePathMatch("00001.TMP"), "SmartE"),
|
|
|
|
|
|
new PathMatchSet(new FilePathMatch("00002.TMP"), "SmartE"),
|
2021-03-23 10:36:14 -07:00
|
|
|
|
};
|
2019-09-27 23:52:24 -07:00
|
|
|
|
|
2021-03-23 10:36:14 -07:00
|
|
|
|
return MatchUtil.GetFirstMatch(path, matchers, any: true);
|
2019-09-27 23:52:24 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|