diff --git a/BinaryObjectScanner/FileType/Executable.cs b/BinaryObjectScanner/FileType/Executable.cs index ef7c0bac..8a06d343 100644 --- a/BinaryObjectScanner/FileType/Executable.cs +++ b/BinaryObjectScanner/FileType/Executable.cs @@ -447,11 +447,15 @@ namespace BinaryObjectScanner.FileType { return assembly.GetTypes()? .Where(t => t.IsClass && t.GetInterface(typeof(T).Name) != null)? +#if NET48 .Select(t => (T)Activator.CreateInstance(t)) +#else + .Select(t => (T?)Activator.CreateInstance(t)) +#endif .Cast() ?? Array.Empty(); } - #endregion +#endregion #region Helpers diff --git a/BinaryObjectScanner/Handler.cs b/BinaryObjectScanner/Handler.cs index 823eadb5..5e8eae2b 100644 --- a/BinaryObjectScanner/Handler.cs +++ b/BinaryObjectScanner/Handler.cs @@ -18,7 +18,11 @@ namespace BinaryObjectScanner /// /// Cache for all IPathCheck types /// +#if NET48 public static IEnumerable PathCheckClasses +#else + public static IEnumerable PathCheckClasses +#endif { get { @@ -39,7 +43,7 @@ namespace BinaryObjectScanner #if NET48 private static IEnumerable pathCheckClasses; #else - private static IEnumerable? pathCheckClasses; + private static IEnumerable? pathCheckClasses; #endif #endregion @@ -67,7 +71,7 @@ namespace BinaryObjectScanner // Iterate through all checks Parallel.ForEach(PathCheckClasses, checkClass => { - var subProtections = checkClass.PerformCheck(path, files); + var subProtections = checkClass?.PerformCheck(path, files); if (subProtections != null) AppendToDictionary(protections, path, subProtections); }); @@ -162,7 +166,7 @@ namespace BinaryObjectScanner return null; // Setup the output dictionary - var protections = new ConcurrentQueue(); + var protections = new ConcurrentQueue(); // If we have a file path if (File.Exists(path)) @@ -191,18 +195,33 @@ namespace BinaryObjectScanner /// /// Initialize all implementations of a type /// +#if NET48 private static IEnumerable InitCheckClasses() - => InitCheckClasses(typeof(BinaryObjectScanner.Packer._DUMMY).Assembly) - .Concat(InitCheckClasses(typeof(BinaryObjectScanner.Protection._DUMMY).Assembly)); +#else + private static IEnumerable InitCheckClasses() +#endif + { + return InitCheckClasses(typeof(GameEngine._DUMMY).Assembly) + .Concat(InitCheckClasses(typeof(Packer._DUMMY).Assembly)) + .Concat(InitCheckClasses(typeof(Protection._DUMMY).Assembly)); + } /// /// Initialize all implementations of a type /// +#if NET48 private static IEnumerable InitCheckClasses(Assembly assembly) +#else + private static IEnumerable InitCheckClasses(Assembly assembly) +#endif { return assembly.GetTypes()? .Where(t => t.IsClass && t.GetInterface(typeof(T).Name) != null)? +#if NET48 .Select(t => (T)Activator.CreateInstance(t)) ?? Array.Empty(); +#else + .Select(t => (T?)Activator.CreateInstance(t)) ?? Array.Empty(); +#endif } #endregion