MCPcopy Create free account
hub / github.com/ajkhoury/ReClassEx / SetPrivilege

Function SetPrivilege

ReClass/Utils.cpp:175–208  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

173
174
175bool SetPrivilege( HANDLE hToken, LPCTSTR lpPrivilege, bool bEnablePrivilege )
176{
177 NTSTATUS Status;
178 LUID privLuid;
179 TOKEN_PRIVILEGES tokenPriv;
180 TOKEN_PRIVILEGES tokenPrivPrevious;
181 DWORD cbPrevious;
182
183 if (!LookupPrivilegeValue( NULL, lpPrivilege, &privLuid ))
184 return false;
185
186 ZeroMemory( &tokenPriv, sizeof( tokenPriv ) );
187 tokenPriv.PrivilegeCount = 1;
188 tokenPriv.Privileges[0].Luid = privLuid;
189 tokenPriv.Privileges[0].Attributes = 0;
190
191 cbPrevious = sizeof( TOKEN_PRIVILEGES );
192 Status = ntdll::NtAdjustPrivilegesToken( hToken, FALSE, &tokenPriv, sizeof( TOKEN_PRIVILEGES ), &tokenPrivPrevious, &cbPrevious );
193 if (!NT_SUCCESS( Status ))
194 return false;
195
196 tokenPrivPrevious.PrivilegeCount = 1;
197 tokenPrivPrevious.Privileges[0].Luid = privLuid;
198 if (bEnablePrivilege)
199 tokenPrivPrevious.Privileges[0].Attributes |= (SE_PRIVILEGE_ENABLED);
200 else
201 tokenPrivPrevious.Privileges[0].Attributes ^= (SE_PRIVILEGE_ENABLED & tokenPrivPrevious.Privileges[0].Attributes);
202
203 Status = ntdll::NtAdjustPrivilegesToken( hToken, FALSE, &tokenPrivPrevious, cbPrevious, NULL, NULL );
204 if (!NT_SUCCESS( Status ))
205 return false;
206
207 return true;
208}
209
210bool SetDebugPrivilege( bool bEnable )
211{

Callers 1

SetDebugPrivilegeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected