Windows Error Code 299 while trying to ReadProcessMemory

问题描述 投票:0回答:1

我有两个文件。我的虚拟文件和我的句柄文件。

在 Windows API 网站上,它说:

只完成了 ReadProcessMemory 或 WriteProcessMemory 请求的一部分

但是,我不知道如何处理该错误代码。

// Handle of Dummy.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <string>
#include <Windows.h>

using namespace std;
int main()
{
    string input;
    int intRead = 0;
    HANDLE a = OpenProcess(PROCESS_ALL_ACCESS, FALSE, 34180);
    if (a == NULL) { // Failed to get a handle
        cout << "OpenProcess failed. GetLastError = " << dec << GetLastError() << endl;
        system("pause");
        return EXIT_FAILURE;
    }
    BOOL b = ReadProcessMemory(a, (LPCVOID)0x159963412292, &intRead, sizeof(int), NULL);
    if (b == FALSE) {
        cout << "ReadProcessMemory failed. GetLastError = " << dec << GetLastError() << endl;
        system("pause");
        return EXIT_FAILURE;
    }
    cout << "intRead = " << dec << intRead << endl;

    while (true)
    {
        system("pause > nul");
        cout << "--------------------------" << endl;
        getline(cin, input);
        if (input.empty()) {
            continue;
        }
    }
}
// Dummy.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <string>
#include <Windows.h>

using namespace std;
int main()
{
    int varInt = 123456;
    string input;
    string varString = "DefaultString";
    char arrChar[128] = "Long char array right there ->";
    int* ptr2int = &varInt;
    int** ptr2ptr = &ptr2int;
    int*** ptr2ptr2 = &ptr2ptr;
    while (true)
    {
        cout << "Process ID: " << GetCurrentProcessId() << endl << endl;
        cout << "varInt (0x" << (uintptr_t) &varInt << ")" << " = " << varInt << endl;
        cout << "varString (0x" << (uintptr_t) &varString << ")" << " = " << varString << endl;
        cout << "arrChar[128] (0x" << (uintptr_t) &arrChar << ")" << " = " << arrChar << endl << endl;
        cout << "ptr2int (0x" << (uintptr_t) &ptr2int << ")" << " = " << "0x" << ptr2int << endl;
        cout << "ptr2ptr (0x" << (uintptr_t) &ptr2ptr << ")" << " = " << "0x" << ptr2ptr << endl;
        cout << "ptr2ptr2 (0x" << (uintptr_t) &ptr2ptr2 << ")" << " = " << "0x" << ptr2ptr2 << endl << endl;
        cout << "Press ENTER to print again." << endl << endl;
        system("pause > nul");
        cout << "--------------------------" << endl;
        getline(cin, input);
        if (input.empty()) {
            continue;
        }
    }
}

ReadProcessMemory 失败。获取上一个错误 = 299

我尝试以管理员身份运行这两个应用程序,尝试在目录和 Visual Studio 中正常打开它,但没有任何帮助。

c++ windows winapi memory
1个回答
-3
投票

修好了! 在 readprocessmemory 行的句柄文件中,我不得不将地址从“0x159963412292”更改为“159963412292”

© www.soinside.com 2019 - 2024. All rights reserved.