1 bool EnableDebugPrivileges() 2 { 3 HANDLE hToken = NULL; 4 5 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &hToken) || hToken == NULL) 6 return false; 7 8 LUID luid; 9 if (!LookupPrivilegeValueA(NULL, "SeDebugPrivilege", &luid)) 10 { 11 CloseHandle(hToken); 12 return false; 13 } 14 15 TOKEN_PRIVILEGES tp; 16 tp.PrivilegeCount = 1; 17 tp.Privileges[0].Luid = luid; 18 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 19 20 TOKEN_PRIVILEGES prvTp; 21 DWORD ReturnLenth; 22 if (!AdjustTokenPrivileges(hToken, false, &tp, sizeof(TOKEN_PRIVILEGES), &prvTp, &ReturnLenth)) 23 { 24 CloseHandle(hToken); 25 return false; 26 } 27 28 CloseHandle(hToken); 29 30 return true; 31 }
时间: 2024-10-13 20:12:39