QuestionMemory Hook to Client.dll C++

Posts 1–2 of 2 · Page 1 of 1
Memory Hook to Client.dll C++
I am currently working on a cheat for myself but I am having some issues attaching to the process in memory to grab the client.dll module. Any help would be greatly appreciated.

Code:
      HANDLE hProcess;
      PROCESSENTRY32 ProcEntry;
      DWORD PID;
      HANDLE hModule;
      MODULEENTRY32 mEntry;
	
	void AttachProcess(char* procName)
	{
		ProcEntry.dwSize = sizeof(ProcEntry);
		hProcess = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
		while (Process32Next(hProcess, &ProcEntry))
		{
			if (!strcmp((char*)ProcEntry.szExeFile, procName))
			{
				PID = ProcEntry.th32ProcessID;
				CloseHandle(hProcess);
				hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, PID);
				return;
			}
		}

		cout << "Error: Couldn't find process! \n";
		CloseHandle(hProcess);
	}

	DWORD GetModule(LPSTR ModuleName)
	{
		hModule = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, PID);
		mEntry.dwSize = sizeof(mEntry);

		while (Module32Next(hModule, &mEntry))
		{

			if (!strcmp((char*)mEntry.szModule, ModuleName))
			{
				return (DWORD)mEntry.modBaseAddr;
				CloseHandle(hModule);
			}

		}
		cout << "Error: No module was found! \n";
		CloseHandle(hModule);
	}
[C++] Find Module's Address (.dll)
I used this for an old osu! cheat of mine, should work just fine

Call it like this (the called parameters should match your variable names):
Code:
DWORD ModuleAddress = FindBaseAddress(hProcess, PID, "client.dll")
I don't know why hModuleSnap is a parameter but this worked for me so I'm not gonna change it...
Good luck!

Edit:
Something I've noticed, you do
Code:
return (DWORD)mEntry.modBaseAddr;
CloseHandle(hModule); // <- never actually executed; You return before

Code:
DWORD FindBaseAddress(HANDLE hModuleSnap, DWORD dwPID, string Modulename)
{
	MODULEENTRY32 me32;
	hModuleSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwPID);
	if (hModuleSnap == INVALID_HANDLE_VALUE)
	{
		system("cls");
		cout << "INVALID HANDLE VALUE!";
		system("pause");
		return NULL;
	}
	
	me32.dwSize = sizeof(MODULEENTRY32);
	
	if (!Module32First(hModuleSnap, &me32))
	{
		system("cls");
		cout << "NO FIRST MODULE!";
		system("pause");
		CloseHandle(hModuleSnap);
		return NULL;
	}
	
	// No errors
	DWORD ModuleAddress = NULL;
	
	do
	{
		if (me32.szModule == Modulename)
		{
			ModuleAddress = (DWORD)me32.modBaseAddr;
			break;
		}
	} while (Module32Next(hModuleSnap, &me32));
	CloseHandle(hModuleSnap);
	return ModuleAddress;
}
Posts 1–2 of 2 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

Talk with us