Module Process::inject(const Library& lib) { if (isInjected(lib)) BOOST_THROW_EXCEPTION(ex_injection() << e_text("library already in process") << e_library(lib.path()) << e_process(*this)); // copy the pathname to the remote process SIZE_T libPathLen = (lib.path().wstring().size() + 1) * sizeof(wchar_t); MemoryArea libFileRemote = alloc(libPathLen, true, MEM_COMMIT, PAGE_READWRITE); libFileRemote.write((void*)(lib.path().c_str())); PTHREAD_START_ROUTINE loadLibraryW = (PTHREAD_START_ROUTINE)Module::kernel32().getProcAddress("LoadLibraryW"); /*DWORD exitCode =*/ runInHiddenThread(loadLibraryW, libFileRemote.address()); return isInjected(lib); }
Module Process::getInjected(HMODULE hmodule) { if (Module module = isInjected(hmodule)) return module; else BOOST_THROW_EXCEPTION(ex_injection() << e_text("failed to find module handle") << e_process(*this)); }
Module Process::getInjected(const Library& lib) { if (Module module = isInjected(lib)) return module; else BOOST_THROW_EXCEPTION(ex_injection() << e_text("failed to find injected library") << e_process(*this) << e_library(lib.path())); }
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) { switch (lParam) { case INJECT_DLL:{ if (getwindowtext(hwnd) == "Diablo II") { string path = getexepath(hwnd); if (path == "") MessageBox(hwnd, str_to_wstr("Could not get Diablo II exe path.\n" + error_code_to_text(GetLastError())).c_str(), L"ERROR", MB_OK); string exename = path.substr(path.rfind("\\") + 1, path.size() - path.rfind("\\")); if (exename == "Game.exe") { if (!isInjected(hwnd)) { if (!InjectDll(hwnd)) { MessageBox(hwnd, L"Injection failed", L"ERROR", MB_OK); break; } } } } break; } } return TRUE; }