diff --git a/LunaHook/engine32/V8.cpp b/LunaHook/engine32/V8.cpp index 37de7e8..0f26522 100644 --- a/LunaHook/engine32/V8.cpp +++ b/LunaHook/engine32/V8.cpp @@ -104,11 +104,45 @@ bool hookv8exports(HMODULE module) { hp.index = 0; return NewHook(hp, "Write@String@v8"); } - -bool V8::attach_function() { - bool b1= InsertV8Hook(pmodule); - bool b2=hookv8addr(pmodule); - bool b3=hookv8exports(pmodule); - return b1||b2||b3; -} +namespace{ + bool hookstringlength(HMODULE hm){ + auto Length=GetProcAddress(hm,"?Length@String@v8@@QBEHXZ"); + static uintptr_t WriteUtf8; + static uintptr_t Utf8Length; + WriteUtf8=(uintptr_t)GetProcAddress(hm,"?WriteUtf8@String@v8@@QBEHPADHPAHH@Z"); + Utf8Length=(uintptr_t)GetProcAddress(hm,"?Utf8Length@String@v8@@QBEHXZ"); + if(Length==0||WriteUtf8==0||Utf8Length==0)return false; + HookParam hp; + hp.address=(uintptr_t)Length; + hp.type=USING_STRING|CODEC_UTF8; + hp.text_fun= + [](hook_stack* stack, HookParam* hp, uintptr_t* data, uintptr_t* split, size_t* len) + { + auto length=((size_t(__thiscall*)(void*))Utf8Length)((void*)stack->ecx); + auto u8str=new char[length+1]; + int writen; + ((size_t(__thiscall*)(void*,char*,int,int*,int))WriteUtf8)((void*)stack->ecx,u8str,length,&writen,0); + *data=(uintptr_t)u8str; + *len=length; + + }; + return NewHook(hp,"v8::String::Length"); + } +} +bool V8::attach_function_() { + for (const wchar_t* moduleName : { (const wchar_t*)NULL, L"node.dll", L"nw.dll" }) { + auto hm=GetModuleHandleW(moduleName); + if(hm==0)continue; + if (GetProcAddress(hm, "?Write@String@v8@@QBEHPAGHHH@Z")==0)continue; + + bool b1= InsertV8Hook(hm); + bool b2=hookv8addr(hm); + bool b3=hookv8exports(hm); + b1=hookstringlength(hm)||b1; + if(b1||b2||b3){ + return true; + } + } + return false; +} diff --git a/LunaHook/engine32/V8.h b/LunaHook/engine32/V8.h index dbb917b..10ecb9d 100644 --- a/LunaHook/engine32/V8.h +++ b/LunaHook/engine32/V8.h @@ -3,29 +3,10 @@ class V8:public ENGINE{ public: V8(){ - check_by=CHECK_BY::CUSTOM; - is_engine_certain=false; - - // Artikash 7/16/2018: Uses node/libuv: likely v8 - sample game https://vndb.org/v22975 - //if (GetProcAddress(GetModuleHandleW(nullptr), "uv_uptime") || GetModuleHandleW(L"node.dll")) - //{ - // InsertV8Hook(); - // return true; - //} - check_by_target=[this](){ - for (HMODULE module : { (HMODULE)processStartAddress, GetModuleHandleW(L"node.dll"), GetModuleHandleW(L"nw.dll") }) - if (GetProcAddress(module, "?Write@String@v8@@QBEHPAGHHH@Z")){ - pmodule=module; - return true; - } - - return false; - - }; + check_by_target=[this](){return attach_function_();}; }; - bool attach_function(); - private: - HMODULE pmodule; + bool attach_function_(); + bool attach_function(){return true;} }; diff --git a/LunaHook/engine64/V8.cpp b/LunaHook/engine64/V8.cpp index a6335f0..28b465d 100644 --- a/LunaHook/engine64/V8.cpp +++ b/LunaHook/engine64/V8.cpp @@ -259,18 +259,43 @@ namespace{ return innerHTML(module)|| success; } } -bool V8::attach_function() { - bool allok=false; +namespace{ + bool hookstringlength(HMODULE hm){ + auto Length=GetProcAddress(hm,"?Length@String@v8@@QEBAHXZ"); + static uintptr_t WriteUtf8; + static uintptr_t Utf8Length; + WriteUtf8=(uintptr_t)GetProcAddress(hm,"?WriteUtf8@String@v8@@QEBAHPEADHPEAHH@Z"); + Utf8Length=(uintptr_t)GetProcAddress(hm,"?Utf8Length@String@v8@@QEBAHXZ"); + if(Length==0||WriteUtf8==0||Utf8Length==0)return false; + HookParam hp; + hp.address=(uintptr_t)Length; + hp.type=USING_STRING|CODEC_UTF8; + hp.text_fun= + [](hook_stack* stack, HookParam* hp, uintptr_t* data, uintptr_t* split, size_t* len) + { + auto length=((size_t(*)(void*))Utf8Length)((void*)stack->rcx); + auto u8str=new char[length+1]; + int writen; + ((size_t(*)(void*,char*,int,int*,int))WriteUtf8)((void*)stack->rcx,u8str,length,&writen,0); + *data=(uintptr_t)u8str; + *len=length; + + }; + return NewHook(hp,"v8::String::Length"); + } +} +bool V8::attach_function_() { for (const wchar_t* moduleName : { (const wchar_t*)NULL, L"node.dll", L"nw.dll" }) { - bool ok=InsertV8Hook(GetModuleHandleW(moduleName)); - ok= hookv8exports(GetModuleHandleW(moduleName))||ok; + auto hm=GetModuleHandleW(moduleName); + if(hm==0)continue; + bool ok=InsertV8Hook(hm); + ok= hookv8exports(hm)||ok; + ok=hookstringlength(hm)||ok; + ok=addhooks(hm)||ok; if(ok){ - allok=true; - break; + return true; } } - - allok=addhooks((HMODULE)processStartAddress)||allok; - return allok; + return false; } diff --git a/LunaHook/engine64/V8.h b/LunaHook/engine64/V8.h index 1d660c6..10ecb9d 100644 --- a/LunaHook/engine64/V8.h +++ b/LunaHook/engine64/V8.h @@ -3,9 +3,10 @@ class V8:public ENGINE{ public: V8(){ - - check_by=CHECK_BY::ALL_TRUE; + check_by=CHECK_BY::CUSTOM; + check_by_target=[this](){return attach_function_();}; }; - bool attach_function(); + bool attach_function_(); + bool attach_function(){return true;} };