簡體   English   中英

如何使用帶有向量的 winapi ReadProcessMemory 從另一個進程讀取緩沖區?

[英]How to use winapi ReadProcessMemory with vector to read buffer from another process?

std::byte *ReadBytes(PVOID address, SIZE_T length)
{
    std::byte *buffer = new std::byte[length];
    std::cout << "length" << sizeof(buffer) << std::endl;

    ReadProcessMemory(this->processHandle, address, buffer, length, NULL);

    return buffer;
};

我正在嘗試將進程的 memory 區域讀入 std::byte 數組,但是使用上面的代碼,我無法獲得外部緩沖區的長度,因此我想將緩沖區的類型更改為std::vector<std::byte>或使用其他一些方法。 我怎樣才能做到這一點?

由於 C++11, std::vector::data將提供一個指向后備數組的指針。 如果您使用的是不支持 C++ 11 的舊工具, &buffer[0]可能有效,我從未見過它不起作用,但標准不保證。

再次查看代碼,如果您有std::byte ,則 C++11 支持不是問題。

所以...

std::vector<std::byte> ReadBytes(PVOID address, SIZE_T length)
{
    std::vector<std::byte> buffer(length);
    std::cout << "length" << buffer.size() << std::endl;

    ReadProcessMemory(this->processHandle, address, buffer.data(), length, NULL);

    return buffer;
};

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM