Solved readprocessmemory and multi level pointers

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

11100001111011100111

Newbie
Full Member
Mar 5, 2017
28
72
1
C++:
#include <iostream>
#include <Windows.h>

#define cout std::cout
#define endl std::endl
#define QWORD uint64_t


void findWindowError() {
	cout << "Did not find window" << endl;
	Sleep(2500);
	system("CLS");
}

int main() {
	
	HWND hwnd = FindWindowA(NULL, "MK10");

	if (hwnd == NULL) {
		findWindowError();
		main();
	}
	else {
		//QWORD baseAddress = 0x7FF731AC0000 + 0x32FF038;
		QWORD baseAddress = 0x7FF734DBF038;
		QWORD baseOffsets[] = { 0xA20, 0x20, 0x5EC };
		QWORD anotherBuffer;

		QWORD healthAddress = 0x16915851118;

		//if i want to read the value in a certain data type, make the specifier data type here for mkxBase
		int mkxBase;
		float mkxBase2;
		float mkxBaseHealth;

		DWORD procID;
		GetWindowThreadProcessId(hwnd, &procID);
		HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, 0, procID);

		//So readprocessmemory when 'cout' it reads the 'value' of the targetd address
		ReadProcessMemory(handle, (LPCVOID)baseAddress, &mkxBase, sizeof(mkxBase), 0);
		cout << "mkxBase = " << &mkxBase << "\n";
		anotherBuffer = mkxBase + baseOffsets[0];
		cout << "anotherBuffer = " << anotherBuffer << "\n";

		ReadProcessMemory(handle, (LPCVOID)anotherBuffer, &mkxBase, sizeof(mkxBase), 0);
		anotherBuffer = mkxBase + baseOffsets[1];
		cout << "anotherBuffer = " << anotherBuffer << "\n";

		/*
		ReadProcessMemory(handle, (LPCVOID)mkxBase, &mkxBase, sizeof(mkxBase), 0);
		cout << "mkxBase = " << mkxBase << "\n";
		mkxBase += baseOffsets[2];

		mkxBase2 = mkxBase;
		cout << "mkxBase = " << mkxBase2 << "\n";
		*/

		//ReadProcessMemory(handle, (LPCVOID)healthAddress, &mkxBaseHealth, sizeof(mkxBaseHealth), 0);
		//cout << "mkxBaseHealth = " << mkxBaseHealth << "\n";

		Sleep(10000000);
	}

}
basically i want to read from the base pointer, which is stored in baseAddress, all the way down to the last offset, stored in baseOffsets[], which is 0x5EC. i tried multiple times and it doesn't go through, am i missing something?! i feel like my head is bout to explode right now and so frustrated. i did this a few months back when i was doing this on Assault Cube, my harddrive fked up, got a new one, can't reference that file anymore, google and a few tinkering, STILL don't get how i'm not reading the right address... i'm at a loss.
 
Last edited by a moderator:

Traxin

Escobar Tier VIP
Dank Tier Donator
Aug 3, 2015
1,041
25,378
154
C++:
cout << "mkxBase = " << &mkxBase << "\n";
You're printing the address of your local variable mkxBase, not the actual value of it.

But the real issue is you're trying to read a 64-bit wide address into a 32-bit variable.
Causing your addresses to get truncated, also output your addresses in hex.
If your tools display pointers in hex it makes no sense to create another tool that displays the same information in decimal. Just makes it harder to analyze.

C++:
ReadProcessMemory(handle, (LPCVOID)baseAddress, &mkxBase, sizeof(mkxBase), 0);
The issue with this code is that you're reading a pointer. Your target is 64bits, therefore it's memory addresses are 64 bits wide. If you're going to read a "pointer" then you need to store the result into a variable that's at least 64 bits (or 8 bytes) wide. An int is 32bits (or 4 bytes) wide so it's not going to work.

