diff --git a/BurnOutSharp/FileType/Executable.cs b/BurnOutSharp/FileType/Executable.cs index 3c65794e..398e5c12 100644 --- a/BurnOutSharp/FileType/Executable.cs +++ b/BurnOutSharp/FileType/Executable.cs @@ -2,8 +2,6 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Reflection; using System.Text; using System.Threading.Tasks; using BurnOutSharp.ExecutableType.Microsoft.NE; @@ -14,20 +12,24 @@ namespace BurnOutSharp.FileType { public class Executable : IScannable { + #region Checking Class Instances + /// /// Cache for all IContentCheck types /// - private static readonly IEnumerable contentCheckClasses = InitContentCheckClasses(); + private static readonly IEnumerable contentCheckClasses = Initializer.InitContentCheckClasses(); /// /// Cache for all INEContentCheck types /// - private static readonly IEnumerable neContentCheckClasses = InitNEContentCheckClasses(); + private static readonly IEnumerable neContentCheckClasses = Initializer.InitNEContentCheckClasses(); /// /// Cache for all IPEContentCheck types /// - private static readonly IEnumerable peContentCheckClasses = InitPEContentCheckClasses(); + private static readonly IEnumerable peContentCheckClasses = Initializer.InitPEContentCheckClasses(); + + #endregion /// public bool ShouldScan(byte[] magic) @@ -179,36 +181,6 @@ namespace BurnOutSharp.FileType #region Helpers - /// - /// Initialize all IContentCheck implementations - /// - private static IEnumerable InitContentCheckClasses() - { - return Assembly.GetExecutingAssembly().GetTypes() - .Where(t => t.IsClass && t.GetInterface(nameof(IContentCheck)) != null) - .Select(t => Activator.CreateInstance(t) as IContentCheck); - } - - /// - /// Initialize all INEContentCheck implementations - /// - private static IEnumerable InitNEContentCheckClasses() - { - return Assembly.GetExecutingAssembly().GetTypes() - .Where(t => t.IsClass && t.GetInterface(nameof(INEContentCheck)) != null) - .Select(t => Activator.CreateInstance(t) as INEContentCheck); - } - - /// - /// Initialize all IPEContentCheck implementations - /// - private static IEnumerable InitPEContentCheckClasses() - { - return Assembly.GetExecutingAssembly().GetTypes() - .Where(t => t.IsClass && t.GetInterface(nameof(IPEContentCheck)) != null) - .Select(t => Activator.CreateInstance(t) as IPEContentCheck); - } - /// /// Check to see if a protection should be added or not /// diff --git a/BurnOutSharp/Initializer.cs b/BurnOutSharp/Initializer.cs new file mode 100644 index 00000000..b7e5288e --- /dev/null +++ b/BurnOutSharp/Initializer.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +namespace BurnOutSharp +{ + /// + /// Internal static initializers using reflection + /// + /// + /// These can probably be consolidated if Type variables are used + /// + internal static class Initializer + { + /// + /// Initialize all IContentCheck implementations + /// + public static IEnumerable InitContentCheckClasses() + { + return Assembly.GetExecutingAssembly().GetTypes() + .Where(t => t.IsClass && t.GetInterface(nameof(IContentCheck)) != null) + .Select(t => Activator.CreateInstance(t) as IContentCheck); + } + + /// + /// Initialize all INEContentCheck implementations + /// + public static IEnumerable InitNEContentCheckClasses() + { + return Assembly.GetExecutingAssembly().GetTypes() + .Where(t => t.IsClass && t.GetInterface(nameof(INEContentCheck)) != null) + .Select(t => Activator.CreateInstance(t) as INEContentCheck); + } + + /// + /// Initialize all IPathCheck implementations + /// + public static IEnumerable InitPathCheckClasses() + { + return Assembly.GetExecutingAssembly().GetTypes() + .Where(t => t.IsClass && t.GetInterface(nameof(IPathCheck)) != null) + .Select(t => Activator.CreateInstance(t) as IPathCheck); + } + + /// + /// Initialize all IPEContentCheck implementations + /// + public static IEnumerable InitPEContentCheckClasses() + { + return Assembly.GetExecutingAssembly().GetTypes() + .Where(t => t.IsClass && t.GetInterface(nameof(IPEContentCheck)) != null) + .Select(t => Activator.CreateInstance(t) as IPEContentCheck); + } + } +} diff --git a/BurnOutSharp/Scanner.cs b/BurnOutSharp/Scanner.cs index ea05c88a..1004aeac 100644 --- a/BurnOutSharp/Scanner.cs +++ b/BurnOutSharp/Scanner.cs @@ -3,7 +3,6 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Reflection; using System.Threading.Tasks; using BurnOutSharp.FileType; using BurnOutSharp.Tools; @@ -12,6 +11,8 @@ namespace BurnOutSharp { public class Scanner { + #region Options + /// /// Determines whether archives are decompressed and scanned /// @@ -32,10 +33,16 @@ namespace BurnOutSharp /// public IProgress FileProgress { get; private set; } + #endregion + + #region Checking Class Instances + /// /// Cache for all IPathCheck types /// - private static readonly IEnumerable pathCheckClasses = InitPathCheckClasses(); + private static readonly IEnumerable pathCheckClasses = Initializer.InitPathCheckClasses(); + + #endregion /// /// Constructor @@ -52,6 +59,8 @@ namespace BurnOutSharp FileProgress = fileProgress; } + #region Scanning + /// /// Scan a single path and get all found protections /// @@ -425,15 +434,7 @@ namespace BurnOutSharp return protections; } - - /// - /// Initialize all IPathCheck implementations - /// - private static IEnumerable InitPathCheckClasses() - { - return Assembly.GetExecutingAssembly().GetTypes() - .Where(t => t.IsClass && t.GetInterface(nameof(IPathCheck)) != null) - .Select(t => Activator.CreateInstance(t) as IPathCheck); - } + + #endregion } }