【问题标题】:Getting base address of a process获取进程的基地址
【发布时间】:2012-04-07 17:23:36
【问题描述】:

我正在尝试制作一个从扫雷中读取计时器值的程序。 (操作系统是windows 7 64bit)

使用作弊引擎我找到了变量的基地址,但每次运行 Minesweeper 时它都会改变。

我需要怎么做才能自动找出基地址?

它与可执行基地址有关吗?

这是我的代码:

#include <windows.h>
#include <iostream>
using namespace std;



int main()
{
    DWORD baseAddress = 0xFF1DAA38;//always changing
    DWORD offset1 = 0x18;
    DWORD offset2 = 0x20;
    DWORD pAddress1;
    DWORD pAddress2;

    float value = 0;
    DWORD pid;
    HWND hwnd;

    hwnd = FindWindow(NULL,"Minesweeper");
    if(!hwnd)//didn't find the window
    {
        cout <<"Window not found!\n";
        cin.get();
    }
    else
    {
        GetWindowThreadProcessId(hwnd,&pid);
        HANDLE phandle = OpenProcess(PROCESS_VM_READ,0,pid);//get permission to read
        if(!phandle)//failed to get permission
        {
            cout <<"Could not get handle!\n";
            cin.get();
        }
        else
        {
            ReadProcessMemory(phandle,(void*)(baseAddress),&pAddress1,sizeof(pAddress1),0);
            ReadProcessMemory(phandle,(void*)(pAddress1 + offset1),&pAddress2,sizeof(pAddress2),0);
            while(1)
            {
                ReadProcessMemory(phandle,(void*)(pAddress2 + offset2),&value,sizeof(value),0);
                cout << value << "\n";
                Sleep(1000);
            }
        }
    }
}

【问题讨论】:

    标签: c++ minesweeper readprocessmemory base-address


    【解决方案1】:
    #pragma comment( lib, "psapi" )
    
    DWORD GetModuleBase(HANDLE hProc, string &sModuleName) 
    { 
       HMODULE *hModules; 
       char szBuf[50]; 
       DWORD cModules; 
       DWORD dwBase = -1; 
       //------ 
    
       EnumProcessModules(hProc, hModules, 0, &cModules); 
       hModules = new HMODULE[cModules/sizeof(HMODULE)]; 
    
       if(EnumProcessModules(hProc, hModules, cModules/sizeof(HMODULE), &cModules)) { 
          for(int i = 0; i < cModules/sizeof(HMODULE); i++) { 
             if(GetModuleBaseName(hProc, hModules[i], szBuf, sizeof(szBuf))) { 
                if(sModuleName.compare(szBuf) == 0) { 
                   dwBase = (DWORD)hModules[i]; 
                   break; 
                } 
             } 
          } 
       } 
    
       delete[] hModules; 
    
       return dwBase; 
    }
    

    【讨论】:

    • 我已包含 和 并尝试以这种方式使用它:GetModuleBase(phandle, (string)"Minesweeper.exe"); 但我收到此错误:error LNK2019: unresolved external symbol _GetModuleBaseNameA@16 referenced in function "unsigned long __cdecl GetModuleBase... 和 error LNK2019: unresolved external symbol _EnumProcessModules@16 referenced in function "unsigned long __cdecl GetModuleBase...。或许你可以举一个可行的例子?
    • @yoni0505 添加#pragma comment(lib, "psapi")
    • 我已经添加了行并且程序编译了。但它给了我这个错误:Run-Time Check Failure #3 - The variable 'hModules' is being used without being initialized.,然后是Unhandled exception at 0x770215de in Minesweeper Timer.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0034f8f8.. 和Unhandled exception at 0x770215de in Minesweeper Timer.exe: 0x00000000: The operation completed successfully.
    猜你喜欢
    • 1970-01-01
    • 2017-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多