Use content matching helper, part 1

This commit is contained in:
Matt Nadareski
2021-03-21 14:30:37 -07:00
parent 7c53eaab13
commit ab07eb96ce
35 changed files with 270 additions and 216 deletions

View File

@@ -1,21 +1,22 @@
namespace BurnOutSharp.PackerType
using System.Collections.Generic;
namespace BurnOutSharp.PackerType
{
public class Armadillo : IContentCheck
{
/// <inheritdoc/>
public string CheckContents(string file, byte[] fileContent, bool includePosition = false)
{
// ".nicode" + (char)0x00
byte?[] check = new byte?[] { 0x2E, 0x6E, 0x69, 0x63, 0x6F, 0x64, 0x65, 0x00 };
if (fileContent.FirstPosition(check, out int position))
return $"Armadillo" + (includePosition ? $" (Index {position})" : string.Empty);
var mappings = new Dictionary<byte?[], string>
{
// .nicode + (char)0x00
[new byte?[] { 0x2E, 0x6E, 0x69, 0x63, 0x6F, 0x64, 0x65, 0x00 }] = "Armadillo",
// "ARMDEBUG"
check = new byte?[] { 0x41, 0x52, 0x4D, 0x44, 0x45, 0x42, 0x55, 0x47 };
if (fileContent.FirstPosition(check, out position))
return $"Armadillo" + (includePosition ? $" (Index {position})" : string.Empty);
// ARMDEBUG
[new byte?[] { 0x41, 0x52, 0x4D, 0x44, 0x45, 0x42, 0x55, 0x47 }] = "Armadillo",
};
return null;
return Utilities.GetContentMatches(fileContent, mappings, includePosition);
}
}
}

View File

@@ -1,16 +1,19 @@
namespace BurnOutSharp.PackerType
using System.Collections.Generic;
namespace BurnOutSharp.PackerType
{
public class EXEStealth : IContentCheck
{
/// <inheritdoc/>
public string CheckContents(string file, byte[] fileContent, bool includePosition = false)
{
// "??[[__[[_" + (char)0x00 + "{{" + (char)0x0 + (char)0x00 + "{{" + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x0 + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x00 + "?;??;??"
byte?[] check = new byte?[] { 0x3F, 0x3F, 0x5B, 0x5B, 0x5F, 0x5F, 0x5B, 0x5B, 0x5F, 0x00, 0x7B, 0x7B, 0x00, 0x00, 0x7B, 0x7B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x3F, 0x3B, 0x3F, 0x3F, 0x3B, 0x3F, 0x3F };
if (fileContent.FirstPosition(check, out int position))
return $"EXE Stealth" + (includePosition ? $" (Index {position})" : string.Empty);
var mappings = new Dictionary<byte?[], string>
{
// ??[[__[[_ + (char)0x00 + {{ + (char)0x0 + (char)0x00 + {{ + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x0 + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x00 + ?;??;??
[new byte?[] { 0x3F, 0x3F, 0x5B, 0x5B, 0x5F, 0x5F, 0x5B, 0x5B, 0x5F, 0x00, 0x7B, 0x7B, 0x00, 0x00, 0x7B, 0x7B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x3F, 0x3B, 0x3F, 0x3F, 0x3B, 0x3F, 0x3F }] = "EXE Stealth",
};
return null;
return Utilities.GetContentMatches(fileContent, mappings, includePosition);
}
}
}

View File

@@ -14,7 +14,7 @@ namespace BurnOutSharp.PackerType
/// <inheritdoc/>
public string CheckContents(string file, byte[] fileContent, bool includePosition = false)
{
// "Inno"
// Inno
byte?[] check = new byte?[] { 0x49, 0x6E, 0x6E, 0x6F };
if (fileContent.FirstPosition(check, out int position) && position == 0x30)
return $"Inno Setup {GetVersion(fileContent)}" + (includePosition ? $" (Index {position})" : string.Empty);

View File

@@ -20,9 +20,7 @@ namespace BurnOutSharp.PackerType
// NullsoftInst
check = new byte?[] { 0x4e, 0x75, 0x6c, 0x6c, 0x73, 0x6f, 0x66, 0x74, 0x49, 0x6e, 0x73, 0x74 };
if (fileContent.FirstPosition(check, out position))
{
return $"NSIS" + (includePosition ? $" (Index {position})" : string.Empty);
}
return null;
}

View File

