2022-05-01 21:02:59 -07:00
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
2021-08-26 20:38:01 -07:00
|
|
|
|
using System.Linq;
|
2022-03-14 10:40:44 -07:00
|
|
|
|
using BurnOutSharp.ExecutableType.Microsoft.PE;
|
2022-05-01 17:41:50 -07:00
|
|
|
|
using BurnOutSharp.Interfaces;
|
2021-03-21 15:24:23 -07:00
|
|
|
|
using BurnOutSharp.Matching;
|
2021-03-21 14:30:37 -07:00
|
|
|
|
|
|
|
|
|
|
namespace BurnOutSharp.PackerType
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
2022-05-01 21:02:59 -07:00
|
|
|
|
// TODO: Add extraction
|
2021-08-26 21:47:44 -07:00
|
|
|
|
// TODO: Add version checking, if possible
|
2022-05-01 21:02:59 -07:00
|
|
|
|
public class Armadillo : IPortableExecutableCheck, IScannable
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
2022-05-01 21:02:59 -07:00
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
public bool ShouldScan(byte[] magic) => true;
|
|
|
|
|
|
|
2021-03-23 09:52:09 -07:00
|
|
|
|
/// <inheritdoc/>
|
2022-05-01 17:17:15 -07:00
|
|
|
|
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
|
2021-08-26 20:38:01 -07:00
|
|
|
|
{
|
|
|
|
|
|
// Get the sections from the executable, if possible
|
2021-08-27 09:42:05 -07:00
|
|
|
|
var sections = pex?.SectionTable;
|
2021-08-26 20:38:01 -07:00
|
|
|
|
if (sections == null)
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
2021-09-11 00:32:48 -07:00
|
|
|
|
// Get the .nicode section, if it exists
|
2021-09-11 21:03:36 -07:00
|
|
|
|
bool nicodeSection = pex.ContainsSection(".nicode", exact: true);
|
|
|
|
|
|
if (nicodeSection)
|
2021-08-26 20:38:01 -07:00
|
|
|
|
return "Armadillo";
|
|
|
|
|
|
|
2021-09-11 22:27:52 -07:00
|
|
|
|
// Loop through all "extension" sections -- usually .data1 or .text1
|
2022-03-14 23:28:31 -07:00
|
|
|
|
foreach (var section in sections.Where(s => s != null && s.NameString.EndsWith("1")))
|
2021-08-26 20:38:01 -07:00
|
|
|
|
{
|
2022-03-14 23:28:31 -07:00
|
|
|
|
var sectionRaw = pex.ReadRawSection(section.NameString);
|
|
|
|
|
|
if (sectionRaw != null)
|
2021-08-26 20:38:01 -07:00
|
|
|
|
{
|
2022-03-14 23:28:31 -07:00
|
|
|
|
var matchers = new List<ContentMatchSet>
|
|
|
|
|
|
{
|
|
|
|
|
|
// ARMDEBUG
|
|
|
|
|
|
new ContentMatchSet(new byte?[] { 0x41, 0x52, 0x4D, 0x44, 0x45, 0x42, 0x55, 0x47 }, $"Armadillo"),
|
|
|
|
|
|
};
|
2021-08-26 20:38:01 -07:00
|
|
|
|
|
2022-03-14 23:28:31 -07:00
|
|
|
|
string match = MatchUtil.GetFirstMatch(file, sectionRaw, matchers, includeDebug);
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(match))
|
|
|
|
|
|
return match;
|
|
|
|
|
|
}
|
2021-08-26 20:38:01 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2022-05-01 21:02:59 -07:00
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
public ConcurrentDictionary<string, ConcurrentQueue<string>> Scan(Scanner scanner, string file)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!File.Exists(file))
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
|
|
using (var fs = File.OpenRead(file))
|
|
|
|
|
|
{
|
|
|
|
|
|
return Scan(scanner, fs, file);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
public ConcurrentDictionary<string, ConcurrentQueue<string>> Scan(Scanner scanner, Stream stream, string file)
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2019-09-27 23:52:24 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|