Skip to content

Commit

Permalink
Enabled debug privilege for "NPFInstall.exe -check_dll".
Browse files Browse the repository at this point in the history
  • Loading branch information
hsluoyz committed Dec 3, 2016
1 parent 659c02d commit 2b1873b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packetWin7/NPFInstall/NPFInstall/ProcessUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@ using namespace std;
#include "debug.h"


BOOL enableDebugPrivilege(BOOL bEnable)
{
HANDLE hToken = nullptr;
LUID luid;

if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken)) return FALSE;
if (!LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &luid)) return FALSE;

TOKEN_PRIVILEGES tokenPriv;
tokenPriv.PrivilegeCount = 1;
tokenPriv.Privileges[0].Luid = luid;
tokenPriv.Privileges[0].Attributes = bEnable ? SE_PRIVILEGE_ENABLED : 0;

if (!AdjustTokenPrivileges(hToken, FALSE, &tokenPriv, sizeof(TOKEN_PRIVILEGES), NULL, NULL)) return FALSE;

return TRUE;
}

BOOL checkModulePathName(tstring strModulePathName)
{
size_t iStart = strModulePathName.find_last_of(_T('\\'));
Expand Down Expand Up @@ -108,6 +126,8 @@ vector<tstring> enumProcesses()
{
vector<tstring> strArrProcessNames;

enableDebugPrivilege(TRUE);

HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (hSnapshot)
{
Expand Down

0 comments on commit 2b1873b

Please sign in to comment.