内存读写

来源:互联网 发布:axure的mac版怎么安装 编辑:程序博客网 时间:2024/04/28 05:40
#include <windows.h>#include <stdio.h>#include <tlhelp32.h>#include <string.h>#include <malloc.h>HANDLE fnGetProcess(){HANDLE hShot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);PROCESSENTRY32 myPro;myPro.dwSize=sizeof(myPro);Process32First(hShot, &myPro);do{if(strcmp(myPro.szExeFile, "测试.exe")==0){HANDLE hPro = OpenProcess(PROCESS_ALL_ACCESS, FALSE, myPro.th32ProcessID);return hPro;}}while(Process32Next(hShot, &myPro));return NULL;}/*读内存*/void main(){HANDLE hPro=fnGetProcess();/*内存基地址*/if(hPro==NULL){puts("没有找到句柄!!!")return;}int *ReAddRess=(int *)1244996;/*偏移量*/int *p=(int *)malloc(sizeof(int));/*存储读出的内容*/unsigned long size;/*实际读出长度*/ReadProcessMemory(hPro, ReAddRess, p, sizeof(int), &size);printf("%d", *p);}/*写内存*/void main(){HANDLE hPro=fnGetProcess();/*内存基地址*/if(hPro==NULL){puts("没有找到句柄!!!")return;}int *WrAddRess=(int *)1244996;/*偏移量*/int *p=(int *)malloc(sizeof(int));/*要写入内容的首地址*/WriteProcessMemory(hPro, WrAddRess, p, 4, NULL);}