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
2021-02-26 01:26:49 -08:00
protection = new ThreePLock().CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// 321Studios Online Activation
2021-02-26 01:26:49 -08:00
protection = new ThreeTwoOneStudios().CheckContents(file, 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
2021-02-26 01:26:49 -08:00
protection = new ActiveMARK().CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// Alpha-ROM
2021-02-26 01:26:49 -08:00
protection = new AlphaROM().CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// Cactus Data Shield
2021-02-26 01:26:49 -08:00
protection = new CactusDataShield().CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// CD-Cops
2021-02-26 01:26:49 -08:00
protection = new CDCops().CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// CD-Lock
2021-02-26 01:26:49 -08:00
protection = new CDLock().CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// CDSHiELD SE
2021-02-26 01:26:49 -08:00
protection = new CDSHiELDSE().CheckContents(file, 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
2021-02-26 01:26:49 -08:00
protection = new CDCheck().CheckContents(file, 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
2021-02-26 01:26:49 -08:00
protection = new CengaProtectDVD().CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// Code Lock
2021-02-26 01:26:49 -08:00
protection = new CodeLock().CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// CopyKiller
2021-02-26 01:26:49 -08:00
protection = new CopyKiller().CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// DVD-Cops
2021-02-26 01:26:49 -08:00
protection = new DVDCops().CheckContents(file, 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
2021-02-26 01:26:49 -08:00
protection = new 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
2021-02-26 01:26:49 -08:00
protection = new GFWL().CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// Impulse Reactor
2021-02-26 01:26:49 -08:00
protection = new 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
2021-02-26 01:26:49 -08:00
protection = new InnoSetup().CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// INTENIUM Trial & Buy Protection
2021-02-26 01:26:49 -08:00
protection = new Intenium().CheckContents(file, fileContent, scanner.IncludePosition);
2020-10-31 14:43:27 -07:00
if (!string.IsNullOrWhiteSpace(protection))
Utilities.AppendToDictionary(protections, file, protection);
// JoWooD X-Prot
2021-02-26 01:26:49 -08:00
protection = new JoWooDXProt().CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// Key-Lock (Dongle)
2021-02-26 01:26:49 -08:00
protection = new KeyLock().CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// LaserLock
2021-02-26 01:26:49 -08:00
protection = new 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
2021-02-26 01:26:49 -08:00
protection = new MediaMaxCD3().CheckContents(file, fileContent, scanner.IncludePosition);
2020-11-03 14:47:15 -08:00
if (!string.IsNullOrWhiteSpace(protection))
Utilities.AppendToDictionary(protections, file, protection);
2021-02-20 22:13:48 -08:00
// Origin
2021-02-26 01:26:49 -08:00
protection = new Origin().CheckContents(file, fileContent, scanner.IncludePosition);
2021-02-20 22:13:48 -08:00
if (!string.IsNullOrWhiteSpace(protection))
Utilities.AppendToDictionary(protections, file, protection);
// ProtectDisc
2021-02-26 01:26:49 -08:00
protection = new 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
2021-02-26 01:26:49 -08:00
protection = new RingPROTECH().CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// SafeDisc / SafeCast
2021-02-26 01:26:49 -08:00
protection = new SafeDisc().CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// SafeLock
2021-02-26 01:26:49 -08:00
protection = new SafeLock().CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// SecuROM
2021-02-26 01:26:49 -08:00
protection = new SecuROM().CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// SmartE
2021-02-26 01:26:49 -08:00
protection = new SmartE().CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// SolidShield
2021-02-26 01:26:49 -08:00
protection = new SolidShield().CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// StarForce
2021-02-26 01:26:49 -08:00
protection = new 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
2021-02-26 01:26:49 -08:00
protection = new SVKProtector().CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// Sysiphus / Sysiphus DVD
2021-02-26 01:26:49 -08:00
protection = new Sysiphus().CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// TAGES
2021-02-26 01:26:49 -08:00
protection = new 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
2021-02-26 01:26:49 -08:00
protection = new 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
2021-02-26 01:26:49 -08:00
protection = new WTMCDProtect().CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// XCP 1/2
2021-02-26 01:26:49 -08:00
protection = new XCP().CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
2020-10-31 14:00:31 -07:00
Utilities.AppendToDictionary(protections, file, protection);
// Xtreme-Protector
2021-02-26 01:26:49 -08:00
protection = new XtremeProtector().CheckContents(file, 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
2021-02-26 01:26:49 -08:00
protection = new Armadillo().CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
Utilities.AppendToDictionary(protections, file, protection);
// dotFuscator
2021-02-26 01:26:49 -08:00
protection = new dotFuscator().CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
Utilities.AppendToDictionary(protections, file, protection);
// EXE Stealth
2021-02-26 01:26:49 -08:00
protection = new EXEStealth().CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
Utilities.AppendToDictionary(protections, file, protection);
// NSIS
2021-02-26 01:26:49 -08:00
protection = new NSIS().CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
Utilities.AppendToDictionary(protections, file, protection);
// PE Compact
2021-02-26 01:26:49 -08:00
protection = new PECompact().CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
Utilities.AppendToDictionary(protections, file, protection);
// UPX
2021-02-26 01:26:49 -08:00
protection = new UPX().CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
Utilities.AppendToDictionary(protections, file, protection);
}
2020-10-30 09:11:17 -07:00
#endregion
return protections;
}
}
}