From c12f2495b2e1d6168a181aa5ea2793f0f927a502 Mon Sep 17 00:00:00 2001 From: dahall Date: Thu, 7 Oct 2021 10:36:36 -0600 Subject: [PATCH] BREAKING CHANGE: Removed `ProcessIntegrityLevel` and replaced use with AdvApi32.MANDATORY_LEVEL. --- System/Extensions/ProcessExtension.cs | 41 +++-------------------------------- 1 file changed, 3 insertions(+), 38 deletions(-) diff --git a/System/Extensions/ProcessExtension.cs b/System/Extensions/ProcessExtension.cs index a389a63d..c5cdcc17 100644 --- a/System/Extensions/ProcessExtension.cs +++ b/System/Extensions/ProcessExtension.cs @@ -20,28 +20,6 @@ using static Vanara.PInvoke.Kernel32; namespace Vanara.Extensions { - /// Values which define a processes integrity level. - public enum ProcessIntegrityLevel - { - /// Untrusted. - Untrusted, - - /// Undefined. - Undefined, - - /// Low. - Low, - - /// Medium. - Medium, - - /// High. - High, - - /// System. - System - } - /// Extension methods for for privileges, status, elevation and relationships. public static partial class ProcessExtension { @@ -132,27 +110,14 @@ namespace Vanara.Extensions /// When any native Windows API call fails, the function throws a Win32Exception with the last error code. /// /// must be a valid . - public static ProcessIntegrityLevel GetIntegrityLevel(this Process p) + public static MANDATORY_LEVEL GetIntegrityLevel(this Process p) { if (p == null) throw new ArgumentNullException(nameof(p)); // Open the access token of the current process with TOKEN_QUERY. - var hObject = SafeHTOKEN.FromProcess(p, TokenAccess.TOKEN_QUERY | TokenAccess.TOKEN_DUPLICATE); - - // Marshal the TOKEN_MANDATORY_LABEL struct from native to .NET object. - var tokenIL = hObject.GetInfo(TOKEN_INFORMATION_CLASS.TokenIntegrityLevel); - - // Integrity Level SIDs are in the form of S-1-16-0xXXXX. (e.g. S-1-16-0x1000 stands for low integrity level SID). There is one and only one subauthority. - return (GetSidSubAuthority(tokenIL.Label.Sid, 0)) switch - { - 0 => ProcessIntegrityLevel.Untrusted, - 0x1000 => ProcessIntegrityLevel.Low, - var iVal when iVal >= 0x2000 && iVal < 0x3000 => ProcessIntegrityLevel.Medium, - var iVal when iVal >= 0x4000 => ProcessIntegrityLevel.System, - var iVal when iVal >= 0x3000 => ProcessIntegrityLevel.High, - _ => ProcessIntegrityLevel.Undefined, - }; + using var hObject = SafeHTOKEN.FromProcess(p, TokenAccess.TOKEN_QUERY | TokenAccess.TOKEN_DUPLICATE); + return ((HTOKEN)hObject).GetIntegrityLevel(); } /// Retrieves the fully qualified path of the executable file of the process.