C++内存读写例子

/*************************************************************
// 声明头文件
#ifndef LyShark__h
#define LyShark__h #pragma comment(lib,"LyShark.lib"); extern "C"__declspec(dllexport) int GetProcessID(char *Name); extern "C"__declspec(dllexport) int GetIntMemory_One(int Pid,long Base,int One);
extern "C"__declspec(dllexport) int GetIntMemory_Two(int Pid,long Base,int One,int Two);
extern "C"__declspec(dllexport) int GetIntMemory_Three(int Pid,long Base,int One,int Two,int Three);
extern "C"__declspec(dllexport) int GetIntMemory_Four(int Pid,long Base,int One,int Two,int Three,int Four);
extern "C"__declspec(dllexport) int GetIntMemory_Five(int Pid,long Base,int One,int Two,int Three,int Four,int Five);
extern "C"__declspec(dllexport) int GetIntMemory_Six(int Pid,long Base,int One,int Two,int Three,int Four,int Five,int Six); extern "C"__declspec(dllexport) int SetIntMemory_One(int Pid,long Base,int One,int WriteValue);
extern "C"__declspec(dllexport) int SetIntMemory_Two(int Pid,long Base,int One,int Two,int WriteValue);
extern "C"__declspec(dllexport) int SetIntMemory_Three(int Pid,long Base,int One,int Two,int Three,int WriteValue);
extern "C"__declspec(dllexport) int SetIntMemory_Four(int Pid,long Base,int One,int Two,int Three,int Four,int WriteValue);
extern "C"__declspec(dllexport) int SetIntMemory_Five(int Pid,long Base,int One,int Two,int Three,int Four,int Five,int WriteValue);
extern "C"__declspec(dllexport) int SetIntMemory_Six(int Pid,long Base,int One,int Two,int Three,int Four,int Five,int Six,int WriteValue); #endif LyShark__h */
//*************************************************************
#include <windows.h> bool APIENTRY DllMain(HANDLE handle,DWORD dword,LPVOID lpvoid)
{
return true;
} //*************************************************************
// 打开进程,取进程PID
extern "C"__declspec(dllexport) int GetProcessID(char *Name)
{
HWND Pid=::FindWindow(NULL,Name);
DWORD Retn;
::GetWindowThreadProcessId(Pid,&Retn);
return Retn;
} //*************************************************************
// 读取内存偏移整数型
extern "C"__declspec(dllexport) int GetIntMemory_One(int Pid,long Base,int One)
{
DWORD byread;
int Value=0;
HANDLE proce=::OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
LPCVOID pbase=(LPCVOID)Base;
LPVOID rbuffer=(LPVOID)&Value; ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + One); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread); return Value;
} extern "C"__declspec(dllexport) int GetIntMemory_Two(int Pid,long Base,int One,int Two)
{
DWORD byread;
int Value=0;
HANDLE proce=::OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
LPCVOID pbase=(LPCVOID)Base;
LPVOID rbuffer=(LPVOID)&Value; ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + Two); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + One); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread); return Value;
} extern "C"__declspec(dllexport) int GetIntMemory_Three(int Pid,long Base,int One,int Two,int Three)
{
DWORD byread;
int Value=0;
HANDLE proce=::OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
LPCVOID pbase=(LPCVOID)Base;
LPVOID rbuffer=(LPVOID)&Value; ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + Three); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + Two); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + One); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread); return Value; } extern "C"__declspec(dllexport) int GetIntMemory_Four(int Pid,long Base,int One,int Two,int Three,int Four)
{
DWORD byread;
int Value=0;
HANDLE proce=::OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
LPCVOID pbase=(LPCVOID)Base;
LPVOID rbuffer=(LPVOID)&Value; ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + Four); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + Three); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + Two); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + One); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread); return Value; } extern "C"__declspec(dllexport) int GetIntMemory_Five(int Pid,long Base,int One,int Two,int Three,int Four,int Five)
{
DWORD byread;
int Value=0;
HANDLE proce=::OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
LPCVOID pbase=(LPCVOID)Base;
LPVOID rbuffer=(LPVOID)&Value; ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + Five); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + Four); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + Three); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + Two); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + One); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread); return Value; } extern "C"__declspec(dllexport) int GetIntMemory_Six(int Pid,long Base,int One,int Two,int Three,int Four,int Five,int Six)
{
DWORD byread;
int Value=0;
HANDLE proce=::OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
LPCVOID pbase=(LPCVOID)Base;
LPVOID rbuffer=(LPVOID)&Value; ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + Six); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + Five); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + Four); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + Three); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + Two); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + One); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread); return Value; } //*************************************************************
// 写入内存偏移整数型 extern "C"__declspec(dllexport) int SetIntMemory_One(int Pid,long Base,int One,int WriteValue)
{
DWORD byread;
int Value=0;
HANDLE proce=::OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
LPCVOID pbase=(LPCVOID)Base;
LPVOID rbuffer=(LPVOID)&Value; ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + One); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread); DWORD bywrite;
LPVOID wbuffer = (LPVOID)&WriteValue;
WriteProcessMemory(proce,(LPVOID)pbase,wbuffer,4,&bywrite); return 1; } extern "C"__declspec(dllexport) int SetIntMemory_Two(int Pid,long Base,int One,int Two,int WriteValue)
{
DWORD byread;
int Value=0;
HANDLE proce=::OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
LPCVOID pbase=(LPCVOID)Base;
LPVOID rbuffer=(LPVOID)&Value; ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + Two); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + One); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread); DWORD bywrite;
LPVOID wbuffer = (LPVOID)&WriteValue;
WriteProcessMemory(proce,(LPVOID)pbase,wbuffer,4,&bywrite); return 1; }
extern "C"__declspec(dllexport) int SetIntMemory_Three(int Pid,long Base,int One,int Two,int Three,int WriteValue)
{
DWORD byread;
int Value=0;
HANDLE proce=::OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
LPCVOID pbase=(LPCVOID)Base;
LPVOID rbuffer=(LPVOID)&Value; ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + Three); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + Two); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + One); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread); DWORD bywrite;
LPVOID wbuffer = (LPVOID)&WriteValue;
WriteProcessMemory(proce,(LPVOID)pbase,wbuffer,4,&bywrite); return 1;
} extern "C"__declspec(dllexport) int SetIntMemory_Four(int Pid,long Base,int One,int Two,int Three,int Four,int WriteValue)
{
DWORD byread;
int Value=0;
HANDLE proce=::OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
LPCVOID pbase=(LPCVOID)Base;
LPVOID rbuffer=(LPVOID)&Value; ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + Four); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + Three); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + Two); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + One); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread); DWORD bywrite;
LPVOID wbuffer = (LPVOID)&WriteValue;
WriteProcessMemory(proce,(LPVOID)pbase,wbuffer,4,&bywrite); return 1;
} extern "C"__declspec(dllexport) int SetIntMemory_Five(int Pid,long Base,int One,int Two,int Three,int Four,int Five,int WriteValue)
{
DWORD byread;
int Value=0;
HANDLE proce=::OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
LPCVOID pbase=(LPCVOID)Base;
LPVOID rbuffer=(LPVOID)&Value; ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + Five); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + Four); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + Three); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + Two); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + One); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread); DWORD bywrite;
LPVOID wbuffer = (LPVOID)&WriteValue;
WriteProcessMemory(proce,(LPVOID)pbase,wbuffer,4,&bywrite); return 1; } extern "C"__declspec(dllexport) int SetIntMemory_Six(int Pid,long Base,int One,int Two,int Three,int Four,int Five,int Six,int WriteValue)
{
DWORD byread;
int Value=0;
HANDLE proce=::OpenProcess(PROCESS_ALL_ACCESS,false,Pid);
LPCVOID pbase=(LPCVOID)Base;
LPVOID rbuffer=(LPVOID)&Value; ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + Six); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + Five); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + Four); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + Three); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + Two); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread);
pbase = (LPCVOID)(Value + One); ::ReadProcessMemory(proce,pbase,rbuffer,4,&byread); DWORD bywrite;
LPVOID wbuffer = (LPVOID)&WriteValue;
WriteProcessMemory(proce,(LPVOID)pbase,wbuffer,4,&bywrite); return 1; }
上一篇:Python的方法解析顺序(MRO)


下一篇:WPF ----在UserControl的xaml里绑定依赖属性