diff --git a/BurnOutSharp/FileType/BFPK.cs b/BurnOutSharp/FileType/BFPK.cs index 91257d3d..494a4b23 100644 --- a/BurnOutSharp/FileType/BFPK.cs +++ b/BurnOutSharp/FileType/BFPK.cs @@ -18,7 +18,7 @@ namespace BurnOutSharp.FileType return false; } - public static List Scan(Stream stream, bool includePosition = false) + public static List Scan(Scanner parentScanner, Stream stream, bool includePosition = false) { List protections = new List(); @@ -28,6 +28,14 @@ namespace BurnOutSharp.FileType string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(tempPath); + // Create a new scanner for the new temp path + Scanner subScanner = new Scanner(tempPath, parentScanner.FileProgress) + { + IncludePosition = parentScanner.IncludePosition, + ScanAllFiles = parentScanner.ScanAllFiles, + ScanArchives = parentScanner.ScanArchives, + }; + using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true)) { br.ReadBytes(4); // Skip magic number diff --git a/BurnOutSharp/FileType/BZip2.cs b/BurnOutSharp/FileType/BZip2.cs index 5b5289e9..d505744e 100644 --- a/BurnOutSharp/FileType/BZip2.cs +++ b/BurnOutSharp/FileType/BZip2.cs @@ -17,7 +17,7 @@ namespace BurnOutSharp.FileType return false; } - public static List Scan(Stream stream, bool includePosition = false) + public static List Scan(Scanner parentScanner, Stream stream, bool includePosition = false) { List protections = new List(); @@ -27,6 +27,14 @@ namespace BurnOutSharp.FileType string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(tempPath); + // Create a new scanner for the new temp path + Scanner subScanner = new Scanner(tempPath, parentScanner.FileProgress) + { + IncludePosition = parentScanner.IncludePosition, + ScanAllFiles = parentScanner.ScanAllFiles, + ScanArchives = parentScanner.ScanArchives, + }; + using (BZip2Stream bz2File = new BZip2Stream(stream, CompressionMode.Decompress, true)) { // If an individual entry fails diff --git a/BurnOutSharp/FileType/GZIP.cs b/BurnOutSharp/FileType/GZIP.cs index 1d9f0414..18d1ee6e 100644 --- a/BurnOutSharp/FileType/GZIP.cs +++ b/BurnOutSharp/FileType/GZIP.cs @@ -17,7 +17,7 @@ namespace BurnOutSharp.FileType return false; } - public static List Scan(Stream stream, bool includePosition = false) + public static List Scan(Scanner parentScanner, Stream stream, bool includePosition = false) { List protections = new List(); @@ -27,6 +27,14 @@ namespace BurnOutSharp.FileType string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(tempPath); + // Create a new scanner for the new temp path + Scanner subScanner = new Scanner(tempPath, parentScanner.FileProgress) + { + IncludePosition = parentScanner.IncludePosition, + ScanAllFiles = parentScanner.ScanAllFiles, + ScanArchives = parentScanner.ScanArchives, + }; + using (GZipArchive zipFile = GZipArchive.Open(stream)) { foreach (var entry in zipFile.Entries) diff --git a/BurnOutSharp/FileType/InstallShieldCAB.cs b/BurnOutSharp/FileType/InstallShieldCAB.cs index 66d58de4..f679b0af 100644 --- a/BurnOutSharp/FileType/InstallShieldCAB.cs +++ b/BurnOutSharp/FileType/InstallShieldCAB.cs @@ -18,7 +18,7 @@ namespace BurnOutSharp.FileType } // TODO: Add stream opening support - public static List Scan(string file, bool includePosition = false) + public static List Scan(Scanner parentScanner, string file, bool includePosition = false) { List protections = new List(); @@ -42,6 +42,14 @@ namespace BurnOutSharp.FileType string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(tempPath); + // Create a new scanner for the new temp path + Scanner subScanner = new Scanner(tempPath, parentScanner.FileProgress) + { + IncludePosition = parentScanner.IncludePosition, + ScanAllFiles = parentScanner.ScanAllFiles, + ScanArchives = parentScanner.ScanArchives, + }; + UnshieldCabinet cabfile = UnshieldCabinet.Open(file); for (int i = 0; i < cabfile.FileCount; i++) { diff --git a/BurnOutSharp/FileType/MPQ.cs b/BurnOutSharp/FileType/MPQ.cs index d2254cd4..0f1606fa 100644 --- a/BurnOutSharp/FileType/MPQ.cs +++ b/BurnOutSharp/FileType/MPQ.cs @@ -17,7 +17,7 @@ namespace BurnOutSharp.FileType } // TODO: Add stream opening support - public static List Scan(string file, bool includePosition = false) + public static List Scan(Scanner parentScanner, string file, bool includePosition = false) { List protections = new List(); @@ -27,6 +27,14 @@ namespace BurnOutSharp.FileType string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(tempPath); + // Create a new scanner for the new temp path + Scanner subScanner = new Scanner(tempPath, parentScanner.FileProgress) + { + IncludePosition = parentScanner.IncludePosition, + ScanAllFiles = parentScanner.ScanAllFiles, + ScanArchives = parentScanner.ScanArchives, + }; + using (MpqArchive mpqArchive = new MpqArchive(file, FileAccess.Read)) { string listfile = null; diff --git a/BurnOutSharp/FileType/MSI.cs b/BurnOutSharp/FileType/MSI.cs index 7120255e..20f8f1f9 100644 --- a/BurnOutSharp/FileType/MSI.cs +++ b/BurnOutSharp/FileType/MSI.cs @@ -21,7 +21,7 @@ namespace BurnOutSharp.FileType } // TODO: Add stream opening support - public static List Scan(string file, bool includePosition = false) + public static List Scan(Scanner parentScanner, string file, bool includePosition = false) { List protections = new List(); @@ -31,6 +31,14 @@ namespace BurnOutSharp.FileType string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(tempPath); + // Create a new scanner for the new temp path + Scanner subScanner = new Scanner(tempPath, parentScanner.FileProgress) + { + IncludePosition = parentScanner.IncludePosition, + ScanAllFiles = parentScanner.ScanAllFiles, + ScanArchives = parentScanner.ScanArchives, + }; + using (Database msidb = new Database(file, DatabaseOpenMode.ReadOnly)) { msidb.ExportAll(tempPath); diff --git a/BurnOutSharp/FileType/MicrosoftCAB.cs b/BurnOutSharp/FileType/MicrosoftCAB.cs index 4f875ff4..df025fb8 100644 --- a/BurnOutSharp/FileType/MicrosoftCAB.cs +++ b/BurnOutSharp/FileType/MicrosoftCAB.cs @@ -17,7 +17,7 @@ namespace BurnOutSharp.FileType } // TODO: Add stream opening support - public static List Scan(string file, bool includePosition = false) + public static List Scan(Scanner parentScanner, string file, bool includePosition = false) { List protections = new List(); @@ -27,6 +27,14 @@ namespace BurnOutSharp.FileType string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(tempPath); + // Create a new scanner for the new temp path + Scanner subScanner = new Scanner(tempPath, parentScanner.FileProgress) + { + IncludePosition = parentScanner.IncludePosition, + ScanAllFiles = parentScanner.ScanAllFiles, + ScanArchives = parentScanner.ScanArchives, + }; + using (MSCabinet cabfile = new MSCabinet(file)) { foreach (var sub in cabfile.GetFiles()) diff --git a/BurnOutSharp/FileType/PKZIP.cs b/BurnOutSharp/FileType/PKZIP.cs index cd8fe2bc..2d4d7fef 100644 --- a/BurnOutSharp/FileType/PKZIP.cs +++ b/BurnOutSharp/FileType/PKZIP.cs @@ -26,7 +26,7 @@ namespace BurnOutSharp.FileType return false; } - public static List Scan(Stream stream, bool includePosition = false) + public static List Scan(Scanner parentScanner, Stream stream, bool includePosition = false) { List protections = new List(); @@ -36,6 +36,14 @@ namespace BurnOutSharp.FileType string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(tempPath); + // Create a new scanner for the new temp path + Scanner subScanner = new Scanner(tempPath, parentScanner.FileProgress) + { + IncludePosition = parentScanner.IncludePosition, + ScanAllFiles = parentScanner.ScanAllFiles, + ScanArchives = parentScanner.ScanArchives, + }; + using (ZipArchive zipFile = ZipArchive.Open(stream)) { foreach (var entry in zipFile.Entries) diff --git a/BurnOutSharp/FileType/RAR.cs b/BurnOutSharp/FileType/RAR.cs index 06addf81..8a963dfc 100644 --- a/BurnOutSharp/FileType/RAR.cs +++ b/BurnOutSharp/FileType/RAR.cs @@ -22,7 +22,7 @@ namespace BurnOutSharp.FileType return false; } - public static List Scan(Stream stream, bool includePosition = false) + public static List Scan(Scanner parentScanner, Stream stream, bool includePosition = false) { List protections = new List(); @@ -32,6 +32,14 @@ namespace BurnOutSharp.FileType string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(tempPath); + // Create a new scanner for the new temp path + Scanner subScanner = new Scanner(tempPath, parentScanner.FileProgress) + { + IncludePosition = parentScanner.IncludePosition, + ScanAllFiles = parentScanner.ScanAllFiles, + ScanArchives = parentScanner.ScanArchives, + }; + using (RarArchive zipFile = RarArchive.Open(stream)) { foreach (var entry in zipFile.Entries) diff --git a/BurnOutSharp/FileType/SevenZip.cs b/BurnOutSharp/FileType/SevenZip.cs index 0c91d2df..f4db9bec 100644 --- a/BurnOutSharp/FileType/SevenZip.cs +++ b/BurnOutSharp/FileType/SevenZip.cs @@ -17,7 +17,7 @@ namespace BurnOutSharp.FileType return false; } - public static List Scan(Stream stream, bool includePosition = false) + public static List Scan(Scanner parentScanner, Stream stream, bool includePosition = false) { List protections = new List(); @@ -27,6 +27,14 @@ namespace BurnOutSharp.FileType string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(tempPath); + // Create a new scanner for the new temp path + Scanner subScanner = new Scanner(tempPath, parentScanner.FileProgress) + { + IncludePosition = parentScanner.IncludePosition, + ScanAllFiles = parentScanner.ScanAllFiles, + ScanArchives = parentScanner.ScanArchives, + }; + using (SevenZipArchive sevenZipFile = SevenZipArchive.Open(stream)) { foreach (var entry in sevenZipFile.Entries) diff --git a/BurnOutSharp/FileType/TapeArchive.cs b/BurnOutSharp/FileType/TapeArchive.cs index 8e160400..ef35a878 100644 --- a/BurnOutSharp/FileType/TapeArchive.cs +++ b/BurnOutSharp/FileType/TapeArchive.cs @@ -20,7 +20,7 @@ namespace BurnOutSharp.FileType return false; } - public static List Scan(Stream stream, bool includePosition = false) + public static List Scan(Scanner parentScanner, Stream stream, bool includePosition = false) { List protections = new List(); @@ -30,6 +30,14 @@ namespace BurnOutSharp.FileType string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(tempPath); + // Create a new scanner for the new temp path + Scanner subScanner = new Scanner(tempPath, parentScanner.FileProgress) + { + IncludePosition = parentScanner.IncludePosition, + ScanAllFiles = parentScanner.ScanAllFiles, + ScanArchives = parentScanner.ScanArchives, + }; + using (TarArchive tarFile = TarArchive.Open(stream)) { foreach (var entry in tarFile.Entries) diff --git a/BurnOutSharp/FileType/Valve.cs b/BurnOutSharp/FileType/Valve.cs index ef467753..1ed8ee16 100644 --- a/BurnOutSharp/FileType/Valve.cs +++ b/BurnOutSharp/FileType/Valve.cs @@ -34,13 +34,21 @@ namespace BurnOutSharp.FileType } // TODO: Add stream opening support - public static List Scan(string file, bool includePosition = false) + public static List Scan(Scanner parentScanner, string file, bool includePosition = false) { List protections = new List(); string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(tempPath); + // Create a new scanner for the new temp path + Scanner subScanner = new Scanner(tempPath, parentScanner.FileProgress) + { + IncludePosition = parentScanner.IncludePosition, + ScanAllFiles = parentScanner.ScanAllFiles, + ScanArchives = parentScanner.ScanArchives, + }; + string[] args = new string[] { "-p", file, diff --git a/BurnOutSharp/FileType/XZ.cs b/BurnOutSharp/FileType/XZ.cs index e8daf6b1..2dceb4ef 100644 --- a/BurnOutSharp/FileType/XZ.cs +++ b/BurnOutSharp/FileType/XZ.cs @@ -16,7 +16,7 @@ namespace BurnOutSharp.FileType return false; } - public static List Scan(Stream stream, bool includePosition = false) + public static List Scan(Scanner parentScanner, Stream stream, bool includePosition = false) { List protections = new List(); @@ -26,6 +26,14 @@ namespace BurnOutSharp.FileType string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(tempPath); + // Create a new scanner for the new temp path + Scanner subScanner = new Scanner(tempPath, parentScanner.FileProgress) + { + IncludePosition = parentScanner.IncludePosition, + ScanAllFiles = parentScanner.ScanAllFiles, + ScanArchives = parentScanner.ScanArchives, + }; + using (XZStream xzFile = new XZStream(stream)) { // If an individual entry fails diff --git a/BurnOutSharp/Scanner.cs b/BurnOutSharp/Scanner.cs index 07dd4301..8c2a2496 100644 --- a/BurnOutSharp/Scanner.cs +++ b/BurnOutSharp/Scanner.cs @@ -48,10 +48,22 @@ namespace BurnOutSharp FileProgress = fileProgress; } + /// + /// Constructor + /// + /// Paths to create a scanner for + /// Optional progress callback + public Scanner(List paths, IProgress fileProgress = null) + { + Paths = paths; + FileProgress = fileProgress; + } + /// /// Scan the list of paths and get all found protections /// /// Dictionary of list of strings representing the found protections + /// TODO: Should this populate an internal field instead of returning? public Dictionary> GetProtections() { // If we have no paths, we can't scan @@ -158,7 +170,7 @@ namespace BurnOutSharp /// Path of the directory or file to scan /// Files contained within if the path is a directory /// Dictionary of list of strings representing the found protections - public Dictionary> GetPathProtections(string path, List files = null) + private Dictionary> GetPathProtections(string path, List files = null) { List protections = new List(); string protection; @@ -446,134 +458,139 @@ namespace BurnOutSharp #region Archive File Types - // 7-Zip archive - if (SevenZip.ShouldScan(magic)) + // If we're scanning archives, we have a few to try out + // TODO: All archives should return a dictionary instead of a list + if (ScanArchives) { - var subProtections = SevenZip.Scan(fs, IncludePosition); - if (!protections.ContainsKey(file)) - protections[file] = new List(); + // 7-Zip archive + if (SevenZip.ShouldScan(magic)) + { + var subProtections = SevenZip.Scan(this, fs, IncludePosition); + if (!protections.ContainsKey(file)) + protections[file] = new List(); - protections[file] = subProtections; - } + protections[file] = subProtections; + } - // BFPK archive - if (BFPK.ShouldScan(magic)) - { - var subProtections = BFPK.Scan(fs, IncludePosition); - if (!protections.ContainsKey(file)) - protections[file] = new List(); + // BFPK archive + if (BFPK.ShouldScan(magic)) + { + var subProtections = BFPK.Scan(this, fs, IncludePosition); + if (!protections.ContainsKey(file)) + protections[file] = new List(); - protections[file] = subProtections; - } + protections[file] = subProtections; + } - // BZip2 - if (BZip2.ShouldScan(magic)) - { - var subProtections = BZip2.Scan(fs, IncludePosition); - if (!protections.ContainsKey(file)) - protections[file] = new List(); + // BZip2 + if (BZip2.ShouldScan(magic)) + { + var subProtections = BZip2.Scan(this, fs, IncludePosition); + if (!protections.ContainsKey(file)) + protections[file] = new List(); - protections[file] = subProtections; - } + protections[file] = subProtections; + } - // GZIP - if (GZIP.ShouldScan(magic)) - { - var subProtections = GZIP.Scan(fs, IncludePosition); - if (!protections.ContainsKey(file)) - protections[file] = new List(); + // GZIP + if (GZIP.ShouldScan(magic)) + { + var subProtections = GZIP.Scan(this, fs, IncludePosition); + if (!protections.ContainsKey(file)) + protections[file] = new List(); - protections[file] = subProtections; - } + protections[file] = subProtections; + } - // InstallShield Cabinet - if (file != null && InstallShieldCAB.ShouldScan(magic)) - { - var subProtections = InstallShieldCAB.Scan(file, IncludePosition); - if (!protections.ContainsKey(file)) - protections[file] = new List(); + // InstallShield Cabinet + if (file != null && InstallShieldCAB.ShouldScan(magic)) + { + var subProtections = InstallShieldCAB.Scan(this, file, IncludePosition); + if (!protections.ContainsKey(file)) + protections[file] = new List(); - protections[file] = subProtections; - } + protections[file] = subProtections; + } - // Microsoft Cabinet - if (file != null && MicrosoftCAB.ShouldScan(magic)) - { - var subProtections = MicrosoftCAB.Scan(file, IncludePosition); - if (!protections.ContainsKey(file)) - protections[file] = new List(); + // Microsoft Cabinet + if (file != null && MicrosoftCAB.ShouldScan(magic)) + { + var subProtections = MicrosoftCAB.Scan(this, file, IncludePosition); + if (!protections.ContainsKey(file)) + protections[file] = new List(); - protections[file] = subProtections; - } + protections[file] = subProtections; + } - // MSI - if (file != null && MSI.ShouldScan(magic)) - { - var subProtections = MSI.Scan(file, IncludePosition); - if (!protections.ContainsKey(file)) - protections[file] = new List(); + // MSI + if (file != null && MSI.ShouldScan(magic)) + { + var subProtections = MSI.Scan(this, file, IncludePosition); + if (!protections.ContainsKey(file)) + protections[file] = new List(); - protections[file] = subProtections; - } + protections[file] = subProtections; + } - // MPQ archive - if (file != null && MPQ.ShouldScan(magic)) - { - var subProtections = MPQ.Scan(file, IncludePosition); - if (!protections.ContainsKey(file)) - protections[file] = new List(); + // MPQ archive + if (file != null && MPQ.ShouldScan(magic)) + { + var subProtections = MPQ.Scan(this, file, IncludePosition); + if (!protections.ContainsKey(file)) + protections[file] = new List(); - protections[file] = subProtections; - } + protections[file] = subProtections; + } - // PKZIP archive (and derivatives) - if (PKZIP.ShouldScan(magic)) - { - var subProtections = PKZIP.Scan(fs, IncludePosition); - if (!protections.ContainsKey(file)) - protections[file] = new List(); + // PKZIP archive (and derivatives) + if (PKZIP.ShouldScan(magic)) + { + var subProtections = PKZIP.Scan(this, fs, IncludePosition); + if (!protections.ContainsKey(file)) + protections[file] = new List(); - protections[file] = subProtections; - } + protections[file] = subProtections; + } - // RAR archive - if (RAR.ShouldScan(magic)) - { - var subProtections = RAR.Scan(fs, IncludePosition); - if (!protections.ContainsKey(file)) - protections[file] = new List(); + // RAR archive + if (RAR.ShouldScan(magic)) + { + var subProtections = RAR.Scan(this, fs, IncludePosition); + if (!protections.ContainsKey(file)) + protections[file] = new List(); - protections[file] = subProtections; - } + protections[file] = subProtections; + } - // Tape Archive - if (TapeArchive.ShouldScan(magic)) - { - var subProtections = TapeArchive.Scan(fs, IncludePosition); - if (!protections.ContainsKey(file)) - protections[file] = new List(); + // Tape Archive + if (TapeArchive.ShouldScan(magic)) + { + var subProtections = TapeArchive.Scan(this, fs, IncludePosition); + if (!protections.ContainsKey(file)) + protections[file] = new List(); - protections[file] = subProtections; - } + protections[file] = subProtections; + } - // Valve archive formats - if (file != null && Valve.ShouldScan(magic)) - { - var subProtections = Valve.Scan(file, IncludePosition); - if (!protections.ContainsKey(file)) - protections[file] = new List(); + // Valve archive formats + if (file != null && Valve.ShouldScan(magic)) + { + var subProtections = Valve.Scan(this, file, IncludePosition); + if (!protections.ContainsKey(file)) + protections[file] = new List(); - protections[file] = subProtections; - } + protections[file] = subProtections; + } - // XZ - if (XZ.ShouldScan(magic)) - { - var subProtections = XZ.Scan(fs, IncludePosition); - if (!protections.ContainsKey(file)) - protections[file] = new List(); + // XZ + if (XZ.ShouldScan(magic)) + { + var subProtections = XZ.Scan(this, fs, IncludePosition); + if (!protections.ContainsKey(file)) + protections[file] = new List(); - protections[file] = subProtections; + protections[file] = subProtections; + } } #endregion