From dff15ef79932cf58e6856d7c6ac1f6311b3593fe Mon Sep 17 00:00:00 2001 From: HeroponRikiBestest <50224630+HeroponRikiBestest@users.noreply.github.com> Date: Fri, 4 Jul 2025 14:34:31 -0400 Subject: [PATCH] Fixes .hdr+.cab installshield cabinet files not being extracted by BOS when relative paths are provided. (#374) * Fixes .hdr+.cab installshield cabinet files not being extracted when relative paths are provided. * Fix for unit tests empty file string. * Better fix for unit test failures, due to https://learn.microsoft.com/en-us/dotnet/api/system.io.path.getfullpath?view=net-9.0 listing several more exceptions than the other functions, most of which I would not imagine should be directly handled. * Removed try-catch fullpath obtaining, added getting fullpath in scanner via filestream name instead. * Undid previous changes again, re-added path assertion at request, added assert.throws exception for empty paths in the unit tests --- .../FileType/InstallShieldCABTests.cs | 9 ++++----- BinaryObjectScanner/FileType/InstallShieldCAB.cs | 2 ++ BinaryObjectScanner/Scanner.cs | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/BinaryObjectScanner.Test/FileType/InstallShieldCABTests.cs b/BinaryObjectScanner.Test/FileType/InstallShieldCABTests.cs index 91f66268..3f041878 100644 --- a/BinaryObjectScanner.Test/FileType/InstallShieldCABTests.cs +++ b/BinaryObjectScanner.Test/FileType/InstallShieldCABTests.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; using BinaryObjectScanner.FileType; using Xunit; @@ -25,8 +26,7 @@ namespace BinaryObjectScanner.Test.FileType string outDir = string.Empty; var extractable = new InstallShieldCAB(); - bool actual = extractable.Extract(stream, file, outDir, includeDebug: false); - Assert.False(actual); + Assert.Throws(() => extractable.Extract(stream, file, outDir, includeDebug: false)); } [Fact] @@ -37,8 +37,7 @@ namespace BinaryObjectScanner.Test.FileType string outDir = string.Empty; var extractable = new InstallShieldCAB(); - bool actual = extractable.Extract(stream, file, outDir, includeDebug: false); - Assert.False(actual); + Assert.Throws(() => extractable.Extract(stream, file, outDir, includeDebug: false)); } } } diff --git a/BinaryObjectScanner/FileType/InstallShieldCAB.cs b/BinaryObjectScanner/FileType/InstallShieldCAB.cs index d7f9a737..4d923a55 100644 --- a/BinaryObjectScanner/FileType/InstallShieldCAB.cs +++ b/BinaryObjectScanner/FileType/InstallShieldCAB.cs @@ -24,6 +24,8 @@ namespace BinaryObjectScanner.FileType /// public bool Extract(Stream? stream, string file, string outDir, bool includeDebug) { + // Handles getting full path if relative paths were passed. + file = Path.GetFullPath(file); // Get the name of the first cabinet file or header var directory = Path.GetDirectoryName(file); string noExtension = Path.GetFileNameWithoutExtension(file); diff --git a/BinaryObjectScanner/Scanner.cs b/BinaryObjectScanner/Scanner.cs index dc223e19..787e0ea0 100644 --- a/BinaryObjectScanner/Scanner.cs +++ b/BinaryObjectScanner/Scanner.cs @@ -207,7 +207,7 @@ namespace BinaryObjectScanner try { using FileStream fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); - return GetInternalProtections(file, fs); + return GetInternalProtections(fs.Name, fs); } catch (Exception ex) {