diff --git a/GUI/host/host.cc b/GUI/host/host.cc index 85a9614..a1e2a08 100644 --- a/GUI/host/host.cc +++ b/GUI/host/host.cc @@ -89,15 +89,15 @@ namespace HANDLE hostPipe = CreateNamedPipeW(ITH_COMMAND_PIPE, PIPE_ACCESS_OUTBOUND, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE, PIPE_UNLIMITED_INSTANCES, PIPE_BUFFER_SIZE, PIPE_BUFFER_SIZE, MAXDWORD, NULL); ConnectNamedPipe(hookPipe, nullptr); - // jichi 9/27/2013: why recursion? - // Artikash 5/20/2018: Easy way to create a new pipe for another process - StartPipe(); - BYTE buffer[PIPE_BUFFER_SIZE + 1] = {}; DWORD bytesRead, processId; ReadFile(hookPipe, &processId, sizeof(processId), &bytesRead, nullptr); RegisterProcess(processId, hostPipe); + // jichi 9/27/2013: why recursion? + // Artikash 5/20/2018: Easy way to create a new pipe for another process + StartPipe(); + while (ReadFile(hookPipe, buffer, PIPE_BUFFER_SIZE, &bytesRead, nullptr)) switch (*(int*)buffer) { diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index 7edea97..d37f671 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -175,22 +175,17 @@ 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)); + QMultiHash allProcesses = GetAllProcesses(); + QStringList processList(allProcesses.uniqueKeys()); 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", + "If you don't see the process you want to inject, try running with admin rights\r\nYou can also type in the process id if you know it", processList, 0, true, &ok); if (!ok) return; - if (process.toInt()) - { - if (Host::InjectProcess(process.toInt())) return; - } - else if (Host::InjectProcess(allProcesses[process.toStdWString()])) return; - Host::AddConsoleOutput(L"failed to attach"); + if (process.toInt()) ok &= Host::InjectProcess(process.toInt()); + else for (auto i : allProcesses.values(process)) ok &= Host::InjectProcess(i); + if (!ok) Host::AddConsoleOutput(L"failed to attach"); } void MainWindow::on_detachButton_clicked() diff --git a/GUI/misc.cpp b/GUI/misc.cpp index f83864a..545a4c9 100644 --- a/GUI/misc.cpp +++ b/GUI/misc.cpp @@ -18,15 +18,15 @@ QString GetModuleName(DWORD processId, HMODULE module) return fullName.remove(0, fullName.lastIndexOf("\\") + 1); } -std::unordered_map GetAllProcesses() +QMultiHash GetAllProcesses() { DWORD allProcessIds[0x1000]; DWORD spaceUsed; - std::unordered_map ret; + QMultiHash ret; if (!EnumProcesses(allProcessIds, sizeof(allProcessIds), &spaceUsed)) return ret; for (int i = 0; i < spaceUsed / sizeof(DWORD); ++i) if (GetModuleName(allProcessIds[i]).size()) - ret[GetModuleName(allProcessIds[i]).toStdWString()] = allProcessIds[i]; + ret.insert(GetModuleName(allProcessIds[i]), allProcessIds[i]); return ret; } diff --git a/GUI/misc.h b/GUI/misc.h index efab030..572f851 100644 --- a/GUI/misc.h +++ b/GUI/misc.h @@ -3,11 +3,12 @@ #include "qtcommon.h" #include "types.h" +#include #include QString GetFullModuleName(DWORD processId, HMODULE module = NULL); QString GetModuleName(DWORD processId, HMODULE module = NULL); -std::unordered_map GetAllProcesses(); +QMultiHash GetAllProcesses(); std::optional ParseCode(QString HCode); QString GenerateCode(HookParam hp, DWORD processId); diff --git a/vnrhook/pipe.cc b/vnrhook/pipe.cc index 1f177fc..f9a9336 100644 --- a/vnrhook/pipe.cc +++ b/vnrhook/pipe.cc @@ -36,7 +36,7 @@ void CreatePipe() { ::hookPipe = CreateFileW(ITH_TEXT_PIPE, GENERIC_WRITE, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); } - if (hostPipe == INVALID_HANDLE_VALUE) + if (::hookPipe != INVALID_HANDLE_VALUE && hostPipe == INVALID_HANDLE_VALUE) { hostPipe = CreateFileW(ITH_COMMAND_PIPE, GENERIC_READ | FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); DWORD mode = PIPE_READMODE_MESSAGE;