diff --git a/BurnOutSharp/FileType/BFPK.cs b/BurnOutSharp/FileType/BFPK.cs
index 526a04be..b2371786 100644
--- a/BurnOutSharp/FileType/BFPK.cs
+++ b/BurnOutSharp/FileType/BFPK.cs
@@ -60,17 +60,11 @@ namespace BurnOutSharp.FileType
// If the BFPK file itself fails
try
{
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- // Create the wrapper
- BinaryObjectScanner.Wrappers.BFPK bfpk = BinaryObjectScanner.Wrappers.BFPK.Create(stream);
- if (bfpk == null)
+ // Extract and get the output path
+ string tempPath = Extract(stream, file);
+ if (tempPath == null)
return null;
- // Extract all files
- bfpk.ExtractAll(tempPath);
-
// Collect and format all found protections
var protections = scanner.GetProtections(tempPath);
diff --git a/BurnOutSharp/FileType/BSP.cs b/BurnOutSharp/FileType/BSP.cs
index dc6bb0bc..46b33b40 100644
--- a/BurnOutSharp/FileType/BSP.cs
+++ b/BurnOutSharp/FileType/BSP.cs
@@ -61,18 +61,11 @@ namespace BurnOutSharp.FileType
// If the BSP file itself fails
try
{
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- // Create the wrapper
- BinaryObjectScanner.Wrappers.BSP bsp = BinaryObjectScanner.Wrappers.BSP.Create(stream);
- if (bsp == null)
+ // Extract and get the output path
+ string tempPath = Extract(stream, file);
+ if (tempPath == null)
return null;
- // Loop through and extract all files
- bsp.ExtractAllLumps(tempPath);
- bsp.ExtractAllTextures(tempPath);
-
// Collect and format all found protections
var protections = scanner.GetProtections(tempPath);
diff --git a/BurnOutSharp/FileType/BZip2.cs b/BurnOutSharp/FileType/BZip2.cs
index e459467b..2442d406 100644
--- a/BurnOutSharp/FileType/BZip2.cs
+++ b/BurnOutSharp/FileType/BZip2.cs
@@ -63,25 +63,10 @@ namespace BurnOutSharp.FileType
// If the BZip2 file itself fails
try
{
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- using (BZip2Stream bz2File = new BZip2Stream(stream, CompressionMode.Decompress, true))
- {
- // If an individual entry fails
- try
- {
- string tempFile = Path.Combine(tempPath, Guid.NewGuid().ToString());
- using (FileStream fs = File.OpenWrite(tempFile))
- {
- bz2File.CopyTo(fs);
- }
- }
- catch (Exception ex)
- {
- if (scanner.IncludeDebug) Console.WriteLine(ex);
- }
- }
+ // Extract and get the output path
+ string tempPath = Extract(stream, file);
+ if (tempPath == null)
+ return null;
// Collect and format all found protections
var protections = scanner.GetProtections(tempPath);
diff --git a/BurnOutSharp/FileType/CFB.cs b/BurnOutSharp/FileType/CFB.cs
index 08c72f7d..933685a8 100644
--- a/BurnOutSharp/FileType/CFB.cs
+++ b/BurnOutSharp/FileType/CFB.cs
@@ -90,43 +90,10 @@ namespace BurnOutSharp.FileType
// If the MSI file itself fails
try
{
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- using (CompoundFile msi = new CompoundFile(stream, CFSUpdateMode.ReadOnly, CFSConfiguration.Default))
- {
- msi.RootStorage.VisitEntries((e) =>
- {
- if (!e.IsStream)
- return;
-
- var str = msi.RootStorage.GetStream(e.Name);
- if (str == null)
- return;
-
- byte[] strData = str.GetData();
- if (strData == null)
- return;
-
- string decoded = DecodeStreamName(e.Name).TrimEnd('\0');
- byte[] nameBytes = Encoding.UTF8.GetBytes(e.Name);
-
- // UTF-8 encoding of 0x4840.
- if (nameBytes[0] == 0xe4 && nameBytes[1] == 0xa1 && nameBytes[2] == 0x80)
- decoded = decoded.Substring(3);
-
- foreach (char c in Path.GetInvalidFileNameChars())
- {
- decoded = decoded.Replace(c, '_');
- }
-
- string filename = Path.Combine(tempPath, decoded);
- using (Stream fs = File.OpenWrite(filename))
- {
- fs.Write(strData, 0, strData.Length);
- }
- }, recursive: true);
- }
+ // Extract and get the output path
+ string tempPath = Extract(stream, file);
+ if (tempPath == null)
+ return null;
// Collect and format all found protections
var protections = scanner.GetProtections(tempPath);
diff --git a/BurnOutSharp/FileType/GCF.cs b/BurnOutSharp/FileType/GCF.cs
index 7343574c..e395680e 100644
--- a/BurnOutSharp/FileType/GCF.cs
+++ b/BurnOutSharp/FileType/GCF.cs
@@ -60,17 +60,11 @@ namespace BurnOutSharp.FileType
// If the GCF file itself fails
try
{
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- // Create the wrapper
- BinaryObjectScanner.Wrappers.GCF gcf = BinaryObjectScanner.Wrappers.GCF.Create(stream);
- if (gcf == null)
+ // Extract and get the output path
+ string tempPath = Extract(stream, file);
+ if (tempPath == null)
return null;
- // Loop through and extract all files
- gcf.ExtractAll(tempPath);
-
// Collect and format all found protections
var protections = scanner.GetProtections(tempPath);
diff --git a/BurnOutSharp/FileType/GZIP.cs b/BurnOutSharp/FileType/GZIP.cs
index fb0a7c41..bd2b2c10 100644
--- a/BurnOutSharp/FileType/GZIP.cs
+++ b/BurnOutSharp/FileType/GZIP.cs
@@ -67,29 +67,10 @@ namespace BurnOutSharp.FileType
// If the gzip file itself fails
try
{
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- using (GZipArchive zipFile = GZipArchive.Open(stream))
- {
- foreach (var entry in zipFile.Entries)
- {
- // If an individual entry fails
- try
- {
- // If we have a directory, skip it
- if (entry.IsDirectory)
- continue;
-
- string tempFile = Path.Combine(tempPath, entry.Key);
- entry.WriteToFile(tempFile);
- }
- catch (Exception ex)
- {
- if (scanner.IncludeDebug) Console.WriteLine(ex);
- }
- }
- }
+ // Extract and get the output path
+ string tempPath = Extract(stream, file);
+ if (tempPath == null)
+ return null;
// Collect and format all found protections
var protections = scanner.GetProtections(tempPath);
diff --git a/BurnOutSharp/FileType/InstallShieldArchiveV3.cs b/BurnOutSharp/FileType/InstallShieldArchiveV3.cs
index fe1d0cd8..453219bc 100644
--- a/BurnOutSharp/FileType/InstallShieldArchiveV3.cs
+++ b/BurnOutSharp/FileType/InstallShieldArchiveV3.cs
@@ -72,33 +72,10 @@ namespace BurnOutSharp.FileType
// If the archive itself fails
try
{
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- UnshieldSharp.Archive.InstallShieldArchiveV3 archive = new UnshieldSharp.Archive.InstallShieldArchiveV3(file);
- foreach (CompressedFile cfile in archive.Files.Select(kvp => kvp.Value))
- {
- // If an individual entry fails
- try
- {
- string tempFile = Path.Combine(tempPath, cfile.FullPath);
- if (!Directory.Exists(Path.GetDirectoryName(tempFile)))
- Directory.CreateDirectory(Path.GetDirectoryName(tempFile));
-
- (byte[] fileContents, string error) = archive.Extract(cfile.FullPath);
- if (!string.IsNullOrWhiteSpace(error))
- continue;
-
- using (FileStream fs = File.OpenWrite(tempFile))
- {
- fs.Write(fileContents, 0, fileContents.Length);
- }
- }
- catch (Exception ex)
- {
- if (scanner.IncludeDebug) Console.WriteLine(ex);
- }
- }
+ // Extract and get the output path
+ string tempPath = Extract(stream, file);
+ if (tempPath == null)
+ return null;
// Collect and format all found protections
var protections = scanner.GetProtections(tempPath);
diff --git a/BurnOutSharp/FileType/InstallShieldCAB.cs b/BurnOutSharp/FileType/InstallShieldCAB.cs
index 8479ce4e..12263183 100644
--- a/BurnOutSharp/FileType/InstallShieldCAB.cs
+++ b/BurnOutSharp/FileType/InstallShieldCAB.cs
@@ -29,6 +29,21 @@ namespace BurnOutSharp.FileType
///
public string Extract(Stream stream, string file)
{
+ // Get the name of the first cabinet file or header
+ string directory = Path.GetDirectoryName(file);
+ string noExtension = Path.GetFileNameWithoutExtension(file);
+ string filenamePattern = Path.Combine(directory, noExtension);
+ filenamePattern = new Regex(@"\d+$").Replace(filenamePattern, string.Empty);
+
+ bool cabinetHeaderExists = File.Exists(Path.Combine(directory, filenamePattern + "1.hdr"));
+ bool shouldScanCabinet = cabinetHeaderExists
+ ? file.Equals(Path.Combine(directory, filenamePattern + "1.hdr"), StringComparison.OrdinalIgnoreCase)
+ : file.Equals(Path.Combine(directory, filenamePattern + "1.cab"), StringComparison.OrdinalIgnoreCase);
+
+ // If we have anything but the first file
+ if (!shouldScanCabinet)
+ return null;
+
// Create a temp output directory
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(tempPath);
@@ -73,77 +88,35 @@ namespace BurnOutSharp.FileType
///
public ConcurrentDictionary> Scan(Scanner scanner, Stream stream, string file)
{
- // Get the name of the first cabinet file or header
- string directory = Path.GetDirectoryName(file);
- string noExtension = Path.GetFileNameWithoutExtension(file);
- string filenamePattern = Path.Combine(directory, noExtension);
- filenamePattern = new Regex(@"\d+$").Replace(filenamePattern, string.Empty);
-
- bool cabinetHeaderExists = File.Exists(Path.Combine(directory, filenamePattern + "1.hdr"));
- bool shouldScanCabinet = cabinetHeaderExists
- ? file.Equals(Path.Combine(directory, filenamePattern + "1.hdr"), StringComparison.OrdinalIgnoreCase)
- : file.Equals(Path.Combine(directory, filenamePattern + "1.cab"), StringComparison.OrdinalIgnoreCase);
-
- // If we have the first file
- if (shouldScanCabinet)
+ // If the cab file itself fails
+ try
{
- // If the cab file itself fails
+ // Extract and get the output path
+ string tempPath = Extract(stream, file);
+ if (tempPath == null)
+ return null;
+
+ // Collect and format all found protections
+ var protections = scanner.GetProtections(tempPath);
+
+ // If temp directory cleanup fails
try
{
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- InstallShieldCabinet cabfile = InstallShieldCabinet.Open(file);
- for (int i = 0; i < cabfile.FileCount; i++)
- {
- // If an individual entry fails
- try
- {
- // Check if the file is valid first
- if (!cabfile.FileIsValid(i))
- continue;
-
- string tempFile;
- try
- {
- string filename = cabfile.FileName(i);
- tempFile = Path.Combine(tempPath, filename);
- }
- catch
- {
- tempFile = Path.Combine(tempPath, $"BAD_FILENAME{i}");
- }
-
- cabfile.FileSave(i, tempFile);
- }
- catch (Exception ex)
- {
- if (scanner.IncludeDebug) Console.WriteLine(ex);
- }
- }
-
- // Collect and format all found protections
- var protections = scanner.GetProtections(tempPath);
-
- // If temp directory cleanup fails
- try
- {
- Directory.Delete(tempPath, true);
- }
- catch (Exception ex)
- {
- if (scanner.IncludeDebug) Console.WriteLine(ex);
- }
-
- // Remove temporary path references
- StripFromKeys(protections, tempPath);
-
- return protections;
+ Directory.Delete(tempPath, true);
}
catch (Exception ex)
{
if (scanner.IncludeDebug) Console.WriteLine(ex);
}
+
+ // Remove temporary path references
+ StripFromKeys(protections, tempPath);
+
+ return protections;
+ }
+ catch (Exception ex)
+ {
+ if (scanner.IncludeDebug) Console.WriteLine(ex);
}
return null;
diff --git a/BurnOutSharp/FileType/MPQ.cs b/BurnOutSharp/FileType/MPQ.cs
index 4ac0b90d..edb3d876 100644
--- a/BurnOutSharp/FileType/MPQ.cs
+++ b/BurnOutSharp/FileType/MPQ.cs
@@ -94,44 +94,10 @@ namespace BurnOutSharp.FileType
// If the MPQ file itself fails
try
{
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- using (MpqArchive mpqArchive = new MpqArchive(file, FileAccess.Read))
- {
- // Try to open the listfile
- string listfile = null;
- MpqFileStream listStream = mpqArchive.OpenFile("(listfile)");
-
- // If we can't read the listfile, we just return
- if (!listStream.CanRead)
- return null;
-
- // Read the listfile in for processing
- using (StreamReader sr = new StreamReader(listStream))
- {
- listfile = sr.ReadToEnd();
- }
-
- // Split the listfile by newlines
- string[] listfileLines = listfile.Replace("\r\n", "\n").Split('\n');
-
- // Loop over each entry
- foreach (string sub in listfileLines)
- {
- // If an individual entry fails
- try
- {
- string tempFile = Path.Combine(tempPath, sub);
- Directory.CreateDirectory(Path.GetDirectoryName(tempFile));
- mpqArchive.ExtractFile(sub, tempFile);
- }
- catch (Exception ex)
- {
- if (scanner.IncludeDebug) Console.WriteLine(ex);
- }
- }
- }
+ // Extract and get the output path
+ string tempPath = Extract(stream, file);
+ if (tempPath == null)
+ return null;
// Collect and format all found protections
var protections = scanner.GetProtections(tempPath);
diff --git a/BurnOutSharp/FileType/MicrosoftCAB.cs b/BurnOutSharp/FileType/MicrosoftCAB.cs
index 3f8d5606..02ede1a4 100644
--- a/BurnOutSharp/FileType/MicrosoftCAB.cs
+++ b/BurnOutSharp/FileType/MicrosoftCAB.cs
@@ -65,30 +65,10 @@ namespace BurnOutSharp.FileType
// If the cab file itself fails
try
{
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- // Open the cab file
- var cabFile = MicrosoftCabinet.Create(stream);
- if (cabFile == null)
- {
- if (scanner.IncludeDebug) Console.WriteLine($"Error occurred while opening");
+ // Extract and get the output path
+ string tempPath = Extract(stream, file);
+ if (tempPath == null)
return null;
- }
-
- // If entry extraction fails
- try
- {
- bool success = cabFile.ExtractAll(tempPath);
- if (!success)
- {
- if (scanner.IncludeDebug) Console.WriteLine($"Error occurred during extraction of files");
- }
- }
- catch (Exception ex)
- {
- if (scanner.IncludeDebug) Console.WriteLine(ex);
- }
// Collect and format all found protections
var protections = scanner.GetProtections(tempPath);
diff --git a/BurnOutSharp/FileType/MicrosoftLZ.cs b/BurnOutSharp/FileType/MicrosoftLZ.cs
index 0438fd0f..1547262c 100644
--- a/BurnOutSharp/FileType/MicrosoftLZ.cs
+++ b/BurnOutSharp/FileType/MicrosoftLZ.cs
@@ -76,30 +76,10 @@ namespace BurnOutSharp.FileType
// If the LZ file itself fails
try
{
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- byte[] data = LZ.Decompress(stream);
-
- // Create the temp filename
- string tempFile = "temp.bin";
- if (!string.IsNullOrEmpty(file))
- {
- string expandedFilePath = LZ.GetExpandedName(file, out _);
- tempFile = Path.GetFileName(expandedFilePath).TrimEnd('\0');
- if (tempFile.EndsWith(".ex"))
- tempFile += "e";
- else if (tempFile.EndsWith(".dl"))
- tempFile += "l";
- }
-
- tempFile = Path.Combine(tempPath, tempFile);
-
- // Write the file data to a temp file
- using (Stream tempStream = File.Open(tempFile, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
- {
- tempStream.Write(data, 0, data.Length);
- }
+ // Extract and get the output path
+ string tempPath = Extract(stream, file);
+ if (tempPath == null)
+ return null;
// Collect and format all found protections
var protections = scanner.GetProtections(tempPath);
diff --git a/BurnOutSharp/FileType/PAK.cs b/BurnOutSharp/FileType/PAK.cs
index 6002d30d..9f14c592 100644
--- a/BurnOutSharp/FileType/PAK.cs
+++ b/BurnOutSharp/FileType/PAK.cs
@@ -60,17 +60,11 @@ namespace BurnOutSharp.FileType
// If the PAK file itself fails
try
{
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- // Create the wrapper
- BinaryObjectScanner.Wrappers.PAK pak = BinaryObjectScanner.Wrappers.PAK.Create(stream);
- if (pak == null)
+ // Extract and get the output path
+ string tempPath = Extract(stream, file);
+ if (tempPath == null)
return null;
- // Loop through and extract all files
- pak.ExtractAll(tempPath);
-
// Collect and format all found protections
var protections = scanner.GetProtections(tempPath);
diff --git a/BurnOutSharp/FileType/PFF.cs b/BurnOutSharp/FileType/PFF.cs
index b7f46205..e75d315f 100644
--- a/BurnOutSharp/FileType/PFF.cs
+++ b/BurnOutSharp/FileType/PFF.cs
@@ -60,17 +60,11 @@ namespace BurnOutSharp.FileType
// If the PFF file itself fails
try
{
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- // Create the wrapper
- BinaryObjectScanner.Wrappers.PFF bfpk = BinaryObjectScanner.Wrappers.PFF.Create(stream);
- if (bfpk == null)
+ // Extract and get the output path
+ string tempPath = Extract(stream, file);
+ if (tempPath == null)
return null;
- // Extract all files
- bfpk.ExtractAll(tempPath);
-
// Collect and format all found protections
var protections = scanner.GetProtections(tempPath);
diff --git a/BurnOutSharp/FileType/PKZIP.cs b/BurnOutSharp/FileType/PKZIP.cs
index 542a90c6..0d9b9248 100644
--- a/BurnOutSharp/FileType/PKZIP.cs
+++ b/BurnOutSharp/FileType/PKZIP.cs
@@ -68,30 +68,10 @@ namespace BurnOutSharp.FileType
// If the zip file itself fails
try
{
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- using (ZipArchive zipFile = ZipArchive.Open(stream))
- {
- foreach (var entry in zipFile.Entries)
- {
- // If an individual entry fails
- try
- {
- // If we have a directory, skip it
- if (entry.IsDirectory)
- continue;
-
- string tempFile = Path.Combine(tempPath, entry.Key);
- Directory.CreateDirectory(Path.GetDirectoryName(tempFile));
- entry.WriteToFile(tempFile);
- }
- catch (Exception ex)
- {
- if (scanner.IncludeDebug) Console.WriteLine(ex);
- }
- }
- }
+ // Extract and get the output path
+ string tempPath = Extract(stream, file);
+ if (tempPath == null)
+ return null;
// Collect and format all found protections
var protections = scanner.GetProtections(tempPath);
diff --git a/BurnOutSharp/FileType/SGA.cs b/BurnOutSharp/FileType/SGA.cs
index 45e95502..1b0273ee 100644
--- a/BurnOutSharp/FileType/SGA.cs
+++ b/BurnOutSharp/FileType/SGA.cs
@@ -60,17 +60,11 @@ namespace BurnOutSharp.FileType
// If the SGA file itself fails
try
{
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- // Create the wrapper
- BinaryObjectScanner.Wrappers.SGA sga = BinaryObjectScanner.Wrappers.SGA.Create(stream);
- if (sga == null)
+ // Extract and get the output path
+ string tempPath = Extract(stream, file);
+ if (tempPath == null)
return null;
- // Loop through and extract all files
- sga.ExtractAll(tempPath);
-
// Collect and format all found protections
var protections = scanner.GetProtections(tempPath);
diff --git a/BurnOutSharp/FileType/SevenZip.cs b/BurnOutSharp/FileType/SevenZip.cs
index abafb158..f12bbd6b 100644
--- a/BurnOutSharp/FileType/SevenZip.cs
+++ b/BurnOutSharp/FileType/SevenZip.cs
@@ -67,47 +67,28 @@ namespace BurnOutSharp.FileType
// If the 7-zip file itself fails
try
{
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
+ // Extract and get the output path
+ string tempPath = Extract(stream, file);
+ if (tempPath == null)
+ return null;
- using (SevenZipArchive sevenZipFile = SevenZipArchive.Open(stream))
+ // Collect and format all found protections
+ var protections = scanner.GetProtections(tempPath);
+
+ // If temp directory cleanup fails
+ try
{
- foreach (var entry in sevenZipFile.Entries)
- {
- // If an individual entry fails
- try
- {
- // If we have a directory, skip it
- if (entry.IsDirectory)
- continue;
-
- string tempFile = Path.Combine(tempPath, entry.Key);
- entry.WriteToFile(tempFile);
- }
- catch (Exception ex)
- {
- if (scanner.IncludeDebug) Console.WriteLine(ex);
- }
- }
-
- // Collect and format all found protections
- var protections = scanner.GetProtections(tempPath);
-
- // If temp directory cleanup fails
- try
- {
- Directory.Delete(tempPath, true);
- }
- catch (Exception ex)
- {
- if (scanner.IncludeDebug) Console.WriteLine(ex);
- }
-
- // Remove temporary path references
- StripFromKeys(protections, tempPath);
-
- return protections;
+ Directory.Delete(tempPath, true);
}
+ catch (Exception ex)
+ {
+ if (scanner.IncludeDebug) Console.WriteLine(ex);
+ }
+
+ // Remove temporary path references
+ StripFromKeys(protections, tempPath);
+
+ return protections;
}
catch (Exception ex)
{
diff --git a/BurnOutSharp/FileType/TapeArchive.cs b/BurnOutSharp/FileType/TapeArchive.cs
index b48ed8a7..eade86e5 100644
--- a/BurnOutSharp/FileType/TapeArchive.cs
+++ b/BurnOutSharp/FileType/TapeArchive.cs
@@ -67,29 +67,10 @@ namespace BurnOutSharp.FileType
// If the tar file itself fails
try
{
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- using (TarArchive tarFile = TarArchive.Open(stream))
- {
- foreach (var entry in tarFile.Entries)
- {
- // If an individual entry fails
- try
- {
- // If we have a directory, skip it
- if (entry.IsDirectory)
- continue;
-
- string tempFile = Path.Combine(tempPath, entry.Key);
- entry.WriteToFile(tempFile);
- }
- catch (Exception ex)
- {
- if (scanner.IncludeDebug) Console.WriteLine(ex);
- }
- }
- }
+ // Extract and get the output path
+ string tempPath = Extract(stream, file);
+ if (tempPath == null)
+ return null;
// Collect and format all found protections
var protections = scanner.GetProtections(tempPath);
diff --git a/BurnOutSharp/FileType/VBSP.cs b/BurnOutSharp/FileType/VBSP.cs
index a2dca8f8..59d4cd61 100644
--- a/BurnOutSharp/FileType/VBSP.cs
+++ b/BurnOutSharp/FileType/VBSP.cs
@@ -60,17 +60,11 @@ namespace BurnOutSharp.FileType
// If the VBSP file itself fails
try
{
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- // Create the wrapper
- BinaryObjectScanner.Wrappers.VBSP vbsp = BinaryObjectScanner.Wrappers.VBSP.Create(stream);
- if (vbsp == null)
+ // Extract and get the output path
+ string tempPath = Extract(stream, file);
+ if (tempPath == null)
return null;
- // Loop through and extract all files
- vbsp.ExtractAllLumps(tempPath);
-
// Collect and format all found protections
var protections = scanner.GetProtections(tempPath);
diff --git a/BurnOutSharp/FileType/VPK.cs b/BurnOutSharp/FileType/VPK.cs
index e87c6881..71119689 100644
--- a/BurnOutSharp/FileType/VPK.cs
+++ b/BurnOutSharp/FileType/VPK.cs
@@ -60,17 +60,11 @@ namespace BurnOutSharp.FileType
// If the VPK file itself fails
try
{
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- // Create the wrapper
- BinaryObjectScanner.Wrappers.VPK vpk = BinaryObjectScanner.Wrappers.VPK.Create(stream);
- if (vpk == null)
+ // Extract and get the output path
+ string tempPath = Extract(stream, file);
+ if (tempPath == null)
return null;
- // Loop through and extract all files
- vpk.ExtractAll(tempPath);
-
// Collect and format all found protections
var protections = scanner.GetProtections(tempPath);
diff --git a/BurnOutSharp/FileType/WAD.cs b/BurnOutSharp/FileType/WAD.cs
index 4f1a9d66..ea098ed2 100644
--- a/BurnOutSharp/FileType/WAD.cs
+++ b/BurnOutSharp/FileType/WAD.cs
@@ -60,17 +60,11 @@ namespace BurnOutSharp.FileType
// If the WAD file itself fails
try
{
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- // Create the wrapper
- BinaryObjectScanner.Wrappers.WAD wad = BinaryObjectScanner.Wrappers.WAD.Create(stream);
- if (wad == null)
+ // Extract and get the output path
+ string tempPath = Extract(stream, file);
+ if (tempPath == null)
return null;
- // Loop through and extract all files
- wad.ExtractAllLumps(tempPath);
-
// Collect and format all found protections
var protections = scanner.GetProtections(tempPath);
diff --git a/BurnOutSharp/FileType/XZ.cs b/BurnOutSharp/FileType/XZ.cs
index 6f973b57..42aea043 100644
--- a/BurnOutSharp/FileType/XZ.cs
+++ b/BurnOutSharp/FileType/XZ.cs
@@ -62,25 +62,10 @@ namespace BurnOutSharp.FileType
// If the xz file itself fails
try
{
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- using (XZStream xzFile = new XZStream(stream))
- {
- // If an individual entry fails
- try
- {
- string tempFile = Path.Combine(tempPath, Guid.NewGuid().ToString());
- using (FileStream fs = File.OpenWrite(tempFile))
- {
- xzFile.CopyTo(fs);
- }
- }
- catch (Exception ex)
- {
- if (scanner.IncludeDebug) Console.WriteLine(ex);
- }
- }
+ // Extract and get the output path
+ string tempPath = Extract(stream, file);
+ if (tempPath == null)
+ return null;
// Collect and format all found protections
var protections = scanner.GetProtections(tempPath);
diff --git a/BurnOutSharp/FileType/XZP.cs b/BurnOutSharp/FileType/XZP.cs
index 7c1b7de1..ceeab3b9 100644
--- a/BurnOutSharp/FileType/XZP.cs
+++ b/BurnOutSharp/FileType/XZP.cs
@@ -60,17 +60,11 @@ namespace BurnOutSharp.FileType
// If the XZP file itself fails
try
{
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- // Create the wrapper
- BinaryObjectScanner.Wrappers.XZP xzp = BinaryObjectScanner.Wrappers.XZP.Create(stream);
- if (xzp == null)
+ // Extract and get the output path
+ string tempPath = Extract(stream, file);
+ if (tempPath == null)
return null;
- // Loop through and extract all files
- xzp.ExtractAll(tempPath);
-
// Collect and format all found protections
var protections = scanner.GetProtections(tempPath);