This commit is contained in:
恍兮惚兮 2024-05-14 10:32:10 +08:00
parent bdd8c86474
commit 216f784790
5 changed files with 35 additions and 25 deletions

View File

@ -561,7 +561,7 @@ namespace il2cpp_symbols
void init(HMODULE game_module); void init(HMODULE game_module);
uintptr_t get_method_pointer(const char* assemblyName, const char* namespaze, uintptr_t get_method_pointer(const char* assemblyName, const char* namespaze,
const char* klassName, const char* name, int argsCount); const char* klassName, const char* name, int argsCount,bool strict);
Il2CppClass* get_class(const char* assemblyName, const char* namespaze, const char* klassName); Il2CppClass* get_class(const char* assemblyName, const char* namespaze, const char* klassName);

View File

@ -69,7 +69,7 @@ namespace il2cpp_symbols
RESOLVE_IMPORT(il2cpp_domain_get_assemblies); RESOLVE_IMPORT(il2cpp_domain_get_assemblies);
} }
Il2CppClass* get_il2cppclass1(const char* assemblyName, const char* namespaze, Il2CppClass* get_il2cppclass1(const char* assemblyName, const char* namespaze,
const char* klassName) const char* klassName,bool strict)
{ {
if(!(il2cpp_assembly_get_image&&il2cpp_class_from_name))return NULL; if(!(il2cpp_assembly_get_image&&il2cpp_class_from_name))return NULL;
void* assembly=0; void* assembly=0;
@ -83,6 +83,7 @@ namespace il2cpp_symbols
if(klass)return klass; if(klass)return klass;
}while(0); }while(0);
} }
if(strict)return NULL;
if(il2cpp_domain_get_assemblies&&il2cpp_assembly_get_image) if(il2cpp_domain_get_assemblies&&il2cpp_assembly_get_image)
{ {
int _ = 0; int _ = 0;
@ -152,14 +153,15 @@ namespace il2cpp_symbols
return ret->methodPointer; return ret->methodPointer;
} }
uintptr_t get_method_pointer(const char* assemblyName, const char* namespaze, uintptr_t get_method_pointer(const char* assemblyName, const char* namespaze,
const char* klassName, const char* name, int argsCount) const char* klassName, const char* name, int argsCount,bool strict)
{ {
auto thread=AutoThread(); auto thread=AutoThread();
if(!thread.thread)return NULL; if(!thread.thread)return NULL;
auto klass=get_il2cppclass1(assemblyName,namespaze,klassName);//正向查询assemblyName可以为空 auto klass=get_il2cppclass1(assemblyName,namespaze,klassName,strict);//正向查询assemblyName可以为空
if(klass) if(klass)
return getmethodofklass(klass,name,argsCount); return getmethodofklass(klass,name,argsCount);
if(strict)return NULL;
auto klasses=get_il2cppclass2(namespaze,klassName);//反向查询namespace可以为空 auto klasses=get_il2cppclass2(namespaze,klassName);//反向查询namespace可以为空
for(auto klass:klasses){ for(auto klass:klasses){
auto method= getmethodofklass(klass,name,argsCount); auto method= getmethodofklass(klass,name,argsCount);

View File

@ -480,7 +480,7 @@ std::vector<MonoImage*>mono_loop_images(){
mono_assembly_foreach(MonoCallBack,(void*)&images); mono_assembly_foreach(MonoCallBack,(void*)&images);
return images; return images;
} }
MonoClass* mono_findklassby_ass_namespace(std::vector<MonoImage*>& images,const char *_dll, const char *_namespace,const char *_class){ MonoClass* mono_findklassby_ass_namespace(std::vector<MonoImage*>& images,const char *_dll, const char *_namespace,const char *_class,bool strict){
if(!(mono_class_from_name))return NULL; if(!(mono_class_from_name))return NULL;
MonoClass* maybe=NULL; MonoClass* maybe=NULL;
@ -494,6 +494,7 @@ MonoClass* mono_findklassby_ass_namespace(std::vector<MonoImage*>& images,const
} }
} }
} }
if(strict)return NULL;
return maybe; return maybe;
} }
std::vector<MonoClass*> mono_findklassby_class(std::vector<MonoImage*>& images,const char *_namespace,const char *_class){ std::vector<MonoClass*> mono_findklassby_class(std::vector<MonoImage*>& images,const char *_namespace,const char *_class){
@ -549,15 +550,16 @@ struct AutoThread{
} }
}; };
} }
uintptr_t getmonofunctionptr(const char *_dll, const char *_namespace, const char *_class, const char *_method, int paramCount) { uintptr_t getmonofunctionptr(const char *_dll, const char *_namespace, const char *_class, const char *_method, int paramCount,bool strict) {
auto thread=AutoThread(); auto thread=AutoThread();
if(!thread.thread)return NULL; if(!thread.thread)return NULL;
auto images=mono_loop_images(); auto images=mono_loop_images();
auto pClass=mono_findklassby_ass_namespace(images,_dll,_namespace,_class);//dll可以为空 auto pClass=mono_findklassby_ass_namespace(images,_dll,_namespace,_class,strict);//dll可以为空
if(pClass) if(pClass)
return getmethodofklass(pClass,_method,paramCount); return getmethodofklass(pClass,_method,paramCount);
if(strict)return NULL;
auto klasses=mono_findklassby_class(images,_namespace,_class);//namespace可以为空 auto klasses=mono_findklassby_class(images,_namespace,_class);//namespace可以为空
for(auto klass:klasses){ for(auto klass:klasses){
auto method= getmethodofklass(klass,_method,paramCount); auto method= getmethodofklass(klass,_method,paramCount);

View File

@ -122,6 +122,7 @@ namespace monocommon{
{"mscorlib","System","String","InternalSubString",2,99999,mscorlib_system_string_InternalSubString_hook_fun,false}, {"mscorlib","System","String","InternalSubString",2,99999,mscorlib_system_string_InternalSubString_hook_fun,false},
{"Unity.TextMeshPro","TMPro","TMP_Text","set_text",1,2,nullptr,true}, {"Unity.TextMeshPro","TMPro","TMP_Text","set_text",1,2,nullptr,true},
{"Unity.TextMeshPro","TMPro","TextMeshPro","set_text",1,2,nullptr,true},
{"UnityEngine.UI","UnityEngine.UI","Text","set_text",1,2,nullptr,true}, {"UnityEngine.UI","UnityEngine.UI","Text","set_text",1,2,nullptr,true},
{"UnityEngine.UIElementsModule","UnityEngine.UIElements","TextElement","set_text",1,2,nullptr,true}, {"UnityEngine.UIElementsModule","UnityEngine.UIElements","TextElement","set_text",1,2,nullptr,true},
{"UnityEngine.UIElementsModule","UnityEngine.UIElements","TextField","set_value",1,2,nullptr,true}, {"UnityEngine.UIElementsModule","UnityEngine.UIElements","TextField","set_value",1,2,nullptr,true},
@ -129,6 +130,11 @@ namespace monocommon{
{"UnityEngine.TextRenderingModule","UnityEngine","TextMesh","set_text",1,2,nullptr,true}, {"UnityEngine.TextRenderingModule","UnityEngine","TextMesh","set_text",1,2,nullptr,true},
{"UGUI","","UILabel","set_text",1,2,nullptr,true}, {"UGUI","","UILabel","set_text",1,2,nullptr,true},
}; };
std::vector<functioninfo>extrahooks{
//https://vndb.org/r37234 && https://vndb.org/r37235
//Higurashi When They Cry Hou - Ch.2 Watanagashi && Higurashi When They Cry Hou - Ch.3 Tatarigoroshi
{"Assembly-CSharp","Assets.Scripts.Core.TextWindow","TextController","SetText",4,3,nullptr,true},
};
bool hook_mono_il2cpp(){ bool hook_mono_il2cpp(){
for (const wchar_t* monoName : { L"mono.dll", L"mono-2.0-bdwgc.dll",L"GameAssembly.dll" }) for (const wchar_t* monoName : { L"mono.dll", L"mono-2.0-bdwgc.dll",L"GameAssembly.dll" })
if (HMODULE module = GetModuleHandleW(monoName)) { if (HMODULE module = GetModuleHandleW(monoName)) {
@ -141,6 +147,11 @@ namespace monocommon{
if(!addr)continue; if(!addr)continue;
succ|=NewHook_check(addr,hook); succ|=NewHook_check(addr,hook);
} }
for(auto hook:extrahooks){
auto addr=tryfindmonoil2cpp(hook.assemblyName,hook.namespaze,hook.klassName,hook.name,hook.argsCount,true);
if(!addr)continue;
succ|=NewHook_check(addr,hook);
}
if(succ||b2)return true; if(succ||b2)return true;
} }
return false; return false;

View File

@ -23,20 +23,15 @@ inline void unity_ui_string_hook_after(uintptr_t *offset,void* data, size_t len)
newstring->length=len/2; newstring->length=len/2;
*offset=(uintptr_t)newstring; *offset=(uintptr_t)newstring;
} }
namespace il2cpp_symbols
{
void init(HMODULE game_module);
uintptr_t get_method_pointer(const char* assemblyName, const char* namespaze,
const char* klassName, const char* name, int argsCount);
}
void load_mono_functions_from_dll(HMODULE dll); void load_mono_functions_from_dll(HMODULE dll);
uintptr_t getmonofunctionptr(const char *_dll, const char *_namespace, const char *_class, const char *_method, int paramCount); uintptr_t getmonofunctionptr(const char *_dll, const char *_namespace, const char *_class, const char *_method, int paramCount,bool strict);
inline uintptr_t tryfindmonoil2cpp(const char *_dll, const char *_namespace, const char *_class, const char *_method, int paramCoun){ inline uintptr_t tryfindmonoil2cpp(const char *_dll, const char *_namespace, const char *_class, const char *_method, int paramCoun,bool strict=false){
auto addr=il2cpp_symbols::get_method_pointer(_dll,_namespace,_class,_method,paramCoun); auto addr=il2cpp_symbols::get_method_pointer(_dll,_namespace,_class,_method,paramCoun,strict);
if(addr)return addr; if(addr)return addr;
return getmonofunctionptr(_dll,_namespace,_class,_method,paramCoun); return getmonofunctionptr(_dll,_namespace,_class,_method,paramCoun,strict);
} }