diff --git a/GUI/extenwindow.cpp b/GUI/extenwindow.cpp index 9ab3b1b..ce3d790 100644 --- a/GUI/extenwindow.cpp +++ b/GUI/extenwindow.cpp @@ -2,6 +2,7 @@ #include "ui_extenwindow.h" #include "defs.h" #include "types.h" +#include "text.h" #include #include #include @@ -142,7 +143,7 @@ void ExtenWindow::dropEvent(QDropEvent* event) void ExtenWindow::on_addButton_clicked() { - Add(QFileDialog::getOpenFileName(this, "Select Extension", "C:\\", "Extensions (*.dll)")); + Add(QFileDialog::getOpenFileName(this, SELECT_EXTENSION, "C:\\", EXTENSIONS)); } void ExtenWindow::on_rmvButton_clicked() diff --git a/GUI/host/host.cc b/GUI/host/host.cc index 10293ff..8ca9df0 100644 --- a/GUI/host/host.cc +++ b/GUI/host/host.cc @@ -5,6 +5,7 @@ #include "host.h" #include "const.h" #include "defs.h" +#include "text.h" #include "../vnrhook/hijack/texthook.h" namespace @@ -59,7 +60,7 @@ namespace LOCK(hostMutex); if (textThreadsByParams[tp] == nullptr) { - if (textThreadsByParams.size() > MAX_THREAD_COUNT) return Host::AddConsoleOutput(L"Textractor: too many text threads: can't create more"); + if (textThreadsByParams.size() > MAX_THREAD_COUNT) return Host::AddConsoleOutput(TOO_MANY_THREADS); OnCreate(textThreadsByParams[tp] = std::make_shared(tp, Host::GetHookParam(tp), Host::GetHookName(tp))); } textThreadsByParams[tp]->Push(text, len); @@ -197,7 +198,7 @@ namespace Host CloseHandle(CreateMutexW(nullptr, FALSE, (ITH_HOOKMAN_MUTEX_ + std::to_wstring(processId)).c_str())); if (GetLastError() == ERROR_ALREADY_EXISTS) { - AddConsoleOutput(L"Textractor: already injected"); + AddConsoleOutput(ALREADY_INJECTED); return false; } @@ -213,7 +214,7 @@ namespace Host IsWow64Process(processHandle, &invalidProcess); if (invalidProcess) { - AddConsoleOutput(L"Textractor: architecture mismatch: try 32 bit Textractor instead"); + AddConsoleOutput(ARCHITECTURE_MISMATCH); CloseHandle(processHandle); return false; } @@ -234,7 +235,7 @@ namespace Host } } - AddConsoleOutput(L"Textractor: couldn't inject dll"); + AddConsoleOutput(INJECT_FAILED); return false; } diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index 11605ce..cc8ad81 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -1,6 +1,7 @@ #include "mainwindow.h" #include "ui_mainwindow.h" #include "defs.h" +#include "text.h" #include "extenwindow.h" #include "misc.h" #include @@ -37,7 +38,7 @@ MainWindow::MainWindow(QWidget *parent) : [&](std::shared_ptr thread) { emit SigRemoveThread(thread); }, [&](TextThread* thread, std::wstring& output) { return ProcessThreadOutput(thread, output); } ); - Host::AddConsoleOutput(L"Textractor beta v3.4.0 by Artikash\r\nSource code and more information available under GPLv3 at https://github.com/Artikash/Textractor"); + Host::AddConsoleOutput(ABOUT); } MainWindow::~MainWindow() @@ -175,18 +176,14 @@ QVector MainWindow::GetAllHooks(DWORD processId) void MainWindow::on_attachButton_clicked() { - QMultiHash allProcesses = GetAllProcesses(); + auto allProcesses = GetAllProcesses(); QStringList processList(allProcesses.uniqueKeys()); processList.sort(Qt::CaseInsensitive); bool ok; - QString process = QInputDialog::getItem(this, "Select Process", - "If you don't see the process you want to inject, try running with admin rights\r\nYou can also type in the process id", - processList, 0, true, &ok); - bool injected = false; + QString process = QInputDialog::getItem(this, SELECT_PROCESS, INJECT_INFO, processList, 0, true, &ok); if (!ok) return; - if (process.toInt(nullptr, 0)) injected |= Host::InjectProcess(process.toInt(nullptr, 0)); - else for (auto processId : allProcesses.values(process)) injected |= Host::InjectProcess(processId); - if (!injected) Host::AddConsoleOutput(L"failed to inject"); + if (process.toInt(nullptr, 0)) Host::InjectProcess(process.toInt(nullptr, 0)); + else for (auto processId : allProcesses.values(process)) Host::InjectProcess(processId); } void MainWindow::on_detachButton_clicked() @@ -197,16 +194,16 @@ void MainWindow::on_detachButton_clicked() void MainWindow::on_hookButton_clicked() { bool ok; - QString hookCode = QInputDialog::getText(this, "Add Hook", CodeInfoDump, QLineEdit::Normal, "", &ok); + QString hookCode = QInputDialog::getText(this, ADD_HOOK, CODE_INFODUMP, QLineEdit::Normal, "", &ok); if (!ok) return; if (auto hp = ParseCode(hookCode)) Host::InsertHook(GetSelectedProcessId(), hp.value()); - else Host::AddConsoleOutput(L"invalid code"); + else Host::AddConsoleOutput(INVALID_CODE); } void MainWindow::on_unhookButton_clicked() { - QVector hooks = GetAllHooks(GetSelectedProcessId()); - if (hooks.empty()) return Host::AddConsoleOutput(L"no hooks detected"); + auto hooks = GetAllHooks(GetSelectedProcessId()); + if (hooks.empty()) return Host::AddConsoleOutput(NO_HOOKS); QStringList hookList; for (auto hook : hooks) hookList.push_back( @@ -215,13 +212,13 @@ void MainWindow::on_unhookButton_clicked() GenerateCode(hook, GetSelectedProcessId()) ); bool ok; - QString hook = QInputDialog::getItem(this, "Unhook", "Which hook to remove?", hookList, 0, false, &ok); + QString hook = QInputDialog::getItem(this, UNHOOK, REMOVE_HOOK, hookList, 0, false, &ok); if (ok) Host::RemoveHook(GetSelectedProcessId(), hooks.at(hookList.indexOf(hook)).insertion_address); } void MainWindow::on_saveButton_clicked() { - QVector hooks = GetAllHooks(GetSelectedProcessId()); + auto hooks = GetAllHooks(GetSelectedProcessId()); QString hookList = GetFullModuleName(GetSelectedProcessId()); for (auto hook : hooks) if (!(hook.type & HOOK_ENGINE)) diff --git a/GUI/misc.h b/GUI/misc.h index 625597c..00270a9 100644 --- a/GUI/misc.h +++ b/GUI/misc.h @@ -10,17 +10,4 @@ QMultiHash GetAllProcesses(); std::optional ParseCode(QString HCode); QString GenerateCode(HookParam hp, DWORD processId); -static QString CodeInfoDump = -"Enter hook code\r\n\ -/H{A|B|W|S|Q|V}[N][codepage#]data_offset[*deref_offset1][:split_offset[*deref_offset2]]@addr[:module[:func]]\r\n\ -OR\r\n\ -Enter read code\r\n\ -/R{S|Q|V}[codepage#][*deref_offset|0]@addr\r\n\ -All numbers except codepage in hexadecimal\r\n\ -A/B: Shift-JIS char little/big endian\r\n\ -W: UTF-16 char\r\n\ -S/Q/V: Shift-JIS/UTF-16/UTF-8 string\r\n\ -Negatives for data_offset/sub_offset refer to registers\r\n\ --4 for EAX, -8 for ECX, -C for EDX, -10 for EBX, -14 for ESP, -18 for EBP, -1C for ESI, -20 for EDI\r\n\ -* means dereference pointer+deref_offset"; #endif // MISC_H diff --git a/include/text.h b/include/text.h new file mode 100644 index 0000000..008f276 --- /dev/null +++ b/include/text.h @@ -0,0 +1,33 @@ +#pragma once + +namespace +{ + auto ABOUT = L"Textractor beta v3.4.0 by Artikash\r\n" + "Source code and more information available under GPLv3 at https://github.com/Artikash/Textractor"; + auto SELECT_PROCESS = "Select Process"; + auto INJECT_INFO = "If you don't see the process you want to inject, try running with admin rights\r\n" + "You can also type in the process id"; + auto ADD_HOOK = "Add hook"; + auto CODE_INFODUMP = "Enter hook code\r\n" + "/H{A|B|W|S|Q|V}[N][codepage#]data_offset[*deref_offset1][:split_offset[*deref_offset2]]@addr[:module[:func]]\r\n" + "OR\r\n" + "Enter read code\r\n" + "/R{S|Q|V}[codepage#][*deref_offset|0]@addr\r\n" + "All numbers except codepage in hexadecimal\r\n" + "A/B: Shift-JIS char little/big endian\r\n" + "W: UTF-16 char\r\n" + "S/Q/V: Shift-JIS/UTF-16/UTF-8 string\r\n" + "Negatives for data_offset/sub_offset refer to registers\r\n" + "-4 for EAX, -8 for ECX, -C for EDX, -10 for EBX, -14 for ESP, -18 for EBP, -1C for ESI, -20 for EDI\r\n" + "* means dereference pointer+deref_offset"; + auto UNHOOK = "Unhook"; + auto REMOVE_HOOK = "Which hook to remove?"; + auto SELECT_EXTENSION = "Select Extension"; + auto EXTENSIONS = "Extensions (*.dll)"; + auto TOO_MANY_THREADS = L"Textractor: ERROR: too many text threads: can't create more"; + auto ALREADY_INJECTED = L"Textractor: ERROR: already injected"; + auto ARCHITECTURE_MISMATCH = L"Textractor: ERROR: architecture mismatch: try 32 bit Textractor instead"; + auto INJECT_FAILED = L"Textractor: ERROR: couldn't inject"; + auto INVALID_CODE = L"Textractor: invalid code"; + auto NO_HOOKS = :"Textractor: no hooks detected"; +}