diff --git a/GUI/extensions.cpp b/GUI/extensions.cpp index 0f96764..87f1233 100644 --- a/GUI/extensions.cpp +++ b/GUI/extensions.cpp @@ -1,32 +1,35 @@ #include "extensions.h" #include +#include std::map extensions; -std::map LoadExtensions() +std::map LoadExtensions() { - std::map extensionNames; - wchar_t path[MAX_PATH]; - wchar_t* end = path + GetModuleFileNameW(nullptr, path, MAX_PATH); - while (*(--end) != L'\\'); - *(end + 1) = L'*'; - *(end + 2) = L'\0'; + extensions = std::map(); + std::map extensionNames; + wchar_t path[MAX_PATH] = {}; + (QDir::currentPath() + "/*_nexthooker_extension.dll").toWCharArray(path); WIN32_FIND_DATAW fileData; HANDLE file = FindFirstFileW(path, &fileData); do - if (!(fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) - if (wcsstr(fileData.cFileName, L"_nexthooker_extension.dll")) - if (GetProcAddress(LoadLibraryW(fileData.cFileName), "OnNewSentence")) - { - extensions[std::wcstol(fileData.cFileName, nullptr, 10)] = (ExtensionFunction)GetProcAddress(LoadLibraryW(fileData.cFileName), "OnNewSentence"); - extensionNames[std::wcstol(fileData.cFileName, nullptr, 10)] = fileData.cFileName; - } + if (GetProcAddress(GetModuleHandleW(fileData.cFileName), "OnNewSentence") || + GetProcAddress(LoadLibraryW(fileData.cFileName), "OnNewSentence") + ) + { + extensions[std::wcstol(fileData.cFileName, nullptr, 10)] = (ExtensionFunction)GetProcAddress(GetModuleHandleW(fileData.cFileName), "OnNewSentence"); + QString name = QString::fromWCharArray(fileData.cFileName); + name.chop(sizeof("_nexthooker_extension.dll") - 1); + name.remove(0, name.split("_")[0].length() + 1); + extensionNames[std::wcstol(fileData.cFileName, nullptr, 10)] = name; + } while (FindNextFileW(file, &fileData) != 0); return extensionNames; } std::wstring DispatchSentenceToExtensions(std::wstring sentence, std::unordered_map miscInfo) { - for (auto extension : extensions) sentence = extension.second(sentence, miscInfo); + for (auto extension : extensions) + extension.second(sentence, miscInfo); return sentence; } diff --git a/GUI/extensions.h b/GUI/extensions.h index 3937f40..560ff4a 100644 --- a/GUI/extensions.h +++ b/GUI/extensions.h @@ -8,10 +8,10 @@ #include #include -std::map LoadExtensions(); +std::map LoadExtensions(); std::wstring DispatchSentenceToExtensions(std::wstring sentence, std::unordered_map miscInfo); -typedef std::wstring(*ExtensionFunction)(std::wstring, std::unordered_map&); +typedef void(*ExtensionFunction)(std::wstring&, std::unordered_map&); extern QComboBox* ttCombo; #endif // EXTENSIONS_H diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index b4799c3..d88fc81 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -62,8 +62,8 @@ MainWindow::MainWindow(QWidget *parent) : connect(hostSignaller, &HostSignaller::AddThread, this, &MainWindow::AddThread); connect(hostSignaller, &HostSignaller::RemoveThread, this, &MainWindow::RemoveThread); connect(hostSignaller, &HostSignaller::ThreadOutput, this, &MainWindow::ThreadOutput); - std::map extensions = LoadExtensions(); - for (auto i : extensions) extenCombo->addItem(QString::number(i.first) + ":" + QString::fromWCharArray(i.second.c_str())); + std::map extensions = LoadExtensions(); + for (auto i : extensions) extenCombo->addItem(QString::number(i.first) + ":" + i.second); Host::Open(); } @@ -157,7 +157,7 @@ void MainWindow::on_hookButton_clicked() { bool ok; QString hookCode = QInputDialog::getText(this, "Add Hook", - "Enter hook code\r\n/H{A|B|W|S|Q}[N][data_offset[*drdo]][:sub_offset[*drso]]@addr[:module]", + "Enter hook code\r\n/H{A|B|W|S|Q}[N]data_offset[*drdo][:sub_offset[*drso]]@addr[:module]", QLineEdit::Normal, "/H", &ok ); if (ok) Host::InsertHook(processCombo->currentText().split(":")[0].toInt(), ParseHCode(hookCode)); @@ -197,6 +197,27 @@ void MainWindow::on_ttCombo_activated(int index) void MainWindow::on_addExtenButton_clicked() { - QFileDialog extenSelector; - + QString extenFileName = QFileDialog::getOpenFileName(this, "Select extension dll", "C:\\", "Extensions (*.dll)"); + if (!extenFileName.length()) return; + QString extenName = extenFileName.split("/")[extenFileName.split("/").count() - 1]; + extenName.chop(4); + QString copyTo = QString::number(extenCombo->itemText(extenCombo->count() - 1).split(":")[0].toInt() + 1) + "_" + + extenName + + "_nexthooker_extension.dll"; + QFile::copy(extenFileName, copyTo); + extenCombo->clear(); + std::map extensions = LoadExtensions(); + for (auto i : extensions) extenCombo->addItem(QString::number(i.first) + ":" + i.second); +} + +void MainWindow::on_rmvExtenButton_clicked() +{ + QString extenFileName = extenCombo->currentText().split(":")[0] + "_" + extenCombo->currentText().split(":")[1] + "_nexthooker_extension.dll"; + FreeLibrary(GetModuleHandleW(extenFileName.toStdWString().c_str())); + QString disabledFileName = extenFileName; + disabledFileName.replace("extension", "disabled_extension"); + QFile::rename(extenFileName, disabledFileName); + extenCombo->clear(); + std::map extensions = LoadExtensions(); + for (auto i : extensions) extenCombo->addItem(QString::number(i.first) + ":" + i.second); } diff --git a/GUI/mainwindow.h b/GUI/mainwindow.h index 9743bb9..0453517 100644 --- a/GUI/mainwindow.h +++ b/GUI/mainwindow.h @@ -36,6 +36,8 @@ private slots: void on_saveButton_clicked(); void on_addExtenButton_clicked(); + void on_rmvExtenButton_clicked(); + private: QVector GetAllHooks(DWORD processId); diff --git a/GUI/mainwindow.ui b/GUI/mainwindow.ui index 7b6955e..d2bb034 100644 --- a/GUI/mainwindow.ui +++ b/GUI/mainwindow.ui @@ -191,16 +191,9 @@ - + - Enable extension - - - - - - - Disable extension + Remove extension diff --git a/texthook/host.cc b/texthook/host.cc index 2b5627f..1f41d26 100644 --- a/texthook/host.cc +++ b/texthook/host.cc @@ -98,7 +98,7 @@ namespace Host CloseHandle(CreateMutexW(nullptr, FALSE, (ITH_HOOKMAN_MUTEX_ + std::to_wstring(processId)).c_str())); if (GetLastError() == ERROR_ALREADY_EXISTS) { - AddConsoleOutput(L"already locked"); + AddConsoleOutput(L"already injected"); return false; }