better ux for attaching games

This commit is contained in:
Akash Mozumdar 2018-08-20 14:30:50 -04:00
parent 4e10a597c9
commit 0b3599cb84
3 changed files with 17 additions and 9 deletions

View File

@ -183,12 +183,22 @@ QVector<HookParam> MainWindow::GetAllHooks(DWORD processId)
void MainWindow::on_attachButton_clicked()
{
std::unordered_map<std::wstring, DWORD> allProcesses = GetAllProcesses();
QStringList processList;
for (auto i : allProcesses)
processList.push_back(QString::fromStdWString(i.first));
processList.sort(Qt::CaseInsensitive);
bool ok;
QString process = QInputDialog::getItem(this, "Select Process",
"If you don't see the process you want to inject, try running with admin rights\r\nYou can just type in the process id if you know it",
GetAllProcesses(), 0, true, &ok);
processList, 0, true, &ok);
if (!ok) return;
if (!Host::InjectProcess(process.split(":")[0].toInt())) Host::AddConsoleOutput(L"Failed to attach");
if (process.toInt())
{
if (Host::InjectProcess(process.toInt())) return;
}
else if (Host::InjectProcess(allProcesses[process.toStdWString()])) return;
Host::AddConsoleOutput(L"Failed to attach");
}
void MainWindow::on_detachButton_clicked()

View File

@ -19,18 +19,15 @@ QString GetModuleName(DWORD processId, HMODULE module)
return fullName.remove(0, fullName.lastIndexOf("\\") + 1);
}
QStringList GetAllProcesses()
std::unordered_map<std::wstring, DWORD> GetAllProcesses()
{
DWORD allProcessIds[0x1000];
DWORD spaceUsed;
QStringList ret;
std::unordered_map<std::wstring, DWORD> ret;
if (!EnumProcesses(allProcessIds, sizeof(allProcessIds), &spaceUsed)) return ret;
for (int i = 0; i < spaceUsed / sizeof(DWORD); ++i)
if (GetModuleName(allProcessIds[i]).size())
ret.push_back(GetModuleName(allProcessIds[i]) + ":" + QString::number(allProcessIds[i]));
ret.sort(Qt::CaseInsensitive);
for (int i = 0; i < ret.size(); ++i)
ret[i] = ret[i].split(":")[1] + ": " + ret[i].split(":")[0];
ret[GetModuleName(allProcessIds[i]).toStdWString()] = allProcessIds[i];
return ret;
}

View File

@ -2,12 +2,13 @@
#define MISC_H
#include <QString>
#include <unordered_map>
#include <Windows.h>
#include "../host/host.h"
QString GetFullModuleName(DWORD processId, HMODULE module = NULL);
QString GetModuleName(DWORD processId, HMODULE module = NULL);
QStringList GetAllProcesses();
std::unordered_map<std::wstring, DWORD> GetAllProcesses();
HookParam ParseCode(QString HCode);
QString GenerateCode(HookParam hp, DWORD processId);