diff --git a/src/entry.cpp b/src/entry.cpp index b905a17..d672f8e 100644 --- a/src/entry.cpp +++ b/src/entry.cpp @@ -80,7 +80,6 @@ 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_indexbssAddr != 0){ + DEBUG_FUNCTION_LINE("Clearing .bss section for %s. Addr: %08X size: %08X\n", curData->plugin_name, curData->bssAddr, curData->bssSize); + memset((void*)curData->bssAddr, 0, curData->bssSize); + } + if(curData->bssAddr != 0){ + DEBUG_FUNCTION_LINE("Clearin .sbss section for %s. Addr: %08X size: %08X\n", curData->plugin_name, curData->sbssAddr, curData->sbssSize); + memset((void*)curData->sbssAddr, 0, curData->sbssSize); + } + } +} + void afterLoadAndLink() { ResolveRelocations(); @@ -211,6 +224,7 @@ extern "C" void doStart(int argc, char **argv) { pluginLoader->loadAndLinkPlugins(pluginList); pluginLoader->clearPluginInformation(pluginList); delete pluginLoader; + clearBSS(); afterLoadAndLink(); } else { DEBUG_FUNCTION_LINE("Mapping was already done\n"); @@ -223,6 +237,8 @@ extern "C" void doStart(int argc, char **argv) { //MemoryMapping::readTestValuesFromMemory(); } + clearBSS(); + if(gbl_to_link_and_load_data[0].name[0] != 0) { ResolveRelocations(); CallHook(WUPS_LOADER_HOOK_DEINIT_PLUGIN); @@ -242,10 +258,13 @@ extern "C" void doStart(int argc, char **argv) { pluginLoader->loadAndLinkPlugins(pluginList); pluginLoader->clearPluginInformation(pluginList); delete pluginLoader; + clearBSS(); afterLoadAndLink(); memset(gbl_to_link_and_load_data,0, sizeof(gbl_to_link_and_load_data)); } + + ResolveRelocations(); MemoryUtils::init(); diff --git a/src/patcher/function_patcher.h b/src/patcher/function_patcher.h index 3e17ea2..ccbd0c8 100644 --- a/src/patcher/function_patcher.h +++ b/src/patcher/function_patcher.h @@ -72,6 +72,10 @@ struct replacement_data_plugin_t { replacement_data_hook_t hooks[MAXIMUM_HOOKS_PER_PLUGIN]; // Replacement information for each function. bool kernel_allowed; // Allow kernel access for the plugin!?!. bool kernel_init_done; // KernelInit was done + uint32_t bssAddr; + uint32_t bssSize; + uint32_t sbssAddr; + uint32_t sbssSize; }; #define MAXIMUM_PLUGINS 32 diff --git a/src/plugin/PluginData.h b/src/plugin/PluginData.h index 20b462d..dd58ea2 100644 --- a/src/plugin/PluginData.h +++ b/src/plugin/PluginData.h @@ -82,6 +82,16 @@ public: hook_data_list.push_back(hook_data); } + void setBSSLocation(uint32_t addr, uint32_t size) { + this->bssAddr = addr; + this->bssSize = size; + } + + void setSBSSLocation(uint32_t addr, uint32_t size) { + this->sbssAddr = addr; + this->sbssSize = size; + } + std::vector getHookDataList() { return hook_data_list; } @@ -118,6 +128,22 @@ public: uint32_t getMemoryForCommonBySymbol(size_t symbol, size_t align, size_t size); + uint32_t getBSSAddr(){ + return bssAddr; + } + + uint32_t getBSSSize(){ + return bssSize; + } + + uint32_t getSBSSAddr(){ + return sbssAddr; + } + + uint32_t getSBSSSize(){ + return sbssSize; + } + private: PluginInformation * pluginInformation; @@ -127,6 +153,11 @@ private: std::vector relocation_data_list; std::vector importRPLInformation_list; + uint32_t bssAddr = 0; + uint32_t bssSize = 0; + uint32_t sbssAddr = 0; + uint32_t sbssSize = 0; + std::map memoryBySymbol; }; diff --git a/src/plugin/PluginLoader.cpp b/src/plugin/PluginLoader.cpp index 2f89aa2..c7b41ec 100644 --- a/src/plugin/PluginLoader.cpp +++ b/src/plugin/PluginLoader.cpp @@ -332,6 +332,11 @@ bool PluginLoader::loadAndLinkElf(PluginData * pluginData, Elf *elf, void * star } ElfTools::elfLoadSymbols(elf_ndxscn(scn), (void*) firstCurAddress, symtab, symtab_count); + if(strcmp(name, ".bss") == 0){ + pluginData->setBSSLocation(destination, shdr->sh_size); + DEBUG_FUNCTION_LINE("Saved .bss section info. Location: %08X size: %08X\n", destination, shdr->sh_size); + } + curAddress = ROUNDUP(destination + shdr->sh_size,0x100); } } @@ -448,8 +453,6 @@ void PluginLoader::copyPluginDataIntoGlobalStruct(std::vector plug } // Other - - std::vector function_data_list = cur_plugin->getFunctionDataList(); std::vector hook_data_list = cur_plugin->getHookDataList(); if(plugin_index >= MAXIMUM_PLUGINS ) { @@ -471,6 +474,11 @@ void PluginLoader::copyPluginDataIntoGlobalStruct(std::vector plug plugin_data->kernel_allowed = true; plugin_data->kernel_init_done = false; + plugin_data->bssAddr = cur_plugin->getBSSAddr(); + plugin_data->bssSize = cur_plugin->getBSSSize(); + plugin_data->sbssAddr = cur_plugin->getSBSSAddr(); + plugin_data->sbssSize = cur_plugin->getSBSSSize(); + strncpy(plugin_data->plugin_name,cur_pluginInformation->getName().c_str(),MAXIMUM_PLUGIN_NAME_LENGTH-1); strncpy(plugin_data->path,cur_pluginInformation->getPath().c_str(),MAXIMUM_PLUGIN_PATH_NAME_LENGTH-1);