免责声明:内容仅供学习参考,请合法利用知识,禁止进行违法犯罪活动!
内容参考于:易道云信息技术研究院
上一个内容:56.游戏辅助模块检测功能代码搭建
以 56.游戏辅助模块检测功能代码搭建 它的代码为基础进行修改
效果图:
IDD_PAGE_1的修改
两个文本框的属性设置:
列表添加点击事件:
CWndINC.h文件的内容:
#pragma once
// CWindProcess 对话框
class CWindProcess : public CDialogEx
{
DECLARE_DYNAMIC(CWindProcess)
public:
CWindProcess(CWnd* pParent = nullptr); // 标准构造函数
virtual ~CWindProcess();
// 对话框数据
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_PROCESS_LST };
#endif
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
DECLARE_MESSAGE_MAP()
public:
CListCtrl ProcessLst;
BOOL IsFirst;
public:
virtual BOOL OnInitDialog();
void RefreshProcess();
afx_msg void OnNMDblclkList1(NMHDR* pNMHDR, LRESULT* pResult);
void Init(LPVOID lPtr, BOOL _First = TRUE);
};
CWindProcess.h文件的内容:
#pragma once
// CWindProcess 对话框
class CWindProcess : public CDialogEx
{
DECLARE_DYNAMIC(CWindProcess)
public:
CWindProcess(CWnd* pParent = nullptr); // 标准构造函数
virtual ~CWindProcess();
// 对话框数据
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_PROCESS_LST };
#endif
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
DECLARE_MESSAGE_MAP()
public:
CListCtrl ProcessLst;
BOOL IsFirst;
public:
virtual BOOL OnInitDialog();
void RefreshProcess();
afx_msg void OnNMDblclkList1(NMHDR* pNMHDR, LRESULT* pResult);
void Init(LPVOID lPtr, BOOL _First = TRUE);
};
CWndINC.cpp文件的修改:
// 打开进程按钮的点击事件
void CWndINC::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
wndProcess.Init(this);
wndProcess.DoModal();
}
// 打开感染进程按钮的点击事件
void CWndINC::OnBnClickedButton2()
{
// TODO: 在此添加控件通知处理程序代码
wndProcess.Init(this, FALSE);
wndProcess.DoModal();
}
// 设置文本框内容的函数
void CWndINC::SetProcess(unsigned Pid, CString& wExe, BOOL bFirst)
{
if (bFirst)
UExe = wExe;
else
UExeRoot = wExe;
UpdateData(FALSE);
}
CWindProcess.cpp文件内容:
// CWindProcess.cpp: 实现文件
//
#include "pch.h"
#include "GAMEHACKER2.h"
#include "CWindProcess.h"
#include "afxdialogex.h"
#include <TlHelp32.h>
#include "CWndINC.h"
CWndINC* wndINC;
// CWindProcess 对话框
IMPLEMENT_DYNAMIC(CWindProcess, CDialogEx)
CWindProcess::CWindProcess(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_PROCESS_LST, pParent)
{
}
CWindProcess::~CWindProcess()
{
}
void CWindProcess::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST1, ProcessLst);
}
BOOL CWindProcess::OnInitDialog()
{
CDialogEx::OnInitDialog();
LONG_PTR lStyle;
// 得到窗口的样式,GWL_STYLE在GetWindowLongPtr说明中有
lStyle = GetWindowLongPtr(ProcessLst.m_hWnd, GWL_STYLE);
lStyle |= LVS_REPORT;
SetWindowLongPtr(ProcessLst.m_hWnd, GWL_STYLE, lStyle);
DWORD dStyle = ProcessLst.GetExtendedStyle();
dStyle |= LVS_EX_FULLROWSELECT;
dStyle |= LVS_EX_GRIDLINES;
ProcessLst.SetExtendedStyle(dStyle);
ProcessLst.InsertColumn(0, L"名称", 0, 200);
ProcessLst.InsertColumn(1, L"可执行文件", 0, 400);
RefreshProcess();
return 0;
}
void CWindProcess::RefreshProcess()
{
ProcessLst.DeleteAllItems();
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnap == INVALID_HANDLE_VALUE) {
AfxMessageBox(L"获取进程列表失败!检查是否具有管理员权限!");
return;
}
PROCESSENTRY32 pe{sizeof(pe)};
BOOL BMORE = Process32First(hSnap, &pe);
while (BMORE) {
CString txt;
txt.Format(L"%d", pe.th32ParentProcessID);
ProcessLst.InsertItem(0, txt);
ProcessLst.SetItemText(0, 1, pe.szExeFile);
BMORE = Process32Next(hSnap, &pe);
}
CloseHandle(hSnap);
}
BEGIN_MESSAGE_MAP(CWindProcess, CDialogEx)
ON_NOTIFY(NM_DBLCLK, IDC_LIST1, &CWindProcess::OnNMDblclkList1)
END_MESSAGE_MAP()
// CWindProcess 消息处理程序
void CWindProcess::OnNMDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
{
LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
// TODO: 在此添加控件通知处理程序代码
*pResult = 0;
NM_LISTVIEW* View = (NM_LISTVIEW*)pNMHDR;
if (View->iItem != -1) {
CString wPid = ProcessLst.GetItemText(View->iItem, 0);
CString wExe = ProcessLst.GetItemText(View->iItem, 1);
// CString 转 DWORD
DWORD dPid = wcstoul(wPid.GetBuffer(), 0, 10);
wndINC->SetProcess(dPid, wExe, IsFirst);
}
// 关闭窗口
OnCancel();
}
void CWindProcess::Init(LPVOID lPtr, BOOL _First)
{
wndINC = (CWndINC*)lPtr;
IsFirst = _First;
}