From 0b0216e41e204559ba0e058b33e2fecafb8e5b79 Mon Sep 17 00:00:00 2001 From: mkrsym1 Date: Sun, 11 Jun 2023 18:04:24 +0300 Subject: [PATCH] Pass commandline arguments to the game process Closes #4 --- README.md | 2 ++ injector/include/injshared.h | 7 ++-- injector/launcher_payload/src/dll.c | 5 ++- injector/src/injector.c | 51 ++++++++++++++++++++++------- 4 files changed, 50 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 96dab1a..c40966e 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,8 @@ Manual usage instructions: This tool is capable of starting the games from a different process. This may be useful for spoofing the parent process (SR is known to report it). Use `wine jadeite.exe 'Z:\wine\path\to\game.exe' 'Z:\wine\path\to\launcher.exe'`. `explorer.exe` is used as the default. +To pass commandline arguments to the game, append them after the launcher path: `wine jadeite.exe 'Z:\wine\path\to\game.exe' 'Z:\wine\path\to\launcher.exe' -arg1 -arg2 -arg3`. To use the default launcher process, use `--`: `wine jadeite.exe 'Z:\wine\path\to\game.exe' -- -arg1 -arg2 -arg3`. + ### Configuration These environment variables can be used to configure the behaviour of the tool. diff --git a/injector/include/injshared.h b/injector/include/injshared.h index 932af1f..0e87352 100644 --- a/injector/include/injshared.h +++ b/injector/include/injshared.h @@ -1,7 +1,10 @@ #include -const char ENV_EXE_PATH[] = "JADEITE_TARGET_EXE_PATH"; -const char ENV_DLL_PATH[] = "JADEITE_INJECT_DLL_PATH"; +#define EPFX "__JADEITE_" + +const char ENV_EXE_PATH[] = EPFX"TARGET_EXE_PATH"; +const char ENV_DLL_PATH[] = EPFX"INJECT_DLL_PATH"; +const char ENV_PROC_CMD[] = EPFX"PROCESS_COMMAND"; static inline void write_protected_process_memory(HANDLE process, void *address, const void *buf, size_t size) { DWORD oldProtect; diff --git a/injector/launcher_payload/src/dll.c b/injector/launcher_payload/src/dll.c index bcd9ce3..7475ecf 100644 --- a/injector/launcher_payload/src/dll.c +++ b/injector/launcher_payload/src/dll.c @@ -16,6 +16,9 @@ BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved) { // Get the path of the DLL to inject char *injectDll = getenv(ENV_DLL_PATH); + // Get game commandline + char *cmdline = getenv(ENV_PROC_CMD); + // Compute the working directory path char workdir[MAX_PATH]; strcpy(workdir, targetExe); @@ -30,8 +33,8 @@ BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved) { ZeroMemory(&pi, sizeof(pi)); if (!CreateProcessA( - targetExe, NULL, + cmdline, NULL, NULL, FALSE, diff --git a/injector/src/injector.c b/injector/src/injector.c index 9885a5a..22be744 100644 --- a/injector/src/injector.c +++ b/injector/src/injector.c @@ -7,29 +7,43 @@ const char LAUNCHER_INJECT_DLL[] = "launcher_payload.dll"; const char GAME_INJECT_DLL[] = "game_payload.dll"; +#define SHIFT(argc, argv) argc--, argv++ + int main(int argc, char **argv) { // Read arguments char *gamePath = NULL; char *launcherPath = NULL; + // Skip executable + SHIFT(argc, argv); + switch (argc) { - case 1: + case 0: printf("Usage: wine jadeite.exe [game path] \n"); return 0; - case 2: - printf("No launcher process specified! Using explorer.exe\n"); - gamePath = argv[1]; - launcherPath = "C:\\Windows\\explorer.exe"; - break; - case 3: - gamePath = argv[1]; - launcherPath = argv[2]; + case 1: + gamePath = argv[0]; + SHIFT(argc, argv); + + launcherPath = "--"; + break; default: - fprintf(stderr, "Too many arguments! (%d)\n", argc); - return 1; + gamePath = argv[0]; + SHIFT(argc, argv); + + launcherPath = argv[0]; + SHIFT(argc, argv); + + break; } + // 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)); @@ -48,13 +62,26 @@ int main(int argc, char **argv) { char launcherPayloadPath[MAX_PATH]; GetFullPathNameA(LAUNCHER_INJECT_DLL, sizeof(launcherPayloadPath), launcherPayloadPath, NULL); - printf("Starting '%s' via '%s'\n", gameExePath, launcherPath); + // 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); + } // Set envvars SetEnvironmentVariableA(ENV_EXE_PATH, gameExePath); SetEnvironmentVariableA(ENV_DLL_PATH, gamePayloadPath); + SetEnvironmentVariableA(ENV_PROC_CMD, cmdline); // Start the launcher + printf("Starting '%s' via '%s'\n", gameExePath, launcherPath); + STARTUPINFO si; ZeroMemory(&si, sizeof(si));