2021-09-06 13:58:16 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
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 22:19:38 -07:00
|
|
|
|
using BurnOutSharp.Matching;
|
|
|
|
|
|
|
|
|
|
|
|
namespace BurnOutSharp.ProtectionType
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
2022-05-01 17:17:15 -07:00
|
|
|
|
public class Sysiphus : IPortableExecutableCheck
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
2021-09-06 13:58:16 -07:00
|
|
|
|
/// <inheritdoc/>
|
2022-05-01 17:17:15 -07:00
|
|
|
|
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
2021-09-06 13:58:16 -07:00
|
|
|
|
// Get the sections from the executable, if possible
|
|
|
|
|
|
var sections = pex?.SectionTable;
|
|
|
|
|
|
if (sections == null)
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
|
|
// Get the .data section, if it exists
|
2021-09-11 16:47:25 -07:00
|
|
|
|
if (pex.DataSectionRaw != null)
|
2021-03-21 22:19:38 -07:00
|
|
|
|
{
|
2021-09-06 13:58:16 -07:00
|
|
|
|
var matchers = new List<ContentMatchSet>
|
2021-07-17 23:40:16 -07:00
|
|
|
|
{
|
2021-09-06 13:58:16 -07:00
|
|
|
|
// V SUHPISYS
|
2021-09-11 16:47:25 -07:00
|
|
|
|
new ContentMatchSet(new byte?[]
|
|
|
|
|
|
{
|
|
|
|
|
|
0x56, 0x20, 0x53, 0x55, 0x48, 0x50, 0x49, 0x53,
|
|
|
|
|
|
0x59, 0x53
|
|
|
|
|
|
}, GetVersion, "Sysiphus"),
|
2021-09-06 13:58:16 -07:00
|
|
|
|
};
|
2019-09-27 23:52:24 -07:00
|
|
|
|
|
2021-09-11 16:47:25 -07:00
|
|
|
|
string match = MatchUtil.GetFirstMatch(file, pex.DataSectionRaw, matchers, includeDebug);
|
2021-09-06 13:58:16 -07:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(match))
|
|
|
|
|
|
return match;
|
|
|
|
|
|
}
|
2019-09-27 23:52:24 -07:00
|
|
|
|
|
2021-09-06 13:58:16 -07:00
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2019-09-27 23:52:24 -07:00
|
|
|
|
|
2021-03-22 11:43:51 -07:00
|
|
|
|
public static string GetVersion(string file, byte[] fileContent, List<int> positions)
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
2021-09-06 13:58:16 -07:00
|
|
|
|
// The version is reversed
|
|
|
|
|
|
string version = new string(
|
|
|
|
|
|
new ArraySegment<byte>(fileContent, positions[0] - 4, 4)
|
|
|
|
|
|
.Reverse()
|
|
|
|
|
|
.Select(b => (char)b)
|
|
|
|
|
|
.ToArray())
|
|
|
|
|
|
.Trim();
|
|
|
|
|
|
|
|
|
|
|
|
// Check for the DVD extra string
|
|
|
|
|
|
string extra = new string(
|
|
|
|
|
|
new ArraySegment<byte>(fileContent, positions[0] + "V SUHPISYS".Length, 3)
|
|
|
|
|
|
.Select(b => (char)b)
|
|
|
|
|
|
.ToArray());
|
|
|
|
|
|
bool isDVD = extra == "DVD";
|
2019-09-27 23:52:24 -07:00
|
|
|
|
|
2021-09-06 13:58:16 -07:00
|
|
|
|
if (char.IsNumber(version[0]) && char.IsNumber(version[2]))
|
|
|
|
|
|
return isDVD ? $"DVD {version}" : version;
|
2021-03-22 16:25:40 -07:00
|
|
|
|
|
2021-09-06 13:58:16 -07:00
|
|
|
|
return isDVD ? "DVD" : string.Empty;
|
2019-09-27 23:52:24 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|