From 8cd03675140a85398104b8ff4a138644fbfc6a24 Mon Sep 17 00:00:00 2001 From: Maschell Date: Sun, 17 Nov 2019 23:05:13 +0100 Subject: [PATCH] Add support for new CRT hook, increase the maximum hooks per plugin to 25 --- src/entry.cpp | 12 ++++++- src/patcher/function_patcher.h | 2 +- src/patcher/hooks_patcher_static.cpp | 2 ++ src/utils.cpp | 48 +++++++++++++++------------- 4 files changed, 39 insertions(+), 25 deletions(-) diff --git a/src/entry.cpp b/src/entry.cpp index ee0f06f..b905a17 100644 --- a/src/entry.cpp +++ b/src/entry.cpp @@ -80,6 +80,8 @@ void ApplyPatchesAndCallHookStartingApp() { PatchInvidualMethodHooks(method_hooks_hooks_static, method_hooks_size_hooks_static, method_calls_hooks_static); PatchInvidualMethodHooks(method_hooks_hooks, method_hooks_size_hooks, method_calls_hooks); for(int32_t plugin_index=0; plugin_indexclearAll(); @@ -118,9 +125,12 @@ void ResolveRelocations() { void afterLoadAndLink() { ResolveRelocations(); + CallHook(WUPS_LOADER_HOOK_INIT_WUT_MALLOC); + CallHook(WUPS_LOADER_HOOK_INIT_WUT_NEWLIB); + CallHook(WUPS_LOADER_HOOK_INIT_WUT_STDCPP); + CallHook(WUPS_LOADER_HOOK_INIT_VID_MEM); CallHook(WUPS_LOADER_HOOK_INIT_KERNEL); - CallHook(WUPS_LOADER_HOOK_INIT_FS); CallHook(WUPS_LOADER_HOOK_INIT_OVERLAY); ConfigUtils::loadConfigFromSD(); CallHook(WUPS_LOADER_HOOK_INIT_PLUGIN); diff --git a/src/patcher/function_patcher.h b/src/patcher/function_patcher.h index 1eda726..3e17ea2 100644 --- a/src/patcher/function_patcher.h +++ b/src/patcher/function_patcher.h @@ -58,7 +58,7 @@ struct replacement_data_hook_t { wups_loader_hook_type_t type; /* [will be filled] */ }; -#define MAXIMUM_HOOKS_PER_PLUGIN 10 +#define MAXIMUM_HOOKS_PER_PLUGIN 25 #define MAXIMUM_FUNCTION_PER_PLUGIN 100 struct replacement_data_plugin_t { diff --git a/src/patcher/hooks_patcher_static.cpp b/src/patcher/hooks_patcher_static.cpp index 9bf240a..0435c5f 100644 --- a/src/patcher/hooks_patcher_static.cpp +++ b/src/patcher/hooks_patcher_static.cpp @@ -314,6 +314,7 @@ DECL(uint32_t, OSReceiveMessage, OSMessageQueue *queue, OSMessage *message, uint if(flags == 0x15154848) { CallHook(WUPS_LOADER_HOOK_ACQUIRED_FOREGROUND); CallHook(WUPS_LOADER_HOOK_APPLICATION_END); + CallHook(WUPS_LOADER_HOOK_FINI_WUT_DEVOPTAB); gInBackground = false; DCFlushRange(&gInBackground,4); return false; @@ -326,6 +327,7 @@ DECL(uint32_t, OSReceiveMessage, OSMessageQueue *queue, OSMessage *message, uint CallHook(WUPS_LOADER_HOOK_ACQUIRED_FOREGROUND); } else if(message->data0 == 0xD1E0D1E0) { CallHook(WUPS_LOADER_HOOK_APPLICATION_END); + CallHook(WUPS_LOADER_HOOK_FINI_WUT_DEVOPTAB); gInBackground = false; DCFlushRange(&gInBackground,4); unmount_sd_fat("sd"); diff --git a/src/utils.cpp b/src/utils.cpp index 1cbdfd1..6fa8ce4 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -36,10 +36,17 @@ bool HasHookCallHook(wups_loader_hook_type_t hook_type) { } static const char** hook_names = (const char *[]){ - "WUPS_LOADER_HOOK_INIT_FS", "WUPS_LOADER_HOOK_INIT_OVERLAY", "WUPS_LOADER_HOOK_INIT_KERNEL", "WUPS_LOADER_HOOK_INIT_VID_MEM", + "WUPS_LOADER_HOOK_INIT_WUT_MALLOC", + "WUPS_LOADER_HOOK_FINI_WUT_MALLOC", + "WUPS_LOADER_HOOK_INIT_WUT_DEVOPTAB", + "WUPS_LOADER_HOOK_FINI_WUT_DEVOPTAB", + "WUPS_LOADER_HOOK_INIT_WUT_NEWLIB", + "WUPS_LOADER_HOOK_FINI_WUT_NEWLIB", + "WUPS_LOADER_HOOK_INIT_WUT_STDCPP", + "WUPS_LOADER_HOOK_FINI_WUT_STDCPP", "WUPS_LOADER_HOOK_INIT_PLUGIN", "WUPS_LOADER_HOOK_DEINIT_PLUGIN", "WUPS_LOADER_HOOK_APPLICATION_START", @@ -73,22 +80,7 @@ void CallHookEx(wups_loader_hook_type_t hook_type, int32_t plugin_index_needed) // Adding arguments! if(func_ptr != NULL) { //DEBUG_FUNCTION_LINE("function pointer is %08x\n",func_ptr); - if(hook_type == WUPS_LOADER_HOOK_INIT_FS) { - wups_loader_init_fs_args_t args; - // open is defined as "extern int open (const char *, int, ...);", we are ignoring the varargs part - args.open_repl = (OpenFunction) &open; - args.close_repl = &close; - args.write_repl = &write; - args.read_repl = &read; - args.lseek_repl = &lseek; - args.stat_repl = &stat; - args.fstat_repl = &fstat; - args.opendir_repl = &opendir; - args.closedir_repl = &closedir; - args.readdir_repl = &readdir; - args.mkdir_repl = &mkdir; - ((void (*)(wups_loader_init_fs_args_t))((uint32_t*)func_ptr) )(args); - } else if(hook_type == WUPS_LOADER_HOOK_INIT_OVERLAY) { + if(hook_type == WUPS_LOADER_HOOK_INIT_OVERLAY) { /*wups_loader_init_overlay_args_t args; args.overlayfunction_ptr = &overlay_helper; args.textureconvertfunction_ptr = &TextureUtils::convertImageToTexture; @@ -101,12 +93,6 @@ void CallHookEx(wups_loader_hook_type_t hook_type, int32_t plugin_index_needed) } else if(hook_type == WUPS_LOADER_HOOK_APPLICATION_START) { wups_loader_app_started_args_t args; memset(&args,0,sizeof(args)); - ///*if(gSDInitDone & WUPS_SD_MOUNTED) { - args.sd_mounted = true; - //} - /*if(gSDInitDone & WUPS_USB_MOUNTED) { - args.usb_mounted = true; - }*/ if(plugin_data->kernel_allowed && plugin_data->kernel_init_done) { args.kernel_access = true; } @@ -123,6 +109,22 @@ void CallHookEx(wups_loader_hook_type_t hook_type, int32_t plugin_index_needed) ((void (*)(void))((uint32_t*)func_ptr))(); } else if(hook_type == WUPS_LOADER_HOOK_APPLET_START) { ((void (*)(void))((uint32_t*)func_ptr))(); + } else if(hook_type == WUPS_LOADER_HOOK_INIT_WUT_MALLOC) { + ((void (*)(void))((uint32_t*)func_ptr))(); + } else if(hook_type == WUPS_LOADER_HOOK_FINI_WUT_MALLOC) { + ((void (*)(void))((uint32_t*)func_ptr))(); + } else if(hook_type == WUPS_LOADER_HOOK_INIT_WUT_DEVOPTAB) { + ((void (*)(void))((uint32_t*)func_ptr))(); + } else if(hook_type == WUPS_LOADER_HOOK_FINI_WUT_DEVOPTAB) { + ((void (*)(void))((uint32_t*)func_ptr))(); + } else if(hook_type == WUPS_LOADER_HOOK_INIT_WUT_NEWLIB) { + ((void (*)(void))((uint32_t*)func_ptr))(); + } else if(hook_type == WUPS_LOADER_HOOK_FINI_WUT_NEWLIB) { + ((void (*)(void))((uint32_t*)func_ptr))(); + } else if(hook_type == WUPS_LOADER_HOOK_INIT_WUT_STDCPP) { + ((void (*)(void))((uint32_t*)func_ptr))(); + } else if(hook_type == WUPS_LOADER_HOOK_FINI_WUT_STDCPP) { + ((void (*)(void))((uint32_t*)func_ptr))(); } else if(hook_type == WUPS_LOADER_HOOK_INIT_KERNEL) { // Only call the hook if kernel is allowed. if(plugin_data->kernel_allowed) {