diff --git a/BinaryObjectScanner/Scanner.cs b/BinaryObjectScanner/Scanner.cs index 35f13067..bd464416 100644 --- a/BinaryObjectScanner/Scanner.cs +++ b/BinaryObjectScanner/Scanner.cs @@ -405,11 +405,13 @@ private ProtectionDictionary GetInternalProtections(string fileName, Stream stre // If we're scanning archives if (_scanArchives && wrapper is IExtractable extractable) { + // Get the output path + string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); + // If the extractable file itself fails try { - // Extract and get the output path - string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); + // Extract to the output path Directory.CreateDirectory(tempPath); _ = extractable.Extract(tempPath, _includeDebug); @@ -426,7 +428,13 @@ private ProtectionDictionary GetInternalProtections(string fileName, Stream stre // Append the values protections.Append(subProtections); } - + } + catch (Exception ex) + { + if (_includeDebug) Console.Error.WriteLine(ex); + } + finally + { // If temp directory cleanup fails try { @@ -438,10 +446,6 @@ private ProtectionDictionary GetInternalProtections(string fileName, Stream stre if (_includeDebug) Console.Error.WriteLine(ex); } } - catch (Exception ex) - { - if (_includeDebug) Console.Error.WriteLine(ex); - } } #endregion