diff --git a/BinaryObjectScanner/Scanner.cs b/BinaryObjectScanner/Scanner.cs
index 34838770..95edbae9 100644
--- a/BinaryObjectScanner/Scanner.cs
+++ b/BinaryObjectScanner/Scanner.cs
@@ -66,29 +66,32 @@ namespace BinaryObjectScanner
/// Path to scan
/// Dictionary of list of strings representing the found protections
public Dictionary> GetProtections(string path)
- => GetProtectionsImpl(path).ToDictionary();
+ => GetProtectionsImpl(path, depth: 0).ToDictionary();
///
/// Scan the list of paths and get all found protections
///
+ /// Paths to scan
/// Dictionary of list of strings representing the found protections
public Dictionary> GetProtections(List? paths)
- => GetProtectionsImpl(paths).ToDictionary();
+ => GetProtectionsImpl(paths, depth: 0).ToDictionary();
///
/// Scan a single path and get all found protections
///
/// Path to scan
+ /// Depth of the current scanner pertaining to extracted data
/// Dictionary of list of strings representing the found protections
- private ProtectionDictionary GetProtectionsImpl(string path)
- => GetProtectionsImpl([path]);
+ private ProtectionDictionary GetProtectionsImpl(string path, int depth)
+ => GetProtectionsImpl([path], depth);
///
/// Scan a single path and get all found protections
///
- /// Path to scan
+ /// Paths to scan
+ /// Depth of the current scanner pertaining to extracted data
/// Dictionary of list of strings representing the found protections
- private ProtectionDictionary GetProtectionsImpl(List? paths)
+ private ProtectionDictionary GetProtectionsImpl(List? paths, int depth)
{
// If we have no paths, we can't scan
if (paths == null || paths.Count == 0)
@@ -130,12 +133,8 @@ namespace BinaryObjectScanner
// Get the reportable file name
string reportableFileName = file;
- int depth = 0;
if (reportableFileName.StartsWith(tempFilePath))
- {
- depth = 1;
reportableFileName = reportableFileName.Substring(tempFilePathWithGuid.Length);
- }
// Checkpoint
_fileProgress?.Report(new ProtectionProgress(reportableFileName, depth, i / (float)files.Count, "Checking file" + (file != reportableFileName ? " from archive" : string.Empty)));
@@ -149,7 +148,7 @@ namespace BinaryObjectScanner
}
// Scan for content-detectable protections
- var fileProtections = GetInternalProtections(file);
+ var fileProtections = GetInternalProtections(file, depth);
if (fileProtections != null && fileProtections.Count > 0)
protections.Append(fileProtections);
@@ -167,12 +166,8 @@ namespace BinaryObjectScanner
{
// Get the reportable file name
string reportableFileName = path;
- int depth = 0;
if (reportableFileName.StartsWith(tempFilePath))
- {
- depth = 1;
reportableFileName = reportableFileName.Substring(tempFilePathWithGuid.Length);
- }
// Checkpoint
_fileProgress?.Report(new ProtectionProgress(reportableFileName, depth, 0, "Checking file" + (path != reportableFileName ? " from archive" : string.Empty)));
@@ -186,7 +181,7 @@ namespace BinaryObjectScanner
}
// Scan for content-detectable protections
- var fileProtections = GetInternalProtections(path);
+ var fileProtections = GetInternalProtections(path, depth);
if (fileProtections != null && fileProtections.Count > 0)
protections.Append(fileProtections);
@@ -220,8 +215,9 @@ namespace BinaryObjectScanner
/// Get the content-detectable protections associated with a single path
///
/// Path to the file to scan
+ /// Depth of the current scanner pertaining to extracted data
/// Dictionary of list of strings representing the found protections
- private ProtectionDictionary GetInternalProtections(string file)
+ private ProtectionDictionary GetInternalProtections(string file, int depth)
{
// Quick sanity check before continuing
if (!File.Exists(file))
@@ -231,7 +227,7 @@ namespace BinaryObjectScanner
try
{
using FileStream fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
- return GetInternalProtections(fs.Name, fs);
+ return GetInternalProtections(fs.Name, fs, depth);
}
catch (Exception ex)
{
@@ -249,8 +245,9 @@ namespace BinaryObjectScanner
///
/// Name of the source file of the stream, for tracking
/// Stream to scan the contents of
+ /// Depth of the current scanner pertaining to extracted data
/// Dictionary of list of strings representing the found protections
- private ProtectionDictionary GetInternalProtections(string fileName, Stream stream)
+ private ProtectionDictionary GetInternalProtections(string fileName, Stream stream, int depth)
{
// Quick sanity check before continuing
if (!stream.CanRead)
@@ -317,7 +314,7 @@ namespace BinaryObjectScanner
// Collect and format all found protections
ProtectionDictionary? subProtections = null;
if (extracted)
- subProtections = GetProtectionsImpl(tempPath);
+ subProtections = GetProtectionsImpl(tempPath, depth + 1);
// If temp directory cleanup fails
try