better ux for adding searched hook

This commit is contained in:
Akash Mozumdar 2019-08-06 11:51:17 -04:00
parent e20f16da80
commit 4ab197c374
2 changed files with 22 additions and 11 deletions

View File

@ -349,7 +349,12 @@ void MainWindow::ForgetProcess()
void MainWindow::AddHook() 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) {} if (auto hp = Util::ParseCode(S(hookCode))) try { Host::InsertHook(GetSelectedProcessId(), hp.value()); } catch (std::out_of_range) {}
else Host::AddConsoleOutput(INVALID_CODE); 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,}"); filter = std::wregex(cjkCheckbox.isChecked() ? L"[\\u3000-\\ua000]{4,}" : L"[\\u0020-\\u1000]{4,}");
} }
auto hooks = std::make_shared<QString>(); auto hooks = std::make_shared<std::vector<std::pair<HookParam, std::wstring>>>();
try try
{ {
Host::FindHooks(processId, sp, [processId, hooks, filter](HookParam hp, const std::wstring& text) Host::FindHooks(processId, sp, [hooks, filter](HookParam hp, const std::wstring& text) { if (std::regex_search(text, filter)) hooks->push_back({ hp, text }); });
{
if (std::regex_search(text, filter)) hooks->append(S(Util::GenerateCode(hp, processId)) + ": " + S(text) + "\n");
});
} }
catch (std::out_of_range) { return; } catch (std::out_of_range) { return; }
std::thread([this, hooks] std::thread([this, hooks, processId]
{ {
DWORD64 cleanupTime = GetTickCount64() + 500'000; DWORD64 cleanupTime = GetTickCount64() + 500'000;
for (int lastSize = 0; hooks->size() == 0 || hooks->size() != lastSize; Sleep(2000)) for (int lastSize = 0; hooks->size() == 0 || hooks->size() != lastSize; Sleep(2000))
if (GetTickCount64() > cleanupTime) return; if (GetTickCount64() > cleanupTime) return;
else lastSize = hooks->size(); 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->setWindowFlags(Qt::Window | Qt::WindowCloseButtonHint);
hookList->setAttribute(Qt::WA_DeleteOnClose); hookList->setAttribute(Qt::WA_DeleteOnClose);
hookList->resize({ 750, 300 }); hookList->resize({ 750, 300 });
hookList->setWindowTitle(SEARCH_FOR_HOOKS); 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(); hookList->show();
QString saveFile = QFileDialog::getSaveFileName(this, SAVE_SEARCH_RESULTS, "./Hooks.txt", TEXT_FILES, nullptr); QString saveFileName = QFileDialog::getSaveFileName(this, SAVE_SEARCH_RESULTS, "./Hooks.txt", TEXT_FILES, nullptr);
if (!saveFile.isEmpty()) QTextFile(saveFile, QIODevice::WriteOnly | QIODevice::Truncate).write(hooks->toUtf8()); 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(); hooks->clear();
}); });
}).detach(); }).detach();

View File

@ -38,6 +38,7 @@ private:
void DetachProcess(); void DetachProcess();
void ForgetProcess(); void ForgetProcess();
void AddHook(); void AddHook();
void AddHook(QString hook);
void RemoveHooks(); void RemoveHooks();
void SaveHooks(); void SaveHooks();
void FindHooks(); void FindHooks();