mirror of
https://github.com/HIllya51/LunaHook.git
synced 2025-01-11 20:39:34 +08:00
Update V8.cpp
v8 v8 Update v8.cpp
This commit is contained in:
parent
4ae1e459e8
commit
a99cd999e0
@ -1,5 +1,6 @@
|
||||
#include"V8.h"
|
||||
#include"v8/v8.h"
|
||||
#if 0
|
||||
/**
|
||||
* Artikash 7/15/2018: Insert Tyranobuilder hook
|
||||
* Sample game: https://vndb.org/v22252: /HWN-8:-1C@233A54:yuika_t.exe
|
||||
@ -71,6 +72,7 @@ bool InsertV8Hook(HMODULE module)
|
||||
return succ;
|
||||
}
|
||||
bool hookv8addr(HMODULE module) {
|
||||
if (GetProcAddress(module, "?Write@String@v8@@QBEHPAGHHH@Z")==0)false;
|
||||
auto [minAddress, maxAddress] = Util::QueryModuleLimits(module);
|
||||
const BYTE bytes[] = {
|
||||
0x89,0xc1,
|
||||
@ -92,32 +94,9 @@ bool hookv8addr(HMODULE module) {
|
||||
return NewHook(hp, "electronW");
|
||||
}
|
||||
|
||||
bool hookv8exports(HMODULE module) {
|
||||
|
||||
auto addr = GetProcAddress(module, "?Write@String@v8@@QBEHPAVIsolate@2@PAGHHH@Z");
|
||||
if (addr == 0)return false;
|
||||
HookParam hp;
|
||||
hp.address = (uint64_t)addr;
|
||||
hp.type = USING_STRING | CODEC_UTF16 | DATA_INDIRECT;
|
||||
hp.offset=get_reg(regs::ecx);
|
||||
hp.padding = 11;
|
||||
hp.index = 0;
|
||||
return NewHook(hp, "Write@String@v8");
|
||||
}
|
||||
|
||||
#endif
|
||||
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=tryhookv8(hm)||b1;
|
||||
if(b1||b2||b3){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
return tryhookv8();
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include"V8.h"
|
||||
#include"v8/v8.h"
|
||||
#if 0
|
||||
// Artikash 6/23/2019: V8 (JavaScript runtime) has rcx = string** at v8::String::Write
|
||||
// sample game https://www.freem.ne.jp/dl/win/18963
|
||||
bool InsertV8Hook(HMODULE module)
|
||||
@ -45,58 +46,6 @@ bool InsertV8Hook(HMODULE module)
|
||||
}
|
||||
return succ;
|
||||
}
|
||||
|
||||
bool hookv8exports(HMODULE module) {
|
||||
enum { rcx=-0x1c };
|
||||
auto addr = GetProcAddress(module, "?Write@String@v8@@QEBAHPEAVIsolate@2@PEAGHHH@Z");
|
||||
if (addr == 0)return false;
|
||||
HookParam hp;
|
||||
hp.address = (uint64_t)addr ;
|
||||
hp.type = USING_STRING | CODEC_UTF16 |NO_CONTEXT;
|
||||
|
||||
hp.text_fun = [](hook_stack* stack, HookParam *hp, uintptr_t* data, uintptr_t* split, size_t* count)
|
||||
{
|
||||
*data=*(uintptr_t*)(stack->rcx)+0xf;
|
||||
int len = *(uintptr_t*)((uintptr_t)*data - 4);
|
||||
|
||||
if(strlen((char*)*data)==len){
|
||||
*count = len;
|
||||
hp->type=USING_STRING|CODEC_UTF8| DATA_INDIRECT|NO_CONTEXT;
|
||||
*split = (strchr((char*)*data, '<') != nullptr)&&(strchr((char*)*data, '>') != nullptr);
|
||||
*split+=0x10;
|
||||
|
||||
}
|
||||
else if((wcslen((wchar_t*)*data)==len)){
|
||||
*count = len*2;
|
||||
*split = (wcschr((wchar_t*)*data, L'<') != nullptr)&&(wcschr((wchar_t*)*data, L'>') != nullptr);
|
||||
hp->type=USING_STRING|CODEC_UTF16| DATA_INDIRECT|NO_CONTEXT;
|
||||
}
|
||||
else{
|
||||
//ConsoleOutput("%d %d %d",len,strlen((char*)*data),wcslen((wchar_t*)*data));
|
||||
return;
|
||||
}
|
||||
|
||||
};
|
||||
// hp.filter_fun=[](void* data, uintptr_t* size, HookParam*) {
|
||||
|
||||
// auto text = reinterpret_cast<LPWSTR>(data);
|
||||
// std::wstring str = text;
|
||||
// str = str.substr(0, *size / 2);
|
||||
// std::wregex reg1(L"<rt>(.*?)</rt>");
|
||||
// std::wstring result2 = std::regex_replace(str, reg1, L"");
|
||||
// std::wregex reg12(L"<span(.*?)visibility: visible(.*?)>(.*?)</span>");
|
||||
// result2 = std::regex_replace(result2, reg12, L"");
|
||||
// std::wregex reg2(L"<(.*?)>");
|
||||
// result2 = std::regex_replace(result2, reg2, L"");
|
||||
// std::wregex reg22(L"\n");
|
||||
// result2 = std::regex_replace(result2, reg22, L"");
|
||||
// *size = (result2.size()) * 2;
|
||||
// wcscpy(text, result2.c_str());
|
||||
// return true;
|
||||
// };
|
||||
|
||||
return NewHook(hp, "Write@String@v8");
|
||||
}
|
||||
namespace{
|
||||
uintptr_t forwardsearch(BYTE* b,int size,uintptr_t addr,int range){
|
||||
for(int i=0;i<range;i++){
|
||||
@ -164,6 +113,7 @@ namespace{
|
||||
}
|
||||
return save;
|
||||
}
|
||||
#if 0
|
||||
std::vector<HookParam> v8hook1(HMODULE module) {
|
||||
|
||||
const BYTE BYTES[] = {
|
||||
@ -205,6 +155,7 @@ namespace{
|
||||
}
|
||||
return save;
|
||||
}
|
||||
#endif
|
||||
bool innerHTML(HMODULE module) {
|
||||
//花葬
|
||||
//result = sub_142DF3CA0(a2, v5, 1u, (__int64)"innerHTML", a3);
|
||||
@ -249,9 +200,6 @@ namespace{
|
||||
bool addhooks(HMODULE module){
|
||||
if (GetProcAddress(module, "?Write@String@v8@@QEBAHPEAVIsolate@2@PEAGHHH@Z") == 0)return false;
|
||||
bool success=false;
|
||||
for(auto h:v8hook1(module)){
|
||||
success|=NewHook(h,"electronQ");
|
||||
}
|
||||
for(auto h:hookw(module)){
|
||||
success|=NewHook(h,"electronW");
|
||||
}
|
||||
@ -259,16 +207,9 @@ namespace{
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
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;
|
||||
bool ok=InsertV8Hook(hm);
|
||||
ok= hookv8exports(hm)||ok;
|
||||
ok=addhooks(hm)||ok;
|
||||
ok=tryhookv8(hm);
|
||||
if(ok) return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
return tryhookv8();
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
|
||||
#include"common.h"
|
||||
#include"defs.h"
|
||||
#include"types.h"
|
||||
#include"main.h"
|
||||
#include"v8.h"
|
||||
@ -142,15 +145,18 @@ bool v8runscript_isolate(void* isolate){
|
||||
}
|
||||
|
||||
void v8runscript_isolate_bypass(hook_stack* stack, HookParam* hp, uintptr_t* data, uintptr_t* split, size_t* len){
|
||||
|
||||
|
||||
hp->type=HOOK_EMPTY;hp->text_fun=nullptr;
|
||||
static bool runonce=false;
|
||||
if(runonce)return;
|
||||
runonce=true;
|
||||
#ifndef _WIN64
|
||||
#define isolatearg stack[2]
|
||||
#else
|
||||
#define isolatearg rdx
|
||||
#endif
|
||||
auto isolate=(void*)stack->isolatearg;//测试正确,且和v8::Isolate::GetCurrent结果相同
|
||||
|
||||
auto isolate=(void*)stack->isolatearg;//测试正确,且和v8::Isolate::GetCurrent结果相同
|
||||
v8runscript_isolate(isolate);
|
||||
}
|
||||
void* v8getcurrisolate(HMODULE hmod){
|
||||
@ -174,48 +180,51 @@ bool v8runscript(HMODULE _hmodule){
|
||||
if(isolate)
|
||||
return v8runscript_isolate(isolate);
|
||||
#ifndef _WIN64
|
||||
#define fnisolategetter "?NewFromUtf8@String@v8@@SA?AV?$Local@VString@v8@@@2@PAVIsolate@2@PBDW4NewStringType@12@H@Z"
|
||||
#define fnisolategetter2 fnisolategetter
|
||||
#define fnisolategetters {"?New@Number@v8@@SA?AV?$Local@VNumber@v8@@@2@PEAVIsolate@2@N@Z","?New@Number@v8@@SA?AV?$Local@VNumber@v8@@@2@PAVIsolate@2@N@Z","?NewFromUtf8@String@v8@@SA?AV?$Local@VString@v8@@@2@PAVIsolate@2@PBDW4NewStringType@12@H@Z"}
|
||||
#else
|
||||
#define fnisolategetter "?Utf8Length@String@v8@@QEBAHPEAVIsolate@2@@Z"
|
||||
#define fnisolategetter2 "?NewFromUtf8@String@v8@@SA?AV?$Local@VString@v8@@@2@PEAVIsolate@2@PEBDW4NewStringType@12@H@Z"
|
||||
#define fnisolategetters {"?New@Integer@v8@@SA?AV?$Local@VInteger@v8@@@2@PEAVIsolate@2@H@Z","?New@Number@v8@@SA?AV?$Local@VNumber@v8@@@2@PEAVIsolate@2@N@Z","?New@Number@v8@@SA?AV?$Local@VNumber@v8@@@2@PAVIsolate@2@N@Z","?NewFromUtf8@String@v8@@SA?AV?$Local@VString@v8@@@2@PEAVIsolate@2@PEBDW4NewStringType@12@H@Z","?Utf8Length@String@v8@@QEBAHPEAVIsolate@2@@Z"}
|
||||
#endif
|
||||
auto isolategetter=GetProcAddress(_hmodule,fnisolategetter);
|
||||
if(!isolategetter)
|
||||
isolategetter=GetProcAddress(_hmodule,fnisolategetter2);
|
||||
if(!isolategetter)return false;
|
||||
|
||||
hmodule=_hmodule;
|
||||
HookParam hp;
|
||||
hp.address=(uintptr_t)isolategetter;
|
||||
hp.text_fun=v8runscript_isolate_bypass;
|
||||
return NewHook(hp,"v8isolate");
|
||||
|
||||
bool succ=false;
|
||||
for(auto fnisolategetter:fnisolategetters){
|
||||
auto isolategetter=GetProcAddress(_hmodule,fnisolategetter);
|
||||
if(!isolategetter)continue;
|
||||
hmodule=_hmodule;
|
||||
HookParam hp;
|
||||
hp.address=(uintptr_t)isolategetter;
|
||||
hp.text_fun=v8runscript_isolate_bypass;
|
||||
succ|= NewHook(hp,"isolategetter");
|
||||
}
|
||||
return succ;
|
||||
}
|
||||
}
|
||||
namespace{
|
||||
bool hookstringlength(HMODULE hm){
|
||||
#ifndef _WIN64
|
||||
#define v8StringLength "?Length@String@v8@@QBEHXZ"
|
||||
#define v8StringWriteUtf8 "?WriteUtf8@String@v8@@QBEHPADHPAHH@Z"
|
||||
#define v8StringUtf8Length "?Utf8Length@String@v8@@QBEHXZ"
|
||||
#else
|
||||
#define v8StringLength "?Length@String@v8@@QEBAHXZ"
|
||||
#define v8StringWriteUtf8 "?WriteUtf8@String@v8@@QEBAHPEADHPEAHH@Z"
|
||||
#define v8StringUtf8Length "?Utf8Length@String@v8@@QEBAHXZ"
|
||||
#endif
|
||||
auto Length=GetProcAddress(hm,v8StringLength);
|
||||
static uintptr_t WriteUtf8;
|
||||
static uintptr_t Utf8Length;
|
||||
#ifndef _WIN64
|
||||
#define v8StringLength "?Length@String@v8@@QBEHXZ"
|
||||
#define v8StringWriteUtf8 "?WriteUtf8@String@v8@@QBEHPADHPAHH@Z"
|
||||
#define v8StringUtf8Length "?Utf8Length@String@v8@@QBEHXZ"
|
||||
#define v8StringWrite "?Write@String@v8@@QBEHPAGHHH@Z"
|
||||
#define v8StringWriteIsolate "?Write@String@v8@@QBEHPAVIsolate@2@PAGHHH@Z"
|
||||
#else
|
||||
#define v8StringLength "?Length@String@v8@@QEBAHXZ"
|
||||
#define v8StringWriteUtf8 "?WriteUtf8@String@v8@@QEBAHPEADHPEAHH@Z"
|
||||
#define v8StringUtf8Length "?Utf8Length@String@v8@@QEBAHXZ"
|
||||
#define v8StringWrite "?Write@String@v8@@QEBAHPEAGHHH@Z"
|
||||
#define v8StringWriteIsolate "?Write@String@v8@@QEBAHPEAVIsolate@2@PEAGHHH@Z"
|
||||
#endif
|
||||
uintptr_t WriteUtf8;
|
||||
uintptr_t Utf8Length;
|
||||
bool hookstring(HMODULE hm){
|
||||
WriteUtf8=(uintptr_t)GetProcAddress(hm,v8StringWriteUtf8);
|
||||
Utf8Length=(uintptr_t)GetProcAddress(hm,v8StringUtf8Length);
|
||||
if(Length==0||WriteUtf8==0||Utf8Length==0)return false;
|
||||
if(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)
|
||||
{
|
||||
|
||||
#ifndef _WIN64
|
||||
auto length=((size_t(__thiscall*)(void*))Utf8Length)((void*)stack->ecx);
|
||||
#else
|
||||
@ -237,12 +246,40 @@ namespace{
|
||||
if(strstr((char*)data,R"(\\?\)")!=0)return false;//过滤路径
|
||||
return true;
|
||||
};
|
||||
return NewHook(hp,"v8::String::Length");
|
||||
bool succ=false;
|
||||
|
||||
auto pv8StringLength=GetProcAddress(hm,v8StringLength);
|
||||
if(pv8StringLength){
|
||||
|
||||
hp.address=(uintptr_t)pv8StringLength;
|
||||
succ|=NewHook(hp,"v8::String::Length");
|
||||
}
|
||||
auto pv8StringWrite=GetProcAddress(hm,v8StringWrite);
|
||||
if(pv8StringWrite){
|
||||
|
||||
hp.address=(uintptr_t)pv8StringWrite;
|
||||
succ|=NewHook(hp,"v8::String::Write");
|
||||
}
|
||||
auto pv8StringWriteIsolate=GetProcAddress(hm,v8StringWriteIsolate);
|
||||
if(pv8StringWriteIsolate){
|
||||
hp.address=(uintptr_t)pv8StringWriteIsolate;
|
||||
succ|=NewHook(hp,"v8::String::Write::isolate");
|
||||
}
|
||||
return succ;
|
||||
}
|
||||
}
|
||||
bool tryhookv8(HMODULE hm){
|
||||
auto succ=hookstringlength(hm);
|
||||
bool tryhookv8_internal(HMODULE hm){
|
||||
auto succ=hookstring(hm);
|
||||
if(v8script::v8runscript(hm))
|
||||
succ|= hookClipboard();
|
||||
return succ;
|
||||
}
|
||||
}
|
||||
bool tryhookv8() {
|
||||
for (const wchar_t* moduleName : { (const wchar_t*)NULL, L"node.dll", L"nw.dll" }) {
|
||||
auto hm=GetModuleHandleW(moduleName);
|
||||
if(hm==0)continue;
|
||||
bool ok=tryhookv8_internal(hm);
|
||||
if(ok) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -1,2 +1,2 @@
|
||||
|
||||
bool tryhookv8(HMODULE hm);
|
||||
bool tryhookv8();
|
Loading…
x
Reference in New Issue
Block a user