tabs to spaces and bugfixes

This commit is contained in:
Akash Mozumdar 2018-07-25 10:46:59 -07:00
parent 9c5be4be80
commit d0b1efd033
7 changed files with 96 additions and 98 deletions

View File

@ -19,11 +19,6 @@ add_definitions(
/DITH_HAS_CRT /DITH_HAS_CRT
) )
include_directories(
.
texthook
)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/Debug) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/Debug)
set(CMAKE_LIBRARY_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) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/Debug)

View File

@ -3,17 +3,17 @@
void HostSignaller::Initialize() void HostSignaller::Initialize()
{ {
Host::RegisterProcessAttachCallback([&](DWORD pid){ emit AddProcess(pid); }); Host::RegisterProcessAttachCallback([&](DWORD pid){ emit AddProcess(pid); });
Host::RegisterProcessDetachCallback([&](DWORD pid){ emit RemoveProcess(pid); }); Host::RegisterProcessDetachCallback([&](DWORD pid){ emit RemoveProcess(pid); });
Host::RegisterThreadCreateCallback([&](TextThread* thread) Host::RegisterThreadCreateCallback([&](TextThread* thread)
{ {
emit AddThread(thread); emit AddThread(thread);
thread->RegisterOutputCallBack([&](TextThread* thread, std::wstring output) thread->RegisterOutputCallBack([&](TextThread* thread, std::wstring output)
{ {
//output = DispatchToExtensions(output); //output = DispatchToExtensions(output);
emit ThreadOutput(thread, QString::fromWCharArray(output.c_str())); emit ThreadOutput(thread, QString::fromWCharArray(output.c_str()));
return output; return output;
}); });
}); });
Host::RegisterThreadRemoveCallback([&](TextThread* thread){ emit RemoveThread(thread); }); Host::RegisterThreadRemoveCallback([&](TextThread* thread){ emit RemoveThread(thread); });
} }

View File

@ -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. // 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 class HostSignaller : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
void Initialize(); void Initialize();
signals: signals:
void AddProcess(unsigned int processId); void AddProcess(unsigned int processId);
void RemoveProcess(unsigned int processId); void RemoveProcess(unsigned int processId);
void AddThread(TextThread* thread); void AddThread(TextThread* thread);
void RemoveThread(TextThread* thread); void RemoveThread(TextThread* thread);
void ThreadOutput(TextThread* thread, QString output); void ThreadOutput(TextThread* thread, QString output);
}; };
#endif // HOSTSIGNALLER_H #endif // HOSTSIGNALLER_H

View File

@ -4,10 +4,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
if (!Host::Start()) return 1; if (!Host::Start()) return 1;
QApplication a(argc, argv); QApplication a(argc, argv);
MainWindow w; MainWindow w;
w.show(); w.show();
return a.exec(); return a.exec();
} }

View File

