From 464c001773ff073e86366a0f6ec25298229dfccf Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Tue, 18 Dec 2018 12:14:54 -0500 Subject: [PATCH] eh who needs moc anyway --- GUI/extenwindow.cpp | 16 ++++------------ GUI/extenwindow.h | 7 ------- GUI/host/textthread.cpp | 5 ----- GUI/host/textthread.h | 3 +-- GUI/mainwindow.cpp | 38 +++++++++++++++++++++----------------- GUI/mainwindow.h | 24 ++++++++---------------- GUI/qtcommon.h | 1 + GUI/setdialog.cpp | 20 ++++++++++---------- GUI/setdialog.h | 6 +----- include/types.h | 2 +- 10 files changed, 47 insertions(+), 75 deletions(-) diff --git a/GUI/extenwindow.cpp b/GUI/extenwindow.cpp index 0effa7a..c939ea4 100644 --- a/GUI/extenwindow.cpp +++ b/GUI/extenwindow.cpp @@ -1,7 +1,7 @@ #include "extenwindow.h" #include "ui_extenwindow.h" -#include "text.h" #include "defs.h" +#include "text.h" #include "types.h" #include "misc.h" #include @@ -83,6 +83,9 @@ ExtenWindow::ExtenWindow(QWidget* parent) : ui->extenList->installEventFilter(this); + connect(ui->addButton, &QPushButton::clicked, [&] { Add(QFileDialog::getOpenFileName(this, SELECT_EXTENSION, "C:\\", EXTENSION_FILES)); }); + connect(ui->rmvButton, &QPushButton::clicked, [&] { if (auto extenName = ui->extenList->currentItem()) Unload(extenName->text()); Sync(); }); + for (auto extenName : QString(QAutoFile(EXTEN_SAVE_FILE, QIODevice::ReadOnly)->readAll()).split(">")) Load(extenName); Sync(); } @@ -134,14 +137,3 @@ void ExtenWindow::dropEvent(QDropEvent* event) { for (auto file : event->mimeData()->urls()) Add(file.toLocalFile()); } - -void ExtenWindow::on_addButton_clicked() -{ - Add(QFileDialog::getOpenFileName(this, SELECT_EXTENSION, "C:\\", EXTENSION_FILES)); -} - -void ExtenWindow::on_rmvButton_clicked() -{ - if (auto extenName = ui->extenList->currentItem()) Unload(extenName->text()); - Sync(); -} diff --git a/GUI/extenwindow.h b/GUI/extenwindow.h index d311d93..3d51de7 100644 --- a/GUI/extenwindow.h +++ b/GUI/extenwindow.h @@ -1,7 +1,6 @@ #pragma once #include "qtcommon.h" -#include #include #include @@ -14,16 +13,10 @@ bool DispatchSentenceToExtensions(std::wstring& sentence, std::unordered_mapc_str(); -} - void TextThread::AddSentence(std::wstring sentence) { if (Output(this, sentence)) storage->append(sentence); diff --git a/GUI/host/textthread.h b/GUI/host/textthread.h index 2a0fdb7..b73d41b 100644 --- a/GUI/host/textthread.h +++ b/GUI/host/textthread.h @@ -19,10 +19,10 @@ public: TextThread(ThreadParam tp, HookParam hp, std::optional name = {}); ~TextThread(); - std::wstring GetStorage(); void AddSentence(std::wstring sentence); void Push(const BYTE* data, int len); + const ThreadSafePtr storage; const int64_t handle; const std::wstring name; const ThreadParam tp; @@ -32,7 +32,6 @@ private: void Flush(); struct TimerDeleter { void operator()(void* h) { DeleteTimerQueueTimer(NULL, h, INVALID_HANDLE_VALUE); } }; - ThreadSafePtr storage; std::wstring buffer; std::unordered_set repeatingChars; std::mutex bufferMutex; diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index 2ee38d5..60b41c1 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -1,5 +1,6 @@ #include "mainwindow.h" #include "ui_mainwindow.h" +#include "defs.h" #include "text.h" #include "extenwindow.h" #include "setdialog.h" @@ -7,8 +8,6 @@ #include "host/util.h" #include #include -#include -#include #include #include @@ -19,12 +18,12 @@ MainWindow::MainWindow(QWidget *parent) : { ui->setupUi(this); for (auto[text, slot] : Array>{ - { ATTACH, &MainWindow::on_attachButton_clicked }, - { DETACH, &MainWindow::on_detachButton_clicked }, - { ADD_HOOK, &MainWindow::on_hookButton_clicked }, - { SAVE_HOOKS, &MainWindow::on_saveButton_clicked }, - { SETTINGS, &MainWindow::on_setButton_clicked }, - { EXTENSIONS, &MainWindow::on_extenButton_clicked } + { ATTACH, &MainWindow::AttachProcess }, + { DETACH, &MainWindow::DetachProcess }, + { ADD_HOOK, &MainWindow::AddHook }, + { SAVE_HOOKS, &MainWindow::SaveHooks }, + { SETTINGS, &MainWindow::Settings }, + { EXTENSIONS, &MainWindow::Extensions } }) { QPushButton* button = new QPushButton(ui->processFrame); @@ -34,10 +33,14 @@ MainWindow::MainWindow(QWidget *parent) : } ui->processLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding)); + connect(ui->ttCombo, (void(QComboBox::*)(int))&QComboBox::activated, this, &MainWindow::ViewThread); + + QSettings settings(CONFIG_FILE, QSettings::IniFormat); if (settings.contains(WINDOW)) setGeometry(settings.value(WINDOW).toRect()); if (settings.contains(FLUSH_DELAY)) TextThread::flushDelay = settings.value(FLUSH_DELAY).toInt(); if (settings.contains(MAX_BUFFER_SIZE)) TextThread::maxBufferSize = settings.value(MAX_BUFFER_SIZE).toInt(); if (settings.contains(DEFAULT_CODEPAGE)) TextThread::defaultCodepage = settings.value(DEFAULT_CODEPAGE).toInt(); + settings.sync(); Host::Start( [&](DWORD processId) { ProcessConnected(processId); }, @@ -68,6 +71,7 @@ MainWindow::MainWindow(QWidget *parent) : MainWindow::~MainWindow() { + QSettings settings(CONFIG_FILE, QSettings::IniFormat); settings.setValue(WINDOW, geometry()); settings.sync(); delete ui; @@ -122,7 +126,7 @@ void MainWindow::ThreadRemoved(TextThread* thread) if (threadIndex == ui->ttCombo->currentIndex()) { ui->ttCombo->setCurrentIndex(0); - on_ttCombo_activated(0); + ViewThread(0); } ui->ttCombo->removeItem(threadIndex); }); @@ -184,7 +188,7 @@ std::unordered_map MainWindow::GetMiscInfo(TextThread* thr }; } -void MainWindow::on_attachButton_clicked() +void MainWindow::AttachProcess() { QMultiHash allProcesses; DWORD allProcessIds[5000] = {}, spaceUsed = 0; @@ -201,12 +205,12 @@ void MainWindow::on_attachButton_clicked() else for (auto processId : allProcesses.values(process)) Host::InjectProcess(processId); } -void MainWindow::on_detachButton_clicked() +void MainWindow::DetachProcess() { Host::DetachProcess(GetSelectedProcessId()); } -void MainWindow::on_hookButton_clicked() +void MainWindow::AddHook() { bool ok; QString hookCode = QInputDialog::getText(this, ADD_HOOK, CODE_INFODUMP, QLineEdit::Normal, "", &ok, Qt::WindowCloseButtonHint); @@ -215,7 +219,7 @@ void MainWindow::on_hookButton_clicked() else Host::AddConsoleOutput(INVALID_CODE); } -void MainWindow::on_saveButton_clicked() +void MainWindow::SaveHooks() { if (auto processName = Util::GetModuleFileName(GetSelectedProcessId())) { @@ -231,19 +235,19 @@ void MainWindow::on_saveButton_clicked() } } -void MainWindow::on_setButton_clicked() +void MainWindow::Settings() { SetDialog(this).exec(); } -void MainWindow::on_extenButton_clicked() +void MainWindow::Extensions() { extenWindow->activateWindow(); extenWindow->showNormal(); } -void MainWindow::on_ttCombo_activated(int index) +void MainWindow::ViewThread(int index) { - ui->textOutput->setPlainText(S(Host::GetThread(ParseTextThreadString(ui->ttCombo->itemText(index)))->GetStorage())); + ui->textOutput->setPlainText(S(Host::GetThread(ParseTextThreadString(ui->ttCombo->itemText(index)))->storage->c_str())); ui->textOutput->moveCursor(QTextCursor::End); } diff --git a/GUI/mainwindow.h b/GUI/mainwindow.h index d6d22fb..a80dfa4 100644 --- a/GUI/mainwindow.h +++ b/GUI/mainwindow.h @@ -2,10 +2,6 @@ #include "qtcommon.h" #include "host/host.h" -#include "defs.h" -#include -#include -#include namespace Ui { @@ -14,23 +10,13 @@ namespace Ui class MainWindow : public QMainWindow { - Q_OBJECT - public: explicit MainWindow(QWidget *parent = nullptr); ~MainWindow(); -private slots: - void on_attachButton_clicked(); - void on_detachButton_clicked(); - void on_hookButton_clicked(); - void on_saveButton_clicked(); - void on_setButton_clicked(); - void on_extenButton_clicked(); - void on_ttCombo_activated(int index); private: - void closeEvent(QCloseEvent*); + void closeEvent(QCloseEvent*) override; void InvokeOnMainThread(std::function f); void ProcessConnected(DWORD processId); void ProcessDisconnected(DWORD processId); @@ -41,8 +27,14 @@ private: ThreadParam ParseTextThreadString(QString ttString); DWORD GetSelectedProcessId(); std::unordered_map GetMiscInfo(TextThread* thread); + void AttachProcess(); + void DetachProcess(); + void AddHook(); + void SaveHooks(); + void Settings(); + void Extensions(); + void ViewThread(int index); Ui::MainWindow* ui; - QSettings settings = QSettings(CONFIG_FILE, QSettings::IniFormat); QWidget* extenWindow; }; diff --git a/GUI/qtcommon.h b/GUI/qtcommon.h index f48dd54..89cee8e 100644 --- a/GUI/qtcommon.h +++ b/GUI/qtcommon.h @@ -9,3 +9,4 @@ #include #include #include +#include diff --git a/GUI/setdialog.cpp b/GUI/setdialog.cpp index 9700ddf..af212dc 100644 --- a/GUI/setdialog.cpp +++ b/GUI/setdialog.cpp @@ -3,7 +3,6 @@ #include "defs.h" #include "text.h" #include "host/host.h" -#include SetDialog::SetDialog(QWidget* parent) : QDialog(parent, Qt::WindowCloseButtonHint), @@ -21,18 +20,19 @@ SetDialog::SetDialog(QWidget* parent) : spinBox->setValue(value); ui->layout->insertRow(0, label, spinBox); } + + connect(ui->buttonBox, &QDialogButtonBox::accepted, [&] { edited = true; }); } SetDialog::~SetDialog() { + if (edited) + { + QSettings settings(CONFIG_FILE, QSettings::IniFormat); + settings.setValue(FLUSH_DELAY, TextThread::flushDelay = flushDelay->value()); + settings.setValue(MAX_BUFFER_SIZE, TextThread::maxBufferSize = maxBufferSize->value()); + settings.setValue(DEFAULT_CODEPAGE, TextThread::defaultCodepage = defaultCodepage->value()); + settings.sync(); + } delete ui; } - -void SetDialog::on_buttonBox_accepted() -{ - QSettings settings(CONFIG_FILE, QSettings::IniFormat); - settings.setValue(FLUSH_DELAY, TextThread::flushDelay = flushDelay->value()); - settings.setValue(MAX_BUFFER_SIZE, TextThread::maxBufferSize = maxBufferSize->value()); - settings.setValue(DEFAULT_CODEPAGE, TextThread::defaultCodepage = defaultCodepage->value()); - settings.sync(); -} diff --git a/GUI/setdialog.h b/GUI/setdialog.h index 4f9ecb7..4f56c22 100644 --- a/GUI/setdialog.h +++ b/GUI/setdialog.h @@ -10,18 +10,14 @@ namespace Ui class SetDialog : public QDialog { - Q_OBJECT - public: explicit SetDialog(QWidget* parent = nullptr); ~SetDialog(); -private slots: - void on_buttonBox_accepted(); - private: Ui::SetDialog* ui; QSpinBox* flushDelay; QSpinBox* maxBufferSize; QSpinBox* defaultCodepage; + bool edited = false; }; diff --git a/include/types.h b/include/types.h index 4f3a4a2..72ce50f 100644 --- a/include/types.h +++ b/include/types.h @@ -10,7 +10,7 @@ class ThreadSafePtr { public: template ThreadSafePtr(Args ...args) : ptr(new E(args...)), mtxPtr(new M) {} - auto operator->() + auto operator->() const { struct {