diff --git a/AppControl Manager/Logic/GetFilesFast.cs b/AppControl Manager/Logic/GetFilesFast.cs index a720a7af8..f694d7b17 100644 --- a/AppControl Manager/Logic/GetFilesFast.cs +++ b/AppControl Manager/Logic/GetFilesFast.cs @@ -76,7 +76,7 @@ internal static List GetFilesFast( }; // If custom extensions are provided, use them and make them case-insensitive - if (extensionsToFilterBy is not null && extensionsToFilterBy.Length > 0) + if (extensionsToFilterBy is { Length: > 0 }) { extensions = new HashSet(extensionsToFilterBy, StringComparer.OrdinalIgnoreCase); } @@ -93,7 +93,7 @@ internal static List GetFilesFast( List tasks = []; // Process directories if provided - if (directories is not null && directories.Length > 0) + if (directories is { Length: > 0 }) { foreach (DirectoryInfo directory in directories) { @@ -163,7 +163,7 @@ internal static List GetFilesFast( } // If files are provided, process them - if (files is not null && files.Length > 0) + if (files is { Length: > 0 }) { foreach (FileInfo file in files) { diff --git a/AppControl Manager/Logic/Main/AppControlSimulation.cs b/AppControl Manager/Logic/Main/AppControlSimulation.cs index b93fd7abf..f9af38efa 100644 --- a/AppControl Manager/Logic/Main/AppControlSimulation.cs +++ b/AppControl Manager/Logic/Main/AppControlSimulation.cs @@ -193,7 +193,7 @@ internal static ConcurrentDictionary Invoke( // Loop through each .cat security catalog on the system - If user selected custom CatRoot folders then use them instead DirectoryInfo[] catRootDirectories = []; - if (catRootPath is not null && catRootPath.Count > 0) + if (catRootPath is { Count: > 0 }) { catRootDirectories = [.. catRootPath.Select(dir => new DirectoryInfo(dir))]; } diff --git a/AppControl Manager/Logic/MoveUserModeToKernelMode.cs b/AppControl Manager/Logic/MoveUserModeToKernelMode.cs index c0d854459..3c742017b 100644 --- a/AppControl Manager/Logic/MoveUserModeToKernelMode.cs +++ b/AppControl Manager/Logic/MoveUserModeToKernelMode.cs @@ -24,7 +24,7 @@ public static void Move(string filePath) XmlNode? allowedSigners12 = codeIntegrityPolicy.UMCI_SigningScenarioNode?.SelectSingleNode("./ns:ProductSigners/ns:AllowedSigners", codeIntegrityPolicy.NamespaceManager); // If AllowedSigners node exists in SigningScenario 12 and has child nodes - if (allowedSigners12 is not null && allowedSigners12.HasChildNodes) + if (allowedSigners12 is { HasChildNodes: true }) { // Loop through each child node of AllowedSigners in SigningScenario 12 foreach (XmlNode allowedSignerNode in allowedSigners12.ChildNodes) diff --git a/AppControl Manager/Logic/PolicyFileSigningStatusDetection.cs b/AppControl Manager/Logic/PolicyFileSigningStatusDetection.cs index c74a76e94..c31ea89e6 100644 --- a/AppControl Manager/Logic/PolicyFileSigningStatusDetection.cs +++ b/AppControl Manager/Logic/PolicyFileSigningStatusDetection.cs @@ -28,7 +28,7 @@ internal static IntelGathering.SignatureStatus Check(string policyXMLPath) // Check if SupplementalPolicySigners exists and has child nodes XmlNodeList? supplementalPolicySignersNodes = codeIntegrityPolicy.SiPolicyNode.SelectNodes("ns:SupplementalPolicySigners/ns:SupplementalPolicySigner", codeIntegrityPolicy.NamespaceManager); - if (supplementalPolicySignersNodes is not null && supplementalPolicySignersNodes.Count > 0) + if (supplementalPolicySignersNodes is { Count: > 0 }) { // Get unique SignerIds from SupplementalPolicySigners foreach (XmlElement node in supplementalPolicySignersNodes) @@ -40,7 +40,7 @@ internal static IntelGathering.SignatureStatus Check(string policyXMLPath) // Check if UpdatePolicySigners exists and has child nodes XmlNodeList? updatePolicySignersNodes = codeIntegrityPolicy.SiPolicyNode.SelectNodes("ns:UpdatePolicySigners/ns:UpdatePolicySigner", codeIntegrityPolicy.NamespaceManager); - if (updatePolicySignersNodes is not null && updatePolicySignersNodes.Count > 0) + if (updatePolicySignersNodes is { Count: > 0 }) { // Get unique SignerIds from UpdatePolicySigners foreach (XmlElement node in updatePolicySignersNodes) diff --git a/AppControl Manager/Logic/RemoveSupplementalSigners.cs b/AppControl Manager/Logic/RemoveSupplementalSigners.cs index 9d7106008..4bdc40858 100644 --- a/AppControl Manager/Logic/RemoveSupplementalSigners.cs +++ b/AppControl Manager/Logic/RemoveSupplementalSigners.cs @@ -36,7 +36,7 @@ internal static void RemoveSupplementalSigners(string path) // Check if SupplementalPolicySigners exists and has child nodes XmlNodeList? supplementalPolicySignersNodes = codeIntegrityPolicy.SiPolicyNode.SelectNodes("ns:SupplementalPolicySigners", codeIntegrityPolicy.NamespaceManager); - if (supplementalPolicySignersNodes is not null && supplementalPolicySignersNodes.Count > 0) + if (supplementalPolicySignersNodes is { Count: > 0 }) { Logger.Write("Removing the SupplementalPolicySigners blocks and corresponding Signers"); diff --git a/AppControl Manager/Pages/AllowNewApps/AllowNewAppsStart.xaml.cs b/AppControl Manager/Pages/AllowNewApps/AllowNewAppsStart.xaml.cs index 072af7db8..e6f4490b3 100644 --- a/AppControl Manager/Pages/AllowNewApps/AllowNewAppsStart.xaml.cs +++ b/AppControl Manager/Pages/AllowNewApps/AllowNewAppsStart.xaml.cs @@ -672,7 +672,7 @@ private void BrowseForFoldersButton_Click(object sender, RoutedEventArgs e) List? selectedFolders = FileDialogHelper.ShowMultipleDirectoryPickerDialog(); - if (selectedFolders is not null && selectedFolders.Count > 0) + if (selectedFolders is { Count: > 0 }) { // Add each folder to the HashSet of the selected directories foreach (string folder in selectedFolders) diff --git a/AppControl Manager/Pages/CreateDenyPolicy.xaml.cs b/AppControl Manager/Pages/CreateDenyPolicy.xaml.cs index cb446c697..33ce6ae14 100644 --- a/AppControl Manager/Pages/CreateDenyPolicy.xaml.cs +++ b/AppControl Manager/Pages/CreateDenyPolicy.xaml.cs @@ -302,7 +302,7 @@ private void FilesAndFoldersBrowseForFilesSettingsCard_Click(object sender, Rout List? selectedFiles = FileDialogHelper.ShowMultipleFilePickerDialog(filter); - if (selectedFiles is not null && selectedFiles.Count != 0) + if (selectedFiles is { Count: > 0 }) { foreach (string file in selectedFiles) { @@ -330,7 +330,7 @@ private void FilesAndFoldersBrowseForFilesButton_Click(object sender, RoutedEven List? selectedFiles = FileDialogHelper.ShowMultipleFilePickerDialog(filter); - if (selectedFiles is not null && selectedFiles.Count != 0) + if (selectedFiles is { Count: > 0 }) { foreach (string file in selectedFiles) { @@ -353,7 +353,7 @@ private void FilesAndFoldersBrowseForFoldersSettingsCard_Click(object sender, Ro List? selectedDirectories = FileDialogHelper.ShowMultipleDirectoryPickerDialog(); - if (selectedDirectories is not null && selectedDirectories.Count > 0) + if (selectedDirectories is { Count: > 0 }) { foreach (string dir in selectedDirectories) { @@ -378,7 +378,7 @@ private void FilesAndFoldersBrowseForFoldersButton_Click(object sender, RoutedEv { List? selectedDirectories = FileDialogHelper.ShowMultipleDirectoryPickerDialog(); - if (selectedDirectories is not null && selectedDirectories.Count > 0) + if (selectedDirectories is { Count: > 0 }) { foreach (string dir in selectedDirectories) { diff --git a/AppControl Manager/Pages/CreateSupplementalPolicy.xaml.cs b/AppControl Manager/Pages/CreateSupplementalPolicy.xaml.cs index e93587d5a..86d164c50 100644 --- a/AppControl Manager/Pages/CreateSupplementalPolicy.xaml.cs +++ b/AppControl Manager/Pages/CreateSupplementalPolicy.xaml.cs @@ -139,7 +139,7 @@ private void FilesAndFoldersBrowseForFilesSettingsCard_Click(object sender, Rout List? selectedFiles = FileDialogHelper.ShowMultipleFilePickerDialog(filter); - if (selectedFiles is not null && selectedFiles.Count != 0) + if (selectedFiles is { Count: > 0 }) { foreach (string file in selectedFiles) { @@ -167,7 +167,7 @@ private void FilesAndFoldersBrowseForFilesButton_Click(object sender, RoutedEven List? selectedFiles = FileDialogHelper.ShowMultipleFilePickerDialog(filter); - if (selectedFiles is not null && selectedFiles.Count != 0) + if (selectedFiles is { Count: > 0 }) { foreach (string file in selectedFiles) { @@ -191,7 +191,7 @@ private void FilesAndFoldersBrowseForFoldersSettingsCard_Click(object sender, Ro List? selectedDirectories = FileDialogHelper.ShowMultipleDirectoryPickerDialog(); - if (selectedDirectories is not null && selectedDirectories.Count > 0) + if (selectedDirectories is { Count: > 0 }) { foreach (string dir in selectedDirectories) { @@ -217,7 +217,7 @@ private void FilesAndFoldersBrowseForFoldersButton_Click(object sender, RoutedEv { List? selectedDirectories = FileDialogHelper.ShowMultipleDirectoryPickerDialog(); - if (selectedDirectories is not null && selectedDirectories.Count > 0) + if (selectedDirectories is { Count: > 0 }) { foreach (string dir in selectedDirectories) { @@ -667,7 +667,7 @@ private void CertificatesBrowseForCertsButton_Click(object sender, RoutedEventAr List? selectedFiles = FileDialogHelper.ShowMultipleFilePickerDialog(filter); - if (selectedFiles is not null && selectedFiles.Count != 0) + if (selectedFiles is { Count: > 0 }) { foreach (string file in selectedFiles) { @@ -682,7 +682,7 @@ private void CertificatesBrowseForCertsSettingsCard_Click(object sender, RoutedE List? selectedFiles = FileDialogHelper.ShowMultipleFilePickerDialog(filter); - if (selectedFiles is not null && selectedFiles.Count != 0) + if (selectedFiles is { Count: > 0 }) { foreach (string file in selectedFiles) { diff --git a/AppControl Manager/Pages/Deployment.xaml.cs b/AppControl Manager/Pages/Deployment.xaml.cs index 93a32cb08..b725eadae 100644 --- a/AppControl Manager/Pages/Deployment.xaml.cs +++ b/AppControl Manager/Pages/Deployment.xaml.cs @@ -170,7 +170,7 @@ private void BrowseForXMLPolicyFilesButton_Click(object sender, RoutedEventArgs List? selectedFiles = FileDialogHelper.ShowMultipleFilePickerDialog(filter); - if (selectedFiles is not null && selectedFiles.Count != 0) + if (selectedFiles is { Count: > 0 }) { foreach (string file in selectedFiles) { @@ -185,7 +185,7 @@ private void BrowseForXMLPolicyFilesSettingsCard_Click(object sender, RoutedEven List? selectedFiles = FileDialogHelper.ShowMultipleFilePickerDialog(filter); - if (selectedFiles is not null && selectedFiles.Count != 0) + if (selectedFiles is { Count: > 0 }) { foreach (string file in selectedFiles) { @@ -200,7 +200,7 @@ private void BrowseForCIPBinaryFilesButton_Click(object sender, RoutedEventArgs List? selectedFiles = FileDialogHelper.ShowMultipleFilePickerDialog(filter); - if (selectedFiles is not null && selectedFiles.Count != 0) + if (selectedFiles is { Count: > 0 }) { foreach (string file in selectedFiles) { @@ -215,7 +215,7 @@ private void BrowseForCIPBinaryFilesSettingsCard_Click(object sender, RoutedEven List? selectedFiles = FileDialogHelper.ShowMultipleFilePickerDialog(filter); - if (selectedFiles is not null && selectedFiles.Count != 0) + if (selectedFiles is { Count: > 0 }) { foreach (string file in selectedFiles) { diff --git a/AppControl Manager/Pages/GitHubDocumentation.xaml.cs b/AppControl Manager/Pages/GitHubDocumentation.xaml.cs index c4879ba3b..29a42bbb5 100644 --- a/AppControl Manager/Pages/GitHubDocumentation.xaml.cs +++ b/AppControl Manager/Pages/GitHubDocumentation.xaml.cs @@ -61,7 +61,7 @@ private void WebView2_NavigationCompleted(object sender, Microsoft.Web.WebView2. { // Check if the WebView2 control or its CoreWebView2 instance is disposed - if (GitHubDocumentationWebView2 is not null && GitHubDocumentationWebView2.CoreWebView2 is not null) + if (GitHubDocumentationWebView2 is { CoreWebView2: not null }) { BackButton.IsEnabled = GitHubDocumentationWebView2.CanGoBack; ForwardButton.IsEnabled = GitHubDocumentationWebView2.CanGoForward; diff --git a/AppControl Manager/Pages/MergePolicies.xaml.cs b/AppControl Manager/Pages/MergePolicies.xaml.cs index e769c7fdd..b7c71388d 100644 --- a/AppControl Manager/Pages/MergePolicies.xaml.cs +++ b/AppControl Manager/Pages/MergePolicies.xaml.cs @@ -163,7 +163,7 @@ private void OtherPoliciesBrowseButton_Click(object sender, RoutedEventArgs e) List? selectedFiles = FileDialogHelper.ShowMultipleFilePickerDialog(filter); - if (selectedFiles is not null && selectedFiles.Count != 0) + if (selectedFiles is { Count: > 0 }) { foreach (string file in selectedFiles) { @@ -183,7 +183,7 @@ private void OtherPoliciesSettingsCard_Click(object sender, RoutedEventArgs e) List? selectedFiles = FileDialogHelper.ShowMultipleFilePickerDialog(filter); - if (selectedFiles is not null && selectedFiles.Count != 0) + if (selectedFiles is { Count: > 0 }) { foreach (string file in selectedFiles) { diff --git a/AppControl Manager/Pages/MicrosoftDocumentation.xaml.cs b/AppControl Manager/Pages/MicrosoftDocumentation.xaml.cs index 6d9586945..4ac9c8927 100644 --- a/AppControl Manager/Pages/MicrosoftDocumentation.xaml.cs +++ b/AppControl Manager/Pages/MicrosoftDocumentation.xaml.cs @@ -57,7 +57,7 @@ private void WebView2_NavigationCompleted(object sender, Microsoft.Web.WebView2. try { // Check if the WebView2 control or its CoreWebView2 instance is disposed - if (MicrosoftDocumentationWebView2 is not null && MicrosoftDocumentationWebView2.CoreWebView2 is not null) + if (MicrosoftDocumentationWebView2 is { CoreWebView2: not null }) { BackButton.IsEnabled = MicrosoftDocumentationWebView2.CanGoBack; ForwardButton.IsEnabled = MicrosoftDocumentationWebView2.CanGoForward; diff --git a/AppControl Manager/Pages/Simulation.xaml.cs b/AppControl Manager/Pages/Simulation.xaml.cs index fd9bbf534..cc81eef1e 100644 --- a/AppControl Manager/Pages/Simulation.xaml.cs +++ b/AppControl Manager/Pages/Simulation.xaml.cs @@ -169,7 +169,7 @@ private void SelectFilesButton_Click(object sender, RoutedEventArgs e) List? selectedFiles = FileDialogHelper.ShowMultipleFilePickerDialog(filter); - if (selectedFiles is not null && selectedFiles.Count != 0) + if (selectedFiles is { Count: > 0 }) { filePaths = [.. selectedFiles]; } @@ -193,7 +193,7 @@ private void CatRootPathsButton_Click(object sender, RoutedEventArgs e) { List? selectedCatRoots = FileDialogHelper.ShowMultipleDirectoryPickerDialog(); - if (selectedCatRoots is not null && selectedCatRoots.Count > 0) + if (selectedCatRoots is { Count: > 0 }) { catRootPaths = selectedCatRoots; } diff --git a/AppControl Manager/Pages/Update.xaml.cs b/AppControl Manager/Pages/Update.xaml.cs index 09c4c7c89..58f4c0b5b 100644 --- a/AppControl Manager/Pages/Update.xaml.cs +++ b/AppControl Manager/Pages/Update.xaml.cs @@ -87,7 +87,7 @@ private async void CheckForUpdateButton_Click(object sender, RoutedEventArgs e) } // If a new version is available or user supplied a custom MSIX path to be installed - if ((updateCheckResult is not null && updateCheckResult.IsNewVersionAvailable) || useCustomMSIXPath) + if ((updateCheckResult is { IsNewVersionAvailable: true }) || useCustomMSIXPath) { string msg1; diff --git a/AppControl Manager/SiPolicy/Merger.Aggregate.cs b/AppControl Manager/SiPolicy/Merger.Aggregate.cs index 7ce388dd1..744d49d5b 100644 --- a/AppControl Manager/SiPolicy/Merger.Aggregate.cs +++ b/AppControl Manager/SiPolicy/Merger.Aggregate.cs @@ -32,7 +32,7 @@ internal static HashSet CollectAllowRules(List siPolicies) // Get all possible FileRuleRef items from the current signing scenario FileRuleRef[]? possibleFileRuleRef = signingScenario.ProductSigners?.FileRulesRef?.FileRuleRef; - if (possibleFileRuleRef is not null && possibleFileRuleRef.Length > 0) + if (possibleFileRuleRef is { Length: > 0 }) { foreach (FileRuleRef fileRuleRef in possibleFileRuleRef) { @@ -88,7 +88,7 @@ internal static HashSet CollectDenyRules(List siPolicies) // Get all possible FileRuleRef items from the current signing scenario FileRuleRef[]? possibleFileRuleRef = signingScenario.ProductSigners?.FileRulesRef?.FileRuleRef; - if (possibleFileRuleRef is not null && possibleFileRuleRef.Length > 0) + if (possibleFileRuleRef is { Length: > 0 }) { foreach (FileRuleRef fileRuleRef in possibleFileRuleRef) { @@ -164,7 +164,7 @@ internal static SignerCollection CollectSignerRules(List siPolicies) AllowedSigner[]? allowedSigners = possibleProdSigners.AllowedSigners?.AllowedSigner; DeniedSigner[]? deniedSigners = possibleProdSigners.DeniedSigners?.DeniedSigner; - if (allowedSigners is not null && allowedSigners.Length > 0) + if (allowedSigners is { Length: > 0 }) { // Process Allowed Signers foreach (AllowedSigner item in allowedSigners) @@ -189,7 +189,7 @@ internal static SignerCollection CollectSignerRules(List siPolicies) } } - if (deniedSigners is not null && deniedSigners.Length > 0) + if (deniedSigners is { Length: > 0 }) { // Process Denied Signers foreach (DeniedSigner item in deniedSigners) diff --git a/AppControl Manager/SiPolicy/Merger.cs b/AppControl Manager/SiPolicy/Merger.cs index b5906f2c4..88b85c316 100644 --- a/AppControl Manager/SiPolicy/Merger.cs +++ b/AppControl Manager/SiPolicy/Merger.cs @@ -155,7 +155,7 @@ internal static void Merge(string mainXmlFilePath, HashSet otherXmlFileP }; // Add miscellaneous settings to the User Mode Signing Scenario from the Main XML - if (mainXMLUserModeSigningScenario is not null && mainXMLUserModeSigningScenario.MinimumHashAlgorithmSpecified) + if (mainXMLUserModeSigningScenario is { MinimumHashAlgorithmSpecified: true }) { UMCISigningScenario.MinimumHashAlgorithmSpecified = true; UMCISigningScenario.MinimumHashAlgorithm = mainXMLUserModeSigningScenario.MinimumHashAlgorithm; @@ -191,7 +191,7 @@ internal static void Merge(string mainXmlFilePath, HashSet otherXmlFileP // Add miscellaneous settings to the Kernel Mode Signing Scenario from the Main XML - if (mainXMLKernelModeSigningScenario is not null && mainXMLKernelModeSigningScenario.MinimumHashAlgorithmSpecified) + if (mainXMLKernelModeSigningScenario is { MinimumHashAlgorithmSpecified: true }) { KMCISigningScenario.MinimumHashAlgorithmSpecified = true; KMCISigningScenario.MinimumHashAlgorithm = mainXMLKernelModeSigningScenario.MinimumHashAlgorithm; diff --git a/Harden-Windows-Security Module/Main files/C#/CimInstances/BitLocker-AddKeyProtectors.cs b/Harden-Windows-Security Module/Main files/C#/CimInstances/BitLocker-AddKeyProtectors.cs index e2c265b0f..102b937a7 100644 --- a/Harden-Windows-Security Module/Main files/C#/CimInstances/BitLocker-AddKeyProtectors.cs +++ b/Harden-Windows-Security Module/Main files/C#/CimInstances/BitLocker-AddKeyProtectors.cs @@ -56,7 +56,7 @@ private static void RemoveTpmBasedKeyProtectors(ManagementObject driveInstance, string[] KeyProtectorIDs = (string[])keyProtectorResult["VolumeKeyProtectorID"]; // Check if there is at least 1 key protector - if (KeyProtectorIDs is not null && KeyProtectorIDs.Length >= 1) + if (KeyProtectorIDs is { Length: >= 1 }) { // Loop over all of the key protectors of the specified type and remove all of them foreach (string KeyProtectorID in KeyProtectorIDs) @@ -79,7 +79,7 @@ private static void RemoveTpmBasedKeyProtectors(ManagementObject driveInstance, deletionResultCode = Convert.ToUInt32(deletionResult["ReturnValue"], CultureInfo.InvariantCulture); } - if (deletionResultCode is not null && deletionResultCode == 0) + if (deletionResultCode is 0) { Logger.LogMessage($"Successfully removed a key protector of type {keyProtectorType}", LogTypeIntel.Information); } @@ -136,7 +136,7 @@ internal static void AddRecoveryPassword(string DriveLetter, string? Password) MethodInvocationResultCode = Convert.ToUInt32(MethodInvocationResult["ReturnValue"], CultureInfo.InvariantCulture); } - if (MethodInvocationResultCode is not null && MethodInvocationResultCode == 0) + if (MethodInvocationResultCode is 0) { Logger.LogMessage("Successfully added the Recovery Password key protector.", LogTypeIntel.Information); } @@ -185,7 +185,7 @@ internal static void AddPasswordProtector(string DriveLetter, string? PassPhrase MethodInvocationResultCode = Convert.ToUInt32(MethodInvocationResult["ReturnValue"], CultureInfo.InvariantCulture); } - if (MethodInvocationResultCode is not null && MethodInvocationResultCode == 0) + if (MethodInvocationResultCode is 0) { Logger.LogMessage("Successfully added Password key protector (aka Passphrase).", LogTypeIntel.Information); } @@ -230,7 +230,7 @@ internal static void AddTpmProtector(string DriveLetter) MethodInvocationResultCode = Convert.ToUInt32(MethodInvocationResult["ReturnValue"], CultureInfo.InvariantCulture); } - if (MethodInvocationResultCode is not null && MethodInvocationResultCode == 0) + if (MethodInvocationResultCode is 0) { Logger.LogMessage("Successfully added the TPM key protector.", LogTypeIntel.Information); } @@ -289,7 +289,7 @@ internal static void AddTpmAndPinProtector(string DriveLetter, string PIN) MethodInvocationResultCode = Convert.ToUInt32(MethodInvocationResult["ReturnValue"], CultureInfo.InvariantCulture); } - if (MethodInvocationResultCode is not null && MethodInvocationResultCode == 0) + if (MethodInvocationResultCode is 0) { Logger.LogMessage("Successfully added the TpmAndPin key protector.", LogTypeIntel.Information); } @@ -349,7 +349,7 @@ internal static void AddTpmAndStartupKeyProtector(string DriveLetter, string Sta MethodInvocationResultCode = Convert.ToUInt32(ProtectKeyWithTPMAndStartupKeyMethodInvocationResult["ReturnValue"], CultureInfo.InvariantCulture); } - if (MethodInvocationResultCode is not null && MethodInvocationResultCode == 0) + if (MethodInvocationResultCode is 0) { Logger.LogMessage("The TpmAndStartupKey key protector was successfully added. Backing up the Startup key in the next step.", LogTypeIntel.Information); } @@ -378,7 +378,7 @@ internal static void AddTpmAndStartupKeyProtector(string DriveLetter, string Sta MethodInvocationResultCode2 = Convert.ToUInt32(SaveExternalKeyToFileMethodInvocationResult["ReturnValue"], CultureInfo.InvariantCulture); } - if (MethodInvocationResultCode2 is not null && MethodInvocationResultCode2 == 0) + if (MethodInvocationResultCode2 is 0) { Logger.LogMessage($"Successfully backed up the Startup key to {StartupKeyPath}", LogTypeIntel.Information); @@ -443,7 +443,7 @@ internal static void AddTpmAndPinAndStartupKeyProtector(string DriveLetter, stri MethodInvocationResultCode = Convert.ToUInt32(ProtectKeyWithTPMAndPinAndStartupKeyMethodInvocationResult["ReturnValue"], CultureInfo.InvariantCulture); } - if (MethodInvocationResultCode is not null && MethodInvocationResultCode == 0) + if (MethodInvocationResultCode is 0) { Logger.LogMessage("The TpmAndPinAndStartupKey key protector was successfully added. Will backup the startup key in the next step.", LogTypeIntel.Information); } @@ -471,7 +471,7 @@ internal static void AddTpmAndPinAndStartupKeyProtector(string DriveLetter, stri MethodInvocationResultCode2 = Convert.ToUInt32(SaveExternalKeyToFileMethodInvocationResult["ReturnValue"], CultureInfo.InvariantCulture); } - if (MethodInvocationResultCode2 is not null && MethodInvocationResultCode2 == 0) + if (MethodInvocationResultCode2 is 0) { Logger.LogMessage($"Successfully backed up the startup key to {StartupKeyPath}", LogTypeIntel.Information); @@ -535,7 +535,7 @@ internal static void AddStartupKeyProtector_OR_RecoveryKeyProtector(string Drive MethodInvocationResultCode = Convert.ToUInt32(ProtectKeyWithExternalKeyMethodInvocationResult["ReturnValue"], CultureInfo.InvariantCulture); } - if (MethodInvocationResultCode is not null && MethodInvocationResultCode == 0) + if (MethodInvocationResultCode is 0) { Logger.LogMessage("The StartupKey key protector was successfully added. Will back up it in the next step.", LogTypeIntel.Information); // Will move forward to the next step @@ -564,7 +564,7 @@ internal static void AddStartupKeyProtector_OR_RecoveryKeyProtector(string Drive MethodInvocationResultCode2 = Convert.ToUInt32(SaveExternalKeyToFileMethodInvocationResult["ReturnValue"], CultureInfo.InvariantCulture); } - if (MethodInvocationResultCode2 is not null && MethodInvocationResultCode2 == 0) + if (MethodInvocationResultCode2 is 0) { Logger.LogMessage($"Successfully backed up the Startup key to {StartupKeyPath}", LogTypeIntel.Information); } @@ -633,7 +633,7 @@ internal static void AddSidProtector(string DriveLetter, string SID, bool Servic MethodInvocationResultCode = Convert.ToUInt32(MethodInvocationResult["ReturnValue"], CultureInfo.InvariantCulture); } - if (MethodInvocationResultCode is not null && MethodInvocationResultCode == 0) + if (MethodInvocationResultCode is 0) { Logger.LogMessage("Successfully added the SID key protector.", LogTypeIntel.Information); } diff --git a/Harden-Windows-Security Module/Main files/C#/CimInstances/BitLocker-Disable.cs b/Harden-Windows-Security Module/Main files/C#/CimInstances/BitLocker-Disable.cs index 0f94f007b..33b212283 100644 --- a/Harden-Windows-Security Module/Main files/C#/CimInstances/BitLocker-Disable.cs +++ b/Harden-Windows-Security Module/Main files/C#/CimInstances/BitLocker-Disable.cs @@ -63,7 +63,7 @@ internal static void Disable(string DriveLetter) MethodInvocationResultCode = Convert.ToUInt32(IsAutoUnlockKeyStoredMethodInvocationResult["ReturnValue"], CultureInfo.InvariantCulture); } - if (MethodInvocationResultCode is not null && MethodInvocationResultCode == 0) + if (MethodInvocationResultCode is 0) { Logger.LogMessage("Successfully checked the OS Drive for any stored auto-unlock keys.", LogTypeIntel.Information); // Will move forward to the next step @@ -108,7 +108,7 @@ internal static void Disable(string DriveLetter) DecryptMethodInvocationResultCode = Convert.ToUInt32(DecryptMethodInvocationResult["ReturnValue"], CultureInfo.InvariantCulture); } - if (DecryptMethodInvocationResultCode is not null && DecryptMethodInvocationResultCode == 0) + if (DecryptMethodInvocationResultCode is 0) { Logger.LogMessage($"Successfully Decrypted the drive {DriveLetter}", LogTypeIntel.InformationInteractionRequired); } diff --git a/Harden-Windows-Security Module/Main files/C#/CimInstances/BitLocker-Enable.cs b/Harden-Windows-Security Module/Main files/C#/CimInstances/BitLocker-Enable.cs index 8a98529ee..ce9607663 100644 --- a/Harden-Windows-Security Module/Main files/C#/CimInstances/BitLocker-Enable.cs +++ b/Harden-Windows-Security Module/Main files/C#/CimInstances/BitLocker-Enable.cs @@ -213,7 +213,7 @@ internal static void Enable(string DriveLetter, OSEncryptionType OSEncryptionTyp PrepareVolumeResultCode = Convert.ToUInt32(PrepareVolumeMethodInvocationResult["ReturnValue"], CultureInfo.InvariantCulture); } - if (PrepareVolumeResultCode is not null && PrepareVolumeResultCode == 0) + if (PrepareVolumeResultCode is 0) { Logger.LogMessage($"Successfully prepared the drive {DriveLetter} for encryption.", LogTypeIntel.Information); } @@ -296,7 +296,7 @@ internal static void Enable(string DriveLetter, OSEncryptionType OSEncryptionTyp EncryptResultCode = Convert.ToUInt32(EncryptMethodInvocationResult["ReturnValue"], CultureInfo.InvariantCulture); } - if (EncryptResultCode is not null && EncryptResultCode == 0) + if (EncryptResultCode is 0) { Logger.LogMessage($"Successfully Encrypted the drive {DriveLetter}.", LogTypeIntel.Information); } @@ -490,7 +490,7 @@ internal static void Enable(string DriveLetter, bool FreePlusUsedSpace) PrepareVolumeResultCode = Convert.ToUInt32(PrepareVolumeMethodInvocationResult["ReturnValue"], CultureInfo.InvariantCulture); } - if (PrepareVolumeResultCode is not null && PrepareVolumeResultCode == 0) + if (PrepareVolumeResultCode is 0) { Logger.LogMessage($"Successfully prepared the drive {DriveLetter} for encryption.", LogTypeIntel.Information); } @@ -548,7 +548,7 @@ internal static void Enable(string DriveLetter, bool FreePlusUsedSpace) EncryptResultCode = Convert.ToUInt32(EncryptMethodInvocationResult["ReturnValue"], CultureInfo.InvariantCulture); } - if (EncryptResultCode is not null && EncryptResultCode == 0) + if (EncryptResultCode is 0) { Logger.LogMessage($"Successfully Encrypted the drive {DriveLetter}.", LogTypeIntel.Information); } @@ -624,7 +624,7 @@ internal static void Enable(string DriveLetter, string? Password, bool FreePlusU PrepareVolumeResultCode = Convert.ToUInt32(PrepareVolumeMethodInvocationResult["ReturnValue"], CultureInfo.InvariantCulture); } - if (PrepareVolumeResultCode is not null && PrepareVolumeResultCode == 0) + if (PrepareVolumeResultCode is 0) { Logger.LogMessage($"Successfully prepared the drive {DriveLetter} for encryption.", LogTypeIntel.Information); } @@ -686,7 +686,7 @@ internal static void Enable(string DriveLetter, string? Password, bool FreePlusU EncryptResultCode = Convert.ToUInt32(EncryptMethodInvocationResult["ReturnValue"], CultureInfo.InvariantCulture); } - if (EncryptResultCode is not null && EncryptResultCode == 0) + if (EncryptResultCode is 0) { Logger.LogMessage($"Successfully Encrypted the drive {DriveLetter}.", LogTypeIntel.Information); } diff --git a/Harden-Windows-Security Module/Main files/C#/CimInstances/BitLocker-EnableBitLockerAutoUnlock.cs b/Harden-Windows-Security Module/Main files/C#/CimInstances/BitLocker-EnableBitLockerAutoUnlock.cs index e2a5ff985..1149e7132 100644 --- a/Harden-Windows-Security Module/Main files/C#/CimInstances/BitLocker-EnableBitLockerAutoUnlock.cs +++ b/Harden-Windows-Security Module/Main files/C#/CimInstances/BitLocker-EnableBitLockerAutoUnlock.cs @@ -33,7 +33,7 @@ internal static void EnableBitLockerAutoUnlock(string DriveLetter) IsAutoUnlockEnabledResultCode = Convert.ToUInt32(IsAutoUnlockEnabledResult["ReturnValue"], CultureInfo.InvariantCulture); } - if (IsAutoUnlockEnabledResultCode is not null && IsAutoUnlockEnabledResultCode == 0) + if (IsAutoUnlockEnabledResultCode is 0) { Logger.LogMessage($"Successfully queried the Auto-unlock status of the drive {DriveLetter}.", LogTypeIntel.Information); } @@ -67,7 +67,7 @@ internal static void EnableBitLockerAutoUnlock(string DriveLetter) MethodInvocationResultCode = Convert.ToUInt32(ProtectKeyWithExternalKeyMethodInvocationResult["ReturnValue"], CultureInfo.InvariantCulture); } - if (MethodInvocationResultCode is not null && MethodInvocationResultCode == 0) + if (MethodInvocationResultCode is 0) { Logger.LogMessage("The ExternalKey key protector was successfully added.", LogTypeIntel.Information); // Will move forward to the next step @@ -97,7 +97,7 @@ internal static void EnableBitLockerAutoUnlock(string DriveLetter) EnableAutoUnlockMethodInvocationResultCode = Convert.ToUInt32(EnableAutoUnlockMethodInvocationResult["ReturnValue"], CultureInfo.InvariantCulture); } - if (EnableAutoUnlockMethodInvocationResultCode is not null && EnableAutoUnlockMethodInvocationResultCode == 0) + if (EnableAutoUnlockMethodInvocationResultCode is 0) { Logger.LogMessage($"Auto-Unlock has been successfully enabled for the drive: {DriveLetter}", LogTypeIntel.Information); } diff --git a/Harden-Windows-Security Module/Main files/C#/CimInstances/BitLocker-EnableKeyProtectors.cs b/Harden-Windows-Security Module/Main files/C#/CimInstances/BitLocker-EnableKeyProtectors.cs index f1c944b3a..259a0bd93 100644 --- a/Harden-Windows-Security Module/Main files/C#/CimInstances/BitLocker-EnableKeyProtectors.cs +++ b/Harden-Windows-Security Module/Main files/C#/CimInstances/BitLocker-EnableKeyProtectors.cs @@ -36,7 +36,7 @@ internal static void EnableKeyProtectors(string DriveLetter) KeyProtectorEnablementResultCode = Convert.ToUInt32(KeyProtectorEnablementResult["ReturnValue"], CultureInfo.InvariantCulture); } - if (KeyProtectorEnablementResultCode is not null && KeyProtectorEnablementResultCode == 0) + if (KeyProtectorEnablementResultCode is 0) { Logger.LogMessage($"Successfully enabled the key protectors of the drive {DriveLetter}.", LogTypeIntel.Information); } diff --git a/Harden-Windows-Security Module/Main files/C#/GUI/ASRRules/View.cs b/Harden-Windows-Security Module/Main files/C#/GUI/ASRRules/View.cs index 53597c83c..17d6f6de1 100644 --- a/Harden-Windows-Security Module/Main files/C#/GUI/ASRRules/View.cs +++ b/Harden-Windows-Security Module/Main files/C#/GUI/ASRRules/View.cs @@ -108,7 +108,7 @@ void ProcessListViewItems(ListView listView) ComboBox? comboBox = stackPanel.Children.OfType().FirstOrDefault(); // To make sure the ComboBox's selected index is not -1 indicating it's empty - if (comboBox is not null && comboBox.SelectedIndex is not -1) + if (comboBox is { SelectedIndex: not -1 }) { // Add the ComboBox Name as string key and ComboBox SelectedIndex as byte value comboBoxDictionary[comboBox.Name.ToString()] = (byte)comboBox.SelectedIndex; diff --git a/Harden-Windows-Security Module/Main files/C#/GUI/Confirm/View.cs b/Harden-Windows-Security Module/Main files/C#/GUI/Confirm/View.cs index 474937d29..05615a25c 100644 --- a/Harden-Windows-Security Module/Main files/C#/GUI/Confirm/View.cs +++ b/Harden-Windows-Security Module/Main files/C#/GUI/Confirm/View.cs @@ -267,7 +267,7 @@ await System.Threading.Tasks.Task.Run(() => }); // if user selected a category for compliance checking - if (SelectedCategory is not null && !string.IsNullOrEmpty(SelectedCategory)) + if (!string.IsNullOrEmpty(SelectedCategory)) { // Perform the compliance check using the selected compliance category InvokeConfirmation.Invoke([SelectedCategory]);