extract more strings

This commit is contained in:
Akash Mozumdar 2018-11-11 00:34:42 -05:00
parent d0f48a67a4
commit 6866e6bfe9
3 changed files with 44 additions and 32 deletions

View File

@ -22,10 +22,19 @@ constexpr auto SELECT_EXTENSION = u8"Select Extension";
constexpr auto EXTENSIONS = u8"Extensions (*.dll)"; constexpr auto EXTENSIONS = u8"Extensions (*.dll)";
constexpr auto ABOUT = L"Textractor beta v3.4.1 by Artikash\r\n" 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"; "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 TOO_MANY_THREADS = L"Textractor: too many text threads: can't create more";
constexpr auto ALREADY_INJECTED = L"Textractor: ERROR: already injected"; constexpr auto ALREADY_INJECTED = L"Textractor: already injected";
constexpr auto ARCHITECTURE_MISMATCH = L"Textractor: ERROR: architecture mismatch: try 32 bit Textractor instead"; constexpr auto ARCHITECTURE_MISMATCH = L"Textractor: architecture mismatch: try 32 bit Textractor instead";
constexpr auto INJECT_FAILED = L"Textractor: ERROR: couldn't inject"; constexpr auto INJECT_FAILED = L"Textractor: couldn't inject";
constexpr auto INVALID_CODE = L"Textractor: invalid code"; constexpr auto INVALID_CODE = L"Textractor: invalid code";
constexpr auto NO_HOOKS = L"Textractor: no hooks detected"; 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: ";

View File

@ -10,18 +10,23 @@
#include "main.h" #include "main.h"
#include "defs.h" #include "defs.h"
#include "text.h"
#include "MinHook.h" #include "MinHook.h"
#include "engine/engine.h" #include "engine/engine.h"
#include "engine/match.h" #include "engine/match.h"
#include "texthook.h" #include "texthook.h"
#include "util/growl.h" #include "util/growl.h"
std::unique_ptr<WinMutex> sectionMutex;
namespace
{
HANDLE hSection, hookPipe; HANDLE hSection, hookPipe;
TextHook* hooks; TextHook* hooks;
bool running; bool running;
int currentHook = 0, userhookCount = 0; int currentHook = 0, userhookCount = 0;
DWORD DUMMY; DWORD DUMMY;
std::unique_ptr<WinMutex> sectionMutex; }
DWORD WINAPI Pipe(LPVOID) DWORD WINAPI Pipe(LPVOID)
{ {
@ -50,9 +55,9 @@ DWORD WINAPI Pipe(LPVOID)
*(DWORD*)buffer = GetCurrentProcessId(); *(DWORD*)buffer = GetCurrentProcessId();
WriteFile(hookPipe, buffer, sizeof(DWORD), &count, nullptr); WriteFile(hookPipe, buffer, sizeof(DWORD), &count, nullptr);
ConsoleOutput("Textractor: pipe connected"); ConsoleOutput(PIPE_CONNECTED);
#ifdef _WIN64 #ifdef _WIN64
ConsoleOutput("Hooks don't work on x64, only read codes work. Engine disabled."); ConsoleOutput(DISABLE_HOOKS);
#else #else
Engine::Hijack(); Engine::Hijack();
#endif #endif
@ -130,18 +135,16 @@ BOOL WINAPI DllMain(HINSTANCE hModule, DWORD fdwReason, LPVOID)
MH_Initialize(); MH_Initialize();
running = true; running = true;
CreateThread(nullptr, 0, Pipe, nullptr, 0, nullptr); CreateThread(nullptr, 0, Pipe, nullptr, 0, nullptr); // Using std::thread here = deadlock
} }
break; break;
case DLL_PROCESS_DETACH: case DLL_PROCESS_DETACH:
{ {
running = false; running = false;
MH_Uninitialize();
for (int i = 0; i < MAX_HOOK; ++i) if (hooks[i].hp.insertion_address) hooks[i].ClearHook(); for (int i = 0; i < MAX_HOOK; ++i) if (hooks[i].hp.insertion_address) hooks[i].ClearHook();
//if (ith_has_section)
UnmapViewOfFile(hooks); UnmapViewOfFile(hooks);
MH_Uninitialize();
CloseHandle(hSection); CloseHandle(hSection);
//} ITH_EXCEPT {}
} }
break; break;
} }
@ -155,14 +158,13 @@ void NewHook(HookParam hp, LPCSTR lpname, DWORD flag)
if (++currentHook < MAX_HOOK) if (++currentHook < MAX_HOOK)
{ {
if (name.empty()) name = "UserHook" + std::to_string(userhookCount++); 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 // jichi 7/13/2014: This function would raise when too many hooks added
hooks[currentHook].InitHook(hp, name.c_str(), flag); hooks[currentHook].InitHook(hp, name.c_str(), flag);
if (hooks[currentHook].InsertHook()) ConsoleOutput("Textractor: inserted hook: " + name); if (!hooks[currentHook].InsertHook()) ConsoleOutput(HOOK_FAILED);
else ConsoleOutput("Textractor:WARNING: failed to insert hook");
} }
else ConsoleOutput("Textractor: too many hooks: can't insert"); else ConsoleOutput(TOO_MANY_HOOKS);
} }
void RemoveHook(uint64_t addr) void RemoveHook(uint64_t addr)

