Issue with reading process array using ReadProcessMemory.

The ReadProcessMemory function can be used to read the memory data of a specified process. To read an array from a process, you can achieve this by reading the starting address of the array and its length.

Here is an example code for reading an array of integers from a process.

#include <iostream>
#include <windows.h>

int main() {
    // 获取目标进程的句柄
    DWORD pid = 1234; // 目标进程的PID
    HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
    if (hProcess == NULL) {
        std::cout << "无法打开进程" << std::endl;
        return 1;
    }

    // 设置要读取的数组的首地址和长度
    DWORD_PTR arrayAddress = 0x12345678; // 数组的首地址
    int arraySize = 10; // 数组的长度

    // 读取数组数据
    int* arrayData = new int[arraySize];
    SIZE_T bytesRead;
    BOOL success = ReadProcessMemory(hProcess, (LPCVOID)arrayAddress, arrayData, sizeof(int) * arraySize, &bytesRead);
    if (!success) {
        std::cout << "读取失败" << std::endl;
        return 1;
    }

    // 输出读取到的数组数据
    for (int i = 0; i < arraySize; i++) {
        std::cout << arrayData[i] << std::endl;
    }

    // 释放资源
    delete[] arrayData;
    CloseHandle(hProcess);

    return 0;
}

In the example code, the target process is first opened using the OpenProcess function to obtain the process handle. Next, the starting address and length of the array to be read are set. Then, the ReadProcessMemory function is used to read the array data and store it in a dynamically allocated integer array. Finally, the array data is outputted, and resources are released.

It is important to note that the ReadProcessMemory function reads the memory data of the target process, so it is necessary to ensure that the target process has sufficient permissions to carry out the read operation.

Leave a Reply 0

Your email address will not be published. Required fields are marked *