Read/WriteProcessMemory for all addresses (C++, Like Cheat Engine)

Posts 1–7 of 7 · Page 1 of 1
Read/WriteProcessMemory for all addresses (C++, Like Cheat Engine)
So I've got an ongoing question that I just.cant seem to figure out!
How does Cheat Engine do it?!

I'm testing on a program to get all values of the int 3.
If I add a loop on increasing hex values, I can eventually find all 3's, but this can take AGES to fully get them all.
I'm not looking for pointers or static addresses, I want to actually find each 3 in the program.

How does Cheat Engine do this?!

For example:
I make a console program. "Type the int to find all addresses of those int's: "
You type "3" and it finds all addresses with the value of 3.

How can this be done?
Obviously I am not going to type in each address for each value manually.

Thanks on advance!
-Luna
Cheat engine narrows the search down aswell, allowing you choose specific value types, that may be part of it, if your just searching for three, well could be a string, bytes anything and wirhout prior knowlege of the type its gonna pull everything, have you also tryed narrowing the search range, choosing specific modules and such.
Let me explain a bit more on what I'm trying to accomplish.
I'm trying to get all addresses of a specific value.
Not only am I trying to get ints, But also strings (char).

I can do it this way: (Pseudo-Code)
Code:
int main() {
    while (true) {
        for (int addr= 0x00000000; addr < 0x7FFFFFFF; addr+=0x00000001) {
            char* value;
            if (ReadProcessMemory(hProc,addr,&value,sizeof(value),NULL) > 0) {
                 cout << value << "\n";
            }
        }
    }
}
This works, but can take as long as 30 minutes to go through!

Any help would really be appreciated.
Here is what I tried now:

Code:
DWORD WINAPI runThread(LPVOID args) {
	 int addr = 0;
	 char* val;
	 
	 HWND hProc = FindWindow(0,"Window");
	 if (hProc > 0) {
	 	while (true) {
	 		addr+=0x00000001;
	 		std::cout << addr << "\n";
	 		if (ReadProcessMemory(hProc,(void*)addr,&val,sizeof(val),NULL) > 0) {
	 		    std::cout << val << "\n";
                        }
	 	}
	}
}

int main() {
	 DWORD threadId;
	 int value = 10;
	 bool threadAll = false;
	 
	 while(true) {
	 	CreateThread( NULL, 0, runThread, NULL, 0, &threadId);
	 }
	 
	 return 0;
}
Output:
Code:
11
111111
The program does not crash at this point, but stops doing anything (Such as printing the address and value).

Any idea?

EDIT:
Added checks to see if the read was successful.
Now the addresses *Sort of?* print correctly.
I say sort of because they are negative, strangely.
Nothing in my code is a negative number so I don't see how this is possible.
Okay I've got it working, sort of.

Code:
DWORD WINAPI Thread(LPVOID lpParam) {
	int startaddr = (int)lpParam;
	int addr = 0x00000000;
	
	while (true) {
		double newdata = 12;
		DWORD newdatasize = sizeof(newdata);
		
		addr+=0x00000008;
		
		int finaddr = startaddr*0.125;
		if(ReadProcessMemory(hProcess, (LPVOID)(0x01000000*finaddr)+addr, &newdata, newdatasize, NULL)){
			if (newdata == 20) std::cout << "Found." << "\n"; //Looking for 20
		} else {
			//MessageBox(NULL, "Error cannot WriteProcessMemory!", "Error", MB_OK + MB_ICONERROR);
		}
	}
}

int main() {
	DWORD thread;
	int x = 0;
	
	while (true) {
		HWND hWnd = FindWindow(0, "Window");
		if(hWnd == 0){
			MessageBox(0, "Error cannot find window.", "Error", MB_OK|MB_ICONERROR);
		} else {
			DWORD proccess_ID;
			GetWindowThreadProcessId(hWnd, &proccess_ID);
			hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, proccess_ID);
			if(!hProcess){
				MessageBox(0, "Could not open the process!", "Error!", MB_OK|MB_ICONERROR);
			} else {
				if (x < 128) {
					CreateThread(NULL,0,Thread,(PVOID)x,0,&thread);
					x++;
				}
			}
		}
		CloseHandle(hProcess);
	}
		
	return 0;
}
I created a thread for each 0x01000000 (0x02000000, 0x03000000, ..., 0x0FFFFFFF).
This is 16 different 0x01's, so I take 16x8, then take all my addresses /8 giving a high range to search.

Anywho, the 20's are being found. But still slowely...
How would I go about getting everything right away?

Someone out there has got to know how, and I'm not giving this thing up until I do as well.
So please help? :P
I guess if anyone tries to answer this post in the far future, or if anyone does ever.
I should announce that I got it working along with searching for int's (2,4,6bytes) , doubles, strings, and finding all processes open (with their PIDs).

Thank anyways, MPGH.
best part about your code is the CloseHandle(hProcess); I hardly see that anymore Gratz btw
Posts 1–7 of 7 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Talk with us