diff --git a/GUI/host/hookcode.cpp b/GUI/host/hookcode.cpp index 1b02273..bf4b432 100644 --- a/GUI/host/hookcode.cpp +++ b/GUI/host/hookcode.cpp @@ -254,7 +254,7 @@ namespace { hp.type |= MODULE_OFFSET; hp.address -= (uint64_t)info.AllocationBase; - wcsncpy_s(hp.module, moduleName->c_str() + moduleName->rfind(L'\\') + 1, MAX_MODULE_SIZE - 1); + wcsncpy_s(hp.module, moduleName->filename().c_str(), MAX_MODULE_SIZE - 1); } HCode += L'@' + HexString(hp.address); diff --git a/GUI/host/host.cpp b/GUI/host/host.cpp index 83e25a8..395540d 100644 --- a/GUI/host/host.cpp +++ b/GUI/host/host.cpp @@ -207,7 +207,7 @@ namespace Host IsWow64Process(process, &invalidProcess); if (invalidProcess) return AddConsoleOutput(NEED_32_BIT); #endif - static std::wstring location = std::filesystem::path(GetModuleFilename().value()).replace_filename(ITH_DLL); + static std::wstring location = GetModuleFilename().value().replace_filename(ITH_DLL); if (LPVOID remoteData = VirtualAllocEx(process, nullptr, (location.size() + 1) * sizeof(wchar_t), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)) { WriteProcessMemory(process, remoteData, location.c_str(), (location.size() + 1) * sizeof(wchar_t), nullptr); diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index 275cfba..6d3c2c0 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -141,7 +141,7 @@ namespace { QMultiHash allProcesses; for (auto [processId, processName] : GetAllProcesses()) - if (processName && (showSystemProcesses || processName->find(L":\\Windows\\") == std::wstring::npos)) + if (processName && (showSystemProcesses || processName->wstring().find(L":\\Windows\\") == std::wstring::npos)) allProcesses.insert(QFileInfo(S(processName.value())).fileName(), processId); QStringList processList(allProcesses.uniqueKeys()); @@ -194,9 +194,9 @@ namespace void OpenProcessConfig() { - if (auto processName = GetModuleFilename(selectedProcessId)) if (int last = processName->rfind(L'\\') + 1) + if (auto processName = GetModuleFilename(selectedProcessId)) { - std::wstring configFile = std::wstring(processName.value()).replace(last, std::wstring::npos, GAME_CONFIG_FILE); + auto configFile = processName->replace_filename(GAME_CONFIG_FILE); if (!std::filesystem::exists(configFile)) QTextFile(S(configFile), QFile::WriteOnly).write("see https://github.com/Artikash/Textractor/wiki/Game-configuration-file"); _wspawnlp(_P_DETACH, L"notepad", L"notepad", configFile.c_str(), NULL); } @@ -642,7 +642,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) if (arg[1] == L'p' || arg[1] == L'P') if (DWORD processId = _wtoi(arg.substr(2).c_str())) Host::InjectProcess(processId); else for (auto [processId, processName] : processes) - if (processName.value_or(L"").find(L"\\" + arg.substr(2)) != std::wstring::npos) Host::InjectProcess(processId); + if (processName.value_or(L"").filename() == arg.substr(2)) Host::InjectProcess(processId); std::thread([] { diff --git a/include/module.h b/include/module.h index ddf508e..7a3bd74 100644 --- a/include/module.h +++ b/include/module.h @@ -1,7 +1,7 @@ #include "common.h" #include -inline std::optional GetModuleFilename(DWORD processId, HMODULE module = NULL) +inline std::optional GetModuleFilename(DWORD processId, HMODULE module = NULL) { std::vector buffer(MAX_PATH); if (AutoHandle<> process = OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, FALSE, processId)) @@ -9,19 +9,19 @@ inline std::optional GetModuleFilename(DWORD processId, HMODULE mo return {}; } -inline std::optional GetModuleFilename(HMODULE module = NULL) +inline std::optional GetModuleFilename(HMODULE module = NULL) { std::vector buffer(MAX_PATH); if (GetModuleFileNameW(module, buffer.data(), MAX_PATH)) return buffer.data(); return {}; } -inline std::vector>> GetAllProcesses() +inline std::vector>> GetAllProcesses() { std::vector processIds(10000); DWORD spaceUsed = 0; EnumProcesses(processIds.data(), 10000 * sizeof(DWORD), &spaceUsed); - std::vector>> processes; + std::vector>> processes; for (int i = 0; i < spaceUsed / sizeof(DWORD); ++i) processes.push_back({ processIds[i], GetModuleFilename(processIds[i]) }); return processes; }