This commit is contained in:
恍兮惚兮 2024-02-14 23:48:36 +08:00
parent 95858a4927
commit 5e45fc7e53
4 changed files with 82 additions and 41 deletions

View File

@ -104,11 +104,45 @@ bool hookv8exports(HMODULE module) {
hp.index = 0; hp.index = 0;
return NewHook(hp, "Write@String@v8"); 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;
}

View File

@ -3,29 +3,10 @@
class V8:public ENGINE{ class V8:public ENGINE{
public: public:
V8(){ V8(){
check_by=CHECK_BY::CUSTOM; check_by=CHECK_BY::CUSTOM;
is_engine_certain=false; check_by_target=[this](){return attach_function_();};
// 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;
};
}; };
bool attach_function(); bool attach_function_();
private: bool attach_function(){return true;}
HMODULE pmodule;
}; };

View File

@ -259,18 +259,43 @@ namespace{
return innerHTML(module)|| success; return innerHTML(module)|| success;
} }
} }
bool V8::attach_function() { namespace{
bool allok=false; 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" }) { for (const wchar_t* moduleName : { (const wchar_t*)NULL, L"node.dll", L"nw.dll" }) {
bool ok=InsertV8Hook(GetModuleHandleW(moduleName)); auto hm=GetModuleHandleW(moduleName);
ok= hookv8exports(GetModuleHandleW(moduleName))||ok; if(hm==0)continue;
bool ok=InsertV8Hook(hm);
ok= hookv8exports(hm)||ok;
ok=hookstringlength(hm)||ok;
ok=addhooks(hm)||ok;
if(ok){ if(ok){
allok=true; return true;
break;
} }
} }
return false;
allok=addhooks((HMODULE)processStartAddress)||allok;
return allok;
} }

View File

@ -3,9 +3,10 @@
class V8:public ENGINE{ class V8:public ENGINE{
public: public:
V8(){ V8(){
check_by=CHECK_BY::CUSTOM;
check_by=CHECK_BY::ALL_TRUE; check_by_target=[this](){return attach_function_();};
}; };
bool attach_function(); bool attach_function_();
bool attach_function(){return true;}
}; };