diff --git a/BinaryObjectScanner.Interfaces/IExtractable.cs b/BinaryObjectScanner.Interfaces/IExtractable.cs
index 53f83e45..d8dceabc 100644
--- a/BinaryObjectScanner.Interfaces/IExtractable.cs
+++ b/BinaryObjectScanner.Interfaces/IExtractable.cs
@@ -5,26 +5,25 @@ namespace BinaryObjectScanner.Interfaces
///
/// Mark a file type as being able to be extracted
///
+ /// TODO: Add debug flag to both of the declarations
public interface IExtractable
{
///
/// Scan a file for all internal protections
///
/// Path to the input file
+ /// True to include debug data, false otherwise
/// Path to extracted files, null on error
- ///
- /// Ideally, this should just point to the other extract implementation.
- /// It is expected that the calling method will provide exception handling.
- ///
- string Extract(string file);
+ /// Ideally, this should just point to the other extract implementation.
+ string Extract(string file, bool includeDebug);
///
/// Scan a stream for all internal protections
///
/// Stream representing the input file
/// Path to the input file
+ /// True to include debug data, false otherwise
/// Path to extracted files, null on error
- /// It is expected that the calling method will provide exception handling.
- string Extract(Stream stream, string file);
+ string Extract(Stream stream, string file, bool includeDebug);
}
}
diff --git a/BurnOutSharp/FileType/BFPK.cs b/BurnOutSharp/FileType/BFPK.cs
index b5fbcc3e..e5e4450a 100644
--- a/BurnOutSharp/FileType/BFPK.cs
+++ b/BurnOutSharp/FileType/BFPK.cs
@@ -10,33 +10,41 @@ namespace BurnOutSharp.FileType
public class BFPK : IExtractable
{
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
- // Create the wrapper
- BinaryObjectScanner.Wrappers.BFPK bfpk = BinaryObjectScanner.Wrappers.BFPK.Create(stream);
- if (bfpk == null)
+ try
+ {
+ // Create the wrapper
+ BinaryObjectScanner.Wrappers.BFPK bfpk = BinaryObjectScanner.Wrappers.BFPK.Create(stream);
+ if (bfpk == null)
+ return null;
+
+ // Create a temp output directory
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ // Extract all files
+ bfpk.ExtractAll(tempPath);
+
+ return tempPath;
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
return null;
-
- // Create a temp output directory
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- // Extract all files
- bfpk.ExtractAll(tempPath);
-
- return tempPath;
+ }
}
}
}
diff --git a/BurnOutSharp/FileType/BSP.cs b/BurnOutSharp/FileType/BSP.cs
index 131b470a..07203545 100644
--- a/BurnOutSharp/FileType/BSP.cs
+++ b/BurnOutSharp/FileType/BSP.cs
@@ -10,34 +10,42 @@ namespace BurnOutSharp.FileType
public class BSP : IExtractable
{
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
- // Create the wrapper
- BinaryObjectScanner.Wrappers.BSP bsp = BinaryObjectScanner.Wrappers.BSP.Create(stream);
- if (bsp == null)
+ try
+ {
+ // Create the wrapper
+ BinaryObjectScanner.Wrappers.BSP bsp = BinaryObjectScanner.Wrappers.BSP.Create(stream);
+ if (bsp == null)
+ return null;
+
+ // Create a temp output directory
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ // Loop through and extract all files
+ bsp.ExtractAllLumps(tempPath);
+ bsp.ExtractAllTextures(tempPath);
+
+ return tempPath;
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
return null;
-
- // Create a temp output directory
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- // Loop through and extract all files
- bsp.ExtractAllLumps(tempPath);
- bsp.ExtractAllTextures(tempPath);
-
- return tempPath;
+ }
}
}
}
diff --git a/BurnOutSharp/FileType/BZip2.cs b/BurnOutSharp/FileType/BZip2.cs
index 022821c1..083879c0 100644
--- a/BurnOutSharp/FileType/BZip2.cs
+++ b/BurnOutSharp/FileType/BZip2.cs
@@ -12,34 +12,42 @@ namespace BurnOutSharp.FileType
public class BZip2 : IExtractable
{
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
- // Create a temp output directory
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- using (BZip2Stream bz2File = new BZip2Stream(stream, CompressionMode.Decompress, true))
+ try
{
- string tempFile = Path.Combine(tempPath, Guid.NewGuid().ToString());
- using (FileStream fs = File.OpenWrite(tempFile))
- {
- bz2File.CopyTo(fs);
- }
- }
+ // Create a temp output directory
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
- return tempPath;
+ using (BZip2Stream bz2File = new BZip2Stream(stream, CompressionMode.Decompress, true))
+ {
+ string tempFile = Path.Combine(tempPath, Guid.NewGuid().ToString());
+ using (FileStream fs = File.OpenWrite(tempFile))
+ {
+ bz2File.CopyTo(fs);
+ }
+ }
+
+ return tempPath;
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
+ return null;
+ }
}
}
}
diff --git a/BurnOutSharp/FileType/CFB.cs b/BurnOutSharp/FileType/CFB.cs
index 8b56d605..b69169c8 100644
--- a/BurnOutSharp/FileType/CFB.cs
+++ b/BurnOutSharp/FileType/CFB.cs
@@ -12,60 +12,75 @@ namespace BurnOutSharp.FileType
public class CFB : IExtractable
{
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
- // Create a temp output directory
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- using (CompoundFile msi = new CompoundFile(stream, CFSUpdateMode.ReadOnly, CFSConfiguration.Default))
+ try
{
- msi.RootStorage.VisitEntries((e) =>
+ // Create a temp output directory
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ using (CompoundFile msi = new CompoundFile(stream, CFSUpdateMode.ReadOnly, CFSConfiguration.Default))
{
- 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())
+ msi.RootStorage.VisitEntries((e) =>
{
- decoded = decoded.Replace(c, '_');
- }
+ try
+ {
+ if (!e.IsStream)
+ return;
- string filename = Path.Combine(tempPath, decoded);
- using (Stream fs = File.OpenWrite(filename))
- {
- fs.Write(strData, 0, strData.Length);
- }
- }, recursive: true);
+ 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);
+ }
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
+ }
+ }, recursive: true);
+ }
+
+ return tempPath;
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
+ return null;
}
-
- return tempPath;
}
/// Adapted from LibMSI
diff --git a/BurnOutSharp/FileType/Executable.cs b/BurnOutSharp/FileType/Executable.cs
index 734181b7..0dddfcf2 100644
--- a/BurnOutSharp/FileType/Executable.cs
+++ b/BurnOutSharp/FileType/Executable.cs
@@ -17,6 +17,9 @@ namespace BurnOutSharp.FileType
/// In order to achiveve this, Executable specifically needs a way of supporting the Packer types (IExtractable) in such
/// a way that we don't scan the files two times over. Somehow, we need to make Executable IExtractable as well and then
/// take the outputs of `Scan` and figure out if we need to try extracting or not.
+ ///
+ /// Since Options is a separate class now, that should be passed in instead of Scanner, so that we only have to worry about
+ /// what the user or implementer was requesting.
public class Executable : IScannable
{
///
@@ -82,7 +85,7 @@ namespace BurnOutSharp.FileType
try
{
// Extract and get the output path
- string tempPath = extractable.Extract(stream, file);
+ string tempPath = extractable.Extract(stream, file, scanner.IncludeDebug);
if (tempPath != null)
return;
@@ -138,7 +141,7 @@ namespace BurnOutSharp.FileType
try
{
// Extract and get the output path
- string tempPath = extractable.Extract(stream, file);
+ string tempPath = extractable.Extract(stream, file, scanner.IncludeDebug);
if (tempPath != null)
return;
@@ -194,7 +197,7 @@ namespace BurnOutSharp.FileType
try
{
// Extract and get the output path
- string tempPath = extractable.Extract(stream, file);
+ string tempPath = extractable.Extract(stream, file, scanner.IncludeDebug);
if (tempPath != null)
return;
diff --git a/BurnOutSharp/FileType/GCF.cs b/BurnOutSharp/FileType/GCF.cs
index b7d1063c..47d292f2 100644
--- a/BurnOutSharp/FileType/GCF.cs
+++ b/BurnOutSharp/FileType/GCF.cs
@@ -10,33 +10,41 @@ namespace BurnOutSharp.FileType
public class GCF : IExtractable
{
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
- // Create the wrapper
- BinaryObjectScanner.Wrappers.GCF gcf = BinaryObjectScanner.Wrappers.GCF.Create(stream);
- if (gcf == null)
+ try
+ {
+ // Create the wrapper
+ BinaryObjectScanner.Wrappers.GCF gcf = BinaryObjectScanner.Wrappers.GCF.Create(stream);
+ if (gcf == null)
+ return null;
+
+ // Create a temp output directory
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ // Loop through and extract all files
+ gcf.ExtractAll(tempPath);
+
+ return tempPath;
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
return null;
-
- // Create a temp output directory
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- // Loop through and extract all files
- gcf.ExtractAll(tempPath);
-
- return tempPath;
+ }
}
}
}
diff --git a/BurnOutSharp/FileType/GZIP.cs b/BurnOutSharp/FileType/GZIP.cs
index d1691f9b..46125465 100644
--- a/BurnOutSharp/FileType/GZIP.cs
+++ b/BurnOutSharp/FileType/GZIP.cs
@@ -12,38 +12,53 @@ namespace BurnOutSharp.FileType
public class GZIP : IExtractable
{
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
- // Create a temp output directory
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- using (GZipArchive zipFile = GZipArchive.Open(stream))
+ try
{
- foreach (var entry in zipFile.Entries)
+ // Create a temp output directory
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ using (GZipArchive zipFile = GZipArchive.Open(stream))
{
- // If we have a directory, skip it
- if (entry.IsDirectory)
- continue;
+ foreach (var entry in zipFile.Entries)
+ {
+ try
+ {
+ // If we have a directory, skip it
+ if (entry.IsDirectory)
+ continue;
- string tempFile = Path.Combine(tempPath, entry.Key);
- entry.WriteToFile(tempFile);
+ string tempFile = Path.Combine(tempPath, entry.Key);
+ entry.WriteToFile(tempFile);
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
+ }
+ }
}
- }
- return tempPath;
+ return tempPath;
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
+ return null;
+ }
}
}
}
diff --git a/BurnOutSharp/FileType/InstallShieldArchiveV3.cs b/BurnOutSharp/FileType/InstallShieldArchiveV3.cs
index fc2a77d9..e535c31c 100644
--- a/BurnOutSharp/FileType/InstallShieldArchiveV3.cs
+++ b/BurnOutSharp/FileType/InstallShieldArchiveV3.cs
@@ -12,42 +12,57 @@ namespace BurnOutSharp.FileType
public class InstallShieldArchiveV3 : IExtractable
{
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
- // Create a temp output directory
- 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))
+ try
{
- string tempFile = Path.Combine(tempPath, cfile.FullPath);
- if (!Directory.Exists(Path.GetDirectoryName(tempFile)))
- Directory.CreateDirectory(Path.GetDirectoryName(tempFile));
+ // Create a temp output directory
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
- (byte[] fileContents, string error) = archive.Extract(cfile.FullPath);
- if (!string.IsNullOrWhiteSpace(error))
- continue;
-
- using (FileStream fs = File.OpenWrite(tempFile))
+ UnshieldSharp.Archive.InstallShieldArchiveV3 archive = new UnshieldSharp.Archive.InstallShieldArchiveV3(file);
+ foreach (CompressedFile cfile in archive.Files.Select(kvp => kvp.Value))
{
- fs.Write(fileContents, 0, fileContents.Length);
- }
- }
+ try
+ {
+ string tempFile = Path.Combine(tempPath, cfile.FullPath);
+ if (!Directory.Exists(Path.GetDirectoryName(tempFile)))
+ Directory.CreateDirectory(Path.GetDirectoryName(tempFile));
- return tempPath;
+ (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 (includeDebug) Console.WriteLine(ex);
+ }
+ }
+
+ return tempPath;
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
+ return null;
+ }
}
}
}
diff --git a/BurnOutSharp/FileType/InstallShieldCAB.cs b/BurnOutSharp/FileType/InstallShieldCAB.cs
index 91296ffb..812c20aa 100644
--- a/BurnOutSharp/FileType/InstallShieldCAB.cs
+++ b/BurnOutSharp/FileType/InstallShieldCAB.cs
@@ -12,19 +12,19 @@ namespace BurnOutSharp.FileType
public class InstallShieldCAB : IExtractable
{
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
// Get the name of the first cabinet file or header
string directory = Path.GetDirectoryName(file);
@@ -41,32 +41,47 @@ namespace BurnOutSharp.FileType
if (!shouldScanCabinet)
return null;
- // Create a temp output directory
- 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++)
+ try
{
- // Check if the file is valid first
- if (!cabfile.FileIsValid(i))
- continue;
+ // Create a temp output directory
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
- string tempFile;
- try
+ InstallShieldCabinet cabfile = InstallShieldCabinet.Open(file);
+ for (int i = 0; i < cabfile.FileCount; i++)
{
- string filename = cabfile.FileName(i);
- tempFile = Path.Combine(tempPath, filename);
- }
- catch
- {
- tempFile = Path.Combine(tempPath, $"BAD_FILENAME{i}");
+ 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 (includeDebug) Console.WriteLine(ex);
+ }
}
- cabfile.FileSave(i, tempFile);
+ return tempPath;
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
+ return null;
}
-
- return tempPath;
}
}
}
diff --git a/BurnOutSharp/FileType/MPQ.cs b/BurnOutSharp/FileType/MPQ.cs
index 1deaf37b..f0a49b79 100644
--- a/BurnOutSharp/FileType/MPQ.cs
+++ b/BurnOutSharp/FileType/MPQ.cs
@@ -13,58 +13,73 @@ namespace BurnOutSharp.FileType
public class MPQ : IExtractable
{
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
// TODO: Add stream opening support
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
#if NET6_0_OR_GREATER
// Not supported for .NET 6.0 due to Windows DLL requirements
return null;
#else
- // Create a temp output directory
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- using (MpqArchive mpqArchive = new MpqArchive(file, FileAccess.Read))
+ try
{
- // Try to open the listfile
- string listfile = null;
- MpqFileStream listStream = mpqArchive.OpenFile("(listfile)");
+ // Create a temp output directory
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
- // 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))
+ using (MpqArchive mpqArchive = new MpqArchive(file, FileAccess.Read))
{
- listfile = sr.ReadToEnd();
+ // 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)
+ {
+ try
+ {
+ string tempFile = Path.Combine(tempPath, sub);
+ Directory.CreateDirectory(Path.GetDirectoryName(tempFile));
+ mpqArchive.ExtractFile(sub, tempFile);
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
+ }
+ }
}
- // Split the listfile by newlines
- string[] listfileLines = listfile.Replace("\r\n", "\n").Split('\n');
-
- // Loop over each entry
- foreach (string sub in listfileLines)
- {
- string tempFile = Path.Combine(tempPath, sub);
- Directory.CreateDirectory(Path.GetDirectoryName(tempFile));
- mpqArchive.ExtractFile(sub, tempFile);
- }
+ return tempPath;
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
+ return null;
}
-
- return tempPath;
#endif
}
}
diff --git a/BurnOutSharp/FileType/MicrosoftCAB.cs b/BurnOutSharp/FileType/MicrosoftCAB.cs
index e65e3e83..4e476cdd 100644
--- a/BurnOutSharp/FileType/MicrosoftCAB.cs
+++ b/BurnOutSharp/FileType/MicrosoftCAB.cs
@@ -13,35 +13,43 @@ namespace BurnOutSharp.FileType
public class MicrosoftCAB : IExtractable
{
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
- // Open the cab file
- var cabFile = MicrosoftCabinet.Create(stream);
- if (cabFile == null)
+ try
+ {
+ // Open the cab file
+ var cabFile = MicrosoftCabinet.Create(stream);
+ if (cabFile == null)
+ return null;
+
+ // Create a temp output directory
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ // If entry extraction fails
+ bool success = cabFile.ExtractAll(tempPath);
+ if (!success)
+ return null;
+
+ return tempPath;
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
return null;
-
- // Create a temp output directory
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- // If entry extraction fails
- bool success = cabFile.ExtractAll(tempPath);
- if (!success)
- return null;
-
- return tempPath;
+ }
}
}
}
diff --git a/BurnOutSharp/FileType/MicrosoftLZ.cs b/BurnOutSharp/FileType/MicrosoftLZ.cs
index d0c52901..5aedec4b 100644
--- a/BurnOutSharp/FileType/MicrosoftLZ.cs
+++ b/BurnOutSharp/FileType/MicrosoftLZ.cs
@@ -12,47 +12,55 @@ namespace BurnOutSharp.FileType
public class MicrosoftLZ : IExtractable
{
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
- // Create a temp output directory
- 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))
+ try
{
- 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";
+ // Create a temp output directory
+ 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);
+ }
+
+ return tempPath;
}
-
- 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))
+ catch (Exception ex)
{
- tempStream.Write(data, 0, data.Length);
+ if (includeDebug) Console.WriteLine(ex);
+ return null;
}
-
- return tempPath;
}
}
}
diff --git a/BurnOutSharp/FileType/PAK.cs b/BurnOutSharp/FileType/PAK.cs
index 38180fc0..106b24d2 100644
--- a/BurnOutSharp/FileType/PAK.cs
+++ b/BurnOutSharp/FileType/PAK.cs
@@ -10,33 +10,41 @@ namespace BurnOutSharp.FileType
public class PAK : IExtractable
{
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
- // Create the wrapper
- BinaryObjectScanner.Wrappers.PAK pak = BinaryObjectScanner.Wrappers.PAK.Create(stream);
- if (pak == null)
+ try
+ {
+ // Create the wrapper
+ BinaryObjectScanner.Wrappers.PAK pak = BinaryObjectScanner.Wrappers.PAK.Create(stream);
+ if (pak == null)
+ return null;
+
+ // Create a temp output directory
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ // Loop through and extract all files
+ pak.ExtractAll(tempPath);
+
+ return tempPath;
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
return null;
-
- // Create a temp output directory
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- // Loop through and extract all files
- pak.ExtractAll(tempPath);
-
- return tempPath;
+ }
}
}
}
diff --git a/BurnOutSharp/FileType/PFF.cs b/BurnOutSharp/FileType/PFF.cs
index 31f95716..9756bcf1 100644
--- a/BurnOutSharp/FileType/PFF.cs
+++ b/BurnOutSharp/FileType/PFF.cs
@@ -10,33 +10,41 @@ namespace BurnOutSharp.FileType
public class PFF : IExtractable
{
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
- // Create the wrapper
- BinaryObjectScanner.Wrappers.PFF pff = BinaryObjectScanner.Wrappers.PFF.Create(stream);
- if (pff == null)
+ try
+ {
+ // Create the wrapper
+ BinaryObjectScanner.Wrappers.PFF pff = BinaryObjectScanner.Wrappers.PFF.Create(stream);
+ if (pff == null)
+ return null;
+
+ // Create a temp output directory
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ // Extract all files
+ pff.ExtractAll(tempPath);
+
+ return tempPath;
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex.Message);
return null;
-
- // Create a temp output directory
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- // Extract all files
- pff.ExtractAll(tempPath);
-
- return tempPath;
+ }
}
}
}
diff --git a/BurnOutSharp/FileType/PKZIP.cs b/BurnOutSharp/FileType/PKZIP.cs
index 057be339..55bb5ff0 100644
--- a/BurnOutSharp/FileType/PKZIP.cs
+++ b/BurnOutSharp/FileType/PKZIP.cs
@@ -12,39 +12,54 @@ namespace BurnOutSharp.FileType
public class PKZIP : IExtractable
{
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
- // Create a temp output directory
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- using (ZipArchive zipFile = ZipArchive.Open(stream))
+ try
{
- foreach (var entry in zipFile.Entries)
+ // Create a temp output directory
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ using (ZipArchive zipFile = ZipArchive.Open(stream))
{
- // If we have a directory, skip it
- if (entry.IsDirectory)
- continue;
+ foreach (var entry in zipFile.Entries)
+ {
+ 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);
+ string tempFile = Path.Combine(tempPath, entry.Key);
+ Directory.CreateDirectory(Path.GetDirectoryName(tempFile));
+ entry.WriteToFile(tempFile);
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
+ }
+ }
}
- }
- return tempPath;
+ return tempPath;
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
+ return null;
+ }
}
}
}
diff --git a/BurnOutSharp/FileType/RAR.cs b/BurnOutSharp/FileType/RAR.cs
index 86e98a3a..1a168076 100644
--- a/BurnOutSharp/FileType/RAR.cs
+++ b/BurnOutSharp/FileType/RAR.cs
@@ -12,38 +12,53 @@ namespace BurnOutSharp.FileType
public class RAR : IExtractable
{
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
- // Create a temp output directory
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- using (RarArchive rarFile = RarArchive.Open(stream))
+ try
{
- foreach (var entry in rarFile.Entries)
+ // Create a temp output directory
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ using (RarArchive rarFile = RarArchive.Open(stream))
{
- // If we have a directory, skip it
- if (entry.IsDirectory)
- continue;
+ foreach (var entry in rarFile.Entries)
+ {
+ try
+ {
+ // If we have a directory, skip it
+ if (entry.IsDirectory)
+ continue;
- string tempFile = Path.Combine(tempPath, entry.Key);
- entry.WriteToFile(tempFile);
+ string tempFile = Path.Combine(tempPath, entry.Key);
+ entry.WriteToFile(tempFile);
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
+ }
+ }
}
- }
- return tempPath;
+ return tempPath;
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
+ return null;
+ }
}
}
}
diff --git a/BurnOutSharp/FileType/SFFS.cs b/BurnOutSharp/FileType/SFFS.cs
index 28107810..1b0f384d 100644
--- a/BurnOutSharp/FileType/SFFS.cs
+++ b/BurnOutSharp/FileType/SFFS.cs
@@ -14,19 +14,19 @@ namespace BurnOutSharp.FileType
public class SFFS : IExtractable, IScannable
{
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
return null;
}
diff --git a/BurnOutSharp/FileType/SGA.cs b/BurnOutSharp/FileType/SGA.cs
index d081afc5..db69f012 100644
--- a/BurnOutSharp/FileType/SGA.cs
+++ b/BurnOutSharp/FileType/SGA.cs
@@ -10,33 +10,41 @@ namespace BurnOutSharp.FileType
public class SGA : IExtractable
{
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
- // Create the wrapper
- BinaryObjectScanner.Wrappers.SGA sga = BinaryObjectScanner.Wrappers.SGA.Create(stream);
- if (sga == null)
+ try
+ {
+ // Create the wrapper
+ BinaryObjectScanner.Wrappers.SGA sga = BinaryObjectScanner.Wrappers.SGA.Create(stream);
+ if (sga == null)
+ return null;
+
+ // Create a temp output directory
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ // Loop through and extract all files
+ sga.ExtractAll(tempPath);
+
+ return tempPath;
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
return null;
-
- // Create a temp output directory
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- // Loop through and extract all files
- sga.ExtractAll(tempPath);
-
- return tempPath;
+ }
}
}
}
diff --git a/BurnOutSharp/FileType/SevenZip.cs b/BurnOutSharp/FileType/SevenZip.cs
index 06250b28..3598b60d 100644
--- a/BurnOutSharp/FileType/SevenZip.cs
+++ b/BurnOutSharp/FileType/SevenZip.cs
@@ -12,38 +12,53 @@ namespace BurnOutSharp.FileType
public class SevenZip : IExtractable
{
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
- // Create a temp output directory
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- using (SevenZipArchive sevenZipFile = SevenZipArchive.Open(stream))
+ try
{
- foreach (var entry in sevenZipFile.Entries)
+ // Create a temp output directory
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ using (SevenZipArchive sevenZipFile = SevenZipArchive.Open(stream))
{
- // If we have a directory, skip it
- if (entry.IsDirectory)
- continue;
+ foreach (var entry in sevenZipFile.Entries)
+ {
+ try
+ {
+ // If we have a directory, skip it
+ if (entry.IsDirectory)
+ continue;
- string tempFile = Path.Combine(tempPath, entry.Key);
- entry.WriteToFile(tempFile);
+ string tempFile = Path.Combine(tempPath, entry.Key);
+ entry.WriteToFile(tempFile);
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
+ }
+ }
}
- }
- return tempPath;
+ return tempPath;
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
+ return null;
+ }
}
}
}
diff --git a/BurnOutSharp/FileType/TapeArchive.cs b/BurnOutSharp/FileType/TapeArchive.cs
index aa032995..53b4eb58 100644
--- a/BurnOutSharp/FileType/TapeArchive.cs
+++ b/BurnOutSharp/FileType/TapeArchive.cs
@@ -12,38 +12,53 @@ namespace BurnOutSharp.FileType
public class TapeArchive : IExtractable
{
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
- // Create a temp output directory
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- using (TarArchive tarFile = TarArchive.Open(stream))
+ try
{
- foreach (var entry in tarFile.Entries)
+ // Create a temp output directory
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ using (TarArchive tarFile = TarArchive.Open(stream))
{
- // If we have a directory, skip it
- if (entry.IsDirectory)
- continue;
+ foreach (var entry in tarFile.Entries)
+ {
+ try
+ {
+ // If we have a directory, skip it
+ if (entry.IsDirectory)
+ continue;
- string tempFile = Path.Combine(tempPath, entry.Key);
- entry.WriteToFile(tempFile);
+ string tempFile = Path.Combine(tempPath, entry.Key);
+ entry.WriteToFile(tempFile);
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
+ }
+ }
}
- }
- return tempPath;
+ return tempPath;
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
+ return null;
+ }
}
}
}
diff --git a/BurnOutSharp/FileType/VBSP.cs b/BurnOutSharp/FileType/VBSP.cs
index 9e3f1540..bf46152e 100644
--- a/BurnOutSharp/FileType/VBSP.cs
+++ b/BurnOutSharp/FileType/VBSP.cs
@@ -10,33 +10,41 @@ namespace BurnOutSharp.FileType
public class VBSP : IExtractable
{
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
- // Create the wrapper
- BinaryObjectScanner.Wrappers.VBSP vbsp = BinaryObjectScanner.Wrappers.VBSP.Create(stream);
- if (vbsp == null)
+ try
+ {
+ // Create the wrapper
+ BinaryObjectScanner.Wrappers.VBSP vbsp = BinaryObjectScanner.Wrappers.VBSP.Create(stream);
+ if (vbsp == null)
+ return null;
+
+ // Create a temp output directory
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ // Loop through and extract all files
+ vbsp.ExtractAllLumps(tempPath);
+
+ return tempPath;
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex.ToString());
return null;
-
- // Create a temp output directory
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- // Loop through and extract all files
- vbsp.ExtractAllLumps(tempPath);
-
- return tempPath;
+ }
}
}
}
diff --git a/BurnOutSharp/FileType/VPK.cs b/BurnOutSharp/FileType/VPK.cs
index ae6a1f70..1a5cb172 100644
--- a/BurnOutSharp/FileType/VPK.cs
+++ b/BurnOutSharp/FileType/VPK.cs
@@ -10,33 +10,41 @@ namespace BurnOutSharp.FileType
public class VPK : IExtractable
{
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
- // Create the wrapper
- BinaryObjectScanner.Wrappers.VPK vpk = BinaryObjectScanner.Wrappers.VPK.Create(stream);
- if (vpk == null)
+ try
+ {
+ // Create the wrapper
+ BinaryObjectScanner.Wrappers.VPK vpk = BinaryObjectScanner.Wrappers.VPK.Create(stream);
+ if (vpk == null)
+ return null;
+
+ // Create a temp output directory
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ // Loop through and extract all files
+ vpk.ExtractAll(tempPath);
+
+ return tempPath;
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
return null;
-
- // Create a temp output directory
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- // Loop through and extract all files
- vpk.ExtractAll(tempPath);
-
- return tempPath;
+ }
}
}
}
diff --git a/BurnOutSharp/FileType/WAD.cs b/BurnOutSharp/FileType/WAD.cs
index 5db71400..e399fdfb 100644
--- a/BurnOutSharp/FileType/WAD.cs
+++ b/BurnOutSharp/FileType/WAD.cs
@@ -10,33 +10,41 @@ namespace BurnOutSharp.FileType
public class WAD : IExtractable
{
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
- // Create the wrapper
- BinaryObjectScanner.Wrappers.WAD wad = BinaryObjectScanner.Wrappers.WAD.Create(stream);
- if (wad == null)
+ try
+ {
+ // Create the wrapper
+ BinaryObjectScanner.Wrappers.WAD wad = BinaryObjectScanner.Wrappers.WAD.Create(stream);
+ if (wad == null)
+ return null;
+
+ // Create a temp output directory
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ // Loop through and extract all files
+ wad.ExtractAllLumps(tempPath);
+
+ return tempPath;
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
return null;
-
- // Create a temp output directory
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- // Loop through and extract all files
- wad.ExtractAllLumps(tempPath);
-
- return tempPath;
+ }
}
}
}
diff --git a/BurnOutSharp/FileType/XZ.cs b/BurnOutSharp/FileType/XZ.cs
index 0c66e1ca..71ce2567 100644
--- a/BurnOutSharp/FileType/XZ.cs
+++ b/BurnOutSharp/FileType/XZ.cs
@@ -11,34 +11,42 @@ namespace BurnOutSharp.FileType
public class XZ : IExtractable
{
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
- // Create a temp output directory
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- using (XZStream xzFile = new XZStream(stream))
+ try
{
- string tempFile = Path.Combine(tempPath, Guid.NewGuid().ToString());
- using (FileStream fs = File.OpenWrite(tempFile))
- {
- xzFile.CopyTo(fs);
- }
- }
+ // Create a temp output directory
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
- return tempPath;
+ using (XZStream xzFile = new XZStream(stream))
+ {
+ string tempFile = Path.Combine(tempPath, Guid.NewGuid().ToString());
+ using (FileStream fs = File.OpenWrite(tempFile))
+ {
+ xzFile.CopyTo(fs);
+ }
+ }
+
+ return tempPath;
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
+ return null;
+ }
}
}
}
diff --git a/BurnOutSharp/FileType/XZP.cs b/BurnOutSharp/FileType/XZP.cs
index 6889051f..85a2090b 100644
--- a/BurnOutSharp/FileType/XZP.cs
+++ b/BurnOutSharp/FileType/XZP.cs
@@ -10,33 +10,41 @@ namespace BurnOutSharp.FileType
public class XZP : IExtractable
{
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
- // Create the wrapper
- BinaryObjectScanner.Wrappers.XZP xzp = BinaryObjectScanner.Wrappers.XZP.Create(stream);
- if (xzp == null)
+ try
+ {
+ // Create the wrapper
+ BinaryObjectScanner.Wrappers.XZP xzp = BinaryObjectScanner.Wrappers.XZP.Create(stream);
+ if (xzp == null)
+ return null;
+
+ // Create a temp output directory
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ // Loop through and extract all files
+ xzp.ExtractAll(tempPath);
+
+ return tempPath;
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
return null;
-
- // Create a temp output directory
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- // Loop through and extract all files
- xzp.ExtractAll(tempPath);
-
- return tempPath;
+ }
}
}
}
diff --git a/BurnOutSharp/PackerType/ASPack.cs b/BurnOutSharp/PackerType/ASPack.cs
index f375bb6d..e6dd2b8b 100644
--- a/BurnOutSharp/PackerType/ASPack.cs
+++ b/BurnOutSharp/PackerType/ASPack.cs
@@ -51,19 +51,19 @@ namespace BurnOutSharp.PackerType
}
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
return null;
}
diff --git a/BurnOutSharp/PackerType/AdvancedInstaller.cs b/BurnOutSharp/PackerType/AdvancedInstaller.cs
index 1a87ea40..98279221 100644
--- a/BurnOutSharp/PackerType/AdvancedInstaller.cs
+++ b/BurnOutSharp/PackerType/AdvancedInstaller.cs
@@ -30,19 +30,19 @@ namespace BurnOutSharp.PackerType
}
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
return null;
}
diff --git a/BurnOutSharp/PackerType/Armadillo.cs b/BurnOutSharp/PackerType/Armadillo.cs
index 9e706656..2c07ac2a 100644
--- a/BurnOutSharp/PackerType/Armadillo.cs
+++ b/BurnOutSharp/PackerType/Armadillo.cs
@@ -40,19 +40,19 @@ namespace BurnOutSharp.PackerType
}
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
return null;
}
diff --git a/BurnOutSharp/PackerType/AutoPlayMediaStudio.cs b/BurnOutSharp/PackerType/AutoPlayMediaStudio.cs
index 57719366..9f860e66 100644
--- a/BurnOutSharp/PackerType/AutoPlayMediaStudio.cs
+++ b/BurnOutSharp/PackerType/AutoPlayMediaStudio.cs
@@ -34,19 +34,19 @@ namespace BurnOutSharp.PackerType
}
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
return null;
}
diff --git a/BurnOutSharp/PackerType/CExe.cs b/BurnOutSharp/PackerType/CExe.cs
index d2051eaf..96ac3da3 100644
--- a/BurnOutSharp/PackerType/CExe.cs
+++ b/BurnOutSharp/PackerType/CExe.cs
@@ -48,89 +48,97 @@ namespace BurnOutSharp.PackerType
}
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
- // Parse into an executable again for easier extraction
- PortableExecutable pex = PortableExecutable.Create(stream);
- if (pex == null)
- return null;
-
- // Get the first resource of type 99 with index 2
- byte[] payload = pex.FindResourceByNamedType("99, 2").FirstOrDefault();
- if (payload == null || payload.Length == 0)
- return null;
-
- // Determine which compression was used
- bool zlib = pex.FindResourceByNamedType("99, 1").Any();
-
- // Create the output data buffer
- byte[] data;
-
- // If we had the decompression DLL included, it's zlib
- if (zlib)
+ try
{
- try
- {
- // Inflate the data into the buffer
- Inflater inflater = new Inflater();
- inflater.SetInput(payload);
- data = new byte[payload.Length * 4];
- int read = inflater.Inflate(data);
+ // Parse into an executable again for easier extraction
+ PortableExecutable pex = PortableExecutable.Create(stream);
+ if (pex == null)
+ return null;
- // Trim the buffer to the proper size
- data = new ReadOnlySpan(data, 0, read).ToArray();
- }
- catch
+ // Get the first resource of type 99 with index 2
+ byte[] payload = pex.FindResourceByNamedType("99, 2").FirstOrDefault();
+ if (payload == null || payload.Length == 0)
+ return null;
+
+ // Determine which compression was used
+ bool zlib = pex.FindResourceByNamedType("99, 1").Any();
+
+ // Create the output data buffer
+ byte[] data;
+
+ // If we had the decompression DLL included, it's zlib
+ if (zlib)
{
- // Reset the data
- data = null;
+ try
+ {
+ // Inflate the data into the buffer
+ Inflater inflater = new Inflater();
+ inflater.SetInput(payload);
+ data = new byte[payload.Length * 4];
+ int read = inflater.Inflate(data);
+
+ // Trim the buffer to the proper size
+ data = new ReadOnlySpan(data, 0, read).ToArray();
+ }
+ catch
+ {
+ // Reset the data
+ data = null;
+ }
}
+
+ // Otherwise, LZ is used via the Windows API
+ else
+ {
+ try
+ {
+ data = LZ.Decompress(payload);
+ }
+ catch
+ {
+ // Reset the data
+ data = null;
+ }
+ }
+
+ // If we have no data
+ if (data == null)
+ return null;
+
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ // Create the temp filename
+ string tempFile = string.IsNullOrEmpty(file) ? "temp.sxe" : $"{Path.GetFileNameWithoutExtension(file)}.sxe";
+ 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);
+ }
+
+ return tempPath;
}
-
- // Otherwise, LZ is used via the Windows API
- else
+ catch (Exception ex)
{
- try
- {
- data = LZ.Decompress(payload);
- }
- catch
- {
- // Reset the data
- data = null;
- }
- }
-
- // If we have no data
- if (data == null)
+ if (includeDebug) Console.WriteLine(ex);
return null;
-
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- // Create the temp filename
- string tempFile = string.IsNullOrEmpty(file) ? "temp.sxe" : $"{Path.GetFileNameWithoutExtension(file)}.sxe";
- 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);
}
-
- return tempPath;
}
}
}
diff --git a/BurnOutSharp/PackerType/EXEStealth.cs b/BurnOutSharp/PackerType/EXEStealth.cs
index ff05c063..352f17c6 100644
--- a/BurnOutSharp/PackerType/EXEStealth.cs
+++ b/BurnOutSharp/PackerType/EXEStealth.cs
@@ -75,19 +75,19 @@ namespace BurnOutSharp.PackerType
}
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
return null;
}
diff --git a/BurnOutSharp/PackerType/EmbeddedExecutable.cs b/BurnOutSharp/PackerType/EmbeddedExecutable.cs
index c98ba543..6c6e7db6 100644
--- a/BurnOutSharp/PackerType/EmbeddedExecutable.cs
+++ b/BurnOutSharp/PackerType/EmbeddedExecutable.cs
@@ -29,52 +29,67 @@ namespace BurnOutSharp.PackerType
}
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
- // Parse into an executable again for easier extraction
- PortableExecutable pex = PortableExecutable.Create(stream);
- if (pex?.ResourceData == null)
- return null;
-
- // Get the resources that have an executable signature
- var resources = pex.ResourceData
- .Where(kvp => kvp.Value != null && kvp.Value is byte[])
- .Where(kvp => (kvp.Value as byte[]).StartsWith(BinaryObjectScanner.Models.MSDOS.Constants.SignatureBytes))
- .ToList();
-
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- for (int i = 0; i < resources.Count; i++)
+ try
{
- // Get the resource data
- var resource = resources[i];
- byte[] data = resource.Value as byte[];
+ // Parse into an executable again for easier extraction
+ PortableExecutable pex = PortableExecutable.Create(stream);
+ if (pex?.ResourceData == null)
+ return null;
- // Create the temp filename
- string tempFile = $"embedded_resource_{i}.bin";
- tempFile = Path.Combine(tempPath, tempFile);
+ // Get the resources that have an executable signature
+ var resources = pex.ResourceData
+ .Where(kvp => kvp.Value != null && kvp.Value is byte[])
+ .Where(kvp => (kvp.Value as byte[]).StartsWith(BinaryObjectScanner.Models.MSDOS.Constants.SignatureBytes))
+ .ToList();
- // Write the resource data to a temp file
- using (Stream tempStream = File.Open(tempFile, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ for (int i = 0; i < resources.Count; i++)
{
- tempStream.Write(data, 0, data.Length);
- }
- }
+ try
+ {
+ // Get the resource data
+ var resource = resources[i];
+ byte[] data = resource.Value as byte[];
- return tempPath;
+ // Create the temp filename
+ string tempFile = $"embedded_resource_{i}.bin";
+ tempFile = Path.Combine(tempPath, tempFile);
+
+ // Write the resource data to a temp file
+ using (Stream tempStream = File.Open(tempFile, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
+ {
+ tempStream.Write(data, 0, data.Length);
+ }
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
+ }
+ }
+
+ return tempPath;
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
+ return null;
+ }
}
}
}
diff --git a/BurnOutSharp/PackerType/GenteeInstaller.cs b/BurnOutSharp/PackerType/GenteeInstaller.cs
index 7ec21c6e..7406567a 100644
--- a/BurnOutSharp/PackerType/GenteeInstaller.cs
+++ b/BurnOutSharp/PackerType/GenteeInstaller.cs
@@ -33,19 +33,19 @@ namespace BurnOutSharp.PackerType
}
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
return null;
}
diff --git a/BurnOutSharp/PackerType/HyperTechCrackProof.cs b/BurnOutSharp/PackerType/HyperTechCrackProof.cs
index 8310aabc..5e64e32e 100644
--- a/BurnOutSharp/PackerType/HyperTechCrackProof.cs
+++ b/BurnOutSharp/PackerType/HyperTechCrackProof.cs
@@ -32,19 +32,19 @@ namespace BurnOutSharp.PackerType
}
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
return null;
}
diff --git a/BurnOutSharp/PackerType/InnoSetup.cs b/BurnOutSharp/PackerType/InnoSetup.cs
index 794dc209..df59afb6 100644
--- a/BurnOutSharp/PackerType/InnoSetup.cs
+++ b/BurnOutSharp/PackerType/InnoSetup.cs
@@ -58,19 +58,19 @@ namespace BurnOutSharp.PackerType
}
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
return null;
}
diff --git a/BurnOutSharp/PackerType/InstallAnywhere.cs b/BurnOutSharp/PackerType/InstallAnywhere.cs
index 570ef206..83c7eb18 100644
--- a/BurnOutSharp/PackerType/InstallAnywhere.cs
+++ b/BurnOutSharp/PackerType/InstallAnywhere.cs
@@ -29,19 +29,19 @@ namespace BurnOutSharp.PackerType
}
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
return null;
}
diff --git a/BurnOutSharp/PackerType/InstallerVISE.cs b/BurnOutSharp/PackerType/InstallerVISE.cs
index e14b247a..eb671c86 100644
--- a/BurnOutSharp/PackerType/InstallerVISE.cs
+++ b/BurnOutSharp/PackerType/InstallerVISE.cs
@@ -31,19 +31,19 @@ namespace BurnOutSharp.PackerType
}
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
return null;
}
diff --git a/BurnOutSharp/PackerType/IntelInstallationFramework.cs b/BurnOutSharp/PackerType/IntelInstallationFramework.cs
index c686e1f3..47716cb3 100644
--- a/BurnOutSharp/PackerType/IntelInstallationFramework.cs
+++ b/BurnOutSharp/PackerType/IntelInstallationFramework.cs
@@ -34,19 +34,19 @@ namespace BurnOutSharp.PackerType
}
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
return null;
}
diff --git a/BurnOutSharp/PackerType/MicrosoftCABSFX.cs b/BurnOutSharp/PackerType/MicrosoftCABSFX.cs
index dd040821..b1a78590 100644
--- a/BurnOutSharp/PackerType/MicrosoftCABSFX.cs
+++ b/BurnOutSharp/PackerType/MicrosoftCABSFX.cs
@@ -49,19 +49,19 @@ namespace BurnOutSharp.PackerType
}
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
return null;
}
diff --git a/BurnOutSharp/PackerType/NSIS.cs b/BurnOutSharp/PackerType/NSIS.cs
index 296c3d0a..b8bc97b4 100644
--- a/BurnOutSharp/PackerType/NSIS.cs
+++ b/BurnOutSharp/PackerType/NSIS.cs
@@ -33,19 +33,19 @@ namespace BurnOutSharp.PackerType
}
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
return null;
}
diff --git a/BurnOutSharp/PackerType/PECompact.cs b/BurnOutSharp/PackerType/PECompact.cs
index ebbc1787..535ac146 100644
--- a/BurnOutSharp/PackerType/PECompact.cs
+++ b/BurnOutSharp/PackerType/PECompact.cs
@@ -42,19 +42,19 @@ namespace BurnOutSharp.PackerType
}
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
return null;
}
diff --git a/BurnOutSharp/PackerType/Petite.cs b/BurnOutSharp/PackerType/Petite.cs
index 8df83588..2c0a65a5 100644
--- a/BurnOutSharp/PackerType/Petite.cs
+++ b/BurnOutSharp/PackerType/Petite.cs
@@ -25,19 +25,19 @@ namespace BurnOutSharp.PackerType
}
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
return null;
}
diff --git a/BurnOutSharp/PackerType/SetupFactory.cs b/BurnOutSharp/PackerType/SetupFactory.cs
index 721be961..5d8472a7 100644
--- a/BurnOutSharp/PackerType/SetupFactory.cs
+++ b/BurnOutSharp/PackerType/SetupFactory.cs
@@ -39,19 +39,19 @@ namespace BurnOutSharp.PackerType
}
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
return null;
}
diff --git a/BurnOutSharp/PackerType/SevenZipSFX.cs b/BurnOutSharp/PackerType/SevenZipSFX.cs
index 3ee86c83..8b3e102e 100644
--- a/BurnOutSharp/PackerType/SevenZipSFX.cs
+++ b/BurnOutSharp/PackerType/SevenZipSFX.cs
@@ -46,19 +46,19 @@ namespace BurnOutSharp.PackerType
}
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
return null;
}
diff --git a/BurnOutSharp/PackerType/Shrinker.cs b/BurnOutSharp/PackerType/Shrinker.cs
index 36d93393..22f73b13 100644
--- a/BurnOutSharp/PackerType/Shrinker.cs
+++ b/BurnOutSharp/PackerType/Shrinker.cs
@@ -26,19 +26,19 @@ namespace BurnOutSharp.PackerType
}
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
return null;
}
diff --git a/BurnOutSharp/PackerType/UPX.cs b/BurnOutSharp/PackerType/UPX.cs
index 694b8618..ee4572ae 100644
--- a/BurnOutSharp/PackerType/UPX.cs
+++ b/BurnOutSharp/PackerType/UPX.cs
@@ -64,19 +64,19 @@ namespace BurnOutSharp.PackerType
}
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
return null;
}
diff --git a/BurnOutSharp/PackerType/WinRARSFX.cs b/BurnOutSharp/PackerType/WinRARSFX.cs
index c943995b..1f113836 100644
--- a/BurnOutSharp/PackerType/WinRARSFX.cs
+++ b/BurnOutSharp/PackerType/WinRARSFX.cs
@@ -30,38 +30,53 @@ namespace BurnOutSharp.PackerType
}
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- // Should be using stream instead of file, but stream fails to extract anything. My guess is that the executable portion of the archive is causing stream to fail, but not file.
- using (RarArchive zipFile = RarArchive.Open(file, new SharpCompress.Readers.ReaderOptions() { LookForHeader = true }))
+ try
{
- foreach (var entry in zipFile.Entries)
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ // Should be using stream instead of file, but stream fails to extract anything. My guess is that the executable portion of the archive is causing stream to fail, but not file.
+ using (RarArchive zipFile = RarArchive.Open(file, new SharpCompress.Readers.ReaderOptions() { LookForHeader = true }))
{
- // If we have a directory, skip it
- if (entry.IsDirectory)
- continue;
+ foreach (var entry in zipFile.Entries)
+ {
+ try
+ {
+ // If we have a directory, skip it
+ if (entry.IsDirectory)
+ continue;
- string tempFile = Path.Combine(tempPath, entry.Key);
- entry.WriteToFile(tempFile);
+ string tempFile = Path.Combine(tempPath, entry.Key);
+ entry.WriteToFile(tempFile);
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
+ }
+ }
}
- }
- return tempPath;
+ return tempPath;
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
+ return null;
+ }
}
}
}
diff --git a/BurnOutSharp/PackerType/WinZipSFX.cs b/BurnOutSharp/PackerType/WinZipSFX.cs
index c0f6dc6e..372d7ab7 100644
--- a/BurnOutSharp/PackerType/WinZipSFX.cs
+++ b/BurnOutSharp/PackerType/WinZipSFX.cs
@@ -65,38 +65,53 @@ namespace BurnOutSharp.PackerType
// TODO: Find a way to generically detect 2.X versions and improve exact version detection for SFX PE versions bundled with WinZip 11+
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- // Should be using stream instead of file, but stream fails to extract anything. My guess is that the executable portion of the archive is causing stream to fail, but not file.
- using (ZipArchive zipFile = ZipArchive.Open(file))
+ try
{
- foreach (var entry in zipFile.Entries)
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ // Should be using stream instead of file, but stream fails to extract anything. My guess is that the executable portion of the archive is causing stream to fail, but not file.
+ using (ZipArchive zipFile = ZipArchive.Open(file))
{
- // If we have a directory, skip it
- if (entry.IsDirectory)
- continue;
+ foreach (var entry in zipFile.Entries)
+ {
+ try
+ {
+ // If we have a directory, skip it
+ if (entry.IsDirectory)
+ continue;
- string tempFile = Path.Combine(tempPath, entry.Key);
- entry.WriteToFile(tempFile);
+ string tempFile = Path.Combine(tempPath, entry.Key);
+ entry.WriteToFile(tempFile);
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
+ }
+ }
}
- }
- return tempPath;
+ return tempPath;
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
+ return null;
+ }
}
///
diff --git a/BurnOutSharp/PackerType/WiseInstaller.cs b/BurnOutSharp/PackerType/WiseInstaller.cs
index 62ab284d..a1d520fa 100644
--- a/BurnOutSharp/PackerType/WiseInstaller.cs
+++ b/BurnOutSharp/PackerType/WiseInstaller.cs
@@ -77,31 +77,39 @@ namespace BurnOutSharp.PackerType
}
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
- // Try to parse as a New Executable
- NewExecutable nex = NewExecutable.Create(stream);
- if (nex != null)
- return ExtractNewExecutable(nex, file);
+ try
+ {
+ // Try to parse as a New Executable
+ NewExecutable nex = NewExecutable.Create(stream);
+ if (nex != null)
+ return ExtractNewExecutable(nex, file, includeDebug);
- // Try to parse as a Portable Executable
- PortableExecutable pex = PortableExecutable.Create(stream);
- if (pex != null)
- return ExtractPortableExecutable(pex, file);
+ // Try to parse as a Portable Executable
+ PortableExecutable pex = PortableExecutable.Create(stream);
+ if (pex != null)
+ return ExtractPortableExecutable(pex, file, includeDebug);
- return null;
+ return null;
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
+ return null;
+ }
}
///
@@ -211,15 +219,24 @@ namespace BurnOutSharp.PackerType
///
/// New executable to check
/// Path to the input file
+ /// True to include debug data, false otherwise
/// True if it matches a known version, false otherwise
- private string ExtractNewExecutable(NewExecutable nex, string file)
+ private string ExtractNewExecutable(NewExecutable nex, string file, bool includeDebug)
{
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(tempPath);
- // TODO: Try to find where the file data lives and how to get it
- Wise unpacker = new Wise();
- unpacker.ExtractTo(file, tempPath);
+ try
+ {
+ // TODO: Try to find where the file data lives and how to get it
+ Wise unpacker = new Wise();
+ unpacker.ExtractTo(file, tempPath);
+ }
+ catch (Exception ex)
+ {
+ if (includeDebug) Console.WriteLine(ex);
+ return null;
+ }
return tempPath;
}
@@ -229,94 +246,103 @@ namespace BurnOutSharp.PackerType
///
/// Portable executable to check
/// Path to the input file
+ /// True to include debug data, false otherwise
/// True if it matches a known version, false otherwise
- private string ExtractPortableExecutable(PortableExecutable pex, string file)
+ private string ExtractPortableExecutable(PortableExecutable pex, string file, bool includeDebug)
{
- // Get the matching PE format
- var format = GetPEFormat(pex);
- if (format == null)
- return null;
-
- // Get the overlay data for easier reading
- int overlayOffset = 0, dataStart = 0;
- byte[] overlayData = pex.OverlayData;
- if (overlayData == null)
- return null;
-
- // Skip over the additional DLL name, if we expect it
- if (format.Dll)
+ try
{
- // Read the name length
- byte dllNameLength = overlayData.ReadByte(ref overlayOffset);
- dataStart++;
+ // Get the matching PE format
+ var format = GetPEFormat(pex);
+ if (format == null)
+ return null;
- // Read the name, if it exists
- if (dllNameLength != 0)
+ // Get the overlay data for easier reading
+ int overlayOffset = 0, dataStart = 0;
+ byte[] overlayData = pex.OverlayData;
+ if (overlayData == null)
+ return null;
+
+ // Skip over the additional DLL name, if we expect it
+ if (format.Dll)
{
- // Ignore the name for now
- _ = overlayData.ReadBytes(ref overlayOffset, dllNameLength);
- dataStart += dllNameLength;
+ // Read the name length
+ byte dllNameLength = overlayData.ReadByte(ref overlayOffset);
+ dataStart++;
- // Named DLLs also have a DLL length that we ignore
+ // Read the name, if it exists
+ if (dllNameLength != 0)
+ {
+ // Ignore the name for now
+ _ = overlayData.ReadBytes(ref overlayOffset, dllNameLength);
+ dataStart += dllNameLength;
+
+ // Named DLLs also have a DLL length that we ignore
+ _ = overlayData.ReadUInt32(ref overlayOffset);
+ dataStart += 4;
+ }
+ }
+
+ // Check if flags are consistent
+ if (!format.NoCrc)
+ {
+ // Unlike WiseUnpacker, we ignore the flag value here
_ = overlayData.ReadUInt32(ref overlayOffset);
- dataStart += 4;
}
- }
- // Check if flags are consistent
- if (!format.NoCrc)
- {
- // Unlike WiseUnpacker, we ignore the flag value here
- _ = overlayData.ReadUInt32(ref overlayOffset);
- }
-
- // Ensure that we have an archive end
- if (format.ArchiveEnd > 0)
- {
- overlayOffset = dataStart + format.ArchiveEnd;
- int archiveEndLoaded = overlayData.ReadInt32(ref overlayOffset);
- if (archiveEndLoaded != 0)
- format.ArchiveEnd = archiveEndLoaded;
- }
-
- // Skip to the start of the archive
- overlayOffset = dataStart + format.ArchiveStart;
-
- // Skip over the initialization text, if we expect it
- if (format.InitText)
- {
- int initTextLength = overlayData.ReadByte(ref overlayOffset);
- _ = overlayData.ReadBytes(ref overlayOffset, initTextLength);
- }
-
- // Cache the current offset in the overlay as the "start of data"
- int offsetReal = overlayOffset;
-
- // If the first entry is PKZIP, we assume it's an embedded zipfile
- byte[] magic = overlayData.ReadBytes(ref overlayOffset, 4); overlayOffset -= 4;
- bool pkzip = magic.StartsWith(new byte?[] { (byte)'P', (byte)'K' });
-
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- // If we have PKZIP
- if (pkzip)
- {
- string tempFile = Path.Combine(tempPath, "WISEDATA.zip");
- using (Stream tempStream = File.Open(tempFile, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
+ // Ensure that we have an archive end
+ if (format.ArchiveEnd > 0)
{
- tempStream.Write(overlayData, overlayOffset, overlayData.Length - overlayOffset);
+ overlayOffset = dataStart + format.ArchiveEnd;
+ int archiveEndLoaded = overlayData.ReadInt32(ref overlayOffset);
+ if (archiveEndLoaded != 0)
+ format.ArchiveEnd = archiveEndLoaded;
}
- }
- // If we have DEFLATE -- TODO: Port implementation here or use DeflateStream
- else
+ // Skip to the start of the archive
+ overlayOffset = dataStart + format.ArchiveStart;
+
+ // Skip over the initialization text, if we expect it
+ if (format.InitText)
+ {
+ int initTextLength = overlayData.ReadByte(ref overlayOffset);
+ _ = overlayData.ReadBytes(ref overlayOffset, initTextLength);
+ }
+
+ // Cache the current offset in the overlay as the "start of data"
+ int offsetReal = overlayOffset;
+
+ // If the first entry is PKZIP, we assume it's an embedded zipfile
+ byte[] magic = overlayData.ReadBytes(ref overlayOffset, 4); overlayOffset -= 4;
+ bool pkzip = magic.StartsWith(new byte?[] { (byte)'P', (byte)'K' });
+
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ // If we have PKZIP
+ if (pkzip)
+ {
+ string tempFile = Path.Combine(tempPath, "WISEDATA.zip");
+ using (Stream tempStream = File.Open(tempFile, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
+ {
+ tempStream.Write(overlayData, overlayOffset, overlayData.Length - overlayOffset);
+ }
+ }
+
+ // If we have DEFLATE -- TODO: Port implementation here or use DeflateStream
+ else
+ {
+ Wise unpacker = new Wise();
+ unpacker.ExtractTo(file, tempPath);
+ }
+
+ return tempPath;
+ }
+ catch (Exception ex)
{
- Wise unpacker = new Wise();
- unpacker.ExtractTo(file, tempPath);
+ if (includeDebug) Console.WriteLine(ex);
+ return null;
}
-
- return tempPath;
}
///
diff --git a/BurnOutSharp/PackerType/dotFuscator.cs b/BurnOutSharp/PackerType/dotFuscator.cs
index 6a8bad54..0f46d54f 100644
--- a/BurnOutSharp/PackerType/dotFuscator.cs
+++ b/BurnOutSharp/PackerType/dotFuscator.cs
@@ -29,19 +29,19 @@ namespace BurnOutSharp.PackerType
}
///
- public string Extract(string file)
+ public string Extract(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
- return Extract(fs, file);
+ return Extract(fs, file, includeDebug);
}
}
///
- public string Extract(Stream stream, string file)
+ public string Extract(Stream stream, string file, bool includeDebug)
{
return null;
}
diff --git a/BurnOutSharp/Scanner.cs b/BurnOutSharp/Scanner.cs
index 7f9c1a71..77669e7f 100644
--- a/BurnOutSharp/Scanner.cs
+++ b/BurnOutSharp/Scanner.cs
@@ -366,7 +366,7 @@ namespace BurnOutSharp
try
{
// Extract and get the output path
- string tempPath = extractable.Extract(stream, fileName);
+ string tempPath = extractable.Extract(stream, fileName, IncludeDebug);
if (tempPath == null)
return null;