From 4ab197c3744ca70c7fe748188b9fd0622559eba4 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Tue, 6 Aug 2019 11:51:17 -0400 Subject: [PATCH] better ux for adding searched hook --- GUI/mainwindow.cpp | 32 +++++++++++++++++++++----------- GUI/mainwindow.h | 1 + 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index 41e5d2c..dc32f1b 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -349,7 +349,12 @@ void MainWindow::ForgetProcess() void MainWindow::AddHook() { - if (QString hookCode = QInputDialog::getText(this, ADD_HOOK, CODE_INFODUMP, QLineEdit::Normal, "", &ok, Qt::WindowCloseButtonHint); ok) + AddHook(""); +} + +void MainWindow::AddHook(QString hook) +{ + if (QString hookCode = QInputDialog::getText(this, ADD_HOOK, CODE_INFODUMP, QLineEdit::Normal, hook, &ok, Qt::WindowCloseButtonHint); ok) if (auto hp = Util::ParseCode(S(hookCode))) try { Host::InsertHook(GetSelectedProcessId(), hp.value()); } catch (std::out_of_range) {} else Host::AddConsoleOutput(INVALID_CODE); } @@ -470,32 +475,37 @@ void MainWindow::FindHooks() filter = std::wregex(cjkCheckbox.isChecked() ? L"[\\u3000-\\ua000]{4,}" : L"[\\u0020-\\u1000]{4,}"); } - auto hooks = std::make_shared(); + auto hooks = std::make_shared>>(); try { - Host::FindHooks(processId, sp, [processId, hooks, filter](HookParam hp, const std::wstring& text) - { - if (std::regex_search(text, filter)) hooks->append(S(Util::GenerateCode(hp, processId)) + ": " + S(text) + "\n"); - }); + Host::FindHooks(processId, sp, [hooks, filter](HookParam hp, const std::wstring& text) { if (std::regex_search(text, filter)) hooks->push_back({ hp, text }); }); } catch (std::out_of_range) { return; } - std::thread([this, hooks] + std::thread([this, hooks, processId] { DWORD64 cleanupTime = GetTickCount64() + 500'000; for (int lastSize = 0; hooks->size() == 0 || hooks->size() != lastSize; Sleep(2000)) if (GetTickCount64() > cleanupTime) return; else lastSize = hooks->size(); - QMetaObject::invokeMethod(this, [this, hooks] + QMetaObject::invokeMethod(this, [this, hooks, processId] { - auto hookList = new QPlainTextEdit(*hooks, this); + auto hookList = new QListWidget(this); hookList->setWindowFlags(Qt::Window | Qt::WindowCloseButtonHint); hookList->setAttribute(Qt::WA_DeleteOnClose); hookList->resize({ 750, 300 }); hookList->setWindowTitle(SEARCH_FOR_HOOKS); + for (auto [hp, text] : *hooks) + new QListWidgetItem(S(Util::GenerateCode(hp, processId) + L" -> " + text), hookList); + connect(hookList, &QListWidget::itemClicked, [this](QListWidgetItem* item) { AddHook(item->text().split(" -> ")[0]); }); hookList->show(); - QString saveFile = QFileDialog::getSaveFileName(this, SAVE_SEARCH_RESULTS, "./Hooks.txt", TEXT_FILES, nullptr); - if (!saveFile.isEmpty()) QTextFile(saveFile, QIODevice::WriteOnly | QIODevice::Truncate).write(hooks->toUtf8()); + QString saveFileName = QFileDialog::getSaveFileName(this, SAVE_SEARCH_RESULTS, "./Hooks.txt", TEXT_FILES, nullptr); + if (!saveFileName.isEmpty()) + { + QTextFile saveFile(saveFileName, QIODevice::WriteOnly | QIODevice::Truncate); + for (auto [hp, text] : *hooks) + saveFile.write(S(Util::GenerateCode(hp, processId) + L" -> " + text + L"\n").toUtf8()); + } hooks->clear(); }); }).detach(); diff --git a/GUI/mainwindow.h b/GUI/mainwindow.h index 7d2bcb9..b9950b3 100644 --- a/GUI/mainwindow.h +++ b/GUI/mainwindow.h @@ -38,6 +38,7 @@ private: void DetachProcess(); void ForgetProcess(); void AddHook(); + void AddHook(QString hook); void RemoveHooks(); void SaveHooks(); void FindHooks();