@ -20,105 +20,108 @@ 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); CloseHandle(handle);
return QString::fromWCharArray(wcsrchr(buffer, L'\\') + 1); return QString::fromWCharArray(wcsrchr(buffer, L'\\') + 1);
} }
QString ProcessString(DWORD processId) 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) QString TextThreadString(TextThread* thread)
{ {
ThreadParameter tp = thread->GetThreadParameter(); ThreadParameter tp = thread->GetThreadParameter();
return QString("%1:%2:%3:%4:%5: ").arg( return QString("%1:%2:%3:%4:%5: ").arg(
QString::number(thread->Number()), QString::number(thread->Number()),
QString::number(tp.pid), QString::number(tp.pid),
QString::number(tp.hook, 16), QString::number(tp.hook, 16),
QString::number(tp.retn, 16), QString::number(tp.retn, 16),
QString::number(tp.spl, 16) QString::number(tp.spl, 16)
).toUpper() + QString::fromWCharArray(Host::GetHookName(tp.pid, tp.hook).c_str()); ).toUpper();
} }
MainWindow::MainWindow(QWidget *parent) : MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
ui(new Ui::MainWindow), ui(new Ui::MainWindow),
hostSignaller(new HostSignaller) hostSignaller(new HostSignaller)
{ {
ui->setupUi(this); ui->setupUi(this);
mainWindow = this; mainWindow = this;
processCombo = mainWindow->findChild<QComboBox*>("processCombo"); processCombo = mainWindow->findChild<QComboBox*>("processCombo");
ttCombo = mainWindow->findChild<QComboBox*>("ttCombo"); ttCombo = mainWindow->findChild<QComboBox*>("ttCombo");
textOutput = mainWindow->findChild<QTextBrowser*>("textOutput"); textOutput = mainWindow->findChild<QTextBrowser*>("textOutput");
hostSignaller->Initialize(); hostSignaller->Initialize();
connect(hostSignaller, &HostSignaller::AddProcess, this, &MainWindow::AddProcess); connect(hostSignaller, &HostSignaller::AddProcess, this, &MainWindow::AddProcess);
connect(hostSignaller, &HostSignaller::RemoveProcess, this, &MainWindow::RemoveProcess); connect(hostSignaller, &HostSignaller::RemoveProcess, this, &MainWindow::RemoveProcess);
connect(hostSignaller, &HostSignaller::AddThread, this, &MainWindow::AddThread); connect(hostSignaller, &HostSignaller::AddThread, this, &MainWindow::AddThread);
connect(hostSignaller, &HostSignaller::RemoveThread, this, &MainWindow::RemoveThread); connect(hostSignaller, &HostSignaller::RemoveThread, this, &MainWindow::RemoveThread);
connect(hostSignaller, &HostSignaller::ThreadOutput, this, &MainWindow::ThreadOutput); connect(hostSignaller, &HostSignaller::ThreadOutput, this, &MainWindow::ThreadOutput);
Host::Open(); Host::Open();
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
Host::Close(); Host::Close();
delete hostSignaller; delete hostSignaller;
delete ui; delete ui;
} }
void MainWindow::AddProcess(unsigned int processId) void MainWindow::AddProcess(unsigned int processId)
{ {
processCombo->addItem(ProcessString(processId)); processCombo->addItem(ProcessString(processId));
} }
void MainWindow::RemoveProcess(unsigned int 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) 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) void MainWindow::RemoveThread(TextThread* thread)
{ {
int threadIndex = ttCombo->findText(QString::number(thread->Number()), Qt::MatchStartsWith); int threadIndex = ttCombo->findText(QString::number(thread->Number()) + ":", Qt::MatchStartsWith);
ttCombo->removeItem(threadIndex); ttCombo->removeItem(threadIndex);
if (threadIndex == ttCombo->currentIndex()) if (threadIndex == ttCombo->currentIndex())
{ {
ttCombo->setCurrentIndex(0); ttCombo->setCurrentIndex(0);
on_ttCombo_activated(0); on_ttCombo_activated(0);
} }
delete thread;
} }
void MainWindow::ThreadOutput(TextThread* thread, QString output) void MainWindow::ThreadOutput(TextThread* thread, QString output)
{ {
if (TextThreadString(thread) == ttCombo->currentText()) if (ttCombo->currentText().startsWith(TextThreadString(thread)))
{ {
textOutput->moveCursor(QTextCursor::End); textOutput->moveCursor(QTextCursor::End);
textOutput->insertPlainText(output); textOutput->insertPlainText(output);
textOutput->moveCursor(QTextCursor::End); textOutput->moveCursor(QTextCursor::End);
} }
} }
void MainWindow::on_attachButton_clicked() 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() 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) 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);
} }

View File

@ -8,31 +8,31 @@
namespace Ui namespace Ui
{ {
class MainWindow; class MainWindow;
} }
class MainWindow : public QMainWindow class MainWindow : public QMainWindow
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit MainWindow(QWidget *parent = nullptr); explicit MainWindow(QWidget *parent = nullptr);
~MainWindow(); ~MainWindow();
QString ProcessOutput(TextThread *thread, QString output); QString ProcessOutput(TextThread *thread, QString output);
private slots: private slots:
void on_attachButton_clicked(); void on_attachButton_clicked();
void on_detachButton_clicked(); void on_detachButton_clicked();
void on_ttCombo_activated(int index); void on_ttCombo_activated(int index);
void AddProcess(unsigned int processId); void AddProcess(unsigned int processId);
void RemoveProcess(unsigned int processId); void RemoveProcess(unsigned int processId);
void AddThread(TextThread* thread); void AddThread(TextThread* thread);
void RemoveThread(TextThread* thread); void RemoveThread(TextThread* thread);
void ThreadOutput(TextThread* thread, QString output); void ThreadOutput(TextThread* thread, QString output);
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
HostSignaller* hostSignaller; HostSignaller* hostSignaller;
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

View File

@ -235,7 +235,7 @@ void RemoveThreads(bool(*RemoveIf)(ThreadParameter, ThreadParameter), ThreadPara
{ {
if (onRemove) onRemove(i.second); 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. //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); removedThreads.push_back(i.first);
} }
for (auto i : removedThreads) textThreadsByParams.erase(i); for (auto i : removedThreads) textThreadsByParams.erase(i);