📄 processform.cpp
字号:
// ProcessForm.cpp : implementation file
//
#include "stdafx.h"
#include "GUI.h"
#include "ProcessForm.h"
#include "AddDlg.h"
#include "CommonFunc.h"
// ProcessForm
IMPLEMENT_DYNCREATE(ProcessForm, CFormView)
ProcessForm::ProcessForm()
: CFormView(ProcessForm::IDD)
{
}
ProcessForm::~ProcessForm()
{
}
void ProcessForm::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST_PROCESS, mListProcess);
}
BEGIN_MESSAGE_MAP(ProcessForm, CFormView)
ON_NOTIFY(NM_RCLICK, IDC_LIST_PROCESS, OnNMRclickListProcess)
ON_COMMAND(ID_MENU_ADD, OnMenuAdd)
ON_COMMAND(ID_MENU_DELEATE, OnMenuDeleate)
// ON_COMMAND(ID_MENU_CANCEL, OnMenuCancel)
ON_COMMAND(ID_MENU_DELEATE_ALL, OnMenuDeleateAll)
// ON_COMMAND(ID_MENU_QUERY, OnMenuQuery)
ON_COMMAND(ID_MENU_QUERY, OnMenuQuery)
END_MESSAGE_MAP()
// ProcessForm diagnostics
#ifdef _DEBUG
void ProcessForm::AssertValid() const
{
CFormView::AssertValid();
}
void ProcessForm::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
// ProcessForm message handlers
void ProcessForm::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
mListProcess.InsertColumn(0,_T("Process name"),LVCFMT_LEFT,120,0);
mListProcess.InsertColumn(1,_T("User Filter"),LVCFMT_LEFT,120,1);
mListProcess.InsertColumn(2,_T("Process Filter"),LVCFMT_LEFT,120,2);
DWORD dwExStyle_f=mListProcess.GetExtendedStyle();
dwExStyle_f= (LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
mListProcess.SetExtendedStyle(dwExStyle_f);
}
void ProcessForm::OnNMRclickListProcess(NMHDR *pNMHDR, LRESULT *pResult)
{
CPoint point;
GetCursorPos( &point);
CMenu menu;
menu.LoadMenu(IDR_MENU_LIST);
POSITION pos = mListProcess.GetFirstSelectedItemPosition();
if(pos == NULL)
menu.EnableMenuItem(ID_MENU_DELEATE,TRUE);
if(mListProcess.GetItemCount() == 0)
menu.EnableMenuItem(ID_MENU_DELEATE_ALL,TRUE);
menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, point.x, point.y, this);
*pResult = 0;
}
void ProcessForm::OnMenuAdd()
{
AddDlg dlg(TYPE_PROCESS);
if( dlg.DoModal() != IDOK )
return;
// Prepare string
CString& strProcessName = dlg.mReturnData.Name;
CString& strAccessUserName = dlg.mReturnData.User;
CString& strAccessProcessName = dlg.mReturnData.Process;
CString strPackage;
strPackage+=strProcessName;
strPackage+=L';';
strPackage+=strAccessUserName;
strPackage+=L';';
strPackage+=strAccessProcessName;
strPackage+=L';';
// Sending
PWCHAR str = (PWCHAR)strPackage.GetString();
DWORD size = strPackage.GetLength();
WCHAR ret_data;
DWORD BytesReturned;
size+=1; // Adding size of '\0' symbol
size*=2; // Take into consideration UNICODE size of character
BOOL res = mDrvWork.Exchange(
_T("\\\\.\\HideDriver"),
IOCTL_ADD_PROCESS_NAME,
str, // Input string
size, // Size of input string
&ret_data, // Output string
sizeof(ret_data), // Size of buffer for output string
&BytesReturned);
if(!res)
AfxMessageBox(_T("Send error"));
else
{
if(BytesReturned!=2 || (UINT)ret_data != HOOK_SUCCESS)
{
AfxMessageBox(_T("Driver return error"));
return;
}
int nIndex = mListProcess.GetItemCount();
mListProcess.InsertItem(nIndex,strProcessName);
mListProcess.SetItemText(nIndex,1,strAccessUserName);
mListProcess.SetItemText(nIndex,2,strAccessProcessName);
}
}
void ProcessForm::OnMenuDeleate()
{
POSITION pos = mListProcess.GetFirstSelectedItemPosition();
if (pos == NULL)
return;
while (pos)
{
int nItem = mListProcess.GetNextSelectedItem(pos);
CString ProcessName = mListProcess.GetItemText(nItem,0);
PWCHAR str = (PWCHAR)ProcessName.GetString();
WCHAR ret_data;
DWORD BytesReturned;
DWORD size = ProcessName.GetLength();
size+=1; // Adding size of '\0' symbol
size*=2; // Take into consideration UNICODE size of character
BOOL res = mDrvWork.Exchange(
_T("\\\\.\\HideDriver"),
IOCTL_DEL_PROCESS_NAME,
str, // Input string
size, // Size of input string
&ret_data, // Output string
sizeof(ret_data), // Size of buffer for output string
&BytesReturned);
if(!res)
AfxMessageBox(_T("Send error"));
else
{
if(BytesReturned!=2 || (UINT)ret_data != HOOK_SUCCESS)
{
AfxMessageBox(_T("Driver return error"));
return;
}
LVFINDINFO info;
int nIndex;
info.flags = LVFI_PARTIAL|LVFI_STRING;
info.psz = ProcessName;
// Delete all of the items that begin with the string ProcessName.
while ((nIndex=mListProcess.FindItem(&info)) != -1)
{
mListProcess.DeleteItem(nIndex);
}
}
}
}
void ProcessForm::OnMenuDeleateAll()
{
WCHAR Data;
WCHAR ret_data;
DWORD BytesReturned;
BOOL res = mDrvWork.Exchange(
_T("\\\\.\\HideDriver"),
IOCTL_CLEAR_PROCESS_NAME,
&Data, // Input string
sizeof(Data), // Size of input string
&ret_data, // Output string
sizeof(ret_data), // Size of buffer for output string
&BytesReturned);
if(!res)
AfxMessageBox(_T("Send error"));
else
{
mListProcess.DeleteAllItems();
}
}
/////////////////////////////////////////////////////////////////////////////////////////
void ProcessForm::OnMenuQuery()
{
WCHAR Data;
DWORD buf_size = 1024;
WCHAR* ret_data = new WCHAR[buf_size];
DWORD BytesReturned;
BOOL res = mDrvWork.Exchange(
_T("\\\\.\\HideDriver"),
IOCTL_QUERY_PROCESS_NAME,
&Data, // Input string
sizeof(Data), // Size of input string
ret_data, // Output string
buf_size, // Size of buffer for output string
&BytesReturned);
if(!res)
AfxMessageBox(_T("Send error"));
else
{
if(BytesReturned==0 ||
(BytesReturned==2 && (UINT)ret_data[0] != HOOK_SUCCESS))
{
AfxMessageBox(_T("Driver return error"));
delete [] ret_data;
return;
}
mListProcess.DeleteAllItems();
CString str;
str.Format(_T("%ws"),ret_data);
int LeftBorder=0;
int RightBorder=0;
while(true)
{
RightBorder = str.Find(_T("\n"),LeftBorder);
if(RightBorder == -1)
break;
CString buf = str.Mid(LeftBorder,RightBorder - LeftBorder);
LeftBorder = RightBorder + 1;
CString ProcessName;
CString AccUserName;
CString AccProcessName;
PackadgeParser(buf,ProcessName,AccUserName,AccProcessName);
int nIndex = mListProcess.GetItemCount();
mListProcess.InsertItem(nIndex,ProcessName);
mListProcess.SetItemText(nIndex,1,AccUserName);
mListProcess.SetItemText(nIndex,2,AccProcessName);
}
}
delete [] ret_data;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -