implement basic gui
This commit is contained in:
parent
fe30b77a44
commit
97fe9800a6
@ -1,6 +1,8 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include "QTextBrowser"
|
||||
#include "QMessageBox"
|
||||
#include "QComboBox"
|
||||
#include "QLineEdit"
|
||||
#include "QTableWidget"
|
||||
#include "QInputDialog"
|
||||
@ -9,46 +11,98 @@
|
||||
#include <Psapi.h>
|
||||
#include "../texthook/host.h"
|
||||
|
||||
QTableWidget* processList;
|
||||
QMainWindow* mainWindow;
|
||||
QComboBox* processCombo;
|
||||
QComboBox* ttCombo;
|
||||
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);
|
||||
}
|
||||
|
||||
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) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::MainWindow)
|
||||
{
|
||||
Host::Start();
|
||||
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::RegisterProcessAttachCallback([](DWORD processId)
|
||||
{
|
||||
processList->insertRow(processList->rowCount());
|
||||
processList->setItem(processList->rowCount() - 1, 0, new QTableWidgetItem(QString::number(processId)));
|
||||
processList->setItem(processList->rowCount() - 1, 1, new QTableWidgetItem(GetModuleName(processId)));
|
||||
});
|
||||
Host::Start();
|
||||
Host::RegisterProcessAttachCallback(AddProcess);
|
||||
Host::RegisterProcessDetachCallback(RemoveProcess);
|
||||
Host::RegisterThreadCreateCallback(AddThread);
|
||||
Host::RegisterThreadRemoveCallback(RemoveThread);
|
||||
Host::Open();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
Host::Close();
|
||||
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()
|
||||
{
|
||||
//processList->insertRow(processList->rowCount());
|
||||
//processList->setItem(processList->rowCount() - 1, 0, new QTableWidgetItem(QString::number(6000)));
|
||||
Host::InjectProcess(QInputDialog::getInt(this, "Process ID?", ""));
|
||||
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)
|
||||
{
|
||||
textOutput->setText(QString::fromWCharArray(Host::GetThread(index)->GetStore().c_str()));
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <Windows.h>
|
||||
#include "../texthook/textthread.h"
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
@ -17,11 +19,17 @@ public:
|
||||
~MainWindow();
|
||||
|
||||
private slots:
|
||||
|
||||
void on_attachButton_clicked();
|
||||
void on_detachButton_clicked();
|
||||
void on_ttCombo_activated(int index);
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
};
|
||||
|
||||
void AddProcess(DWORD processId);
|
||||
void RemoveProcess(DWORD processId);
|
||||
void AddThread(TextThread* thread);
|
||||
void RemoveThread(TextThread* thread);
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
@ -15,20 +15,10 @@
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<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>
|
||||
<widget class="QFrame" name="processManager">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>2</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
@ -40,6 +30,9 @@
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="attachButton">
|
||||
<property name="text">
|
||||
@ -48,51 +41,44 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<widget class="QComboBox" name="processCombo"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="detachButton">
|
||||
<property name="text">
|
||||
<string>Currently attached to:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
<string>Detach from game</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="output">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>6</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QTableWidget" name="processList">
|
||||
<property name="columnCount">
|
||||
<number>2</number>
|
||||
<widget class="QComboBox" name="ttCombo"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTextBrowser" name="textOutput">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>5</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderDefaultSectionSize">
|
||||
<number>50</number>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderStretchLastSection">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>ID</string>
|
||||
</property>
|
||||
<property name="textAlignment">
|
||||
<set>AlignCenter</set>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
<property name="textAlignment">
|
||||
<set>AlignCenter</set>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
@ -74,13 +74,15 @@ namespace Host
|
||||
onCreate = onRemove = nullptr;
|
||||
nextThreadNumber = 0;
|
||||
// Console text thread
|
||||
(textThreadsByParams[{ 0, -1UL, -1UL, -1UL }] = new TextThread({ 0, -1UL, -1UL, -1UL }, nextThreadNumber++))->Status() |= USING_UNICODE;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@ -179,6 +181,7 @@ namespace Host
|
||||
|
||||
DLLEXPORT std::wstring GetHookName(DWORD pid, DWORD addr)
|
||||
{
|
||||
if (pid == 0) return L"Console";
|
||||
HOST_LOCK;
|
||||
std::string buffer = "";
|
||||
ProcessRecord pr = processRecordsByIds[pid];
|
||||
|
Loading…
x
Reference in New Issue
Block a user