❓ C++ Address read from CoD Ghosts problem

Posts 1–5 of 5 · Page 1 of 1
❓ C++ Address read from CoD Ghosts problem
Hello,
I am quite new to C++ programs, and I have a problem. I already have programmed some programs which worked, but I am stuck with CoD Ghosts.
I want to read the Squad Points from the game, the address is the right one (tested it several times with Cheat Engine), but my value always returns 0 instead of the value which should return (e.g. 30). I first tried to declare the variables "SquadPointsAddr" and "SquadPointsDec" with just int, but Visual Basic said I should use __int64, which didn't work too.
Please ask when you need more information. I also ran the project in 32 and 64 bit, but that didn't solve the problem too. Please help wherever you can


CODE:

Code:
#include <iostream>
#include <iomanip>
#include <Windows.h>
#include <string>
#include <stdint.h>
using namespace std;

int main()
{
	HWND hwnd = FindWindow(0, L"Call of Duty® Ghosts Multiplayer"); 
	DWORD ProcessId;
	ProcessId = GetProcessId(hwnd);
	GetWindowThreadProcessId(hwnd, &ProcessId);
	HANDLE hProcess = OpenProcess(PROCESS_VM_READ, FALSE, ProcessId);

	if (hwnd){
		cout << "WINDOW FOUND" << endl;
	}
	else {
		cout << "WINDOW NOT FOUND" << endl;
		cout << hwnd << endl;
	}
	
	__int64 SquadPointsAddr = 0x1444C2E40;
	__int64 SquadPointsDec;
	cout << hex << SquadPointsAddr << ", " << sizeof(SquadPointsAddr) << endl;
	cout << "-----------------------------------------------------" << "\n\n\n\n";

	if (!hProcess)
	{
			Beep(100, 100);
	}
	else {
		cout << "-----------------------------------------" << endl;

		if (ReadProcessMemory(hProcess, (unsigned __int64 *)SquadPointsAddr, &SquadPointsDec, sizeof(SquadPointsAddr), NULL)){
			cout << dec << "ADDRESS:    " << SquadPointsDec << endl;
			cout << endl;
		}
	}
	CloseHandle(hProcess);
	cout << endl;
	system("pause");
}
if (ReadProcessMemory(hProcess, (unsigned __int64 *)SquadPointsAddr, &SquadPointsDec, sizeof(SquadPointsAddr), NULL))
ReadProcessMemory(handle, source_addr, dest_addr, size_of_dest, bytes_read)

size_of_dest = sizeof(SquadPointsDec), not sizeOf(SquadPointsAddr) -- but in this example they're both 64 bits.

Is squad points actually stored as Int64, or something smaller?



Also, GetProcessId()
GetProcessId function (Windows)

It expects a process HANDLE, not a window HANDLE. Probably a different windows function for you to use...

guick google: https://www.google.com/search?q=GetP...+window+handle

result: Get process id from window handle

GetWindowThreadProcessId(hwnd, out processId);
edit: looks like you call the correct one right after ..I think the first call to GetProcessId() is pointless, but the next line should set it correctly. ?
ProcessId = GetProcessId(hwnd);
GetWindowThreadProcessId(hwnd, &ProcessId);
Which part is giving you trouble? What works / doesn't work?

1. is the window found?
2. is the process ID found?
3. does OpenProcess() return a valid handle?

I re-structured the code a little bit (the IF statements). Your way kind-of worked, but for example you use 'hwnd' before making sure it's valid. I changed the cout's because it's helpful to know which functions/values you're getting messages for.

 
codefromimage

Code:
#include <Windows.h>
#include <iostream>
using namespace std;

int main()
{
	HWND hwnd;			//window handle returned by FindWindow()
	DWORD ProcessId;	//processID returned by GetWindowThreadProcessId()
	HANDLE hProcess;	//handle returned from OpenProcess()

	hwnd = FindWindow(0, "Calculator"); 
	if (hwnd){
		cout << "WINDOW FOUND: " << hwnd << endl;
		GetWindowThreadProcessId(hwnd, &ProcessId);
		cout << "ProcessId: " << ProcessId << endl;
		HANDLE hProcess = OpenProcess(PROCESS_VM_READ, FALSE, ProcessId);
		if (hProcess)
		{
		cout << "OpenProcess() Success : Handle returned: " << hProcess << endl;
		/*Do Reading and whatnot here...*/
		CloseHandle(hProcess);
		}
		else
		{
		cout <<"OpenProcess() FAILED : Handle returned: " << hProcess << endl;
		}
	}
	else {
		cout << "WINDOW NOT FOUND." << endl << "Window Handle (invalid): " << hwnd << endl;
	}
	

	cout << "\n\nLeaving program...\n\n" << endl;
	system("pause");
	return 0;
}
Once this part is working 100%, move on to calling ReadProcessMemory().
Just use Dll Injection:

Code:
#include <windows.h>

#define Addy1 0x1444C2E40


BOOL WINAPI DllMain(HMODULE hDll, DWORD reason, LPVOID reserved)
{
      if(reason == 1)
      {
             DWORD dwAddy1 = *(DWORD*)(Addy1);
             *(DWORD*)(dwAddy1)=100000;
      }
      return TRUE;
}
Quote Originally Posted by _PuRe.LucK* View Post
Just use Dll Injection:

Code:
#include <windows.h>

#define Addy1 0x1444C2E40


BOOL WINAPI DllMain(HMODULE hDll, DWORD reason, LPVOID reserved)
{
      if(reason == 1)
      {
             DWORD dwAddy1 = *(DWORD*)(Addy1);
             *(DWORD*)(dwAddy1)=100000;
      }
      return TRUE;
}
#define Addy1 0x1444C2E40
14 44 C2 E4 0

9 digits(ie. too big for DWORD) - typo, or ?
Quote Originally Posted by abuckau907 View Post
#define Addy1 0x1444C2E40
14 44 C2 E4 0

9 digits(ie. too big for DWORD) - typo, or ?
No matters... It's only an example
Posts 1–5 of 5 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

Talk with us