HyperDbg Debugger
Loading...
Searching...
No Matches
windows-privilege.c File Reference

Implementation of Windows only APIs for adjusting privileges. More...

#include "pch.h"

Functions

BOOLEAN WindowsSetDebugPrivilege ()
 Adjust kernel debug privilege.

Variables

BOOLEAN g_PrivilegesAlreadyAdjusted = FALSE
 Is privileges already adjusted.

Detailed Description

Implementation of Windows only APIs for adjusting privileges.

Author
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
Version
0.19
Date
2026-05-28

Function Documentation

◆ WindowsSetDebugPrivilege()

BOOLEAN WindowsSetDebugPrivilege ( )

Adjust kernel debug privilege.

Returns
BOOLEAN return TRUE if it was successful or FALSE if there
26{
27#ifdef _WIN32 // Windows
28 BOOL Status;
29 HANDLE Token;
30
31 //
32 // Check if we already adjusted the privilege
33 //
35 {
36 return TRUE;
37 }
38
39 //
40 // Enable Debug privilege
41 //
42 Status = OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &Token);
43 if (!Status)
44 {
45 ShowMessages("err, OpenProcessToken failed (%x)\n", GetLastError());
46 return FALSE;
47 }
48
49 Status = SetPrivilege(Token, SE_DEBUG_NAME, TRUE);
50 if (!Status)
51 {
52 CloseHandle(Token);
53 return FALSE;
54 }
55
56 //
57 // Indicate that the privilege is already adjusted
58 //
60
61 CloseHandle(Token);
62 return TRUE;
63
64#elif defined(__linux__) // Linux
65 return TRUE; // No need to adjust privileges on Linux
66#endif
67}
int BOOL
Definition BasicTypes.h:25
#define TRUE
Definition BasicTypes.h:114
#define FALSE
Definition BasicTypes.h:113
BOOL SetPrivilege(HANDLE Token, LPCTSTR Privilege, BOOL EnablePrivilege)
SetPrivilege enables/disables process token privilege.
Definition common.cpp:643
BOOLEAN g_PrivilegesAlreadyAdjusted
Is privileges already adjusted.
Definition windows-privilege.c:17

Variable Documentation

◆ g_PrivilegesAlreadyAdjusted

BOOLEAN g_PrivilegesAlreadyAdjusted = FALSE

Is privileges already adjusted.