diff --git a/BurnOutSharp/FileType/Executable.cs b/BurnOutSharp/FileType/Executable.cs index f7411a64..e22421b1 100644 --- a/BurnOutSharp/FileType/Executable.cs +++ b/BurnOutSharp/FileType/Executable.cs @@ -3,12 +3,13 @@ using System.Collections.Concurrent; using System.IO; using System.Text; using System.Threading.Tasks; -using BurnOutSharp.Interfaces; +using BurnOutSharp; using BinaryObjectScanner.Interfaces; using BinaryObjectScanner.Wrappers; using static BinaryObjectScanner.Utilities.Dictionary; +using System.Linq; -namespace BurnOutSharp.FileType +namespace BinaryObjectScanner.FileType { /// /// Executable or library @@ -37,6 +38,84 @@ namespace BurnOutSharp.FileType // - Can this somehow delegate to the proper extractable type? return null; + + // The below code is a copy of what is currently in Scan, but without any of the + // extraction code or packer filtering code. It is not currently enabled since it + // is not as complete as the IScannable implementation and therefore cannot be reasonably + // used as a replacement yet. + + // Files can be protected in multiple ways + var protections = new ConcurrentQueue(); + + // Load the current file content for debug only + byte[] fileContent = null; + if (includeDebug) + { + try + { + using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true)) + { + fileContent = br.ReadBytes((int)stream.Length); + } + } + catch (Exception ex) + { + if (includeDebug) Console.WriteLine(ex); + } + } + + // Get the wrapper for the appropriate executable type + WrapperBase wrapper = WrapperFactory.CreateExecutableWrapper(stream); + if (wrapper == null) + return null; + + // Iterate through all generic content checks + if (fileContent != null) + { + Parallel.ForEach(ScanningClasses.ContentCheckClasses, checkClass => + { + string protection = checkClass.CheckContents(file, fileContent, includeDebug); + protections.Enqueue(protection); + }); + } + + // If we have an MS-DOS executable + if (wrapper is MSDOS mz) + { + // No-op + } + + // If we have a New Executable + else if (wrapper is NewExecutable nex) + { + Parallel.ForEach(ScanningClasses.NewExecutableCheckClasses, checkClass => + { + string protection = checkClass.CheckNewExecutable(file, nex, includeDebug); + protections.Enqueue(protection); + }); + } + + // If we have a Linear Executable + else if (wrapper is LinearExecutable lex) + { + Parallel.ForEach(ScanningClasses.LinearExecutableCheckClasses, checkClass => + { + string protection = checkClass.CheckLinearExecutable(file, lex, includeDebug); + protections.Enqueue(protection); + }); + } + + // If we have a Portable Executable + else if (wrapper is PortableExecutable pex) + { + Parallel.ForEach(ScanningClasses.PortableExecutableCheckClasses, checkClass => + { + string protection = checkClass.CheckPortableExecutable(file, pex, includeDebug); + protections.Enqueue(protection); + }); + } + + return string.Join(";", protections.ToArray()); } /// diff --git a/BurnOutSharp/Interfaces/IScannable.cs b/BurnOutSharp/Interfaces/IScannable.cs index fb893d41..e0d5670e 100644 --- a/BurnOutSharp/Interfaces/IScannable.cs +++ b/BurnOutSharp/Interfaces/IScannable.cs @@ -1,7 +1,8 @@ using System.Collections.Concurrent; using System.IO; +using BurnOutSharp; -namespace BurnOutSharp.Interfaces +namespace BinaryObjectScanner.Interfaces { /// /// Mark a file type as being able to be scanned diff --git a/BurnOutSharp/Scanner.cs b/BurnOutSharp/Scanner.cs index 4e621257..a7432191 100644 --- a/BurnOutSharp/Scanner.cs +++ b/BurnOutSharp/Scanner.cs @@ -5,7 +5,6 @@ using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; -using BurnOutSharp.Interfaces; using BinaryObjectScanner.Interfaces; using BinaryObjectScanner.Utilities; using static BinaryObjectScanner.Utilities.Dictionary; @@ -449,7 +448,7 @@ namespace BurnOutSharp case SupportedFileType.AACSMediaKeyBlock: return new BinaryObjectScanner.FileType.AACSMediaKeyBlock(); case SupportedFileType.BDPlusSVM: return new BinaryObjectScanner.FileType.BDPlusSVM(); //case SupportedFileType.CIA: return new BinaryObjectScanner.FileType.CIA(); - case SupportedFileType.Executable: return new FileType.Executable(); + case SupportedFileType.Executable: return new BinaryObjectScanner.FileType.Executable(); case SupportedFileType.LDSCRYPT: return new BinaryObjectScanner.FileType.LDSCRYPT(); //case SupportedFileType.N3DS: return new BinaryObjectScanner.FileType.N3DS(); //case SupportedFileType.Nitro: return new BinaryObjectScanner.FileType.Nitro(); @@ -472,7 +471,7 @@ namespace BurnOutSharp case SupportedFileType.BZip2: return new BinaryObjectScanner.FileType.BZip2(); case SupportedFileType.CFB: return new BinaryObjectScanner.FileType.CFB(); //case SupportedFileType.CIA: return new BinaryObjectScanner.FileType.CIA(); - case SupportedFileType.Executable: return new FileType.Executable(); + case SupportedFileType.Executable: return new BinaryObjectScanner.FileType.Executable(); case SupportedFileType.GCF: return new BinaryObjectScanner.FileType.GCF(); case SupportedFileType.GZIP: return new BinaryObjectScanner.FileType.GZIP(); case SupportedFileType.InstallShieldArchiveV3: return new BinaryObjectScanner.FileType.InstallShieldArchiveV3(); @@ -509,7 +508,7 @@ namespace BurnOutSharp { switch (fileType) { - case SupportedFileType.Executable: return new FileType.Executable(); + case SupportedFileType.Executable: return new BinaryObjectScanner.FileType.Executable(); default: return null; } }