Files
BinaryObjectScanner/BinaryObjectScanner.Protection/Sysiphus.cs

49 lines
1.6 KiB
C#
Raw Normal View History

2021-09-06 13:58:16 -07:00
using System;
using System.Collections.Generic;
using System.Linq;
using BinaryObjectScanner.Interfaces;
2023-03-07 16:59:14 -05:00
using BinaryObjectScanner.Wrappers;
2021-03-21 22:19:38 -07:00
namespace BinaryObjectScanner.Protection
{
2022-05-01 17:17:15 -07:00
public class Sysiphus : IPortableExecutableCheck
{
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)
{
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;
2022-12-09 21:25:19 -08:00
// Get the .data/DATA section strings, if they exist
List<string> strs = pex.GetFirstSectionStrings(".data") ?? pex.GetFirstSectionStrings("DATA");
if (strs != null)
2021-03-21 22:19:38 -07:00
{
2022-12-09 21:25:19 -08:00
string str = strs.FirstOrDefault(s => s.Contains("V SUHPISYS"));
if (str != null)
return $"Sysiphus {GetVersion(str)}";
2021-09-06 13:58:16 -07:00
}
2021-09-06 13:58:16 -07:00
return null;
}
2022-12-09 21:25:19 -08:00
public static string GetVersion(string matchedString)
{
2022-12-09 21:25:19 -08:00
// The string is reversed
matchedString = new string(matchedString.Reverse().ToArray()).Trim();
2021-09-06 13:58:16 -07:00
// Check for the DVD extra string
2022-12-09 21:25:19 -08:00
bool isDVD = matchedString.StartsWith("DVD");
// Get the version string
string version = matchedString.Substring(isDVD ? "V SUHPISYSDVD".Length : "V SUHPISYS".Length, 4).Trim();
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;
}
}
}