Merge branch 'pr/208'
This commit is contained in:
commit
4a2f26711d
@ -35,6 +35,7 @@ int main(int argc, char* argv[])
|
|||||||
if (!OpenGenshinProcess(&hProcess, &hThread))
|
if (!OpenGenshinProcess(&hProcess, &hThread))
|
||||||
{
|
{
|
||||||
std::cout << "Failed to open GenshinImpact process." << std::endl;
|
std::cout << "Failed to open GenshinImpact process." << std::endl;
|
||||||
|
system("pause");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,31 +67,61 @@ int main(int argc, char* argv[])
|
|||||||
CloseHandle(hProcess);
|
CloseHandle(hProcess);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenGenshinProcess(HANDLE *phProcess, HANDLE* phThread)
|
bool OpenGenshinProcess(HANDLE* phProcess, HANDLE* phThread)
|
||||||
{
|
{
|
||||||
STARTUPINFOA startInfo{};
|
|
||||||
PROCESS_INFORMATION processInformation{};
|
|
||||||
|
|
||||||
|
HANDLE hToken;
|
||||||
|
BOOL TokenRet = OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &hToken);
|
||||||
|
if (!TokenRet) {
|
||||||
|
LOG_LAST_ERROR("Privilege escalation failed!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool OpenRet = false;
|
||||||
auto filePath = util::GetOrSelectPath(ini, "Inject", "GenshinPath", "genshin path", "Executable\0GenshinImpact.exe;YuanShen.exe\0");
|
auto filePath = util::GetOrSelectPath(ini, "Inject", "GenshinPath", "genshin path", "Executable\0GenshinImpact.exe;YuanShen.exe\0");
|
||||||
auto commandline = ini.GetValue("Inject", "GenshinCommandLine");
|
auto commandline = ini.GetValue("Inject", "GenshinCommandLine");
|
||||||
|
|
||||||
LPSTR lpstr = commandline == nullptr ? nullptr : const_cast<LPSTR>(commandline);
|
LPSTR lpstr = commandline == nullptr ? nullptr : const_cast<LPSTR>(commandline);
|
||||||
|
|
||||||
if (!filePath)
|
if (!filePath)
|
||||||
return false;
|
return false;
|
||||||
|
DWORD pid = FindProcessId("explorer.exe");
|
||||||
BOOL result = CreateProcessA(filePath->c_str(),
|
if (pid == 0)
|
||||||
lpstr, 0, 0, FALSE, CREATE_SUSPENDED, nullptr, nullptr, &startInfo, &processInformation);
|
{
|
||||||
|
LOG_ERROR("Can't find 'explorer' pid!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
std::string CurrentDirectory = filePath.value();
|
||||||
|
int pos = CurrentDirectory.rfind("\\", CurrentDirectory.length());
|
||||||
|
CurrentDirectory = CurrentDirectory.substr(0, pos);
|
||||||
|
LOG_INFO("%s", CurrentDirectory.data());
|
||||||
|
HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
|
||||||
|
STARTUPINFOEXA si;
|
||||||
|
ZeroMemory(&si, sizeof(si));
|
||||||
|
si.StartupInfo.cb = sizeof(si);
|
||||||
|
SIZE_T lpsize = 0;
|
||||||
|
InitializeProcThreadAttributeList(NULL, 1, 0, &lpsize);
|
||||||
|
char* temp = new char[lpsize];
|
||||||
|
LPPROC_THREAD_ATTRIBUTE_LIST AttributeList = (LPPROC_THREAD_ATTRIBUTE_LIST)temp;
|
||||||
|
InitializeProcThreadAttributeList(AttributeList, 1, 0, &lpsize);
|
||||||
|
if (!UpdateProcThreadAttribute(AttributeList, 0, PROC_THREAD_ATTRIBUTE_PARENT_PROCESS, &handle, sizeof(HANDLE), NULL, NULL))
|
||||||
|
{
|
||||||
|
LOG_WARNING("UpdateProcThreadAttribute failed ! (%d).\n", GetLastError());
|
||||||
|
}
|
||||||
|
si.lpAttributeList = AttributeList;
|
||||||
|
PROCESS_INFORMATION pi;
|
||||||
|
ZeroMemory(&pi, sizeof(pi));
|
||||||
|
BOOL result = CreateProcessAsUserA(hToken, const_cast<LPSTR>(filePath->data()), lpstr,
|
||||||
|
0, 0, 0, EXTENDED_STARTUPINFO_PRESENT | CREATE_SUSPENDED, 0, (LPSTR)CurrentDirectory.data(), (LPSTARTUPINFOA)&si, &pi);
|
||||||
if (result == FALSE)
|
if (result == FALSE)
|
||||||
{
|
{
|
||||||
LOG_LAST_ERROR("Failed to create game process.");
|
LOG_LAST_ERROR("Failed to create game process.");
|
||||||
LOG_ERROR("If you have problem with GenshinImpact.exe path. You can change it manually in cfg.ini.");
|
LOG_ERROR("If you have problem with GenshinImpact.exe path. You can change it manually in cfg.ini.");
|
||||||
return false;
|
goto End;
|
||||||
}
|
}
|
||||||
|
|
||||||
ini.SaveFile("cfg.ini");
|
ini.SaveFile("cfg.ini");
|
||||||
|
*phThread = pi.hThread;
|
||||||
*phThread = processInformation.hThread;
|
*phProcess = pi.hProcess;
|
||||||
*phProcess = processInformation.hProcess;
|
OpenRet = true;
|
||||||
return true;
|
End:
|
||||||
|
DeleteProcThreadAttributeList(AttributeList);
|
||||||
|
delete temp;
|
||||||
|
return OpenRet;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user