diff --git a/LunaHook/engine32/V8.cpp b/LunaHook/engine32/V8.cpp index 0f26522..45693d7 100644 --- a/LunaHook/engine32/V8.cpp +++ b/LunaHook/engine32/V8.cpp @@ -120,6 +120,7 @@ namespace{ [](hook_stack* stack, HookParam* hp, uintptr_t* data, uintptr_t* split, size_t* len) { auto length=((size_t(__thiscall*)(void*))Utf8Length)((void*)stack->ecx); + if(!length)return; auto u8str=new char[length+1]; int writen; ((size_t(__thiscall*)(void*,char*,int,int*,int))WriteUtf8)((void*)stack->ecx,u8str,length,&writen,0); diff --git a/LunaHook/engine64/V8.cpp b/LunaHook/engine64/V8.cpp index 28b465d..c04e700 100644 --- a/LunaHook/engine64/V8.cpp +++ b/LunaHook/engine64/V8.cpp @@ -274,6 +274,7 @@ namespace{ [](hook_stack* stack, HookParam* hp, uintptr_t* data, uintptr_t* split, size_t* len) { auto length=((size_t(*)(void*))Utf8Length)((void*)stack->rcx); + if(!length)return; auto u8str=new char[length+1]; int writen; ((size_t(*)(void*,char*,int,int*,int))WriteUtf8)((void*)stack->rcx,u8str,length,&writen,0); diff --git a/LunaHook/engines/mono/monocommon.hpp b/LunaHook/engines/mono/monocommon.hpp index 7166563..ee71563 100644 --- a/LunaHook/engines/mono/monocommon.hpp +++ b/LunaHook/engines/mono/monocommon.hpp @@ -61,18 +61,45 @@ void unity_ui_string_hook_fun(hook_stack* stack, HookParam *hp, uintptr_t *dat #endif commonsolemonostring(offset,data,len); } -template +void unity_ui_string_hook_after(hook_stack* stack,void* data, size_t len) +{ + #ifdef _WIN64 + uintptr_t offset=stack->rdx; + #else + uintptr_t offset=stack->stack[2]; + #endif + MonoString* string = (MonoString*)offset; + if(string==0)return; + if(wcslen((wchar_t*)string->chars)!=string->length)return; + + //其实也可以直接覆写到原来的String上,但重新创建一个是更安全的操作。 + auto newstring=(MonoString*)malloc(sizeof(MonoString)+len+2); + memcpy(newstring,string,sizeof(MonoString)); + wcscpy((wchar_t*)newstring->chars,(wchar_t*)data); + newstring->length=len/2; + #ifdef _WIN64 + stack->rdx=(uintptr_t)newstring; + #else + stack->stack[2]=(uintptr_t)newstring; + #endif +} +template void MONO_IL2CPP_NEW_HOOK(uintptr_t addr,const char*name){ if(addr==0)return; HookParam hp; hp.address = addr; hp.type = USING_STRING | CODEC_UTF16|FULL_STRING; hp.text_fun =(decltype(hp.text_fun))text_fun; - + + if(hook_after) + { + hp.type|=EMBED_ABLE|EMBED_BEFORE_SIMPLE; + hp.hook_after=(decltype(hp.hook_after))hook_after; + } NewHook_check(hp, name); } -auto unity_ui_string_hook=MONO_IL2CPP_NEW_HOOK; -auto mscorlib_system_string_hook=MONO_IL2CPP_NEW_HOOK; +auto unity_ui_string_hook=MONO_IL2CPP_NEW_HOOK; +auto mscorlib_system_string_hook=MONO_IL2CPP_NEW_HOOK; /** jichi 12/26/2014 Mono