diff --git a/BinaryObjectScanner.Test/FileType/ExecutableTests.cs b/BinaryObjectScanner.Test/FileType/ExecutableTests.cs
index 5ead4ccc..3ecb2531 100644
--- a/BinaryObjectScanner.Test/FileType/ExecutableTests.cs
+++ b/BinaryObjectScanner.Test/FileType/ExecutableTests.cs
@@ -26,16 +26,5 @@ namespace BinaryObjectScanner.Test.FileType
string? actual = detectable.Detect(stream, file, includeDebug: false);
Assert.Null(actual);
}
-
- [Fact]
- public void DetectDict_EmptyStream_Empty()
- {
- Stream? stream = new MemoryStream();
- string file = string.Empty;
- var detectable = new Executable();
-
- ProtectionDictionary actual = detectable.DetectDict(stream, file, includeDebug: false);
- Assert.Empty(actual);
- }
}
}
diff --git a/BinaryObjectScanner/FileType/Executable.cs b/BinaryObjectScanner/FileType/Executable.cs
index c9bfc9db..66523f48 100644
--- a/BinaryObjectScanner/FileType/Executable.cs
+++ b/BinaryObjectScanner/FileType/Executable.cs
@@ -25,28 +25,6 @@ namespace BinaryObjectScanner.FileType
///
public string? Detect(Stream stream, string file, bool includeDebug)
- {
- // Get all non-nested protections
- var protections = DetectDict(stream, file, includeDebug);
- if (protections.Count == 0)
- return null;
-
- // Create the internal list
- var protectionList = new List();
- foreach (string key in protections.Keys)
- {
- protectionList.AddRange(protections[key]);
- }
-
- return string.Join(";", [.. protectionList]);
- }
-
- ///
- ///
- /// Ideally, we wouldn't need to circumvent the proper handling of file types just for Executable,
- /// but due to the complexity of scanning, this is not currently possible.
- ///
- public ProtectionDictionary DetectDict(Stream stream, string file, bool includeDebug)
{
// Create the output dictionary
var protections = new ProtectionDictionary();
@@ -57,12 +35,12 @@ namespace BinaryObjectScanner.FileType
{
wrapper = WrapperFactory.CreateExecutableWrapper(stream);
if (wrapper == null)
- return protections;
+ return null;
}
catch (Exception ex)
{
if (includeDebug) Console.Error.WriteLine(ex);
- return protections;
+ return null;
}
// Only use generic content checks if we're in debug mode
@@ -101,7 +79,18 @@ namespace BinaryObjectScanner.FileType
protections.Append(file, subProtections.Values);
}
- return protections;
+ // If there are no protections
+ if (protections.Count == 0)
+ return null;
+
+ // Create the internal list
+ var protectionList = new List();
+ foreach (string key in protections.Keys)
+ {
+ protectionList.AddRange(protections[key]);
+ }
+
+ return string.Join(";", [.. protectionList]);
}
///
diff --git a/BinaryObjectScanner/Scanner.cs b/BinaryObjectScanner/Scanner.cs
index fd89f0e3..1dbda5e4 100644
--- a/BinaryObjectScanner/Scanner.cs
+++ b/BinaryObjectScanner/Scanner.cs
@@ -276,19 +276,8 @@ namespace BinaryObjectScanner
// If we're scanning file contents
if (detectable != null && _options.ScanContents)
{
- // If we have an executable, it needs to bypass normal handling
- if (detectable is Executable executable)
- {
- var subProtections = executable.DetectDict(stream, fileName, _options.IncludeDebug);
- protections.Append(subProtections);
- }
-
- // Otherwise, use the default implementation
- else
- {
- var subProtection = detectable.Detect(stream, fileName, _options.IncludeDebug);
- protections.Append(fileName, subProtection);
- }
+ var subProtection = detectable.Detect(stream, fileName, _options.IncludeDebug);
+ protections.Append(fileName, subProtection);
}
#endregion