implement basic gui

This commit is contained in:
Akash Mozumdar 2018-07-23 22:57:54 -07:00
parent fe30b77a44
commit 97fe9800a6
4 changed files with 117 additions and 66 deletions

View File

@ -1,6 +1,8 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include "QTextBrowser"
#include "QMessageBox" #include "QMessageBox"
#include "QComboBox"
#include "QLineEdit" #include "QLineEdit"
#include "QTableWidget" #include "QTableWidget"
#include "QInputDialog" #include "QInputDialog"
@ -9,46 +11,98 @@
#include <Psapi.h> #include <Psapi.h>
#include "../texthook/host.h" #include "../texthook/host.h"
QTableWidget* processList; QMainWindow* mainWindow;
QComboBox* processCombo;
QComboBox* ttCombo;
QTextBrowser* textOutput;
QString GetModuleName(DWORD processId, HMODULE module = NULL) QString GetModuleName(DWORD processId, HMODULE module = NULL)
{ {
HANDLE handle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processId); HANDLE handle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processId);
wchar_t buffer[MAX_PATH]; wchar_t buffer[MAX_PATH];
GetModuleFileNameExW(handle, module, buffer, MAX_PATH); GetModuleFileNameExW(handle, module, buffer, MAX_PATH);
CloseHandle(handle);
return QString::fromWCharArray(wcsrchr(buffer, L'\\') + 1); return QString::fromWCharArray(wcsrchr(buffer, L'\\') + 1);
} }
void OnProcessAttach(DWORD processId) QString ProcessString(DWORD processId)
{ {
processList->setItem(processList->rowCount(), 0, new QTableWidgetItem(QString::number(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:%6").arg(
QString::number(thread->Number()),
QString::number(tp.pid),
QString::number(tp.hook, 16),
QString::number(tp.retn, 16),
QString::number(tp.spl, 16),
QString::fromWCharArray(Host::GetHookName(tp.pid, tp.hook).c_str())
);
} }
MainWindow::MainWindow(QWidget *parent) : MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
ui(new Ui::MainWindow) ui(new Ui::MainWindow)
{ {
Host::Start();
ui->setupUi(this); ui->setupUi(this);
mainWindow = this;
processCombo = mainWindow->findChild<QComboBox*>("processCombo");
ttCombo = mainWindow->findChild<QComboBox*>("ttCombo");
textOutput = this->findChild<QTextBrowser*>("textOutput");
processList = this->findChild<QTableWidget*>("processList"); Host::Start();
Host::RegisterProcessAttachCallback([](DWORD processId) Host::RegisterProcessAttachCallback(AddProcess);
{ Host::RegisterProcessDetachCallback(RemoveProcess);
processList->insertRow(processList->rowCount()); Host::RegisterThreadCreateCallback(AddThread);
processList->setItem(processList->rowCount() - 1, 0, new QTableWidgetItem(QString::number(processId))); Host::RegisterThreadRemoveCallback(RemoveThread);
processList->setItem(processList->rowCount() - 1, 1, new QTableWidgetItem(GetModuleName(processId)));
});
Host::Open(); Host::Open();
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
Host::Close();
delete ui; delete ui;
} }
void AddProcess(DWORD processId)
{
processCombo->addItem(ProcessString(processId));
}
void RemoveProcess(DWORD processId)
{
processCombo->removeItem(processCombo->findText(ProcessString(processId)));
}
void AddThread(TextThread* thread)
{
ttCombo->addItem(TextThreadString(thread));
thread->RegisterOutputCallBack([](auto thread, auto data)
{
if (ttCombo->currentText() == TextThreadString(thread)) textOutput->append(QString::fromWCharArray(data.c_str()));
return data + L"\r\n";
});
}
void RemoveThread(TextThread* thread)
{
ttCombo->removeItem(ttCombo->findText(TextThreadString(thread)));
}
void MainWindow::on_attachButton_clicked() void MainWindow::on_attachButton_clicked()
{ {
//processList->insertRow(processList->rowCount()); Host::InjectProcess(QInputDialog::getInt(this, "Process ID?", "You can find this under Task Manager -> Details"));
//processList->setItem(processList->rowCount() - 1, 0, new QTableWidgetItem(QString::number(6000))); }
Host::InjectProcess(QInputDialog::getInt(this, "Process ID?", ""));
void MainWindow::on_detachButton_clicked()
{
Host::DetachProcess(processCombo->currentText().split(":")[0].toInt());
}
void MainWindow::on_ttCombo_activated(int index)
{
textOutput->setText(QString::fromWCharArray(Host::GetThread(index)->GetStore().c_str()));
} }

View File

@ -2,6 +2,8 @@
#define MAINWINDOW_H #define MAINWINDOW_H
#include <QMainWindow> #include <QMainWindow>
#include <Windows.h>
#include "../texthook/textthread.h"
namespace Ui namespace Ui
{ {
@ -17,11 +19,17 @@ public:
~MainWindow(); ~MainWindow();
private slots: private slots:
void on_attachButton_clicked(); void on_attachButton_clicked();
void on_detachButton_clicked();
void on_ttCombo_activated(int index);
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
}; };
void AddProcess(DWORD processId);
void RemoveProcess(DWORD processId);
void AddThread(TextThread* thread);
void RemoveThread(TextThread* thread);
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

View File

@ -15,20 +15,10 @@
</property> </property>
<widget class="QWidget" name="centralWidget"> <widget class="QWidget" name="centralWidget">
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QTextBrowser" name="textBrowser">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>5</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item> <item>
<widget class="QFrame" name="processManager"> <widget class="QFrame" name="processManager">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>2</horstretch> <horstretch>2</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -40,6 +30,9 @@
<enum>QFrame::Raised</enum> <enum>QFrame::Raised</enum>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLineEdit" name="lineEdit"/>
</item>
<item> <item>
<widget class="QPushButton" name="attachButton"> <widget class="QPushButton" name="attachButton">
<property name="text"> <property name="text">
@ -48,51 +41,44 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="label"> <widget class="QComboBox" name="processCombo"/>
<property name="sizePolicy"> </item>
<sizepolicy hsizetype="Preferred" vsizetype="Fixed"> <item>
<horstretch>0</horstretch> <widget class="QPushButton" name="detachButton">
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text"> <property name="text">
<string>Currently attached to:</string> <string>Detach from game</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property> </property>
</widget> </widget>
</item> </item>
</layout>
</widget>
</item>
<item> <item>
<widget class="QTableWidget" name="processList"> <widget class="QFrame" name="output">
<property name="columnCount"> <property name="sizePolicy">
<number>2</number> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>6</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property> </property>
<attribute name="horizontalHeaderDefaultSectionSize"> <property name="frameShape">
<number>50</number> <enum>QFrame::StyledPanel</enum>
</attribute>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string>ID</string>
</property> </property>
<property name="textAlignment"> <property name="frameShadow">
<set>AlignCenter</set> <enum>QFrame::Raised</enum>
</property> </property>
</column> <layout class="QVBoxLayout" name="verticalLayout_2">
<column> <item>
<property name="text"> <widget class="QComboBox" name="ttCombo"/>
<string>Name</string> </item>
<item>
<widget class="QTextBrowser" name="textOutput">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>5</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property> </property>
<property name="textAlignment">
<set>AlignCenter</set>
</property>
</column>
</widget> </widget>
</item> </item>
</layout> </layout>

View File

@ -74,13 +74,15 @@ namespace Host
onCreate = onRemove = nullptr; onCreate = onRemove = nullptr;
nextThreadNumber = 0; nextThreadNumber = 0;
// Console text thread // Console text thread
(textThreadsByParams[{ 0, -1UL, -1UL, -1UL }] = new TextThread({ 0, -1UL, -1UL, -1UL }, nextThreadNumber++))->Status() |= USING_UNICODE;
return true; return true;
} }
} }
DLLEXPORT void Open() DLLEXPORT void Open()
{ {
TextThread* console = textThreadsByParams[{ 0, -1UL, -1UL, -1UL }] = new TextThread({ 0, -1UL, -1UL, -1UL }, nextThreadNumber++);
console->Status() |= USING_UNICODE;
if (onCreate) onCreate(console);
CreateNewPipe(); CreateNewPipe();
} }
@ -179,6 +181,7 @@ namespace Host
DLLEXPORT std::wstring GetHookName(DWORD pid, DWORD addr) DLLEXPORT std::wstring GetHookName(DWORD pid, DWORD addr)
{ {
if (pid == 0) return L"Console";
HOST_LOCK; HOST_LOCK;
std::string buffer = ""; std::string buffer = "";
ProcessRecord pr = processRecordsByIds[pid]; ProcessRecord pr = processRecordsByIds[pid];