From e48adc14bba0b44967772cfc6dd74432b8ebc620 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Thu, 1 Nov 2018 10:38:14 -0400 Subject: [PATCH 1/7] add extension dialog --- GUI/CMakeLists.txt | 2 +- GUI/extendialog.cpp | 117 ++++++++++++++++++++++++++++++++++++++++++++ GUI/extendialog.h | 70 ++++++++++++++++++++++++++ GUI/extendialog.ui | 78 +++++++++++++++++++++++++++++ GUI/extensions.cpp | 67 ------------------------- GUI/extensions.h | 32 ------------ GUI/mainwindow.cpp | 54 ++------------------ GUI/mainwindow.h | 4 +- GUI/tests.cpp | 2 +- 9 files changed, 273 insertions(+), 153 deletions(-) create mode 100644 GUI/extendialog.cpp create mode 100644 GUI/extendialog.h create mode 100644 GUI/extendialog.ui delete mode 100644 GUI/extensions.cpp delete mode 100644 GUI/extensions.h diff --git a/GUI/CMakeLists.txt b/GUI/CMakeLists.txt index 95d0397..476f311 100644 --- a/GUI/CMakeLists.txt +++ b/GUI/CMakeLists.txt @@ -9,7 +9,7 @@ set(gui_SRCS main.cpp mainwindow.cpp misc.cpp - extensions.cpp + extendialog.cpp tests.cpp host/host.cc host/textthread.cc diff --git a/GUI/extendialog.cpp b/GUI/extendialog.cpp new file mode 100644 index 0000000..fe28cd6 --- /dev/null +++ b/GUI/extendialog.cpp @@ -0,0 +1,117 @@ +#include "extendialog.h" +#include "ui_extendialog.h" +#include "types.h" +#include + +ListRearrangeFilter::ListRearrangeFilter(QWidget* parent) : QObject(parent) {} + +bool ListRearrangeFilter::eventFilter(QObject*, QEvent* event) +{ + if (event->type() == QEvent::ChildRemoved) emit SigRearranged(); + return false; +} + +ExtenDialog::ExtenDialog(QWidget* parent) : + QDialog(parent), + ui(new Ui::ExtenDialog), + filter(new ListRearrangeFilter(this)) +{ + ui->setupUi(this); + + extenList = findChild("extenList"); + extenList->installEventFilter(filter); + connect(filter, &ListRearrangeFilter::SigRearranged, this, &ExtenDialog::Rearrange); + + if (extensions.empty()) + { + extenSaveFile.open(QIODevice::ReadOnly); + for (auto extenName : QString(extenSaveFile.readAll()).split(">")) Load(extenName); + extenSaveFile.close(); + } + + for (auto extension : extensions) + extenList->addItem(extension.name); +} + +ExtenDialog::~ExtenDialog() +{ + delete ui; +} + +bool ExtenDialog::DispatchSentenceToExtensions(std::wstring& sentence, std::unordered_map miscInfo) +{ + bool success = true; + wchar_t* sentenceBuffer = (wchar_t*)HeapAlloc(GetProcessHeap(), 0, (sentence.size() + 1) * sizeof(wchar_t)); + wcscpy_s(sentenceBuffer, sentence.size() + 1, sentence.c_str()); + + InfoForExtension miscInfoLinkedList{ "", 0, nullptr }; + InfoForExtension* miscInfoTraverser = &miscInfoLinkedList; + for (auto& i : miscInfo) miscInfoTraverser = miscInfoTraverser->next = new InfoForExtension{ i.first.c_str(), i.second, nullptr }; + + std::shared_lock sharedLock(extenMutex); + for (auto extension : extensions) + { + wchar_t* nextBuffer = extension.callback(sentenceBuffer, &miscInfoLinkedList); + if (nextBuffer == nullptr) { success = false; break; } + if (nextBuffer != sentenceBuffer) HeapFree(GetProcessHeap(), 0, sentenceBuffer); + sentenceBuffer = nextBuffer; + } + sentence = std::wstring(sentenceBuffer); + + HeapFree(GetProcessHeap(), 0, sentenceBuffer); + return success; +} + +void ExtenDialog::Load(QString extenName) +{ + // Extension is dll and exports "OnNewSentence" + HMODULE module = GetModuleHandleW(extenName.toStdWString().c_str()); + if (!module) module = LoadLibraryW(extenName.toStdWString().c_str()); + if (!module) return; + FARPROC callback = GetProcAddress(module, "OnNewSentence"); + if (!callback) return; + extensions.push_back({ extenName, (wchar_t*(*)(const wchar_t*, const InfoForExtension*))callback }); +} + +void ExtenDialog::Unload(QString extenName) +{ + extensions.erase(std::remove_if(extensions.begin(), extensions.end(), [&](Extension extension) { return extension.name == extenName; }), extensions.end()); + FreeLibrary(GetModuleHandleW(extenName.toStdWString().c_str())); +} + +void ExtenDialog::on_addButton_clicked() +{ + QString extenFileName = QFileDialog::getOpenFileName(this, "Select Extension", "C:\\", "Extensions (*.dll)"); + if (!extenFileName.size()) return; + QString extenName = extenFileName.mid(extenFileName.lastIndexOf("/") + 1); + QFile::copy(extenFileName, extenName); + Load(extenName.left(extenName.lastIndexOf(".dll"))); + Sync(); +} + +void ExtenDialog::on_rmvButton_clicked() +{ + for (auto extenName : extenList->selectedItems()) Unload(extenName->text()); + Sync(); +} + +void ExtenDialog::Rearrange() +{ + QVector newExtensions; + for (int i = 0; i < extenList->count(); ++i) + newExtensions.push_back(*std::find_if(extensions.begin(), extensions.end(), [=](Extension extension) { return extension.name == extenList->item(i)->text(); })); + extensions = newExtensions; + Sync(); +} + +void ExtenDialog::Sync() +{ + extenList->clear(); + extenSaveFile.open(QIODevice::WriteOnly | QIODevice::Truncate); + for (auto extension : extensions) + { + extenList->addItem(extension.name); + extenSaveFile.write((extension.name + ">").toUtf8()); + } + extenSaveFile.close(); +} diff --git a/GUI/extendialog.h b/GUI/extendialog.h new file mode 100644 index 0000000..2ad0c0e --- /dev/null +++ b/GUI/extendialog.h @@ -0,0 +1,70 @@ +#ifndef EXTENSIONS_H +#define EXTENSIONS_H + +#include "qtcommon.h" +#include +#include +#include +#include + +namespace Ui +{ + class ExtenDialog; +} + +class ListRearrangeFilter : public QObject +{ + Q_OBJECT + +public: + explicit ListRearrangeFilter(QWidget* parent = nullptr); + +protected: + bool eventFilter(QObject*, QEvent* event); + +signals: + void SigRearranged(); +}; + +class ExtenDialog : public QDialog +{ + Q_OBJECT + +public: + explicit ExtenDialog(QWidget* parent = nullptr); + ~ExtenDialog(); + static bool DispatchSentenceToExtensions(std::wstring& sentence, std::unordered_map miscInfo); + +private slots: + void on_addButton_clicked(); + void on_rmvButton_clicked(); + void Rearrange(); + +private: + struct InfoForExtension + { + const char* name; + int64_t value; + InfoForExtension* next; + ~InfoForExtension() { if (next) delete next; }; + }; + struct Extension + { + QString name; + wchar_t*(*callback)(const wchar_t*, const InfoForExtension*); + }; + inline static std::shared_mutex extenMutex; + inline static QVector extensions; + + static void Load(QString extenName); + static void Unload(QString extenName); + + void Sync(); + + Ui::ExtenDialog* ui; + QFile extenSaveFile = QFile("Extensions.txt"); + QListWidget* extenList; + ListRearrangeFilter* filter; +}; + +#endif // EXTENSIONS_H diff --git a/GUI/extendialog.ui b/GUI/extendialog.ui new file mode 100644 index 0000000..31d3257 --- /dev/null +++ b/GUI/extendialog.ui @@ -0,0 +1,78 @@ + + + ExtenDialog + + + + 0 + 0 + 400 + 300 + + + + Extensions + + + + + + QAbstractItemView::InternalMove + + + Qt::MoveAction + + + QAbstractItemView::MultiSelection + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Add + + + + + + + Remove + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + diff --git a/GUI/extensions.cpp b/GUI/extensions.cpp deleted file mode 100644 index 082f3d0..0000000 --- a/GUI/extensions.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include "extensions.h" -#include "types.h" - -static std::optional LoadExtension(QString extenName) -{ - // Extension is dll and exports "OnNewSentence" - HMODULE module = GetModuleHandleW(extenName.toStdWString().c_str()); - if (!module) module = LoadLibraryW(extenName.toStdWString().c_str()); - if (!module) return {}; - FARPROC callback = GetProcAddress(module, "OnNewSentence"); - if (!callback) return {}; - return Extension{ extenName, (wchar_t*(*)(const wchar_t*, const InfoForExtension*))callback }; -} - -void Extension::Load(QString extenName) -{ - LOCK(extenMutex); - if (auto extension = LoadExtension(extenName)) extensions.push_back(extension.value()); -} - -void Extension::SendToBack(QString extenName) -{ - LOCK(extenMutex); - Extension* extenIter = std::find_if(extensions.begin(), extensions.end(), [&](Extension extension) { return extension.name == extenName; }); - Extension extension = *extenIter; - extensions.erase(extenIter); - extensions.push_back(extension); -} - -void Extension::Unload(QString extenName) -{ - LOCK(extenMutex); - extensions.erase(std::find_if(extensions.begin(), extensions.end(), [&](Extension extension) { return extension.name == extenName; })); - FreeLibrary(GetModuleHandleW(extenName.toStdWString().c_str())); -} - -QVector Extension::GetNames() -{ - std::shared_lock sharedLock(extenMutex); - QVector ret; - for (auto extension : extensions) ret.push_back(extension.name); - return ret; -} - -bool Extension::DispatchSentence(std::wstring& sentence, std::unordered_map miscInfo) -{ - bool success = true; - wchar_t* sentenceBuffer = (wchar_t*)HeapAlloc(GetProcessHeap(), 0, (sentence.size() + 1) * sizeof(wchar_t)); - wcscpy_s(sentenceBuffer, sentence.size() + 1, sentence.c_str()); - - InfoForExtension miscInfoLinkedList{ "", 0, nullptr }; - InfoForExtension* miscInfoTraverser = &miscInfoLinkedList; - for (auto& i : miscInfo) miscInfoTraverser = miscInfoTraverser->next = new InfoForExtension{ i.first.c_str(), i.second, nullptr }; - - std::shared_lock sharedLock(extenMutex); - for (auto extension : extensions) - { - wchar_t* nextBuffer = extension.callback(sentenceBuffer, &miscInfoLinkedList); - if (nextBuffer == nullptr) { success = false; break; } - if (nextBuffer != sentenceBuffer) HeapFree(GetProcessHeap(), 0, sentenceBuffer); - sentenceBuffer = nextBuffer; - } - sentence = std::wstring(sentenceBuffer); - - HeapFree(GetProcessHeap(), 0, sentenceBuffer); - return success; -} diff --git a/GUI/extensions.h b/GUI/extensions.h deleted file mode 100644 index fd414f9..0000000 --- a/GUI/extensions.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef EXTENSIONS_H -#define EXTENSIONS_H - -#include "qtcommon.h" -#include - -struct InfoForExtension -{ - const char* name; - int64_t value; - InfoForExtension* next; - ~InfoForExtension() { if (next) delete next; }; -}; - -class Extension -{ -public: - static bool DispatchSentence(std::wstring& sentence, std::unordered_map miscInfo); - static void Load(QString extenName); - static void SendToBack(QString extenName); - static void Unload(QString extenName); - static QVector GetNames(); - - QString name; - wchar_t* (*callback)(const wchar_t*, const InfoForExtension*); - -private: - inline static std::shared_mutex extenMutex; - inline static QVector extensions; -}; - -#endif // EXTENSIONS_H diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index e094c76..15912f6 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -1,7 +1,7 @@ #include "mainwindow.h" #include "ui_mainwindow.h" #include "defs.h" -#include "extensions.h" +#include "extendialog.h" #include "misc.h" #include #include @@ -9,7 +9,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), - ui(new Ui::MainWindow) + ui(new Ui::MainWindow), + extenDialog(new ExtenDialog(this)) { ui->setupUi(this); @@ -18,19 +19,6 @@ MainWindow::MainWindow(QWidget *parent) : extenCombo = findChild("extenCombo"); textOutput = findChild("textOutput"); - QFile extenSaveFile("Extensions.txt"); - if (extenSaveFile.exists()) - { - extenSaveFile.open(QIODevice::ReadOnly); - for (auto extenName : QString(extenSaveFile.readAll()).split(">")) Extension::Load(extenName); - } - else - { - for (auto file : QDir().entryList()) - if (file.endsWith(".dll") && file != ITH_DLL) Extension::Load(file.left(file.lastIndexOf(".dll"))); - } - ReloadExtensions(); - if (settings.contains("Window")) this->setGeometry(settings.value("Window").toRect()); // TODO: add GUI for changing these if (settings.contains("Flush_Delay")) TextThread::flushDelay = settings.value("Flush_Delay").toInt(); @@ -120,7 +108,7 @@ void MainWindow::ThreadOutput(QString threadString, QString output) bool MainWindow::ProcessThreadOutput(TextThread* thread, std::wstring& output) { - if (Extension::DispatchSentence(output, GetInfoForExtensions(thread))) + if (ExtenDialog::DispatchSentenceToExtensions(output, GetInfoForExtensions(thread))) { output += L"\r\n"; emit SigThreadOutput(TextThreadString(thread), QString::fromStdWString(output)); @@ -152,18 +140,6 @@ DWORD MainWindow::GetSelectedProcessId() return processCombo->currentText().split(":")[0].toULong(nullptr, 16); } -void MainWindow::ReloadExtensions() -{ - extenCombo->clear(); - QFile extenSaveFile("Extensions.txt"); - extenSaveFile.open(QIODevice::WriteOnly | QIODevice::Truncate); - for (auto extenName : Extension::GetNames()) - { - extenSaveFile.write((extenName + ">").toUtf8()); - extenCombo->addItem(extenName); - } -} - std::unordered_map MainWindow::GetInfoForExtensions(TextThread* thread) { return @@ -259,25 +235,5 @@ void MainWindow::on_ttCombo_activated(int index) void MainWindow::on_addExtenButton_clicked() { - QString extenFileName = QFileDialog::getOpenFileName(this, "Select Extension", "C:\\", "Extensions (*.dll)"); - if (!extenFileName.size()) return; - QString extenName = extenFileName.mid(extenFileName.lastIndexOf("/") + 1); - QFile::copy(extenFileName, extenName); - Extension::Load(extenName.left(extenName.lastIndexOf(".dll"))); - ReloadExtensions(); -} - -void MainWindow::on_moveExtenButton_clicked() -{ - if (extenCombo->currentText() == "") return; - Extension::SendToBack(extenCombo->currentText()); - ReloadExtensions(); - Host::AddConsoleOutput(L"extension sent to back"); -} - -void MainWindow::on_rmvExtenButton_clicked() -{ - if (extenCombo->currentText() == "") return; - Extension::Unload(extenCombo->currentText()); - ReloadExtensions(); + extenDialog->show(); } diff --git a/GUI/mainwindow.h b/GUI/mainwindow.h index 91a3840..c312a38 100644 --- a/GUI/mainwindow.h +++ b/GUI/mainwindow.h @@ -43,15 +43,12 @@ private slots: void on_hookButton_clicked(); void on_saveButton_clicked(); void on_addExtenButton_clicked(); - void on_moveExtenButton_clicked(); - void on_rmvExtenButton_clicked(); private: bool ProcessThreadOutput(TextThread* thread, std::wstring& output); QString TextThreadString(TextThread* thread); ThreadParam ParseTextThreadString(QString textThreadString); DWORD GetSelectedProcessId(); - void ReloadExtensions(); std::unordered_map GetInfoForExtensions(TextThread* thread); QVector GetAllHooks(DWORD processId); @@ -61,6 +58,7 @@ private: QComboBox* ttCombo; QComboBox* extenCombo; QPlainTextEdit* textOutput; + QWidget* extenDialog; }; #endif // MAINWINDOW_H diff --git a/GUI/tests.cpp b/GUI/tests.cpp index a831b8a..35ae875 100644 --- a/GUI/tests.cpp +++ b/GUI/tests.cpp @@ -1,4 +1,4 @@ -#include "extensions.h" +#include "extendialog.h" #include "misc.h" static int TESTS = [] From ce225fd9007e591a67c43f522cc9e3c0781fda9c Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Thu, 1 Nov 2018 14:07:42 -0400 Subject: [PATCH 2/7] big refactor. move extension internals into unnamed namespace. use mainwindow instead of dialog for extension window. and other renames/bugfixes --- GUI/CMakeLists.txt | 2 +- GUI/extendialog.cpp | 117 ---------------------- GUI/extendialog.h | 70 ------------- GUI/extenwindow.cpp | 130 +++++++++++++++++++++++++ GUI/extenwindow.h | 36 +++++++ GUI/{extendialog.ui => extenwindow.ui} | 21 +--- GUI/mainwindow.cpp | 13 ++- GUI/mainwindow.h | 5 +- GUI/qtcommon.h | 2 + GUI/tests.cpp | 1 - 10 files changed, 181 insertions(+), 216 deletions(-) delete mode 100644 GUI/extendialog.cpp delete mode 100644 GUI/extendialog.h create mode 100644 GUI/extenwindow.cpp create mode 100644 GUI/extenwindow.h rename GUI/{extendialog.ui => extenwindow.ui} (74%) diff --git a/GUI/CMakeLists.txt b/GUI/CMakeLists.txt index 476f311..25048a7 100644 --- a/GUI/CMakeLists.txt +++ b/GUI/CMakeLists.txt @@ -9,7 +9,7 @@ set(gui_SRCS main.cpp mainwindow.cpp misc.cpp - extendialog.cpp + extenwindow.cpp tests.cpp host/host.cc host/textthread.cc diff --git a/GUI/extendialog.cpp b/GUI/extendialog.cpp deleted file mode 100644 index fe28cd6..0000000 --- a/GUI/extendialog.cpp +++ /dev/null @@ -1,117 +0,0 @@ -#include "extendialog.h" -#include "ui_extendialog.h" -#include "types.h" -#include - -ListRearrangeFilter::ListRearrangeFilter(QWidget* parent) : QObject(parent) {} - -bool ListRearrangeFilter::eventFilter(QObject*, QEvent* event) -{ - if (event->type() == QEvent::ChildRemoved) emit SigRearranged(); - return false; -} - -ExtenDialog::ExtenDialog(QWidget* parent) : - QDialog(parent), - ui(new Ui::ExtenDialog), - filter(new ListRearrangeFilter(this)) -{ - ui->setupUi(this); - - extenList = findChild("extenList"); - extenList->installEventFilter(filter); - connect(filter, &ListRearrangeFilter::SigRearranged, this, &ExtenDialog::Rearrange); - - if (extensions.empty()) - { - extenSaveFile.open(QIODevice::ReadOnly); - for (auto extenName : QString(extenSaveFile.readAll()).split(">")) Load(extenName); - extenSaveFile.close(); - } - - for (auto extension : extensions) - extenList->addItem(extension.name); -} - -ExtenDialog::~ExtenDialog() -{ - delete ui; -} - -bool ExtenDialog::DispatchSentenceToExtensions(std::wstring& sentence, std::unordered_map miscInfo) -{ - bool success = true; - wchar_t* sentenceBuffer = (wchar_t*)HeapAlloc(GetProcessHeap(), 0, (sentence.size() + 1) * sizeof(wchar_t)); - wcscpy_s(sentenceBuffer, sentence.size() + 1, sentence.c_str()); - - InfoForExtension miscInfoLinkedList{ "", 0, nullptr }; - InfoForExtension* miscInfoTraverser = &miscInfoLinkedList; - for (auto& i : miscInfo) miscInfoTraverser = miscInfoTraverser->next = new InfoForExtension{ i.first.c_str(), i.second, nullptr }; - - std::shared_lock sharedLock(extenMutex); - for (auto extension : extensions) - { - wchar_t* nextBuffer = extension.callback(sentenceBuffer, &miscInfoLinkedList); - if (nextBuffer == nullptr) { success = false; break; } - if (nextBuffer != sentenceBuffer) HeapFree(GetProcessHeap(), 0, sentenceBuffer); - sentenceBuffer = nextBuffer; - } - sentence = std::wstring(sentenceBuffer); - - HeapFree(GetProcessHeap(), 0, sentenceBuffer); - return success; -} - -void ExtenDialog::Load(QString extenName) -{ - // Extension is dll and exports "OnNewSentence" - HMODULE module = GetModuleHandleW(extenName.toStdWString().c_str()); - if (!module) module = LoadLibraryW(extenName.toStdWString().c_str()); - if (!module) return; - FARPROC callback = GetProcAddress(module, "OnNewSentence"); - if (!callback) return; - extensions.push_back({ extenName, (wchar_t*(*)(const wchar_t*, const InfoForExtension*))callback }); -} - -void ExtenDialog::Unload(QString extenName) -{ - extensions.erase(std::remove_if(extensions.begin(), extensions.end(), [&](Extension extension) { return extension.name == extenName; }), extensions.end()); - FreeLibrary(GetModuleHandleW(extenName.toStdWString().c_str())); -} - -void ExtenDialog::on_addButton_clicked() -{ - QString extenFileName = QFileDialog::getOpenFileName(this, "Select Extension", "C:\\", "Extensions (*.dll)"); - if (!extenFileName.size()) return; - QString extenName = extenFileName.mid(extenFileName.lastIndexOf("/") + 1); - QFile::copy(extenFileName, extenName); - Load(extenName.left(extenName.lastIndexOf(".dll"))); - Sync(); -} - -void ExtenDialog::on_rmvButton_clicked() -{ - for (auto extenName : extenList->selectedItems()) Unload(extenName->text()); - Sync(); -} - -void ExtenDialog::Rearrange() -{ - QVector newExtensions; - for (int i = 0; i < extenList->count(); ++i) - newExtensions.push_back(*std::find_if(extensions.begin(), extensions.end(), [=](Extension extension) { return extension.name == extenList->item(i)->text(); })); - extensions = newExtensions; - Sync(); -} - -void ExtenDialog::Sync() -{ - extenList->clear(); - extenSaveFile.open(QIODevice::WriteOnly | QIODevice::Truncate); - for (auto extension : extensions) - { - extenList->addItem(extension.name); - extenSaveFile.write((extension.name + ">").toUtf8()); - } - extenSaveFile.close(); -} diff --git a/GUI/extendialog.h b/GUI/extendialog.h deleted file mode 100644 index 2ad0c0e..0000000 --- a/GUI/extendialog.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef EXTENSIONS_H -#define EXTENSIONS_H - -#include "qtcommon.h" -#include -#include -#include -#include - -namespace Ui -{ - class ExtenDialog; -} - -class ListRearrangeFilter : public QObject -{ - Q_OBJECT - -public: - explicit ListRearrangeFilter(QWidget* parent = nullptr); - -protected: - bool eventFilter(QObject*, QEvent* event); - -signals: - void SigRearranged(); -}; - -class ExtenDialog : public QDialog -{ - Q_OBJECT - -public: - explicit ExtenDialog(QWidget* parent = nullptr); - ~ExtenDialog(); - static bool DispatchSentenceToExtensions(std::wstring& sentence, std::unordered_map miscInfo); - -private slots: - void on_addButton_clicked(); - void on_rmvButton_clicked(); - void Rearrange(); - -private: - struct InfoForExtension - { - const char* name; - int64_t value; - InfoForExtension* next; - ~InfoForExtension() { if (next) delete next; }; - }; - struct Extension - { - QString name; - wchar_t*(*callback)(const wchar_t*, const InfoForExtension*); - }; - inline static std::shared_mutex extenMutex; - inline static QVector extensions; - - static void Load(QString extenName); - static void Unload(QString extenName); - - void Sync(); - - Ui::ExtenDialog* ui; - QFile extenSaveFile = QFile("Extensions.txt"); - QListWidget* extenList; - ListRearrangeFilter* filter; -}; - -#endif // EXTENSIONS_H diff --git a/GUI/extenwindow.cpp b/GUI/extenwindow.cpp new file mode 100644 index 0000000..34cb6b1 --- /dev/null +++ b/GUI/extenwindow.cpp @@ -0,0 +1,130 @@ +#include "extenwindow.h" +#include "ui_extenwindow.h" +#include "types.h" +#include + +namespace +{ + struct InfoForExtension + { + const char* name; + int64_t value; + InfoForExtension* next; + ~InfoForExtension() { if (next) delete next; }; + }; + + struct Extension + { + QString name; + wchar_t*(*callback)(const wchar_t*, const InfoForExtension*); + }; + + std::shared_mutex extenMutex; + QVector extensions; + + void Load(QString extenName) + { + // Extension is dll and exports "OnNewSentence" + HMODULE module = GetModuleHandleW(extenName.toStdWString().c_str()); + if (!module) module = LoadLibraryW(extenName.toStdWString().c_str()); + if (!module) return; + FARPROC callback = GetProcAddress(module, "OnNewSentence"); + if (!callback) return; + extensions.push_back({ extenName, (wchar_t*(*)(const wchar_t*, const InfoForExtension*))callback }); + } + + void Unload(QString extenName) + { + extensions.erase(std::remove_if(extensions.begin(), extensions.end(), [&](Extension extension) { return extension.name == extenName; }), extensions.end()); + FreeLibrary(GetModuleHandleW(extenName.toStdWString().c_str())); + } +} + +bool DispatchSentenceToExtensions(std::wstring& sentence, std::unordered_map miscInfo) +{ + bool success = true; + wchar_t* sentenceBuffer = (wchar_t*)HeapAlloc(GetProcessHeap(), 0, (sentence.size() + 1) * sizeof(wchar_t)); + wcscpy_s(sentenceBuffer, sentence.size() + 1, sentence.c_str()); + + InfoForExtension miscInfoLinkedList{ "", 0, nullptr }; + InfoForExtension* miscInfoTraverser = &miscInfoLinkedList; + for (auto& i : miscInfo) miscInfoTraverser = miscInfoTraverser->next = new InfoForExtension{ i.first.c_str(), i.second, nullptr }; + + std::shared_lock sharedLock(extenMutex); + for (auto extension : extensions) + { + wchar_t* nextBuffer = extension.callback(sentenceBuffer, &miscInfoLinkedList); + if (nextBuffer == nullptr) { success = false; break; } + if (nextBuffer != sentenceBuffer) HeapFree(GetProcessHeap(), 0, sentenceBuffer); + sentenceBuffer = nextBuffer; + } + sentence = std::wstring(sentenceBuffer); + + HeapFree(GetProcessHeap(), 0, sentenceBuffer); + return success; +} + +ExtenWindow::ExtenWindow(QWidget* parent) : + QMainWindow(parent), + ui(new Ui::ExtenWindow) +{ + ui->setupUi(this); + + extenList = findChild("extenList"); + extenList->installEventFilter(this); + + if (extensions.empty()) + { + extenSaveFile.open(QIODevice::ReadOnly); + for (auto extenName : QString(extenSaveFile.readAll()).split(">")) Load(extenName); + extenSaveFile.close(); + } + Sync(); +} + +ExtenWindow::~ExtenWindow() +{ + delete ui; +} + +void ExtenWindow::on_addButton_clicked() +{ + QString extenFileName = QFileDialog::getOpenFileName(this, "Select Extension", "C:\\", "Extensions (*.dll)"); + if (!extenFileName.size()) return; + QString extenName = extenFileName.mid(extenFileName.lastIndexOf("/") + 1); + QFile::copy(extenFileName, extenName); + Load(extenName.left(extenName.lastIndexOf(".dll"))); + Sync(); +} + +void ExtenWindow::on_rmvButton_clicked() +{ + if (auto extenName = extenList->currentItem()) Unload(extenName->text()); + Sync(); +} + +bool ExtenWindow::eventFilter(QObject* target, QEvent* event) +{ + // See https://stackoverflow.com/questions/1224432/how-do-i-respond-to-an-internal-drag-and-drop-operation-using-a-qlistwidget/1528215 + if (event->type() == QEvent::ChildRemoved) + { + QVector newExtensions; + for (int i = 0; i < extenList->count(); ++i) + newExtensions.push_back(*std::find_if(extensions.begin(), extensions.end(), [=](Extension extension) { return extension.name == extenList->item(i)->text(); })); + extensions = newExtensions; + Sync(); + } + return false; +} + +void ExtenWindow::Sync() +{ + extenList->clear(); + extenSaveFile.open(QIODevice::WriteOnly | QIODevice::Truncate); + for (auto extension : extensions) + { + extenList->addItem(extension.name); + extenSaveFile.write((extension.name + ">").toUtf8()); + } + extenSaveFile.close(); +} diff --git a/GUI/extenwindow.h b/GUI/extenwindow.h new file mode 100644 index 0000000..576de31 --- /dev/null +++ b/GUI/extenwindow.h @@ -0,0 +1,36 @@ +#ifndef EXTENSIONS_H +#define EXTENSIONS_H + +#include "qtcommon.h" +#include +#include + +namespace Ui +{ + class ExtenWindow; +} + +bool DispatchSentenceToExtensions(std::wstring& sentence, std::unordered_map miscInfo); + +class ExtenWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit ExtenWindow(QWidget* parent = nullptr); + ~ExtenWindow(); + +private slots: + void on_addButton_clicked(); + void on_rmvButton_clicked(); + +private: + bool eventFilter(QObject* target, QEvent* event); + void Sync(); + + Ui::ExtenWindow* ui; + QFile extenSaveFile = QFile("Extensions.txt"); + QListWidget* extenList; +}; + +#endif // EXTENSIONS_H diff --git a/GUI/extendialog.ui b/GUI/extenwindow.ui similarity index 74% rename from GUI/extendialog.ui rename to GUI/extenwindow.ui index 31d3257..8a945ae 100644 --- a/GUI/extendialog.ui +++ b/GUI/extenwindow.ui @@ -1,7 +1,7 @@ - ExtenDialog - + ExtenWindow + 0 @@ -13,6 +13,7 @@ Extensions + @@ -22,9 +23,6 @@ Qt::MoveAction - - QAbstractItemView::MultiSelection - @@ -34,12 +32,6 @@ Qt::Vertical - - - 20 - 40 - - @@ -61,17 +53,12 @@ Qt::Vertical - - - 20 - 40 - - + diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index 15912f6..b4aea98 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -1,16 +1,14 @@ #include "mainwindow.h" #include "ui_mainwindow.h" #include "defs.h" -#include "extendialog.h" +#include "extenwindow.h" #include "misc.h" -#include #include -#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), - extenDialog(new ExtenDialog(this)) + extenWindow(new ExtenWindow) { ui->setupUi(this); @@ -108,7 +106,7 @@ void MainWindow::ThreadOutput(QString threadString, QString output) bool MainWindow::ProcessThreadOutput(TextThread* thread, std::wstring& output) { - if (ExtenDialog::DispatchSentenceToExtensions(output, GetInfoForExtensions(thread))) + if (DispatchSentenceToExtensions(output, GetMiscInfo(thread))) { output += L"\r\n"; emit SigThreadOutput(TextThreadString(thread), QString::fromStdWString(output)); @@ -140,7 +138,7 @@ DWORD MainWindow::GetSelectedProcessId() return processCombo->currentText().split(":")[0].toULong(nullptr, 16); } -std::unordered_map MainWindow::GetInfoForExtensions(TextThread* thread) +std::unordered_map MainWindow::GetMiscInfo(TextThread* thread) { return { @@ -235,5 +233,6 @@ void MainWindow::on_ttCombo_activated(int index) void MainWindow::on_addExtenButton_clicked() { - extenDialog->show(); + extenWindow->activateWindow(); + extenWindow->showNormal(); } diff --git a/GUI/mainwindow.h b/GUI/mainwindow.h index c312a38..fc6f234 100644 --- a/GUI/mainwindow.h +++ b/GUI/mainwindow.h @@ -3,7 +3,6 @@ #include "qtcommon.h" #include "host/host.h" -#include #include #include #include @@ -49,7 +48,7 @@ private: QString TextThreadString(TextThread* thread); ThreadParam ParseTextThreadString(QString textThreadString); DWORD GetSelectedProcessId(); - std::unordered_map GetInfoForExtensions(TextThread* thread); + std::unordered_map GetMiscInfo(TextThread* thread); QVector GetAllHooks(DWORD processId); Ui::MainWindow* ui; @@ -58,7 +57,7 @@ private: QComboBox* ttCombo; QComboBox* extenCombo; QPlainTextEdit* textOutput; - QWidget* extenDialog; + QWidget* extenWindow; }; #endif // MAINWINDOW_H diff --git a/GUI/qtcommon.h b/GUI/qtcommon.h index 07fc0db..46029ba 100644 --- a/GUI/qtcommon.h +++ b/GUI/qtcommon.h @@ -3,4 +3,6 @@ #include "common.h" #include #include +#include +#include #include diff --git a/GUI/tests.cpp b/GUI/tests.cpp index 35ae875..0ae4dc0 100644 --- a/GUI/tests.cpp +++ b/GUI/tests.cpp @@ -1,4 +1,3 @@ -#include "extendialog.h" #include "misc.h" static int TESTS = [] From 6ec8e7c19e608a7fa70be16f981de6915a367080 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Thu, 1 Nov 2018 14:46:37 -0400 Subject: [PATCH 3/7] make extensions thread safe --- GUI/extenwindow.cpp | 40 ++++++++++++++++++++++------------------ GUI/misc.h | 1 - GUI/qtcommon.h | 1 + 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/GUI/extenwindow.cpp b/GUI/extenwindow.cpp index 34cb6b1..449ef62 100644 --- a/GUI/extenwindow.cpp +++ b/GUI/extenwindow.cpp @@ -13,14 +13,9 @@ namespace ~InfoForExtension() { if (next) delete next; }; }; - struct Extension - { - QString name; - wchar_t*(*callback)(const wchar_t*, const InfoForExtension*); - }; - + QHash extensions; + QStringList extenNames; std::shared_mutex extenMutex; - QVector extensions; void Load(QString extenName) { @@ -30,14 +25,23 @@ namespace if (!module) return; FARPROC callback = GetProcAddress(module, "OnNewSentence"); if (!callback) return; - extensions.push_back({ extenName, (wchar_t*(*)(const wchar_t*, const InfoForExtension*))callback }); + LOCK(extenMutex); + extensions[extenName] = (wchar_t*(*)(const wchar_t*, const InfoForExtension*))callback; + extenNames.push_back(extenName); } void Unload(QString extenName) { - extensions.erase(std::remove_if(extensions.begin(), extensions.end(), [&](Extension extension) { return extension.name == extenName; }), extensions.end()); + LOCK(extenMutex); + extenNames.erase(std::remove(extenNames.begin(), extenNames.end(), extenName), extenNames.end()); FreeLibrary(GetModuleHandleW(extenName.toStdWString().c_str())); } + + void Reorder(QStringList extenNames) + { + LOCK(extenMutex); + ::extenNames = extenNames; + } } bool DispatchSentenceToExtensions(std::wstring& sentence, std::unordered_map miscInfo) @@ -51,9 +55,9 @@ bool DispatchSentenceToExtensions(std::wstring& sentence, std::unordered_mapnext = new InfoForExtension{ i.first.c_str(), i.second, nullptr }; std::shared_lock sharedLock(extenMutex); - for (auto extension : extensions) + for (auto extenName : extenNames) { - wchar_t* nextBuffer = extension.callback(sentenceBuffer, &miscInfoLinkedList); + wchar_t* nextBuffer = extensions[extenName](sentenceBuffer, &miscInfoLinkedList); if (nextBuffer == nullptr) { success = false; break; } if (nextBuffer != sentenceBuffer) HeapFree(GetProcessHeap(), 0, sentenceBuffer); sentenceBuffer = nextBuffer; @@ -108,10 +112,9 @@ bool ExtenWindow::eventFilter(QObject* target, QEvent* event) // See https://stackoverflow.com/questions/1224432/how-do-i-respond-to-an-internal-drag-and-drop-operation-using-a-qlistwidget/1528215 if (event->type() == QEvent::ChildRemoved) { - QVector newExtensions; - for (int i = 0; i < extenList->count(); ++i) - newExtensions.push_back(*std::find_if(extensions.begin(), extensions.end(), [=](Extension extension) { return extension.name == extenList->item(i)->text(); })); - extensions = newExtensions; + QStringList extenNames; + for (int i = 0; i < extenList->count(); ++i) extenNames.push_back(extenList->item(i)->text()); + Reorder(extenNames); Sync(); } return false; @@ -121,10 +124,11 @@ void ExtenWindow::Sync() { extenList->clear(); extenSaveFile.open(QIODevice::WriteOnly | QIODevice::Truncate); - for (auto extension : extensions) + std::shared_lock sharedLock(extenMutex); + for (auto extenName : extenNames) { - extenList->addItem(extension.name); - extenSaveFile.write((extension.name + ">").toUtf8()); + extenList->addItem(extenName); + extenSaveFile.write((extenName + ">").toUtf8()); } extenSaveFile.close(); } diff --git a/GUI/misc.h b/GUI/misc.h index 7cab830..dd93884 100644 --- a/GUI/misc.h +++ b/GUI/misc.h @@ -3,7 +3,6 @@ #include "qtcommon.h" #include "types.h" -#include QString GetFullModuleName(DWORD processId, HMODULE module = NULL); QString GetModuleName(DWORD processId, HMODULE module = NULL); diff --git a/GUI/qtcommon.h b/GUI/qtcommon.h index 46029ba..cdc2efe 100644 --- a/GUI/qtcommon.h +++ b/GUI/qtcommon.h @@ -3,6 +3,7 @@ #include "common.h" #include #include +#include #include #include #include From 4b82d545bfefbe646227f1bee2239b00b421cd02 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Thu, 1 Nov 2018 17:02:52 -0400 Subject: [PATCH 4/7] update ui to match new extension window design --- GUI/extenwindow.ui | 106 +++++++++------ GUI/mainwindow.cpp | 13 +- GUI/mainwindow.h | 5 +- GUI/mainwindow.ui | 326 ++++++++++++--------------------------------- 4 files changed, 152 insertions(+), 298 deletions(-) diff --git a/GUI/extenwindow.ui b/GUI/extenwindow.ui index 8a945ae..495b38a 100644 --- a/GUI/extenwindow.ui +++ b/GUI/extenwindow.ui @@ -13,51 +13,69 @@ Extensions + + QObject +{ + font: 10pt "MS Shell Dlg 2"; +} +#textOutput +{ + font: 13pt "MS Shell Dlg 2";; +} +QPushButton, QComboBox +{ + padding-top: 3px; + padding-bottom: 3px; + padding-right: 5px; + padding-left: 5px; + text-align: left; +} + - - - - - QAbstractItemView::InternalMove - - - Qt::MoveAction - - - - - - - - - Qt::Vertical - - - - - - - Add - - - - - - - Remove - - - - - - - Qt::Vertical - - - - - - + + + + + QAbstractItemView::InternalMove + + + Qt::MoveAction + + + + + + + + + Qt::Vertical + + + + + + + Add + + + + + + + Remove + + + + + + + Qt::Vertical + + + + + + diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index b4aea98..c94c238 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -14,7 +14,6 @@ MainWindow::MainWindow(QWidget *parent) : processCombo = findChild("processCombo"); ttCombo = findChild("ttCombo"); - extenCombo = findChild("extenCombo"); textOutput = findChild("textOutput"); if (settings.contains("Window")) this->setGeometry(settings.value("Window").toRect()); @@ -225,14 +224,14 @@ void MainWindow::on_saveButton_clicked() file.write((hookList + "\r\n").toUtf8()); } +void MainWindow::on_extenButton_clicked() +{ + extenWindow->activateWindow(); + extenWindow->showNormal(); +} + void MainWindow::on_ttCombo_activated(int index) { textOutput->setPlainText(QString::fromStdWString(Host::GetThread(ParseTextThreadString(ttCombo->itemText(index)))->GetStorage())); textOutput->moveCursor(QTextCursor::End); } - -void MainWindow::on_addExtenButton_clicked() -{ - extenWindow->activateWindow(); - extenWindow->showNormal(); -} diff --git a/GUI/mainwindow.h b/GUI/mainwindow.h index fc6f234..9494492 100644 --- a/GUI/mainwindow.h +++ b/GUI/mainwindow.h @@ -37,11 +37,11 @@ private slots: void ThreadOutput(QString threadString, QString output); // this function doesn't take TextThread* because it might be destroyed on pipe thread void on_attachButton_clicked(); void on_detachButton_clicked(); - void on_ttCombo_activated(int index); void on_unhookButton_clicked(); void on_hookButton_clicked(); void on_saveButton_clicked(); - void on_addExtenButton_clicked(); + void on_extenButton_clicked(); + void on_ttCombo_activated(int index); private: bool ProcessThreadOutput(TextThread* thread, std::wstring& output); @@ -55,7 +55,6 @@ private: QSettings settings = QSettings("Textractor.ini", QSettings::IniFormat); QComboBox* processCombo; QComboBox* ttCombo; - QComboBox* extenCombo; QPlainTextEdit* textOutput; QWidget* extenWindow; }; diff --git a/GUI/mainwindow.ui b/GUI/mainwindow.ui index b3d9271..e3aaf74 100644 --- a/GUI/mainwindow.ui +++ b/GUI/mainwindow.ui @@ -6,16 +6,10 @@ 0 0 - 949 + 900 600 - - - 2 - 0 - - Textractor @@ -38,269 +32,113 @@ QPushButton, QComboBox } - - - 0 - - - 0 - - - 0 - - - 0 - + - - - - 0 - 0 - + + + true - - QFrame::StyledPanel - - - QFrame::Raised - - + - 4 + 0 - 4 + 0 - 4 + 0 - 4 + 0 - - - true - - - - 2 - 0 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - false - - - QComboBox::InsertAtBottom - - - QComboBox::AdjustToContents - - - - - - - Attach to game - - - - - - - Detach from game - - - - - - - Add hook - - - - - - - Remove hook - - - - - - - Save hook(s) - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - 0 - 0 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - false - - - QComboBox::AdjustToContents - - - - - - - Add extension - - - - - - - Move extension - - - - - - - Remove extension - - - - - - - - - - - - - - 6 - 0 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - 4 - - - 4 - - - 4 - - - 4 - - - + false - - 50 + + QComboBox::InsertAtBottom + + + QComboBox::AdjustToContents - - - - 5 - 0 - - - - true + + + Attach to game + + + + Detach from game + + + + + + + Add hook + + + + + + + Remove hook + + + + + + + Save hook(s) + + + + + + + Extensions + + + + + + + Qt::Vertical + + + + + + + + + false + + + 50 + + + + + + + true + + + + + - - - - 0 - 0 - 949 - 22 - - - From ee0a8c4887520eb590611016ab73837cb549d5f6 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Thu, 1 Nov 2018 18:47:19 -0400 Subject: [PATCH 5/7] add drag'n'drop for extensions --- GUI/extenwindow.cpp | 56 ++++++++++++++++++++++++++++++--------------- GUI/extenwindow.h | 7 +++++- GUI/extenwindow.ui | 3 +++ include/defs.h | 2 +- 4 files changed, 47 insertions(+), 21 deletions(-) diff --git a/GUI/extenwindow.cpp b/GUI/extenwindow.cpp index 449ef62..9ab3b1b 100644 --- a/GUI/extenwindow.cpp +++ b/GUI/extenwindow.cpp @@ -1,7 +1,10 @@ #include "extenwindow.h" #include "ui_extenwindow.h" +#include "defs.h" #include "types.h" #include +#include +#include namespace { @@ -19,6 +22,7 @@ namespace void Load(QString extenName) { + if (extenName == ITH_DLL) return; // Extension is dll and exports "OnNewSentence" HMODULE module = GetModuleHandleW(extenName.toStdWString().c_str()); if (!module) module = LoadLibraryW(extenName.toStdWString().c_str()); @@ -91,19 +95,25 @@ ExtenWindow::~ExtenWindow() delete ui; } -void ExtenWindow::on_addButton_clicked() +void ExtenWindow::Sync() { - QString extenFileName = QFileDialog::getOpenFileName(this, "Select Extension", "C:\\", "Extensions (*.dll)"); - if (!extenFileName.size()) return; - QString extenName = extenFileName.mid(extenFileName.lastIndexOf("/") + 1); - QFile::copy(extenFileName, extenName); - Load(extenName.left(extenName.lastIndexOf(".dll"))); - Sync(); + extenList->clear(); + extenSaveFile.open(QIODevice::WriteOnly | QIODevice::Truncate); + std::shared_lock sharedLock(extenMutex); + for (auto extenName : extenNames) + { + extenList->addItem(extenName); + extenSaveFile.write((extenName + ">").toUtf8()); + } + extenSaveFile.close(); } -void ExtenWindow::on_rmvButton_clicked() +void ExtenWindow::Add(QString fileName) { - if (auto extenName = extenList->currentItem()) Unload(extenName->text()); + if (!fileName.endsWith(".dll")) return; + QString extenName = fileName.mid(fileName.lastIndexOf("/") + 1); + QFile::copy(fileName, extenName); + Load(extenName.split(".dll")[0]); Sync(); } @@ -120,15 +130,23 @@ bool ExtenWindow::eventFilter(QObject* target, QEvent* event) return false; } -void ExtenWindow::Sync() +void ExtenWindow::dragEnterEvent(QDragEnterEvent* event) { - extenList->clear(); - extenSaveFile.open(QIODevice::WriteOnly | QIODevice::Truncate); - std::shared_lock sharedLock(extenMutex); - for (auto extenName : extenNames) - { - extenList->addItem(extenName); - extenSaveFile.write((extenName + ">").toUtf8()); - } - extenSaveFile.close(); + event->acceptProposedAction(); +} + +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:\\", "Extensions (*.dll)")); +} + +void ExtenWindow::on_rmvButton_clicked() +{ + if (auto extenName = extenList->currentItem()) Unload(extenName->text()); + Sync(); } diff --git a/GUI/extenwindow.h b/GUI/extenwindow.h index 576de31..9923674 100644 --- a/GUI/extenwindow.h +++ b/GUI/extenwindow.h @@ -4,6 +4,8 @@ #include "qtcommon.h" #include #include +#include +#include namespace Ui { @@ -25,8 +27,11 @@ private slots: void on_rmvButton_clicked(); private: - bool eventFilter(QObject* target, QEvent* event); + void Add(QString fileName); void Sync(); + bool eventFilter(QObject* target, QEvent* event); + void dragEnterEvent(QDragEnterEvent* event); + void dropEvent(QDropEvent* event); Ui::ExtenWindow* ui; QFile extenSaveFile = QFile("Extensions.txt"); diff --git a/GUI/extenwindow.ui b/GUI/extenwindow.ui index 495b38a..d6273c3 100644 --- a/GUI/extenwindow.ui +++ b/GUI/extenwindow.ui @@ -10,6 +10,9 @@ 300 + + true + Extensions diff --git a/include/defs.h b/include/defs.h index da11226..de94067 100644 --- a/include/defs.h +++ b/include/defs.h @@ -3,7 +3,7 @@ // vnrhook/defs.h // 8/23/2013 jichi -#define ITH_DLL L"vnrhook.dll" +#define ITH_DLL L"vnrhook" // Pipes From 5caf42a6b1d2a9e41d145437d410955c6d2e171a Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Thu, 1 Nov 2018 18:47:46 -0400 Subject: [PATCH 6/7] kill everything when mainwindow is closed --- GUI/mainwindow.cpp | 5 +++++ GUI/mainwindow.h | 1 + 2 files changed, 6 insertions(+) diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index c94c238..c523829 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -50,6 +50,11 @@ MainWindow::~MainWindow() Host::Close(); } +void MainWindow::closeEvent(QCloseEvent*) +{ + QCoreApplication::quit(); // Need to do this to kill any windows that might've been made by extensions +} + void MainWindow::AddProcess(unsigned processId) { processCombo->addItem(QString::number(processId, 16).toUpper() + ": " + GetModuleName(processId)); diff --git a/GUI/mainwindow.h b/GUI/mainwindow.h index 9494492..a9bd8c4 100644 --- a/GUI/mainwindow.h +++ b/GUI/mainwindow.h @@ -50,6 +50,7 @@ private: DWORD GetSelectedProcessId(); std::unordered_map GetMiscInfo(TextThread* thread); QVector GetAllHooks(DWORD processId); + void closeEvent(QCloseEvent*); Ui::MainWindow* ui; QSettings settings = QSettings("Textractor.ini", QSettings::IniFormat); From 7696d45475ce2d2b8d256fda8d8f17619c130f0c Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Thu, 1 Nov 2018 18:54:28 -0400 Subject: [PATCH 7/7] ui touchup --- GUI/extenwindow.ui | 1 + GUI/mainwindow.ui | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/GUI/extenwindow.ui b/GUI/extenwindow.ui index d6273c3..b6fbe41 100644 --- a/GUI/extenwindow.ui +++ b/GUI/extenwindow.ui @@ -81,6 +81,7 @@ QPushButton, QComboBox + diff --git a/GUI/mainwindow.ui b/GUI/mainwindow.ui index e3aaf74..692749d 100644 --- a/GUI/mainwindow.ui +++ b/GUI/mainwindow.ui @@ -140,7 +140,7 @@ QPushButton, QComboBox - +