From 49d9d7a0c47767a1390c0889112855596e113380 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Sat, 5 Jan 2019 03:46:13 -0500 Subject: [PATCH] display error if text couldnt be found --- vnrhook/main.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vnrhook/main.cc b/vnrhook/main.cc index 4eacee4..a05c0fa 100644 --- a/vnrhook/main.cc +++ b/vnrhook/main.cc @@ -136,10 +136,11 @@ void NewHook(HookParam hp, LPCSTR lpname, DWORD flag) { if (hp.type & READ_SEARCH) { + bool found = false; char utf8Text[MAX_MODULE_SIZE * 4] = {}; WideCharToMultiByte(CP_UTF8, 0, hp.text, MAX_MODULE_SIZE, utf8Text, MAX_MODULE_SIZE * 4, nullptr, nullptr); char codepageText[MAX_MODULE_SIZE * 4] = {}; - WideCharToMultiByte(hp.codepage ? hp.codepage : SHIFT_JIS, 0, hp.text, MAX_MODULE_SIZE, codepageText, MAX_MODULE_SIZE * 4, nullptr, nullptr); + WideCharToMultiByte(hp.codepage, 0, hp.text, MAX_MODULE_SIZE, codepageText, MAX_MODULE_SIZE * 4, nullptr, nullptr); if (strlen(utf8Text) < 8 || strlen(codepageText) < 8 || wcslen(hp.text) < 4) return ConsoleOutput(NOT_ENOUGH_TEXT); for (auto[addrs, type] : Array, HookParamType>>{ { Util::SearchMemory(utf8Text, strlen(utf8Text), PAGE_READWRITE), USING_UTF8 }, @@ -148,12 +149,15 @@ void NewHook(HookParam hp, LPCSTR lpname, DWORD flag) }) for (auto addr : addrs) { + if (abs((long long)(utf8Text - addr)) < 20000) continue; // don't add read code if text is on this thread's stack + found = true; HookParam h = {}; h.type = DIRECT_READ | type; h.address = addr; h.codepage = hp.codepage; NewHook(h, lpname, 0); } + if (!found) ConsoleOutput(COULD_NOT_FIND); } else {