游戏修改器

0804itask.h

#pragma once
#ifndef __AFXWIN_H__
	#error "在包含此文件之前包含“stdafx.h”以生成 PCH 文件"
#endif
#include "resource.h"		// 主符号
0804itask.cpp 
#include "stdafx.h"
#include "0804itask.h"
#include "0804itaskDlg.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#endif




// CMy0804itaskApp


BEGIN_MESSAGE_MAP(CMy0804itaskApp, CWinApp)
	ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()




// CMy0804itaskApp 构造


CMy0804itaskApp::CMy0804itaskApp()
{
	// 支持重新启动管理器
	m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART;


	// TODO: 在此处添加构造代码,
	// 将所有重要的初始化放置在 InitInstance 中
}




// 唯一的一个 CMy0804itaskApp 对象


CMy0804itaskApp theApp;




// CMy0804itaskApp 初始化


BOOL CMy0804itaskApp::InitInstance()
{
	// 如果一个运行在 Windows XP 上的应用程序清单指定要
	// 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
	//则需要 InitCommonControlsEx()。否则,将无法创建窗口。
	INITCOMMONCONTROLSEX InitCtrls;
	InitCtrls.dwSize = sizeof(InitCtrls);
	// 将它设置为包括所有要在应用程序中使用的
	// 公共控件类。
	InitCtrls.dwICC = ICC_WIN95_CLASSES;
	InitCommonControlsEx(&InitCtrls);


	CWinApp::InitInstance();




	AfxEnableControlContainer();


	// 创建 shell 管理器,以防对话框包含
	// 任何 shell 树视图控件或 shell 列表视图控件。
	CShellManager *pShellManager = new CShellManager;


	// 激活“Windows Native”视觉管理器,以便在 MFC 控件中启用主题
	CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));


	// 标准初始化
	// 如果未使用这些功能并希望减小
	// 最终可执行文件的大小,则应移除下列
	// 不需要的特定初始化例程
	// 更改用于存储设置的注册表项
	// TODO: 应适当修改该字符串,
	// 例如修改为公司或组织名
	SetRegistryKey(_T("应用程序向导生成的本地应用程序"));


	CMy0804itaskDlg dlg;
	m_pMainWnd = &dlg;
	INT_PTR nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{
		// TODO: 在此放置处理何时用
		//  “确定”来关闭对话框的代码
	}
	else if (nResponse == IDCANCEL)
	{
		// TODO: 在此放置处理何时用
		//  “取消”来关闭对话框的代码
	}
	else if (nResponse == -1)
	{
		TRACE(traceAppMsg, 0, "警告: 对话框创建失败,应用程序将意外终止。\n");
		TRACE(traceAppMsg, 0, "警告: 如果您在对话框上使用 MFC 控件,则无法 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。\n");
	}


	// 删除上面创建的 shell 管理器。
	if (pShellManager != NULL)
	{
		delete pShellManager;
	}


	// 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序,
	//  而不是启动应用程序的消息泵。
	return FALSE;
}
0804itaskDlg.h

#pragma once
#include "afxcmn.h"
#include <list>
enum Type{ONE_BYTE = 1,TWO_BYTE = 2,FOUR_BYTE = 4,EIGHT_BYTE = 8};

using namespace std;
// CMy0804itaskDlg 对话框
class CMy0804itaskDlg : public CDialogEx
{
// 构造
public:
	CMy0804itaskDlg(CWnd* pParent = NULL);	// 标准构造函数
// 对话框数据
	enum { IDD = IDD_MY0804ITASK_DIALOG };
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV 支持
// 实现
protected:
	HICON m_hIcon;
	// 生成的消息映射函数
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	afx_msg void OnBnClickedButton1();
	afx_msg void OnBnClickedButton2();
	afx_msg void OnBnClickedButton3();
	afx_msg void OnNMDblclkList1(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnBnClickedButton4();
	DECLARE_MESSAGE_MAP()
public:
	void ShowProcess();
	void ShowAddress();
	void FindFirst();
	void FindNext();
	void FindOnePage(DWORD dwBaseAddress);
	static DWORD WINAPI ThreadProc(LPVOID lpvoid);
public:
	struct Node
	{
		Node(DWORD dwBaseAddress,Type  dwType):m_dwBaseAddress(dwBaseAddress),m_dwType(dwType)
		{
		}
		DWORD m_dwBaseAddress;
		Type  m_dwType;
	};
public:
	CListCtrl m_lstCtrl;

	DWORD m_edtProcessID;
	DWORD m_edtSearchValue;

	HANDLE m_hProcess;
	list<Node *> m_lstNode;
	
	CListCtrl m_lstAddress;
	afx_msg void OnDestroy();
	ULONGLONG m_edtModifyValue;
	afx_msg void OnBnClickedButton5();
};

0804itaskDlg.cpp

#include "stdafx.h"
#include "0804itask.h"
#include "0804itaskDlg.h"
#include "afxdialogex.h"
#include <TlHelp32.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif




// 用于应用程序“关于”菜单项的 CAboutDlg 对话框


const DWORD ONE_GB = 1*1024*1024*1024;
const DWORD ONE_PAGE = 4*1024;


class CAboutDlg : public CDialogEx
{
public:
	CAboutDlg();


// 对话框数据
	enum { IDD = IDD_ABOUTBOX };


	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持


// 实现
protected:
	DECLARE_MESSAGE_MAP()
};


CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
{
}


void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()



// CMy0804itaskDlg 对话框


CMy0804itaskDlg::CMy0804itaskDlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(CMy0804itaskDlg::IDD, pParent)
	, m_edtProcessID(0)
	, m_edtSearchValue(0)
	, m_edtModifyValue(0)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}


