From 3465a10361d5975d4dc6d4461a9fe40a8638148b Mon Sep 17 00:00:00 2001
From: CreepyCrafter24 <33260128+CreepyCrafter24@users.noreply.github.com>
Date: Sun, 10 Nov 2019 13:04:27 +0100
Subject: [PATCH] Breaking Change! (Quality fix)
---
W32/Hooks/MouseHook.cs | 1 -
W32/Power.cs | 3 +-
W32/Privileges.cs | 196 ++++++++++++++++-------------------------
3 files changed, 80 insertions(+), 120 deletions(-)
diff --git a/W32/Hooks/MouseHook.cs b/W32/Hooks/MouseHook.cs
index 3510bdd..2f76c5e 100644
--- a/W32/Hooks/MouseHook.cs
+++ b/W32/Hooks/MouseHook.cs
@@ -9,7 +9,6 @@ using System.Drawing;
namespace CC_Functions.W32
{
-
public sealed class MouseHook : IDisposable
{
public void Dispose()
diff --git a/W32/Power.cs b/W32/Power.cs
index 52fbaef..8ddca84 100644
--- a/W32/Power.cs
+++ b/W32/Power.cs
@@ -4,6 +4,7 @@ using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
+using static CC_Functions.W32.Privileges;
namespace CC_Functions.W32
{
@@ -106,7 +107,7 @@ namespace CC_Functions.W32
}
else
{
- Privileges.EnablePrivilege(SecurityEntity.SE_SHUTDOWN_NAME);
+ EnablePrivilege(SecurityEntity.SeShutdownPrivilege);
ExitWindowsEx((ExitWindows)((uint)mode | (uint)mod), reason);
}
}
diff --git a/W32/Privileges.cs b/W32/Privileges.cs
index e3f0dc0..8feb951 100644
--- a/W32/Privileges.cs
+++ b/W32/Privileges.cs
@@ -9,13 +9,13 @@ using System.Threading.Tasks;
namespace CC_Functions.W32
{
- public class Privileges
+ public static class Privileges
{
public static void EnablePrivilege(SecurityEntity securityEntity)
{
if (!Enum.IsDefined(typeof(SecurityEntity), securityEntity))
throw new InvalidEnumArgumentException("securityEntity", (int)securityEntity, typeof(SecurityEntity));
- var securityEntityValue = GetSecurityEntityValue(securityEntity);
+ var securityEntityValue = securityEntity.ToString();
try
{
var locallyUniqueIdentifier = new NativeMethods.LUID();
@@ -67,126 +67,86 @@ namespace CC_Functions.W32
}
}
- ///
- /// Gets the security entity value.
- ///
- /// The security entity.
- private static string GetSecurityEntityValue(SecurityEntity securityEntity)
- {
- switch (securityEntity)
- {
- case SecurityEntity.SE_ASSIGNPRIMARYTOKEN_NAME:
- return "SeAssignPrimaryTokenPrivilege";
- case SecurityEntity.SE_AUDIT_NAME:
- return "SeAuditPrivilege";
- case SecurityEntity.SE_BACKUP_NAME:
- return "SeBackupPrivilege";
- case SecurityEntity.SE_CHANGE_NOTIFY_NAME:
- return "SeChangeNotifyPrivilege";
- case SecurityEntity.SE_CREATE_GLOBAL_NAME:
- return "SeCreateGlobalPrivilege";
- case SecurityEntity.SE_CREATE_PAGEFILE_NAME:
- return "SeCreatePagefilePrivilege";
- case SecurityEntity.SE_CREATE_PERMANENT_NAME:
- return "SeCreatePermanentPrivilege";
- case SecurityEntity.SE_CREATE_SYMBOLIC_LINK_NAME:
- return "SeCreateSymbolicLinkPrivilege";
- case SecurityEntity.SE_CREATE_TOKEN_NAME:
- return "SeCreateTokenPrivilege";
- case SecurityEntity.SE_DEBUG_NAME:
- return "SeDebugPrivilege";
- case SecurityEntity.SE_ENABLE_DELEGATION_NAME:
- return "SeEnableDelegationPrivilege";
- case SecurityEntity.SE_IMPERSONATE_NAME:
- return "SeImpersonatePrivilege";
- case SecurityEntity.SE_INC_BASE_PRIORITY_NAME:
- return "SeIncreaseBasePriorityPrivilege";
- case SecurityEntity.SE_INCREASE_QUOTA_NAME:
- return "SeIncreaseQuotaPrivilege";
- case SecurityEntity.SE_INC_WORKING_SET_NAME:
- return "SeIncreaseWorkingSetPrivilege";
- case SecurityEntity.SE_LOAD_DRIVER_NAME:
- return "SeLoadDriverPrivilege";
- case SecurityEntity.SE_LOCK_MEMORY_NAME:
- return "SeLockMemoryPrivilege";
- case SecurityEntity.SE_MACHINE_ACCOUNT_NAME:
- return "SeMachineAccountPrivilege";
- case SecurityEntity.SE_MANAGE_VOLUME_NAME:
- return "SeManageVolumePrivilege";
- case SecurityEntity.SE_PROF_SINGLE_PROCESS_NAME:
- return "SeProfileSingleProcessPrivilege";
- case SecurityEntity.SE_RELABEL_NAME:
- return "SeRelabelPrivilege";
- case SecurityEntity.SE_REMOTE_SHUTDOWN_NAME:
- return "SeRemoteShutdownPrivilege";
- case SecurityEntity.SE_RESTORE_NAME:
- return "SeRestorePrivilege";
- case SecurityEntity.SE_SECURITY_NAME:
- return "SeSecurityPrivilege";
- case SecurityEntity.SE_SHUTDOWN_NAME:
- return "SeShutdownPrivilege";
- case SecurityEntity.SE_SYNC_AGENT_NAME:
- return "SeSyncAgentPrivilege";
- case SecurityEntity.SE_SYSTEM_ENVIRONMENT_NAME:
- return "SeSystemEnvironmentPrivilege";
- case SecurityEntity.SE_SYSTEM_PROFILE_NAME:
- return "SeSystemProfilePrivilege";
- case SecurityEntity.SE_SYSTEMTIME_NAME:
- return "SeSystemtimePrivilege";
- case SecurityEntity.SE_TAKE_OWNERSHIP_NAME:
- return "SeTakeOwnershipPrivilege";
- case SecurityEntity.SE_TCB_NAME:
- return "SeTcbPrivilege";
- case SecurityEntity.SE_TIME_ZONE_NAME:
- return "SeTimeZonePrivilege";
- case SecurityEntity.SE_TRUSTED_CREDMAN_ACCESS_NAME:
- return "SeTrustedCredManAccessPrivilege";
- case SecurityEntity.SE_UNDOCK_NAME:
- return "SeUndockPrivilege";
- default:
- throw new ArgumentOutOfRangeException(typeof(SecurityEntity).Name);
- }
- }
-
public enum SecurityEntity
{
- SE_CREATE_TOKEN_NAME,
- SE_ASSIGNPRIMARYTOKEN_NAME,
- SE_LOCK_MEMORY_NAME,
- SE_INCREASE_QUOTA_NAME,
- SE_UNSOLICITED_INPUT_NAME,
- SE_MACHINE_ACCOUNT_NAME,
- SE_TCB_NAME,
- SE_SECURITY_NAME,
- SE_TAKE_OWNERSHIP_NAME,
- SE_LOAD_DRIVER_NAME,
- SE_SYSTEM_PROFILE_NAME,
- SE_SYSTEMTIME_NAME,
- SE_PROF_SINGLE_PROCESS_NAME,
- SE_INC_BASE_PRIORITY_NAME,
- SE_CREATE_PAGEFILE_NAME,
- SE_CREATE_PERMANENT_NAME,
- SE_BACKUP_NAME,
- SE_RESTORE_NAME,
- SE_SHUTDOWN_NAME,
- SE_DEBUG_NAME,
- SE_AUDIT_NAME,
- SE_SYSTEM_ENVIRONMENT_NAME,
- SE_CHANGE_NOTIFY_NAME,
- SE_REMOTE_SHUTDOWN_NAME,
- SE_UNDOCK_NAME,
- SE_SYNC_AGENT_NAME,
- SE_ENABLE_DELEGATION_NAME,
- SE_MANAGE_VOLUME_NAME,
- SE_IMPERSONATE_NAME,
- SE_CREATE_GLOBAL_NAME,
- SE_CREATE_SYMBOLIC_LINK_NAME,
- SE_INC_WORKING_SET_NAME,
- SE_RELABEL_NAME,
- SE_TIME_ZONE_NAME,
- SE_TRUSTED_CREDMAN_ACCESS_NAME
+ SeAssignPrimaryTokenPrivilege,
+ SeAuditPrivilege,
+ SeBackupPrivilege,
+ SeChangeNotifyPrivilege,
+ SeCreateGlobalPrivilege,
+ SeCreatePagefilePrivilege,
+ SeCreatePermanentPrivilege,
+ SeCreateSymbolicLinkPrivilege,
+ SeCreateTokenPrivilege,
+ SeDebugPrivilege,
+ SeDelegateSessionUserImpersonatePrivilege,
+ SeEnableDelegationPrivilege,
+ SeImpersonatePrivilege,
+ SeIncreaseBasePriorityPrivilege,
+ SeIncreaseWorkingSetPrivilege,
+ SeIncreaseQuotaPrivilege,
+ SeLoadDriverPrivilege,
+ SeLockMemoryPrivilege,
+ SeMachineAccountPrivilege,
+ SeManageVolumePrivilege,
+ SeProfileSingleProcessPrivilege,
+ SeRelabelPrivilege,
+ SeRemoteShutdownPrivilege,
+ SeRestorePrivilege,
+ SeSecurityPrivilege,
+ SeShutdownPrivilege,
+ SeSyncAgentPrivilege,
+ SeSystemEnvironmentPrivilege,
+ SeSystemProfilePrivilege,
+ SeSystemtimePrivilege,
+ SeTakeOwnershipPrivilege,
+ SeTcbPrivilege,
+ SeTimeZonePrivilege,
+ SeTrustedCredManAccessPrivilege,
+ SeUndockPrivilege,
+ SeUnsolicitedInputPrivilege
}
+ public enum SecurityEntity2
+ {
+ SE_ASSIGNPRIMARYTOKEN_NAME_TEXT,
+ SE_AUDIT_NAME_TEXT,
+ SE_BACKUP_NAME_TEXT,
+ SE_CHANGE_NOTIFY_NAME_TEXT,
+ SE_CREATE_GLOBAL_NAME_TEXT,
+ SE_CREATE_PAGEFILE_NAME_TEXT,
+ SE_CREATE_PERMANENT_NAME_TEXT,
+ SE_CREATE_SYMBOLIC_LINK_NAME_TEXT,
+ SE_CREATE_TOKEN_NAME_TEXT,
+ SE_DEBUG_NAME_TEXT,
+ SE_DELEGATE_SESSION_USER_IMPERSONATE_NAME_TEXT,
+ SE_ENABLE_DELEGATION_NAME_TEXT,
+ SE_IMPERSONATE_NAME_TEXT,
+ SE_INC_BASE_PRIORITY_NAME_TEXT,
+ SE_INC_WORKING_SET_NAME_TEXT,
+ SE_INCREASE_QUOTA_NAME_TEXT,
+ SE_LOAD_DRIVER_NAME_TEXT,
+ SE_LOCK_MEMORY_NAME_TEXT,
+ SE_MACHINE_ACCOUNT_NAME_TEXT,
+ SE_MANAGE_VOLUME_NAME_TEXT,
+ SE_PROF_SINGLE_PROCESS_NAME_TEXT,
+ SE_RELABEL_NAME_TEXT,
+ SE_REMOTE_SHUTDOWN_NAME_TEXT,
+ SE_RESTORE_NAME_TEXT,
+ SE_SECURITY_NAME_TEXT,
+ SE_SHUTDOWN_NAME_TEXT,
+ SE_SYNC_AGENT_NAME_TEXT,
+ SE_SYSTEM_ENVIRONMENT_NAME_TEXT,
+ SE_SYSTEM_PROFILE_NAME_TEXT,
+ SE_SYSTEMTIME_NAME_TEXT,
+ SE_TAKE_OWNERSHIP_NAME_TEXT,
+ SE_TCB_NAME_TEXT,
+ SE_TIME_ZONE_NAME_TEXT,
+ SE_TRUSTED_CREDMAN_ACCESS_NAME_TEXT,
+ SE_UNDOCK_NAME_TEXT,
+ SE_UNSOLICITED_INPUT_NAME_TEXT
+ }
+ public static SecurityEntity EntityToEntity(SecurityEntity2 entity) => (SecurityEntity)entity;
internal static class NativeMethods
{
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]