From 6866e6bfe9521c6018c345008e3acf108ae226f7 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Sun, 11 Nov 2018 00:34:42 -0500 Subject: [PATCH] extract more strings --- include/text.h | 19 ++++++++++++++----- vnrhook/main.cc | 32 +++++++++++++++++--------------- vnrhook/texthook.cc | 25 +++++++++++++------------ 3 files changed, 44 insertions(+), 32 deletions(-) diff --git a/include/text.h b/include/text.h index ac9afe1..1305af1 100644 --- a/include/text.h +++ b/include/text.h @@ -22,10 +22,19 @@ constexpr auto SELECT_EXTENSION = u8"Select Extension"; constexpr auto EXTENSIONS = u8"Extensions (*.dll)"; constexpr auto ABOUT = L"Textractor beta v3.4.1 by Artikash\r\n" "Source code and more information available under GPLv3 at https://github.com/Artikash/Textractor"; -constexpr auto TOO_MANY_THREADS = L"Textractor: ERROR: too many text threads: can't create more"; -constexpr auto ALREADY_INJECTED = L"Textractor: ERROR: already injected"; -constexpr auto ARCHITECTURE_MISMATCH = L"Textractor: ERROR: architecture mismatch: try 32 bit Textractor instead"; -constexpr auto INJECT_FAILED = L"Textractor: ERROR: couldn't inject"; +constexpr auto TOO_MANY_THREADS = L"Textractor: too many text threads: can't create more"; +constexpr auto ALREADY_INJECTED = L"Textractor: already injected"; +constexpr auto ARCHITECTURE_MISMATCH = L"Textractor: architecture mismatch: try 32 bit Textractor instead"; +constexpr auto INJECT_FAILED = L"Textractor: couldn't inject"; constexpr auto INVALID_CODE = L"Textractor: invalid code"; constexpr auto NO_HOOKS = L"Textractor: no hooks detected"; -constexpr auto INVALID_CODEPAGE = L"Textractor: ERROR: couldn't convert text (invalid codepage?)"; +constexpr auto INVALID_CODEPAGE = L"Textractor: couldn't convert text (invalid codepage?)"; +constexpr auto PIPE_CONNECTED = "Textractor: pipe connected"; +constexpr auto DISABLE_HOOKS = "Textractor: hooks don't work on x64, only read codes work. Engine disabled."; +constexpr auto INSERTING_HOOK = "Textractor: inserting hook: "; +constexpr auto HOOK_FAILED = "Textractor: failed to insert hook"; +constexpr auto TOO_MANY_HOOKS = "Textractor: too many hooks: can't insert"; +constexpr auto FUNC_MISSING = "Textractor: function not present"; +constexpr auto MODULE_MISSING = "Textractor: module not present"; +constexpr auto GARBAGE_MEMORY = "Textractor: memory constantly changing, useless to read"; +constexpr auto REMOVING_HOOK = "Textractor: removing hook: "; \ No newline at end of file diff --git a/vnrhook/main.cc b/vnrhook/main.cc index 4fb64b2..984d17d 100644 --- a/vnrhook/main.cc +++ b/vnrhook/main.cc @@ -10,19 +10,24 @@ #include "main.h" #include "defs.h" +#include "text.h" #include "MinHook.h" #include "engine/engine.h" #include "engine/match.h" #include "texthook.h" #include "util/growl.h" -HANDLE hSection, hookPipe; -TextHook* hooks; -bool running; -int currentHook = 0, userhookCount = 0; -DWORD DUMMY; std::unique_ptr sectionMutex; +namespace +{ + HANDLE hSection, hookPipe; + TextHook* hooks; + bool running; + int currentHook = 0, userhookCount = 0; + DWORD DUMMY; +} + DWORD WINAPI Pipe(LPVOID) { while (running) @@ -50,9 +55,9 @@ DWORD WINAPI Pipe(LPVOID) *(DWORD*)buffer = GetCurrentProcessId(); WriteFile(hookPipe, buffer, sizeof(DWORD), &count, nullptr); - ConsoleOutput("Textractor: pipe connected"); + ConsoleOutput(PIPE_CONNECTED); #ifdef _WIN64 - ConsoleOutput("Hooks don't work on x64, only read codes work. Engine disabled."); + ConsoleOutput(DISABLE_HOOKS); #else Engine::Hijack(); #endif @@ -130,18 +135,16 @@ BOOL WINAPI DllMain(HINSTANCE hModule, DWORD fdwReason, LPVOID) MH_Initialize(); running = true; - CreateThread(nullptr, 0, Pipe, nullptr, 0, nullptr); + CreateThread(nullptr, 0, Pipe, nullptr, 0, nullptr); // Using std::thread here = deadlock } break; case DLL_PROCESS_DETACH: { running = false; - MH_Uninitialize(); for (int i = 0; i < MAX_HOOK; ++i) if (hooks[i].hp.insertion_address) hooks[i].ClearHook(); - //if (ith_has_section) UnmapViewOfFile(hooks); + MH_Uninitialize(); CloseHandle(hSection); - //} ITH_EXCEPT {} } break; } @@ -155,14 +158,13 @@ void NewHook(HookParam hp, LPCSTR lpname, DWORD flag) if (++currentHook < MAX_HOOK) { if (name.empty()) name = "UserHook" + std::to_string(userhookCount++); - ConsoleOutput("Textractor: try inserting hook: " + name); + ConsoleOutput(INSERTING_HOOK + name); // jichi 7/13/2014: This function would raise when too many hooks added hooks[currentHook].InitHook(hp, name.c_str(), flag); - if (hooks[currentHook].InsertHook()) ConsoleOutput("Textractor: inserted hook: " + name); - else ConsoleOutput("Textractor:WARNING: failed to insert hook"); + if (!hooks[currentHook].InsertHook()) ConsoleOutput(HOOK_FAILED); } - else ConsoleOutput("Textractor: too many hooks: can't insert"); + else ConsoleOutput(TOO_MANY_HOOKS); } void RemoveHook(uint64_t addr) diff --git a/vnrhook/texthook.cc b/vnrhook/texthook.cc index 93fcb54..0017f51 100644 --- a/vnrhook/texthook.cc +++ b/vnrhook/texthook.cc @@ -14,18 +14,13 @@ #include "engine/match.h" #include "main.h" #include "const.h" +#include "text.h" #include "ithsys/ithsys.h" #include "growl.h" #include extern std::unique_ptr sectionMutex; -bool trigger = 0; -void SetTrigger() -{ - trigger = true; -} - // - Unnamed helpers - namespace { // unnamed @@ -89,8 +84,15 @@ namespace { // unnamed 0xff, 0x25, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 // jmp @original }; #endif + + bool trigger = false; } // unnamed namespace +void SetTrigger() +{ + trigger = true; +} + // - TextHook methods - bool TextHook::InsertHook() @@ -199,9 +201,9 @@ bool TextHook::InsertHookCode() if (hp.type & MODULE_OFFSET) // Map hook offset to real address if (hp.type & FUNCTION_OFFSET) if (FARPROC function = GetProcAddress(GetModuleHandleW(hp.module), hp.function)) hp.insertion_address += (uint64_t)function; - else return ConsoleOutput("Textractor: InsertHookCode FAILED: function not present"), false; + else return ConsoleOutput(FUNC_MISSING), false; else if (HMODULE moduleBase = GetModuleHandleW(hp.module)) hp.insertion_address += (uint64_t)moduleBase; - else return ConsoleOutput("Textractor: InsertHookCode FAILED: module not present"), false; + else return ConsoleOutput(MODULE_MISSING), false; void* original; insert: @@ -213,7 +215,7 @@ insert: } else { - ConsoleOutput(("Textractor: InsertHookCode FAILED: error " + std::string(MH_StatusToString(err))).c_str()); + ConsoleOutput(MH_StatusToString(err)); return false; } @@ -258,7 +260,7 @@ DWORD WINAPI Reader(LPVOID hookPtr) } if (++changeCount > 10) { - ConsoleOutput("Textractor: memory constantly changing, useless to read"); + ConsoleOutput(GARBAGE_MEMORY); break; } @@ -275,7 +277,6 @@ DWORD WINAPI Reader(LPVOID hookPtr) { ConsoleOutput("Textractor: Reader ERROR (likely an incorrect R-code)"); } - ConsoleOutput("Textractor: remove read code"); hook->ClearHook(); return 0; } @@ -311,7 +312,7 @@ void TextHook::RemoveReadCode() void TextHook::ClearHook() { LOCK(*sectionMutex); - ConsoleOutput(("Textractor: removing hook: " + std::string(hookName)).c_str()); + ConsoleOutput((REMOVING_HOOK + std::string(hookName)).c_str()); if (hp.type & DIRECT_READ) RemoveReadCode(); else RemoveHookCode(); NotifyHookRemove(hp.insertion_address);