I wanted to talk a bit about @Adam Rosenfield's answer. I will use the League of Legends as an example here.
To open a process (getting a handle), we need a PID (process identifier). We can do this with a window handle (HWND), because the window name is usually known
//You will need to change this the name of the window of the foreign process HWND WindowHandle = FindWindow(nullptr, L"League of Legends (TM) Client"); DWORD PID; GetWindowThreadProcessId(WindowHandle, &PID); PVOID hProcess = OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, 0, PID);
Now that we can get the process descriptor, continue
HMODULE Module = GetModule(); DWORD BaseAddress = (DWORD)Module;
Getmodule function
HMODULE GetModule() { HMODULE hMods[1024]; HANDLE pHandle = GetHandle(); DWORD cbNeeded; unsigned int i; if (EnumProcessModules(pHandle, hMods, sizeof(hMods), &cbNeeded)) { for (i = 0; i < (cbNeeded / sizeof(HMODULE)); i++) { TCHAR szModName[MAX_PATH]; if (GetModuleFileNameEx(pHandle, hMods[i], szModName, sizeof(szModName) / sizeof(TCHAR))) { wstring wstrModName = szModName; //you will need to change this to the name of the exe of the foreign process wstring wstrModContain = L"League of Legends.exe"; if (wstrModName.find(wstrModContain) != string::npos) { CloseHandle(pHandle); return hMods[i]; } } } } return nullptr; }
as for me personally I like to write two separate functions for receiving a descriptor and one for receiving a module.
There we go, we have successfully received the base address of the foreign process.
user5166622
source share