[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;
}