2021-07-18 09:44:23 -07:00
|
|
|
|
using System.Collections.Concurrent;
|
2021-03-21 22:39:01 -06:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
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 22:45:06 -07:00
|
|
|
|
using BurnOutSharp.Matching;
|
2021-03-21 22:39:01 -06:00
|
|
|
|
|
|
|
|
|
|
namespace BurnOutSharp.PackerType
|
|
|
|
|
|
{
|
2021-03-21 22:45:06 -07:00
|
|
|
|
// The official website for CExe also includes the source code (which does have to be retrieved by the Wayback Machine)
|
|
|
|
|
|
// http://www.scottlu.com/Content/CExe.html
|
2022-05-01 21:02:59 -07:00
|
|
|
|
// TODO: Add extraction
|
2022-05-01 17:17:15 -07:00
|
|
|
|
public class CExe : IPortableExecutableCheck, IScannable
|
2021-03-21 22:39:01 -06:00
|
|
|
|
{
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
public bool ShouldScan(byte[] magic) => true;
|
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-10 15:32:37 -07:00
|
|
|
|
{
|
2021-09-11 00:32:48 -07:00
|
|
|
|
// Get the sections from the executable, if possible
|
2021-09-11 21:54:38 -07:00
|
|
|
|
var stub = pex?.DOSStubHeader;
|
|
|
|
|
|
if (stub == null)
|
2021-09-11 00:32:48 -07:00
|
|
|
|
return null;
|
|
|
|
|
|
|
2021-09-11 21:54:38 -07:00
|
|
|
|
var matchers = new List<ContentMatchSet>
|
|
|
|
|
|
{
|
|
|
|
|
|
// %Wo<57>a6.<2E>a6.<2E>a6.<2E>a6.<2E>{6.<2E>.).<2E>f6.<2E><>).<2E>`6.<2E><>0.<2E>`6.<2E>
|
|
|
|
|
|
new ContentMatchSet(new byte?[]
|
|
|
|
|
|
{
|
|
|
|
|
|
0x25, 0x57, 0x6F, 0xC1, 0x61, 0x36, 0x01, 0x92,
|
|
|
|
|
|
0x61, 0x36, 0x01, 0x92, 0x61, 0x36, 0x01, 0x92,
|
|
|
|
|
|
0x61, 0x36, 0x00, 0x92, 0x7B, 0x36, 0x01, 0x92,
|
|
|
|
|
|
0x03, 0x29, 0x12, 0x92, 0x66, 0x36, 0x01, 0x92,
|
|
|
|
|
|
0x89, 0x29, 0x0A, 0x92, 0x60, 0x36, 0x01, 0x92,
|
|
|
|
|
|
0xD9, 0x30, 0x07, 0x92, 0x60, 0x36, 0x01, 0x92
|
|
|
|
|
|
}, "CExe")
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
string match = MatchUtil.GetFirstMatch(file, pex.DOSStubHeader.ExecutableData, matchers, includeDebug);
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(match))
|
|
|
|
|
|
return match;
|
2021-09-10 15:32:37 -07:00
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2021-03-21 22:39:01 -06:00
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
2021-07-18 09:44:23 -07:00
|
|
|
|
public ConcurrentDictionary<string, ConcurrentQueue<string>> Scan(Scanner scanner, string file)
|
2021-03-21 22:39:01 -06:00
|
|
|
|
{
|
|
|
|
|
|
if (!File.Exists(file))
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
|
|
using (var fs = File.OpenRead(file))
|
|
|
|
|
|
{
|
|
|
|
|
|
return Scan(scanner, fs, file);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
2021-07-18 09:44:23 -07:00
|
|
|
|
public ConcurrentDictionary<string, ConcurrentQueue<string>> Scan(Scanner scanner, Stream stream, string file)
|
2021-03-21 22:39:01 -06:00
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|