[英]I can't read values from memory
So i am trying to get read some values from a game.所以我试图从游戏中读取一些值。 I can successfully read the data from game via Cheat Engine.
我可以通过作弊引擎成功读取游戏中的数据。 But when i try to enter the value to my code and receive values i only get 0. However when i try to do the same thing with some other programs it works without a problem.
但是当我尝试在我的代码中输入值并接收值时,我只得到 0。但是,当我尝试对其他一些程序做同样的事情时,它可以正常工作。 Here is the code
这是代码
#include <iostream>
#include <Windows.h>
#include <string>
DWORD pid;
DWORD adr = 0x23CAE074AA8;
int my_value;
int main(){
HWND hWnd = FindWindowA(0, ("game"));
GetWindowThreadProcessId(hWnd, &pid);
std::cout << pid << std::endl;
HANDLE pHandle = OpenProcess(PROCESS_VM_READ, FALSE, pid);
while(1){
ReadProcessMemory(pHandle, (LPVOID)adr, &my_value, sizeof(my_value),0);
std::cout << my_value << std::endl;
}
}
I think the problem is the length of my address.我认为问题是我的地址的长度。 Other programs adresses had shorter length.
其他节目地址的长度较短。 It also gives these errors:
它还给出了这些错误:
Description Resource Path Location Type
cast to pointer from integer of different size [-Wint-to-pointer-cast] read_memory.cpp /read_memory/src line 17 C/C++ Problem
Description Resource Path Location Type
overflow in conversion from 'long long int' to 'LONG' {aka 'long int'} changes value from '2459641006760' to '-1375253848' [-Woverflow] read_memory.cpp /read_memory/src line 6 C/C++ Problem
As the message says, DWORD
seems too small to store addresses in your environment.正如消息中所说,
DWORD
似乎太小而无法在您的环境中存储地址。
You should use uintptr_t
from the header cstdint
to store integers to be used as pointers.您应该使用 header
cstdint
中的uintptr_t
来存储用作指针的整数。
#include <iostream>
#include <Windows.h>
#include <string>
#include <cstdint> // add this
DWORD pid;
uintptr_t adr = 0x23CAE074AA8; // change type
// ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.