📄 fileform.cpp
字号:
// FileForm.cpp : implementation file
//
#include "stdafx.h"
#include "GUI.h"
#include "FileForm.h"
#include "AddDlg.h"
#include "CommonFunc.h"
// FileForm
IMPLEMENT_DYNCREATE(FileForm, CFormView)
FileForm::FileForm()
: CFormView(FileForm::IDD)
{
}
FileForm::~FileForm()
{
}
void FileForm::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST_FILE, mListFile);
}
BEGIN_MESSAGE_MAP(FileForm, CFormView)
ON_NOTIFY(NM_RCLICK, IDC_LIST_FILE, OnNMRclickListFile)
ON_COMMAND(ID_MENU_DELEATE, OnMenuDeleate)
ON_COMMAND(ID_MENU_ADD, OnMenuAdd)
ON_COMMAND(ID_MENU_QUERY, OnMenuQuery)
ON_COMMAND(ID_MENU_DELEATE_ALL, OnMenuDeleateAll)
END_MESSAGE_MAP()
// FileForm diagnostics
#ifdef _DEBUG
void FileForm::AssertValid() const
{
CFormView::AssertValid();
}
void FileForm::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
// FileForm message handlers
void FileForm::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
mListFile.InsertColumn(0,_T("File path"),LVCFMT_LEFT,150,0);
mListFile.InsertColumn(1,_T("User Filter"),LVCFMT_LEFT,100,1);
mListFile.InsertColumn(2,_T("Process Filter"),LVCFMT_LEFT,100,2);
DWORD dwExStyle_f=mListFile.GetExtendedStyle();
dwExStyle_f= (LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
mListFile.SetExtendedStyle(dwExStyle_f);
}
void FileForm::OnNMRclickListFile(NMHDR *pNMHDR, LRESULT *pResult)
{
CPoint point;
GetCursorPos( &point);
CMenu menu;
menu.LoadMenu(IDR_MENU_LIST);
POSITION pos = mListFile.GetFirstSelectedItemPosition();
if(pos == NULL)
menu.EnableMenuItem(ID_MENU_DELEATE,TRUE);
if(mListFile.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 FileForm::OnMenuAdd()
{
AddDlg dlg(TYPE_FILE);
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_FILE_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\nFile name isn't correct"));
return;
}
int nIndex = mListFile.GetItemCount();
mListFile.InsertItem(nIndex,strProcessName);
mListFile.SetItemText(nIndex,1,strAccessUserName);
mListFile.SetItemText(nIndex,2,strAccessProcessName);
}
}
void FileForm::OnMenuDeleate()
{
POSITION pos = mListFile.GetFirstSelectedItemPosition();
if (pos == NULL)
return;
while (pos)
{
int nItem = mListFile.GetNextSelectedItem(pos);
CString FileName = mListFile.GetItemText(nItem,0);
PWCHAR str = (PWCHAR)FileName.GetString();
WCHAR ret_data;
DWORD BytesReturned;
DWORD size = FileName.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_FILE_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\nFile name isn't correct"));
return;
}
LVFINDINFO info;
int nIndex;
info.flags = LVFI_PARTIAL|LVFI_STRING;
info.psz = FileName;
// Delete all of the items that begin with the string ProcessName.
while ((nIndex=mListFile.FindItem(&info)) != -1)
{
mListFile.DeleteItem(nIndex);
}
}
}
}
void FileForm::OnMenuDeleateAll()
{
WCHAR Data;
WCHAR ret_data;
DWORD BytesReturned;
BOOL res = mDrvWork.Exchange(
_T("\\\\.\\HideDriver"),
IOCTL_CLEAR_FILE_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
{
if(BytesReturned!=2 || (UINT)ret_data != HOOK_SUCCESS)
{
AfxMessageBox(_T("Driver return error"));
return;
}
mListFile.DeleteAllItems();
}
}
void FileForm::OnMenuQuery()
{
WCHAR Data;
DWORD buf_size = 1024;
WCHAR* ret_data = new WCHAR[buf_size];
DWORD BytesReturned;
BOOL res = mDrvWork.Exchange(
_T("\\\\.\\HideDriver"),
IOCTL_QUERY_FILE_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;
}
mListFile.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 FileName;
CString AccUserName;
CString AccProcessName;
PackadgeParser(buf,FileName,AccUserName,AccProcessName);
int nIndex = mListFile.GetItemCount();
mListFile.InsertItem(nIndex,FileName);
mListFile.SetItemText(nIndex,1,AccUserName);
mListFile.SetItemText(nIndex,2,AccProcessName);
}
}
delete [] ret_data;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -