eh who needs moc anyway

This commit is contained in:
Akash Mozumdar 2018-12-18 12:14:54 -05:00
parent 29822c89c8
commit 464c001773
10 changed files with 47 additions and 75 deletions

View File

@ -1,7 +1,7 @@
#include "extenwindow.h"
#include "ui_extenwindow.h"
#include "text.h"
#include "defs.h"
#include "text.h"
#include "types.h"
#include "misc.h"
#include <shared_mutex>
@ -83,6 +83,9 @@ ExtenWindow::ExtenWindow(QWidget* parent) :
ui->extenList->installEventFilter(this);
connect(ui->addButton, &QPushButton::clicked, [&] { Add(QFileDialog::getOpenFileName(this, SELECT_EXTENSION, "C:\\", EXTENSION_FILES)); });
connect(ui->rmvButton, &QPushButton::clicked, [&] { if (auto extenName = ui->extenList->currentItem()) Unload(extenName->text()); Sync(); });
for (auto extenName : QString(QAutoFile(EXTEN_SAVE_FILE, QIODevice::ReadOnly)->readAll()).split(">")) Load(extenName);
Sync();
}
@ -134,14 +137,3 @@ 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:\\", EXTENSION_FILES));
}
void ExtenWindow::on_rmvButton_clicked()
{
if (auto extenName = ui->extenList->currentItem()) Unload(extenName->text());
Sync();
}

View File

@ -1,7 +1,6 @@
#pragma once
#include "qtcommon.h"
#include <QListWidget>
#include <QDragEnterEvent>
#include <QDropEvent>
@ -14,16 +13,10 @@ bool DispatchSentenceToExtensions(std::wstring& sentence, std::unordered_map<std
class ExtenWindow : public QMainWindow
{
Q_OBJECT
public:
explicit ExtenWindow(QWidget* parent = nullptr);
~ExtenWindow();
private slots:
void on_addButton_clicked();
void on_rmvButton_clicked();
private:
void Add(QFileInfo extenFile);
void Sync();

View File

@ -19,11 +19,6 @@ TextThread::~TextThread()
OnDestroy(this);
}
std::wstring TextThread::GetStorage()
{
return storage->c_str();
}
void TextThread::AddSentence(std::wstring sentence)
{
if (Output(this, sentence)) storage->append(sentence);

View File

@ -19,10 +19,10 @@ public:
TextThread(ThreadParam tp, HookParam hp, std::optional<std::wstring> name = {});
~TextThread();
std::wstring GetStorage();
void AddSentence(std::wstring sentence);
void Push(const BYTE* data, int len);
const ThreadSafePtr<std::wstring> storage;
const int64_t handle;
const std::wstring name;
const ThreadParam tp;
@ -32,7 +32,6 @@ private:
void Flush();
struct TimerDeleter { void operator()(void* h) { DeleteTimerQueueTimer(NULL, h, INVALID_HANDLE_VALUE); } };
ThreadSafePtr<std::wstring> storage;
std::wstring buffer;
std::unordered_set<wchar_t> repeatingChars;
std::mutex bufferMutex;

View File

@ -1,5 +1,6 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "defs.h"
#include "text.h"
#include "extenwindow.h"
#include "setdialog.h"
@ -7,8 +8,6 @@
#include "host/util.h"
#include <Psapi.h>
#include <winhttp.h>
#include <QFrame>
#include <QLayout>
#include <QPushButton>
#include <QInputDialog>
@ -19,12 +18,12 @@ MainWindow::MainWindow(QWidget *parent) :
{
ui->setupUi(this);
for (auto[text, slot] : Array<std::tuple<QString, void(MainWindow::*)()>>{
{ ATTACH, &MainWindow::on_attachButton_clicked },
{ DETACH, &MainWindow::on_detachButton_clicked },
{ ADD_HOOK, &MainWindow::on_hookButton_clicked },
{ SAVE_HOOKS, &MainWindow::on_saveButton_clicked },
{ SETTINGS, &MainWindow::on_setButton_clicked },
{ EXTENSIONS, &MainWindow::on_extenButton_clicked }
{ ATTACH, &MainWindow::AttachProcess },
{ DETACH, &MainWindow::DetachProcess },
{ ADD_HOOK, &MainWindow::AddHook },
{ SAVE_HOOKS, &MainWindow::SaveHooks },
{ SETTINGS, &MainWindow::Settings },
{ EXTENSIONS, &MainWindow::Extensions }
})
{
QPushButton* button = new QPushButton(ui->processFrame);
@ -34,10 +33,14 @@ MainWindow::MainWindow(QWidget *parent) :
}
ui->processLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding));
connect(ui->ttCombo, (void(QComboBox::*)(int))&QComboBox::activated, this, &MainWindow::ViewThread);
QSettings settings(CONFIG_FILE, QSettings::IniFormat);
if (settings.contains(WINDOW)) setGeometry(settings.value(WINDOW).toRect());
if (settings.contains(FLUSH_DELAY)) TextThread::flushDelay = settings.value(FLUSH_DELAY).toInt();
if (settings.contains(MAX_BUFFER_SIZE)) TextThread::maxBufferSize = settings.value(MAX_BUFFER_SIZE).toInt();
if (settings.contains(DEFAULT_CODEPAGE)) TextThread::defaultCodepage = settings.value(DEFAULT_CODEPAGE).toInt();
settings.sync();
Host::Start(
[&](DWORD processId) { ProcessConnected(processId); },
@ -68,6 +71,7 @@ MainWindow::MainWindow(QWidget *parent) :
MainWindow::~MainWindow()
{
QSettings settings(CONFIG_FILE, QSettings::IniFormat);
settings.setValue(WINDOW, geometry());
settings.sync();
delete ui;
@ -122,7 +126,7 @@ void MainWindow::ThreadRemoved(TextThread* thread)
if (threadIndex == ui->ttCombo->currentIndex())
{
ui->ttCombo->setCurrentIndex(0);
on_ttCombo_activated(0);
ViewThread(0);
}
ui->ttCombo->removeItem(threadIndex);
});
@ -184,7 +188,7 @@ std::unordered_map<std::string, int64_t> MainWindow::GetMiscInfo(TextThread* thr
};
}
void MainWindow::on_attachButton_clicked()
void MainWindow::AttachProcess()
{
QMultiHash<QString, DWORD> allProcesses;
DWORD allProcessIds[5000] = {}, spaceUsed = 0;
@ -201,12 +205,12 @@ void MainWindow::on_attachButton_clicked()
else for (auto processId : allProcesses.values(process)) Host::InjectProcess(processId);
}
void MainWindow::on_detachButton_clicked()
void MainWindow::DetachProcess()
{
Host::DetachProcess(GetSelectedProcessId());
}
void MainWindow::on_hookButton_clicked()
void MainWindow::AddHook()
{
bool ok;
QString hookCode = QInputDialog::getText(this, ADD_HOOK, CODE_INFODUMP, QLineEdit::Normal, "", &ok, Qt::WindowCloseButtonHint);
@ -215,7 +219,7 @@ void MainWindow::on_hookButton_clicked()
else Host::AddConsoleOutput(INVALID_CODE);
}
void MainWindow::on_saveButton_clicked()
void MainWindow::SaveHooks()
{
if (auto processName = Util::GetModuleFileName(GetSelectedProcessId()))
{
@ -231,19 +235,19 @@ void MainWindow::on_saveButton_clicked()
}
}
void MainWindow::on_setButton_clicked()
void MainWindow::Settings()
{
SetDialog(this).exec();
}
void MainWindow::on_extenButton_clicked()
void MainWindow::Extensions()
{
extenWindow->activateWindow();
extenWindow->showNormal();
}
void MainWindow::on_ttCombo_activated(int index)
void MainWindow::ViewThread(int index)
{
ui->textOutput->setPlainText(S(Host::GetThread(ParseTextThreadString(ui->ttCombo->itemText(index)))->GetStorage()));
ui->textOutput->setPlainText(S(Host::GetThread(ParseTextThreadString(ui->ttCombo->itemText(index)))->storage->c_str()));
ui->textOutput->moveCursor(QTextCursor::End);
}

View File

@ -2,10 +2,6 @@
#include "qtcommon.h"
#include "host/host.h"
#include "defs.h"
#include <QPlainTextEdit>
#include <QComboBox>
#include <QSettings>
namespace Ui
{
@ -14,23 +10,13 @@ namespace Ui
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
void on_attachButton_clicked();
void on_detachButton_clicked();
void on_hookButton_clicked();
void on_saveButton_clicked();
void on_setButton_clicked();
void on_extenButton_clicked();
void on_ttCombo_activated(int index);
private:
void closeEvent(QCloseEvent*);
void closeEvent(QCloseEvent*) override;
void InvokeOnMainThread(std::function<void()> f);
void ProcessConnected(DWORD processId);
void ProcessDisconnected(DWORD processId);
@ -41,8 +27,14 @@ private:
ThreadParam ParseTextThreadString(QString ttString);
DWORD GetSelectedProcessId();
std::unordered_map<std::string, int64_t> GetMiscInfo(TextThread* thread);
void AttachProcess();
void DetachProcess();
void AddHook();
void SaveHooks();
void Settings();
void Extensions();
void ViewThread(int index);
Ui::MainWindow* ui;
QSettings settings = QSettings(CONFIG_FILE, QSettings::IniFormat);
QWidget* extenWindow;
};

View File

@ -9,3 +9,4 @@
#include <QFile>
#include <QFileInfo>
#include <QRegularExpression>
#include <QSettings>

View File

@ -3,7 +3,6 @@
#include "defs.h"
#include "text.h"
#include "host/host.h"
#include <QSettings>
SetDialog::SetDialog(QWidget* parent) :
QDialog(parent, Qt::WindowCloseButtonHint),
@ -21,14 +20,13 @@ SetDialog::SetDialog(QWidget* parent) :
spinBox->setValue(value);
ui->layout->insertRow(0, label, spinBox);
}
connect(ui->buttonBox, &QDialogButtonBox::accepted, [&] { edited = true; });
}
SetDialog::~SetDialog()
{
delete ui;
}
void SetDialog::on_buttonBox_accepted()
if (edited)
{
QSettings settings(CONFIG_FILE, QSettings::IniFormat);
settings.setValue(FLUSH_DELAY, TextThread::flushDelay = flushDelay->value());
@ -36,3 +34,5 @@ void SetDialog::on_buttonBox_accepted()
settings.setValue(DEFAULT_CODEPAGE, TextThread::defaultCodepage = defaultCodepage->value());
settings.sync();
}
delete ui;
}

View File

@ -10,18 +10,14 @@ namespace Ui
class SetDialog : public QDialog
{
Q_OBJECT
public:
explicit SetDialog(QWidget* parent = nullptr);
~SetDialog();
private slots:
void on_buttonBox_accepted();
private:
Ui::SetDialog* ui;
QSpinBox* flushDelay;
QSpinBox* maxBufferSize;
QSpinBox* defaultCodepage;
bool edited = false;
};

View File

@ -10,7 +10,7 @@ class ThreadSafePtr
{
public:
template <typename ...Args> ThreadSafePtr(Args ...args) : ptr(new E(args...)), mtxPtr(new M) {}
auto operator->()
auto operator->() const
{
struct
{