Basic C++ || Questions

Hey guys new to C++ and learning the basics but got questions that I wanna know.

Example purposes:

.Exe Base Address = 0x000000
.Exe Base Offset = 0x1111111
Pointer Address of above = 0x222222

When I do readprocessmemory(ExeBaseAddress + ExeBaseOffset) &result, sizeofresult....

Why doesn’t the &result show the Pointer Address? Instead it shows something else, what do you call this being shown? Is it just showing the address where the result is being stored?
And how do you make it show the Pointer Address 0x2222222? PS using cout to get the readings.



Thanks hope can help!
Your question makes no sense.

1. What's a "base offset"? A "base address" is a main address from which other addresses are computed, and an "offset" is a term that is added to a base address to obtain an address.

At this point your question is already meaningless because I don't what you're talking about, or how you obtained the values you're talking about. For all I know if you read the memory at ExeBaseAddress + ExeBaseOffset you could very well get unicorns and rainbows.
But let's keep going.

2. "Pointer Address of above"? Of what? Of the number 0x1111111? It's a number, a mathematical entity. It doesn't have an address. Did you mean that the value 0x222222 can be found at some address?
3.
Why doesn’t the &result show the Pointer Address?
I don't know. I don't know how you obtained the values you're talking about or even what they are, let alone if they're correct and whether they should give you result you were expecting.
4.
Instead it shows something else, what do you call this being shown?
I'll go with Mr. Sparkles. That seems as good as anything else, given how much information I have available.

This is the only question I can actually answer:
Is it just showing the address where the result is being stored?
Provided the rest of your code is "reasonable", no. Result should contain the actual memory contents on the remote process found at the address provided.
So, if process A.exe contains 42 at memory address 0xDEADBEEF and process B.exe reads process A.exe's memory at address 0xDEADBEEF, it will get the value 42, not another address in B.exe's address space.
The above was just an example, here is example of real code. I'm new so I won't know the exact names of everything so please try bare with me.

Exe Base Address = 0x400000
Exe Base Offset = 0x109b74
Exe Base Address + Exe Base Offset = 0x0509b74
Local Player Base Address Pointer = 0x0509b74

int = Result;

ReadProcessMemory(hProcess, (LPCVOID*)(Exe Base Address + Exe Base Offset), &Result, sizeof(Result), NULL);
cout << Result << endl;


Now, when I do the code above how come the Result does not show code: 0x0509b74? It shows something else like 00002334322. I want to know when I do &Result what does it show? Is it showing the memory storage location? And how would I make it show 0x0509b74?

Basically because I thought that the ExeBaseAddress+ExeBaseOffset equals 0x0509b74 and where to store it would be at &Result. Or is &Result just the address of where it is going to be stored? That is what I'm confused with.....

Last edited on
ReadProcessMemory is for reading data from memory. Whatever you get back from that function isn't going to be a memory address. It's going to be some data read from memory.

0x0509b74 is the memory address you're telling the function to read from. What you get back is the data stored at that location.
It is not a good idea to play with pointers and addresses, if you are new to the language, you need to learn the basics first, but If you are doing c++ for game hacking, what you wrote is meaningless. (That's not basic c++ thought)
Last edited on
Now, when I do the code above how come the Result does not show code: 0x0509b74?
It would be a pretty useless function if you always got back from it exactly what you put in, don't you think?

Basically because I thought that the ExeBaseAddress+ExeBaseOffset equals 0x0509b74 and where to store it would be at &Result. Or is &Result just the address of where it is going to be stored? That is what I'm confused with.
Suppose you and I each have 10 bags numbered 0 to 9. we can put anything a bag, but it can contain at most one thing. And of course, while your bag 4 may contain a brick, mine could contain nothing, or a fish, or whatever.

When you do ReadProcessMemory(), what you're telling me is "show me what you've put in bag x, so I can put it in one of my bags".
So, an exchange could go like this:
-Show me what you've put in bag 0x0509b74, so I can put it in my bag &Result.
-I don't have a bag numbered 0x0509b74. (ReadProcessMemory() may fail with an error, which you've failed to check).
-I'll put some garbage in my &Result bag.

A different exchange could go like this:
-Show me what you've put in bag 0x0509b74, so I can put it in my bag &Result.
-My bag contains a dog.
-I'll put a dog in my &Result bag. Now Result == dog.

Note that &Result is a number that identifies a bag, while Result are the contents of that bag. In this case, a dog.
ReadProcessMemory() needs somewhere to store the data it reads, you want it stored in Result.

you cant just call ReadProcessMemory(...,Result,...) because when the call goes through it will try to pass the value stored at Result (just like any other parameter) when the function really wants the address of result so it can save data there, so pass the address of Result using &Result.

the function receives the address and duly saves its data there. Which you can then access using Result as a normal variable.

you could have also expressed
1
2
 int *pResult = new int;
ReadProcessMemory(...,pResult,...)


as it stands in your code while the function is executing there are 2 variables referring to the same memory location, one is in your scope "Result" and the other is the pointer inside ReadProcessMemory(),

1
2
3
4
int result;
int *pResult = &result;
result = 5;
cout << *pResult; // displays "5" 




I didnt fully follow the question you are trying to ask, but code is integers.
if you are trying to look at what the cpu is executing it is going to look like a pile of integers, in other words. Its not going to look like c++ or even assembly.






Topic archived. No new replies allowed.