2022-05-01 21:02:59 -07:00
|
|
|
using System.Collections.Concurrent;
|
2021-03-21 15:24:23 -07:00
|
|
|
using System.Collections.Generic;
|
2022-05-01 21:02:59 -07:00
|
|
|
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 15:24:23 -07:00
|
|
|
using BurnOutSharp.Matching;
|
2020-10-30 09:56:34 -06:00
|
|
|
|
2020-10-30 09:09:16 -07:00
|
|
|
namespace BurnOutSharp.PackerType
|
2020-10-30 09:56:34 -06:00
|
|
|
{
|
2022-05-01 21:02:59 -07:00
|
|
|
// TODO: Add extraction
|
|
|
|
|
public class NSIS : IPortableExecutableCheck, IScannable
|
2020-10-30 09:56:34 -06:00
|
|
|
{
|
2022-05-01 21:02:59 -07: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-08-27 13:30:24 -07:00
|
|
|
{
|
2021-08-30 11:40:14 -07:00
|
|
|
// Get the sections from the executable, if possible
|
|
|
|
|
var sections = pex?.SectionTable;
|
|
|
|
|
if (sections == null)
|
|
|
|
|
return null;
|
|
|
|
|
|
2022-04-02 16:12:23 -07:00
|
|
|
string description = pex.ManifestDescription;
|
2021-09-10 21:45:14 -07:00
|
|
|
if (!string.IsNullOrWhiteSpace(description) && description.StartsWith("Nullsoft Install System"))
|
|
|
|
|
return $"NSIS {description.Substring("Nullsoft Install System".Length).Trim()}";
|
2021-08-30 11:40:14 -07:00
|
|
|
|
|
|
|
|
// Get the .data section, if it exists
|
2021-09-11 16:47:25 -07:00
|
|
|
if (pex.DataSectionRaw != null)
|
2021-08-30 11:40:14 -07:00
|
|
|
{
|
|
|
|
|
var matchers = new List<ContentMatchSet>
|
|
|
|
|
{
|
|
|
|
|
// NullsoftInst
|
2021-09-11 16:47:25 -07:00
|
|
|
new ContentMatchSet(new byte?[]
|
|
|
|
|
{
|
|
|
|
|
0x4E, 0x75, 0x6C, 0x6C, 0x73, 0x6F, 0x66, 0x74,
|
|
|
|
|
0x49, 0x6E, 0x73, 0x74
|
|
|
|
|
}, "NSIS"),
|
2021-08-30 11:40:14 -07:00
|
|
|
};
|
|
|
|
|
|
2021-09-11 16:47:25 -07:00
|
|
|
string match = MatchUtil.GetFirstMatch(file, pex.DataSectionRaw, matchers, includeDebug);
|
2021-08-30 11:40:14 -07:00
|
|
|
if (!string.IsNullOrWhiteSpace(match))
|
|
|
|
|
return match;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-27 13:30:24 -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;
|
|
|
|
|
}
|
2020-10-30 09:56:34 -06:00
|
|
|
}
|
|
|
|
|
}
|