[英]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;
};
I'm trying to read memory regions of a process into std::byte array, but with code above, I can't get the length of buffer outside, so I want to change the type of buffer to std::vector<std::byte>
or use some other methods.我正在尝试将进程的 memory 区域读入 std::byte 数组,但是使用上面的代码,我无法获得外部缓冲区的长度,因此我想将缓冲区的类型更改为
std::vector<std::byte>
或使用其他一些方法。 How can I do this?我怎样才能做到这一点?
Since C++11, std::vector::data
will provide a pointer to the backing array.由于 C++11,
std::vector::data
将提供一个指向后备数组的指针。 If you're using older tools without support for C++ 11, &buffer[0]
probably works, I've never seen it not work, but is not guaranteed by the Standard.如果您使用的是不支持 C++ 11 的旧工具,
&buffer[0]
可能有效,我从未见过它不起作用,但标准不保证。
Looking at the code again, if you've got std::byte
, C++11 support is not an issue.再次查看代码,如果您有
std::byte
,则 C++11 支持不是问题。
So...所以...
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.