Iterating through memory addresses

I've lately gotten my hands on the (in)famous Cheat Engine[1] and found that it was really easy to simulate it in C++, there's just one thing that keeps to disturb me; how to "iterate" through memory addresses (using a void pointer, as types may differ per address)?



Cheat Engine[1]: Iterates through a list of addresses of unknown types, in which the list length is determined at run-time. It adds elements to this list whenever the current pointer (dereferenced) equals the value of the input and is of the specified type.
You can't do anything with a void pointer but cast to another type.

So if you want to treat the memory as a block of ints, you need to cast to int*:

1
2
3
4
5
6
7
8
void* v = /*some address*/;

int sum = 0;

int* ptr = reinterpret_cast<int*>(v);

for(int i = 0; i < some_value; ++i)
  sum += ptr[i];
The whole point is that I get access to addresses which are determined at run-time, and then iterate till an end value is reached (in normal cases 0xFFFFFF). How to do this?

Note, the addresses stated here are from outside the program itself.
Last edited on
If you want to iterate through memory one byte at a time then you need to cast it to a char*. If you want to iterate through however many bytes make up an int each iteration then you need to cast the memory to an int*.
http://cplusplus.com/forum/windows/19725/

Just don't laugh at the "problem" I had...
Topic archived. No new replies allowed.