void CMy0804itaskDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_LIST1, m_lstCtrl);
	DDX_Text(pDX, IDC_EDIT1, m_edtProcessID);
	DDX_Text(pDX, IDC_EDIT2, m_edtSearchValue);
	DDX_Control(pDX, IDC_LIST2, m_lstAddress);
	DDX_Text(pDX, IDC_EDIT3, m_edtModifyValue);
}


BEGIN_MESSAGE_MAP(CMy0804itaskDlg, CDialogEx)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, &CMy0804itaskDlg::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON2, &CMy0804itaskDlg::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON3, &CMy0804itaskDlg::OnBnClickedButton3)
	ON_NOTIFY(NM_DBLCLK, IDC_LIST1, &CMy0804itaskDlg::OnNMDblclkList1)
	ON_BN_CLICKED(IDC_BUTTON4, &CMy0804itaskDlg::OnBnClickedButton4)
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_BUTTON5, &CMy0804itaskDlg::OnBnClickedButton5)
END_MESSAGE_MAP()




// CMy0804itaskDlg 消息处理程序


BOOL CMy0804itaskDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();


	// 将“关于...”菜单项添加到系统菜单中。


	// IDM_ABOUTBOX 必须在系统命令范围内。
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);


	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		BOOL bNameValid;
		CString strAboutMenu;
		bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
		ASSERT(bNameValid);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}


	// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
	//  执行此操作
	SetIcon(m_hIcon, TRUE);			// 设置大图标
	SetIcon(m_hIcon, FALSE);		// 设置小图标


	// TODO: 在此添加额外的初始化代码
	//初始化listctrl
	CString str;
	int ntable[3] = {IDS_PNAME,IDS_PID,IDS_THREADNUM};
	CRect rect;
	m_lstCtrl.GetClientRect(&rect);


	for(int i =0; i< 3;i++)
	{
		str.LoadString(ntable[i]);
		m_lstCtrl.InsertColumn(i,str,0,rect.Width()/3);
	}
	m_lstCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
	ShowProcess();


	//初始化listctrl--进程地址
	m_lstAddress.GetClientRect(&rect);
	for(int i =0; i< 3;i++)
	{
		str.LoadString(IDS_NUMBER + i);
		m_lstAddress.InsertColumn(i,str,0,rect.Width()/3);
	}
	m_lstAddress.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);


	
	return TRUE;  // 除非将焦点设置到控件,否则返回 TRUE
}
void CMy0804itaskDlg::ShowProcess()
{
	m_lstCtrl.DeleteAllItems();
	//1.获得进程信息表--
	CString str;
	PROCESSENTRY32 pe = {sizeof(PROCESSENTRY32)};
	HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
	if( INVALID_HANDLE_VALUE == hSnapShot)return;
	//2.获得表头--
	BOOL bflag = Process32First(hSnapShot,&pe);
	while(bflag)
	{
		//进程名称
		m_lstCtrl.InsertItem(0,pe.szExeFile);
		//进程ID
		str.Format(_T("%d"),pe.th32ProcessID);
		m_lstCtrl.SetItemText(0,1,str);
		//线程数
		str.Format("%d",pe.cntThreads);
		m_lstCtrl.SetItemText(0,2,str);
		//3.遍历表
		bflag = Process32Next(hSnapShot,&pe);
		
	}
	
}


void CMy0804itaskDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialogEx::OnSysCommand(nID, lParam);
	}
}

// 如果向对话框添加最小化按钮,则需要下面的代码
//  来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
//  这将由框架自动完成。


void CMy0804itaskDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // 用于绘制的设备上下文


		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);


		// 使图标在工作区矩形中居中
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;


		// 绘制图标
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialogEx::OnPaint();
	}
}

//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR CMy0804itaskDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}

