Breaking Change! (Quality fix)

This commit is contained in:
CreepyCrafter24 2019-11-10 13:04:27 +01:00
parent c8db67a695
commit 3465a10361
3 changed files with 80 additions and 120 deletions

View File

@ -9,7 +9,6 @@ using System.Drawing;
namespace CC_Functions.W32 namespace CC_Functions.W32
{ {
public sealed class MouseHook : IDisposable public sealed class MouseHook : IDisposable
{ {
public void Dispose() public void Dispose()

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using static CC_Functions.W32.Privileges;
namespace CC_Functions.W32 namespace CC_Functions.W32
{ {
@ -106,7 +107,7 @@ namespace CC_Functions.W32
} }
else else
{ {
Privileges.EnablePrivilege(SecurityEntity.SE_SHUTDOWN_NAME); EnablePrivilege(SecurityEntity.SeShutdownPrivilege);
ExitWindowsEx((ExitWindows)((uint)mode | (uint)mod), reason); ExitWindowsEx((ExitWindows)((uint)mode | (uint)mod), reason);
} }
} }

View File

@ -9,13 +9,13 @@ using System.Threading.Tasks;
namespace CC_Functions.W32 namespace CC_Functions.W32
{ {
public class Privileges public static class Privileges
{ {
public static void EnablePrivilege(SecurityEntity securityEntity) public static void EnablePrivilege(SecurityEntity securityEntity)
{ {
if (!Enum.IsDefined(typeof(SecurityEntity), securityEntity)) if (!Enum.IsDefined(typeof(SecurityEntity), securityEntity))
throw new InvalidEnumArgumentException("securityEntity", (int)securityEntity, typeof(SecurityEntity)); throw new InvalidEnumArgumentException("securityEntity", (int)securityEntity, typeof(SecurityEntity));
var securityEntityValue = GetSecurityEntityValue(securityEntity); var securityEntityValue = securityEntity.ToString();
try try
{ {
var locallyUniqueIdentifier = new NativeMethods.LUID(); var locallyUniqueIdentifier = new NativeMethods.LUID();
@ -67,126 +67,86 @@ namespace CC_Functions.W32
} }
} }
/// <summary>
/// Gets the security entity value.
/// </summary>
/// <param name="securityEntity">The security entity.</param>
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 public enum SecurityEntity
{ {
SE_CREATE_TOKEN_NAME, SeAssignPrimaryTokenPrivilege,
SE_ASSIGNPRIMARYTOKEN_NAME, SeAuditPrivilege,
SE_LOCK_MEMORY_NAME, SeBackupPrivilege,
SE_INCREASE_QUOTA_NAME, SeChangeNotifyPrivilege,
SE_UNSOLICITED_INPUT_NAME, SeCreateGlobalPrivilege,
SE_MACHINE_ACCOUNT_NAME, SeCreatePagefilePrivilege,
SE_TCB_NAME, SeCreatePermanentPrivilege,
SE_SECURITY_NAME, SeCreateSymbolicLinkPrivilege,
SE_TAKE_OWNERSHIP_NAME, SeCreateTokenPrivilege,
SE_LOAD_DRIVER_NAME, SeDebugPrivilege,
SE_SYSTEM_PROFILE_NAME, SeDelegateSessionUserImpersonatePrivilege,
SE_SYSTEMTIME_NAME, SeEnableDelegationPrivilege,
SE_PROF_SINGLE_PROCESS_NAME, SeImpersonatePrivilege,
SE_INC_BASE_PRIORITY_NAME, SeIncreaseBasePriorityPrivilege,
SE_CREATE_PAGEFILE_NAME, SeIncreaseWorkingSetPrivilege,
SE_CREATE_PERMANENT_NAME, SeIncreaseQuotaPrivilege,
SE_BACKUP_NAME, SeLoadDriverPrivilege,
SE_RESTORE_NAME, SeLockMemoryPrivilege,
SE_SHUTDOWN_NAME, SeMachineAccountPrivilege,
SE_DEBUG_NAME, SeManageVolumePrivilege,
SE_AUDIT_NAME, SeProfileSingleProcessPrivilege,
SE_SYSTEM_ENVIRONMENT_NAME, SeRelabelPrivilege,
SE_CHANGE_NOTIFY_NAME, SeRemoteShutdownPrivilege,
SE_REMOTE_SHUTDOWN_NAME, SeRestorePrivilege,
SE_UNDOCK_NAME, SeSecurityPrivilege,
SE_SYNC_AGENT_NAME, SeShutdownPrivilege,
SE_ENABLE_DELEGATION_NAME, SeSyncAgentPrivilege,
SE_MANAGE_VOLUME_NAME, SeSystemEnvironmentPrivilege,
SE_IMPERSONATE_NAME, SeSystemProfilePrivilege,
SE_CREATE_GLOBAL_NAME, SeSystemtimePrivilege,
SE_CREATE_SYMBOLIC_LINK_NAME, SeTakeOwnershipPrivilege,
SE_INC_WORKING_SET_NAME, SeTcbPrivilege,
SE_RELABEL_NAME, SeTimeZonePrivilege,
SE_TIME_ZONE_NAME, SeTrustedCredManAccessPrivilege,
SE_TRUSTED_CREDMAN_ACCESS_NAME 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 internal static class NativeMethods
{ {
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)] [DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]