2018-07-21 15:40:16 -07:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "ui_mainwindow.h"
|
2018-07-24 10:39:02 -07:00
|
|
|
#include "QCoreApplication"
|
2018-07-23 22:57:54 -07:00
|
|
|
#include "QTextBrowser"
|
2018-07-22 16:53:51 -07:00
|
|
|
#include "QMessageBox"
|
2018-07-23 22:57:54 -07:00
|
|
|
#include "QComboBox"
|
2018-07-23 12:25:02 -07:00
|
|
|
#include "QLineEdit"
|
|
|
|
#include "QInputDialog"
|
2018-07-24 10:39:02 -07:00
|
|
|
#include <QCursor>
|
|
|
|
#include <Qt>
|
2018-07-22 16:53:51 -07:00
|
|
|
#include <Windows.h>
|
2018-07-23 12:25:02 -07:00
|
|
|
#include <qdebug.h>
|
|
|
|
#include <Psapi.h>
|
2018-07-22 16:53:51 -07:00
|
|
|
#include "../texthook/host.h"
|
2018-07-21 15:40:16 -07:00
|
|
|
|
2018-07-23 22:57:54 -07:00
|
|
|
QMainWindow* mainWindow;
|
|
|
|
QComboBox* processCombo;
|
|
|
|
QComboBox* ttCombo;
|
|
|
|
QTextBrowser* textOutput;
|
2018-07-23 12:25:02 -07:00
|
|
|
|
|
|
|
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);
|
2018-07-23 22:57:54 -07:00
|
|
|
CloseHandle(handle);
|
2018-07-23 12:25:02 -07:00
|
|
|
return QString::fromWCharArray(wcsrchr(buffer, L'\\') + 1);
|
|
|
|
}
|
|
|
|
|
2018-07-23 22:57:54 -07:00
|
|
|
QString ProcessString(DWORD processId)
|
2018-07-23 12:25:02 -07:00
|
|
|
{
|
2018-07-23 22:57:54 -07:00
|
|
|
return QString("%1: %2").arg(QString::number(processId), GetModuleName(processId));
|
|
|
|
}
|
|
|
|
|
|
|
|
QString TextThreadString(TextThread* thread)
|
|
|
|
{
|
|
|
|
ThreadParameter tp = thread->GetThreadParameter();
|
2018-07-24 10:39:02 -07:00
|
|
|
return QString("%1:%2:%3:%4:%5: ").arg(
|
2018-07-23 22:57:54 -07:00
|
|
|
QString::number(thread->Number()),
|
|
|
|
QString::number(tp.pid),
|
|
|
|
QString::number(tp.hook, 16),
|
|
|
|
QString::number(tp.retn, 16),
|
2018-07-24 10:39:02 -07:00
|
|
|
QString::number(tp.spl, 16)
|
|
|
|
).toUpper() + QString::fromWCharArray(Host::GetHookName(tp.pid, tp.hook).c_str());
|
2018-07-23 12:25:02 -07:00
|
|
|
}
|
|
|
|
|
2018-07-21 15:40:16 -07:00
|
|
|
MainWindow::MainWindow(QWidget *parent) :
|
|
|
|
QMainWindow(parent),
|
2018-07-24 10:39:02 -07:00
|
|
|
ui(new Ui::MainWindow),
|
|
|
|
hostSignaller(new HostSignaller)
|
2018-07-21 15:40:16 -07:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2018-07-23 22:57:54 -07:00
|
|
|
mainWindow = this;
|
|
|
|
processCombo = mainWindow->findChild<QComboBox*>("processCombo");
|
|
|
|
ttCombo = mainWindow->findChild<QComboBox*>("ttCombo");
|
2018-07-24 10:39:02 -07:00
|
|
|
textOutput = mainWindow->findChild<QTextBrowser*>("textOutput");
|
2018-07-23 12:25:02 -07:00
|
|
|
|
2018-07-24 10:39:02 -07:00
|
|
|
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);
|
2018-07-23 12:25:02 -07:00
|
|
|
Host::Open();
|
2018-07-21 15:40:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
{
|
2018-07-23 22:57:54 -07:00
|
|
|
Host::Close();
|
2018-07-24 10:39:02 -07:00
|
|
|
delete hostSignaller;
|
2018-07-21 15:40:16 -07:00
|
|
|
delete ui;
|
|
|
|
}
|
2018-07-22 16:53:51 -07:00
|
|
|
|
2018-07-24 10:39:02 -07:00
|
|
|
void MainWindow::AddProcess(unsigned int processId)
|
2018-07-23 22:57:54 -07:00
|
|
|
{
|
2018-07-24 19:00:10 -07:00
|
|
|
processCombo->addItem(ProcessString(processId));
|
2018-07-23 22:57:54 -07:00
|
|
|
}
|
|
|
|
|
2018-07-24 10:39:02 -07:00
|
|
|
void MainWindow::RemoveProcess(unsigned int processId)
|
2018-07-23 22:57:54 -07:00
|
|
|
{
|
2018-07-24 19:00:10 -07:00
|
|
|
processCombo->removeItem(processCombo->findText(QString::number(processId), Qt::MatchStartsWith));
|
2018-07-23 22:57:54 -07:00
|
|
|
}
|
|
|
|
|
2018-07-24 10:39:02 -07:00
|
|
|
void MainWindow::AddThread(TextThread* thread)
|
2018-07-23 22:57:54 -07:00
|
|
|
{
|
|
|
|
ttCombo->addItem(TextThreadString(thread));
|
|
|
|
}
|
|
|
|
|
2018-07-24 10:39:02 -07:00
|
|
|
void MainWindow::RemoveThread(TextThread* thread)
|
2018-07-23 22:57:54 -07:00
|
|
|
{
|
2018-07-24 19:00:10 -07:00
|
|
|
int threadIndex = ttCombo->findText(QString::number(thread->Number()), Qt::MatchStartsWith);
|
|
|
|
ttCombo->removeItem(threadIndex);
|
|
|
|
if (threadIndex == ttCombo->currentIndex())
|
|
|
|
{
|
|
|
|
ttCombo->setCurrentIndex(0);
|
|
|
|
on_ttCombo_activated(0);
|
|
|
|
}
|
2018-07-24 10:39:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::ThreadOutput(TextThread* thread, QString output)
|
|
|
|
{
|
|
|
|
if (TextThreadString(thread) == ttCombo->currentText())
|
|
|
|
{
|
|
|
|
textOutput->moveCursor(QTextCursor::End);
|
|
|
|
textOutput->insertPlainText(output);
|
|
|
|
textOutput->moveCursor(QTextCursor::End);
|
|
|
|
}
|
2018-07-23 22:57:54 -07:00
|
|
|
}
|
|
|
|
|
2018-07-23 12:25:02 -07:00
|
|
|
void MainWindow::on_attachButton_clicked()
|
2018-07-22 16:53:51 -07:00
|
|
|
{
|
2018-07-23 22:57:54 -07:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_ttCombo_activated(int index)
|
|
|
|
{
|
2018-07-24 10:39:02 -07:00
|
|
|
textOutput->setText(QString::fromWCharArray(Host::GetThread(ttCombo->itemText(index).split(":")[0].toInt())->GetStore().c_str()));
|
2018-07-22 16:53:51 -07:00
|
|
|
}
|