From 4ff4c2afefe6abbf92bab7b6fc52c36b60c8d558 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Fri, 10 Mar 2023 11:41:08 -0500 Subject: [PATCH] Move helper methods used in a single place --- BurnOutSharp/Scanner.cs | 75 ++++++++++++++++++++++++++++- BurnOutSharp/Tools/FileTypeTools.cs | 67 -------------------------- 2 files changed, 73 insertions(+), 69 deletions(-) diff --git a/BurnOutSharp/Scanner.cs b/BurnOutSharp/Scanner.cs index 33258157..49c60d40 100644 --- a/BurnOutSharp/Scanner.cs +++ b/BurnOutSharp/Scanner.cs @@ -5,6 +5,8 @@ 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; @@ -343,7 +345,7 @@ namespace BurnOutSharp #region Non-Archive File Types // Create a scannable for the given file type - var scannable = Tools.FileTypeTools.CreateScannable(fileType); + var scannable = CreateScannable(fileType); // If we're scanning file contents if (scannable != null && ScanContents) @@ -357,7 +359,7 @@ namespace BurnOutSharp #region Archive File Types // Create an extractable for the given file type - var extractable = Tools.FileTypeTools.CreateExtractable(fileType); + var extractable = CreateExtractable(fileType); // If we're scanning archives if (extractable != null && ScanArchives) @@ -412,5 +414,74 @@ namespace BurnOutSharp } #endregion + + #region Helpers + + /// + /// Create an instance of an extractable based on file type + /// + private static IExtractable CreateExtractable(SupportedFileType fileType) + { + switch (fileType) + { + case SupportedFileType.BFPK: return new FileType.BFPK(); + case SupportedFileType.BSP: return new FileType.BSP(); + case SupportedFileType.BZip2: return new FileType.BZip2(); + case SupportedFileType.CFB: return new FileType.CFB(); + //case SupportedFileType.CIA: return new FileType.CIA(); + //case SupportedFileType.Executable: return new FileType.Executable(); + case SupportedFileType.GCF: return new FileType.GCF(); + case SupportedFileType.GZIP: return new FileType.GZIP(); + case SupportedFileType.InstallShieldArchiveV3: return new FileType.InstallShieldArchiveV3(); + case SupportedFileType.InstallShieldCAB: return new FileType.InstallShieldCAB(); + case SupportedFileType.MicrosoftCAB: return new FileType.MicrosoftCAB(); + case SupportedFileType.MicrosoftLZ: return new FileType.MicrosoftLZ(); + case SupportedFileType.MPQ: return new FileType.MPQ(); + //case SupportedFileType.N3DS: return new FileType.N3DS(); + //case SupportedFileType.NCF: return new FileType.NCF(); + //case SupportedFileType.Nitro: return new FileType.Nitro(); + case SupportedFileType.PAK: return new FileType.PAK(); + case SupportedFileType.PFF: return new FileType.PFF(); + case SupportedFileType.PKZIP: return new FileType.PKZIP(); + //case SupportedFileType.PLJ: return new FileType.PLJ(); + //case SupportedFileType.Quantum: return new FileType.Quantum(); + case SupportedFileType.RAR: return new FileType.RAR(); + case SupportedFileType.SevenZip: return new FileType.SevenZip(); + case SupportedFileType.SFFS: return new FileType.SFFS(); + case SupportedFileType.SGA: return new FileType.SGA(); + case SupportedFileType.TapeArchive: return new FileType.TapeArchive(); + case SupportedFileType.VBSP: return new FileType.VBSP(); + case SupportedFileType.VPK: return new FileType.VPK(); + case SupportedFileType.WAD: return new FileType.WAD(); + case SupportedFileType.XZ: return new FileType.XZ(); + case SupportedFileType.XZP: return new FileType.XZP(); + default: return null; + } + } + + /// + /// Create an instance of a scannable based on file type + /// + private static IScannable CreateScannable(SupportedFileType fileType) + { + switch (fileType) + { + case SupportedFileType.AACSMediaKeyBlock: return new FileType.AACSMediaKeyBlock(); + case SupportedFileType.BDPlusSVM: return new FileType.BDPlusSVM(); + //case SupportedFileType.CIA: return new FileType.CIA(); + case SupportedFileType.Executable: return new FileType.Executable(); + //case FileTypes.IniFile: return new FileType.IniFile(); + case SupportedFileType.LDSCRYPT: return new FileType.LDSCRYPT(); + //case SupportedFileType.N3DS: return new FileType.N3DS(); + //case SupportedFileType.NCF: return new FileType.NCF(); + //case SupportedFileType.Nitro: return new FileType.Nitro(); + case SupportedFileType.PLJ: return new FileType.PLJ(); + case SupportedFileType.SFFS: return new FileType.SFFS(); + case SupportedFileType.Textfile: return new FileType.Textfile(); + default: return null; + } + } + + #endregion } } diff --git a/BurnOutSharp/Tools/FileTypeTools.cs b/BurnOutSharp/Tools/FileTypeTools.cs index 7fc0177c..60d0ae1f 100644 --- a/BurnOutSharp/Tools/FileTypeTools.cs +++ b/BurnOutSharp/Tools/FileTypeTools.cs @@ -1,10 +1,8 @@ using System; using System.IO; -using BurnOutSharp.Interfaces; using BinaryObjectScanner.Matching; using BinaryObjectScanner.Utilities; using BinaryObjectScanner.Wrappers; -using BinaryObjectScanner.Interfaces; namespace BurnOutSharp.Tools { @@ -785,71 +783,6 @@ namespace BurnOutSharp.Tools return SupportedFileType.UNKNOWN; } - /// - /// Create an instance of an extractable based on file type - /// - public static IExtractable CreateExtractable(SupportedFileType fileType) - { - switch (fileType) - { - case SupportedFileType.BFPK: return new FileType.BFPK(); - case SupportedFileType.BSP: return new FileType.BSP(); - case SupportedFileType.BZip2: return new FileType.BZip2(); - case SupportedFileType.CFB: return new FileType.CFB(); - //case SupportedFileType.CIA: return new FileType.CIA(); - //case SupportedFileType.Executable: return new FileType.Executable(); - case SupportedFileType.GCF: return new FileType.GCF(); - case SupportedFileType.GZIP: return new FileType.GZIP(); - case SupportedFileType.InstallShieldArchiveV3: return new FileType.InstallShieldArchiveV3(); - case SupportedFileType.InstallShieldCAB: return new FileType.InstallShieldCAB(); - case SupportedFileType.MicrosoftCAB: return new FileType.MicrosoftCAB(); - case SupportedFileType.MicrosoftLZ: return new FileType.MicrosoftLZ(); - case SupportedFileType.MPQ: return new FileType.MPQ(); - //case SupportedFileType.N3DS: return new FileType.N3DS(); - //case SupportedFileType.NCF: return new FileType.NCF(); - //case SupportedFileType.Nitro: return new FileType.Nitro(); - case SupportedFileType.PAK: return new FileType.PAK(); - case SupportedFileType.PFF: return new FileType.PFF(); - case SupportedFileType.PKZIP: return new FileType.PKZIP(); - //case SupportedFileType.PLJ: return new FileType.PLJ(); - //case SupportedFileType.Quantum: return new FileType.Quantum(); - case SupportedFileType.RAR: return new FileType.RAR(); - case SupportedFileType.SevenZip: return new FileType.SevenZip(); - case SupportedFileType.SFFS: return new FileType.SFFS(); - case SupportedFileType.SGA: return new FileType.SGA(); - case SupportedFileType.TapeArchive: return new FileType.TapeArchive(); - case SupportedFileType.VBSP: return new FileType.VBSP(); - case SupportedFileType.VPK: return new FileType.VPK(); - case SupportedFileType.WAD: return new FileType.WAD(); - case SupportedFileType.XZ: return new FileType.XZ(); - case SupportedFileType.XZP: return new FileType.XZP(); - default: return null; - } - } - - /// - /// Create an instance of a scannable based on file type - /// - public static IScannable CreateScannable(SupportedFileType fileType) - { - switch (fileType) - { - case SupportedFileType.AACSMediaKeyBlock: return new FileType.AACSMediaKeyBlock(); - case SupportedFileType.BDPlusSVM: return new FileType.BDPlusSVM(); - //case SupportedFileType.CIA: return new FileType.CIA(); - case SupportedFileType.Executable: return new FileType.Executable(); - //case FileTypes.IniFile: return new FileType.IniFile(); - case SupportedFileType.LDSCRYPT: return new FileType.LDSCRYPT(); - //case SupportedFileType.N3DS: return new FileType.N3DS(); - //case SupportedFileType.NCF: return new FileType.NCF(); - //case SupportedFileType.Nitro: return new FileType.Nitro(); - case SupportedFileType.PLJ: return new FileType.PLJ(); - case SupportedFileType.SFFS: return new FileType.SFFS(); - case SupportedFileType.Textfile: return new FileType.Textfile(); - default: return null; - } - } - /// /// Create an instance of a wrapper based on file type ///