RT

解决方案 »

  1.   

    其实也很简单
    我给你看个类
    你就知道了
    #include "windows.h"
    #include "stdio.h"/*************变量声明***************/
    HANDLE g_hProcess;
    DWORD g_arList[1024];
    DWORD g_nListCnt=0;/*************函数声明***************/
    BOOL FindFirst(DWORD iVal);
    BOOL CompareAPage(DWORD dwBase,DWORD dwValue);
    void ShowList();
    BOOL FindNext(DWORD dwValue);
    BOOL WriteMemory(DWORD dwAddr,DWORD dwValue);int main()
    {
    // char szFileName[]="D:\\game\\连连看.exe";// STARTUPINFO si={sizeof(si)};
    // PROCESS_INFORMATION pi;
    // ::CreateProcess(NULL,szFileName,NULL,NULL,FALSE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi);// ::CloseHandle(pi.hThread);
    // g_hProcess=pi.hProcess; DWORD dwProcessId;
    scanf("%d",&dwProcessId);
        g_hProcess = ::OpenProcess(PROCESS_VM_READ|PROCESS_VM_WRITE|PROCESS_VM_OPERATION, FALSE, dwProcessId); int iVal;
    printf("Input val=");
    scanf("%d",&iVal);// FindFirst(iVal);
    ShowList();
    while(g_nListCnt>1)
    {
    printf("Input val=");
    scanf("%d",&iVal);//
    FindNext(iVal);
    ShowList();
    } printf("Input New Ival=");
    scanf("%d",&iVal);
    if(WriteMemory(g_arList[0],iVal))
    printf("\n修改数据成功!\n");
    ::CloseHandle(g_hProcess);
    return 0;}BOOL FindFirst(DWORD dwValue)
    {
    const int dwOneGB=1024*1024*1024;
    const int dwOnePage=4*1024;
    if(g_hProcess==NULL)
    {
    return FALSE;
    } DWORD dwBase;
    /* OSVERSIONINFO vi={sizeof(vi)};//windows 98操作系统为应用程序预留4MB-4GB空间
    ::GetVersionEx(&vi); if(vi.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS)
    dwBase=4*1024*1024;
    else
    dwBase=640*1024;*/ for(dwBase=0;dwBase<2*dwOneGB;dwBase+=dwOnePage)
    {
    CompareAPage(dwBase,dwValue);
    } return TRUE;
    }BOOL CompareAPage(DWORD dwBaseAddr,DWORD dwValue)
    {
    BYTE arBytes[4096];
    if(!::ReadProcessMemory(g_hProcess,(LPVOID)dwBaseAddr,arBytes,4096,NULL))
    return FALSE; DWORD* pdw;
    for(int i=0;i<4*1024-3;i++)
    {
    pdw=(DWORD*)&arBytes[i];
    if(*pdw==dwValue)
    {
    if(g_nListCnt>=1024)
    return FALSE;
    g_arList[g_nListCnt]=dwBaseAddr+i;
    g_nListCnt++;
    }
    }
    return TRUE;
    }void ShowList()
    {
    for(int i=0;i<g_nListCnt;i++)
    printf("%08X\n",g_arList[i]);
    }BOOL FindNext(DWORD dwValue)
    {
    int nOrgCnt=g_nListCnt;
    g_nListCnt=0; BOOL bRet=FALSE;
    DWORD dwReadValue;
    for(int i=0;i<nOrgCnt;i++)
    {
    if(::ReadProcessMemory(g_hProcess,(LPVOID)g_arList[i],&dwReadValue,sizeof(DWORD),NULL))
    {
    if(dwReadValue==dwValue)
    {
            g_arList[g_nListCnt]=g_arList[i];
               g_nListCnt++;
         bRet=TRUE;
    }
    }
    }
    return bRet;
    }BOOL WriteMemory(DWORD dwAddr,DWORD dwValue)
    {
    BOOL bRet=WriteProcessMemory(
      g_hProcess,  // handle to process whose memory is written to
      (LPVOID)dwAddr,  // address to start writing to
      &dwValue,  // pointer to buffer to write data to
      sizeof(DWORD),      // number of bytes to write
      NULL                    // actual number of bytes written
    );
       return bRet;}