mirror of
https://github.com/Artikash/Textractor.git
synced 2024-12-23 08:54:12 +08:00
getmodulefilename return path
This commit is contained in:
parent
386e09a81a
commit
9b4f229ff0
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -141,7 +141,7 @@ namespace
|
||||
{
|
||||
QMultiHash<QString, DWORD> 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([]
|
||||
{
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "common.h"
|
||||
#include <Psapi.h>
|
||||
|
||||
inline std::optional<std::wstring> GetModuleFilename(DWORD processId, HMODULE module = NULL)
|
||||
inline std::optional<std::filesystem::path> GetModuleFilename(DWORD processId, HMODULE module = NULL)
|
||||
{
|
||||
std::vector<wchar_t> buffer(MAX_PATH);
|
||||
if (AutoHandle<> process = OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, FALSE, processId))
|
||||
@ -9,19 +9,19 @@ inline std::optional<std::wstring> GetModuleFilename(DWORD processId, HMODULE mo
|
||||
return {};
|
||||
}
|
||||
|
||||
inline std::optional<std::wstring> GetModuleFilename(HMODULE module = NULL)
|
||||
inline std::optional<std::filesystem::path> GetModuleFilename(HMODULE module = NULL)
|
||||
{
|
||||
std::vector<wchar_t> buffer(MAX_PATH);
|
||||
if (GetModuleFileNameW(module, buffer.data(), MAX_PATH)) return buffer.data();
|
||||
return {};
|
||||
}
|
||||
|
||||
inline std::vector<std::pair<DWORD, std::optional<std::wstring>>> GetAllProcesses()
|
||||
inline std::vector<std::pair<DWORD, std::optional<std::filesystem::path>>> GetAllProcesses()
|
||||
{
|
||||
std::vector<DWORD> processIds(10000);
|
||||
DWORD spaceUsed = 0;
|
||||
EnumProcesses(processIds.data(), 10000 * sizeof(DWORD), &spaceUsed);
|
||||
std::vector<std::pair<DWORD, std::optional<std::wstring>>> processes;
|
||||
std::vector<std::pair<DWORD, std::optional<std::filesystem::path>>> processes;
|
||||
for (int i = 0; i < spaceUsed / sizeof(DWORD); ++i) processes.push_back({ processIds[i], GetModuleFilename(processIds[i]) });
|
||||
return processes;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user