diff --git a/BurnOutSharp/FileType/Executable.cs b/BurnOutSharp/FileType/Executable.cs index 1def1a25..55bffc2a 100644 --- a/BurnOutSharp/FileType/Executable.cs +++ b/BurnOutSharp/FileType/Executable.cs @@ -1,13 +1,19 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.IO; +using System.Linq; +using System.Reflection; using System.Text; -using BurnOutSharp.PackerType; -using BurnOutSharp.ProtectionType; namespace BurnOutSharp.FileType { internal class Executable : IScannable { + /// + /// Cache for all IContentCheck types + /// + private static IEnumerable contentCheckClasses = null; + /// public bool ShouldScan(byte[] magic) { @@ -70,269 +76,40 @@ namespace BurnOutSharp.FileType // Files can be protected in multiple ways var protections = new Dictionary>(); - string protection; - #region Protections - - // 3PLock - protection = new ThreePLock().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // 321Studios Online Activation - protection = new ThreeTwoOneStudios().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // ActiveMARK - protection = new ActiveMARK().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // Alpha-ROM - protection = new AlphaROM().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // Cactus Data Shield - protection = new CactusDataShield().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // CD-Cops - protection = new CDCops().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // CD-Lock - protection = new CDLock().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // CDSHiELD SE - protection = new CDSHiELDSE().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // CD Check - protection = new CDCheck().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // Cenega ProtectDVD - protection = new CengaProtectDVD().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // Code Lock - protection = new CodeLock().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // CopyKiller - protection = new CopyKiller().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // DVD-Cops - protection = new DVDCops().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // EA Protections - protection = new ElectronicArts().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // Games for Windows - Live - protection = new GFWL().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // Impulse Reactor - protection = new ImpulseReactor().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // INTENIUM Trial & Buy Protection - protection = new Intenium().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // JoWooD X-Prot - protection = new JoWooDXProt().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // Key-Lock (Dongle) - protection = new KeyLock().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // LaserLock - protection = new LaserLock().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // MediaMax CD-3 - protection = new MediaMaxCD3().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // Origin - protection = new Origin().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // ProtectDisc - protection = new ProtectDisc().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // Ring PROTECH - protection = new RingPROTECH().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // SafeDisc / SafeCast - protection = new SafeDisc().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // SafeLock - protection = new SafeLock().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // SecuROM - protection = new SecuROM().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // SmartE - protection = new SmartE().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // SolidShield - protection = new SolidShield().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // StarForce - protection = new StarForce().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // SVK Protector - protection = new SVKProtector().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // Sysiphus / Sysiphus DVD - protection = new Sysiphus().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // TAGES - protection = new Tages().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // VOB ProtectCD/DVD - protection = new VOBProtectCDDVD().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // WTM CD Protect - protection = new WTMCDProtect().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // XCP 1/2 - protection = new XCP().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // Xtreme-Protector - protection = new XtremeProtector().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - #endregion - - #region Archive-as-Executable Formats / Installers - - // If we're looking for archives too, run scans - if (scanner.ScanArchives) + // Get all IContentCheck implementations + if (contentCheckClasses == null) { - // Inno Setup - if (file != null && !string.IsNullOrEmpty(new InnoSetup().CheckContents(file, fileContent, scanner.IncludePosition))) - { - var subProtections = new InnoSetup().Scan(scanner, null, file); - Utilities.PrependToKeys(subProtections, file); - Utilities.AppendToDictionary(protections, subProtections); - } - - // Wise Installer - if (file != null && !string.IsNullOrEmpty(new WiseInstaller().CheckContents(file, fileContent, scanner.IncludePosition))) - { - var subProtections = new WiseInstaller().Scan(scanner, null, file); - Utilities.PrependToKeys(subProtections, file); - Utilities.AppendToDictionary(protections, subProtections); - } + contentCheckClasses = Assembly.GetExecutingAssembly().GetTypes() + .Where(t => t.IsClass && t.GetInterface("IContentCheck") != null); } - #endregion - - #region Packers - - // If we're looking for packers too, run scans - if (scanner.ScanPackers) + // Iterate through all content checks + foreach (var contentCheckClass in contentCheckClasses) { - // Armadillo - protection = new Armadillo().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); + IContentCheck contentCheck = Activator.CreateInstance(contentCheckClass) as IContentCheck; + string protection = contentCheck.CheckContents(file, fileContent, scanner.IncludePosition); - // dotFuscator - protection = new dotFuscator().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); + // If we have a valid cotnent check based on settings + if (!contentCheckClass.Namespace.ToLowerInvariant().Contains("packertype") || scanner.ScanPackers) + { + if (!string.IsNullOrWhiteSpace(protection)) + Utilities.AppendToDictionary(protections, file, protection); + } - // EXE Stealth - protection = new EXEStealth().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // Inno Setup - protection = new InnoSetup().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // NSIS - protection = new NSIS().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // PE Compact - protection = new PECompact().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // UPX - protection = new UPX().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); - - // Wise Installer - protection = new WiseInstaller().CheckContents(file, fileContent, scanner.IncludePosition); - if (!string.IsNullOrWhiteSpace(protection)) - Utilities.AppendToDictionary(protections, file, protection); + // If we have an IScannable implementation + if (contentCheckClass.GetInterface("IScannable") != null) + { + IScannable scannable = Activator.CreateInstance(contentCheckClass) as IScannable; + if (file != null && !string.IsNullOrEmpty(protection)) + { + var subProtections = scannable.Scan(scanner, null, file); + Utilities.PrependToKeys(subProtections, file); + Utilities.AppendToDictionary(protections, subProtections); + } + } } - #endregion - return protections; } } diff --git a/BurnOutSharp/ProtectionType/CopyKiller.cs b/BurnOutSharp/ProtectionType/CopyKiller.cs index 742ada98..319673ba 100644 --- a/BurnOutSharp/ProtectionType/CopyKiller.cs +++ b/BurnOutSharp/ProtectionType/CopyKiller.cs @@ -21,18 +21,21 @@ namespace BurnOutSharp.ProtectionType /// public string CheckPath(string path, bool isDirectory, IEnumerable files) { - if (isDirectory) - { - if (files.Any(f => Path.GetFileName(f).Equals("Autorun.dat", StringComparison.OrdinalIgnoreCase))) - return "CopyKiller"; - } - else - { - if (Path.GetFileName(path).Equals("Autorun.dat", StringComparison.OrdinalIgnoreCase)) - return "CopyKiller"; - } - return null; + + // TODO: The following checks are overly broad and should be refined + //if (isDirectory) + //{ + // if (files.Any(f => Path.GetFileName(f).Equals("Autorun.dat", StringComparison.OrdinalIgnoreCase))) + // return "CopyKiller"; + //} + //else + //{ + // if (Path.GetFileName(path).Equals("Autorun.dat", StringComparison.OrdinalIgnoreCase)) + // return "CopyKiller"; + //} + + //return null; } } } diff --git a/BurnOutSharp/Scanner.cs b/BurnOutSharp/Scanner.cs index b6db6a1c..49e064cf 100644 --- a/BurnOutSharp/Scanner.cs +++ b/BurnOutSharp/Scanner.cs @@ -2,8 +2,8 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Reflection; using BurnOutSharp.FileType; -using BurnOutSharp.ProtectionType; namespace BurnOutSharp { @@ -34,6 +34,11 @@ namespace BurnOutSharp /// public bool ScanPackers { get; set; } = false; + /// + /// Cache for all IPathCheck types + /// + private static IEnumerable pathCheckClasses = null; + /// /// Constructor /// @@ -179,220 +184,24 @@ namespace BurnOutSharp /// Dictionary of list of strings representing the found protections private Dictionary> GetPathProtections(string path, bool isDirectory, List files = null) { + // Create an empty list for protections List protections = new List(); - string protection; - // AACS - protection = new AACS().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); + // Get all IPathCheck implementations + if (pathCheckClasses == null) + { + pathCheckClasses = Assembly.GetExecutingAssembly().GetTypes() + .Where(t => t.IsClass && t.GetInterface("IPathCheck") != null); + } - // Alpha-DVD - protection = new AlphaDVD().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // Bitpool - protection = new Bitpool().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // ByteShield - protection = new ByteShield().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // Cactus Data Shield - protection = new CactusDataShield().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // CD-Cops - protection = new CDCops().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // CD-Lock - protection = new CDLock().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // CD-Protector - protection = new CDProtector().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // CD-X - protection = new CDX().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - /* - // CopyKiller - protection = new CopyKiller().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - */ - - // DiscGuard - protection = new DiscGuard().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // DVD Crypt - protection = new DVDCrypt().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // DVD-Movie-PROTECT - protection = new DVDMoviePROTECT().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // FreeLock - protection = new FreeLock().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // Games for Windows - Live - protection = new GFWL().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // Hexalock AutoLock - protection = new HexalockAutoLock().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // Impulse Reactor - protection = new ImpulseReactor().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // IndyVCD - protection = new IndyVCD().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // Key2Audio XS - protection = new Key2AudioXS().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // LaserLock - protection = new LaserLock().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // MediaCloQ - protection = new MediaCloQ().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // MediaMax CD3 - protection = new MediaMaxCD3().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // Origin - protection = new Origin().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // Protect DVD-Video - protection = new ProtectDVDVideo().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // SafeCast - protection = new SafeCast().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // SafeDisc - protection = new SafeDisc().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // SafeDisc Lite - protection = new SafeDiscLite().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // SafeLock - protection = new SafeLock().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // SecuROM - protection = new SecuROM().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // SmartE - protection = new SmartE().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // SoftLock - protection = new SoftLock().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // SolidShield - protection = new SolidShield().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // StarForce - protection = new StarForce().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // Steam - protection = new Steam().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // TAGES - protection = new Tages().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // TZCopyProtector - protection = new TZCopyProtector().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // Uplay - protection = new Uplay().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // VOB ProtectCD/DVD - protection = new VOBProtectCDDVD().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // Winlock - protection = new Winlock().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // WTM CD Protect - protection = new WTMCDProtect().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // XCP - protection = new XCP().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); - - // Zzxzz - protection = new Zzxzz().CheckPath(path, isDirectory, files); - if (!string.IsNullOrWhiteSpace(protection)) - protections.Add(protection); + // Iterate through all path checks + foreach (var pathCheckClass in pathCheckClasses) + { + IPathCheck pathCheck = Activator.CreateInstance(pathCheckClass) as IPathCheck; + string protection = pathCheck.CheckPath(path, isDirectory, files); + if (!string.IsNullOrWhiteSpace(protection)) + protections.Add(protection); + } // Create and return the dictionary return new Dictionary>