jadeite/injector/src/dll.c

75 lines
1.9 KiB
C
Raw Normal View History

#include <stdio.h>
2023-06-25 09:32:19 +00:00
#include <inject.h>
2023-06-05 21:23:08 +00:00
2023-06-25 09:32:19 +00:00
#include <game_p.h>
2023-06-05 21:23:08 +00:00
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 = getenv(ENV_EXE_PATH);
2023-06-05 21:23:08 +00:00
// Get the path of the DLL to inject
char *injectDll = getenv(ENV_DLL_PATH);
2023-06-05 21:23:08 +00:00
// Get game commandline
char *cmdline = getenv(ENV_PROC_CMD);
2023-06-05 21:23:08 +00:00
// 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(
NULL,
cmdline,
2023-06-05 21:23:08 +00:00
NULL,
NULL,
FALSE,
CREATE_SUSPENDED,
NULL,
workdir,
&si,
&pi
)) {
char message[64];
sprintf(message, "Failed to start game process: %ld", GetLastError());
MessageBoxA(NULL, message, "Jadeite Launcher Payload", MB_OK | MB_ICONERROR);
2023-06-05 21:23:08 +00:00
exit(1);
}
// Inject
2023-06-25 09:32:19 +00:00
void *payloadStart = &_binary_game_p_o_p_game_p_bin_start;
size_t payloadSize = (size_t)&_binary_game_p_o_p_game_p_bin_size;
2023-06-05 21:23:08 +00:00
inject(pi.hProcess, payloadStart, payloadSize, injectDll);
2023-06-10 15:23:43 +00:00
// Optional: wait for user input before resuming (useful for debugging)
char *waitEnabled = getenv("WAIT_BEFORE_RESUME");
if (waitEnabled && strcmp(waitEnabled, "") != 0) {
char message[64];
sprintf(message, "PID: %ld. Press OK to continue", pi.dwProcessId);
MessageBoxA(NULL, message, "Jadeite Launcher Payload", MB_OK | MB_ICONINFORMATION);
}
2023-06-05 21:23:08 +00:00
// Resume the process
ResumeThread(pi.hThread);
// The launcher process should now hang untill the game terminates
WaitForSingleObject(pi.hProcess, INFINITE);
return TRUE;
}