MCPcopy Create free account
hub / github.com/BeneficialCode/WinArk / EnablePrivilege

Function EnablePrivilege

WinSysCore/TraceManager.cpp:12–27  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10#pragma comment(lib,"tdh")
11
12static bool EnablePrivilege(PCWSTR privilege) {
13 HANDLE hToken;
14 if (!::OpenProcessToken(::GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
15 return false;
16
17 TOKEN_PRIVILEGES tp;
18 tp.PrivilegeCount = 1;
19 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
20 if (!::LookupPrivilegeValue(nullptr, privilege, &tp.Privileges[0].Luid))
21 return false;
22
23 BOOL success = ::AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(tp), nullptr, nullptr);
24 ::CloseHandle(hToken);
25
26 return success && ::GetLastError() == ERROR_SUCCESS;
27}
28
29TraceManager::TraceManager() {
30 EnablePrivilege(SE_DEBUG_NAME);

Callers 5

OnKeyPermissionsMethod · 0.85
OnImportMethod · 0.85
OnExportMethod · 0.85
OnRunAsSystemMethod · 0.85
TraceManagerMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected