From d0b1efd0335900e3b497ed140731e72f2656147c Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Wed, 25 Jul 2018 10:46:59 -0700 Subject: [PATCH] tabs to spaces and bugfixes --- CMakeLists.txt | 5 -- GUI/hostsignaller.cpp | 26 +++++----- GUI/hostsignaller.h | 14 +++--- GUI/main.cpp | 10 ++-- GUI/mainwindow.cpp | 107 ++++++++++++++++++++++-------------------- GUI/mainwindow.h | 30 ++++++------ texthook/host.cc | 2 +- 7 files changed, 96 insertions(+), 98 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 050bff0..db236f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,11 +19,6 @@ add_definitions( /DITH_HAS_CRT ) -include_directories( - . - texthook -) - set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/Debug) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/Debug) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/Debug) diff --git a/GUI/hostsignaller.cpp b/GUI/hostsignaller.cpp index fb5a9a2..fb52831 100644 --- a/GUI/hostsignaller.cpp +++ b/GUI/hostsignaller.cpp @@ -3,17 +3,17 @@ void HostSignaller::Initialize() { - Host::RegisterProcessAttachCallback([&](DWORD pid){ emit AddProcess(pid); }); - Host::RegisterProcessDetachCallback([&](DWORD pid){ emit RemoveProcess(pid); }); - Host::RegisterThreadCreateCallback([&](TextThread* thread) - { - emit AddThread(thread); - thread->RegisterOutputCallBack([&](TextThread* thread, std::wstring output) - { - //output = DispatchToExtensions(output); - emit ThreadOutput(thread, QString::fromWCharArray(output.c_str())); - return output; - }); - }); - Host::RegisterThreadRemoveCallback([&](TextThread* thread){ emit RemoveThread(thread); }); + Host::RegisterProcessAttachCallback([&](DWORD pid){ emit AddProcess(pid); }); + Host::RegisterProcessDetachCallback([&](DWORD pid){ emit RemoveProcess(pid); }); + Host::RegisterThreadCreateCallback([&](TextThread* thread) + { + emit AddThread(thread); + thread->RegisterOutputCallBack([&](TextThread* thread, std::wstring output) + { + //output = DispatchToExtensions(output); + emit ThreadOutput(thread, QString::fromWCharArray(output.c_str())); + return output; + }); + }); + Host::RegisterThreadRemoveCallback([&](TextThread* thread){ emit RemoveThread(thread); }); } diff --git a/GUI/hostsignaller.h b/GUI/hostsignaller.h index 537d3a5..79d8ccb 100644 --- a/GUI/hostsignaller.h +++ b/GUI/hostsignaller.h @@ -8,17 +8,17 @@ // Artikash 7/24/2018: This class is a workaround for the fact that Qt only lets me manipulate the GUI in the main thread. class HostSignaller : public QObject { - Q_OBJECT + Q_OBJECT public: - void Initialize(); + void Initialize(); signals: - void AddProcess(unsigned int processId); - void RemoveProcess(unsigned int processId); - void AddThread(TextThread* thread); - void RemoveThread(TextThread* thread); - void ThreadOutput(TextThread* thread, QString output); + void AddProcess(unsigned int processId); + void RemoveProcess(unsigned int processId); + void AddThread(TextThread* thread); + void RemoveThread(TextThread* thread); + void ThreadOutput(TextThread* thread, QString output); }; #endif // HOSTSIGNALLER_H diff --git a/GUI/main.cpp b/GUI/main.cpp index 0058c1d..ef0ae07 100644 --- a/GUI/main.cpp +++ b/GUI/main.cpp @@ -4,10 +4,10 @@ int main(int argc, char *argv[]) { - if (!Host::Start()) return 1; - QApplication a(argc, argv); - MainWindow w; - w.show(); + if (!Host::Start()) return 1; + QApplication a(argc, argv); + MainWindow w; + w.show(); - return a.exec(); + return a.exec(); } diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index 6e460db..f642880 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -20,105 +20,108 @@ QTextBrowser* textOutput; QString GetModuleName(DWORD processId, HMODULE module = NULL) { - HANDLE handle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processId); - wchar_t buffer[MAX_PATH]; - GetModuleFileNameExW(handle, module, buffer, MAX_PATH); - CloseHandle(handle); - return QString::fromWCharArray(wcsrchr(buffer, L'\\') + 1); + HANDLE handle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processId); + wchar_t buffer[MAX_PATH]; + GetModuleFileNameExW(handle, module, buffer, MAX_PATH); + CloseHandle(handle); + return QString::fromWCharArray(wcsrchr(buffer, L'\\') + 1); } QString ProcessString(DWORD processId) { - return QString("%1: %2").arg(QString::number(processId), GetModuleName(processId)); + return QString("%1: %2").arg(QString::number(processId), GetModuleName(processId)); } QString TextThreadString(TextThread* thread) { - ThreadParameter tp = thread->GetThreadParameter(); - return QString("%1:%2:%3:%4:%5: ").arg( - QString::number(thread->Number()), - QString::number(tp.pid), - QString::number(tp.hook, 16), - QString::number(tp.retn, 16), - QString::number(tp.spl, 16) - ).toUpper() + QString::fromWCharArray(Host::GetHookName(tp.pid, tp.hook).c_str()); + ThreadParameter tp = thread->GetThreadParameter(); + return QString("%1:%2:%3:%4:%5: ").arg( + QString::number(thread->Number()), + QString::number(tp.pid), + QString::number(tp.hook, 16), + QString::number(tp.retn, 16), + QString::number(tp.spl, 16) + ).toUpper(); } MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::MainWindow), - hostSignaller(new HostSignaller) + QMainWindow(parent), + ui(new Ui::MainWindow), + hostSignaller(new HostSignaller) { - ui->setupUi(this); - mainWindow = this; - processCombo = mainWindow->findChild("processCombo"); - ttCombo = mainWindow->findChild("ttCombo"); - textOutput = mainWindow->findChild("textOutput"); + ui->setupUi(this); + mainWindow = this; + processCombo = mainWindow->findChild("processCombo"); + ttCombo = mainWindow->findChild("ttCombo"); + textOutput = mainWindow->findChild("textOutput"); - hostSignaller->Initialize(); - connect(hostSignaller, &HostSignaller::AddProcess, this, &MainWindow::AddProcess); - connect(hostSignaller, &HostSignaller::RemoveProcess, this, &MainWindow::RemoveProcess); - connect(hostSignaller, &HostSignaller::AddThread, this, &MainWindow::AddThread); - connect(hostSignaller, &HostSignaller::RemoveThread, this, &MainWindow::RemoveThread); - connect(hostSignaller, &HostSignaller::ThreadOutput, this, &MainWindow::ThreadOutput); - Host::Open(); + hostSignaller->Initialize(); + connect(hostSignaller, &HostSignaller::AddProcess, this, &MainWindow::AddProcess); + connect(hostSignaller, &HostSignaller::RemoveProcess, this, &MainWindow::RemoveProcess); + connect(hostSignaller, &HostSignaller::AddThread, this, &MainWindow::AddThread); + connect(hostSignaller, &HostSignaller::RemoveThread, this, &MainWindow::RemoveThread); + connect(hostSignaller, &HostSignaller::ThreadOutput, this, &MainWindow::ThreadOutput); + Host::Open(); } MainWindow::~MainWindow() { - Host::Close(); - delete hostSignaller; - delete ui; + Host::Close(); + delete hostSignaller; + delete ui; } void MainWindow::AddProcess(unsigned int processId) { - processCombo->addItem(ProcessString(processId)); + processCombo->addItem(ProcessString(processId)); } void MainWindow::RemoveProcess(unsigned int processId) { - processCombo->removeItem(processCombo->findText(QString::number(processId), Qt::MatchStartsWith)); + processCombo->removeItem(processCombo->findText(QString::number(processId) + ":", Qt::MatchStartsWith)); } void MainWindow::AddThread(TextThread* thread) { - ttCombo->addItem(TextThreadString(thread)); + ttCombo->addItem( + TextThreadString(thread) + + QString::fromWCharArray(Host::GetHookName(thread->GetThreadParameter().pid, thread->GetThreadParameter().hook).c_str()) + ); } void MainWindow::RemoveThread(TextThread* thread) { - int threadIndex = ttCombo->findText(QString::number(thread->Number()), Qt::MatchStartsWith); - ttCombo->removeItem(threadIndex); - if (threadIndex == ttCombo->currentIndex()) - { - ttCombo->setCurrentIndex(0); - on_ttCombo_activated(0); - } - delete thread; + int threadIndex = ttCombo->findText(QString::number(thread->Number()) + ":", Qt::MatchStartsWith); + ttCombo->removeItem(threadIndex); + if (threadIndex == ttCombo->currentIndex()) + { + ttCombo->setCurrentIndex(0); + on_ttCombo_activated(0); + } } void MainWindow::ThreadOutput(TextThread* thread, QString output) { - if (TextThreadString(thread) == ttCombo->currentText()) - { - textOutput->moveCursor(QTextCursor::End); - textOutput->insertPlainText(output); - textOutput->moveCursor(QTextCursor::End); - } + if (ttCombo->currentText().startsWith(TextThreadString(thread))) + { + textOutput->moveCursor(QTextCursor::End); + textOutput->insertPlainText(output); + textOutput->moveCursor(QTextCursor::End); + } } void MainWindow::on_attachButton_clicked() { - Host::InjectProcess(QInputDialog::getInt(this, "Process ID?", "You can find this under Task Manager -> Details")); + Host::InjectProcess(QInputDialog::getInt(this, "Process ID?", "You can find this under Task Manager -> Details")); } void MainWindow::on_detachButton_clicked() { - Host::DetachProcess(processCombo->currentText().split(":")[0].toInt()); + Host::DetachProcess(processCombo->currentText().split(":")[0].toInt()); } void MainWindow::on_ttCombo_activated(int index) { - textOutput->setText(QString::fromWCharArray(Host::GetThread(ttCombo->itemText(index).split(":")[0].toInt())->GetStore().c_str())); + textOutput->setText(QString::fromWCharArray(Host::GetThread(ttCombo->itemText(index).split(":")[0].toInt())->GetStore().c_str())); + textOutput->moveCursor(QTextCursor::End); } diff --git a/GUI/mainwindow.h b/GUI/mainwindow.h index 6169cbd..91212e8 100644 --- a/GUI/mainwindow.h +++ b/GUI/mainwindow.h @@ -8,31 +8,31 @@ namespace Ui { - class MainWindow; + class MainWindow; } class MainWindow : public QMainWindow { - Q_OBJECT + Q_OBJECT public: - explicit MainWindow(QWidget *parent = nullptr); - ~MainWindow(); + explicit MainWindow(QWidget *parent = nullptr); + ~MainWindow(); - QString ProcessOutput(TextThread *thread, QString output); + QString ProcessOutput(TextThread *thread, QString output); private slots: - void on_attachButton_clicked(); - void on_detachButton_clicked(); - void on_ttCombo_activated(int index); - void AddProcess(unsigned int processId); - void RemoveProcess(unsigned int processId); - void AddThread(TextThread* thread); - void RemoveThread(TextThread* thread); - void ThreadOutput(TextThread* thread, QString output); + void on_attachButton_clicked(); + void on_detachButton_clicked(); + void on_ttCombo_activated(int index); + void AddProcess(unsigned int processId); + void RemoveProcess(unsigned int processId); + void AddThread(TextThread* thread); + void RemoveThread(TextThread* thread); + void ThreadOutput(TextThread* thread, QString output); private: - Ui::MainWindow *ui; - HostSignaller* hostSignaller; + Ui::MainWindow *ui; + HostSignaller* hostSignaller; }; #endif // MAINWINDOW_H diff --git a/texthook/host.cc b/texthook/host.cc index 6c6ca8e..2b5627f 100644 --- a/texthook/host.cc +++ b/texthook/host.cc @@ -235,7 +235,7 @@ void RemoveThreads(bool(*RemoveIf)(ThreadParameter, ThreadParameter), ThreadPara { if (onRemove) onRemove(i.second); //delete i.second; // Artikash 7/24/2018: FIXME: Qt GUI updates on another thread, so I can't delete this yet. - //i.second->Clear(); // Temp workaround to free some memory. + i.second->Clear(); // Temp workaround to free some memory. removedThreads.push_back(i.first); } for (auto i : removedThreads) textThreadsByParams.erase(i);