mirror of
https://github.com/wiiu-env/WiiUPluginLoaderBackend.git
synced 2024-11-25 14:16:53 +01:00
Add .bss/.sbss clearing
This commit is contained in:
parent
69ed56522a
commit
fbb6c98314
@ -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_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);
|
||||
new_PatchInvidualMethodHooks(&gbl_replacement_data.plugin_data[plugin_index]);
|
||||
@ -122,6 +121,20 @@ void ResolveRelocations() {
|
||||
}
|
||||
}
|
||||
|
||||
void clearBSS(){
|
||||
for(int32_t plugin_index=0; plugin_index<gbl_replacement_data.number_used_plugins; plugin_index++) {
|
||||
replacement_data_plugin_t * curData = &gbl_replacement_data.plugin_data[plugin_index];
|
||||
if(curData->bssAddr != 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();
|
||||
|
@ -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
|
||||
|
@ -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<HookData *> 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<RelocationData *> relocation_data_list;
|
||||
std::vector<ImportRPLInformation *> importRPLInformation_list;
|
||||
|
||||
uint32_t bssAddr = 0;
|
||||
uint32_t bssSize = 0;
|
||||
uint32_t sbssAddr = 0;
|
||||
uint32_t sbssSize = 0;
|
||||
|
||||
std::map<size_t, uint32_t> memoryBySymbol;
|
||||
};
|
||||
|
||||
|
@ -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<PluginData *> plug
|
||||
}
|
||||
|
||||
// Other
|
||||
|
||||
|
||||
std::vector<FunctionData *> function_data_list = cur_plugin->getFunctionDataList();
|
||||
std::vector<HookData *> hook_data_list = cur_plugin->getHookDataList();
|
||||
if(plugin_index >= MAXIMUM_PLUGINS ) {
|
||||
@ -471,6 +474,11 @@ void PluginLoader::copyPluginDataIntoGlobalStruct(std::vector<PluginData *> 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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user