View File

@ -14,18 +14,13 @@
#include "engine/match.h" #include "engine/match.h"
#include "main.h" #include "main.h"
#include "const.h" #include "const.h"
#include "text.h"
#include "ithsys/ithsys.h" #include "ithsys/ithsys.h"
#include "growl.h" #include "growl.h"
#include <Psapi.h> #include <Psapi.h>
extern std::unique_ptr<WinMutex> sectionMutex; extern std::unique_ptr<WinMutex> sectionMutex;
bool trigger = 0;
void SetTrigger()
{
trigger = true;
}
// - Unnamed helpers - // - Unnamed helpers -
namespace { // unnamed namespace { // unnamed
@ -89,8 +84,15 @@ namespace { // unnamed
0xff, 0x25, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 // jmp @original 0xff, 0x25, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 // jmp @original
}; };
#endif #endif
bool trigger = false;
} // unnamed namespace } // unnamed namespace
void SetTrigger()
{
trigger = true;
}
// - TextHook methods - // - TextHook methods -
bool TextHook::InsertHook() bool TextHook::InsertHook()
@ -199,9 +201,9 @@ bool TextHook::InsertHookCode()
if (hp.type & MODULE_OFFSET) // Map hook offset to real address if (hp.type & MODULE_OFFSET) // Map hook offset to real address
if (hp.type & FUNCTION_OFFSET) if (hp.type & FUNCTION_OFFSET)
if (FARPROC function = GetProcAddress(GetModuleHandleW(hp.module), hp.function)) hp.insertion_address += (uint64_t)function; 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 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; void* original;
insert: insert:
@ -213,7 +215,7 @@ insert:
} }
else else
{ {
ConsoleOutput(("Textractor: InsertHookCode FAILED: error " + std::string(MH_StatusToString(err))).c_str()); ConsoleOutput(MH_StatusToString(err));
return false; return false;
} }
@ -258,7 +260,7 @@ DWORD WINAPI Reader(LPVOID hookPtr)
} }
if (++changeCount > 10) if (++changeCount > 10)
{ {
ConsoleOutput("Textractor: memory constantly changing, useless to read"); ConsoleOutput(GARBAGE_MEMORY);
break; break;
} }
@ -275,7 +277,6 @@ DWORD WINAPI Reader(LPVOID hookPtr)
{ {
ConsoleOutput("Textractor: Reader ERROR (likely an incorrect R-code)"); ConsoleOutput("Textractor: Reader ERROR (likely an incorrect R-code)");
} }
ConsoleOutput("Textractor: remove read code");
hook->ClearHook(); hook->ClearHook();
return 0; return 0;
} }
@ -311,7 +312,7 @@ void TextHook::RemoveReadCode()
void TextHook::ClearHook() void TextHook::ClearHook()
{ {
LOCK(*sectionMutex); 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(); if (hp.type & DIRECT_READ) RemoveReadCode();
else RemoveHookCode(); else RemoveHookCode();
NotifyHookRemove(hp.insertion_address); NotifyHookRemove(hp.insertion_address);