Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Read text with readprocessmemory. Address > FFFFFFFFh

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
jonasirgreta
How do I cheat?
Reputation: 0

Joined: 27 Sep 2019
Posts: 2

PostPosted: Fri Sep 27, 2019 11:33 pm    Post subject: Read text with readprocessmemory. Address > FFFFFFFFh Reply with quote

Hello.

I've got this little problem which I assume there is an easy solution to it. Basically, I am trying to read text from address. The text is "tests" (I don't know if it's NUL terminated). The first letter is at address 0x144B97DE1, the second one is at 0x144B97DE2 and so on. When I try to print the letter to the console, I get a non-english letter (as if somekinda symbol, chinese letter, etc...). Here is the code I am using:

char letter1;
long long address = 0x144B97DE1;
ReadProcessMemory(hProc, (LPVOID)address , &letter1, 1, 0);
cout << letter1<< endl;

I don't think the code above is correct, given the fact that address is of type long long instead of DWORD. But, I've never encountered address that is more than 0xFFFFFFFF and I don't know how to treat it. I tried modifying the code in other ways, but it was still bad. So this is the second problem. Plus, I don't know if it's supposed to be char type, or char*, char[], string or even other types like byte, int, etc... Whole my life I've been reading numbers from DWORD addresses.

Please, anyone, help me.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 155

Joined: 25 Jan 2006
Posts: 7983
Location: 127.0.0.1

PostPosted: Sat Sep 28, 2019 12:12 am    Post subject: Reply with quote

0x144B97DE1 would imply the address is 64bit. So you need to make sure that you are compiling your application as 64bit.

Address wise, 64bit has pointer types such as DWORD_PTR. That will expand out to:
- typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR;
- typedef unsigned __int64 ULONG_PTR, *PULONG_PTR;

Character-wise, are you sure the string is not unicode? If so, then you would need to use wchar_t. For a full string you can use:

char buffer[1024]{}; // For ANSI
wchar_t buffer[1024]{}; // Fo Unicode

When reading just pass the size of the buffer instead of 1, and the pointer to the buffer.

Code:

DWORD_PTR address = 0x144B97DE1;

char buffer[1024]{};
::ReadProcessMemory(hProc, (LPVOID)address, &buffer, 1024, 0);
std::cout << buffer << std::endl;

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
jonasirgreta
How do I cheat?
Reputation: 0

Joined: 27 Sep 2019
Posts: 2

PostPosted: Sat Sep 28, 2019 1:34 am    Post subject: Reply with quote

Thank you for the quick and well-explained reply. But more importantly, thank you for the right answer. I changed compiling as 64bit, like you said. I was surprised, after reading what you said and trying out your code (which worked like a charm), that it read the entire text. I was expecting to read 1 letter at a time, then append them.

For curiousity I tried to change -> char buffer[1024]{}; <- to -> string buffer; <- but it didn't work. Luckily, it's easity to convert from char array to string. Also, nice to learn about new data type "DWORD_PTR".

Thanks again, seriously.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 155

Joined: 25 Jan 2006
Posts: 7983
Location: 127.0.0.1

PostPosted: Sat Sep 28, 2019 1:48 pm    Post subject: Reply with quote

std::string is not a straight buffer. It is a STL type that contains some mechanisms to deal with variable string length. If a string is less than 16 bytes, the data is stored in a static buffer (basically char buffer[16]; ) but if longer, the buffer is used as a pointer (first 4 or 8 bytes) and points to an allocated block of memory for the string.

If you need a string buffer, you can read the data into a char array then convert it to a string, like this:

Code:

DWORD_PTR address = 0x144B97DE1;

char buffer[1024]{};
::ReadProcessMemory(hProc, (LPVOID)address, &buffer, 1024, 0);

std::string str = buffer;
std::cout << str << std::endl;

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites