From df9fb07395eecd748f68d7a57295c8fee4828041 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Fri, 3 Aug 2018 15:04:48 -0400 Subject: [PATCH] clean up engine --- vnrhook/src/engine/engine.cc | 16 ++++++------ vnrhook/src/hijack/texthook.cc | 45 +++++++++------------------------- 2 files changed, 18 insertions(+), 43 deletions(-) diff --git a/vnrhook/src/engine/engine.cc b/vnrhook/src/engine/engine.cc index 65e7da9..da311ad 100644 --- a/vnrhook/src/engine/engine.cc +++ b/vnrhook/src/engine/engine.cc @@ -7655,19 +7655,17 @@ void InsertBrunsHook() HookParam hp = {}; hp.offset = 4; hp.length_offset = 1; - hp.type = USING_UNICODE|MODULE_OFFSET|FUNCTION_OFFSET; - // jichi 12/27/2013: This function does not work for the latest bruns games anymore - hp.function = 0x8b24c7bc; + hp.type = USING_UNICODE; //?push_back@?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@QAEXG@Z - if (Util::CheckFile(L"msvcp90.dll")) - hp.module = 0xc9c36a5b; // 3385027163 + if (Util::CheckFile(L"msvcp90.dll")) + hp.address = (DWORD)GetProcAddress(GetModuleHandleW(L"msvcp90.dll"), "?push_back@?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@QAEXG@Z"); else if (Util::CheckFile(L"msvcp80.dll")) - hp.module = 0xa9c36a5b; // 2848156251 + hp.address = (DWORD)GetProcAddress(GetModuleHandleW(L"msvcp80.dll"), "?push_back@?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@QAEXG@Z"); else if (Util::CheckFile(L"msvcp100.dll")) // jichi 8/17/2013: MSVCRT 10.0 and 11.0 - hp.module = 0xb571d760; // 3044136800; + hp.address = (DWORD)GetProcAddress(GetModuleHandleW(L"msvcp100.dll"), "?push_back@?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@QAEXG@Z"); else if (Util::CheckFile(L"msvcp110.dll")) - hp.module = 0xd571d760; // 3581007712; - if (hp.module) { + hp.address = (DWORD)GetProcAddress(GetModuleHandleW(L"msvcp110.dll"), "?push_back@?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@QAEXG@Z"); + if (hp.address) { ConsoleOutput("vnreng: INSERT Brus#1"); NewHook(hp, "Bruns"); } diff --git a/vnrhook/src/hijack/texthook.cc b/vnrhook/src/hijack/texthook.cc index 6041830..851b240 100644 --- a/vnrhook/src/hijack/texthook.cc +++ b/vnrhook/src/hijack/texthook.cc @@ -498,42 +498,19 @@ int TextHook::UnsafeInsertHookCode() { //ConsoleOutput("vnrcli:UnsafeInsertHookCode: enter"); enum : int { yes = 0, no = 1 }; - // MODULE_OFFSET is set, but there's no module address - // this means that this is an absolute address found on Windows 2000/XP - // we make the address relative to the process base - // we also store the original address in the function field because normally there can not - // exist a function address without a module address - if (hp.type & MODULE_OFFSET && !hp.module) { - DWORD base = GetModuleBase(); - hp.function = hp.address; - hp.address -= 0x400000; - hp.address += base; - hp.type &= ~MODULE_OFFSET; - } - else if (hp.module && (hp.type & MODULE_OFFSET)) { // Map hook offset to real address. - if (DWORD base = GetModuleBase(hp.module)) { - if (hp.function && (hp.type & FUNCTION_OFFSET)) { - base = GetExportAddress(base, hp.function); - if (base) - hp.address += base; - else { - currentHook--; - ConsoleOutput("vnrcli:UnsafeInsertHookCode: FAILED: function not found in the export table"); - return no; - } - } - else { - hp.address += base; - } - hp.type &= ~(MODULE_OFFSET | FUNCTION_OFFSET); - } - else { - currentHook--; - ConsoleOutput("vnrcli:UnsafeInsertHookCode: FAILED: module not present"); - return no; - } + if (hp.module && (hp.type & MODULE_OFFSET)) { // Map hook offset to real address. + if (DWORD base = GetModuleBase(hp.module)) { + hp.address += base; + } + else { + currentHook--; + ConsoleOutput("vnrcli:UnsafeInsertHookCode: FAILED: module not present"); + return no; + } + hp.type &= ~MODULE_OFFSET; } + { TextHook *it = hookman; for (int i = 0; (i < currentHook) && it; it++) { // Check if there is a collision.