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 String Memory UTF-16 C++

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Liger
Cheater
Reputation: 0

Joined: 26 Jan 2019
Posts: 35
Location: don't have

PostPosted: Thu Jul 22, 2021 9:08 pm    Post subject: Read String Memory UTF-16 C++ Reply with quote

I try to read this string, but it only reads the first letter

using language C++

https://im.ge/i/7xr8P

_________________
(^_^)
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
DanyDollaro
Master Cheater
Reputation: 3

Joined: 01 Aug 2019
Posts: 328

PostPosted: Fri Jul 23, 2021 2:21 am    Post subject: Reply with quote

That's a UTF-16 string, you need to use the wide version of the output function you are using, assuming you are using cout, what you are doing could be:
Code:
std::cout << string;

To show that string you have to do:
Code:
std::wcout << string;


In case that is not the solution, it could also be that you are reading with ReadProcessMemory the wrong amount of bytes, as size you cannot put things like "sizeof(wchar_t)", but the actual length of the string in bytes, which is "6 * sizeof ( wchar_t)" also counting the escape sequence '\ 0'.

(it would help in case you also post the code you wrote)
Back to top
View user's profile Send private message
Liger
Cheater
Reputation: 0

Joined: 26 Jan 2019
Posts: 35
Location: don't have

PostPosted: Sat Jul 24, 2021 9:43 pm    Post subject: Reply with quote

DanyDollaro wrote:
That's a UTF-16 string, you need to use the wide version of the output function you are using, assuming you are using cout, what you are doing could be:
Code:
std::cout << string;

To show that string you have to do:
Code:
std::wcout << string;


In case that is not the solution, it could also be that you are reading with ReadProcessMemory the wrong amount of bytes, as size you cannot put things like "sizeof(wchar_t)", but the actual length of the string in bytes, which is "6 * sizeof ( wchar_t)" also counting the escape sequence '\ 0'.

(it would help in case you also post the code you wrote)




I already use . ReadProcessMemory function .
and i'm not strong enough in C++ language
So can you give me an example.
Thank you for helping me.

_________________
(^_^)
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
DanyDollaro
Master Cheater
Reputation: 3

Joined: 01 Aug 2019
Posts: 328

PostPosted: Sun Jul 25, 2021 3:38 am    Post subject: Reply with quote

I used a 32-bit process as a target.

Code:
#include <iostream>
#include <Windows.h>

int main()
{
   DWORD pid = 1337; // Pid stand for Process ID

   HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, pid);

   wchar_t wstring[256] = { 0 };
   ReadProcessMemory(hProcess, (LPVOID)0x008D31C0, wstring, sizeof(wstring), NULL);

   std::wcout << wstring << std::endl;

   CloseHandle(hProcess);
   getchar();
   return 0;
}


And I am attaching the contents of the address 0x008D31C0 (the memory address on which the string is located).



Mem.png
 Description:
 Filesize:  3.88 KB
 Viewed:  420 Time(s)

Mem.png


Back to top
View user's profile Send private message
Liger
Cheater
Reputation: 0

Joined: 26 Jan 2019
Posts: 35
Location: don't have

PostPosted: Sun Jul 25, 2021 4:31 pm    Post subject: Reply with quote

DanyDollaro wrote:
I used a 32-bit process as a target.

Code:
#include <iostream>
#include <Windows.h>

int main()
{
   DWORD pid = 1337; // Pid stand for Process ID

   HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, pid);

   wchar_t wstring[256] = { 0 };
   ReadProcessMemory(hProcess, (LPVOID)0x008D31C0, wstring, sizeof(wstring), NULL);

   std::wcout << wstring << std::endl;

   CloseHandle(hProcess);
   getchar();
   return 0;
}


And I am attaching the contents of the address 0x008D31C0 (the memory address on which the string is located).



It really worked, thank you Smile Smile

_________________
(^_^)
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
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