void CMy0804itaskDlg::OnBnClickedButton1()
{
	// TODO: 在此添加控件通知处理程序代码
	//1.获得当前选中项
	int nindex = m_lstCtrl.GetSelectionMark();
	if(-1 == nindex) return;


	//2.获得第一列ID
	CString strid = m_lstCtrl.GetItemText(nindex,1);
	DWORD dwid = atoi(strid);


	//3.通过ID 获得句柄
	HANDLE  hOpenProcess = OpenProcess(PROCESS_TERMINATE ,FALSE,dwid);
	//4.杀死它
	if(hOpenProcess)
	{
		TerminateProcess(hOpenProcess,-1);
		m_lstCtrl.DeleteItem(nindex);
	}

}

void CMy0804itaskDlg::OnBnClickedButton2()
{
	// TODO: 在此添加控件通知处理程序代码
	ShowProcess();
	
}
void CMy0804itaskDlg::OnBnClickedButton3()
{
	// TODO: 在此添加控件通知处理程序代码
	HANDLE hToken; 
   TOKEN_PRIVILEGES tkp; 
 
   // Get a token for this process. 
 
   if (!OpenProcessToken(GetCurrentProcess(), 
        TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) 
      return; 
 
   // Get the LUID for the shutdown privilege. 
 
   LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, 
        &tkp.Privileges[0].Luid); 
 
   tkp.PrivilegeCount = 1;  // one privilege to set    
   tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 
 
   // Get the shutdown privilege for this process. 
 
   AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, 
        (PTOKEN_PRIVILEGES)NULL, 0); 
 
   if (GetLastError() != ERROR_SUCCESS) 
      return ; 
 
   // Shut down the system and force all applications to close. 
 
   if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 
               SHTDN_REASON_MAJOR_OPERATINGSYSTEM |
               SHTDN_REASON_MINOR_UPGRADE |
               SHTDN_REASON_FLAG_PLANNED)) 
      return ; 




}
void CMy0804itaskDlg::OnNMDblclkList1(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
	
	// TODO: 在此添加控件通知处理程序代码
	//1.获得当前选中项
	int nindex = m_lstCtrl.GetSelectionMark();
	if(-1 == nindex)return;
	//2.获得Id那一列
	CString strID = m_lstCtrl.GetItemText(nindex,1);
	m_edtProcessID = _ttoi(strID);
	//数据交换
	UpdateData(FALSE);
	*pResult = 0;
}


void CMy0804itaskDlg::OnBnClickedButton4()
{
	// TODO: 在此添加控件通知处理程序代码
	//1.获得要搜索的进程ID 和要搜索的值
	 UpdateData(TRUE);


	//2判断是不是第一次搜索
	static bool bflag = true;
	if(bflag)
	{
		m_hProcess = OpenProcess(PROCESS_ALL_ACCESS,FALSE,m_edtProcessID);
		if(NULL == m_hProcess)return;
		//FindFirst();
		CreateThread(NULL,0,&CMy0804itaskDlg::ThreadProc,this,0,NULL);
		bflag = false;
	}
	else
	{
		//2.2搜索链表中
		FindNext();
	}
	

}


 DWORD WINAPI CMy0804itaskDlg::ThreadProc(LPVOID lpvoid)
 {
	 CMy0804itaskDlg *pthis = (CMy0804itaskDlg *)lpvoid;
	 pthis->FindFirst();
	 return 0;
 }
void CMy0804itaskDlg::FindFirst()
{
	//2.1遍历进程的地址空间64k -- 2GB,如果值相同,将当前地址存入链表
    //3.分页遍历
	for(DWORD dwBaseAddress = 64*1024;dwBaseAddress <= 2*ONE_GB;dwBaseAddress += ONE_PAGE)
	{
		FindOnePage(dwBaseAddress);
	}
	//显示
	ShowAddress();
}

void CMy0804itaskDlg::ShowAddress()
{
	m_lstAddress.DeleteAllItems();
	list<Node*>::iterator ite = m_lstNode.begin();
	CString str;
	int i =0;
	while(ite != m_lstNode.end())
	{


		//序号
		str.Format(_T("%d"),i+1);
		m_lstAddress.InsertItem(i,str);
		//地址
		str.Format(_T("%x"),(*ite)->m_dwBaseAddress);
		m_lstAddress.SetItemText(i,1,str);


		//类型
		str.Format(_T("%d"),(*ite)->m_dwType);
		m_lstAddress.SetItemText(i,2,str);
		ite++;
		i++;
	}
}

