diff --git a/BinaryObjectScanner/FileType/GZIP.cs b/BinaryObjectScanner/FileType/GZIP.cs
index c5a4cbc7..ec1937de 100644
--- a/BinaryObjectScanner/FileType/GZIP.cs
+++ b/BinaryObjectScanner/FileType/GZIP.cs
@@ -42,10 +42,14 @@ namespace BinaryObjectScanner.FileType
{
try
{
- // If we have a directory, skip it
+ // If the entry is a directory
if (entry.IsDirectory)
continue;
+ // If the entry has an invalid key
+ if (entry.Key == null)
+ continue;
+
string tempFile = Path.Combine(tempPath, entry.Key);
entry.WriteToFile(tempFile);
}
diff --git a/BinaryObjectScanner/FileType/PKZIP.cs b/BinaryObjectScanner/FileType/PKZIP.cs
index ca9f7e60..fa725a98 100644
--- a/BinaryObjectScanner/FileType/PKZIP.cs
+++ b/BinaryObjectScanner/FileType/PKZIP.cs
@@ -42,11 +42,15 @@ namespace BinaryObjectScanner.FileType
{
try
{
- // If we have a directory, skip it
+ // If the entry is a directory
if (entry.IsDirectory)
continue;
- // If we have a partial entry due to an incomplete multi-part archive, skip it
+ // If the entry has an invalid key
+ if (entry.Key == null)
+ continue;
+
+ // If the entry is partial due to an incomplete multi-part archive, skip it
if (!entry.IsComplete)
continue;
diff --git a/BinaryObjectScanner/FileType/RAR.cs b/BinaryObjectScanner/FileType/RAR.cs
index 8bddc8f2..f1c7e1f9 100644
--- a/BinaryObjectScanner/FileType/RAR.cs
+++ b/BinaryObjectScanner/FileType/RAR.cs
@@ -42,10 +42,14 @@ namespace BinaryObjectScanner.FileType
{
try
{
- // If we have a directory, skip it
+ // If the entry is a directory
if (entry.IsDirectory)
continue;
+ // If the entry has an invalid key
+ if (entry.Key == null)
+ continue;
+
string tempFile = Path.Combine(tempPath, entry.Key);
entry.WriteToFile(tempFile);
}
diff --git a/BinaryObjectScanner/FileType/SevenZip.cs b/BinaryObjectScanner/FileType/SevenZip.cs
index 75056575..4f384f6c 100644
--- a/BinaryObjectScanner/FileType/SevenZip.cs
+++ b/BinaryObjectScanner/FileType/SevenZip.cs
@@ -26,6 +26,9 @@ namespace BinaryObjectScanner.FileType
///
public string? Extract(Stream? stream, string file, bool includeDebug)
{
+ if (stream == null)
+ return null;
+
#if NET462_OR_GREATER || NETCOREAPP
try
{
@@ -39,10 +42,14 @@ namespace BinaryObjectScanner.FileType
{
try
{
- // If we have a directory, skip it
+ // If the entry is a directory
if (entry.IsDirectory)
continue;
+ // If the entry has an invalid key
+ if (entry.Key == null)
+ continue;
+
string tempFile = Path.Combine(tempPath, entry.Key);
entry.WriteToFile(tempFile);
}
diff --git a/BinaryObjectScanner/FileType/TapeArchive.cs b/BinaryObjectScanner/FileType/TapeArchive.cs
index 13fe09c1..1711fdb2 100644
--- a/BinaryObjectScanner/FileType/TapeArchive.cs
+++ b/BinaryObjectScanner/FileType/TapeArchive.cs
@@ -42,10 +42,14 @@ namespace BinaryObjectScanner.FileType
{
try
{
- // If we have a directory, skip it
+ // If the entry is a directory
if (entry.IsDirectory)
continue;
+ // If the entry has an invalid key
+ if (entry.Key == null)
+ continue;
+
string tempFile = Path.Combine(tempPath, entry.Key);
entry.WriteToFile(tempFile);
}
diff --git a/BinaryObjectScanner/Packer/EmbeddedExecutable.cs b/BinaryObjectScanner/Packer/EmbeddedExecutable.cs
index ac07a02b..09d2e48d 100644
--- a/BinaryObjectScanner/Packer/EmbeddedExecutable.cs
+++ b/BinaryObjectScanner/Packer/EmbeddedExecutable.cs
@@ -33,6 +33,10 @@ namespace BinaryObjectScanner.Packer
{
try
{
+ // If there are no resources
+ 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[])
@@ -57,11 +61,8 @@ namespace BinaryObjectScanner.Packer
tempFile = Path.Combine(tempPath, tempFile);
// Write the resource data to a temp file
- using (var tempStream = File.Open(tempFile, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
- {
- if (tempStream != null)
- tempStream.Write(data, 0, data.Length);
- }
+ using var tempStream = File.Open(tempFile, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
+ tempStream?.Write(data, 0, data.Length);
}
catch (Exception ex)
{
diff --git a/BinaryObjectScanner/Packer/WinRARSFX.cs b/BinaryObjectScanner/Packer/WinRARSFX.cs
index c6e6aa49..30252875 100644
--- a/BinaryObjectScanner/Packer/WinRARSFX.cs
+++ b/BinaryObjectScanner/Packer/WinRARSFX.cs
@@ -51,10 +51,14 @@ namespace BinaryObjectScanner.Packer
{
try
{
- // If we have a directory, skip it
+ // If the entry is a directory
if (entry.IsDirectory)
continue;
+ // If the entry has an invalid key
+ if (entry.Key == null)
+ continue;
+
string tempFile = Path.Combine(tempPath, entry.Key);
entry.WriteToFile(tempFile);
}
diff --git a/BinaryObjectScanner/Packer/WinZipSFX.cs b/BinaryObjectScanner/Packer/WinZipSFX.cs
index 09c5e259..57c20a80 100644
--- a/BinaryObjectScanner/Packer/WinZipSFX.cs
+++ b/BinaryObjectScanner/Packer/WinZipSFX.cs
@@ -74,7 +74,7 @@ namespace BinaryObjectScanner.Packer
/// Handle common extraction between executable types
///
///
- public string? Extract(string file, bool includeDebug)
+ public static string? Extract(string file, bool includeDebug)
{
#if NET462_OR_GREATER || NETCOREAPP
try
@@ -89,10 +89,14 @@ namespace BinaryObjectScanner.Packer
{
try
{
- // If we have a directory, skip it
+ // 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;