63 lines
1.7 KiB
C++
Raw Normal View History

2024-04-02 15:36:52 +08:00
#include <Windows.h>
#include <detours.h>
#include <string>
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\\";
auto targetexe = wargv[1];
2024-04-02 15:36:52 +08:00
std::wstring cmd = L"";
for (int i = 1; i < argc; i++)
{
cmd += L"\"";
cmd += wargv[i];
cmd += L"\" ";
2024-01-08 23:37:00 +08:00
}
2024-04-02 15:36:52 +08:00
auto cmd_x = new wchar_t[cmd.size() + 1];
wcscpy(cmd_x, cmd.c_str());
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;
beta.CodePage = 932;
beta.LCID = 0x0411;
beta.Bias = 540; // Bias will become negative in HookGetTimeZoneInformation
beta.HookIME = false;
beta.HookLCID = true;
WrtieConfigFileMap(&beta);
STARTUPINFOW si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(STARTUPINFO));
ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
si.cb = sizeof(STARTUPINFO);
DetourCreateProcessWithDllExW(NULL, cmd_x, 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;
}