#include #include static inline void read_env(const char *env, char *dest, size_t size) { GetEnvironmentVariableA(env, dest, size); SetEnvironmentVariableA(env, ""); } BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved) { // Only listen for attach if (reason != DLL_PROCESS_ATTACH) { return TRUE; } // Get target EXE path char targetExe[MAX_PATH]; read_env(ENV_EXE_PATH, targetExe, sizeof(targetExe)); // Get the path of the DLL to inject char injectDll[MAX_PATH]; read_env(ENV_DLL_PATH, injectDll, sizeof(injectDll)); // Compute the working directory path char workdir[MAX_PATH]; strcpy(workdir, targetExe); *(strrchr(workdir, '\\')) = '\0'; // Start the game STARTUPINFO si; ZeroMemory(&si, sizeof(si)); PROCESS_INFORMATION pi; si.cb = sizeof(si); ZeroMemory(&pi, sizeof(pi)); if (!CreateProcessA( targetExe, NULL, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, workdir, &si, &pi )) { exit(1); } // Inject void *payloadStart = &_binary_lpayload_o_p_payload_bin_start; size_t payloadSize = (size_t)&_binary_lpayload_o_p_payload_bin_size; inject(pi.hProcess, payloadStart, payloadSize, injectDll); // Resume the process ResumeThread(pi.hThread); // The launcher process should now hang untill the game terminates WaitForSingleObject(pi.hProcess, INFINITE); return TRUE; }