From 91ac0825f8cac4a9d1ab6c38df09dd4fa1343650 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Sun, 19 Aug 2018 17:55:50 -0400 Subject: [PATCH] misc refactors --- GUI/extensions.cpp | 28 ++++++++++++---------------- GUI/mainwindow.cpp | 8 ++++---- extensions/googletranslate.cpp | 6 +++--- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/GUI/extensions.cpp b/GUI/extensions.cpp index 512a7f6..a86a650 100644 --- a/GUI/extensions.cpp +++ b/GUI/extensions.cpp @@ -9,22 +9,18 @@ std::map LoadExtensions() { std::map newExtensions; 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 (GetProcAddress(GetModuleHandleW(fileData.cFileName), "OnNewSentence") || - GetProcAddress(LoadLibraryW(fileData.cFileName), "OnNewSentence") - ) - { - newExtensions[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); + QStringList files = QDir().entryList(); + for (auto file : files) + if (file.endsWith("_nexthooker_extension.dll")) + if (GetProcAddress(GetModuleHandleW(file.toStdWString().c_str()), "OnNewSentence") || + GetProcAddress(LoadLibraryW(file.toStdWString().c_str()), "OnNewSentence")) + { + QString extensionNumber = file.split("_")[0]; + newExtensions[extensionNumber.toInt()] = (ExtensionFunction)GetProcAddress(GetModuleHandleW(file.toStdWString().c_str()), "OnNewSentence"); + file.chop(sizeof("_nexthooker_extension.dll") - 1); + file.remove(0, extensionNumber.length() + 1); + extensionNames[extensionNumber.toInt()] = file; + } while (processing) Sleep(10); processing = -1; extensions = newExtensions; diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index b49349f..d8d6e32 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -103,7 +103,7 @@ void MainWindow::AddThread(TextThread* thread) { ttCombo->addItem( TextThreadString(thread) + - QString::fromWCharArray(Host::GetHookName(thread->GetThreadParameter().pid, thread->GetThreadParameter().hook).c_str()) + + QString::fromStdWString(Host::GetHookName(thread->GetThreadParameter().pid, thread->GetThreadParameter().hook)) + " (" + GenerateCode(Host::GetHookParam(thread->GetThreadParameter().pid, thread->GetThreadParameter().hook), thread->GetThreadParameter().pid) + ")" @@ -112,7 +112,7 @@ void MainWindow::AddThread(TextThread* thread) { output = DispatchSentenceToExtensions(output, GetInfoForExtensions(thread)); output += L"\r\n"; - emit ThreadOutputReceived(thread, QString::fromWCharArray(output.c_str())); + emit ThreadOutputReceived(thread, QString::fromStdWString(output)); return output; }); } @@ -205,7 +205,7 @@ void MainWindow::on_unhookButton_clicked() QVector hooks = GetAllHooks(processCombo->currentText().split(":")[0].toInt()); QStringList hookList; for (auto i : hooks) hookList.push_back( - QString::fromWCharArray(Host::GetHookName(processCombo->currentText().split(":")[0].toInt(), i.address).c_str()) + + QString::fromStdWString(Host::GetHookName(processCombo->currentText().split(":")[0].toInt(), i.address)) + ": " + GenerateCode(i, processCombo->currentText().split(":")[0].toInt()) ); @@ -250,6 +250,6 @@ void MainWindow::on_rmvExtenButton_clicked() if (extenCombo->currentText().size() == 0) return; QString extenFileName = extenCombo->currentText().split(":")[0] + "_" + extenCombo->currentText().split(": ")[1] + "_nexthooker_extension.dll"; FreeLibrary(GetModuleHandleW(extenFileName.toStdWString().c_str())); - DeleteFileW(extenFileName.toStdWString().c_str()); + QFile::remove(extenFileName); ReloadExtensions(); } diff --git a/extensions/googletranslate.cpp b/extensions/googletranslate.cpp index 20bf5af..be9cfaa 100644 --- a/extensions/googletranslate.cpp +++ b/extensions/googletranslate.cpp @@ -60,7 +60,7 @@ extern "C" if (WinHttpSendRequest(request, NULL, 0, NULL, 0, 0, NULL)) { DWORD bytesRead; - char buffer[100000]; // Google Translate page is ~64kb + char buffer[100000] = {}; // Google Translate page is ~64kb WinHttpReceiveResponse(request, NULL); WinHttpReadData(request, buffer, 100000, &bytesRead); TKK = strtoll(strstr(buffer, "a\\x3d") + 5, nullptr, 10) + strtoll(strstr(buffer, "b\\x3d") + 5, nullptr, 10); @@ -76,9 +76,9 @@ extern "C" if (WinHttpSendRequest(request, NULL, 0, NULL, 0, 0, NULL)) { DWORD bytesRead; - char buffer[0x10000] = {}; + char buffer[10000] = {}; WinHttpReceiveResponse(request, NULL); - WinHttpReadData(request, buffer, 0x10000, &bytesRead); + WinHttpReadData(request, buffer, 10000, &bytesRead); // Response formatted as JSON: starts with '[[["' MultiByteToWideChar(CP_UTF8, 0, buffer + 4, (int)((strstr(buffer, "\",\"")) - (buffer + 4)), translation, 10000); message = translation;