tabs to spaces and bugfixes
This commit is contained in:
parent
9c5be4be80
commit
d0b1efd033
@ -19,11 +19,6 @@ add_definitions(
|
||||
/DITH_HAS_CRT
|
||||
)
|
||||
|
||||
include_directories(
|
||||
.
|
||||
texthook
|
||||
)
|
||||
|
||||
set(CMAKE_ARCHIVE_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)
|
||||
|
@ -3,17 +3,17 @@
|
||||
|
||||
void HostSignaller::Initialize()
|
||||
{
|
||||
Host::RegisterProcessAttachCallback([&](DWORD pid){ emit AddProcess(pid); });
|
||||
Host::RegisterProcessDetachCallback([&](DWORD pid){ emit RemoveProcess(pid); });
|
||||
Host::RegisterThreadCreateCallback([&](TextThread* thread)
|
||||
{
|
||||
emit AddThread(thread);
|
||||
thread->RegisterOutputCallBack([&](TextThread* thread, std::wstring output)
|
||||
{
|
||||
//output = DispatchToExtensions(output);
|
||||
emit ThreadOutput(thread, QString::fromWCharArray(output.c_str()));
|
||||
return output;
|
||||
});
|
||||
});
|
||||
Host::RegisterThreadRemoveCallback([&](TextThread* thread){ emit RemoveThread(thread); });
|
||||
Host::RegisterProcessAttachCallback([&](DWORD pid){ emit AddProcess(pid); });
|
||||
Host::RegisterProcessDetachCallback([&](DWORD pid){ emit RemoveProcess(pid); });
|
||||
Host::RegisterThreadCreateCallback([&](TextThread* thread)
|
||||
{
|
||||
emit AddThread(thread);
|
||||
thread->RegisterOutputCallBack([&](TextThread* thread, std::wstring output)
|
||||
{
|
||||
//output = DispatchToExtensions(output);
|
||||
emit ThreadOutput(thread, QString::fromWCharArray(output.c_str()));
|
||||
return output;
|
||||
});
|
||||
});
|
||||
Host::RegisterThreadRemoveCallback([&](TextThread* thread){ emit RemoveThread(thread); });
|
||||
}
|
||||
|
@ -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.
|
||||
class HostSignaller : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
void Initialize();
|
||||
void Initialize();
|
||||
|
||||
signals:
|
||||
void AddProcess(unsigned int processId);
|
||||
void RemoveProcess(unsigned int processId);
|
||||
void AddThread(TextThread* thread);
|
||||
void RemoveThread(TextThread* thread);
|
||||
void ThreadOutput(TextThread* thread, QString output);
|
||||
void AddProcess(unsigned int processId);
|
||||
void RemoveProcess(unsigned int processId);
|
||||
void AddThread(TextThread* thread);
|
||||
void RemoveThread(TextThread* thread);
|
||||
void ThreadOutput(TextThread* thread, QString output);
|
||||
};
|
||||
|
||||
#endif // HOSTSIGNALLER_H
|
||||
|
10
GUI/main.cpp
10
GUI/main.cpp
@ -4,10 +4,10 @@
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (!Host::Start()) return 1;
|
||||
QApplication a(argc, argv);
|
||||
MainWindow w;
|
||||
w.show();
|
||||
if (!Host::Start()) return 1;
|
||||
QApplication a(argc, argv);
|
||||
MainWindow w;
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
return a.exec();
|
||||
}
|
||||
|
@ -20,105 +20,108 @@ 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);
|
||||
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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
ThreadParameter tp = thread->GetThreadParameter();
|
||||
return QString("%1:%2:%3:%4:%5: ").arg(
|
||||
QString::number(thread->Number()),
|
||||
QString::number(tp.pid),
|
||||
QString::number(tp.hook, 16),
|
||||
QString::number(tp.retn, 16),
|
||||
QString::number(tp.spl, 16)
|
||||
).toUpper() + QString::fromWCharArray(Host::GetHookName(tp.pid, tp.hook).c_str());
|
||||
ThreadParameter tp = thread->GetThreadParameter();
|
||||
return QString("%1:%2:%3:%4:%5: ").arg(
|
||||
QString::number(thread->Number()),
|
||||
QString::number(tp.pid),
|
||||
QString::number(tp.hook, 16),
|
||||
QString::number(tp.retn, 16),
|
||||
QString::number(tp.spl, 16)
|
||||
).toUpper();
|
||||
}
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::MainWindow),
|
||||
hostSignaller(new HostSignaller)
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::MainWindow),
|
||||
hostSignaller(new HostSignaller)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
mainWindow = this;
|
||||
processCombo = mainWindow->findChild<QComboBox*>("processCombo");
|
||||
ttCombo = mainWindow->findChild<QComboBox*>("ttCombo");
|
||||
textOutput = mainWindow->findChild<QTextBrowser*>("textOutput");
|
||||
ui->setupUi(this);
|
||||
mainWindow = this;
|
||||
processCombo = mainWindow->findChild<QComboBox*>("processCombo");
|
||||
ttCombo = mainWindow->findChild<QComboBox*>("ttCombo");
|
||||
textOutput = mainWindow->findChild<QTextBrowser*>("textOutput");
|
||||
|
||||
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);
|
||||
Host::Open();
|
||||
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);
|
||||
Host::Open();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
Host::Close();
|
||||
delete hostSignaller;
|
||||
delete ui;
|
||||
Host::Close();
|
||||
delete hostSignaller;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void MainWindow::AddProcess(unsigned int processId)
|
||||
{
|
||||
processCombo->addItem(ProcessString(processId));
|
||||
processCombo->addItem(ProcessString(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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
int threadIndex = ttCombo->findText(QString::number(thread->Number()), Qt::MatchStartsWith);
|
||||
ttCombo->removeItem(threadIndex);
|
||||
if (threadIndex == ttCombo->currentIndex())
|
||||
{
|
||||
ttCombo->setCurrentIndex(0);
|
||||
on_ttCombo_activated(0);
|
||||
}
|
||||
delete thread;
|
||||
int threadIndex = ttCombo->findText(QString::number(thread->Number()) + ":", Qt::MatchStartsWith);
|
||||
ttCombo->removeItem(threadIndex);
|
||||
if (threadIndex == ttCombo->currentIndex())
|
||||
{
|
||||
ttCombo->setCurrentIndex(0);
|
||||
on_ttCombo_activated(0);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::ThreadOutput(TextThread* thread, QString output)
|
||||
{
|
||||
if (TextThreadString(thread) == ttCombo->currentText())
|
||||
{
|
||||
textOutput->moveCursor(QTextCursor::End);
|
||||
textOutput->insertPlainText(output);
|
||||
textOutput->moveCursor(QTextCursor::End);
|
||||
}
|
||||
if (ttCombo->currentText().startsWith(TextThreadString(thread)))
|
||||
{
|
||||
textOutput->moveCursor(QTextCursor::End);
|
||||
textOutput->insertPlainText(output);
|
||||
textOutput->moveCursor(QTextCursor::End);
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
Host::DetachProcess(processCombo->currentText().split(":")[0].toInt());
|
||||
Host::DetachProcess(processCombo->currentText().split(":")[0].toInt());
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -8,31 +8,31 @@
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class MainWindow;
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
|
||||
QString ProcessOutput(TextThread *thread, QString output);
|
||||
QString ProcessOutput(TextThread *thread, QString output);
|
||||
private slots:
|
||||
void on_attachButton_clicked();
|
||||
void on_detachButton_clicked();
|
||||
void on_ttCombo_activated(int index);
|
||||
void AddProcess(unsigned int processId);
|
||||
void RemoveProcess(unsigned int processId);
|
||||
void AddThread(TextThread* thread);
|
||||
void RemoveThread(TextThread* thread);
|
||||
void ThreadOutput(TextThread* thread, QString output);
|
||||
void on_attachButton_clicked();
|
||||
void on_detachButton_clicked();
|
||||
void on_ttCombo_activated(int index);
|
||||
void AddProcess(unsigned int processId);
|
||||
void RemoveProcess(unsigned int processId);
|
||||
void AddThread(TextThread* thread);
|
||||
void RemoveThread(TextThread* thread);
|
||||
void ThreadOutput(TextThread* thread, QString output);
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
HostSignaller* hostSignaller;
|
||||
Ui::MainWindow *ui;
|
||||
HostSignaller* hostSignaller;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
@ -235,7 +235,7 @@ void RemoveThreads(bool(*RemoveIf)(ThreadParameter, ThreadParameter), ThreadPara
|
||||
{
|
||||
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.
|
||||
//i.second->Clear(); // Temp workaround to free some memory.
|
||||
i.second->Clear(); // Temp workaround to free some memory.
|
||||
removedThreads.push_back(i.first);
|
||||
}
|
||||
for (auto i : removedThreads) textThreadsByParams.erase(i);
|
||||
|
Loading…
x
Reference in New Issue
Block a user