From 0f95acc92f4fe54db1ac5bc48e3843ad75c9d6f1 Mon Sep 17 00:00:00 2001 From: Violet Hansen Date: Sat, 15 Feb 2025 21:44:48 +0200 Subject: [PATCH] Fixed-wildcard-file-path-rules-for-drive-roots (#600) Fixed an issue with wildcard file paths that you make for supplemental or deny policies by selecting the root of the drives such as C: or D: Previously they would look like C:\\* in the policy XML file but now it's fixed by not adding the extra backward slash when drive root is selected. --- AppControl Manager/XMLOps/SignerAndHashBuilder.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/AppControl Manager/XMLOps/SignerAndHashBuilder.cs b/AppControl Manager/XMLOps/SignerAndHashBuilder.cs index eade45e91..c93c2d68e 100644 --- a/AppControl Manager/XMLOps/SignerAndHashBuilder.cs +++ b/AppControl Manager/XMLOps/SignerAndHashBuilder.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using AppControlManager.IntelGathering; using AppControlManager.Others; @@ -6,6 +7,11 @@ namespace AppControlManager.XMLOps; internal static class SignerAndHashBuilder { + // Get all of the drive letters on the system + private static readonly List Drives = DriveLetterMapper.GetGlobalRootDrives(); + private static readonly IEnumerable DriveLetters = Drives.Select(x => x.DriveLetter); + + /// /// Creates Signer and Hash objects from the input data /// @@ -378,8 +384,9 @@ internal static FileBasedInfoPackage BuildSignerAndHashObjects( foreach (string item in wildCardFilePathData) { - // Create wildcard path - string wildcardPath = item + @"\" + "*"; + + // Create wildcard path - If user selected a root of a drive then do not add the extra backward slash otherwise we'd create an invalid path such as "D:\\*" in the policy + string wildcardPath = DriveLetters.Any(x => string.Equals(x, item[..^1], System.StringComparison.OrdinalIgnoreCase)) ? item + "*" : item + @"\" + "*"; // FilePath rules can only be used for User-Mode files only // Plus we wouldn't know if the folder contains user-mode or kernel-mode files