diff --git a/loader/Makefile b/loader/Makefile index 81418bf..ff73d6b 100644 --- a/loader/Makefile +++ b/loader/Makefile @@ -37,9 +37,9 @@ SOURCES := src/common \ src/libelf \ src/menu/content \ src/menu \ - src/modules \ src/myutils \ src/patcher \ + src/plugin \ src/resources \ src/settings \ src/ diff --git a/loader/src/main.cpp b/loader/src/main.cpp index eada4a8..bebb771 100644 --- a/loader/src/main.cpp +++ b/loader/src/main.cpp @@ -30,8 +30,8 @@ #include "common/retain_vars.h" #include "common/common.h" -#include "modules/ModuleLoader.h" -#include "modules/ModuleData.h" +#include "plugin/PluginLoader.h" +#include "plugin/PluginInformation.h" #include @@ -89,9 +89,9 @@ extern "C" int Menu_Main(int argc, char **argv){ if(isFirstBoot){ memset((void*)&gbl_replacement_data,0,sizeof(gbl_replacement_data)); - ModuleLoader * moduleLoader = ModuleLoader::getInstance(); - std::vector moduleList = moduleLoader->getModuleInformation("sd:/wiiu/plugins/"); - moduleLoader->loadAndLinkModules(moduleList); + PluginLoader * pluginLoader = PluginLoader::getInstance(); + std::vector pluginList = pluginLoader->getPluginInformation("sd:/wiiu/plugins/"); + pluginLoader->loadAndLinkPlugins(pluginList); //!******************************************************************* //! Initialize heap memory * @@ -149,18 +149,18 @@ extern "C" int Menu_Main(int argc, char **argv){ void ApplyPatches(){ PatchInvidualMethodHooks(method_hooks_hooks, method_hooks_size_hooks, method_calls_hooks); - for(int module_index=0;module_indexmodule_name); - DEBUG_FUNCTION_LINE("Found hooks: %d\n",module_data->number_used_hooks); - for(int j=0;jnumber_used_hooks;j++){ - replacement_data_hook_t * hook_data = &module_data->hooks[j]; + for(int plugin_index=0;plugin_indexplugin_name); + DEBUG_FUNCTION_LINE("Found hooks: %d\n",plugin_data->number_used_hooks); + for(int j=0;jnumber_used_hooks;j++){ + replacement_data_hook_t * hook_data = &plugin_data->hooks[j]; if(hook_data->type == hook_type){ DEBUG_FUNCTION_LINE("Calling hook of type %d\n",hook_data->type); void * func_ptr = hook_data->func_pointer; @@ -198,9 +198,9 @@ void DeInit(){ } void RestorePatches(){ - for(int module_index=gbl_replacement_data.number_used_modules-1;module_index>=0;module_index--){ - DEBUG_FUNCTION_LINE("Restoring function for module: %d\n",module_index); - new_RestoreInvidualInstructions(&gbl_replacement_data.module_data[module_index]); + for(int plugin_index=gbl_replacement_data.number_used_plugins-1;plugin_index>=0;plugin_index--){ + DEBUG_FUNCTION_LINE("Restoring function for plugin: %d\n",plugin_index); + new_RestoreInvidualInstructions(&gbl_replacement_data.plugin_data[plugin_index]); } RestoreInvidualInstructions(method_hooks_hooks, method_hooks_size_hooks); } diff --git a/loader/src/patcher/function_patcher.cpp b/loader/src/patcher/function_patcher.cpp index 48191bd..b914c79 100644 --- a/loader/src/patcher/function_patcher.cpp +++ b/loader/src/patcher/function_patcher.cpp @@ -99,20 +99,20 @@ rpl_handling rpl_handles[] __attribute__((section(".data"))) = { {WUPS_LOADER_LIBRARY_ZLIB125, "zlib125.rpl" ,0} }; -void new_PatchInvidualMethodHooks(replacement_data_module_t * module_data){ +void new_PatchInvidualMethodHooks(replacement_data_plugin_t * plugin_data){ InitAcquireOS(); new_resetLibs(); - DEBUG_FUNCTION_LINE("Patching %d given functions\n",module_data->number_used_functions); + DEBUG_FUNCTION_LINE("Patching %d given functions\n",plugin_data->number_used_functions); - s32 method_hooks_count = module_data->number_used_functions; + s32 method_hooks_count = plugin_data->number_used_functions; u32 skip_instr = 1; u32 my_instr_len = 6; u32 instr_len = my_instr_len + skip_instr; u32 flush_len = 4*instr_len; for(s32 i = 0; i < method_hooks_count; i++){ - replacement_data_function_t * function_data = &module_data->functions[i]; + replacement_data_function_t * function_data = &plugin_data->functions[i]; /* Patch branches to it. */ volatile u32 *space = function_data->replace_data; @@ -209,15 +209,15 @@ void new_PatchInvidualMethodHooks(replacement_data_module_t * module_data){ /* ****************************************************************** */ /* RESTORE ORIGINAL INSTRUCTIONS */ /* ****************************************************************** */ -void new_RestoreInvidualInstructions(replacement_data_module_t * module_data){ +void new_RestoreInvidualInstructions(replacement_data_plugin_t * plugin_data){ InitAcquireOS(); new_resetLibs(); DEBUG_FUNCTION_LINE("Restoring given functions!\n"); - s32 method_hooks_count = module_data->number_used_functions; + s32 method_hooks_count = plugin_data->number_used_functions; for(s32 i = 0; i < method_hooks_count; i++){ - replacement_data_function_t * function_data = &module_data->functions[i]; + replacement_data_function_t * function_data = &plugin_data->functions[i]; DEBUG_FUNCTION_LINE("Restoring %s... ",function_data->function_name); if(function_data->restoreInstruction == 0 || function_data->realAddr == 0){ diff --git a/loader/src/patcher/function_patcher.h b/loader/src/patcher/function_patcher.h index 613c051..b81eeb7 100644 --- a/loader/src/patcher/function_patcher.h +++ b/loader/src/patcher/function_patcher.h @@ -38,7 +38,7 @@ struct rpl_handling { #define DYNAMIC_FUNCTION 1 #define FUNCTION_PATCHER_METHOD_STORE_SIZE 7 -#define MAXIMUM_MODULE_NAME_LENGTH 51 +#define MAXIMUM_PLUGIN_NAME_LENGTH 51 #define MAXIMUM_FUNCTION_NAME_LENGTH 51 struct replacement_data_function_t{ @@ -62,28 +62,28 @@ struct replacement_data_hook_t{ }; -#define MAXIMUM_HOOKS_PER_MODULE 10 -#define MAXIMUM_FUNCTION_PER_MODULE 100 +#define MAXIMUM_HOOKS_PER_PLUGIN 10 +#define MAXIMUM_FUNCTION_PER_PLUGIN 100 -struct replacement_data_module_t{ - char module_name[MAXIMUM_MODULE_NAME_LENGTH] = ""; // Name of this module - int priority; // Priority of this module - int number_used_functions; // Number of used function. Maximum is MAXIMUM_FUNCTION_PER_MODULE - replacement_data_function_t functions[MAXIMUM_FUNCTION_PER_MODULE]; // Replacement information for each function. +struct replacement_data_plugin_t{ + char plugin_name[MAXIMUM_PLUGIN_NAME_LENGTH] = ""; // Name of this plugin + int priority; // Priority of this plugin + int number_used_functions; // Number of used function. Maximum is MAXIMUM_FUNCTION_PER_PLUGIN + replacement_data_function_t functions[MAXIMUM_FUNCTION_PER_PLUGIN]; // Replacement information for each function. - int number_used_hooks; // Number of used hooks. Maximum is MAXIMUM_HOOKS_PER_MODULE - replacement_data_hook_t hooks[MAXIMUM_HOOKS_PER_MODULE]; // Replacement information for each function. + int number_used_hooks; // Number of used hooks. Maximum is MAXIMUM_HOOKS_PER_PLUGIN + replacement_data_hook_t hooks[MAXIMUM_HOOKS_PER_PLUGIN]; // Replacement information for each function. }; -#define MAXIMUM_MODULES 32 +#define MAXIMUM_PLUGINS 32 struct replacement_data_t{ - int number_used_modules = 0; // Number of used function. Maximum is MAXIMUM_FUNCTION_PER_MODULE - replacement_data_module_t module_data[MAXIMUM_MODULES]; + int number_used_plugins = 0; // Number of used function. Maximum is MAXIMUM_FUNCTION_PER_PLUGIN + replacement_data_plugin_t plugin_data[MAXIMUM_PLUGINS]; }; -void new_PatchInvidualMethodHooks(replacement_data_module_t * data); -void new_RestoreInvidualInstructions(replacement_data_module_t * module_data); +void new_PatchInvidualMethodHooks(replacement_data_plugin_t * data); +void new_RestoreInvidualInstructions(replacement_data_plugin_t * plugin_data); u32 new_GetAddressOfFunction(const char * functionName,wups_loader_library_type_t library); s32 new_isDynamicFunction(u32 physicalAddress); void new_resetLibs(); diff --git a/loader/src/modules/ElfTools.cpp b/loader/src/plugin/ElfTools.cpp similarity index 98% rename from loader/src/modules/ElfTools.cpp rename to loader/src/plugin/ElfTools.cpp index f57816b..f64fb0a 100644 --- a/loader/src/modules/ElfTools.cpp +++ b/loader/src/plugin/ElfTools.cpp @@ -175,7 +175,7 @@ bool ElfTools::elfLink(Elf *elf, size_t shndx, void *destination, Elf32_Sym *sym sizeof(module_unresolved_relocation_t), 1, &module_relocations_capacity, &module_relocations_count, - MODULE_RELOCATIONS_CAPCITY_DEFAULT); + PLUGIN_RELOCATIONS_CAPCITY_DEFAULT); if (reloc == NULL) return false; @@ -262,7 +262,7 @@ bool ElfTools::elfLink(Elf *elf, size_t shndx, void *destination, Elf32_Sym *sym sizeof(module_unresolved_relocation_t), 1, &module_relocations_capacity, &module_relocations_count, - MODULE_RELOCATIONS_CAPCITY_DEFAULT); + PLUGIN_RELOCATIONS_CAPCITY_DEFAULT); if (reloc == NULL) return false; @@ -422,7 +422,7 @@ bool ElfTools::elfLinkOne(char type, size_t offset, int addend, void *destinatio result = true; exit_error: - if (!result) DEBUG_FUNCTION_LINE("Module_ElfLinkOne: exit_error\n"); + if (!result) DEBUG_FUNCTION_LINE("Plugin_ElfLinkOne: exit_error\n"); return result; } diff --git a/loader/src/modules/ElfTools.h b/loader/src/plugin/ElfTools.h similarity index 100% rename from loader/src/modules/ElfTools.h rename to loader/src/plugin/ElfTools.h diff --git a/loader/src/modules/EntryData.h b/loader/src/plugin/EntryData.h similarity index 100% rename from loader/src/modules/EntryData.h rename to loader/src/plugin/EntryData.h diff --git a/loader/src/modules/HookData.h b/loader/src/plugin/HookData.h similarity index 100% rename from loader/src/modules/HookData.h rename to loader/src/plugin/HookData.h diff --git a/loader/src/modules/ModuleData.h b/loader/src/plugin/PluginData.h similarity index 84% rename from loader/src/modules/ModuleData.h rename to loader/src/plugin/PluginData.h index 6727f04..c874bd0 100644 --- a/loader/src/modules/ModuleData.h +++ b/loader/src/plugin/PluginData.h @@ -15,14 +15,14 @@ * along with this program. If not, see . ****************************************************************************/ -#ifndef _MODULE_DATA_H_ -#define _MODULE_DATA_H_ +#ifndef _PLUGIN_DATA_H_ +#define _PLUGIN_DATA_H_ #include #include #include "EntryData.h" #include "HookData.h" -#include "ModuleInformation.h" +#include "PluginInformation.h" #include #ifdef __cplusplus @@ -35,13 +35,13 @@ extern "C" { } #endif -class ModuleData{ +class PluginData{ public: - ModuleData(ModuleInformation * moduleInformation){ - this->moduleInformation = moduleInformation; + PluginData(PluginInformation * pluginInformation){ + this->pluginInformation = pluginInformation; } - ~ModuleData(){ + ~PluginData(){ for(size_t i = 0;i< entry_data_list.size();i++){ if(entry_data_list[i] != NULL){ delete entry_data_list[i]; @@ -71,13 +71,13 @@ class ModuleData{ return hook_data_list; } - ModuleInformation * getModuleInformation(){ - return moduleInformation; + PluginInformation * getPluginInformation(){ + return pluginInformation; } private: - ModuleInformation * moduleInformation; + PluginInformation * pluginInformation; std::vector entry_data_list; std::vector hook_data_list; diff --git a/loader/src/modules/ModuleInformation.cpp b/loader/src/plugin/PluginInformation.cpp similarity index 93% rename from loader/src/modules/ModuleInformation.cpp rename to loader/src/plugin/PluginInformation.cpp index 4808f62..2a2aeca 100644 --- a/loader/src/modules/ModuleInformation.cpp +++ b/loader/src/plugin/PluginInformation.cpp @@ -1,4 +1,4 @@ -/* based on module.c +/* based on plugin.c * by Alex Chadwick * * Copyright (C) 2014, Alex Chadwick @@ -23,7 +23,7 @@ * SOFTWARE. */ -#include "ModuleInformation.h" +#include "PluginInformation.h" #include #include #include @@ -36,7 +36,7 @@ #include #include "ElfTools.h" -bool ModuleInformation::checkFileExtenstion(const char * path) { +bool PluginInformation::checkFileExtenstion(const char * path) { if(path == NULL){ return false; } @@ -63,7 +63,7 @@ bool ModuleInformation::checkFileExtenstion(const char * path) { return false; } -bool ModuleInformation::openAndParseElf() { +bool PluginInformation::openAndParseElf() { bool result = false; int fd = -1; Elf *elf = NULL; @@ -110,7 +110,7 @@ exit_error: return result; } -bool ModuleInformation::parseElf( Elf *elf) { +bool PluginInformation::parseElf( Elf *elf) { bool res = false; Elf_Scn *scn; Elf32_Ehdr *ehdr; @@ -237,7 +237,7 @@ exit_error: return res; } -bool ModuleInformation::metadataRead(Elf *elf, Elf32_Sym *symtab, size_t symtab_count, size_t symtab_strndx) { +bool PluginInformation::metadataRead(Elf *elf, Elf32_Sym *symtab, size_t symtab_count, size_t symtab_strndx) { char *metadata = NULL, *metadata_cur, *metadata_end; const char *game, *name, *author, *version, *license, *wups; @@ -296,7 +296,7 @@ bool ModuleInformation::metadataRead(Elf *elf, Elf32_Sym *symtab, size_t symtab_ } if (metadata == NULL) { - DEBUG_FUNCTION_LINE("Warning: Ignoring '%s' - Not a WUPS module file.\n", path); + DEBUG_FUNCTION_LINE("Warning: Ignoring '%s' - Not a WUPS plugin file.\n", path); goto exit_error; } @@ -326,37 +326,37 @@ bool ModuleInformation::metadataRead(Elf *elf, Elf32_Sym *symtab, size_t symtab_ if (strncmp(metadata_cur, "game", eq - metadata_cur) == 0) { if (game != NULL) { - DEBUG_FUNCTION_LINE("Warning: Ignoring '%s' - Multiple WUPS_MODULE_GAME declarations.\n", path); + DEBUG_FUNCTION_LINE("Warning: Ignoring '%s' - Multiple WUPS_PLUGIN_GAME declarations.\n", path); goto exit_error; } game = eq + 1; } else if (strncmp(metadata_cur, "name", eq - metadata_cur) == 0) { if (name != NULL) { - DEBUG_FUNCTION_LINE("Warning: Ignoring '%s' - Multiple WUPS_MODULE_NAME declarations.\n", path); + DEBUG_FUNCTION_LINE("Warning: Ignoring '%s' - Multiple WUPS_PLUGIN_NAME declarations.\n", path); goto exit_error; } name = eq + 1; } else if (strncmp(metadata_cur, "author", eq - metadata_cur) == 0) { if (author != NULL) { - DEBUG_FUNCTION_LINE("Warning: Ignoring '%s' - Multiple WUPS_MODULE_AUTHOR declarations.\n", path); + DEBUG_FUNCTION_LINE("Warning: Ignoring '%s' - Multiple WUPS_PLUGIN_AUTHOR declarations.\n", path); goto exit_error; } author = eq + 1; } else if (strncmp(metadata_cur, "version", eq - metadata_cur) == 0) { if (version != NULL) { - DEBUG_FUNCTION_LINE("Warning: Ignoring '%s' - Multiple WUPS_MODULE_VERSION declarations.\n", path); + DEBUG_FUNCTION_LINE("Warning: Ignoring '%s' - Multiple WUPS_PLUGIN_VERSION declarations.\n", path); goto exit_error; } version = eq + 1; } else if (strncmp(metadata_cur, "license", eq - metadata_cur) == 0) { if (license != NULL) { - DEBUG_FUNCTION_LINE("Warning: Ignoring '%s' - Multiple WUPS_MODULE_LICENSE declarations.\n", path); + DEBUG_FUNCTION_LINE("Warning: Ignoring '%s' - Multiple WUPS_PLUGIN_LICENSE declarations.\n", path); goto exit_error; } license = eq + 1; } else if (strncmp(metadata_cur, "wups", eq - metadata_cur) == 0) { if (wups != NULL) { - DEBUG_FUNCTION_LINE("Warning: Ignoring '%s' - Multiple WUPS_MODULE_NAME declarations.\n", path); + DEBUG_FUNCTION_LINE("Warning: Ignoring '%s' - Multiple WUPS_PLUGIN_NAME declarations.\n", path); goto exit_error; } wups = eq + 1; @@ -372,19 +372,19 @@ bool ModuleInformation::metadataRead(Elf *elf, Elf32_Sym *symtab, size_t symtab_ goto exit_error; }*/ if (name == NULL) { - DEBUG_FUNCTION_LINE("Warning: Ignoring '%s' - Missing WUPS_MODULE_NAME declaration.\n",path); + DEBUG_FUNCTION_LINE("Warning: Ignoring '%s' - Missing WUPS_PLUGIN_NAME declaration.\n",path); goto exit_error; } if (author == NULL) { - DEBUG_FUNCTION_LINE("Warning: Ignoring '%s' - Missing WUPS_MODULE_AUTHOR declaration.\n", path); + DEBUG_FUNCTION_LINE("Warning: Ignoring '%s' - Missing WUPS_PLUGIN_AUTHOR declaration.\n", path); goto exit_error; } if (version == NULL) { - DEBUG_FUNCTION_LINE("Warning: Ignoring '%s' - Missing WUPS_MODULE_VERSION declaration.\n", path); + DEBUG_FUNCTION_LINE("Warning: Ignoring '%s' - Missing WUPS_PLUGIN_VERSION declaration.\n", path); goto exit_error; } if (license == NULL) { - DEBUG_FUNCTION_LINE("Warning: Ignoring '%s' - Missing WUPS_MODULE_LICENSE declaration.\n", path); + DEBUG_FUNCTION_LINE("Warning: Ignoring '%s' - Missing WUPS_PLUGIN_LICENSE declaration.\n", path); goto exit_error; } diff --git a/loader/src/modules/ModuleInformation.h b/loader/src/plugin/PluginInformation.h similarity index 83% rename from loader/src/modules/ModuleInformation.h rename to loader/src/plugin/PluginInformation.h index e80172e..1027f72 100644 --- a/loader/src/modules/ModuleInformation.h +++ b/loader/src/plugin/PluginInformation.h @@ -23,8 +23,8 @@ * SOFTWARE. */ -#ifndef _MODULE_INFORMATION_H_ -#define _MODULE_INFORMATION_H_ +#ifndef _PLUGIN_INFORMATION_H_ +#define _PLUGIN_INFORMATION_H_ #include #include @@ -42,20 +42,20 @@ extern "C" { } #endif -class ModuleInformation{ +class PluginInformation{ public: /** - returns ModuleInformation* if a valid plugin was found at the given path. Otherwise returns NULL + returns PluginInformation* if a valid plugin was found at the given path. Otherwise returns NULL **/ - static ModuleInformation * loadModuleInformation(std::string path){ - if(ModuleInformation::checkFileExtenstion(path.c_str())){ - DEBUG_FUNCTION_LINE("Checkfile successfully, loading now Module Information\n"); - ModuleInformation * moduleInformation = new ModuleInformation(path); - if(moduleInformation->openAndParseElf()){ - return moduleInformation; + static PluginInformation * loadPluginInformation(std::string path){ + if(PluginInformation::checkFileExtenstion(path.c_str())){ + DEBUG_FUNCTION_LINE("Checkfile successfully, loading now Plugin Information\n"); + PluginInformation * pluginInformation = new PluginInformation(path); + if(pluginInformation->openAndParseElf()){ + return pluginInformation; }else{ - delete moduleInformation; + delete pluginInformation; return NULL; } } else { @@ -87,7 +87,7 @@ class ModuleInformation{ return this->size; } private: - ModuleInformation(std::string path){ + PluginInformation(std::string path){ this->path = path; } diff --git a/loader/src/modules/ModuleLoader.cpp b/loader/src/plugin/PluginLoader.cpp similarity index 71% rename from loader/src/modules/ModuleLoader.cpp rename to loader/src/plugin/PluginLoader.cpp index 90b2ae6..84dc82e 100644 --- a/loader/src/modules/ModuleLoader.cpp +++ b/loader/src/plugin/PluginLoader.cpp @@ -29,15 +29,15 @@ #include #include #include "ElfTools.h" -#include "ModuleData.h" -#include "ModuleLoader.h" +#include "PluginData.h" +#include "PluginLoader.h" #include "utils/StringTools.h" #include "common/retain_vars.h" -ModuleLoader * ModuleLoader::instance = NULL; +PluginLoader * PluginLoader::instance = NULL; -std::vector ModuleLoader::getModuleInformation(const char * path){ - std::vector result; +std::vector PluginLoader::getPluginInformation(const char * path){ + std::vector result; struct dirent *dp; DIR *dfd = NULL; @@ -64,10 +64,10 @@ std::vector ModuleLoader::getModuleInformation(const char * continue; }else{ DEBUG_FUNCTION_LINE("Found file: %s\n",full_file_path.c_str()) ; - ModuleInformation * module = ModuleInformation::loadModuleInformation(full_file_path); - if(module != NULL){ - DEBUG_FUNCTION_LINE("Found plugin %s by %s. Size: %d kb \n",module->getName().c_str(),module->getAuthor().c_str(),module->getSize()/1024) ; - result.push_back(module); + PluginInformation * plugin = PluginInformation::loadPluginInformation(full_file_path); + if(plugin != NULL){ + DEBUG_FUNCTION_LINE("Found plugin %s by %s. Size: %d kb \n",plugin->getName().c_str(),plugin->getAuthor().c_str(),plugin->getSize()/1024) ; + result.push_back(plugin); } else { DEBUG_FUNCTION_LINE("%s is not a valid plugin\n",full_file_path.c_str()) ; } @@ -77,46 +77,46 @@ std::vector ModuleLoader::getModuleInformation(const char * return result; } -void ModuleLoader::loadAndLinkModules(std::vector moduleInformation){ - std::vector loadedModules; - for(size_t i = 0;i < moduleInformation.size(); i++){ - DEBUG_FUNCTION_LINE("loadAndLinkModules for %d\n",i) ; - ModuleInformation * cur_info = moduleInformation[i]; - ModuleData * moduleData = loadAndLinkModule(cur_info); - if(moduleData == NULL){ - DEBUG_FUNCTION_LINE("loadAndLinkModules failed for %d\n",i) ; +void PluginLoader::loadAndLinkPlugins(std::vector pluginInformation){ + std::vector loadedPlugins; + for(size_t i = 0;i < pluginInformation.size(); i++){ + DEBUG_FUNCTION_LINE("loadAndLinkPlugins for %d\n",i) ; + PluginInformation * cur_info = pluginInformation[i]; + PluginData * pluginData = loadAndLinkPlugin(cur_info); + if(pluginData == NULL){ + DEBUG_FUNCTION_LINE("loadAndLinkPlugins failed for %d\n",i) ; continue; } else { - loadedModules.push_back(moduleData); + loadedPlugins.push_back(pluginData); } } - copyModuleDataIntoGlobalStruct(loadedModules); - clearModuleData(loadedModules); + copyPluginDataIntoGlobalStruct(loadedPlugins); + clearPluginData(loadedPlugins); } -void ModuleLoader::clearModuleData(std::vector moduleData){ - for(size_t i = 0;i < moduleData.size(); i++){ - ModuleData * curModuleData = moduleData[i]; - if(curModuleData != NULL){ - delete curModuleData; +void PluginLoader::clearPluginData(std::vector pluginData){ + for(size_t i = 0;i < pluginData.size(); i++){ + PluginData * curPluginData = pluginData[i]; + if(curPluginData != NULL){ + delete curPluginData; } } } -ModuleData * ModuleLoader::loadAndLinkModule(ModuleInformation * moduleInformation){ +PluginData * PluginLoader::loadAndLinkPlugin(PluginInformation * pluginInformation){ DEBUG_FUNCTION_LINE("\n"); - ModuleData * result = NULL; + PluginData * result = NULL; int fd = -1; Elf *elf = NULL; - if(moduleInformation == NULL){ - DEBUG_FUNCTION_LINE("moduleInformation was NULL\n"); + if(pluginInformation == NULL){ + DEBUG_FUNCTION_LINE("pluginInformation was NULL\n"); goto exit_error; } - if(moduleInformation->getSize() > ((u32) this->getCurrentStoreAddress() - (u32) this->startAddress)){ + if(pluginInformation->getSize() > ((u32) this->getCurrentStoreAddress() - (u32) this->startAddress)){ DEBUG_FUNCTION_LINE("Not enough space left to loader the plugin into memory\n"); goto exit_error; } @@ -126,10 +126,10 @@ ModuleData * ModuleLoader::loadAndLinkModule(ModuleInformation * moduleInformati goto exit_error; } - fd = open(moduleInformation->getPath().c_str(), O_RDONLY, 0); + fd = open(pluginInformation->getPath().c_str(), O_RDONLY, 0); if (fd == -1){ - DEBUG_FUNCTION_LINE("failed to open '%s' \n", moduleInformation->getPath().c_str()); + DEBUG_FUNCTION_LINE("failed to open '%s' \n", pluginInformation->getPath().c_str()); goto exit_error; } @@ -141,7 +141,7 @@ ModuleData * ModuleLoader::loadAndLinkModule(ModuleInformation * moduleInformati } DEBUG_FUNCTION_LINE("\n"); - result = new ModuleData(moduleInformation); + result = new PluginData(pluginInformation); if(result == NULL){ DEBUG_FUNCTION_LINE("Failed to create object\n"); goto exit_error; @@ -162,8 +162,8 @@ exit_error: return result; } -bool ModuleLoader::loadAndLinkElf(ModuleData * moduleData, Elf *elf, void * endAddress) { - if(moduleData == NULL || elf == NULL || endAddress == NULL){ +bool PluginLoader::loadAndLinkElf(PluginData * pluginData, Elf *elf, void * endAddress) { + if(pluginData == NULL || elf == NULL || endAddress == NULL){ return false; } @@ -317,16 +317,16 @@ bool ModuleLoader::loadAndLinkElf(ModuleData * moduleData, Elf *elf, void * endA for(size_t j=0;jgetModuleInformation()->getName().c_str(),hook->type,(void*) hook->target); + DEBUG_FUNCTION_LINE("Saving hook of plugin \"%s\". Type: %08X, target: %08X\n",pluginData->getPluginInformation()->getName().c_str(),hook->type,(void*) hook->target); HookData * hook_data = new HookData((void *) hook->target,hook->type); - moduleData->addHookData(hook_data); + pluginData->addHookData(hook_data); } for(size_t j=0;j_function.name,moduleData->getModuleInformation()->getName().c_str(),entry->_function.library,entry->_function.target, (void *) entry->_function.call_addr); + DEBUG_FUNCTION_LINE("Saving entry \"%s\" of plugin \"%s\". Library: %08X, target: %08X, call_addr: %08X\n",entry->_function.name,pluginData->getPluginInformation()->getName().c_str(),entry->_function.library,entry->_function.target, (void *) entry->_function.call_addr); EntryData * entry_data = new EntryData(entry->_function.name,entry->_function.library, (void *) entry->_function.target, (void *) entry->_function.call_addr); - moduleData->addEntryData(entry_data); + pluginData->addEntryData(entry_data); } this->setCurrentStoreAddress((void *) curAddress); @@ -349,39 +349,39 @@ exit_error: return result; } -void ModuleLoader::copyModuleDataIntoGlobalStruct(std::vector modules){ +void PluginLoader::copyPluginDataIntoGlobalStruct(std::vector plugins){ // Reset data memset((void*)&gbl_replacement_data,0,sizeof(gbl_replacement_data)); - int module_index = 0; + int plugin_index = 0; // Copy data to global struct. - for(size_t i = 0; i< modules.size();i++){ - ModuleData * cur_module = modules.at(i); - ModuleInformation * cur_moduleInformation = cur_module->getModuleInformation(); + for(size_t i = 0; i< plugins.size();i++){ + PluginData * cur_plugin = plugins.at(i); + PluginInformation * cur_pluginInformation = cur_plugin->getPluginInformation(); - std::vector entry_data_list = cur_module->getEntryDataList(); - std::vector hook_data_list = cur_module->getHookDataList(); - if(module_index >= MAXIMUM_MODULES ){ - DEBUG_FUNCTION_LINE("Maximum of %d modules reached. %s won't be loaded!\n",MAXIMUM_MODULES,cur_moduleInformation->getName().c_str()); + std::vector entry_data_list = cur_plugin->getEntryDataList(); + std::vector hook_data_list = cur_plugin->getHookDataList(); + if(plugin_index >= MAXIMUM_PLUGINS ){ + DEBUG_FUNCTION_LINE("Maximum of %d plugins reached. %s won't be loaded!\n",MAXIMUM_PLUGINS,cur_pluginInformation->getName().c_str()); continue; } - if(entry_data_list.size() > MAXIMUM_FUNCTION_PER_MODULE){ - DEBUG_FUNCTION_LINE("Module %s would replace to many function (%d, maximum is %d). It won't be loaded.\n",cur_moduleInformation->getName().c_str(),entry_data_list.size(),MAXIMUM_FUNCTION_PER_MODULE); + if(entry_data_list.size() > MAXIMUM_FUNCTION_PER_PLUGIN){ + DEBUG_FUNCTION_LINE("Plugin %s would replace to many function (%d, maximum is %d). It won't be loaded.\n",cur_pluginInformation->getName().c_str(),entry_data_list.size(),MAXIMUM_FUNCTION_PER_PLUGIN); continue; } - if(hook_data_list.size() > MAXIMUM_HOOKS_PER_MODULE){ - DEBUG_FUNCTION_LINE("Module %s would set too many hooks (%d, maximum is %d). It won't be loaded.\n",cur_moduleInformation->getName().c_str(),hook_data_list.size(),MAXIMUM_HOOKS_PER_MODULE); + if(hook_data_list.size() > MAXIMUM_HOOKS_PER_PLUGIN){ + DEBUG_FUNCTION_LINE("Plugin %s would set too many hooks (%d, maximum is %d). It won't be loaded.\n",cur_pluginInformation->getName().c_str(),hook_data_list.size(),MAXIMUM_HOOKS_PER_PLUGIN); continue; } - replacement_data_module_t * module_data = &gbl_replacement_data.module_data[module_index]; + replacement_data_plugin_t * plugin_data = &gbl_replacement_data.plugin_data[plugin_index]; - strncpy(module_data->module_name,cur_moduleInformation->getName().c_str(),MAXIMUM_MODULE_NAME_LENGTH-1); + strncpy(plugin_data->plugin_name,cur_pluginInformation->getName().c_str(),MAXIMUM_PLUGIN_NAME_LENGTH-1); for(size_t j = 0; j < entry_data_list.size();j++){ - replacement_data_function_t * function_data = &module_data->functions[j]; + replacement_data_function_t * function_data = &plugin_data->functions[j]; EntryData * cur_entry = entry_data_list[j]; - DEBUG_FUNCTION_LINE("Adding entry \"%s\" for module \"%s\"\n",cur_entry->getName().c_str(),module_data->module_name); + DEBUG_FUNCTION_LINE("Adding entry \"%s\" for plugin \"%s\"\n",cur_entry->getName().c_str(),plugin_data->plugin_name); //TODO: Warning/Error if string is too long. strncpy(function_data->function_name,cur_entry->getName().c_str(),MAXIMUM_FUNCTION_NAME_LENGTH-1); @@ -390,25 +390,25 @@ void ModuleLoader::copyModuleDataIntoGlobalStruct(std::vector modu function_data->replaceAddr = (u32) cur_entry->getReplaceAddress(); function_data->replaceCall = (u32) cur_entry->getReplaceCall(); - module_data->number_used_functions++; + plugin_data->number_used_functions++; } - DEBUG_FUNCTION_LINE("Entries for module \"%s\": %d\n",module_data->module_name,module_data->number_used_functions); + DEBUG_FUNCTION_LINE("Entries for plugin \"%s\": %d\n",plugin_data->plugin_name,plugin_data->number_used_functions); for(size_t j = 0; j < hook_data_list.size();j++){ - replacement_data_hook_t * hook_data = &module_data->hooks[j]; + replacement_data_hook_t * hook_data = &plugin_data->hooks[j]; HookData * hook_entry = hook_data_list[j]; - DEBUG_FUNCTION_LINE("Set hook for module \"%s\" of type %08X to target %08X\n",module_data->module_name,hook_entry->getType(),(void*) hook_entry->getFunctionPointer()); + DEBUG_FUNCTION_LINE("Set hook for plugin \"%s\" of type %08X to target %08X\n",plugin_data->plugin_name,hook_entry->getType(),(void*) hook_entry->getFunctionPointer()); hook_data->func_pointer = (void*) hook_entry->getFunctionPointer(); hook_data->type = hook_entry->getType(); - module_data->number_used_hooks++; + plugin_data->number_used_hooks++; } - DEBUG_FUNCTION_LINE("Hooks for module \"%s\": %d\n",module_data->module_name,module_data->number_used_hooks); + DEBUG_FUNCTION_LINE("Hooks for plugin \"%s\": %d\n",plugin_data->plugin_name,plugin_data->number_used_hooks); - module_index++; - gbl_replacement_data.number_used_modules++; + plugin_index++; + gbl_replacement_data.number_used_plugins++; } } diff --git a/loader/src/modules/ModuleLoader.h b/loader/src/plugin/PluginLoader.h similarity index 74% rename from loader/src/modules/ModuleLoader.h rename to loader/src/plugin/PluginLoader.h index 4bd9706..0f82558 100644 --- a/loader/src/modules/ModuleLoader.h +++ b/loader/src/plugin/PluginLoader.h @@ -23,12 +23,12 @@ * SOFTWARE. */ -#ifndef _MODULE_LOADER_H_ -#define _MODULE_LOADER_H_ +#ifndef _PLUGIN_LOADER_H_ +#define _PLUGIN_LOADER_H_ #include -#include "ModuleInformation.h" -#include "ModuleData.h" +#include "PluginInformation.h" +#include "PluginData.h" #ifdef __cplusplus extern "C" { @@ -43,12 +43,12 @@ extern "C" { #define PLUGIN_LOCATION_END_ADDRESS 0x01000000 -class ModuleLoader{ +class PluginLoader{ public: - static ModuleLoader *getInstance() { + static PluginLoader *getInstance() { if(!instance){ - instance = new ModuleLoader((void*)getApplicationEndAddr(),(void *)PLUGIN_LOCATION_END_ADDRESS); + instance = new PluginLoader((void*)getApplicationEndAddr(),(void *)PLUGIN_LOCATION_END_ADDRESS); } return instance; } @@ -65,9 +65,9 @@ public: \param path the path of the directory which should be scanned. - \return a list of ModuleInformation objects, one for each valid plugin. + \return a list of PluginInformation objects, one for each valid plugin. **/ - std::vector getModuleInformation(const char * path); + std::vector getPluginInformation(const char * path); /** \brief Gets plugin information from the global struct. @@ -75,64 +75,64 @@ public: \return a list of MetaInformation objects for all plugins currently loaded and linked (relocated). Will only contain plugin which are still on the sd card. **/ - //std::vector getModulesLoadedInMemory(); + //std::vector getPluginsLoadedInMemory(); /** - \brief Takes a list of modules that should be linked (relocated) loaded into the memory. + \brief Takes a list of plugins that should be linked (relocated) loaded into the memory. The function that should be replaced will be replaced in the order of the given plugin list. So two plugin will override the same function, the plugin first in this list will override the function first. Also the hooks of the plugins will be called in the order their plugin where passed to this method. \param A list of plugin that should be linked (relocated) an loaded into memory **/ - void loadAndLinkModules(std::vector moduleInformation); + void loadAndLinkPlugins(std::vector pluginInformation); private: - ModuleLoader(void * startAddress, void * endAddress){ + PluginLoader(void * startAddress, void * endAddress){ // TODO: Check if endAddress > startAddress. this->startAddress = startAddress; this->endAddress = endAddress; this->currentStoreAddress = endAddress; } - ~ModuleLoader(){ + ~PluginLoader(){ } - static ModuleLoader *instance; + static PluginLoader *instance; /** \brief Iterates through the vector and delete all it's elements - \param A list of ModuleData* that should be deleted. + \param A list of PluginData* that should be deleted. **/ - void clearModuleData(std::vector moduleData); + void clearPluginData(std::vector pluginData); /** \brief Load - \param moduleInformation a ModuleInformation object of the plugin that should be linked (relocated) and loaded. + \param pluginInformation a PluginInformation object of the plugin that should be linked (relocated) and loaded. - \return NULL on error. On success it will return a ModuleData object. + \return NULL on error. On success it will return a PluginData object. **/ - ModuleData * loadAndLinkModule(ModuleInformation * moduleInformation); + PluginData * loadAndLinkPlugin(PluginInformation * pluginInformation); /** \brief Loads a plugin into memory (in the startAddress/endAddress range defined in this loader) and relocates it. - Modifies the moduleData param. Adds loaded functions and hooks. - \param moduleData object where the result should be stored + Modifies the pluginData param. Adds loaded functions and hooks. + \param pluginData object where the result should be stored \param elf source elf from where the sections will be loaded \param storeAddressEnd the address where the plugin data will be stored in memory. Saving BACKWARD. **/ - bool loadAndLinkElf(ModuleData * moduleData, Elf *elf, void * storeAddressEnd); + bool loadAndLinkElf(PluginData * pluginData, Elf *elf, void * storeAddressEnd); /** \brief Copies the needed information into a global, persistent struct. This struct holds information on which function should be override in which order and which hook should be called. - \param modules list of modules that should be used. + \param plugins list of plugins that should be used. **/ - void copyModuleDataIntoGlobalStruct(std::vector modules); + void copyPluginDataIntoGlobalStruct(std::vector plugins); void * getCurrentStoreAddress(){ return this->currentStoreAddress; diff --git a/plugins/example_plugin/src/main.cpp b/plugins/example_plugin/src/main.cpp index dee4ebd..dedbd7b 100644 --- a/plugins/example_plugin/src/main.cpp +++ b/plugins/example_plugin/src/main.cpp @@ -6,10 +6,10 @@ #include "dynamic_libs/fs_functions.h" #include "utils/logger.h" -WUPS_MODULE_NAME("test module"); -WUPS_MODULE_VERSION("v1.0"); -WUPS_MODULE_AUTHOR("Maschell"); -WUPS_MODULE_LICENSE("BSD"); +WUPS_PLUGIN_NAME("test PLUGIN"); +WUPS_PLUGIN_VERSION("v1.0"); +WUPS_PLUGIN_AUTHOR("Maschell"); +WUPS_PLUGIN_LICENSE("BSD"); INITIALIZE(args){ InitOSFunctionPointers(); diff --git a/plugins/hid_to_vpad/src/main.cpp b/plugins/hid_to_vpad/src/main.cpp index 4f810bb..0c4d216 100644 --- a/plugins/hid_to_vpad/src/main.cpp +++ b/plugins/hid_to_vpad/src/main.cpp @@ -9,10 +9,10 @@ #include #include -WUPS_MODULE_NAME("HID to VPAD lite"); -WUPS_MODULE_VERSION("v1.0"); -WUPS_MODULE_AUTHOR("Maschell"); -WUPS_MODULE_LICENSE("GPL"); +WUPS_PLUGIN_NAME("HID to VPAD lite"); +WUPS_PLUGIN_VERSION("v1.0"); +WUPS_PLUGIN_AUTHOR("Maschell"); +WUPS_PLUGIN_LICENSE("GPL"); #define SD_PATH "sd:" #define WIIU_PATH "/wiiu" diff --git a/plugins/padcon/src/main.c b/plugins/padcon/src/main.c index 931d797..ced0162 100644 --- a/plugins/padcon/src/main.c +++ b/plugins/padcon/src/main.c @@ -5,10 +5,10 @@ #include "dynamic_libs/socket_functions.h" #include "utils/logger.h" -WUPS_MODULE_NAME("Padcon"); -WUPS_MODULE_VERSION("v1.0"); -WUPS_MODULE_AUTHOR("Maschell"); -WUPS_MODULE_LICENSE("GPL"); +WUPS_PLUGIN_NAME("Padcon"); +WUPS_PLUGIN_VERSION("v1.0"); +WUPS_PLUGIN_AUTHOR("Maschell"); +WUPS_PLUGIN_LICENSE("GPL"); INITIALIZE(args){ diff --git a/plugins/sdcafiine/src/main.cpp b/plugins/sdcafiine/src/main.cpp index 54948a8..63de938 100644 --- a/plugins/sdcafiine/src/main.cpp +++ b/plugins/sdcafiine/src/main.cpp @@ -14,10 +14,10 @@ #include "main.h" #include "modpackSelector.h" -WUPS_MODULE_NAME("SDCaffiine lite"); -WUPS_MODULE_VERSION("v1.0"); -WUPS_MODULE_AUTHOR("Maschell"); -WUPS_MODULE_LICENSE("GPL"); +WUPS_PLUGIN_NAME("SDCaffiine lite"); +WUPS_PLUGIN_VERSION("v1.0"); +WUPS_PLUGIN_AUTHOR("Maschell"); +WUPS_PLUGIN_LICENSE("GPL"); INITIALIZE(args){ WUPS_InitFS(args); diff --git a/plugins/swipswapme/src/main.c b/plugins/swipswapme/src/main.c index a8e5208..15757b8 100644 --- a/plugins/swipswapme/src/main.c +++ b/plugins/swipswapme/src/main.c @@ -34,10 +34,10 @@ #include #include -WUPS_MODULE_NAME("SwipSwapMe"); -WUPS_MODULE_VERSION("v1.0"); -WUPS_MODULE_AUTHOR("Maschell"); -WUPS_MODULE_LICENSE("GPL"); +WUPS_PLUGIN_NAME("SwipSwapMe"); +WUPS_PLUGIN_VERSION("v1.0"); +WUPS_PLUGIN_AUTHOR("Maschell"); +WUPS_PLUGIN_LICENSE("GPL"); u8 isFirstBoot __attribute__((section(".data"))) = 1; diff --git a/wups_include/wups.h b/wups_include/wups.h index 95c7567..881a3f9 100644 --- a/wups_include/wups.h +++ b/wups_include/wups.h @@ -215,10 +215,10 @@ typedef struct wups_loader_entry_t { extern const char wups_meta_ ## id [] WUPS_SECTION("meta"); \ const char wups_meta_ ## id [] = #id "=" value -#define WUPS_MODULE_NAME(x) WUPS_META(name, x); WUPS_META(wups, "0.1") -#define WUPS_MODULE_AUTHOR(x) WUPS_META(author, x) -#define WUPS_MODULE_VERSION(x) WUPS_META(version, x) -#define WUPS_MODULE_LICENSE(x) WUPS_META(license, x) +#define WUPS_PLUGIN_NAME(x) WUPS_META(name, x); WUPS_META(wups, "0.1") +#define WUPS_PLUGIN_AUTHOR(x) WUPS_META(author, x) +#define WUPS_PLUGIN_VERSION(x) WUPS_META(version, x) +#define WUPS_PLUGIN_LICENSE(x) WUPS_META(license, x) void WUPS_InitFS(wups_loader_init_args_t* args);