From 7310f9349bdffc6ece2cbb3290185d8cedb040e9 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Tue, 27 Nov 2018 16:57:47 -0500 Subject: [PATCH] remove unhook button --- GUI/host/host.cpp | 16 ---------------- GUI/host/host.h | 3 --- GUI/mainwindow.cpp | 42 +++++++----------------------------------- GUI/mainwindow.h | 4 +--- GUI/mainwindow.ui | 7 ------- include/types.h | 7 ------- vnrhook/main.cc | 6 ------ 7 files changed, 8 insertions(+), 77 deletions(-) diff --git a/GUI/host/host.cpp b/GUI/host/host.cpp index a27525d..d4b8e7f 100644 --- a/GUI/host/host.cpp +++ b/GUI/host/host.cpp @@ -146,17 +146,6 @@ namespace Host CreatePipe(); } - void Close() - { - // Artikash 7/25/2018: This is only called when Textractor is closed, at which point Windows should free everything itself...right? -#ifdef _DEBUG // Check memory leaks - ProcessRecord::OnConnect = ProcessRecord::OnDisconnect = [](auto) {}; - TextThread::OnCreate = TextThread::OnDestroy = [](auto) {}; - processRecordsByIds->clear(); - textThreadsByParams->clear(); -#endif - } - bool InjectProcess(DWORD processId, DWORD timeout) { if (processId == GetCurrentProcessId()) return false; @@ -209,11 +198,6 @@ namespace Host processRecordsByIds->at(processId)->Send(InsertHookCmd(hp, name)); } - void RemoveHook(DWORD processId, uint64_t addr) - { - processRecordsByIds->at(processId)->Send(RemoveHookCmd(addr)); - } - HookParam GetHookParam(DWORD processId, uint64_t addr) { return processRecordsByIds->at(processId)->GetHook(addr).hp; diff --git a/GUI/host/host.h b/GUI/host/host.h index 1337140..81d1843 100644 --- a/GUI/host/host.h +++ b/GUI/host/host.h @@ -7,13 +7,10 @@ namespace Host { typedef std::function ProcessEventCallback; void Start(ProcessEventCallback OnConnect, ProcessEventCallback OnDisconnect, TextThread::EventCallback OnCreate, TextThread::EventCallback OnDestroy, TextThread::OutputCallback Output); - void Close(); bool InjectProcess(DWORD processId, DWORD timeout = 5000); void DetachProcess(DWORD processId); - void InsertHook(DWORD processId, HookParam hp, std::string name = ""); - void RemoveHook(DWORD processId, uint64_t addr); HookParam GetHookParam(DWORD processId, uint64_t addr); inline HookParam GetHookParam(ThreadParam tp) { return GetHookParam(tp.processId, tp.addr); } diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index 3fe942b..870c7ad 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -37,7 +37,6 @@ MainWindow::~MainWindow() { settings.setValue(WINDOW, geometry()); settings.sync(); - Host::Close(); delete ui; } @@ -152,22 +151,6 @@ std::unordered_map MainWindow::GetMiscInfo(TextThread* thr }; } -QVector MainWindow::GetAllHooks(DWORD processId) -{ - QSet addresses; - QVector hooks; - for (int i = 0; i < ttCombo->count(); ++i) - { - ThreadParam tp = ParseTextThreadString(ttCombo->itemText(i)); - if (tp.processId == processId && !addresses.contains(tp.addr)) - { - addresses.insert(tp.addr); - hooks.push_back(Host::GetHookParam(tp)); - } - } - return hooks; -} - void MainWindow::on_attachButton_clicked() { auto allProcesses = GetAllProcesses(); @@ -194,27 +177,16 @@ void MainWindow::on_hookButton_clicked() else Host::AddConsoleOutput(INVALID_CODE); } -void MainWindow::on_unhookButton_clicked() -{ - auto hooks = GetAllHooks(GetSelectedProcessId()); - if (hooks.empty()) return Host::AddConsoleOutput(NO_HOOKS); - QStringList hookList; - for (auto hp : hooks) - hookList.push_back( - QString::fromStdWString(Host::GetHookName(GetSelectedProcessId(), hp.insertion_address)) + - ": " + - GenerateCode(hp, GetSelectedProcessId()) - ); - bool ok; - QString hook = QInputDialog::getItem(this, UNHOOK, REMOVE_HOOK, hookList, 0, false, &ok, Qt::WindowCloseButtonHint); - if (ok) Host::RemoveHook(GetSelectedProcessId(), hooks.at(hookList.indexOf(hook)).insertion_address); -} - void MainWindow::on_saveButton_clicked() { + QHash hookCodes; + for (int i = 0; i < ttCombo->count(); ++i) + { + ThreadParam tp = ParseTextThreadString(ttCombo->itemText(i)); + if (tp.processId == GetSelectedProcessId() && !(Host::GetHookParam(tp).type & HOOK_ENGINE)) hookCodes[tp.addr] = GenerateCode(Host::GetHookParam(tp), tp.processId); + } QString hookList = GetFullModuleName(GetSelectedProcessId()); - for (auto hp : GetAllHooks(GetSelectedProcessId())) - if (!(hp.type & HOOK_ENGINE)) hookList += " , " + GenerateCode(hp, GetSelectedProcessId()); + for (auto hookCode : hookCodes) hookList += " , " + hookCode; QAutoFile(HOOK_SAVE_FILE, QIODevice::Append)->write((hookList + "\r\n").toUtf8()); } diff --git a/GUI/mainwindow.h b/GUI/mainwindow.h index 4dc7635..ece749f 100644 --- a/GUI/mainwindow.h +++ b/GUI/mainwindow.h @@ -24,7 +24,6 @@ public: private slots: void on_attachButton_clicked(); void on_detachButton_clicked(); - void on_unhookButton_clicked(); void on_hookButton_clicked(); void on_saveButton_clicked(); void on_setButton_clicked(); @@ -32,6 +31,7 @@ private slots: void on_ttCombo_activated(int index); private: + void closeEvent(QCloseEvent*); void InvokeOnMainThread(std::function&& f); void ProcessConnected(DWORD processId); void ProcessDisconnected(DWORD processId); @@ -42,8 +42,6 @@ private: ThreadParam ParseTextThreadString(QString ttString); DWORD GetSelectedProcessId(); std::unordered_map GetMiscInfo(TextThread* thread); - QVector GetAllHooks(DWORD processId); - void closeEvent(QCloseEvent*); Ui::MainWindow* ui; QSettings settings = QSettings(CONFIG_FILE, QSettings::IniFormat); diff --git a/GUI/mainwindow.ui b/GUI/mainwindow.ui index 3fcfbe1..8afd627 100644 --- a/GUI/mainwindow.ui +++ b/GUI/mainwindow.ui @@ -87,13 +87,6 @@ - - - - Remove hook - - - diff --git a/include/types.h b/include/types.h index 3d10055..d09f749 100644 --- a/include/types.h +++ b/include/types.h @@ -99,13 +99,6 @@ struct InsertHookCmd // From host char name[HOOK_NAME_SIZE] = {}; }; -struct RemoveHookCmd // From host -{ - RemoveHookCmd(uint64_t address) : address(address) {}; - int command = HOST_COMMAND_REMOVE_HOOK; - uint64_t address; -}; - struct ConsoleOutputNotif // From hook { ConsoleOutputNotif(std::string message = "") { strcpy_s(this->message, message.c_str()); }; diff --git a/vnrhook/main.cc b/vnrhook/main.cc index 0c74922..009412a 100644 --- a/vnrhook/main.cc +++ b/vnrhook/main.cc @@ -71,12 +71,6 @@ DWORD WINAPI Pipe(LPVOID) NewHook(info.hp, info.name, 0); } break; - case HOST_COMMAND_REMOVE_HOOK: - { - auto info = *(RemoveHookCmd*)buffer; - RemoveHook(info.address); - } - break; case HOST_COMMAND_DETACH: { running = false;