diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index 43cd02f..e386eea 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -183,12 +183,22 @@ QVector MainWindow::GetAllHooks(DWORD processId) void MainWindow::on_attachButton_clicked() { + std::unordered_map 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() diff --git a/GUI/misc.cpp b/GUI/misc.cpp index 6a95143..d94badd 100644 --- a/GUI/misc.cpp +++ b/GUI/misc.cpp @@ -19,18 +19,15 @@ QString GetModuleName(DWORD processId, HMODULE module) return fullName.remove(0, fullName.lastIndexOf("\\") + 1); } -QStringList GetAllProcesses() +std::unordered_map GetAllProcesses() { DWORD allProcessIds[0x1000]; DWORD spaceUsed; - QStringList ret; + std::unordered_map 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; } diff --git a/GUI/misc.h b/GUI/misc.h index 2a4e0b7..556b62f 100644 --- a/GUI/misc.h +++ b/GUI/misc.h @@ -2,12 +2,13 @@ #define MISC_H #include +#include #include #include "../host/host.h" QString GetFullModuleName(DWORD processId, HMODULE module = NULL); QString GetModuleName(DWORD processId, HMODULE module = NULL); -QStringList GetAllProcesses(); +std::unordered_map GetAllProcesses(); HookParam ParseCode(QString HCode); QString GenerateCode(HookParam hp, DWORD processId);