jadeite/injector/src/injector.c

120 lines
3.0 KiB
C
Raw Normal View History

2023-06-05 21:23:08 +00:00
#include <stdio.h>
#include <injshared.h>
#include <ipayload.h>
const char LAUNCHER_INJECT_DLL[] = "launcher_payload.dll";
const char GAME_INJECT_DLL[] = "game_payload.dll";
#define SHIFT(argc, argv) argc--, argv++
2023-06-05 21:23:08 +00:00
int main(int argc, char **argv) {
// Read arguments
char *gamePath = NULL;
char *launcherPath = NULL;
// Skip executable
SHIFT(argc, argv);
2023-06-05 21:23:08 +00:00
switch (argc) {
case 0:
2023-06-05 21:23:08 +00:00
printf("Usage: wine jadeite.exe [game path] <launcher path>\n");
return 0;
case 1:
gamePath = argv[0];
SHIFT(argc, argv);
launcherPath = "--";
2023-06-05 21:23:08 +00:00
break;
default:
gamePath = argv[0];
SHIFT(argc, argv);
launcherPath = argv[0];
SHIFT(argc, argv);
break;
2023-06-05 21:23:08 +00:00
}
// Default launcher path
if (strcmp(launcherPath, "--") == 0) {
printf("No launcher process specified! Using explorer.exe\n");
launcherPath = "C:\\Windows\\explorer.exe";
}
// cd into the injector directory
char injectorPath[MAX_PATH];
GetModuleFileNameA(GetModuleHandleA(NULL), injectorPath, sizeof(injectorPath));
*(strrchr(injectorPath, '\\')) = '\0';
SetCurrentDirectoryA(injectorPath);
2023-06-05 21:23:08 +00:00
// Compute absolute paths
char gameExePath[MAX_PATH];
GetFullPathNameA(gamePath, sizeof(gameExePath), gameExePath, NULL);
char gamePayloadPath[MAX_PATH];
GetFullPathNameA(GAME_INJECT_DLL, sizeof(gamePayloadPath), gamePayloadPath, NULL);
char launcherPayloadPath[MAX_PATH];
GetFullPathNameA(LAUNCHER_INJECT_DLL, sizeof(launcherPayloadPath), launcherPayloadPath, NULL);
// Construct commandline for the game process
char cmdline[8192];
sprintf(cmdline, "\"%s\"", gameExePath);
while (argc) {
char arg[8192];
sprintf(arg, " \"%s\"", argv[0]);
strcat(cmdline, arg);
SHIFT(argc, argv);
}
2023-06-05 21:23:08 +00:00
// Set envvars
2023-06-06 17:23:15 +00:00
SetEnvironmentVariableA(ENV_EXE_PATH, gameExePath);
SetEnvironmentVariableA(ENV_DLL_PATH, gamePayloadPath);
SetEnvironmentVariableA(ENV_PROC_CMD, cmdline);
2023-06-05 21:23:08 +00:00
// Start the launcher
printf("Starting '%s' via '%s'\n", gameExePath, launcherPath);
2023-06-05 21:23:08 +00:00
STARTUPINFO si;
ZeroMemory(&si, sizeof(si));
PROCESS_INFORMATION pi;
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
if (!CreateProcessA(
launcherPath,
NULL,
NULL,
NULL,
FALSE,
CREATE_SUSPENDED,
NULL,
NULL,
&si,
&pi
)) {
fprintf(stderr, "Could not start process! (%ld)\n", GetLastError());
exit(1);
}
printf("Started launcher process (%ld)\n", pi.dwProcessId);
// Inject
void *payloadStart = &_binary_ipayload_o_p_payload_bin_start;
size_t payloadSize = (size_t)&_binary_ipayload_o_p_payload_bin_size; // yes this is valid
inject(pi.hProcess, payloadStart, payloadSize, launcherPayloadPath);
// Resume the process
ResumeThread(pi.hThread);
return 0;
}