forked from InWILL/Locale_Remulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLRProc.cpp
87 lines (70 loc) · 2.36 KB
/
LRProc.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include<iostream>
#include<Windows.h>
#include<detours.h>
#include<cstdio>
#include<cstring>
#include<vcclr.h>
#include"../LRCommonLibrary/LRCommonLibrary.h"
#pragma comment(lib, "LRCommonLibrary.lib")
using namespace System::Reflection;
using namespace System::Runtime::InteropServices;
#ifdef _DEBUG
#using <../LRSubMenu/bin/Debug/LRSubMenus.dll>
#else
#using <../LRSubMenu/bin/Release/LRSubMenus.dll>
#endif
const int GuidLength = 37;
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR lpCmdLine, int nCmdShow)
{
LRCSharpLibrary::LRConfig::CheckConfigFile();
if (__argc < 3)
{
MessageBox(
NULL,
TEXT(R"(
Welcome to Locale Remulator x64 command line tool.
Usage: LRProc.exe GUID Path Args
GUID Guid of the target profile (in LRConfig.xml).
Path Full path of the target application.
Args Additional arguments will be passed to the application.
You can also run LREditor to use this applicaction.
)"
),
TEXT("Locale Remulator x64"),
NULL
);
return 0;
}
System::String^ Guid = gcnew System::String(__wargv[1]);
System::String^ CurrentPath = LRCSharpLibrary::LRConfig::CurrentPath;
System::String^ DllPath = System::IO::Path::Combine(CurrentPath, "LRHookx64.dll");
LPSTR dllpath = (LPSTR)(void*)Marshal::StringToHGlobalAnsi(DllPath);
lpCmdLine = wcsstr(lpCmdLine, __wargv[1]);
LPWSTR CommandLine = lpCmdLine + GuidLength;
LRCSharpLibrary::LRProfile^ alpha = LRCSharpLibrary::LRConfig::GetProfile(Guid);
LRProfile beta;
beta.CodePage = alpha->CodePage;
beta.LCID = alpha->LCID;
beta.Bias = alpha->Bias; // Bias will become negative in HookGetTimeZoneInformation
beta.HookIME = alpha->HookIME;
beta.HookLCID = alpha->HookLCID;
// Convert managed System::String to unmanaged std::wstring
std::wstring wLocation;
const wchar_t* chars = (const wchar_t*)Marshal::StringToHGlobalUni(alpha->Location).ToPointer();
wLocation = chars;
Marshal::FreeHGlobal(System::IntPtr((void*)chars));
// Set name of Location
beta.Location = wLocation.c_str();
LRConfigFileMap filemap;
filemap.WrtieConfigFileMap(&beta);
STARTUPINFOW si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(STARTUPINFO));
ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
si.cb = sizeof(STARTUPINFO);
//std::cout << beta.CodePage;
DetourCreateProcessWithDllExW(NULL, CommandLine, NULL,
NULL, FALSE, CREATE_DEFAULT_ERROR_MODE, NULL, NULL,
&si, &pi, dllpath, NULL);
return 0;
}