mirror of
https://github.com/HIllya51/LunaHook.git
synced 2024-12-25 20:54:15 +08:00
mono
This commit is contained in:
parent
bdd8c86474
commit
216f784790
@ -561,7 +561,7 @@ 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);
|
||||
const char* klassName, const char* name, int argsCount,bool strict);
|
||||
|
||||
Il2CppClass* get_class(const char* assemblyName, const char* namespaze, const char* klassName);
|
||||
|
||||
|
@ -69,20 +69,21 @@ namespace il2cpp_symbols
|
||||
RESOLVE_IMPORT(il2cpp_domain_get_assemblies);
|
||||
}
|
||||
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;
|
||||
void* assembly=0;
|
||||
if(il2cpp_domain_assembly_open){
|
||||
do{
|
||||
assembly = il2cpp_domain_assembly_open(il2cpp_domain, assemblyName);
|
||||
if(!assembly)break;
|
||||
auto image = il2cpp_assembly_get_image(assembly);
|
||||
if(!image)break;
|
||||
auto klass = il2cpp_class_from_name(image, namespaze, klassName);
|
||||
if(klass)return klass;
|
||||
}while(0);
|
||||
do{
|
||||
assembly = il2cpp_domain_assembly_open(il2cpp_domain, assemblyName);
|
||||
if(!assembly)break;
|
||||
auto image = il2cpp_assembly_get_image(assembly);
|
||||
if(!image)break;
|
||||
auto klass = il2cpp_class_from_name(image, namespaze, klassName);
|
||||
if(klass)return klass;
|
||||
}while(0);
|
||||
}
|
||||
if(strict)return NULL;
|
||||
if(il2cpp_domain_get_assemblies&&il2cpp_assembly_get_image)
|
||||
{
|
||||
int _ = 0;
|
||||
@ -152,14 +153,15 @@ namespace il2cpp_symbols
|
||||
return ret->methodPointer;
|
||||
}
|
||||
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();
|
||||
if(!thread.thread)return NULL;
|
||||
|
||||
auto klass=get_il2cppclass1(assemblyName,namespaze,klassName);//正向查询,assemblyName可以为空
|
||||
auto klass=get_il2cppclass1(assemblyName,namespaze,klassName,strict);//正向查询,assemblyName可以为空
|
||||
if(klass)
|
||||
return getmethodofklass(klass,name,argsCount);
|
||||
if(strict)return NULL;
|
||||
auto klasses=get_il2cppclass2(namespaze,klassName);//反向查询,namespace可以为空
|
||||
for(auto klass:klasses){
|
||||
auto method= getmethodofklass(klass,name,argsCount);
|
||||
|
@ -480,7 +480,7 @@ std::vector<MonoImage*>mono_loop_images(){
|
||||
mono_assembly_foreach(MonoCallBack,(void*)&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;
|
||||
MonoClass* maybe=NULL;
|
||||
|
||||
@ -494,6 +494,7 @@ MonoClass* mono_findklassby_ass_namespace(std::vector<MonoImage*>& images,const
|
||||
}
|
||||
}
|
||||
}
|
||||
if(strict)return NULL;
|
||||
return maybe;
|
||||
}
|
||||
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();
|
||||
if(!thread.thread)return NULL;
|
||||
|
||||
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)
|
||||
return getmethodofklass(pClass,_method,paramCount);
|
||||
if(strict)return NULL;
|
||||
auto klasses=mono_findklassby_class(images,_namespace,_class);//namespace可以为空
|
||||
for(auto klass:klasses){
|
||||
auto method= getmethodofklass(klass,_method,paramCount);
|
||||
|
@ -122,6 +122,7 @@ namespace monocommon{
|
||||
{"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","TextMeshPro","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","TextField","set_value",1,2,nullptr,true},
|
||||
@ -129,6 +130,11 @@ namespace monocommon{
|
||||
{"UnityEngine.TextRenderingModule","UnityEngine","TextMesh","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(){
|
||||
for (const wchar_t* monoName : { L"mono.dll", L"mono-2.0-bdwgc.dll",L"GameAssembly.dll" })
|
||||
if (HMODULE module = GetModuleHandleW(monoName)) {
|
||||
@ -141,6 +147,11 @@ namespace monocommon{
|
||||
if(!addr)continue;
|
||||
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;
|
||||
}
|
||||
return false;
|
||||
|
@ -23,20 +23,15 @@ inline void unity_ui_string_hook_after(uintptr_t *offset,void* data, size_t len)
|
||||
newstring->length=len/2;
|
||||
*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);
|
||||
|
||||
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){
|
||||
auto addr=il2cpp_symbols::get_method_pointer(_dll,_namespace,_class,_method,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,strict);
|
||||
if(addr)return addr;
|
||||
return getmonofunctionptr(_dll,_namespace,_class,_method,paramCoun);
|
||||
return getmonofunctionptr(_dll,_namespace,_class,_method,paramCoun,strict);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user