From 7aec6a2bfde5fcdb21a4b0afc27c10c32ce5d968 Mon Sep 17 00:00:00 2001 From: Maschell Date: Mon, 12 Feb 2018 20:51:24 +0100 Subject: [PATCH] [General] Updated the wups_loader_entry_t struct Removed the union --- loader/src/elf_utils.cpp | 3 +++ loader/src/link_utils.cpp | 20 ++++++++++++-------- loader/src/main.cpp | 31 ++++++++----------------------- wups_include/wups.h | 20 ++++++++------------ 4 files changed, 31 insertions(+), 43 deletions(-) diff --git a/loader/src/elf_utils.cpp b/loader/src/elf_utils.cpp index 51b8393..31cb920 100644 --- a/loader/src/elf_utils.cpp +++ b/loader/src/elf_utils.cpp @@ -336,6 +336,7 @@ bool Module_ElfLinkOne(char type, size_t offset, int addend, void *destination, break; } case R_PPC_REL24: case R_PPC_PLTREL24: + case R_PPC_LOCAL24PC: case R_PPC_REL14: case R_PPC_REL14_BRTAKEN: case R_PPC_REL14_BRNTAKEN: @@ -357,6 +358,7 @@ bool Module_ElfLinkOne(char type, size_t offset, int addend, void *destination, value = addend - (int)symbol_addr; break; } default: + DEBUG_FUNCTION_LINE("Module_ElfLinkOne01: %02X\n",type); goto exit_error; } @@ -370,6 +372,7 @@ bool Module_ElfLinkOne(char type, size_t offset, int addend, void *destination, break; } case R_PPC_ADDR24: case R_PPC_PLTREL24: + case R_PPC_LOCAL24PC: case R_PPC_REL24: { *(int *)target = (*(int *)target & 0xfc000003) | (value & 0x03fffffc); diff --git a/loader/src/link_utils.cpp b/loader/src/link_utils.cpp index bd2998c..faa04d0 100644 --- a/loader/src/link_utils.cpp +++ b/loader/src/link_utils.cpp @@ -284,7 +284,7 @@ bool Module_ListLinkFinal() { goto exit_error; } wups_loader_hook_t * hook = &module_hooks[hook_data->hook_index]; - DEBUG_FUNCTION_LINE("Set hook %d of module \"%s\" of type %08X\n",hook_data->hook_index,module_data->module_name,hook->type); + DEBUG_FUNCTION_LINE("Set hook %d of module \"%s\" of type %08X to target %08X\n",hook_data->hook_index,module_data->module_name,hook->type,(void*) hook->target); hook_data->func_pointer = (void*) hook->target; hook_data->type = hook->type; @@ -299,10 +299,14 @@ bool Module_ListLinkFinal() { goto exit_error; } wups_loader_entry_t * entry = &module_entries[function_data->entry_index]; - strncpy(function_data->function_name,entry->data._function.name,MAXIMUM_FUNCTION_NAME_LENGTH-1); - function_data->library = entry->data._function.library; - function_data->replaceAddr = (u32) entry->data._function.target; - function_data->replaceCall = (u32) entry->data._function.call_addr; + if(entry->_function.name != NULL){ + strncpy(function_data->function_name,entry->_function.name,MAXIMUM_FUNCTION_NAME_LENGTH-1); + }else { + DEBUG_FUNCTION_LINE("WARNING NAME IS NULL\n"); + } + function_data->library = entry->_function.library; + function_data->replaceAddr = (u32) entry->_function.target; + function_data->replaceCall = (u32) entry->_function.call_addr; /* We don't need this... @@ -313,8 +317,8 @@ bool Module_ListLinkFinal() { for (int relocation_index = 0;relocation_index < module_relocations_count;relocation_index++) { DEBUG_FUNCTION_LINE("Try relocation %d\n",relocation_index); if (module_relocations[relocation_index].module == module_index){ - if(strcmp(entry->data._function.real_function_name,module_relocations[relocation_index].name) == 0){ - DEBUG_FUNCTION_LINE("Found the entry we want to replace %s\n",entry->data._function.real_function_name); + if(strcmp(entry->_function.real_function_name,module_relocations[relocation_index].name) == 0){ + DEBUG_FUNCTION_LINE("Found the entry we want to replace %s\n",entry->_function.real_function_name); reloc = &module_relocations[relocation_index]; break; } @@ -323,7 +327,7 @@ bool Module_ListLinkFinal() { if(reloc != NULL){ u32 call_addr = (u32) &function_data->replace_data[0]; - //DEBUG_FUNCTION_LINE("Found reloc. We need to find the symbol for: %s in lib %d\n",entry->data._function.name,entry->data._function.library); + //DEBUG_FUNCTION_LINE("Found reloc. We need to find the symbol for: %s in lib %d\n",entry->_function.name,entry->_function.library); //u32 call_addr = (u32) new_GetAddressOfFunction("OSFatal",WUPS_LOADER_LIBRARY_COREINIT); DEBUG_FUNCTION_LINE("Relocating\n"); if (!Module_ElfLinkOne(reloc->type, reloc->offset, reloc->addend, reloc->address, (uint32_t)call_addr)){ diff --git a/loader/src/main.cpp b/loader/src/main.cpp index d36a9c0..edf4bf0 100644 --- a/loader/src/main.cpp +++ b/loader/src/main.cpp @@ -59,11 +59,10 @@ extern "C" int Menu_Main(int argc, char **argv){ if(!loadSamplePlugin()){ return EXIT_SUCCESS; } - } if(module_relocations_count != 0){ - DEBUG_FUNCTION_LINE("We still have undefined symbol. Make sure to link them in =/ Exiting\n"); + DEBUG_FUNCTION_LINE("We still have undefined symbol. Make sure to link them in =/ Exiting!\n"); return EXIT_SUCCESS; } @@ -151,10 +150,13 @@ bool loadSamplePlugin(){ int res = 0; if((res = mount_sd_fat("sd")) >= 0){ DEBUG_FUNCTION_LINE("Mounting successful\n"); - loadElf("sd:/wiiu/plugins/example_plugin.mod"); + + loadElf("sd:/wiiu/plugins/hid_to_vpad.mod"); loadElf("sd:/wiiu/plugins/sdcafiine.mod"); + //loadElf("sd:/wiiu/plugins/example_plugin.mod"); loadElf("sd:/wiiu/plugins/padcon.mod"); loadElf("sd:/wiiu/plugins/swapdrc.mod"); + if(module_list_count == 0){ DEBUG_FUNCTION_LINE("Found no valid modules! =( Exiting\n"); return false; @@ -186,23 +188,6 @@ bool loadSamplePlugin(){ printReplacementInfos(); - /* - test code for calling the loaded functions. - - DEBUG_FUNCTION_LINE("We need no more relocations, we can call the functions!!\n"); - DEBUG_FUNCTION_LINE("Calling %d functions!\n",module_entries_count); - for (unsigned int i = 0; i < module_entries_count; i++) { - DEBUG_FUNCTION_LINE("--- Function %d ---\n",i); - if( module_entries[i].type == WUPS_LOADER_ENTRY_FUNCTION || - module_entries[i].type == WUPS_LOADER_ENTRY_FUNCTION_MANDATORY){ - DEBUG_FUNCTION_LINE("Let's call the function: %08X \n",module_entries[i].data._function.name); - DEBUG_FUNCTION_LINE("Let's call the function: %s \n",module_entries[i].data._function.name); - dumpHex(module_entries[i].data._function.target,0x80); - //int ret = ( (int (*)(void))((unsigned int*)module_entries[i].data._function.target) )(); - //DEBUG_FUNCTION_LINE("result: %08X \n",ret); - } - }*/ - unmount_sd_fat("sd"); } return true; @@ -244,9 +229,9 @@ static void printInfos(){ DEBUG_FUNCTION_LINE("--- Entry %d ---\n",i); if( module_entries[i].type == WUPS_LOADER_ENTRY_FUNCTION || module_entries[i].type == WUPS_LOADER_ENTRY_FUNCTION_MANDATORY){ - DEBUG_FUNCTION_LINE("library: %d \n",module_entries[i].data._function.library); - DEBUG_FUNCTION_LINE("function: %s \n",module_entries[i].data._function.name); - DEBUG_FUNCTION_LINE("pointer: %08X \n",module_entries[i].data._function.target); + DEBUG_FUNCTION_LINE("library: %d \n",module_entries[i]._function.library); + DEBUG_FUNCTION_LINE("function: %s \n",module_entries[i]._function.name); + DEBUG_FUNCTION_LINE("pointer: %08X \n",module_entries[i]._function.target); } } DEBUG_FUNCTION_LINE("--- Entry list end ---\n"); diff --git a/wups_include/wups.h b/wups_include/wups.h index aaed87f..72600ef 100644 --- a/wups_include/wups.h +++ b/wups_include/wups.h @@ -140,15 +140,13 @@ typedef enum wups_loader_entry_type_t { typedef struct wups_loader_entry_t { wups_loader_entry_type_t type; - union { - struct { - const char *name; /* Name of the function that will be replaced */ - const wups_loader_library_type_t library; /**/ - const char *my_function_name; /* Function name of your own, new function (my_XXX) */ - const void *call_addr; /* Function name of function, to call the real function.(real_XXX) */ - const void *target; /*Address of our own, new function (my_XXX)*/ - } _function; - } data; + struct { + const char *name; /* Name of the function that will be replaced */ + const wups_loader_library_type_t library; /**/ + const char *my_function_name; /* Function name of your own, new function (my_XXX) */ + const void *call_addr; /* Function name of function, to call the real function.(real_XXX) */ + const void *target; /*Address of our own, new function (my_XXX)*/ + } _function; } wups_loader_entry_t; #define WUPS_MUST_REPLACE(x, lib, function_name) WUPS_MUST_REPLACE_EX(real_ ## x, lib, my_ ## x, function_name); @@ -158,15 +156,13 @@ typedef struct wups_loader_entry_t { WUPS_SECTION("load"); \ const wups_loader_entry_t wups_load_ ## replace_func = { \ .type = WUPS_LOADER_ENTRY_FUNCTION_MANDATORY, \ - .data = { \ - ._function = { \ + ._function = { \ .name = #replace_function_name, \ .library = rpl_type, \ .my_function_name = #replace_func, \ .call_addr = (const void*)&(original_func), \ .target = (const void*)&(replace_func) \ } \ - } \ } #define WUPS_META(id, value) \