// HandleMon.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "HandleMon.h"
#include "helpdlg.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
BOOL EnablePrivilege (HANDLE hprocess, LPSTR privilege, BOOL flag)
{
HANDLE hToken = NULL;
LUID DebugValue;
TOKEN_PRIVILEGES tkp;
if (!OpenProcessToken (hprocess,
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
&hToken))
goto errexit;
if (!LookupPrivilegeValue((LPSTR) NULL,
privilege,
&DebugValue))
goto errexit;
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Luid = DebugValue;
if (flag)
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED |
SE_PRIVILEGE_ENABLED_BY_DEFAULT |
SE_PRIVILEGE_USED_FOR_ACCESS;
else
tkp.Privileges[0].Attributes = NULL;
AdjustTokenPrivileges(hToken,
FALSE,
&tkp,
sizeof(TOKEN_PRIVILEGES),
(PTOKEN_PRIVILEGES) NULL,
(PDWORD) NULL);
if (GetLastError() != ERROR_SUCCESS)
goto errexit;
CloseHandle (hToken);
return TRUE;
errexit:
CloseHandle (hToken);
return FALSE;
}
/////////////////////////////////////////////////////////////////////////////
// CHandleMonApp
BEGIN_MESSAGE_MAP(CHandleMonApp, CWinApp)
//{{AFX_MSG_MAP(CHandleMonApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHandleMonApp construction
CHandleMonApp::CHandleMonApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CHandleMonApp object
CMainFrame *frame;
CHandleMonApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CHandleMonApp initialization
BOOL CHandleMonApp::InitInstance()
{
Enable3dControls(); // Call this when using MFC in a shared DLL
if (!EnablePrivilege (GetCurrentProcess(), SE_DEBUG_NAME, TRUE))
AfxMessageBox ("Failed to get Privilege SE_DEBUG_NAME...");
frame = new CMainFrame;
m_pMainWnd = frame;
frame->Create (NULL, "PittBull's Handle Monitor");
SetClassLong (frame->GetSafeHwnd(), GCL_HICON, (LONG)LoadIcon (IDI_ICON1));
frame->ShowWindow (SW_SHOW);
frame->UpdateWindow();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
/////////////////////////////////////////////////////////////////////////////
// CHandleMonApp commands