Switch to using wide strings in the injector
This commit is contained in:
@ -7,7 +7,7 @@
|
||||
|
||||
typedef char *(*wgufn_t)(wchar_t* path); // wine_get_unix_file_name
|
||||
|
||||
const char *J_MB_TITLE = "Jadeite Launcher Payload";
|
||||
const wchar_t *J_MB_TITLE = L"Jadeite Launcher Payload";
|
||||
|
||||
BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved) {
|
||||
// Only listen for attach
|
||||
@ -16,30 +16,29 @@ BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved) {
|
||||
}
|
||||
|
||||
// Get target EXE path
|
||||
char *targetExe = getenv(ENV_EXE_PATH);
|
||||
wchar_t targetExe[MAX_PATH];
|
||||
GetEnvironmentVariableW(ENV_EXE_PATH, targetExe, MAX_PATH);
|
||||
|
||||
// Get the path of the DLL to inject
|
||||
char *injectDll = getenv(ENV_DLL_PATH);
|
||||
wchar_t injectDll[MAX_PATH];
|
||||
GetEnvironmentVariableW(ENV_DLL_PATH, injectDll, MAX_PATH);
|
||||
|
||||
// Get game commandline
|
||||
char *cmdline = getenv(ENV_PROC_CMD);
|
||||
wchar_t cmdline[8192];
|
||||
GetEnvironmentVariableW(ENV_PROC_CMD, cmdline, sizeof(cmdline) / sizeof(wchar_t));
|
||||
|
||||
// Compute the working directory path
|
||||
char workdir[MAX_PATH];
|
||||
strcpy(workdir, targetExe);
|
||||
*(strrchr(workdir, '\\')) = '\0';
|
||||
wchar_t workdir[MAX_PATH];
|
||||
wcscpy(workdir, targetExe);
|
||||
*(wcsrchr(workdir, '\\')) = '\0';
|
||||
|
||||
// SAFETY: verify that the injector is not inside the game directory
|
||||
HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
|
||||
wgufn_t wine_get_unix_file_name = (wgufn_t)GetProcAddress(kernel32, "wine_get_unix_file_name");
|
||||
|
||||
if (wine_get_unix_file_name) {
|
||||
wchar_t wInjectDll[MAX_PATH], wWorkdir[MAX_PATH];
|
||||
MultiByteToWideChar(CP_UTF8, 0, injectDll, strlen(injectDll) + 1, wInjectDll, MAX_PATH);
|
||||
MultiByteToWideChar(CP_UTF8, 0, workdir, strlen(workdir) + 1, wWorkdir, MAX_PATH);
|
||||
|
||||
char *unixInjectDll = wine_get_unix_file_name(wInjectDll);
|
||||
char *unixWorkdir = wine_get_unix_file_name(wWorkdir);
|
||||
char *unixInjectDll = wine_get_unix_file_name(injectDll);
|
||||
char *unixWorkdir = wine_get_unix_file_name(workdir);
|
||||
|
||||
char *i = unixInjectDll, *w = unixWorkdir;
|
||||
char startsWith = 0;
|
||||
@ -55,22 +54,22 @@ BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved) {
|
||||
HeapFree(heap, 0, unixWorkdir);
|
||||
|
||||
if (startsWith) {
|
||||
MessageBoxA(NULL, "Putting the patcher (or any other foreign PE binaries) inside the game directory is dangerous! Please move it elsewhere.", J_MB_TITLE, MB_OK | MB_ICONERROR);
|
||||
MessageBoxW(NULL, L"Putting the patcher (or any other foreign PE binaries) inside the game directory is dangerous! Please move it elsewhere.", J_MB_TITLE, MB_OK | MB_ICONERROR);
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
MessageBoxA(NULL, "Could not find wine_get_unix_file_name! Wine version too old?", J_MB_TITLE, MB_OK | MB_ICONWARNING);
|
||||
MessageBoxW(NULL, L"Could not find wine_get_unix_file_name! Wine version too old?", J_MB_TITLE, MB_OK | MB_ICONWARNING);
|
||||
}
|
||||
|
||||
// Start the game
|
||||
STARTUPINFO si;
|
||||
STARTUPINFOW si;
|
||||
ZeroMemory(&si, sizeof(si));
|
||||
|
||||
PROCESS_INFORMATION pi;
|
||||
si.cb = sizeof(si);
|
||||
ZeroMemory(&pi, sizeof(pi));
|
||||
|
||||
if (!CreateProcessA(
|
||||
if (!CreateProcessW(
|
||||
NULL,
|
||||
cmdline,
|
||||
NULL,
|
||||
@ -82,9 +81,9 @@ BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved) {
|
||||
&si,
|
||||
&pi
|
||||
)) {
|
||||
char message[64];
|
||||
sprintf(message, "Failed to start game process: %ld", GetLastError());
|
||||
MessageBoxA(NULL, message, J_MB_TITLE, MB_OK | MB_ICONERROR);
|
||||
wchar_t message[1024];
|
||||
wsprintfW(message, L"Failed to start game process: %ld", GetLastError());
|
||||
MessageBoxW(NULL, message, J_MB_TITLE, MB_OK | MB_ICONERROR);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
@ -97,9 +96,9 @@ BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved) {
|
||||
// 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, J_MB_TITLE, MB_OK | MB_ICONINFORMATION);
|
||||
wchar_t message[64];
|
||||
wsprintfW(message, L"PID: %ld. Press OK to continue", pi.dwProcessId);
|
||||
MessageBoxW(NULL, message, J_MB_TITLE, MB_OK | MB_ICONINFORMATION);
|
||||
}
|
||||
|
||||
// Resume the process
|
||||
|
||||
Reference in New Issue
Block a user