mirror of
https://github.com/HIllya51/LunaHook.git
synced 2025-01-13 05:13:58 +08:00
fix
1
This commit is contained in:
parent
52e4412561
commit
d34ed3473d
@ -71,30 +71,28 @@ namespace il2cpp_symbols
|
||||
Il2CppClass* get_il2cppclass1(const char* assemblyName, const char* namespaze,
|
||||
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);
|
||||
}
|
||||
|
||||
void* assembly=0;
|
||||
do{
|
||||
assembly = (SafeFptr(il2cpp_domain_assembly_open))(il2cpp_domain, assemblyName);
|
||||
if(!assembly)break;
|
||||
auto image = (SafeFptr(il2cpp_assembly_get_image))(assembly);
|
||||
if(!image)break;
|
||||
auto klass = (SafeFptr(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;
|
||||
size_t sz = 0;
|
||||
auto assemblies = il2cpp_domain_get_assemblies(il2cpp_domain, &sz);
|
||||
for (auto i = 0; i < sz; i++, assemblies++) {
|
||||
auto image = il2cpp_assembly_get_image(*assemblies);
|
||||
auto cls = il2cpp_class_from_name(image, namespaze, klassName);
|
||||
if(cls)return cls;
|
||||
}
|
||||
}
|
||||
|
||||
int _ = 0;
|
||||
size_t sz = 0;
|
||||
auto assemblies = (SafeFptr(il2cpp_domain_get_assemblies))(il2cpp_domain, &sz);
|
||||
if(assemblies)
|
||||
for (auto i = 0; i < sz; i++, assemblies++) {
|
||||
auto image = (SafeFptr(il2cpp_assembly_get_image))(*assemblies);
|
||||
if(!image)continue;
|
||||
auto cls = (SafeFptr(il2cpp_class_from_name))(image, namespaze, klassName);
|
||||
if(cls)return cls;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
}
|
||||
@ -106,20 +104,19 @@ namespace il2cpp_symbols
|
||||
std::vector<Il2CppClass*> get_il2cppclass2(const char* namespaze,
|
||||
const char* klassName)
|
||||
{
|
||||
if(!(il2cpp_class_for_each&&il2cpp_class_get_name))return {};
|
||||
std::vector<Il2CppClass*>maybes;
|
||||
std::vector<Il2CppClass*>klasses;
|
||||
il2cpp_class_for_each(foreach_func,&klasses);
|
||||
(SafeFptr(il2cpp_class_for_each))(foreach_func,&klasses);
|
||||
|
||||
for(auto klass:klasses){
|
||||
auto classname = il2cpp_class_get_name(klass);
|
||||
auto classname = (SafeFptr(il2cpp_class_get_name))(klass);
|
||||
if(!classname)continue;
|
||||
if(strcmp(classname,klassName)!=0)continue;
|
||||
maybes.push_back(klass);
|
||||
if(il2cpp_class_get_namespace){
|
||||
auto namespacename=il2cpp_class_get_namespace(klass);
|
||||
if(strlen(namespaze)&&(strcmp(namespacename,namespaze)==0)){
|
||||
return {klass};
|
||||
}
|
||||
auto namespacename=(SafeFptr(il2cpp_class_get_namespace))(klass);
|
||||
if(!namespacename)continue;
|
||||
if(strlen(namespaze)&&(strcmp(namespacename,namespaze)==0)){
|
||||
return {klass};
|
||||
}
|
||||
}
|
||||
return maybes;
|
||||
@ -127,27 +124,26 @@ namespace il2cpp_symbols
|
||||
struct AutoThread{
|
||||
void*thread=NULL;
|
||||
AutoThread(){
|
||||
if(!(il2cpp_thread_attach&&il2cpp_domain_get))return;
|
||||
auto il2cpp_domain=il2cpp_domain_get();
|
||||
auto il2cpp_domain=(SafeFptr(il2cpp_domain_get))();
|
||||
if (!il2cpp_domain) return;
|
||||
thread= il2cpp_thread_attach(il2cpp_domain);
|
||||
thread= (SafeFptr(il2cpp_thread_attach))(il2cpp_domain);
|
||||
}
|
||||
~AutoThread(){
|
||||
if(!thread)return;
|
||||
if(!il2cpp_thread_detach)return;
|
||||
il2cpp_thread_detach(thread);
|
||||
(SafeFptr(il2cpp_thread_detach))(thread);
|
||||
}
|
||||
};
|
||||
void tryprintimage(Il2CppClass* klass){
|
||||
if(!(il2cpp_class_get_namespace&&il2cpp_class_get_image&&il2cpp_image_get_name))return;
|
||||
auto image=il2cpp_class_get_image(klass);
|
||||
auto image=(SafeFptr(il2cpp_class_get_image))(klass);
|
||||
if(!image)return;
|
||||
ConsoleOutput("%s:%s",il2cpp_image_get_name(image),il2cpp_class_get_namespace(klass));
|
||||
auto imagen=(SafeFptr(il2cpp_image_get_name))(image);
|
||||
auto names=(SafeFptr(il2cpp_class_get_namespace))(klass);
|
||||
if(imagen&&names)
|
||||
ConsoleOutput("%s:%s",imagen,names);
|
||||
}
|
||||
uintptr_t getmethodofklass(Il2CppClass* klass,const char* name, int argsCount){
|
||||
if(!(il2cpp_class_get_method_from_name))return NULL;
|
||||
if(!klass)return NULL;
|
||||
auto ret = il2cpp_class_get_method_from_name(klass, name, argsCount);
|
||||
auto ret = (SafeFptr(il2cpp_class_get_method_from_name))(klass, name, argsCount);
|
||||
if(!ret)return NULL;
|
||||
tryprintimage(klass);
|
||||
return ret->methodPointer;
|
||||
|
@ -469,84 +469,82 @@ void load_mono_functions_from_dll(HMODULE dll)
|
||||
}
|
||||
namespace{
|
||||
void MonoCallBack(void* assembly, void* userData) {
|
||||
auto Image=mono_assembly_get_image((MonoAssembly*)assembly);
|
||||
auto Image=(SafeFptr(mono_assembly_get_image))((MonoAssembly*)assembly);
|
||||
if(!Image)return;
|
||||
auto st=reinterpret_cast<std::vector<MonoImage*>*>(userData);
|
||||
st->push_back(Image);
|
||||
}
|
||||
std::vector<MonoImage*>mono_loop_images(){
|
||||
if(!(mono_assembly_get_image&&mono_assembly_foreach))return {};
|
||||
std::vector<MonoImage*>images;
|
||||
mono_assembly_foreach(MonoCallBack,(void*)&images);
|
||||
(SafeFptr(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,bool strict){
|
||||
if(!(mono_class_from_name))return NULL;
|
||||
MonoClass* maybe=NULL;
|
||||
|
||||
for(auto Image:images){
|
||||
auto tmp=mono_class_from_name(Image, _namespace,_class);
|
||||
if(tmp){
|
||||
maybe=tmp;
|
||||
if(mono_image_get_name){
|
||||
auto name=mono_image_get_name(Image);
|
||||
if(name&&(strcmp(_dll,name)==0))return tmp;
|
||||
}
|
||||
}
|
||||
auto tmp=(SafeFptr(mono_class_from_name))(Image, _namespace,_class);
|
||||
if(!tmp)continue;
|
||||
|
||||
maybe=tmp;
|
||||
auto name=(SafeFptr(mono_image_get_name))(Image);
|
||||
if(!name)continue;
|
||||
if(strcmp(_dll,name)==0)return tmp;
|
||||
|
||||
}
|
||||
if(strict)return NULL;
|
||||
return maybe;
|
||||
}
|
||||
std::vector<MonoClass*> mono_findklassby_class(std::vector<MonoImage*>& images,const char *_namespace,const char *_class){
|
||||
if(!(mono_image_get_table_info&&mono_table_info_get_rows&&mono_class_get&&mono_class_get_name))return {};
|
||||
|
||||
std::vector<MonoClass*>maybes;
|
||||
for(auto image:images){
|
||||
auto _1=mono_image_get_table_info((void*)image,MONO_TABLE_TYPEDEF);
|
||||
auto tdefcount=mono_table_info_get_rows(_1);
|
||||
auto _1=(SafeFptr(mono_image_get_table_info))((void*)image,MONO_TABLE_TYPEDEF);
|
||||
if(!_1)continue;
|
||||
auto tdefcount=(SafeFptr(mono_table_info_get_rows))(_1);
|
||||
if(!tdefcount)continue;
|
||||
for (int i = 0; i < tdefcount; i++)
|
||||
{
|
||||
auto klass = (MonoClass*)mono_class_get(image, MONO_TOKEN_TYPE_DEF | i+1);
|
||||
|
||||
auto name=mono_class_get_name(klass);
|
||||
auto klass = (MonoClass*)(SafeFptr(mono_class_get))(image, MONO_TOKEN_TYPE_DEF | i+1);
|
||||
if(!klass)continue;
|
||||
auto name=(SafeFptr(mono_class_get_name))(klass);
|
||||
if(!name)continue;
|
||||
if(strcmp(name,_class)!=0)continue;
|
||||
maybes.push_back(klass);
|
||||
if(mono_class_get_namespace){
|
||||
auto namespacename=mono_class_get_namespace(klass);
|
||||
if(strlen(_namespace)&&(strcmp(namespacename,_namespace)==0)){
|
||||
return {klass};
|
||||
}
|
||||
}
|
||||
auto namespacename=(SafeFptr(mono_class_get_namespace))(klass);
|
||||
if(!namespacename)continue;
|
||||
if(strlen(_namespace)&&(strcmp(namespacename,_namespace)==0)){
|
||||
return {klass};
|
||||
}
|
||||
}
|
||||
}
|
||||
return maybes;
|
||||
}
|
||||
void tryprintimage(MonoClass* klass){
|
||||
if(!(mono_class_get_image&&mono_image_get_name&&mono_class_get_namespace))return;
|
||||
auto image=mono_class_get_image(klass);
|
||||
auto image=(SafeFptr(mono_class_get_image))(klass);
|
||||
if(!image)return;
|
||||
ConsoleOutput("%s:%s",mono_image_get_name(image),mono_class_get_namespace(klass));
|
||||
auto imagen=(SafeFptr(mono_image_get_name))(image);
|
||||
auto names=(SafeFptr(mono_class_get_namespace))(klass);
|
||||
if(imagen&&names)
|
||||
ConsoleOutput("%s:%s",imagen,names);
|
||||
}
|
||||
uintptr_t getmethodofklass(MonoClass* klass,const char* name, int argsCount){
|
||||
if(!(mono_class_get_method_from_name&&mono_compile_method))return NULL;
|
||||
if(!klass)return NULL;
|
||||
MonoMethod* MonoClassMethod = mono_class_get_method_from_name(klass, name, argsCount);
|
||||
auto MonoClassMethod = (SafeFptr(mono_class_get_method_from_name))(klass, name, argsCount);
|
||||
if(!MonoClassMethod)return NULL;
|
||||
tryprintimage(klass);
|
||||
return (uintptr_t)mono_compile_method((uintptr_t)MonoClassMethod);
|
||||
return (uintptr_t)(SafeFptr(mono_compile_method))((uintptr_t)MonoClassMethod);
|
||||
}
|
||||
struct AutoThread{
|
||||
MonoThread *thread=NULL;
|
||||
AutoThread(){
|
||||
if(!(mono_get_root_domain&&mono_thread_attach))return ;
|
||||
auto _root=mono_get_root_domain();
|
||||
auto _root=(SafeFptr(mono_get_root_domain))();
|
||||
if(!_root)return ;
|
||||
thread= mono_thread_attach(_root);
|
||||
thread= (SafeFptr(mono_thread_attach))(_root);
|
||||
}
|
||||
~AutoThread(){
|
||||
if(!thread)return;
|
||||
if(!mono_thread_detach)return;
|
||||
mono_thread_detach(thread);
|
||||
(SafeFptr(mono_thread_detach))(thread);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -98,16 +98,16 @@ namespace monocommon{
|
||||
hp.argidx=hook.argidx;
|
||||
hp.text_fun =(decltype(hp.text_fun))hook.text_fun;
|
||||
if(hook.isstring){
|
||||
hp.type = USING_STRING | CODEC_UTF16|FULL_STRING;
|
||||
if(!hp.text_fun)hp.type|=SPECIAL_JIT_STRING;
|
||||
hp.type = USING_STRING | CODEC_UTF16|FULL_STRING;
|
||||
if(!hp.text_fun)hp.type|=SPECIAL_JIT_STRING;
|
||||
if(hook.Embed)
|
||||
hp.type|=EMBED_ABLE|EMBED_BEFORE_SIMPLE;
|
||||
}
|
||||
else{
|
||||
hp.type = USING_CHAR | CODEC_UTF16;
|
||||
}
|
||||
hp.jittype=JITTYPE::UNITY;
|
||||
strcpy(hp.unityfunctioninfo,hook.info().c_str());
|
||||
if(hook.Embed)
|
||||
hp.type|=EMBED_ABLE|EMBED_BEFORE_SIMPLE;
|
||||
auto succ=NewHook(hp,hook.hookname().c_str());
|
||||
#ifdef _WIN64
|
||||
if(!succ){
|
||||
@ -124,7 +124,7 @@ namespace monocommon{
|
||||
{"mscorlib","System","String","IndexOf",1,1},
|
||||
{"mscorlib","System","String","Substring",2,1},
|
||||
{"mscorlib","System","String","op_Inequality",2,1},
|
||||
{"mscorlib","System","String","InternalSubString",2,99999,mscorlib_system_string_InternalSubString_hook_fun},
|
||||
{"mscorlib","System","String","InternalSubString",2,1,mscorlib_system_string_InternalSubString_hook_fun},
|
||||
|
||||
{"Unity.TextMeshPro","TMPro","TMP_Text","set_text",1,2,nullptr,true},
|
||||
{"Unity.TextMeshPro","TMPro","TextMeshPro","set_text",1,2,nullptr,true},
|
||||
|
@ -1,5 +1,11 @@
|
||||
#include"../include/pch.h"
|
||||
|
||||
enum { TEXT_BUFFER_SIZE = PIPE_BUFFER_SIZE - sizeof(TextOutput_T) };
|
||||
|
||||
#define wcslen(XX) wcsnlen((XX), TEXT_BUFFER_SIZE*2)
|
||||
#define strlen(XX) strnlen((XX), TEXT_BUFFER_SIZE*2)
|
||||
|
||||
|
||||
#include"main.h"
|
||||
#include"stackoffset.hpp"
|
||||
#include"util/stringfilters.h"
|
||||
@ -22,4 +28,4 @@
|
||||
#include"engines/mono/monoil2cpp.hpp"
|
||||
#include "hookfinder.h"
|
||||
#include"util/textunion.h"
|
||||
#include"util/ntxpundef.h"
|
||||
#include"util/ntxpundef.h"
|
||||
|
@ -81,7 +81,6 @@ namespace { // unnamed
|
||||
|
||||
//thread_local BYTE buffer[PIPE_BUFFER_SIZE];
|
||||
//thread_local will crush on windowsxp
|
||||
enum { TEXT_BUFFER_SIZE = PIPE_BUFFER_SIZE - sizeof(TextOutput_T) };
|
||||
} // unnamed namespace
|
||||
|
||||
// - TextHook methods -
|
||||
|
@ -56,7 +56,7 @@ private:
|
||||
ALIGNPTR(uint64_t __2,HANDLE readerEvent);
|
||||
bool err;
|
||||
ALIGNPTR(BYTE __4[ 140],BYTE trampoline[x64 ? 140 : 40]);
|
||||
ALIGNPTR(uint64_t __3,BYTE* local_buffer);
|
||||
ALIGNPTR(uint64_t __3,BYTE* local_buffer);
|
||||
};
|
||||
|
||||
enum { MAX_HOOK = 2500};
|
||||
|
@ -203,4 +203,4 @@ struct TextOutput_T
|
||||
HookParam hp;
|
||||
uint64_t type;
|
||||
BYTE data[0];
|
||||
};
|
||||
};
|
||||
|
@ -92,3 +92,16 @@ inline std::optional<std::wstring> getModuleFilename(HMODULE module = NULL)
|
||||
if (GetModuleFileNameW(module, buffer.data(), MAX_PATH)) return buffer.data();
|
||||
return {};
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
struct SafeFptr {
|
||||
T ptr;
|
||||
uintptr_t errorvalue;
|
||||
SafeFptr(T _ptr, uintptr_t v = {NULL}) : ptr(_ptr), errorvalue(v) {}
|
||||
|
||||
template<typename... Args>
|
||||
std::invoke_result_t<T, Args...> operator()(Args... args) {
|
||||
if (!ptr) return (std::invoke_result_t<T, Args...>)(errorvalue);
|
||||
return ptr(std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user