diff --git a/BinaryObjectScanner/FileType/PKZIP.cs b/BinaryObjectScanner/FileType/PKZIP.cs
index f5e4f02c..b21b9d31 100644
--- a/BinaryObjectScanner/FileType/PKZIP.cs
+++ b/BinaryObjectScanner/FileType/PKZIP.cs
@@ -4,6 +4,7 @@ using BinaryObjectScanner.Interfaces;
#if NET462_OR_GREATER || NETCOREAPP
using SharpCompress.Archives;
using SharpCompress.Archives.Zip;
+using SharpCompress.Readers;
#endif
namespace BinaryObjectScanner.FileType
@@ -15,16 +16,24 @@ namespace BinaryObjectScanner.FileType
{
///
public bool Extract(string file, string outDir, bool includeDebug)
+ => Extract(file, outDir, lookForHeader: false, includeDebug);
+
+ ///
+ public bool Extract(string file, string outDir, bool lookForHeader, bool includeDebug)
{
if (!File.Exists(file))
return false;
using var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
- return Extract(fs, file, outDir, includeDebug);
+ return Extract(fs, file, outDir, lookForHeader, includeDebug);
}
///
public bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
+ => Extract(stream, file, outDir, lookForHeader: false, includeDebug);
+
+ ///
+ public bool Extract(Stream? stream, string file, string outDir, bool lookForHeader, bool includeDebug)
{
if (stream == null || !stream.CanRead)
return false;
@@ -32,7 +41,8 @@ namespace BinaryObjectScanner.FileType
#if NET462_OR_GREATER || NETCOREAPP
try
{
- using var zipFile = ZipArchive.Open(stream);
+ var readerOptions = new ReaderOptions() { LookForHeader = lookForHeader };
+ using var zipFile = ZipArchive.Open(stream, readerOptions);
foreach (var entry in zipFile.Entries)
{
try
diff --git a/BinaryObjectScanner/FileType/RAR.cs b/BinaryObjectScanner/FileType/RAR.cs
index f0292168..086b1370 100644
--- a/BinaryObjectScanner/FileType/RAR.cs
+++ b/BinaryObjectScanner/FileType/RAR.cs
@@ -4,6 +4,7 @@ using BinaryObjectScanner.Interfaces;
#if NET462_OR_GREATER || NETCOREAPP
using SharpCompress.Archives;
using SharpCompress.Archives.Rar;
+using SharpCompress.Readers;
#endif
namespace BinaryObjectScanner.FileType
@@ -15,16 +16,24 @@ namespace BinaryObjectScanner.FileType
{
///
public bool Extract(string file, string outDir, bool includeDebug)
+ => Extract(file, outDir, lookForHeader: false, includeDebug);
+
+ ///
+ public bool Extract(string file, string outDir, bool lookForHeader, bool includeDebug)
{
if (!File.Exists(file))
return false;
using var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
- return Extract(fs, file, outDir, includeDebug);
+ return Extract(fs, file, outDir, lookForHeader, includeDebug);
}
///
public bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
+ => Extract(stream, file, outDir, lookForHeader: false, includeDebug);
+
+ ///
+ public bool Extract(Stream? stream, string file, string outDir, bool lookForHeader, bool includeDebug)
{
if (stream == null || !stream.CanRead)
return false;
@@ -32,7 +41,8 @@ namespace BinaryObjectScanner.FileType
#if NET462_OR_GREATER || NETCOREAPP
try
{
- using RarArchive rarFile = RarArchive.Open(stream);
+ var readerOptions = new ReaderOptions() { LookForHeader = lookForHeader };
+ using RarArchive rarFile = RarArchive.Open(stream, readerOptions);
if (!rarFile.IsComplete)
return false;
diff --git a/BinaryObjectScanner/FileType/SevenZip.cs b/BinaryObjectScanner/FileType/SevenZip.cs
index b35222ed..a5d3008e 100644
--- a/BinaryObjectScanner/FileType/SevenZip.cs
+++ b/BinaryObjectScanner/FileType/SevenZip.cs
@@ -4,6 +4,7 @@ using BinaryObjectScanner.Interfaces;
#if NET462_OR_GREATER || NETCOREAPP
using SharpCompress.Archives;
using SharpCompress.Archives.SevenZip;
+using SharpCompress.Readers;
#endif
namespace BinaryObjectScanner.FileType
@@ -15,16 +16,24 @@ namespace BinaryObjectScanner.FileType
{
///
public bool Extract(string file, string outDir, bool includeDebug)
+ => Extract(file, outDir, lookForHeader: false, includeDebug);
+
+ ///
+ public bool Extract(string file, string outDir, bool lookForHeader, bool includeDebug)
{
if (!File.Exists(file))
return false;
using var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
- return Extract(fs, file, outDir, includeDebug);
+ return Extract(fs, file, outDir, lookForHeader, includeDebug);
}
///
public bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
+ => Extract(stream, file, outDir, lookForHeader: false, includeDebug);
+
+ ///
+ public bool Extract(Stream? stream, string file, string outDir, bool lookForHeader, bool includeDebug)
{
if (stream == null || !stream.CanRead)
return false;
@@ -32,7 +41,8 @@ namespace BinaryObjectScanner.FileType
#if NET462_OR_GREATER || NETCOREAPP
try
{
- using var sevenZip = SevenZipArchive.Open(stream);
+ var readerOptions = new ReaderOptions() { LookForHeader = lookForHeader };
+ using var sevenZip = SevenZipArchive.Open(stream, readerOptions);
foreach (var entry in sevenZip.Entries)
{
try
diff --git a/BinaryObjectScanner/Packer/SevenZipSFX.cs b/BinaryObjectScanner/Packer/SevenZipSFX.cs
index 21c3ef2b..563f3db1 100644
--- a/BinaryObjectScanner/Packer/SevenZipSFX.cs
+++ b/BinaryObjectScanner/Packer/SevenZipSFX.cs
@@ -1,13 +1,6 @@
-using System;
-using System.IO;
using System.Linq;
using BinaryObjectScanner.Interfaces;
using SabreTools.Serialization.Wrappers;
-#if NET462_OR_GREATER || NETCOREAPP
-using SharpCompress.Archives;
-using SharpCompress.Archives.SevenZip;
-using SharpCompress.Readers;
-#endif
namespace BinaryObjectScanner.Packer
{
@@ -53,52 +46,8 @@ namespace BinaryObjectScanner.Packer
///
public bool Extract(string file, PortableExecutable pex, string outDir, bool includeDebug)
{
- if (!File.Exists(file))
- return false;
-
-#if NET462_OR_GREATER || NETCOREAPP
- try
- {
- using var sevenZip = SevenZipArchive.Open(file, new ReaderOptions() { LookForHeader = true });
- foreach (var entry in sevenZip.Entries)
- {
- try
- {
- // If the entry is a directory
- if (entry.IsDirectory)
- continue;
-
- // If the entry has an invalid key
- if (entry.Key == null)
- continue;
-
- // If we have a partial entry due to an incomplete multi-part archive, skip it
- if (!entry.IsComplete)
- continue;
-
- string tempFile = Path.Combine(outDir, entry.Key);
- var directoryName = Path.GetDirectoryName(tempFile);
- if (directoryName != null && !Directory.Exists(directoryName))
- Directory.CreateDirectory(directoryName);
-
- entry.WriteToFile(tempFile);
- }
- catch (Exception ex)
- {
- if (includeDebug) Console.WriteLine(ex);
- }
- }
-
- return true;
- }
- catch (Exception ex)
- {
- if (includeDebug) Console.WriteLine(ex);
- return false;
- }
-#else
- return false;
-#endif
+ var sevenZip = new FileType.SevenZip();
+ return sevenZip.Extract(file, outDir, lookForHeader: true, includeDebug);
}
}
}
diff --git a/BinaryObjectScanner/Packer/WinRARSFX.cs b/BinaryObjectScanner/Packer/WinRARSFX.cs
index 21f9b781..767c7921 100644
--- a/BinaryObjectScanner/Packer/WinRARSFX.cs
+++ b/BinaryObjectScanner/Packer/WinRARSFX.cs
@@ -1,13 +1,6 @@
-using System;
-using System.IO;
using System.Linq;
using BinaryObjectScanner.Interfaces;
using SabreTools.Serialization.Wrappers;
-#if NET462_OR_GREATER || NETCOREAPP
-using SharpCompress.Archives;
-using SharpCompress.Archives.Rar;
-using SharpCompress.Readers;
-#endif
namespace BinaryObjectScanner.Packer
{
@@ -35,56 +28,8 @@ namespace BinaryObjectScanner.Packer
///
public bool Extract(string file, PortableExecutable pex, string outDir, bool includeDebug)
{
- if (!File.Exists(file))
- return false;
-
-#if NET462_OR_GREATER || NETCOREAPP
- try
- {
- // 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 var rarFile = RarArchive.Open(file, new ReaderOptions() { LookForHeader = true });
- if (!rarFile.IsComplete)
- return false;
-
- foreach (var entry in rarFile.Entries)
- {
- try
- {
- // If the entry is a directory
- if (entry.IsDirectory)
- continue;
-
- // If the entry has an invalid key
- if (entry.Key == null)
- continue;
-
- // If we have a partial entry due to an incomplete multi-part archive, skip it
- if (!entry.IsComplete)
- continue;
-
- string tempFile = Path.Combine(outDir, entry.Key);
- var directoryName = Path.GetDirectoryName(tempFile);
- if (directoryName != null && !Directory.Exists(directoryName))
- Directory.CreateDirectory(directoryName);
-
- entry.WriteToFile(tempFile);
- }
- catch (Exception ex)
- {
- if (includeDebug) Console.WriteLine(ex);
- }
- }
-
- return true;
- }
- catch (Exception ex)
- {
- if (includeDebug) Console.WriteLine(ex);
- return false;
- }
-#else
- return false;
-#endif
+ var rar = new FileType.RAR();
+ return rar.Extract(file, outDir, lookForHeader: true, includeDebug);
}
}
}
diff --git a/BinaryObjectScanner/Packer/WinZipSFX.cs b/BinaryObjectScanner/Packer/WinZipSFX.cs
index 68b211f2..2005ffb0 100644
--- a/BinaryObjectScanner/Packer/WinZipSFX.cs
+++ b/BinaryObjectScanner/Packer/WinZipSFX.cs
@@ -1,13 +1,7 @@
-using System;
-using System.IO;
using System.Linq;
using System.Text;
using BinaryObjectScanner.Interfaces;
using SabreTools.Serialization.Wrappers;
-#if NET462_OR_GREATER || NETCOREAPP
-using SharpCompress.Archives;
-using SharpCompress.Archives.Zip;
-#endif
namespace BinaryObjectScanner.Packer
{
@@ -78,52 +72,8 @@ namespace BinaryObjectScanner.Packer
///
public static bool Extract(string file, string outDir, bool includeDebug)
{
- if (!File.Exists(file))
- return false;
-
-#if NET462_OR_GREATER || NETCOREAPP
- try
- {
- using var zipFile = ZipArchive.Open(file);
- foreach (var entry in zipFile.Entries)
- {
- try
- {
- // If the entry is a directory
- if (entry.IsDirectory)
- continue;
-
- // If the entry has an invalid key
- if (entry.Key == null)
- continue;
-
- // If we have a partial entry due to an incomplete multi-part archive, skip it
- if (!entry.IsComplete)
- continue;
-
- string tempFile = Path.Combine(outDir, entry.Key);
- var directoryName = Path.GetDirectoryName(tempFile);
- if (directoryName != null && !Directory.Exists(directoryName))
- Directory.CreateDirectory(directoryName);
-
- entry.WriteToFile(tempFile);
- }
- catch (Exception ex)
- {
- if (includeDebug) Console.WriteLine(ex);
- }
- }
-
- return true;
- }
- catch (Exception ex)
- {
- if (includeDebug) Console.WriteLine(ex);
- return false;
- }
-#else
- return false;
-#endif
+ var pkzip = new FileType.PKZIP();
+ return pkzip.Extract(file, outDir, lookForHeader: true, includeDebug);
}
///