Add support for new CRT hook, increase the maximum hooks per plugin to 25

This commit is contained in:
Maschell 2019-11-17 23:05:13 +01:00
parent 7d7a668210
commit 8cd0367514
4 changed files with 39 additions and 25 deletions

View File

@ -80,6 +80,8 @@ void ApplyPatchesAndCallHookStartingApp() {
PatchInvidualMethodHooks(method_hooks_hooks_static, method_hooks_size_hooks_static, method_calls_hooks_static); 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); PatchInvidualMethodHooks(method_hooks_hooks, method_hooks_size_hooks, method_calls_hooks);
for(int32_t plugin_index=0; plugin_index<gbl_replacement_data.number_used_plugins; plugin_index++) { for(int32_t plugin_index=0; plugin_index<gbl_replacement_data.number_used_plugins; plugin_index++) {
CallHookEx(WUPS_LOADER_HOOK_INIT_WUT_DEVOPTAB,plugin_index);
CallHookEx(WUPS_LOADER_HOOK_APPLICATION_START,plugin_index); CallHookEx(WUPS_LOADER_HOOK_APPLICATION_START,plugin_index);
new_PatchInvidualMethodHooks(&gbl_replacement_data.plugin_data[plugin_index]); new_PatchInvidualMethodHooks(&gbl_replacement_data.plugin_data[plugin_index]);
CallHookEx(WUPS_LOADER_HOOK_FUNCTIONS_PATCHED,plugin_index); CallHookEx(WUPS_LOADER_HOOK_FUNCTIONS_PATCHED,plugin_index);
@ -99,6 +101,11 @@ void RestoreEverything() {
CallHook(WUPS_LOADER_HOOK_APPLICATION_END); CallHook(WUPS_LOADER_HOOK_APPLICATION_END);
CallHook(WUPS_LOADER_HOOK_DEINIT_PLUGIN); CallHook(WUPS_LOADER_HOOK_DEINIT_PLUGIN);
CallHook(WUPS_LOADER_HOOK_FINI_WUT_DEVOPTAB);
CallHook(WUPS_LOADER_HOOK_FINI_WUT_STDCPP);
CallHook(WUPS_LOADER_HOOK_FINI_WUT_NEWLIB);
CallHook(WUPS_LOADER_HOOK_FINI_WUT_MALLOC);
// Restore patches as the patched functions could change. // Restore patches as the patched functions could change.
RestorePatches(); RestorePatches();
DynamicLinkingHelper::getInstance()->clearAll(); DynamicLinkingHelper::getInstance()->clearAll();
@ -118,9 +125,12 @@ void ResolveRelocations() {
void afterLoadAndLink() { void afterLoadAndLink() {
ResolveRelocations(); 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_VID_MEM);
CallHook(WUPS_LOADER_HOOK_INIT_KERNEL); CallHook(WUPS_LOADER_HOOK_INIT_KERNEL);
CallHook(WUPS_LOADER_HOOK_INIT_FS);
CallHook(WUPS_LOADER_HOOK_INIT_OVERLAY); CallHook(WUPS_LOADER_HOOK_INIT_OVERLAY);
ConfigUtils::loadConfigFromSD(); ConfigUtils::loadConfigFromSD();
CallHook(WUPS_LOADER_HOOK_INIT_PLUGIN); CallHook(WUPS_LOADER_HOOK_INIT_PLUGIN);

View File

@ -58,7 +58,7 @@ struct replacement_data_hook_t {
wups_loader_hook_type_t type; /* [will be filled] */ 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 #define MAXIMUM_FUNCTION_PER_PLUGIN 100
struct replacement_data_plugin_t { struct replacement_data_plugin_t {

View File

@ -314,6 +314,7 @@ DECL(uint32_t, OSReceiveMessage, OSMessageQueue *queue, OSMessage *message, uint
if(flags == 0x15154848) { if(flags == 0x15154848) {
CallHook(WUPS_LOADER_HOOK_ACQUIRED_FOREGROUND); CallHook(WUPS_LOADER_HOOK_ACQUIRED_FOREGROUND);
CallHook(WUPS_LOADER_HOOK_APPLICATION_END); CallHook(WUPS_LOADER_HOOK_APPLICATION_END);
CallHook(WUPS_LOADER_HOOK_FINI_WUT_DEVOPTAB);
gInBackground = false; gInBackground = false;
DCFlushRange(&gInBackground,4); DCFlushRange(&gInBackground,4);
return false; return false;
@ -326,6 +327,7 @@ DECL(uint32_t, OSReceiveMessage, OSMessageQueue *queue, OSMessage *message, uint
CallHook(WUPS_LOADER_HOOK_ACQUIRED_FOREGROUND); CallHook(WUPS_LOADER_HOOK_ACQUIRED_FOREGROUND);
} else if(message->data0 == 0xD1E0D1E0) { } else if(message->data0 == 0xD1E0D1E0) {
CallHook(WUPS_LOADER_HOOK_APPLICATION_END); CallHook(WUPS_LOADER_HOOK_APPLICATION_END);
CallHook(WUPS_LOADER_HOOK_FINI_WUT_DEVOPTAB);
gInBackground = false; gInBackground = false;
DCFlushRange(&gInBackground,4); DCFlushRange(&gInBackground,4);
unmount_sd_fat("sd"); unmount_sd_fat("sd");

View File

@ -36,10 +36,17 @@ bool HasHookCallHook(wups_loader_hook_type_t hook_type) {
} }
static const char** hook_names = (const char *[]){ static const char** hook_names = (const char *[]){
"WUPS_LOADER_HOOK_INIT_FS",
"WUPS_LOADER_HOOK_INIT_OVERLAY", "WUPS_LOADER_HOOK_INIT_OVERLAY",
"WUPS_LOADER_HOOK_INIT_KERNEL", "WUPS_LOADER_HOOK_INIT_KERNEL",
"WUPS_LOADER_HOOK_INIT_VID_MEM", "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_INIT_PLUGIN",
"WUPS_LOADER_HOOK_DEINIT_PLUGIN", "WUPS_LOADER_HOOK_DEINIT_PLUGIN",
"WUPS_LOADER_HOOK_APPLICATION_START", "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! // Adding arguments!
if(func_ptr != NULL) { if(func_ptr != NULL) {
//DEBUG_FUNCTION_LINE("function pointer is %08x\n",func_ptr); //DEBUG_FUNCTION_LINE("function pointer is %08x\n",func_ptr);
if(hook_type == WUPS_LOADER_HOOK_INIT_FS) { if(hook_type == WUPS_LOADER_HOOK_INIT_OVERLAY) {
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) {
/*wups_loader_init_overlay_args_t args; /*wups_loader_init_overlay_args_t args;
args.overlayfunction_ptr = &overlay_helper; args.overlayfunction_ptr = &overlay_helper;
args.textureconvertfunction_ptr = &TextureUtils::convertImageToTexture; 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) { } else if(hook_type == WUPS_LOADER_HOOK_APPLICATION_START) {
wups_loader_app_started_args_t args; wups_loader_app_started_args_t args;
memset(&args,0,sizeof(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) { if(plugin_data->kernel_allowed && plugin_data->kernel_init_done) {
args.kernel_access = true; 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))(); ((void (*)(void))((uint32_t*)func_ptr))();
} else if(hook_type == WUPS_LOADER_HOOK_APPLET_START) { } else if(hook_type == WUPS_LOADER_HOOK_APPLET_START) {
((void (*)(void))((uint32_t*)func_ptr))(); ((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) { } else if(hook_type == WUPS_LOADER_HOOK_INIT_KERNEL) {
// Only call the hook if kernel is allowed. // Only call the hook if kernel is allowed.
if(plugin_data->kernel_allowed) { if(plugin_data->kernel_allowed) {