mirror of
https://github.com/SabreTools/BinaryObjectScanner.git
synced 2026-07-09 18:36:43 +00:00
Improve Setup Factory matching
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using BurnOutSharp.ExecutableType.Microsoft;
|
||||
using BurnOutSharp.Matching;
|
||||
using BurnOutSharp.Tools;
|
||||
|
||||
@@ -13,50 +16,11 @@ namespace BurnOutSharp.PackerType
|
||||
public bool ShouldScan(byte[] magic) => true;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public List<ContentMatchSet> GetContentMatchSets()
|
||||
{
|
||||
return new List<ContentMatchSet>
|
||||
{
|
||||
// S.e.t.u.p. .F.a.c.t.o.r.y.
|
||||
new ContentMatchSet(new byte?[]
|
||||
{
|
||||
0x53, 0x00, 0x65, 0x00, 0x74, 0x00, 0x75, 0x00,
|
||||
0x70, 0x00, 0x20, 0x00, 0x46, 0x00, 0x61, 0x00,
|
||||
0x63, 0x00, 0x74, 0x00, 0x6F, 0x00, 0x72, 0x00,
|
||||
0x79, 0x00
|
||||
}, GetVersion, "Setup Factory"),
|
||||
|
||||
// Longer version of the check that can be used if false positves become an issue:
|
||||
// S.e.t.u.p. .F.a.c.t.o.r.y. .i.s. .a. .t.r.a.d.e.m.a.r.k. .o.f. .I.n.d.i.g.o. .R.o.s.e. .C.o.r.p.o.r.a.t.i.o.n.
|
||||
// new ContentMatchSet(new byte?[]
|
||||
// {
|
||||
// 0x53, 0x00, 0x65, 0x00, 0x74, 0x00, 0x75, 0x00,
|
||||
// 0x70, 0x00, 0x20, 0x00, 0x46, 0x00, 0x61, 0x00,
|
||||
// 0x63, 0x00, 0x74, 0x00, 0x6F, 0x00, 0x72, 0x00,
|
||||
// 0x79, 0x00, 0x20, 0x00, 0x69, 0x00, 0x73, 0x00,
|
||||
// 0x20, 0x00, 0x61, 0x00, 0x20, 0x00, 0x74, 0x00,
|
||||
// 0x72, 0x00, 0x61, 0x00, 0x64, 0x00, 0x65, 0x00,
|
||||
// 0x6D, 0x00, 0x61, 0x00, 0x72, 0x00, 0x6B, 0x00,
|
||||
// 0x20, 0x00, 0x6F, 0x00, 0x66, 0x00, 0x20, 0x00,
|
||||
// 0x49, 0x00, 0x6E, 0x00, 0x64, 0x00, 0x69, 0x00,
|
||||
// 0x67, 0x00, 0x6F, 0x00, 0x20, 0x00, 0x52, 0x00,
|
||||
// 0x6F, 0x00, 0x73, 0x00, 0x65, 0x00, 0x20, 0x00,
|
||||
// 0x43, 0x00, 0x6F, 0x00, 0x72, 0x00, 0x70, 0x00,
|
||||
// 0x6F, 0x00, 0x72, 0x00, 0x61, 0x00, 0x74, 0x00,
|
||||
// 0x69, 0x00, 0x6F, 0x00, 0x6E, 0x00
|
||||
// }, GetVersion, "Setup Factory"),
|
||||
};
|
||||
}
|
||||
public List<ContentMatchSet> GetContentMatchSets() => null;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string CheckContents(string file, byte[] fileContent, bool includeDebug = false)
|
||||
{
|
||||
// Get the sections from the executable, if possible
|
||||
// PortableExecutable pex = PortableExecutable.Deserialize(fileContent, 0);
|
||||
// var sections = pex?.SectionTable;
|
||||
// if (sections == null)
|
||||
// return null;
|
||||
|
||||
// TODO: Implement resource finding instead of using the built in methods
|
||||
// Assembly information lives in the .rsrc section
|
||||
// I need to find out how to navigate the resources in general
|
||||
@@ -74,6 +38,59 @@ namespace BurnOutSharp.PackerType
|
||||
if (!string.IsNullOrWhiteSpace(name) && name.StartsWith("Setup Factory", StringComparison.OrdinalIgnoreCase))
|
||||
return $"Setup Factory {GetVersion(file, fileContent, null)}";
|
||||
|
||||
// Get the sections from the executable, if possible
|
||||
PortableExecutable pex = PortableExecutable.Deserialize(fileContent, 0);
|
||||
var sections = pex?.SectionTable;
|
||||
if (sections == null)
|
||||
return null;
|
||||
|
||||
// Get the .rsrc section, if it exists
|
||||
var rsrcSection = sections.FirstOrDefault(s => Encoding.ASCII.GetString(s.Name).StartsWith(".rsrc"));
|
||||
if (rsrcSection != null)
|
||||
{
|
||||
int sectionAddr = (int)rsrcSection.PointerToRawData;
|
||||
int sectionEnd = sectionAddr + (int)rsrcSection.VirtualSize;
|
||||
var matchers = new List<ContentMatchSet>
|
||||
{
|
||||
// S + (char)0x00 + e + (char)0x00 + t + (char)0x00 + u + (char)0x00 + p + (char)0x00 + + (char)0x00 + F + (char)0x00 + a + (char)0x00 + c + (char)0x00 + t + (char)0x00 + o + (char)0x00 + r + (char)0x00 + y + (char)0x00
|
||||
new ContentMatchSet(
|
||||
new ContentMatch(new byte?[]
|
||||
{
|
||||
0x53, 0x00, 0x65, 0x00, 0x74, 0x00, 0x75, 0x00,
|
||||
0x70, 0x00, 0x20, 0x00, 0x46, 0x00, 0x61, 0x00,
|
||||
0x63, 0x00, 0x74, 0x00, 0x6F, 0x00, 0x72, 0x00,
|
||||
0x79, 0x00
|
||||
}, start: sectionAddr, end: sectionEnd),
|
||||
GetVersion, "Setup Factory"),
|
||||
|
||||
// Longer version of the check that can be used if false positves become an issue:
|
||||
// S + (char)0x00 + e + (char)0x00 + t + (char)0x00 + u + (char)0x00 + p + (char)0x00 + + (char)0x00 + F + (char)0x00 + a + (char)0x00 + c + (char)0x00 + t + (char)0x00 + o + (char)0x00 + r + (char)0x00 + y + (char)0x00 + + (char)0x00 + i + (char)0x00 + s + (char)0x00 + + (char)0x00 + a + (char)0x00 + + (char)0x00 + t + (char)0x00 + r + (char)0x00 + a + (char)0x00 + d + (char)0x00 + e + (char)0x00 + m + (char)0x00 + a + (char)0x00 + r + (char)0x00 + k + (char)0x00 + + (char)0x00 + o + (char)0x00 + f + (char)0x00 + + (char)0x00 + I + (char)0x00 + n + (char)0x00 + d + (char)0x00 + i + (char)0x00 + g + (char)0x00 + o + (char)0x00 + + (char)0x00 + R + (char)0x00 + o + (char)0x00 + s + (char)0x00 + e + (char)0x00 + + (char)0x00 + C + (char)0x00 + o + (char)0x00 + r + (char)0x00 + p + (char)0x00 + o + (char)0x00 + r + (char)0x00 + a + (char)0x00 + t + (char)0x00 + i + (char)0x00 + o + (char)0x00 + n + (char)0x00
|
||||
// new ContentMatchSet(
|
||||
// new ContentMatch(new byte?[]
|
||||
// {
|
||||
// 0x53, 0x00, 0x65, 0x00, 0x74, 0x00, 0x75, 0x00,
|
||||
// 0x70, 0x00, 0x20, 0x00, 0x46, 0x00, 0x61, 0x00,
|
||||
// 0x63, 0x00, 0x74, 0x00, 0x6F, 0x00, 0x72, 0x00,
|
||||
// 0x79, 0x00, 0x20, 0x00, 0x69, 0x00, 0x73, 0x00,
|
||||
// 0x20, 0x00, 0x61, 0x00, 0x20, 0x00, 0x74, 0x00,
|
||||
// 0x72, 0x00, 0x61, 0x00, 0x64, 0x00, 0x65, 0x00,
|
||||
// 0x6D, 0x00, 0x61, 0x00, 0x72, 0x00, 0x6B, 0x00,
|
||||
// 0x20, 0x00, 0x6F, 0x00, 0x66, 0x00, 0x20, 0x00,
|
||||
// 0x49, 0x00, 0x6E, 0x00, 0x64, 0x00, 0x69, 0x00,
|
||||
// 0x67, 0x00, 0x6F, 0x00, 0x20, 0x00, 0x52, 0x00,
|
||||
// 0x6F, 0x00, 0x73, 0x00, 0x65, 0x00, 0x20, 0x00,
|
||||
// 0x43, 0x00, 0x6F, 0x00, 0x72, 0x00, 0x70, 0x00,
|
||||
// 0x6F, 0x00, 0x72, 0x00, 0x61, 0x00, 0x74, 0x00,
|
||||
// 0x69, 0x00, 0x6F, 0x00, 0x6E, 0x00
|
||||
// }, start: sectionAddr, end: sectionEnd),
|
||||
// GetVersion, "Setup Factory"),
|
||||
};
|
||||
|
||||
string match = MatchUtil.GetFirstMatch(file, fileContent, matchers, includeDebug);
|
||||
if (!string.IsNullOrWhiteSpace(match))
|
||||
return match;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user