From b9b8bceebfded561121c91af7eca32380c0cb8ed Mon Sep 17 00:00:00 2001 From: Maschell Date: Thu, 8 Mar 2018 16:38:26 +0100 Subject: [PATCH] [Loader] Added mkdir support to the plugins --- ide_templates/codeblocks/Makefile | 1 + loader/src/utils.cpp | 1 + plugins/example_plugin/Makefile | 1 + plugins/hid_to_vpad/Makefile | 2 +- plugins/memory_info/Makefile | 2 +- plugins/nnu_patcher/Makefile | 1 + plugins/overlay/Makefile | 2 +- plugins/padcon/Makefile | 2 +- plugins/sdcafiine/Makefile | 2 +- plugins/swipswapme/Makefile | 2 +- src/fs_function_wrapper.c | 7 +++++++ wups_include/hooks.h | 1 + 12 files changed, 18 insertions(+), 6 deletions(-) diff --git a/ide_templates/codeblocks/Makefile b/ide_templates/codeblocks/Makefile index a9f10c7..d28c1d1 100644 --- a/ide_templates/codeblocks/Makefile +++ b/ide_templates/codeblocks/Makefile @@ -85,6 +85,7 @@ ASFLAGS := -mregnames # -Map: generate a map file LDFLAG_COMMON += -u wups_load -u wups_meta -u wups_hooks -T $(WUPSDIR)/wups.ld \ + -Wl,-wrap,open,-wrap,close,-wrap,write,-wrap,read,-wrap,lseek,-wrap,stat,-wrap,fstat,-wrap,opendir,-wrap,closedir,-wrap,readdir,-wrap,mkdir \ -Wl,-Map,$(notdir $@).map,-wrap,malloc,-wrap,free,-wrap,memalign,-wrap,calloc,-wrap,realloc,-wrap,malloc_usable_size,-wrap,_malloc_r,-wrap,_free_r,-wrap,_realloc_r,-wrap,_calloc_r,-wrap,_memalign_r,-wrap,_malloc_usable_size_r,--gc-sections LDFLAGS_MOD += $(LDFLAG_COMMON),--relocatable diff --git a/loader/src/utils.cpp b/loader/src/utils.cpp index 86c2ddc..7fdd4b9 100644 --- a/loader/src/utils.cpp +++ b/loader/src/utils.cpp @@ -48,6 +48,7 @@ void CallHookEx(wups_loader_hook_type_t hook_type, s32 plugin_index_needed) { args.opendir_repl = (const void*)&opendir; args.closedir_repl = (const void*)&closedir; args.readdir_repl = (const void*)&readdir; + args.mkdir_repl = (const void*)&mkdir; ((void (*)(wups_loader_init_fs_args_t))((unsigned int*)func_ptr) )(args); } else if(hook_type == WUPS_LOADER_HOOK_INIT_OVERLAY) { diff --git a/plugins/example_plugin/Makefile b/plugins/example_plugin/Makefile index a9f10c7..d28c1d1 100644 --- a/plugins/example_plugin/Makefile +++ b/plugins/example_plugin/Makefile @@ -85,6 +85,7 @@ ASFLAGS := -mregnames # -Map: generate a map file LDFLAG_COMMON += -u wups_load -u wups_meta -u wups_hooks -T $(WUPSDIR)/wups.ld \ + -Wl,-wrap,open,-wrap,close,-wrap,write,-wrap,read,-wrap,lseek,-wrap,stat,-wrap,fstat,-wrap,opendir,-wrap,closedir,-wrap,readdir,-wrap,mkdir \ -Wl,-Map,$(notdir $@).map,-wrap,malloc,-wrap,free,-wrap,memalign,-wrap,calloc,-wrap,realloc,-wrap,malloc_usable_size,-wrap,_malloc_r,-wrap,_free_r,-wrap,_realloc_r,-wrap,_calloc_r,-wrap,_memalign_r,-wrap,_malloc_usable_size_r,--gc-sections LDFLAGS_MOD += $(LDFLAG_COMMON),--relocatable diff --git a/plugins/hid_to_vpad/Makefile b/plugins/hid_to_vpad/Makefile index 45b6da6..fde1f49 100644 --- a/plugins/hid_to_vpad/Makefile +++ b/plugins/hid_to_vpad/Makefile @@ -87,7 +87,7 @@ ASFLAGS := -mregnames # -Map: generate a map file LDFLAG_COMMON += -u wups_load -u wups_meta -u wups_hooks -T $(WUPSDIR)/wups.ld \ - -Wl,-wrap,open,-wrap,close,-wrap,write,-wrap,read,-wrap,lseek,-wrap,stat,-wrap,fstat,-wrap,opendir,-wrap,closedir,-wrap,readdir \ + -Wl,-wrap,open,-wrap,close,-wrap,write,-wrap,read,-wrap,lseek,-wrap,stat,-wrap,fstat,-wrap,opendir,-wrap,closedir,-wrap,readdir,-wrap,mkdir \ -Wl,-Map,$(notdir $@).map,-wrap,malloc,-wrap,free,-wrap,memalign,-wrap,calloc,-wrap,realloc,-wrap,malloc_usable_size,-wrap,_malloc_r,-wrap,_free_r,-wrap,_realloc_r,-wrap,_calloc_r,-wrap,_memalign_r,-wrap,_malloc_usable_size_r,--gc-sections LDFLAGS_MOD += $(LDFLAG_COMMON),--relocatable diff --git a/plugins/memory_info/Makefile b/plugins/memory_info/Makefile index d89c552..d28c1d1 100644 --- a/plugins/memory_info/Makefile +++ b/plugins/memory_info/Makefile @@ -85,7 +85,7 @@ ASFLAGS := -mregnames # -Map: generate a map file LDFLAG_COMMON += -u wups_load -u wups_meta -u wups_hooks -T $(WUPSDIR)/wups.ld \ - -Wl,-wrap,open,-wrap,close,-wrap,write,-wrap,read,-wrap,lseek,-wrap,stat,-wrap,fstat,-wrap,opendir,-wrap,closedir,-wrap,readdir \ + -Wl,-wrap,open,-wrap,close,-wrap,write,-wrap,read,-wrap,lseek,-wrap,stat,-wrap,fstat,-wrap,opendir,-wrap,closedir,-wrap,readdir,-wrap,mkdir \ -Wl,-Map,$(notdir $@).map,-wrap,malloc,-wrap,free,-wrap,memalign,-wrap,calloc,-wrap,realloc,-wrap,malloc_usable_size,-wrap,_malloc_r,-wrap,_free_r,-wrap,_realloc_r,-wrap,_calloc_r,-wrap,_memalign_r,-wrap,_malloc_usable_size_r,--gc-sections LDFLAGS_MOD += $(LDFLAG_COMMON),--relocatable diff --git a/plugins/nnu_patcher/Makefile b/plugins/nnu_patcher/Makefile index a9f10c7..d28c1d1 100644 --- a/plugins/nnu_patcher/Makefile +++ b/plugins/nnu_patcher/Makefile @@ -85,6 +85,7 @@ ASFLAGS := -mregnames # -Map: generate a map file LDFLAG_COMMON += -u wups_load -u wups_meta -u wups_hooks -T $(WUPSDIR)/wups.ld \ + -Wl,-wrap,open,-wrap,close,-wrap,write,-wrap,read,-wrap,lseek,-wrap,stat,-wrap,fstat,-wrap,opendir,-wrap,closedir,-wrap,readdir,-wrap,mkdir \ -Wl,-Map,$(notdir $@).map,-wrap,malloc,-wrap,free,-wrap,memalign,-wrap,calloc,-wrap,realloc,-wrap,malloc_usable_size,-wrap,_malloc_r,-wrap,_free_r,-wrap,_realloc_r,-wrap,_calloc_r,-wrap,_memalign_r,-wrap,_malloc_usable_size_r,--gc-sections LDFLAGS_MOD += $(LDFLAG_COMMON),--relocatable diff --git a/plugins/overlay/Makefile b/plugins/overlay/Makefile index 51d4093..dc104eb 100644 --- a/plugins/overlay/Makefile +++ b/plugins/overlay/Makefile @@ -87,7 +87,7 @@ ASFLAGS := -mregnames # -Map: generate a map file LDFLAG_COMMON += -u wups_load -u wups_meta -u wups_hooks -T $(WUPSDIR)/wups.ld \ - -Wl,-wrap,open,-wrap,close,-wrap,write,-wrap,read,-wrap,lseek,-wrap,stat,-wrap,fstat,-wrap,opendir,-wrap,closedir,-wrap,readdir \ + -Wl,-wrap,open,-wrap,close,-wrap,write,-wrap,read,-wrap,lseek,-wrap,stat,-wrap,fstat,-wrap,opendir,-wrap,closedir,-wrap,readdir,-wrap,mkdir \ -Wl,-Map,$(notdir $@).map,-wrap,malloc,-wrap,free,-wrap,memalign,-wrap,calloc,-wrap,realloc,-wrap,malloc_usable_size,-wrap,_malloc_r,-wrap,_free_r,-wrap,_realloc_r,-wrap,_calloc_r,-wrap,_memalign_r,-wrap,_malloc_usable_size_r,--gc-sections LDFLAGS_MOD += $(LDFLAG_COMMON),--relocatable diff --git a/plugins/padcon/Makefile b/plugins/padcon/Makefile index d89c552..d28c1d1 100644 --- a/plugins/padcon/Makefile +++ b/plugins/padcon/Makefile @@ -85,7 +85,7 @@ ASFLAGS := -mregnames # -Map: generate a map file LDFLAG_COMMON += -u wups_load -u wups_meta -u wups_hooks -T $(WUPSDIR)/wups.ld \ - -Wl,-wrap,open,-wrap,close,-wrap,write,-wrap,read,-wrap,lseek,-wrap,stat,-wrap,fstat,-wrap,opendir,-wrap,closedir,-wrap,readdir \ + -Wl,-wrap,open,-wrap,close,-wrap,write,-wrap,read,-wrap,lseek,-wrap,stat,-wrap,fstat,-wrap,opendir,-wrap,closedir,-wrap,readdir,-wrap,mkdir \ -Wl,-Map,$(notdir $@).map,-wrap,malloc,-wrap,free,-wrap,memalign,-wrap,calloc,-wrap,realloc,-wrap,malloc_usable_size,-wrap,_malloc_r,-wrap,_free_r,-wrap,_realloc_r,-wrap,_calloc_r,-wrap,_memalign_r,-wrap,_malloc_usable_size_r,--gc-sections LDFLAGS_MOD += $(LDFLAG_COMMON),--relocatable diff --git a/plugins/sdcafiine/Makefile b/plugins/sdcafiine/Makefile index 6d5d176..eed846f 100644 --- a/plugins/sdcafiine/Makefile +++ b/plugins/sdcafiine/Makefile @@ -88,7 +88,7 @@ ASFLAGS := -mregnames # -Map: generate a map file LDFLAG_COMMON += -u wups_load -u wups_meta -u wups_hooks -T $(WUPSDIR)/wups.ld \ - -Wl,-wrap,open,-wrap,close,-wrap,write,-wrap,read,-wrap,lseek,-wrap,stat,-wrap,fstat,-wrap,opendir,-wrap,closedir,-wrap,readdir \ + -Wl,-wrap,open,-wrap,close,-wrap,write,-wrap,read,-wrap,lseek,-wrap,stat,-wrap,fstat,-wrap,opendir,-wrap,closedir,-wrap,readdir,-wrap,mkdir \ -Wl,-Map,$(notdir $@).map,-wrap,malloc,-wrap,free,-wrap,memalign,-wrap,calloc,-wrap,realloc,-wrap,malloc_usable_size,-wrap,_malloc_r,-wrap,_free_r,-wrap,_realloc_r,-wrap,_calloc_r,-wrap,_memalign_r,-wrap,_malloc_usable_size_r,-wrap,opendir,--gc-sections LDFLAGS_MOD += $(LDFLAG_COMMON),--relocatable diff --git a/plugins/swipswapme/Makefile b/plugins/swipswapme/Makefile index 51d4093..dc104eb 100644 --- a/plugins/swipswapme/Makefile +++ b/plugins/swipswapme/Makefile @@ -87,7 +87,7 @@ ASFLAGS := -mregnames # -Map: generate a map file LDFLAG_COMMON += -u wups_load -u wups_meta -u wups_hooks -T $(WUPSDIR)/wups.ld \ - -Wl,-wrap,open,-wrap,close,-wrap,write,-wrap,read,-wrap,lseek,-wrap,stat,-wrap,fstat,-wrap,opendir,-wrap,closedir,-wrap,readdir \ + -Wl,-wrap,open,-wrap,close,-wrap,write,-wrap,read,-wrap,lseek,-wrap,stat,-wrap,fstat,-wrap,opendir,-wrap,closedir,-wrap,readdir,-wrap,mkdir \ -Wl,-Map,$(notdir $@).map,-wrap,malloc,-wrap,free,-wrap,memalign,-wrap,calloc,-wrap,realloc,-wrap,malloc_usable_size,-wrap,_malloc_r,-wrap,_free_r,-wrap,_realloc_r,-wrap,_calloc_r,-wrap,_memalign_r,-wrap,_malloc_usable_size_r,--gc-sections LDFLAGS_MOD += $(LDFLAG_COMMON),--relocatable diff --git a/src/fs_function_wrapper.c b/src/fs_function_wrapper.c index a906119..aa52d2f 100644 --- a/src/fs_function_wrapper.c +++ b/src/fs_function_wrapper.c @@ -17,6 +17,7 @@ static void * new_fstat_ptr __attribute__((section(".data"))) = NULL; static void * new_opendir_ptr __attribute__((section(".data"))) = NULL; static void * new_closedir_ptr __attribute__((section(".data"))) = NULL; static void * new_readdir_ptr __attribute__((section(".data"))) = NULL; +static void * new_mkdir_ptr __attribute__((section(".data"))) = NULL; #ifdef __cplusplus extern "C" { @@ -32,6 +33,7 @@ static void * new_readdir_ptr __attribute__((section(".data"))) = NULL; new_opendir_ptr = (void*) args.opendir_repl; new_closedir_ptr = (void*) args.closedir_repl; new_readdir_ptr = (void*) args.readdir_repl; + new_mkdir_ptr = (void*) args.mkdir_repl; } int __real_open(const char *pathname, int flags); @@ -84,6 +86,11 @@ static void * new_readdir_ptr __attribute__((section(".data"))) = NULL; if(new_readdir_ptr == NULL) return __real_readdir(dirp); return ( (struct dirent * (*)(DIR *))((unsigned int*)new_readdir_ptr) )(dirp); } + int __real_mkdir(const char *path, mode_t mode); + int __wrap_mkdir(const char *path, mode_t mode){ + if(new_mkdir_ptr == NULL) return __real_mkdir(path, mode); + return ( (int (*)(const char *, mode_t))((unsigned int*) new_mkdir_ptr) )(path, mode); + } #ifdef __cplusplus } diff --git a/wups_include/hooks.h b/wups_include/hooks.h index 9f58ba5..8bf0274 100644 --- a/wups_include/hooks.h +++ b/wups_include/hooks.h @@ -73,6 +73,7 @@ typedef struct wups_loader_init_fs_args_t { const void * opendir_repl; const void * closedir_repl; const void * readdir_repl; + const void * mkdir_repl; } wups_loader_init_fs_args_t;