From 479c73d0291d7b0e93469ee2387ed678b3dfea4f Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Tue, 1 Jan 2019 18:44:27 -0500 Subject: [PATCH] move more text into text.h, refactor and fix bug in texthook --- include/text.h | 11 +++++++---- vnrhook/engine/match.cc | 3 ++- vnrhook/engine/match64.cc | 7 ++++--- vnrhook/texthook.cc | 38 ++++++++++++-------------------------- 4 files changed, 25 insertions(+), 34 deletions(-) diff --git a/include/text.h b/include/text.h index af7b2be..9b2be69 100644 --- a/include/text.h +++ b/include/text.h @@ -26,9 +26,9 @@ u8"Negatives for data_offset/sub_offset refer to registers\r\n" u8"-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" u8"* means dereference pointer+deref_offset"; constexpr auto SAVE_SETTINGS = u8"Save settings"; -constexpr auto EXTEN_WINDOW_INSTRUCTIONS = u8"Drag and drop extensions (.dll files) here to add them\r\n" -u8"Press delete with an extension selected to remove it\r\n" -u8"Drag and drop extensions to rearrange them"; +constexpr auto EXTEN_WINDOW_INSTRUCTIONS = u8"Drag and drop extension (.dll) files here from your computer to add them\r\n" +u8"Drag and drop within the list to reorder\r\n" +u8"Press delete with an extension selected to remove it"; constexpr auto WINDOW = u8"Window"; constexpr auto DEFAULT_CODEPAGE = u8"Default Codepage"; constexpr auto FLUSH_DELAY = u8"Flush Delay"; @@ -38,7 +38,7 @@ L"Made by me: Artikash (email: akashmozumdar@gmail.com)\r\n" L"Please contact me with any problems, feature requests, or questions relating to Textractor\r\n" L"You can do so via the project homepage (issues section) or via email\r\n" L"Source code available under GPLv3 at project homepage\r\n" -L"I'm currently on the job market: please email me if you're hiring US software engineers"; +L"I'm currently looking for a new job: please email me if you're hiring US software engineers"; constexpr auto UPDATE_AVAILABLE = L"Update available: download it from https://github.com/Artikash/Textractor/releases"; constexpr auto ALREADY_INJECTED = L"Textractor: already injected"; constexpr auto ARCHITECTURE_MISMATCH = L"Textractor: architecture mismatch: try 32 bit Textractor instead"; @@ -53,6 +53,9 @@ constexpr auto TOO_MANY_HOOKS = u8"Textractor: too many hooks: can't insert"; constexpr auto FUNC_MISSING = u8"Textractor: function not present"; constexpr auto MODULE_MISSING = u8"Textractor: module not present"; constexpr auto GARBAGE_MEMORY = u8"Textractor: memory constantly changing, useless to read"; +constexpr auto SEND_ERROR = u8"Textractor: Send ERROR (likely an incorrect H-code)"; +constexpr auto READ_ERROR = u8"Textractor: Reader ERROR (likely an incorrect R-code)"; +constexpr auto HIJACK_ERROR = u8"Textractor: Hijack ERROR"; constexpr auto SELECT_LANGUAGE = u8"Select Language"; constexpr auto BING_PROMPT = u8"What language should Bing translate to?"; constexpr auto GOOGLE_PROMPT = u8"What language should Google translate to?"; diff --git a/vnrhook/engine/match.cc b/vnrhook/engine/match.cc index 974a770..09485b1 100644 --- a/vnrhook/engine/match.cc +++ b/vnrhook/engine/match.cc @@ -13,6 +13,7 @@ #include "util/growl.h" #include "util/util.h" #include "main.h" +#include "text.h" #include "ithsys/ithsys.h" //#define ConsoleOutput(...) (void)0 // jichi 8/18/2013: I don't need ConsoleOutput @@ -866,7 +867,7 @@ bool DetermineEngineType() bool found = false; #ifndef ITH_DISABLE_ENGINE __try { found = UnsafeDetermineEngineType(); } - __except (ExceptHandler((GetExceptionInformation())->ExceptionRecord, 0, 0, 0)) { ConsoleOutput("Textractor: Hijack ERROR"); } + __except (ExceptHandler((GetExceptionInformation())->ExceptionRecord, 0, 0, 0)) { ConsoleOutput(HIJACK_ERROR); } #endif // ITH_DISABLE_ENGINE if (!found) { // jichi 10/2/2013: Only enable it if no game engine is detected PcHooks::hookOtherPcFunctions(); diff --git a/vnrhook/engine/match64.cc b/vnrhook/engine/match64.cc index 17fb7de..15f34f1 100644 --- a/vnrhook/engine/match64.cc +++ b/vnrhook/engine/match64.cc @@ -1,6 +1,7 @@ -#include "main.h" -#include "native/pchooks.h" #include "match.h" +#include "main.h" +#include "text.h" +#include "native/pchooks.h" namespace Engine { @@ -15,6 +16,6 @@ namespace Engine PcHooks::hookGDIPlusFunctions(); PcHooks::hookOtherPcFunctions(); } - __except (EXCEPTION_EXECUTE_HANDLER) { ConsoleOutput("Textractor: Hijack ERROR"); } + __except (EXCEPTION_EXECUTE_HANDLER) { ConsoleOutput(HIJACK_ERROR); } } } \ No newline at end of file diff --git a/vnrhook/texthook.cc b/vnrhook/texthook.cc index 63170dc..1e07c59 100644 --- a/vnrhook/texthook.cc +++ b/vnrhook/texthook.cc @@ -18,7 +18,6 @@ extern std::unique_ptr viewMutex; namespace { // unnamed #ifndef _WIN64 - BYTE common_hook[] = { 0x9c, // pushfd 0x60, // pushad @@ -34,7 +33,7 @@ namespace { // unnamed 0x68, 0,0,0,0, // push @original 0xc3 // ret ; basically absolute jmp to @original }; - + int this_offset = 9, send_offset = 14, original_offset = 24; #else BYTE common_hook[] = { 0x9c, // push rflags @@ -86,6 +85,7 @@ namespace { // unnamed 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // jmp qword ptr [0] ; relative to next instruction (i.e. jmp @original) 0,0,0,0,0,0,0,0 // @original }; + int this_offset = 50, send_offset = 60, original_offset = 116; #endif bool trigger = false; @@ -189,7 +189,7 @@ void TextHook::Send(uintptr_t dwDataBase) { if (!err) { - ConsoleOutput("Textractor: Send ERROR (likely an incorrect H-code)"); + ConsoleOutput(SEND_ERROR); err = true; } } @@ -207,28 +207,14 @@ bool TextHook::InsertHookCode() else return ConsoleOutput(MODULE_MISSING), false; void* original; -insert: - if (MH_STATUS err = MH_CreateHook(location, trampoline, &original)) - if (err == MH_ERROR_ALREADY_CREATED) - { - RemoveHook(address); - goto insert; // FIXME: i'm too lazy to do this properly right now... - } - else - { - ConsoleOutput(MH_StatusToString(err)); - return false; - } + MH_STATUS error; + while ((error = MH_CreateHook(location, trampoline, &original)) != MH_OK) + if (error == MH_ERROR_ALREADY_CREATED) RemoveHook(address); + else return ConsoleOutput(MH_StatusToString(error)), false; -#ifndef _WIN64 - *(TextHook**)(common_hook + 9) = this; - *(void(TextHook::**)(uintptr_t))(common_hook + 14) = &TextHook::Send; - *(void**)(common_hook + 24) = original; -#else // _WIN32 - *(TextHook**)(common_hook + 50) = this; - *(void(TextHook::**)(uintptr_t))(common_hook + 60) = &TextHook::Send; - *(void**)(common_hook + 116) = original; -#endif // _WIN64 + *(TextHook**)(common_hook + this_offset) = this; + *(void(TextHook::**)(uintptr_t))(common_hook + send_offset) = &TextHook::Send; + *(void**)(common_hook + original_offset) = original; memcpy(trampoline, common_hook, sizeof(common_hook)); return MH_EnableHook(location) == MH_OK; } @@ -243,7 +229,7 @@ DWORD WINAPI TextHook::Reader(LPVOID hookPtr) uint64_t currentAddress = This->address; while (WaitForSingleObject(This->readerEvent, 500) == WAIT_TIMEOUT) { - if (This->hp.type & DATA_INDIRECT) currentAddress = *(uint64_t*)This->address + This->hp.index; + if (This->hp.type & DATA_INDIRECT) currentAddress = *(uintptr_t*)This->address + This->hp.index; if (memcmp(buffer, (void*)currentAddress, dataLen + 1) == 0) { changeCount = 0; @@ -265,7 +251,7 @@ DWORD WINAPI TextHook::Reader(LPVOID hookPtr) } __except (EXCEPTION_EXECUTE_HANDLER) { - ConsoleOutput("Textractor: Reader ERROR (likely an incorrect R-code)"); + ConsoleOutput(READ_ERROR); This->Clear(); } return 0;