mirror of
https://github.com/SabreTools/BinaryObjectScanner.git
synced 2026-07-19 23:35:01 +00:00
Improve CD-Key matching
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using BurnOutSharp.ExecutableType.Microsoft;
|
||||
using BurnOutSharp.Matching;
|
||||
using BurnOutSharp.Tools;
|
||||
|
||||
@@ -8,31 +11,11 @@ namespace BurnOutSharp.ProtectionType
|
||||
public class CDKey : IContentCheck
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public List<ContentMatchSet> GetContentMatchSets()
|
||||
{
|
||||
return new List<ContentMatchSet>
|
||||
{
|
||||
// I + (char)0x00 + n + (char)0x00 + t + (char)0x00 + e + (char)0x00 + r + (char)0x00 + n + (char)0x00 + a + (char)0x00 + l + (char)0x00 + N + (char)0x00 + a + (char)0x00 + m + (char)0x00 + e + (char)0x00 + + (char)0x00 + + (char)0x00 + C + (char)0x00 + D + (char)0x00 + K + (char)0x00 + e + (char)0x00 + y + (char)0x00
|
||||
new ContentMatchSet(new byte?[]
|
||||
{
|
||||
0x49, 0x00, 0x6E, 0x00, 0x74, 0x00, 0x65, 0x00,
|
||||
0x72, 0x00, 0x6E, 0x00, 0x61, 0x00, 0x6C, 0x00,
|
||||
0x4E, 0x00, 0x61, 0x00, 0x6D, 0x00, 0x65, 0x00,
|
||||
0x00, 0x00, 0x43, 0x00, 0x44, 0x00, 0x4B, 0x00,
|
||||
0x65, 0x00, 0x79, 0x00
|
||||
}, Utilities.GetFileVersion, "CD-Key / Serial"),
|
||||
};
|
||||
}
|
||||
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
|
||||
@@ -46,6 +29,38 @@ namespace BurnOutSharp.ProtectionType
|
||||
if (!string.IsNullOrWhiteSpace(name) && name.Equals("CDKey", StringComparison.OrdinalIgnoreCase))
|
||||
return "CD-Key / Serial";
|
||||
|
||||
// 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>
|
||||
{
|
||||
// I + (char)0x00 + n + (char)0x00 + t + (char)0x00 + e + (char)0x00 + r + (char)0x00 + n + (char)0x00 + a + (char)0x00 + l + (char)0x00 + N + (char)0x00 + a + (char)0x00 + m + (char)0x00 + e + (char)0x00 + + (char)0x00 + + (char)0x00 + C + (char)0x00 + D + (char)0x00 + K + (char)0x00 + e + (char)0x00 + y + (char)0x00
|
||||
new ContentMatchSet(
|
||||
new ContentMatch(new byte?[]
|
||||
{
|
||||
0x49, 0x00, 0x6E, 0x00, 0x74, 0x00, 0x65, 0x00,
|
||||
0x72, 0x00, 0x6E, 0x00, 0x61, 0x00, 0x6C, 0x00,
|
||||
0x4E, 0x00, 0x61, 0x00, 0x6D, 0x00, 0x65, 0x00,
|
||||
0x00, 0x00, 0x43, 0x00, 0x44, 0x00, 0x4B, 0x00,
|
||||
0x65, 0x00, 0x79, 0x00,
|
||||
}, start: sectionAddr, end: sectionEnd),
|
||||
"CD-Key / Serial"),
|
||||
};
|
||||
|
||||
string match = MatchUtil.GetFirstMatch(file, fileContent, matchers, includeDebug);
|
||||
if (!string.IsNullOrWhiteSpace(match))
|
||||
return match;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user