@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
namespace BurnOutSharp.PackerType
{

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using SharpCompress.Archives;
using SharpCompress.Archives.Rar;
@@ -15,12 +14,13 @@ namespace BurnOutSharp.PackerType
/// <inheritdoc/>
public string CheckContents(string file, byte[] fileContent, bool includePosition = false)
{
// "Software\WinRAR SFX"
byte?[] check = new byte?[] { 0x53, 0x6F, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, 0x5C, 0x57, 0x69, 0x6E, 0x52, 0x41, 0x52, 0x20, 0x53, 0x46, 0x58 };
if (fileContent.FirstPosition(check, out int position))
return "WinRAR SFX" + (includePosition ? $" (Index {position})" : string.Empty);
var mappings = new Dictionary<byte?[], string>
{
// Software\WinRAR SFX
[new byte?[] { 0x53, 0x6F, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, 0x5C, 0x57, 0x69, 0x6E, 0x52, 0x41, 0x52, 0x20, 0x53, 0x46, 0x58 }] = "WinRAR SFX",
};
return null;
return Utilities.GetContentMatches(fileContent, mappings, includePosition);
}
public Dictionary<string, List<string>> Scan(Scanner scanner, string file)

View File

@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
using SharpCompress.Archives;
using SharpCompress.Archives.Zip;

View File

@@ -13,12 +13,13 @@ namespace BurnOutSharp.PackerType
/// <inheritdoc/>
public string CheckContents(string file, byte[] fileContent, bool includePosition = false)
{
// WiseMain
byte?[] check = new byte?[] { 0x57, 0x69, 0x73, 0x65, 0x4D, 0x61, 0x69, 0x6E };
if (fileContent.FirstPosition(check, out int position))
return "Wise Installation Wizard Module" + (includePosition ? $" (Index {position})" : string.Empty);
var mappings = new Dictionary<byte?[], string>
{
// WiseMain
[new byte?[] { 0x57, 0x69, 0x73, 0x65, 0x4D, 0x61, 0x69, 0x6E }] = "Wise Installation Wizard Module",
};
return null;
return Utilities.GetContentMatches(fileContent, mappings, includePosition);
}
/// <inheritdoc/>

View File

@@ -1,16 +1,19 @@
namespace BurnOutSharp.PackerType
using System.Collections.Generic;
namespace BurnOutSharp.PackerType
{
public class dotFuscator : IContentCheck
{
/// <inheritdoc/>
public string CheckContents(string file, byte[] fileContent, bool includePosition = false)
{
// "DotfuscatorAttribute"
byte?[] check = new byte?[] { 0x44, 0x6F, 0x74, 0x66, 0x75, 0x73, 0x63, 0x61, 0x74, 0x6F, 0x72, 0x41, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65 };
if (fileContent.FirstPosition(check, out int position))
return "dotFuscator" + (includePosition ? $" (Index {position})" : string.Empty);
var mappings = new Dictionary<byte?[], string>
{
// DotfuscatorAttribute
[new byte?[] { 0x44, 0x6F, 0x74, 0x66, 0x75, 0x73, 0x63, 0x61, 0x74, 0x6F, 0x72, 0x41, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65 }] = "dotFuscator",
};
return null;
return Utilities.GetContentMatches(fileContent, mappings, includePosition);
}
}
}

View File

@@ -55,6 +55,7 @@ namespace BurnOutSharp.ProtectionType
{
if (!File.Exists(path))
return null;
try
{
using (var fs = File.OpenRead(path))

View File

@@ -1,21 +1,22 @@
namespace BurnOutSharp.ProtectionType
using System.Collections.Generic;
namespace BurnOutSharp.ProtectionType
{
public class ActiveMARK : IContentCheck
{
/// <inheritdoc/>
public string CheckContents(string file, byte[] fileContent, bool includePosition = false)
{
// "TMSAMVOF"
byte?[] check = new byte?[] { 0x54, 0x4D, 0x53, 0x41, 0x4D, 0x56, 0x4F, 0x46 };
if (fileContent.FirstPosition(check, out int position))
return "ActiveMARK" + (includePosition ? $" (Index {position})" : string.Empty);
var mappings = new Dictionary<byte?[], string>
{
// TMSAMVOF
[new byte?[] { 0x54, 0x4D, 0x53, 0x41, 0x4D, 0x56, 0x4F, 0x46 }] = "ActiveMARK",
// " " + (char)0xC2 + (char)0x16 + (char)0x00 + (char)0xA8 + (char)0xC1 + (char)0x16 + (char)0x00 + (char)0xB8 + (char)0xC1 + (char)0x16 + (char)0x00 + (char)0x86 + (char)0xC8 + (char)0x16 + (char)0x0 + (char)0x9A + (char)0xC1 + (char)0x16 + (char)0x00 + (char)0x10 + (char)0xC2 + (char)0x16 + (char)0x00
check = new byte?[] { 0x20, 0xC2, 0x16, 0x00, 0xA8, 0xC1, 0x16, 0x00, 0xB8, 0xC1, 0x16, 0x00, 0x86, 0xC8, 0x16, 0x0, 0x9A, 0xC1, 0x16, 0x00, 0x10, 0xC2, 0x16, 0x00 };
if (fileContent.FirstPosition(check, out position))
return "ActiveMARK 5" + (includePosition ? $" (Index {position})" : string.Empty);
// " " + (char)0xC2 + (char)0x16 + (char)0x00 + (char)0xA8 + (char)0xC1 + (char)0x16 + (char)0x00 + (char)0xB8 + (char)0xC1 + (char)0x16 + (char)0x00 + (char)0x86 + (char)0xC8 + (char)0x16 + (char)0x0 + (char)0x9A + (char)0xC1 + (char)0x16 + (char)0x00 + (char)0x10 + (char)0xC2 + (char)0x16 + (char)0x00
[new byte?[] { 0x20, 0xC2, 0x16, 0x00, 0xA8, 0xC1, 0x16, 0x00, 0xB8, 0xC1, 0x16, 0x00, 0x86, 0xC8, 0x16, 0x0, 0x9A, 0xC1, 0x16, 0x00, 0x10, 0xC2, 0x16, 0x00 }] = "ActiveMARK 5",
};
return null;
return Utilities.GetContentMatches(fileContent, mappings, includePosition);
}
}
}

View File

@@ -1,16 +1,19 @@
namespace BurnOutSharp.ProtectionType
using System.Collections.Generic;
namespace BurnOutSharp.ProtectionType
{
public class AlphaROM : IContentCheck
{
/// <inheritdoc/>
public string CheckContents(string file, byte[] fileContent, bool includePosition = false)
{
// "SETTEC"
byte?[] check = new byte?[] { 0x53, 0x45, 0x54, 0x54, 0x45, 0x43 };
if (fileContent.FirstPosition(check, out int position))
return "Alpha-ROM" + (includePosition ? $" (Index {position})" : string.Empty);
var mappings = new Dictionary<byte?[], string>
{
// SETTEC
[new byte?[] { 0x53, 0x45, 0x54, 0x54, 0x45, 0x43 }] = "Alpha-ROM",
};
return null;
return Utilities.GetContentMatches(fileContent, mappings, includePosition);
}
}
}

View File

@@ -1,37 +1,37 @@
namespace BurnOutSharp.ProtectionType
using System.Collections.Generic;
namespace BurnOutSharp.ProtectionType
{
public class CDCheck : IContentCheck
{
/// <inheritdoc/>
public string CheckContents(string file, byte[] fileContent, bool includePosition = false)
{
// MGS CDCheck
byte?[] check = new byte?[] { 0x4D, 0x47, 0x53, 0x20, 0x43, 0x44, 0x43, 0x68, 0x65, 0x63, 0x6B };
if (fileContent.FirstPosition(check, out int position))
return "Microsoft Game Studios CD Check" + (includePosition ? $" (Index {position})" : string.Empty);
// CDCheck
check = new byte?[] { 0x43, 0x44, 0x43, 0x68, 0x65, 0x63, 0x6B };
if (fileContent.FirstPosition(check, out position))
return "Executable-Based CD Check" + (includePosition ? $" (Index {position})" : string.Empty);
var mappings = new Dictionary<byte?[], string>
{
// MGS CDCheck
[new byte?[] { 0x4D, 0x47, 0x53, 0x20, 0x43, 0x44, 0x43, 0x68, 0x65, 0x63, 0x6B }] = "Microsoft Game Studios CD Check",
return null;
// CDCheck
[new byte?[] { 0x43, 0x44, 0x43, 0x68, 0x65, 0x63, 0x6B }] = "Executable-Based CD Check",
};
return Utilities.GetContentMatches(fileContent, mappings, includePosition);
}
// These content checks are too broad to be useful
private static string CheckContentsBroad(byte[] fileContent, bool includePosition = false)
{
// GetDriveType
byte?[] check = new byte?[] { 0x47, 0x65, 0x74, 0x44, 0x72, 0x69, 0x76, 0x65, 0x54, 0x79, 0x70, 0x65 };
if (fileContent.FirstPosition(check, out int position))
return "CD Check" + (includePosition ? $" (Index {position})" : string.Empty);
var mappings = new Dictionary<byte?[], string>
{
// GetDriveType
[new byte?[] { 0x47, 0x65, 0x74, 0x44, 0x72, 0x69, 0x76, 0x65, 0x54, 0x79, 0x70, 0x65 }] = "Executable-Based CD Check",
// GetVolumeInformation
check = new byte?[] { 0x47, 0x65, 0x74, 0x56, 0x6F, 0x6C, 0x75, 0x6D, 0x65, 0x49, 0x6E, 0x66, 0x6F, 0x72, 0x6D, 0x61, 0x74, 0x69, 0x6F, 0x6E };
if (fileContent.FirstPosition(check, out position))
return "CD Check" + (includePosition ? $" (Index {position})" : string.Empty);
// GetVolumeInformation
[new byte?[] { 0x47, 0x65, 0x74, 0x56, 0x6F, 0x6C, 0x75, 0x6D, 0x65, 0x49, 0x6E, 0x66, 0x6F, 0x72, 0x6D, 0x61, 0x74, 0x69, 0x6F, 0x6E }] = "Executable-Based CD Check",
};
return null;
return Utilities.GetContentMatches(fileContent, mappings, includePosition);
}
}
}

View File

@@ -10,12 +10,12 @@ namespace BurnOutSharp.ProtectionType
/// <inheritdoc/>
public string CheckContents(string file, byte[] fileContent, bool includePosition = false)
{
// "CD-Cops, ver. "
// CD-Cops, ver.
byte?[] check = new byte?[] { 0x43, 0x44, 0x2D, 0x43, 0x6F, 0x70, 0x73, 0x2C, 0x20, 0x20, 0x76, 0x65, 0x72, 0x2E, 0x20 };
if (fileContent.FirstPosition(check, out int position))
return $"CD-Cops {GetVersion(fileContent, position)}" + (includePosition ? $" (Index {position})" : string.Empty);
// ".grand" + (char)0x00
// .grand + (char)0x00
check = new byte?[] { 0x2E, 0x67, 0x72, 0x61, 0x6E, 0x64, 0x00};
if (fileContent.FirstPosition(check, out position))
return "CD-Cops" + (includePosition ? $" (Index {position})" : string.Empty);

View File

@@ -10,12 +10,13 @@ namespace BurnOutSharp.ProtectionType
/// <inheritdoc/>
public string CheckContents(string file, byte[] fileContent, bool includePosition = false)
{
// "2" + (char)0xF2 + (char)0x02 + (char)0x82 + (char)0xC3 + (char)0xBC + (char)0x0B + "$" + (char)0x99 + (char)0xAD + "'C" + (char)0xE4 + (char)0x9D + "st" + (char)0x99 + (char)0xFA + "2$" + (char)0x9D + ")4" + (char)0xFF + "t"
byte?[] check = new byte?[] { 0x32, 0xF2, 0x02, 0x82, 0xC3, 0xBC, 0x0B, 0x24, 0x99, 0xAD, 0x27, 0x43, 0xE4, 0x9D, 0x73, 0x74, 0x99, 0xFA, 0x32, 0x24, 0x9D, 0x29, 0x34, 0xFF, 0x74 };
if (fileContent.FirstPosition(check, out int position))
return "CD-Lock" + (includePosition ? $" (Index {position})" : string.Empty);
var mappings = new Dictionary<byte?[], string>
{
// 2 + (char)0xF2 + (char)0x02 + (char)0x82 + (char)0xC3 + (char)0xBC + (char)0x0B + $ + (char)0x99 + (char)0xAD + 'C + (char)0xE4 + (char)0x9D + st + (char)0x99 + (char)0xFA + 2$ + (char)0x9D + )4 + (char)0xFF + t
[new byte?[] { 0x32, 0xF2, 0x02, 0x82, 0xC3, 0xBC, 0x0B, 0x24, 0x99, 0xAD, 0x27, 0x43, 0xE4, 0x9D, 0x73, 0x74, 0x99, 0xFA, 0x32, 0x24, 0x9D, 0x29, 0x34, 0xFF, 0x74 }] = "CD-Lock",
};
return null;
return Utilities.GetContentMatches(fileContent, mappings, includePosition);
}
/// <inheritdoc/>

View File

@@ -1,16 +1,19 @@
namespace BurnOutSharp.ProtectionType
using System.Collections.Generic;
namespace BurnOutSharp.ProtectionType
{
public class CDSHiELDSE : IContentCheck
{
/// <inheritdoc/>
public string CheckContents(string file, byte[] fileContent, bool includePosition = false)
{
// "~0017.tmp"
byte?[] check = new byte?[] { 0x7E, 0x30, 0x30, 0x31, 0x37, 0x2E, 0x74, 0x6D, 0x70 };
if (fileContent.FirstPosition(check, out int position))
return "CDSHiELD SE" + (includePosition ? $" (Index {position})" : string.Empty);
var mappings = new Dictionary<byte?[], string>
{
// ~0017.tmp
[new byte?[] { 0x7E, 0x30, 0x30, 0x31, 0x37, 0x2E, 0x74, 0x6D, 0x70 }] = "CDSHiELD SE",
};
return null;
return Utilities.GetContentMatches(fileContent, mappings, includePosition);
}
}
}

View File

@@ -11,22 +11,19 @@ namespace BurnOutSharp.ProtectionType
/// <inheritdoc/>
public string CheckContents(string file, byte[] fileContent, bool includePosition = false)
{
// DATA.CDS
byte?[] check = new byte?[] { 0x44, 0x41, 0x54, 0x41, 0x2E, 0x43, 0x44, 0x53 };
if (fileContent.FirstPosition(check, out int position))
return "Cactus Data Shield 200" + (includePosition ? $" (Index {position})" : string.Empty);
var mappings = new Dictionary<byte?[], string>
{
// DATA.CDS
[new byte?[] { 0x44, 0x41, 0x54, 0x41, 0x2E, 0x43, 0x44, 0x53 }] = "Cactus Data Shield 200",
// \*.CDS
check = new byte?[] { 0x5C, 0x2A, 0x2E, 0x43, 0x44, 0x53 };
if (fileContent.FirstPosition(check, out position))
return "Cactus Data Shield 200" + (includePosition ? $" (Index {position})" : string.Empty);
// \*.CDS
[new byte?[] { 0x5C, 0x2A, 0x2E, 0x43, 0x44, 0x53 }] = "Cactus Data Shield 200",
// CDSPlayer
check = new byte?[] { 0x43, 0x44, 0x53, 0x50, 0x6C, 0x61, 0x79, 0x65, 0x72 };
if (fileContent.FirstPosition(check, out position))
return "Cactus Data Shield 200" + (includePosition ? $" (Index {position})" : string.Empty);
// CDSPlayer
[new byte?[] { 0x43, 0x44, 0x53, 0x50, 0x6C, 0x61, 0x79, 0x65, 0x72 }] = "Cactus Data Shield 200",
};
return null;
return Utilities.GetContentMatches(fileContent, mappings, includePosition);
}
/// <inheritdoc/>

View File

@@ -1,16 +1,19 @@
namespace BurnOutSharp.ProtectionType
using System.Collections.Generic;
namespace BurnOutSharp.ProtectionType
{
public class CengaProtectDVD : IContentCheck
{
/// <inheritdoc/>
public string CheckContents(string file, byte[] fileContent, bool includePosition = false)
{
// ".cenega"
byte?[] check = new byte?[] { 0x2E, 0x63, 0x65, 0x6E, 0x65, 0x67, 0x61 };
if (fileContent.FirstPosition(check, out int position))
return "Cenega ProtectDVD" + (includePosition ? $" (Index {position})" : string.Empty);
var mappings = new Dictionary<byte?[], string>
{
// .cenega
[new byte?[] { 0x2E, 0x63, 0x65, 0x6E, 0x65, 0x67, 0x61 }] = "Cenega ProtectDVD",
};
return null;
return Utilities.GetContentMatches(fileContent, mappings, includePosition);
}
}
}

View File

@@ -1,4 +1,6 @@
namespace BurnOutSharp.ProtectionType
using System.Collections.Generic;
namespace BurnOutSharp.ProtectionType
{
public class CodeLock : IContentCheck
{
@@ -6,22 +8,19 @@
/// <inheritdoc/>
public string CheckContents(string file, byte[] fileContent, bool includePosition = false)
{
// "icd1" + (char)0x00
byte?[] check = new byte?[] { 0x69, 0x63, 0x64, 0x31, 0x00 };
if (fileContent.FirstPosition(check, out int position))
return "Code Lock" + (includePosition ? $" (Index {position})" : string.Empty);
var mappings = new Dictionary<byte?[], string>
{
// icd1 + (char)0x00
[new byte?[] { 0x69, 0x63, 0x64, 0x31, 0x00 }] = "Code Lock",
// "icd2" + (char)0x00
check = new byte?[] { 0x69, 0x63, 0x64, 0x32, 0x00 };
if (fileContent.FirstPosition(check, out position))
return "Code Lock" + (includePosition ? $" (Index {position})" : string.Empty);
// icd2 + (char)0x00
[new byte?[] { 0x69, 0x63, 0x64, 0x32, 0x00 }] = "Code Lock",
// "CODE-LOCK.OCX"
check = new byte?[] { 0x43, 0x4F, 0x44, 0x45, 0x2D, 0x4C, 0x4F, 0x43, 0x4B, 0x2E, 0x4F, 0x43, 0x58 };
if (fileContent.FirstPosition(check, out position))
return "Code Lock" + (includePosition ? $" (Index {position})" : string.Empty);
// CODE-LOCK.OCX
[new byte?[] { 0x43, 0x4F, 0x44, 0x45, 0x2D, 0x4C, 0x4F, 0x43, 0x4B, 0x2E, 0x4F, 0x43, 0x58 }] = "Code Lock",
};
return null;
return Utilities.GetContentMatches(fileContent, mappings, includePosition);
}
}
}

View File

@@ -10,12 +10,13 @@ namespace BurnOutSharp.ProtectionType
/// <inheritdoc/>
public string CheckContents(string file, byte[] fileContent, bool includePosition = false)
{
// "Tom Commander"
byte?[] check = new byte?[] { 0x54, 0x6F, 0x6D, 0x20, 0x43, 0x6F, 0x6D, 0x6D, 0x61, 0x6E, 0x64, 0x65, 0x72 };
if (fileContent.FirstPosition(check, out int position))
return "CopyKiller" + (includePosition ? $" (Index {position})" : string.Empty);
var mappings = new Dictionary<byte?[], string>
{
// Tom Commander
[new byte?[] { 0x54, 0x6F, 0x6D, 0x20, 0x43, 0x6F, 0x6D, 0x6D, 0x61, 0x6E, 0x64, 0x65, 0x72 }] = "CopyKiller",
};
return null;
return Utilities.GetContentMatches(fileContent, mappings, includePosition);
}
/// <inheritdoc/>

View File

@@ -10,12 +10,13 @@ namespace BurnOutSharp.ProtectionType
/// <inheritdoc/>
public string CheckContents(string file, byte[] fileContent, bool includePosition = false)
{
// "xlive.dll"
byte?[] check = new byte?[] { 0x78, 0x6C, 0x69, 0x76, 0x65, 0x2E, 0x64, 0x6C, 0x6C };
if (fileContent.FirstPosition(check, out int position))
return "Games for Windows - Live" + (includePosition ? $" (Index {position})" : string.Empty);
var mappings = new Dictionary<byte?[], string>
{
// xlive.dll
[new byte?[] { 0x78, 0x6C, 0x69, 0x76, 0x65, 0x2E, 0x64, 0x6C, 0x6C }] = "Games for Windows - Live",
};
return null;
return Utilities.GetContentMatches(fileContent, mappings, includePosition);
}
/// <inheritdoc/>

View File

@@ -1,4 +1,6 @@
namespace BurnOutSharp.ProtectionType
using System.Collections.Generic;
namespace BurnOutSharp.ProtectionType
{
public class Intenium : IContentCheck
{
@@ -21,12 +23,13 @@
/// <inheritdoc/>
public string CheckContents(string file, byte[] fileContent, bool includePosition = false)
{
// Trial + (char)0x00 + P
byte?[] check = new byte?[] { 0x54, 0x72, 0x69, 0x61, 0x6C, 0x00, 0x50 };
if (fileContent.FirstPosition(check, out int position))
return "INTENIUM Trial & Buy Protection" + (includePosition ? $" (Index {position})" : string.Empty);
var mappings = new Dictionary<byte?[], string>
{
// Trial + (char)0x00 + P
[new byte?[] { 0x54, 0x72, 0x69, 0x61, 0x6C, 0x00, 0x50 }] = "INTENIUM Trial & Buy Protection",
};
return null;
return Utilities.GetContentMatches(fileContent, mappings, includePosition);
}
}
}

View File

@@ -1,16 +1,19 @@
namespace BurnOutSharp.ProtectionType
using System.Collections.Generic;
namespace BurnOutSharp.ProtectionType
{
public class KeyLock : IContentCheck
{
/// <inheritdoc/>
public string CheckContents(string file, byte[] fileContent, bool includePosition = false)
{
// "KEY-LOCK COMMAND"
byte?[] check = new byte?[] { 0x4B, 0x45, 0x59, 0x2D, 0x4C, 0x4F, 0x43, 0x4B, 0x20, 0x43, 0x4F, 0x4D, 0x4D, 0x41, 0x4E, 0x44 };
if (fileContent.FirstPosition(check, out int position))
return $"Key-Lock (Dongle)" + (includePosition ? $" (Index {position})" : string.Empty);
var mappings = new Dictionary<byte?[], string>
{
// KEY-LOCK COMMAND
[new byte?[] { 0x4B, 0x45, 0x59, 0x2D, 0x4C, 0x4F, 0x43, 0x4B, 0x20, 0x43, 0x4F, 0x4D, 0x4D, 0x41, 0x4E, 0x44 }] = "Key-Lock (Dongle)",
};
return null;
return Utilities.GetContentMatches(fileContent, mappings, includePosition);
}
}
}

View File

@@ -8,7 +8,7 @@
// 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 + E + (char)0x00 + R + (char)0x00 + e + (char)0x00 + g + (char)0x00
byte?[] check = 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, 0x45, 0x00, 0x52, 0x00, 0x65, 0x00, 0x67, 0x00 };
if (fileContent.FirstPosition(check, out int position))
return $"EA CdKey Registration Module {Utilities.GetFileVersion(file)}" + (includePosition ? $" (Index {position})" : string.Empty);
return $"Executable-Based Online Registration {Utilities.GetFileVersion(file)}" + (includePosition ? $" (Index {position})" : string.Empty);
return null;
}

View File

@@ -10,12 +10,13 @@ namespace BurnOutSharp.ProtectionType
/// <inheritdoc/>
public string CheckContents(string file, byte[] fileContent, bool includePosition = false)
{
// O + (char)0x00 + r + (char)0x00 + i + (char)0x00 + g + (char)0x00 + i + (char)0x00 + n + (char)0x00 + S + (char)0x00 + e + (char)0x00 + t + (char)0x00 + u + (char)0x00 + p + (char)0x00 + . + (char)0x00 + e + (char)0x00 + x + (char)0x00 + e + (char)0x00
byte?[] check = new byte?[] { 0x4F, 0x00, 0x72, 0x00, 0x69, 0x00, 0x67, 0x00, 0x69, 0x00, 0x6E, 0x00, 0x53, 0x00, 0x65, 0x00, 0x74, 0x00, 0x75, 0x00, 0x70, 0x00, 0x2E, 0x00, 0x65, 0x00, 0x78, 0x00, 0x65, 0x00 };
if (fileContent.FirstPosition(check, out int position))
return "Origin" + (includePosition ? $" (Index {position})" : string.Empty);
var mappings = new Dictionary<byte?[], string>
{
// O + (char)0x00 + r + (char)0x00 + i + (char)0x00 + g + (char)0x00 + i + (char)0x00 + n + (char)0x00 + S + (char)0x00 + e + (char)0x00 + t + (char)0x00 + u + (char)0x00 + p + (char)0x00 + . + (char)0x00 + e + (char)0x00 + x + (char)0x00 + e + (char)0x00
[new byte?[] { 0x4F, 0x00, 0x72, 0x00, 0x69, 0x00, 0x67, 0x00, 0x69, 0x00, 0x6E, 0x00, 0x53, 0x00, 0x65, 0x00, 0x74, 0x00, 0x75, 0x00, 0x70, 0x00, 0x2E, 0x00, 0x65, 0x00, 0x78, 0x00, 0x65, 0x00 }] = "Origin",
};
return null;
return Utilities.GetContentMatches(fileContent, mappings, includePosition);
}
/// <inheritdoc/>

View File

@@ -1,4 +1,6 @@
namespace BurnOutSharp.ProtectionType
using System.Collections.Generic;
namespace BurnOutSharp.ProtectionType
{
public class PSXAntiModchip : IContentCheck
{
@@ -7,17 +9,16 @@
/// <inheritdoc/>
public string CheckContents(string file, byte[] fileContent, bool includePosition = false)
{
// " SOFTWARE TERMINATED\nCONSOLE MAY HAVE BEEN MODIFIED\n CALL 1-888-780-7690"
byte?[] check = new byte?[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x53, 0x4F, 0x46, 0x54, 0x57, 0x41, 0x52, 0x45, 0x20, 0x54, 0x45, 0x52, 0x4D, 0x49, 0x4E, 0x41, 0x54, 0x45, 0x44, 0x5C, 0x6E, 0x43, 0x4F, 0x4E, 0x53, 0x4F, 0x4C, 0x45, 0x20, 0x4D, 0x41, 0x59, 0x20, 0x48, 0x41, 0x56, 0x45, 0x20, 0x42, 0x45, 0x45, 0x4E, 0x20, 0x4D, 0x4F, 0x44, 0x49, 0x46, 0x49, 0x45, 0x44, 0x5C, 0x6E, 0x20, 0x20, 0x20, 0x20, 0x20, 0x43, 0x41, 0x4C, 0x4C, 0x20, 0x31, 0x2D, 0x38, 0x38, 0x38, 0x2D, 0x37, 0x38, 0x30, 0x2D, 0x37, 0x36, 0x39, 0x30 };
if (fileContent.FirstPosition(check, out int position))
return $"PlayStation Anti-modchip (English)" + (includePosition ? $"(Index {position})" : string.Empty);
var mappings = new Dictionary<byte?[], string>
{
// SOFTWARE TERMINATED\nCONSOLE MAY HAVE BEEN MODIFIED\n CALL 1-888-780-7690
[new byte?[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x53, 0x4F, 0x46, 0x54, 0x57, 0x41, 0x52, 0x45, 0x20, 0x54, 0x45, 0x52, 0x4D, 0x49, 0x4E, 0x41, 0x54, 0x45, 0x44, 0x5C, 0x6E, 0x43, 0x4F, 0x4E, 0x53, 0x4F, 0x4C, 0x45, 0x20, 0x4D, 0x41, 0x59, 0x20, 0x48, 0x41, 0x56, 0x45, 0x20, 0x42, 0x45, 0x45, 0x4E, 0x20, 0x4D, 0x4F, 0x44, 0x49, 0x46, 0x49, 0x45, 0x44, 0x5C, 0x6E, 0x20, 0x20, 0x20, 0x20, 0x20, 0x43, 0x41, 0x4C, 0x4C, 0x20, 0x31, 0x2D, 0x38, 0x38, 0x38, 0x2D, 0x37, 0x38, 0x30, 0x2D, 0x37, 0x36, 0x39, 0x30 }] = "PlayStation Anti-modchip (English)",
// "強制終了しました。\n本体が改造されている\nおそれがあります。"
check = new byte?[] { 0x5F, 0x37, 0x52, 0x36, 0x7D, 0x42, 0x4E, 0x86, 0x30, 0x57, 0x30, 0x7E, 0x30, 0x57, 0x30, 0x5F, 0x30, 0x02, 0x5C, 0x6E, 0x67, 0x2C, 0x4F, 0x53, 0x30, 0x4C, 0x65, 0x39, 0x90, 0x20, 0x30, 0x55, 0x30, 0x8C, 0x30, 0x66, 0x30, 0x44, 0x30, 0x8B, 0x5C, 0x6E, 0x30, 0x4A, 0x30, 0x5D, 0x30, 0x8C, 0x30, 0x4C, 0x30, 0x42, 0x30, 0x8A, 0x30, 0x7E, 0x30, 0x59, 0x30, 0x02 };
if (fileContent.FirstPosition(check, out position))
return $"PlayStation Anti-modchip (Japanese)" + (includePosition ? $"(Index {position})" : string.Empty);
// 強制終了しました。\n本体が改造されている\nおそれがあります。
[new byte?[] { 0x5F, 0x37, 0x52, 0x36, 0x7D, 0x42, 0x4E, 0x86, 0x30, 0x57, 0x30, 0x7E, 0x30, 0x57, 0x30, 0x5F, 0x30, 0x02, 0x5C, 0x6E, 0x67, 0x2C, 0x4F, 0x53, 0x30, 0x4C, 0x65, 0x39, 0x90, 0x20, 0x30, 0x55, 0x30, 0x8C, 0x30, 0x66, 0x30, 0x44, 0x30, 0x8B, 0x5C, 0x6E, 0x30, 0x4A, 0x30, 0x5D, 0x30, 0x8C, 0x30, 0x4C, 0x30, 0x42, 0x30, 0x8A, 0x30, 0x7E, 0x30, 0x59, 0x30, 0x02 }] = "PlayStation Anti-modchip (Japanese)",
};
return null;
return Utilities.GetContentMatches(fileContent, mappings, includePosition);
}
}
}

View File

@@ -1,4 +1,6 @@
namespace BurnOutSharp.ProtectionType
using System.Collections.Generic;
namespace BurnOutSharp.ProtectionType
{
public class RingPROTECH : IContentCheck
{
@@ -6,12 +8,13 @@
/// TODO: Investigate as this may be over-matching
public string CheckContents(string file, byte[] fileContent, bool includePosition = false)
{
// (char)0x00 + "Allocator" + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x00
byte?[] check = new byte?[] { 0x00, 0x41, 0x6C, 0x6C, 0x6F, 0x63, 0x61, 0x74, 0x6F, 0x72, 0x00, 0x00, 0x00, 0x00 };
if (fileContent.FirstPosition(check, out int position))
return "Ring PROTECH [Check disc for physical ring]" + (includePosition ? $" (Index {position})" : string.Empty);
var mappings = new Dictionary<byte?[], string>
{
// (char)0x00 + Allocator + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x00
[new byte?[] { 0x00, 0x41, 0x6C, 0x6C, 0x6F, 0x63, 0x61, 0x74, 0x6F, 0x72, 0x00, 0x00, 0x00, 0x00 }] = "Ring PROTECH [Check disc for physical ring]",
};
return null;
return Utilities.GetContentMatches(fileContent, mappings, includePosition);
}
}
}

View File

@@ -1,16 +1,19 @@
namespace BurnOutSharp.ProtectionType
using System.Collections.Generic;
namespace BurnOutSharp.ProtectionType
{
public class SVKProtector : IContentCheck
{
/// <inheritdoc/>
public string CheckContents(string file, byte[] fileContent, bool includePosition = false)
{
// "?SVKP" + (char)0x00 + (char)0x00
byte?[] check = new byte?[] { 0x3F, 0x53, 0x56, 0x4B, 0x50, 0x00, 0x00 };
if (fileContent.FirstPosition(check, out int position))
return "SVK Protector" + (includePosition ? $" (Index {position})" : string.Empty);
var mappings = new Dictionary<byte?[], string>
{
// ?SVKP + (char)0x00 + (char)0x00
[new byte?[] { 0x3F, 0x53, 0x56, 0x4B, 0x50, 0x00, 0x00 }] = "SVK Protector",
};
return null;
return Utilities.GetContentMatches(fileContent, mappings, includePosition);
}
}
}

View File

@@ -10,12 +10,13 @@ namespace BurnOutSharp.ProtectionType
/// <inheritdoc/>
public string CheckContents(string file, byte[] fileContent, bool includePosition = false)
{
// BITARTS
byte?[] check = new byte?[] { 0x42, 0x49, 0x54, 0x41, 0x52, 0x54, 0x53 };
if (fileContent.FirstPosition(check, out int position))
return "SmartE" + (includePosition ? $" (Index {position})" : string.Empty);
var mappings = new Dictionary<byte?[], string>
{
// BITARTS
[new byte?[] { 0x42, 0x49, 0x54, 0x41, 0x52, 0x54, 0x53 }] = "SmartE",
};
return null;
return Utilities.GetContentMatches(fileContent, mappings, includePosition);
}
/// <inheritdoc/>

View File

@@ -5,7 +5,6 @@ using System.Linq;
namespace BurnOutSharp.ProtectionType
{
// TODO: Can this be split into file and directory checks separately?
public class Steam : IPathCheck
{
/// <inheritdoc/>

View File

@@ -1,16 +1,19 @@
namespace BurnOutSharp.ProtectionType
using System.Collections.Generic;
namespace BurnOutSharp.ProtectionType
{
public class ThreeTwoOneStudios : IContentCheck
{
/// <inheritdoc/>
public string CheckContents(string file, byte[] fileContent, bool includePosition = false)
{
// 3 + (char)0x00 + 1 + 2 + (char)0x00 + 1 + (char)0x00 + S + (char)0x00 + t + (char)0x00 + u + (char)0x00 + d + (char)0x00 + i + (char)0x00 + o + (char)0x00 + s + (char)0x00 + + (char)0x00 + A + (char)0x00 + c + (char)0x00 + t + (char)0x00 + i + (char)0x00 + v + (char)0x00 + a + (char)0x00 + t + (char)0x00 + i + (char)0x00 + o + (char)0x00 + n + (char)0x00
byte?[] check = new byte?[] { 0x33, 0x00, 0x32, 0x00, 0x31, 0x00, 0x53, 0x00, 0x74, 0x00, 0x75, 0x00, 0x64, 0x00, 0x69, 0x00, 0x6F, 0x00, 0x73, 0x00, 0x20, 0x00, 0x41, 0x00, 0x63, 0x00, 0x74, 0x00, 0x69, 0x00, 0x76, 0x00, 0x61, 0x00, 0x74, 0x00, 0x69, 0x00, 0x6F, 0x00, 0x6E, 0x00 };
if (fileContent.FirstPosition(check, out int position))
return "321Studios Online Activation" + (includePosition ? $" (Index {position})" : string.Empty);
var mappings = new Dictionary<byte?[], string>
{
// 3 + (char)0x00 + 1 + 2 + (char)0x00 + 1 + (char)0x00 + S + (char)0x00 + t + (char)0x00 + u + (char)0x00 + d + (char)0x00 + i + (char)0x00 + o + (char)0x00 + s + (char)0x00 + + (char)0x00 + A + (char)0x00 + c + (char)0x00 + t + (char)0x00 + i + (char)0x00 + v + (char)0x00 + a + (char)0x00 + t + (char)0x00 + i + (char)0x00 + o + (char)0x00 + n + (char)0x00
[new byte?[] { 0x33, 0x00, 0x32, 0x00, 0x31, 0x00, 0x53, 0x00, 0x74, 0x00, 0x75, 0x00, 0x64, 0x00, 0x69, 0x00, 0x6F, 0x00, 0x73, 0x00, 0x20, 0x00, 0x41, 0x00, 0x63, 0x00, 0x74, 0x00, 0x69, 0x00, 0x76, 0x00, 0x61, 0x00, 0x74, 0x00, 0x69, 0x00, 0x6F, 0x00, 0x6E, 0x00 }] = "321Studios Online Activation",
};
return null;
return Utilities.GetContentMatches(fileContent, mappings, includePosition);
}
}
}

View File

@@ -10,12 +10,13 @@ namespace BurnOutSharp.ProtectionType
/// <inheritdoc/>
public string CheckContents(string file, byte[] fileContent, bool includePosition = false)
{
// "WTM76545"
byte?[] check = new byte?[] { 0x57, 0x54, 0x4D, 0x37, 0x36, 0x35, 0x34, 0x35 };
if (fileContent.FirstPosition(check, out int position))
return "WTM CD Protect" + (includePosition ? $" (Index {position})" : string.Empty);
var mappings = new Dictionary<byte?[], string>
{
// WTM76545
[new byte?[] { 0x57, 0x54, 0x4D, 0x37, 0x36, 0x35, 0x34, 0x35 }] = "WTM CD Protect",
};
return null;
return Utilities.GetContentMatches(fileContent, mappings, includePosition);
}
/// <inheritdoc/>

View File

@@ -11,22 +11,19 @@ namespace BurnOutSharp.ProtectionType
/// <inheritdoc/>
public string CheckContents(string file, byte[] fileContent, bool includePosition = false)
{
// XCP.DAT
byte?[] check = new byte?[] { 0x58, 0x43, 0x50, 0x2E, 0x44, 0x41, 0x54 };
if (fileContent.FirstPosition(check, out int position))
return "XCP" + (includePosition ? $" (Index {position})" : string.Empty);
// XCPPlugins.dll
check = new byte?[] { 0x58, 0x43, 0x50, 0x50, 0x6C, 0x75, 0x67, 0x69, 0x6E, 0x73, 0x2E, 0x64, 0x6C, 0x6C };
if (fileContent.FirstPosition(check, out position))
return "XCP" + (includePosition ? $" (Index {position})" : string.Empty);
// XCPPhoenix.dll
check = new byte?[] { 0x58, 0x43, 0x50, 0x50, 0x68, 0x6F, 0x65, 0x6E, 0x69, 0x78, 0x2E, 0x64, 0x6C, 0x6C };
if (fileContent.FirstPosition(check, out position))
return "XCP" + (includePosition ? $" (Index {position})" : string.Empty);
var mappings = new Dictionary<byte?[], string>
{
// XCP.DAT
[new byte?[] { 0x58, 0x43, 0x50, 0x2E, 0x44, 0x41, 0x54 }] = "XCP",
return null;
// XCPPlugins.dll
[new byte?[] { 0x58, 0x43, 0x50, 0x50, 0x6C, 0x75, 0x67, 0x69, 0x6E, 0x73, 0x2E, 0x64, 0x6C, 0x6C }] = "XCP",
// XCPPhoenix.dll
[new byte?[] { 0x58, 0x43, 0x50, 0x50, 0x68, 0x6F, 0x65, 0x6E, 0x69, 0x78, 0x2E, 0x64, 0x6C, 0x6C }] = "XCP",
};
return Utilities.GetContentMatches(fileContent, mappings, includePosition);
}
/// <inheritdoc/>

View File

@@ -1,16 +1,19 @@
namespace BurnOutSharp.ProtectionType
using System.Collections.Generic;
namespace BurnOutSharp.ProtectionType
{
public class XtremeProtector : IContentCheck
{
/// <inheritdoc/>
public string CheckContents(string file, byte[] fileContent, bool includePosition = false)
{
// "XPROT "
byte?[] check = new byte?[] { 0x58, 0x50, 0x52, 0x4F, 0x54, 0x20, 0x20, 0x20 };
if (fileContent.FirstPosition(check, out int position))
return "Xtreme-Protector" + (includePosition ? $" (Index {position})" : string.Empty);
var mappings = new Dictionary<byte?[], string>
{
// XPROT
[new byte?[] { 0x58, 0x50, 0x52, 0x4F, 0x54, 0x20, 0x20, 0x20 }] = "Xtreme-Protector",
};
return null;
return Utilities.GetContentMatches(fileContent, mappings, includePosition);
}
}
}

View File

@@ -252,17 +252,43 @@ namespace BurnOutSharp
/// <param name="mappings">Mapping of byte array to string for matching</param>
/// <param name="includePosition">True to include positional data, false otherwise</param>
/// <returns>String representing the matched protection, null otherwise</returns>
/// <remarks>
/// This is useful for checks that don't do anything special with versions or other positions.
/// TODO: Make variant of this that returns *all* content matches for later
/// TODO: Make variant of this that can take multiple content checks per check for later
/// </remarks>
public static string GetContentMatches(byte[] fileContent, Dictionary<byte?[], string> mappings, bool includePosition = false)
{
return GetVersionedContentMatches(fileContent, mappings.Select(kvp => (kvp.Key, (Func<byte[], int, string>)null, kvp.Value)).ToList(), includePosition);
}
/// <summary>
/// Get versioned content matches for a given protection
/// </summary>
/// <param name="fileContent">Byte array representing the file contents</param>
/// <param name="mappings">Tuple of matching byte array, version method, and string to output</param>
/// <param name="includePosition">True to include positional data, false otherwise</param>
/// <returns>String representing the matched protection, null otherwise</returns>
/// <remarks>
/// This is useful for checks that don't do anything special with versions or other positions.
/// TODO: Make variant of this that returns *all* content matches for later
/// TODO: Make variant of this that can take multiple content checks per check for later
/// </remarks>
public static string GetVersionedContentMatches(byte[] fileContent, List<(byte?[], Func<byte[], int, string>, string)> mappings, bool includePosition = false)
{
// If there's no mappings, we can't match
if (mappings == null || !mappings.Any())
return null;
// Loop through and try everything otherwise
foreach (var kvp in mappings)
foreach (var mapping in mappings)
{
if (fileContent.FirstPosition(kvp.Key, out int position))
return kvp.Value + (includePosition ? $" (Index {position})" : string.Empty);
if (fileContent.FirstPosition(mapping.Item1, out int position))
{
string version = mapping.Item2 == null ? string.Empty : (mapping.Item2(fileContent, position) ?? "Unknown Version");
string protection = string.IsNullOrWhiteSpace(version) ? mapping.Item3 : $"{mapping.Item3} {version}";
return protection + (includePosition ? $" (Index {position})" : string.Empty);
}
}
return null;