LH
发布于 2018-01-26 / 430 阅读 / 0 评论 / 0 点赞

折腾“XP扫雷”

在windows中,要访问其他进程,要使用OpenProcess 函数用来打开一个已存在的进程对象,并返回进程的句柄。 然后利用返回的进程句柄进行ReadProcessMemory或者WriteProcessMemory 扫雷的状态信息是固定的,我们可以直接使用CE找出相应的状态地址,然后进行读写即可。

#include "stdio.h"
#include "windows.h"
#include "shellapi.h"
int main(){
    int time=0,wtime=666;
    DWORD process=0;
    HANDLE hp=0;
    HWND sl=0;
    ShellExecute(0,"open","winmine.exe","","C:\\WINDOWS\\system32",SW_SHOWNORMAL);
    Sleep(68);
    sl = FindWindow(NULL,"扫雷");
    if(!sl){
        printf("Can't find the window!\n");
        return -1;

    }
    GetWindowThreadProcessId(sl,&process);
    if(!process){
        printf("Can't get the windowID!\n");
        return -1;

    }
    hp = OpenProcess(PROCESS_ALL_ACCESS,FALSE,process);

    while (1){
        ReadProcessMemory(hp,(LPCVOID)0x0100579C,&time,4,NULL);
        if (time>=999)
        {
            time=0;
            WriteProcessMemory(hp,(LPCVOID)0x0100579C,&time,4,NULL);
            system("cls");

        }
        printf("\r当前时间:%d",time);
        Sleep(300);

    }
    return 0;

}

评论