void CMy0804itaskDlg::FindOnePage(DWORD dwBaseAddress)
{
	//查找当前页的内容,
	BYTE szbuffer[ONE_PAGE] = {0};
    SIZE_T NumberOfBytesRead;
	Node *pNode = NULL;


	if(ReadProcessMemory(m_hProcess,(void*)dwBaseAddress,szbuffer,ONE_PAGE,&NumberOfBytesRead))
	{
		//遍历缓冲区szbuffer


		//1.字节
		//BYTE  *pbyte = NULL;
		for(ULONG i = 0;i <ONE_PAGE;i++ )
		{
			if(szbuffer[i] == m_edtSearchValue)
			{
				//加入链表中地址 dwBaseAddress +i,类型
				pNode = new Node(dwBaseAddress +i,ONE_BYTE);
				m_lstNode.push_back(pNode);
			}


		}
		


	    //2.字节
		short  *pShort = NULL;
		for(ULONG i = 0;i <ONE_PAGE -1;i++ )
		{
			pShort = (short*)(szbuffer + i);
			if(*pShort == m_edtSearchValue)
			{
				//加入链表中地址 dwBaseAddress +i
				pNode = new Node(dwBaseAddress +i,TWO_BYTE);
				m_lstNode.push_back(pNode);
			}


		}


	    //4.字节
		int   *pint = NULL;
		for(ULONG i = 0;i <ONE_PAGE -3;i++ )
		{
			pint = (int*)(szbuffer + i);
			if(*pint == m_edtSearchValue)
			{
				//加入链表中地址 dwBaseAddress +i
				pNode = new Node(dwBaseAddress +i,FOUR_BYTE);
				m_lstNode.push_back(pNode);
			}


		}


	    //8.字节
		LONGLONG   *pll = NULL;
		for(ULONG i = 0;i <ONE_PAGE - 7;i++ )
		{
			pll = (LONGLONG*)(szbuffer + i);
			if(*pll == m_edtSearchValue)
			{
				//加入链表中地址 dwBaseAddress +i
				pNode = new Node(dwBaseAddress +i,EIGHT_BYTE);
				m_lstNode.push_back(pNode);


			}


		}


	}
}


void CMy0804itaskDlg::FindNext()
{
	//遍历链表
	list<Node *>::iterator ite = m_lstNode.begin();


	while(ite != m_lstNode.end())
	{


		switch ((*ite)->m_dwType)
		{
		case ONE_BYTE:
			{
				BYTE b;
				if(ReadProcessMemory(m_hProcess,(LPCVOID)(*ite)->m_dwBaseAddress,&b,ONE_BYTE,NULL))
				{
					if(b != m_edtSearchValue)
					{
						delete (*ite);
						*ite = NULL;


						ite = m_lstNode.erase(ite);
						continue;
					}
				}
			}
			break;
		case TWO_BYTE:
			{
				short b;
				if(ReadProcessMemory(m_hProcess,(LPCVOID)(*ite)->m_dwBaseAddress,&b,TWO_BYTE,NULL))
				{
					if(b != m_edtSearchValue)
					{
						delete (*ite);
						*ite = NULL;


						ite = m_lstNode.erase(ite);
						continue;
					}
				}
			}
			break;
		case FOUR_BYTE:
			{
				int b;
				if(ReadProcessMemory(m_hProcess,(LPCVOID)(*ite)->m_dwBaseAddress,&b,FOUR_BYTE,NULL))
				{
					if(b != m_edtSearchValue)
					{
						delete (*ite);
						*ite = NULL;


						ite = m_lstNode.erase(ite);
						continue;
					}
				}
			}
			break;
		case EIGHT_BYTE:
			{
				LONGLONG b;
				if(ReadProcessMemory(m_hProcess,(LPCVOID)(*ite)->m_dwBaseAddress,&b,EIGHT_BYTE,NULL))
				{
					if(b != m_edtSearchValue)
					{
						delete (*ite);
						*ite = NULL;


						ite = m_lstNode.erase(ite);
						continue;
					}
				}
			}
			break;
		default:
			break;
		}
			
		ite++;
	}




	//显示
	ShowAddress();


}

void CMy0804itaskDlg::OnDestroy()
{
	CDialogEx::OnDestroy();


	// TODO: 在此处添加消息处理程序代码
	list<Node*>::iterator ite = m_lstNode.begin();
	
	while(ite != m_lstNode.end())
	{
		delete (*ite);
		*ite = NULL;
		ite++;
	}


	m_lstNode.clear();
}

void CMy0804itaskDlg::OnBnClickedButton5()
{
	// TODO: 在此添加控件通知处理程序代码
	//1.获得要修改的地址和 类型
	int nindex =  m_lstAddress.GetSelectionMark();
	if(-1 == nindex)return;
	CString strAddress = m_lstAddress.GetItemText(nindex,1);
	CString strType = m_lstAddress.GetItemText(nindex,2);


	DWORD dwAddress = strtol(strAddress,0,16);
	DWORD dwType  = atoi(strType);
	//2.获得更改后的值
	UpdateData(TRUE);
	//3.修改
	if(WriteProcessMemory(m_hProcess,(LPVOID)dwAddress,&m_edtModifyValue,dwType,NULL))
	{
		MessageBox(_T("ok"));
	}
}

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值