本文介绍了ReadProcessMemory上的错误299的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试从游戏内存中读取实体名称,与使用ce进行检查相比,指针100%正确.

Trying to read entity name from game memory, pointers 100% correct as using ce to check.

读取/写入浮点数/整数值没有问题

have no problems reading/writing float/integer values

32位进程,也是如此-尝试在x64中编译代码,没有帮助.

32 bit process, game aswell - tried compiling code in x64, didnt help.

GetLastError()

返回299卢比

ERROR_PARTIAL_COPY

ERROR_PARTIAL_COPY

299 (0x12B)

Only part of a ReadProcessMemory or WriteProcessMemory request was completed.

任何想法都是什么原因?下面的代码

Any ideas what can be reason ?code below

#include <windows.h>
#include <TlHelp32.h>
#include <iostream>
#include <string>
#include <time.h>
#include <tchar.h>



using namespace std;

DWORD dwGetModuleBaseAddress(DWORD dwProcessIdentifier, TCHAR *lpszModuleName);
string readName(HANDLE handlez, DWORD base, DWORD bp, DWORD ofset1, DWORD ofset2, DWORD ofsetInc);


int main()
{
    DWORD baseOfset = 0x60DE90;
    DWORD ofset1 = 0x4c4;
    DWORD ofset2 = 0x6a0;
    DWORD ofset3 = 0x18;


    HWND window = NULL;//FindWindow(0, _TEXT("Gothic II - 2.6 (pol)"));
    DWORD pID = 0;
    DWORD dwBP = NULL;
    HANDLE handle = NULL;// OpenProcess(PROCESS_ALL_ACCESS, FALSE, pID);
    string gameStatus;
    int refresher = clock();
    gameStatus = "Waiting for game";




    window = FindWindow(0, _TEXT("Gothic II - 2.6 (pol)")); // window title
    if (window)
    {
        GetWindowThreadProcessId(window, &pID);
        if (pID != 0)
        {
            handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pID);
            dwBP = dwGetModuleBaseAddress(pID, _T("Gothic2.exe"));  // proc name

            if (handle == INVALID_HANDLE_VALUE || handle == NULL || dwBP == NULL)
            {
                gameStatus = "No handle";
            }
            else
            {
                gameStatus = "OK";
            }
        }
        else
        {
            gameStatus = "No access";
        }
    }
    else
    {
        gameStatus = "No window";

    }




    while (!GetAsyncKeyState(VK_DELETE))
    {
        if (clock() - refresher > 1000)
        {
            refresher = clock();


            cout << gameStatus << endl;
            string elo="a";


                elo = readName(handle,  dwBP, baseOfset, ofset1, ofset2, ofset3);
                if (elo == "a")
                {
                    cout << ":(\n";
                }

                cout << "Name: " <<  elo <<".\n";

                cout << "Name: " << &elo << ".\n" << endl;
                system("pause");

                        }
    }


    CloseHandle(handle);
}

string readName(HANDLE handlez, DWORD base, DWORD bp, DWORD ofset1, DWORD ofset2, DWORD ofsetInc)
{

    DWORD adresik;

    ReadProcessMemory(handlez, (LPCVOID)(base + bp), &adresik, sizeof(DWORD), NULL); // base adress + base pointer
    adresik += ofset1;          //1st lvl pointer
    ReadProcessMemory(handlez, (LPCVOID)adresik, &adresik, sizeof(DWORD), NULL); 
    adresik += ofset2;          // 2nd lvl pointer
    ReadProcessMemory(handlez, (LPCVOID)adresik, &adresik, sizeof(DWORD), NULL); 
    adresik += ofsetInc;            // 3rd lvl pointer this goes up +=20
    ReadProcessMemory(handlez, (LPCVOID)adresik, &adresik, sizeof(DWORD), NULL); 
    adresik += 0x12c;                   // 4th static pointer
    ReadProcessMemory(handlez, (LPCVOID)adresik, &adresik, sizeof(DWORD), NULL); 
    adresik += 0x0;                     // 5th static pointer
    ReadProcessMemory(handlez, (LPCVOID)adresik, &adresik, sizeof(DWORD), NULL); 


    string papa;

    ReadProcessMemory(handlez, (LPCVOID)adresik, &papa, sizeof(string), NULL); // get name
    DWORD ero = GetLastError();
    cout << ero << endl;
    return papa;  // return name


}


DWORD dwGetModuleBaseAddress(DWORD dwProcessIdentifier, TCHAR *lpszModuleName)
{
    HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwProcessIdentifier);
    DWORD dwModuleBaseAddress = 0;
    if (hSnapshot != INVALID_HANDLE_VALUE)
    {
        MODULEENTRY32 ModuleEntry32 = { 0 };
        ModuleEntry32.dwSize = sizeof(MODULEENTRY32);
        if (Module32First(hSnapshot, &ModuleEntry32))
        {
            do
            {
                if (_tcscmp(ModuleEntry32.szModule, lpszModuleName) == 0)
                {
                    dwModuleBaseAddress = (DWORD)ModuleEntry32.modBaseAddr;
                    break;
                }
            } while (Module32Next(hSnapshot, &ModuleEntry32));
        }
        CloseHandle(hSnapshot);
    }
    return dwModuleBaseAddress;
}

推荐答案

您不能只将c字符串复制到std :: string的内存位置.

You can't just copy in c-strings into the memory location of a std::string.

您想要的大概是这样的(假设这实际上是您正在读取的以空终止的字符串):

What you want is presumably something like this (assuming this is actually have a null terminated string that you are reading):

const int MAX_SIZE = 512;
const char buffer[MAX_SIZE];
string papa;

ReadProcessMemory(handlez, (LPCVOID)adresik, buffer, MAX_SIZE, NULL); // get name

papa = buffer;    

此外,如果字符串恰好位于页面边界附近,则可能需要逐字节或小块读取它,直到找到终止的空字符为止.因此,如果您可以找到存储在任何地方的字符串长度,我建议您阅读并使用它.

Also if the string is right around a page-boundary you might need to read it byte-by-byte or in small chunks until you found the terminating null character. So if you can find the string length being stored anywhere I would suggest that you read and use that.

这篇关于ReadProcessMemory上的错误299的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 16:13