mirror of
https://github.com/HIllya51/LunaHook.git
synced 2024-11-23 22:05:36 +08:00
simplfy
This commit is contained in:
parent
780cc66c4f
commit
2fa1f50aed
@ -33,24 +33,13 @@ void commonsolvemonostring(uintptr_t offset,uintptr_t *data, size_t*len){
|
|||||||
}
|
}
|
||||||
void mscorlib_system_string_hook_fun(hook_stack* stack, HookParam *hp, uintptr_t *data, uintptr_t *split, size_t*len)
|
void mscorlib_system_string_hook_fun(hook_stack* stack, HookParam *hp, uintptr_t *data, uintptr_t *split, size_t*len)
|
||||||
{
|
{
|
||||||
#ifdef _WIN64
|
commonsolvemonostring(stack->ARG1,data,len);
|
||||||
uintptr_t offset=stack->rcx;
|
|
||||||
#else
|
|
||||||
uintptr_t offset=stack->stack[1];
|
|
||||||
#endif
|
|
||||||
commonsolvemonostring(offset,data,len);
|
|
||||||
}
|
}
|
||||||
void mscorlib_system_string_InternalSubString_hook_fun(hook_stack* stack, HookParam *hp, uintptr_t *data, uintptr_t *split, size_t*len)
|
void mscorlib_system_string_InternalSubString_hook_fun(hook_stack* stack, HookParam *hp, uintptr_t *data, uintptr_t *split, size_t*len)
|
||||||
{
|
{
|
||||||
#ifdef _WIN64
|
uintptr_t offset=stack->ARG1;
|
||||||
uintptr_t offset=stack->rcx;
|
uintptr_t startIndex=stack->ARG2;
|
||||||
uintptr_t startIndex=stack->rdx;
|
uintptr_t length=stack->ARG3;
|
||||||
uintptr_t length=stack->r8;
|
|
||||||
#else
|
|
||||||
uintptr_t offset=stack->stack[1];
|
|
||||||
uintptr_t startIndex=stack->stack[2];
|
|
||||||
uintptr_t length=stack->stack[3];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
MonoString* string = (MonoString*)offset;
|
MonoString* string = (MonoString*)offset;
|
||||||
if(string==0)return;
|
if(string==0)return;
|
||||||
@ -73,21 +62,11 @@ auto mscorlib_system_string_funcs=std::unordered_map<std::string,void*>{
|
|||||||
};
|
};
|
||||||
void unity_ui_string_hook_fun(hook_stack* stack, HookParam *hp, uintptr_t *data, uintptr_t *split, size_t*len)
|
void unity_ui_string_hook_fun(hook_stack* stack, HookParam *hp, uintptr_t *data, uintptr_t *split, size_t*len)
|
||||||
{
|
{
|
||||||
#ifdef _WIN64
|
commonsolvemonostring(stack->ARG2,data,len);
|
||||||
uintptr_t offset=stack->rdx;
|
|
||||||
#else
|
|
||||||
uintptr_t offset=stack->stack[2];
|
|
||||||
#endif
|
|
||||||
commonsolvemonostring(offset,data,len);
|
|
||||||
}
|
}
|
||||||
void unity_ui_string_hook_after(hook_stack* stack,void* data, size_t len)
|
void unity_ui_string_hook_after(hook_stack* stack,void* data, size_t len)
|
||||||
{
|
{
|
||||||
#ifdef _WIN64
|
MonoString* string = (MonoString*)stack->ARG2;
|
||||||
uintptr_t offset=stack->rdx;
|
|
||||||
#else
|
|
||||||
uintptr_t offset=stack->stack[2];
|
|
||||||
#endif
|
|
||||||
MonoString* string = (MonoString*)offset;
|
|
||||||
if(string==0)return;
|
if(string==0)return;
|
||||||
if(wcslen((wchar_t*)string->chars)!=string->length)return;
|
if(wcslen((wchar_t*)string->chars)!=string->length)return;
|
||||||
|
|
||||||
@ -96,11 +75,7 @@ void unity_ui_string_hook_after(hook_stack* stack,void* data, size_t len)
|
|||||||
memcpy(newstring,string,sizeof(MonoString));
|
memcpy(newstring,string,sizeof(MonoString));
|
||||||
wcscpy((wchar_t*)newstring->chars,(wchar_t*)data);
|
wcscpy((wchar_t*)newstring->chars,(wchar_t*)data);
|
||||||
newstring->length=len/2;
|
newstring->length=len/2;
|
||||||
#ifdef _WIN64
|
stack->ARG2=(uintptr_t)newstring;
|
||||||
stack->rdx=(uintptr_t)newstring;
|
|
||||||
#else
|
|
||||||
stack->stack[2]=(uintptr_t)newstring;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MONO_IL2CPP_NEW_HOOK(void* text_fun,void* hook_after, uintptr_t addr,const char*name){
|
void MONO_IL2CPP_NEW_HOOK(void* text_fun,void* hook_after, uintptr_t addr,const char*name){
|
||||||
|
@ -42,13 +42,8 @@ void PyRunScript(const char* script)
|
|||||||
void hook_internal_renpy_call_host(){
|
void hook_internal_renpy_call_host(){
|
||||||
HookParam hp_internal;
|
HookParam hp_internal;
|
||||||
hp_internal.address=(uintptr_t)internal_renpy_call_host;
|
hp_internal.address=(uintptr_t)internal_renpy_call_host;
|
||||||
#ifndef _WIN64
|
hp_internal.offset=GETARG1;
|
||||||
hp_internal.offset=get_stack(1);
|
hp_internal.split=GETARG2;
|
||||||
hp_internal.split=get_stack(2);
|
|
||||||
#else
|
|
||||||
hp_internal.offset=get_reg(regs::rcx);
|
|
||||||
hp_internal.split=get_reg(regs::rdx);
|
|
||||||
#endif
|
|
||||||
hp_internal.type=USING_SPLIT|USING_STRING|CODEC_UTF16|EMBED_ABLE|EMBED_BEFORE_SIMPLE|EMBED_AFTER_NEW;
|
hp_internal.type=USING_SPLIT|USING_STRING|CODEC_UTF16|EMBED_ABLE|EMBED_BEFORE_SIMPLE|EMBED_AFTER_NEW;
|
||||||
NewHook(hp_internal, "internal_renpy_call_host");
|
NewHook(hp_internal, "internal_renpy_call_host");
|
||||||
PyRunScript(LoadResData(L"renpy_hook_text",L"PYSOURCE").c_str());
|
PyRunScript(LoadResData(L"renpy_hook_text",L"PYSOURCE").c_str());
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include"types.h"
|
#include"types.h"
|
||||||
#include"python.h"
|
#include"python.h"
|
||||||
#include"main.h"
|
#include"main.h"
|
||||||
|
#include"stackoffset.hpp"
|
||||||
namespace {
|
namespace {
|
||||||
typedef wchar_t Py_UNICODE ;
|
typedef wchar_t Py_UNICODE ;
|
||||||
typedef size_t Py_ssize_t;
|
typedef size_t Py_ssize_t;
|
||||||
@ -82,11 +83,7 @@ bool InsertRenpyHook(){
|
|||||||
|
|
||||||
hp.text_fun = [](hook_stack* stack, HookParam* hp, uintptr_t* data, uintptr_t* split, size_t* len)
|
hp.text_fun = [](hook_stack* stack, HookParam* hp, uintptr_t* data, uintptr_t* split, size_t* len)
|
||||||
{
|
{
|
||||||
#ifndef _WIN64
|
auto format=(PyObject *)stack->ARG1;
|
||||||
auto format=(PyObject *)stack->stack[1];
|
|
||||||
#else
|
|
||||||
auto format=(PyObject *)stack->rcx;
|
|
||||||
#endif
|
|
||||||
auto [strptr,strlen]=GetPyUnicodeString(format);
|
auto [strptr,strlen]=GetPyUnicodeString(format);
|
||||||
*data=(uintptr_t)strptr;
|
*data=(uintptr_t)strptr;
|
||||||
*len=0;
|
*len=0;
|
||||||
@ -101,18 +98,9 @@ bool InsertRenpyHook(){
|
|||||||
hp.type|=EMBED_ABLE|EMBED_BEFORE_SIMPLE;
|
hp.type|=EMBED_ABLE|EMBED_BEFORE_SIMPLE;
|
||||||
hp.hook_after=[](hook_stack* stack,void* data, size_t len)
|
hp.hook_after=[](hook_stack* stack,void* data, size_t len)
|
||||||
{
|
{
|
||||||
#ifndef _WIN64
|
auto format=(PyObject *)stack->ARG1;
|
||||||
auto format=(PyObject *)stack->stack[1];
|
|
||||||
#else
|
|
||||||
auto format=(PyObject *)stack->rcx;
|
|
||||||
#endif
|
|
||||||
if(format==NULL)return;
|
if(format==NULL)return;
|
||||||
#ifndef _WIN64
|
stack->ARG1=(uintptr_t)PyUnicode_FromUnicode((Py_UNICODE *)data,len/2);
|
||||||
stack->stack[1]=
|
|
||||||
#else
|
|
||||||
stack->rcx=
|
|
||||||
#endif
|
|
||||||
(uintptr_t)PyUnicode_FromUnicode((Py_UNICODE *)data,len/2);
|
|
||||||
};
|
};
|
||||||
hookrenpy(module);
|
hookrenpy(module);
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,7 @@
|
|||||||
#include"main.h"
|
#include"main.h"
|
||||||
#include"v8.h"
|
#include"v8.h"
|
||||||
#include"embed_util.h"
|
#include"embed_util.h"
|
||||||
#ifndef _WIN64
|
#include"stackoffset.hpp"
|
||||||
#define arg2 stack[2]
|
|
||||||
#else
|
|
||||||
#define arg2 rdx
|
|
||||||
#endif
|
|
||||||
namespace{
|
namespace{
|
||||||
|
|
||||||
bool hookClipboard(){
|
bool hookClipboard(){
|
||||||
@ -17,7 +13,7 @@ namespace{
|
|||||||
hp.address=(uintptr_t)SetClipboardData;
|
hp.address=(uintptr_t)SetClipboardData;
|
||||||
hp.type= USING_STRING|CODEC_UTF16|EMBED_ABLE|EMBED_BEFORE_SIMPLE;
|
hp.type= USING_STRING|CODEC_UTF16|EMBED_ABLE|EMBED_BEFORE_SIMPLE;
|
||||||
hp.text_fun=[](hook_stack* stack, HookParam *hp, uintptr_t* data, uintptr_t* split, size_t* len){
|
hp.text_fun=[](hook_stack* stack, HookParam *hp, uintptr_t* data, uintptr_t* split, size_t* len){
|
||||||
HGLOBAL hClipboardData=(HGLOBAL)stack->arg2;
|
HGLOBAL hClipboardData=(HGLOBAL)stack->ARG2;
|
||||||
*data=(uintptr_t)GlobalLock(hClipboardData);
|
*data=(uintptr_t)GlobalLock(hClipboardData);
|
||||||
*len=wcslen((wchar_t*)*data)*2;
|
*len=wcslen((wchar_t*)*data)*2;
|
||||||
GlobalUnlock(hClipboardData);
|
GlobalUnlock(hClipboardData);
|
||||||
@ -33,7 +29,7 @@ namespace{
|
|||||||
auto pchData = (wchar_t*)GlobalLock(hClipboardData);
|
auto pchData = (wchar_t*)GlobalLock(hClipboardData);
|
||||||
wcscpy(pchData, (wchar_t*)transwithfont.c_str());
|
wcscpy(pchData, (wchar_t*)transwithfont.c_str());
|
||||||
GlobalUnlock(hClipboardData);
|
GlobalUnlock(hClipboardData);
|
||||||
s->arg2=(uintptr_t)hClipboardData;
|
s->ARG2=(uintptr_t)hClipboardData;
|
||||||
};
|
};
|
||||||
return NewHook(hp,"hookClipboard");
|
return NewHook(hp,"hookClipboard");
|
||||||
}
|
}
|
||||||
@ -53,12 +49,7 @@ typedef void(*RequestInterrupt_callback)(void*, void*);
|
|||||||
#define fnRunv1 "?Run@Script@v8@@QAE?AV?$Local@VValue@v8@@@2@XZ"
|
#define fnRunv1 "?Run@Script@v8@@QAE?AV?$Local@VValue@v8@@@2@XZ"
|
||||||
#define fnCompilev2 "?Compile@Script@v8@@SA?AV?$MaybeLocal@VScript@v8@@@2@V?$Local@VContext@v8@@@2@V?$Local@VString@v8@@@2@PAVScriptOrigin@2@@Z"
|
#define fnCompilev2 "?Compile@Script@v8@@SA?AV?$MaybeLocal@VScript@v8@@@2@V?$Local@VContext@v8@@@2@V?$Local@VString@v8@@@2@PAVScriptOrigin@2@@Z"
|
||||||
#define fnRunv2 "?Run@Script@v8@@QAE?AV?$MaybeLocal@VValue@v8@@@2@V?$Local@VContext@v8@@@2@@Z"
|
#define fnRunv2 "?Run@Script@v8@@QAE?AV?$MaybeLocal@VValue@v8@@@2@V?$Local@VContext@v8@@@2@@Z"
|
||||||
typedef void*(__thiscall *GetCurrentContextt)(void*, void*);
|
|
||||||
|
|
||||||
typedef void*(__thiscall*Runt1)(void*,void*);
|
|
||||||
typedef void*(__thiscall*Runt2)(void*,void*,void*);
|
|
||||||
|
|
||||||
typedef void*(__thiscall *RequestInterruptt)(void*, RequestInterrupt_callback, void*);
|
|
||||||
#else
|
#else
|
||||||
#define fnRequestInterrupt "?RequestInterrupt@Isolate@v8@@QEAAXP6AXPEAV12@PEAX@Z1@Z"
|
#define fnRequestInterrupt "?RequestInterrupt@Isolate@v8@@QEAAXP6AXPEAV12@PEAX@Z1@Z"
|
||||||
#define fnNewFromUtf8v2 "?NewFromUtf8@String@v8@@SA?AV?$MaybeLocal@VString@v8@@@2@PEAVIsolate@2@PEBDW4NewStringType@2@H@Z"
|
#define fnNewFromUtf8v2 "?NewFromUtf8@String@v8@@SA?AV?$MaybeLocal@VString@v8@@@2@PEAVIsolate@2@PEBDW4NewStringType@2@H@Z"
|
||||||
@ -69,13 +60,13 @@ typedef void*(__thiscall *RequestInterruptt)(void*, RequestInterrupt_callback, v
|
|||||||
#define fnRunv1 "?Run@Script@v8@@QEAA?AV?$Local@VValue@v8@@@2@XZ"
|
#define fnRunv1 "?Run@Script@v8@@QEAA?AV?$Local@VValue@v8@@@2@XZ"
|
||||||
#define fnCompilev2 "?Compile@Script@v8@@SA?AV?$MaybeLocal@VScript@v8@@@2@V?$Local@VContext@v8@@@2@V?$Local@VString@v8@@@2@PEAVScriptOrigin@2@@Z"
|
#define fnCompilev2 "?Compile@Script@v8@@SA?AV?$MaybeLocal@VScript@v8@@@2@V?$Local@VContext@v8@@@2@V?$Local@VString@v8@@@2@PEAVScriptOrigin@2@@Z"
|
||||||
#define fnRunv2 "?Run@Script@v8@@QEAA?AV?$MaybeLocal@VValue@v8@@@2@V?$Local@VContext@v8@@@2@@Z"
|
#define fnRunv2 "?Run@Script@v8@@QEAA?AV?$MaybeLocal@VValue@v8@@@2@V?$Local@VContext@v8@@@2@@Z"
|
||||||
typedef void*(*GetCurrentContextt)(void*, void*);
|
|
||||||
typedef void*(*Runt1)(void*,void*);
|
|
||||||
typedef void*(*Runt2)(void*,void*,void*);
|
|
||||||
|
|
||||||
typedef void*(*RequestInterruptt)(void*, RequestInterrupt_callback, void*);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
typedef void*(THISCALL *GetCurrentContextt)(void*, void*);
|
||||||
|
typedef void*(THISCALL *Runt1)(void*,void*);
|
||||||
|
typedef void*(THISCALL *Runt2)(void*,void*,void*);
|
||||||
|
typedef void*(THISCALL *RequestInterruptt)(void*, RequestInterrupt_callback, void*);
|
||||||
|
|
||||||
typedef void*(*NewFromUtf8t)(void*, void*, const char*, int, int) ;
|
typedef void*(*NewFromUtf8t)(void*, void*, const char*, int, int) ;
|
||||||
typedef void*(*Compilet)(void*, void*, void*, void*);
|
typedef void*(*Compilet)(void*, void*, void*, void*);
|
||||||
RequestInterruptt RequestInterrupt;
|
RequestInterruptt RequestInterrupt;
|
||||||
@ -151,13 +142,8 @@ void v8runscript_isolate_bypass(hook_stack* stack, HookParam* hp, uintptr_t* dat
|
|||||||
static bool runonce=false;
|
static bool runonce=false;
|
||||||
if(runonce)return;
|
if(runonce)return;
|
||||||
runonce=true;
|
runonce=true;
|
||||||
#ifndef _WIN64
|
|
||||||
#define isolatearg stack[2]
|
auto isolate=(void*)stack->ARG2;//测试正确,且和v8::Isolate::GetCurrent结果相同
|
||||||
#else
|
|
||||||
#define isolatearg rdx
|
|
||||||
#endif
|
|
||||||
|
|
||||||
auto isolate=(void*)stack->isolatearg;//测试正确,且和v8::Isolate::GetCurrent结果相同
|
|
||||||
v8runscript_isolate(isolate);
|
v8runscript_isolate(isolate);
|
||||||
}
|
}
|
||||||
void* v8getcurrisolate(HMODULE hmod){
|
void* v8getcurrisolate(HMODULE hmod){
|
||||||
@ -226,20 +212,12 @@ namespace{
|
|||||||
[](hook_stack* stack, HookParam* hp, uintptr_t* data, uintptr_t* split, size_t* len)
|
[](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->THISCALLTHIS);
|
||||||
auto length=((size_t(__thiscall*)(void*))Utf8Length)((void*)stack->ecx);
|
|
||||||
#else
|
|
||||||
auto length=((size_t(*)(void*))Utf8Length)((void*)stack->rcx);
|
|
||||||
#endif
|
|
||||||
if(!length)return;
|
if(!length)return;
|
||||||
auto u8str=new char[length+1];
|
auto u8str=new char[length+1];
|
||||||
int writen;
|
int writen;
|
||||||
#ifndef _WIN64
|
((size_t(THISCALL *)(void*,char*,int,int*,int))WriteUtf8)((void*)stack->THISCALLTHIS,u8str,length,&writen,0);
|
||||||
((size_t(__thiscall*)(void*,char*,int,int*,int))WriteUtf8)((void*)stack->ecx,u8str,length,&writen,0);
|
*data=(uintptr_t)u8str;
|
||||||
#else
|
|
||||||
((size_t(*)(void*,char*,int,int*,int))WriteUtf8)((void*)stack->rcx,u8str,length,&writen,0);
|
|
||||||
#endif
|
|
||||||
*data=(uintptr_t)u8str;
|
|
||||||
*len=length;
|
*len=length;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -82,3 +82,21 @@ inline uintptr_t regof(regs reg,hook_stack* stack){
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef _WIN64
|
||||||
|
#define ARG1 stack[1]
|
||||||
|
#define ARG2 stack[2]
|
||||||
|
#define ARG3 stack[3]
|
||||||
|
#define THISCALL __thiscall
|
||||||
|
#define THISCALLTHIS ecx
|
||||||
|
#define GETARG1 get_stack(1)
|
||||||
|
#define GETARG2 get_stack(2)
|
||||||
|
#else
|
||||||
|
#define ARG1 rcx
|
||||||
|
#define ARG2 rdx
|
||||||
|
#define ARG3 r8
|
||||||
|
#define THISCALLTHIS rcx
|
||||||
|
#define THISCALL
|
||||||
|
#define GETARG1 get_reg(regs::rcx)
|
||||||
|
#define GETARG2 get_reg(regs::rdx)
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user