61 lines
1.7 KiB
C++
Raw Normal View History

2024-05-03 01:54:36 +08:00
2024-10-22 11:41:47 +08:00
#include <detours.h>
2024-01-08 23:37:00 +08:00
struct LRProfile
{
UINT CodePage;
UINT LCID;
long Bias;
int HookIME;
int HookLCID;
};
2024-04-02 15:36:52 +08:00
int WrtieConfigFileMap(LRProfile *profile)
2024-01-08 23:37:00 +08:00
{
SetEnvironmentVariableW(L"LRCodePage", (LPCWSTR)&profile->CodePage);
SetEnvironmentVariableW(L"LRLCID", (LPCWSTR)&profile->LCID);
SetEnvironmentVariableW(L"LRBIAS", (LPCWSTR)&profile->Bias);
SetEnvironmentVariableW(L"LRHookIME", (LPCWSTR)&profile->HookIME);
SetEnvironmentVariableW(L"LRHookLCID", (LPCWSTR)&profile->HookLCID);
return 0;
}
2024-04-02 15:36:52 +08:00
// https://github.com/InWILL/Locale_Remulator/blob/master/LRProc/LRProc.cpp
int LRwmain(int argc, wchar_t *wargv[])
{
2024-01-08 23:37:00 +08:00
char current[2048];
GetModuleFileNameA(NULL, current, 2048);
2024-04-02 15:36:52 +08:00
std::string _s = current;
2024-01-08 23:37:00 +08:00
_s = _s.substr(0, _s.find_last_of("\\"));
auto dllpath = _s + "\\Locale_Remulator\\";
2024-07-14 22:08:26 +08:00
auto targetexe = wargv[6];
2024-04-02 15:36:52 +08:00
std::wstring cmd = L"";
2024-07-14 22:08:26 +08:00
for (int i = 6; i < argc; i++)
2024-04-02 15:36:52 +08:00
{
cmd += L"\"";
cmd += wargv[i];
cmd += L"\" ";
2024-01-08 23:37:00 +08:00
}
DWORD type;
GetBinaryTypeW(targetexe, &type);
2024-04-02 15:36:52 +08:00
if (type == 6)
dllpath += "LRHookx64.dll";
else
2024-01-08 23:37:00 +08:00
dllpath += "LRHookx32.dll";
LRProfile beta;
2024-07-14 22:08:26 +08:00
beta.CodePage = std::stoi(wargv[1]); // 932;
beta.LCID = std::stoi(wargv[2]); // 0x0411;
beta.Bias = std::stoi(wargv[3]); // 540; // Bias will become negative in HookGetTimeZoneInformation
beta.HookIME = std::stoi(wargv[4]); // false;
beta.HookLCID = std::stoi(wargv[5]); // true;
2024-01-08 23:37:00 +08:00
WrtieConfigFileMap(&beta);
STARTUPINFOW si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(STARTUPINFO));
ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
si.cb = sizeof(STARTUPINFO);
2024-07-14 22:08:26 +08:00
DetourCreateProcessWithDllExW(NULL, cmd.data(), NULL,
2024-04-02 15:36:52 +08:00
NULL, FALSE, CREATE_DEFAULT_ERROR_MODE, NULL, NULL,
&si, &pi, dllpath.c_str(), NULL);
2024-01-08 23:37:00 +08:00
return 0;
}