From 8c8f6b2c7eccd48031a6944a36c6c354101158e7 Mon Sep 17 00:00:00 2001 From: Ciremun Date: Fri, 19 Apr 2024 01:50:22 +0300 Subject: [PATCH] fix #149 save settings --- freedom/dll/dll_main.cpp | 4 ++++ freedom/standalone/standalone_main.cpp | 1 + freedom/ui/config.cpp | 18 +++++++++++++++++- include/baked_utils_dll.h | 4 ++-- injector.cpp | 8 +++++++- nobuild.exe | Bin 192512 -> 192512 bytes 6 files changed, 31 insertions(+), 4 deletions(-) diff --git a/freedom/dll/dll_main.cpp b/freedom/dll/dll_main.cpp index cc96f44..bdd44c1 100644 --- a/freedom/dll/dll_main.cpp +++ b/freedom/dll/dll_main.cpp @@ -19,6 +19,7 @@ static bool init = false; HWND g_hwnd = NULL; HANDLE g_process = NULL; HMODULE g_module = NULL; +LPVOID g_config_path = NULL; IDirect3DDevice9 *g_d3d9_device = 0; void *pDeviceTable[D3DDEV9_LEN]; @@ -203,6 +204,9 @@ DWORD WINAPI freedom_main(HMODULE hModule) BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { if (ul_reason_for_call == DLL_PROCESS_ATTACH) + { + g_config_path = lpReserved; CloseHandle(CreateThread(0, 0, (LPTHREAD_START_ROUTINE)freedom_main, hModule, 0, 0)); + } return TRUE; } diff --git a/freedom/standalone/standalone_main.cpp b/freedom/standalone/standalone_main.cpp index b51f5d3..f2d75fc 100644 --- a/freedom/standalone/standalone_main.cpp +++ b/freedom/standalone/standalone_main.cpp @@ -45,6 +45,7 @@ HWND g_hwnd = NULL; HANDLE g_process = NULL; HMODULE g_module = NULL; +LPVOID g_config_path = NULL; bool compatibility_mode = false; IDirect3DDevice9 *g_d3d9_device = 0; void unload_dll() {} diff --git a/freedom/ui/config.cpp b/freedom/ui/config.cpp index cd5e6c8..6f3a392 100644 --- a/freedom/ui/config.cpp +++ b/freedom/ui/config.cpp @@ -36,7 +36,23 @@ const char *get_imgui_ini_filename(HMODULE hMod) if (module_path_length == 0) { FR_INFO_FMT("[!] GetModuleFileName (0x%X)", GetLastError()); - return 0; + + // NOTE(Ciremun): config path from freedom_injector + extern LPVOID g_config_path; + if (g_config_path == NULL) + return 0; + + uint8_t test_byte = 0; + if (!internal_memory_read(g_process, (uintptr_t)g_config_path, &test_byte)) + return 0; + + module_path_length = wcslen((wchar_t *)g_config_path); + if (module_path_length == 0) + return 0; + + memcpy(module_path, g_config_path, (module_path_length + 1) * sizeof(wchar_t)); + SecureZeroMemory(g_config_path, (module_path_length + 1) * sizeof(wchar_t)); + VirtualFreeEx(g_process, g_config_path, 0, MEM_RELEASE); } static char module_path_u8[MAX_PATH * 2]; diff --git a/include/baked_utils_dll.h b/include/baked_utils_dll.h index a9eca2f..57c6bd9 100644 --- a/include/baked_utils_dll.h +++ b/include/baked_utils_dll.h @@ -5,7 +5,7 @@ static const unsigned int utils_dll_data[9728/4] = { 0x00905a4d, 0x00000003, 0x00000004, 0x0000ffff, 0x000000b8, 0x00000000, 0x00000040, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000080, 0x0eba1f0e, 0xcd09b400, 0x4c01b821, 0x685421cd, 0x70207369, 0x72676f72, 0x63206d61, 0x6f6e6e61, - 0x65622074, 0x6e757220, 0x206e6920, 0x20534f44, 0x65646f6d, 0x0a0d0d2e, 0x00000024, 0x00000000, 0x00004550, 0x0003014c, 0x661efca3, 0x00000000, + 0x65622074, 0x6e757220, 0x206e6920, 0x20534f44, 0x65646f6d, 0x0a0d0d2e, 0x00000024, 0x00000000, 0x00004550, 0x0003014c, 0x6621a31b, 0x00000000, 0x00000000, 0x202200e0, 0x0030010b, 0x00001e00, 0x00000600, 0x00000000, 0x00003c26, 0x00002000, 0x00004000, 0x10000000, 0x00002000, 0x00000200, 0x00000004, 0x00000000, 0x00000004, 0x00000000, 0x00008000, 0x00000200, 0x00000000, 0x85400003, 0x00100000, 0x00001000, 0x00100000, 0x00001000, 0x00000000, 0x00000010, 0x00000000, 0x00000000, 0x00003bd4, 0x0000004f, 0x00004000, 0x00000298, 0x00000000, 0x00000000, 0x00000000, 0x00000000, @@ -148,7 +148,7 @@ static const unsigned int utils_dll_data[9728/4] = 0x00300054, 0x003d006f, 0x00233f00, 0x007a003d, 0x00300045, 0x00440056, 0x0066005a, 0x004a0077, 0x00480045, 0x007a0033, 0x00440036, 0x00580033, 0x00710047, 0x0054006d, 0x0044006b, 0x00460052, 0x0077006b, 0x00470066, 0x3f000100, 0x003d0023, 0x004e007a, 0x00740044, 0x00300073, 0x00360067, 0x0058004a, 0x00240045, 0x005f0059, 0x00700059, 0x00650068, 0x00760053, 0x00670062, 0x007a007a, 0x007a0068, 0x006f0070, 0x17000051, 0x003d0023, - 0x004f007a, 0x00710035, 0x0062006d, 0x00550070, 0x0000003d, 0xd4b5e313, 0x4f66c0c0, 0x2a6661b7, 0xe73a6e6d, 0x01200400, 0x20030801, 0x20050100, + 0x004f007a, 0x00710035, 0x0062006d, 0x00550070, 0x0000003d, 0x3ee6b8b3, 0x4705a61b, 0x33f9a8a1, 0x72ec81e5, 0x01200400, 0x20030801, 0x20050100, 0x11110101, 0x01012005, 0x07041d11, 0x04311101, 0x65120000, 0x12012005, 0x20050e35, 0x0e391201, 0x11002004, 0x00200331, 0x01000418, 0x07061808, 0x112d1102, 0x1215072d, 0x110e0229, 0x0120052d, 0x06001302, 0x01130120, 0x00050013, 0x08181802, 0x11020007, 0x71111c2d, 0x01022007, 0x01130013, 0x11010704, 0x0307082d, 0x0824111d, 0x20032411, 0x20030e00, 0x070e0800, 0x113d1106, 0x113d113d, 0x41121d3d, 0x00200408, 0x20043d11, 0x04591100, diff --git a/injector.cpp b/injector.cpp index 7fe206b..b641a66 100644 --- a/injector.cpp +++ b/injector.cpp @@ -756,7 +756,13 @@ int wmain(int argc, wchar_t **argv, wchar_t **envp) return 1; } - manual_map_dll(hProc, (BYTE *)module_file.start); + LPVOID config_path = _VirtualAllocEx(hProc, NULL, sizeof(module_path), MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); + if (!config_path) + log_warn("Couldn't allocate config path 0x%X", _GetLastError()); + else if (!_WriteProcessMemory(hProc, config_path, module_path, sizeof(module_path), NULL)) + log_warn("Couldn't write config path 0x%X", _GetLastError()); + + manual_map_dll(hProc, (BYTE *)module_file.start, true, true, true, true, DLL_PROCESS_ATTACH, config_path); unmap_file(module_file); close_file(module_file.handle); diff --git a/nobuild.exe b/nobuild.exe index dfdbb7ed8ce5964e70c179895d271368b1facc85..27d8c60d6eabe22b484f2f433b500a96fe6f9425 100644 GIT binary patch delta 36 qcmZp8z}@hGdjkg}bLe8lW^TrIZbruK+>A_}Ye53rr>|qmbOZp{H4Baa delta 36 qcmZp8z}@hGdjkg}^PJyu&D@Ob+>DIdxfz){*MbDLPhZEB=?DPq