2021-07-18 09:44:23 -07:00
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
|
using System.Collections.Generic;
|
2021-04-01 11:20:13 -07:00
|
|
|
|
using System.IO;
|
2022-03-14 10:40:44 -07:00
|
|
|
|
using BurnOutSharp.ExecutableType.Microsoft.PE;
|
|
|
|
|
|
using BurnOutSharp.ExecutableType.Microsoft.PE.Headers;
|
2022-05-01 17:41:50 -07:00
|
|
|
|
using BurnOutSharp.Interfaces;
|
2021-03-21 15:34:19 -07:00
|
|
|
|
using BurnOutSharp.Matching;
|
2019-09-27 23:52:24 -07:00
|
|
|
|
|
|
|
|
|
|
namespace BurnOutSharp.ProtectionType
|
|
|
|
|
|
{
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
// Get the .edata section, if it exists
|
2021-09-11 21:10:29 -07:00
|
|
|
|
string match = GetMatchForSection(file, pex.ExportDataSectionRaw, includeDebug);
|
2021-09-03 13:26:52 -07:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(match))
|
|
|
|
|
|
return match;
|
|
|
|
|
|
|
|
|
|
|
|
// Get the .idata section, if it exists
|
2021-09-11 21:10:29 -07:00
|
|
|
|
match = GetMatchForSection(file, pex.ImportDataSectionRaw, includeDebug);
|
2021-09-03 13:26:52 -07:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(match))
|
|
|
|
|
|
return match;
|
|
|
|
|
|
|
|
|
|
|
|
// Get the .rdata section, if it exists
|
2021-09-11 16:47:25 -07:00
|
|
|
|
match = GetMatchForSection(file, pex.ResourceDataSectionRaw, includeDebug);
|
2021-09-03 13:26:52 -07:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(match))
|
|
|
|
|
|
return match;
|
|
|
|
|
|
|
|
|
|
|
|
// Get the .tls section, if it exists
|
2022-03-14 23:01:06 -07:00
|
|
|
|
var tlsSectionRaw = pex.ReadRawSection(".tls", first: false);
|
2021-09-11 22:27:52 -07:00
|
|
|
|
match = GetMatchForSection(file, tlsSectionRaw, includeDebug);
|
2021-09-03 13:26:52 -07:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(match))
|
|
|
|
|
|
return match;
|
|
|
|
|
|
|
|
|
|
|
|
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>
|
|
|
|
|
|
{
|
|
|
|
|
|
new PathMatch($"{Path.DirectorySeparatorChar}00001.TMP", useEndsWith: true),
|
|
|
|
|
|
new PathMatch($"{Path.DirectorySeparatorChar}00002.TMP", useEndsWith: true)
|
|
|
|
|
|
}, "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
|
|
|
|
{
|
2021-04-01 11:20:13 -07:00
|
|
|
|
new PathMatchSet(new PathMatch($"{Path.DirectorySeparatorChar}00001.TMP", useEndsWith: true), "SmartE"),
|
|
|
|
|
|
new PathMatchSet(new PathMatch($"{Path.DirectorySeparatorChar}00002.TMP", useEndsWith: true), "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
|
|
|
|
}
|
2021-09-03 13:26:52 -07:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Check a section for the SmartE string(s)
|
|
|
|
|
|
/// </summary>
|
2022-03-08 22:30:12 -08:00
|
|
|
|
private string GetMatchForSection(SectionHeader section, string file, byte[] sectionContent, bool includeDebug)
|
2021-09-03 13:26:52 -07:00
|
|
|
|
{
|
|
|
|
|
|
if (section == null)
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
|
|
int sectionAddr = (int)section.PointerToRawData;
|
|
|
|
|
|
int sectionEnd = sectionAddr + (int)section.VirtualSize;
|
|
|
|
|
|
var matchers = new List<ContentMatchSet>
|
|
|
|
|
|
{
|
|
|
|
|
|
// BITARTS
|
|
|
|
|
|
new ContentMatchSet(
|
|
|
|
|
|
new ContentMatch(new byte?[] { 0x42, 0x49, 0x54, 0x41, 0x52, 0x54, 0x53 }, start: sectionAddr, end: sectionEnd),
|
|
|
|
|
|
"SmartE"),
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2022-03-08 22:30:12 -08:00
|
|
|
|
return MatchUtil.GetFirstMatch(file, sectionContent, matchers, includeDebug);
|
2021-09-03 13:26:52 -07:00
|
|
|
|
}
|
2021-09-11 16:47:25 -07:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Check a section for the SmartE string(s)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private string GetMatchForSection(string file, byte[] sectionContent, bool includeDebug)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (sectionContent == null)
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
|
|
var matchers = new List<ContentMatchSet>
|
|
|
|
|
|
{
|
|
|
|
|
|
// BITARTS
|
|
|
|
|
|
new ContentMatchSet(new byte?[] { 0x42, 0x49, 0x54, 0x41, 0x52, 0x54, 0x53 }, "SmartE"),
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return MatchUtil.GetFirstMatch(file, sectionContent, matchers, includeDebug);
|
|
|
|
|
|
}
|
2019-09-27 23:52:24 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|