Convert Sysiphus to string finding

This commit is contained in:
Matt Nadareski
2022-12-09 21:25:19 -08:00
parent 847fa7d2ad
commit ff4214877e

View File

@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using BurnOutSharp.Interfaces;
using BurnOutSharp.Matching;
using BurnOutSharp.Wrappers;
namespace BurnOutSharp.ProtectionType
@@ -17,44 +16,28 @@ namespace BurnOutSharp.ProtectionType
if (sections == null)
return null;
// Get the .data/DATA section, if it exists
var dataSectionRaw = pex.GetFirstSectionData(".data") ?? pex.GetFirstSectionData("DATA");
if (dataSectionRaw != null)
// Get the .data/DATA section strings, if they exist
List<string> strs = pex.GetFirstSectionStrings(".data") ?? pex.GetFirstSectionStrings("DATA");
if (strs != null)
{
var matchers = new List<ContentMatchSet>
{
// V SUHPISYS
new ContentMatchSet(new byte?[]
{
0x56, 0x20, 0x53, 0x55, 0x48, 0x50, 0x49, 0x53,
0x59, 0x53
}, GetVersion, "Sysiphus"),
};
string match = MatchUtil.GetFirstMatch(file, dataSectionRaw, matchers, includeDebug);
if (!string.IsNullOrWhiteSpace(match))
return match;
string str = strs.FirstOrDefault(s => s.Contains("V SUHPISYS"));
if (str != null)
return $"Sysiphus {GetVersion(str)}";
}
return null;
}
public static string GetVersion(string file, byte[] fileContent, List<int> positions)
public static string GetVersion(string matchedString)
{
// The version is reversed
string version = new string(
new ArraySegment<byte>(fileContent, positions[0] - 4, 4)
.Reverse()
.Select(b => (char)b)
.ToArray())
.Trim();
// The string is reversed
matchedString = new string(matchedString.Reverse().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";
bool isDVD = matchedString.StartsWith("DVD");
// Get the version string
string version = matchedString.Substring(isDVD ? "V SUHPISYSDVD".Length : "V SUHPISYS".Length, 4).Trim();
if (char.IsNumber(version[0]) && char.IsNumber(version[2]))
return isDVD ? $"DVD {version}" : version;