I have a process that I want to read memory from and it contains a string. When I get the string from it and build the string from the char array there are alot of random characters surrounding the string.
uintptr_t stringAdress = 0x0; //String Adress
char strRead[32]; //String array
cout << "Enter String Adress: ";
cin >> hex >> stringAdress;
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pId); //Hook onto the process
if (hProcess == NULL) {
cout << "Open Process Error: " << dec << GetLastError() << endl;
system("pause");
return EXIT_FAILURE;
}
//Read String Memory
BOOL readMemory = ReadProcessMemory(hProcess, LPCVOID(stringAdress), &strRead, 32, NULL);
if (readMemory == FALSE) {
cout << "Read Process Memory Error: " << dec << DdeGetLastError << endl;
system("pause");
}
//Build string from chars
for (size_t i = 0; i < 32; i++)
{
cout << strRead[i] << endl;
strDone += strRead[i];
}
//Close the handle
BOOL closeHandle = CloseHandle(hProcess);
cout << "varString = " << dec << strDone << endl;
Here is the output:
varString = h░ Default String ╠ ╠╠╠╠
I have no idea why its doing this, any help would be appreciated.