Use an appropriate data type such as QWORD or uintptr_t (preferred since it's defined according to build platform).

Best Answer Edit: all your questions are answered by this tutorial:
 
Last edited by a moderator:

11100001111011100111

Newbie
Full Member
Mar 5, 2017
28
72
1
C++:
cout << "mkxBase = " << &mkxBase << "\n";
You're printing the address of your local variable mkxBase, not the actual value of it.

But the real issue is you're trying to read a 64-bit wide address into a 32-bit variable.
Causing your addresses to get truncated, also output your addresses in hex.
If your tools display pointers in hex it makes no sense to create another tool that displays the same information in decimal. Just makes it harder to analyze.
yea i put the '&' there as my last gestimation before i gave up xD, i knew it has something to do with it being 64bit storage compared to a 32bit but don't know where the issue lies in my code, so i was checking the address before i pasted it here lol. as for the hex thing, lol it doesn't really confuse me, if i know the output is the same as the tool i'm using i'm going to get the same answer in hex, viceversa.

C++:
ReadProcessMemory(handle, (LPCVOID)baseAddress, &mkxBase, sizeof(mkxBase), 0);
The issue with this code is that you're reading a pointer. Your target is 64bits, therefore it's memory addresses are 64 bits wide. If you're going to read a "pointer" then you need to store the result into a variable that's at least 64 bits (or 8 bytes) wide. An int is 32bits (or 4 bytes) wide so it's not going to work.

Use an appropriate data type such as QWORD or uintptr_t (preferred since it's defined according to build platform).

C++:
ReadProcessMemory(handle, (LPCVOID)baseAddress, &mkxBase, sizeof(mkxBase), 0);
		cout << "mkxBase = " << std::hex << mkxBase << "\n";
		anotherBuffer = mkxBase + baseOffsets[0];
		cout << "anotherBuffer = " << anotherBuffer << "\n";
i put everything into 'uintptr_t', still not giving me the result i want. i'm getting the address of the original base right, but when i add in the very first offset (0xA20), it gives me something else different from the address i have on my table displaying a it's correct number. as for the array variable 'baseOffsets' should i also put the identifier into a 'uintptr_t' or a 'int'? cuz i turned everything 'uintptr_t'


EDIT: OOOHHH i get it, just solved it..... i think, still need some input but. i just checked the output (cout) of the variable 'anotherBuffer' and it showed the 'ADDRESS' as the value lol this whole time i was looking if it matches the value that the table show. so it is working, but how do i show the value of the address that was stored as a value inside 'anotherBuffer' ? inception 2.0....
 
Last edited:

idx[0]

Jr.Coder
Full Member
Nobleman
Mar 24, 2016
55
523
1
Hi,
If you mean that the variable "anotherBuffer" stores the address of the target value then you can ReadProcessMemory "anotherBuffer" like so:
C++:
// Change the type of the variable below to your selected type
uint32_t target_value_to_read = 0;

std::cout << "ReadProcessMemory: " <<
   (ReadProcessMemory(handle, (LPCVOID)anotherBuffer, &target_value_to_read, 4, 0) ? "Successful" : "Unsuccessful");

cout << "\nThe value at address 0x" << std::hex << anotherBuffer << " is: " << std::dec <<  target_value_to_read << "\n";
I can't double check this code so I'm sorry if there's an error.
 

11100001111011100111

Newbie
Full Member
Mar 5, 2017
28
72
1
idx[0];49730 said:
Hi,
If you mean that the variable "anotherBuffer" stores the address of the target value then you can ReadProcessMemory "anotherBuffer" like so:
C++:
// Change the type of the variable below to your selected type
uint32_t target_value_to_read = 0;

std::cout << "ReadProcessMemory: " <<
   (ReadProcessMemory(handle, (LPCVOID)anotherBuffer, &target_value_to_read, 4, 0) ? "Successful" : "Unsuccessful");

cout << "\nThe value at address 0x" << std::hex << anotherBuffer << " is: " << std::dec <<  target_value_to_read << "\n";
I can't double check this code so I'm sorry if there's an error.
hey bud! code works like a charm! you're a savior! question, what is 'std::dec' used for in this situation? laymens terms please :)

EDIT: oh it meant to convert it into a decimal. anyways, thanx! this was a great learning process, didn't know 64bit was a tad bit different than my regular 32bit procedure
 
Last edited:
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods