Files
BinaryObjectScanner/BurnOutSharp/FileType/Executable.cs

303 lines
14 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.IO;
using System.Text;
2020-10-30 09:09:16 -07:00
using BurnOutSharp.PackerType;
using BurnOutSharp.ProtectionType;
namespace BurnOutSharp.FileType
{
internal class Executable
{
public static bool ShouldScan(byte[] magic)
{
// DOS MZ executable file format (and descendants)
if (magic.StartsWith(new byte[] { 0x4d, 0x5a }))
return true;
// Executable and Linkable Format
if (magic.StartsWith(new byte[] { 0x7f, 0x45, 0x4c, 0x46 }))
return true;
// Mach-O binary (32-bit)
if (magic.StartsWith(new byte[] { 0xfe, 0xed, 0xfa, 0xce }))
return true;
// Mach-O binary (32-bit, reverse byte ordering scheme)
if (magic.StartsWith(new byte[] { 0xce, 0xfa, 0xed, 0xfe }))
return true;
// Mach-O binary (64-bit)
if (magic.StartsWith(new byte[] { 0xfe, 0xed, 0xfa, 0xcf }))
return true;
// Mach-O binary (64-bit, reverse byte ordering scheme)
if (magic.StartsWith(new byte[] { 0xcf, 0xfa, 0xed, 0xfe }))
return true;
// Prefrred Executable File Format
if (magic.StartsWith(new byte[] { 0x4a, 0x6f, 0x79, 0x21, 0x70, 0x65, 0x66, 0x66 }))
return true;
return false;
}
2020-10-31 14:00:31 -07:00
public static Dictionary<string, List<string>> Scan(Scanner scanner, Stream stream, string file = null)
{
// Load the current file content
byte[] fileContent = null;
using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
{
fileContent = br.ReadBytes((int)stream.Length);
}
// If we can, seek to the beginning of the stream
if (stream.CanSeek)
stream.Seek(0, SeekOrigin.Begin);
// Files can be protected in multiple ways
2020-10-31 14:00:31 -07:00
var protections = new Dictionary<string, List<string>>();
var subProtections = new Dictionary<string, List<string>>();
string protection;
2020-10-30 09:11:17 -07:00
#region Protections
// 3PLock
2020-10-31 14:00:31 -07:00
protection = ThreePLock.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// 321Studios Online Activation
2020-10-31 14:00:31 -07:00
protection = ThreeTwoOneStudios.CheckContents(fileContent, scanner.IncludePosition);
2020-10-28 22:51:14 -07:00
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
2020-10-28 22:51:14 -07:00
// ActiveMARK
2020-10-31 14:00:31 -07:00
protection = ActiveMARK.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// Alpha-ROM
2020-10-31 14:00:31 -07:00
protection = AlphaROM.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// Cactus Data Shield
2020-10-31 14:00:31 -07:00
protection = CactusDataShield.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// CD-Cops
2020-10-31 14:00:31 -07:00
protection = CDCops.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// CD-Lock
2020-10-31 14:00:31 -07:00
protection = CDLock.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// CDSHiELD SE
2020-10-31 14:00:31 -07:00
protection = CDSHiELDSE.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
2020-10-28 16:33:20 -07:00
// CD Check
2020-10-31 14:00:31 -07:00
protection = CDCheck.CheckContents(fileContent, scanner.IncludePosition);
2020-10-28 16:33:20 -07:00
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// Cenega ProtectDVD
2020-10-31 14:00:31 -07:00
protection = CengaProtectDVD.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// Code Lock
2020-10-31 14:00:31 -07:00
protection = CodeLock.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// CopyKiller
2020-10-31 14:00:31 -07:00
protection = CopyKiller.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// DVD-Cops
2020-10-31 14:00:31 -07:00
protection = DVDCops.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
2020-10-28 10:42:54 -07:00
// EA Protections
2020-10-31 14:00:31 -07:00
protection = ElectronicArts.CheckContents(file, fileContent, scanner.IncludePosition);
2020-10-28 10:42:54 -07:00
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
2020-10-28 10:42:54 -07:00
// Games for Windows - Live
2020-10-31 14:00:31 -07:00
protection = GFWL.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// Impulse Reactor
2020-10-31 14:00:31 -07:00
protection = ImpulseReactor.CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// Inno Setup
2020-10-31 14:00:31 -07:00
protection = InnoSetup.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// INTENIUM Trial & Buy Protection
protection = Intenium.CheckContents(fileContent, scanner.IncludePosition);
2020-10-31 14:43:27 -07:00
if (!string.IsNullOrWhiteSpace(protection))
Utilities.AppendToDictionary(protections, file, protection);
// JoWooD X-Prot
2020-10-31 14:00:31 -07:00
protection = JoWooDXProt.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// Key-Lock (Dongle)
2020-10-31 14:00:31 -07:00
protection = KeyLock.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// LaserLock
2020-10-31 14:00:31 -07:00
protection = LaserLock.CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
2020-11-03 14:47:15 -08:00
// MediaMax CD-3
protection = MediaMaxCD3.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
Utilities.AppendToDictionary(protections, file, protection);
2021-02-20 22:13:48 -08:00
// Origin
protection = Origin.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
Utilities.AppendToDictionary(protections, file, protection);
// ProtectDisc
2020-10-31 14:00:31 -07:00
protection = ProtectDisc.CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// Ring PROTECH
2020-10-31 14:00:31 -07:00
protection = RingPROTECH.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// SafeDisc / SafeCast
2020-10-31 14:00:31 -07:00
protection = SafeDisc.CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// SafeLock
2020-10-31 14:00:31 -07:00
protection = SafeLock.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// SecuROM
2020-10-31 14:00:31 -07:00
protection = SecuROM.CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// SmartE
2020-10-31 14:00:31 -07:00
protection = SmartE.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// SolidShield
2020-10-31 14:00:31 -07:00
protection = SolidShield.CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// StarForce
2020-10-31 14:00:31 -07:00
protection = StarForce.CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// SVK Protector
2020-10-31 14:00:31 -07:00
protection = SVKProtector.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// Sysiphus / Sysiphus DVD
2020-10-31 14:00:31 -07:00
protection = Sysiphus.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// TAGES
2020-10-31 14:00:31 -07:00
protection = Tages.CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// VOB ProtectCD/DVD
2020-10-31 14:00:31 -07:00
protection = VOBProtectCDDVD.CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// Wise Installer
2020-10-31 14:00:31 -07:00
subProtections = WiseInstaller.CheckContents(scanner, file, fileContent);
if (subProtections != null && subProtections.Count > 0)
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, subProtections);
// WTM CD Protect
2020-10-31 14:00:31 -07:00
protection = WTMCDProtect.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// XCP 1/2
2020-10-31 14:00:31 -07:00
protection = XCP.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// Xtreme-Protector
2020-10-31 14:00:31 -07:00
protection = XtremeProtector.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
2020-10-30 09:11:17 -07:00
#endregion
#region Packers
// If we're looking for packers too, run scans
2020-10-31 14:48:25 -07:00
if (scanner.ScanPackers)
{
// Armadillo
protection = Armadillo.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
Utilities.AppendToDictionary(protections, file, protection);
// dotFuscator
protection = dotFuscator.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
Utilities.AppendToDictionary(protections, file, protection);
// EXE Stealth
protection = EXEStealth.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
Utilities.AppendToDictionary(protections, file, protection);
// NSIS
protection = NSIS.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
Utilities.AppendToDictionary(protections, file, protection);
// PE Compact
protection = PECompact.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
Utilities.AppendToDictionary(protections, file, protection);
// UPX
protection = UPX.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
Utilities.AppendToDictionary(protections, file, protection);
}
2020-10-30 09:11:17 -07:00
#endregion
return protections;
}
}
}