Implementation of InitBeforeRelocationDoneHook and SkipEntrypoint module options

This commit is contained in:
Maschell 2020-12-26 16:01:46 +01:00
parent 6e352b0085
commit 98c8de7479
5 changed files with 38 additions and 23 deletions

View File

@ -31,7 +31,8 @@ std::vector<ModuleData> ModuleDataPersistence::loadModuleData(module_information
moduleData.setEntrypoint(module_data->entrypoint);
moduleData.setStartAddress(module_data->startAddress);
moduleData.setEndAddress(module_data->endAddress);
moduleData.setInitBeforeEntrypoint(module_data->initBeforeEntrypoint);
moduleData.setSkipEntrypoint(module_data->skipEntrypoint);
moduleData.setInitBeforeRelocationDoneHook(module_data->initBeforeRelocationDoneHook);
moduleData.setExportName(module_data->module_export_name);

View File

@ -1,19 +1,16 @@
#include <vector>
#include <string>
#include <string.h>
#include <stdint.h>
#include <cstring>
#include <cstdint>
#include <coreinit/dynload.h>
#include <coreinit/cache.h>
#include <nsysnet/socket.h>
#include <coreinit/memorymap.h>
#include <map>
#include <algorithm>
#include "../../source/module/RelocationData.h"
#include "../../source/module/ModuleData.h"
#include "ModuleDataPersistence.h"
#include "ElfUtils.h"
#include "utils/logger.h"
#include "utils/dynamic.h"
#include "globals.h"
#include "hooks.h"
@ -125,24 +122,25 @@ extern "C" void doStart(int argc, char **argv) {
DEBUG_FUNCTION_LINE("Resolve relocations without replacing alloc functions\n");
ResolveRelocations(loadedModules);
DEBUG_FUNCTION_LINE("Try to call kernel init\n");
// Call init hook of kernel
for (auto &curModule : loadedModules) {
if (curModule.isInitBeforeEntrypoint()) {
if (curModule.isInitBeforeRelocationDoneHook()) {
CallHook(curModule, WUMS_HOOK_INIT);
}
}
DEBUG_FUNCTION_LINE("Relocations done\n");
CallHook(loadedModules, WUMS_HOOK_RELOCATIONS_DONE);
for (int i = 0; i < gModuleData->number_used_modules; i++) {
DEBUG_FUNCTION_LINE("About to call %08X\n", gModuleData->module_data[i].entrypoint);
int ret = ((int (*)(int, char **)) (gModuleData->module_data[i].entrypoint))(argc, argv);
DEBUG_FUNCTION_LINE("return code was %d\n", ret);
if (!gModuleData->module_data[i].skipEntrypoint) {
DEBUG_FUNCTION_LINE("About to call %08X\n", gModuleData->module_data[i].entrypoint);
int ret = ((int (*)(int, char **)) (gModuleData->module_data[i].entrypoint))(argc, argv);
DEBUG_FUNCTION_LINE("return code was %d\n", ret);
}
}
for (auto &curModule : loadedModules) {
if (!curModule.isInitBeforeEntrypoint()) {
if (!curModule.isInitBeforeRelocationDoneHook()) {
CallHook(curModule, WUMS_HOOK_INIT);
}
}
@ -152,6 +150,7 @@ extern "C" void doStart(int argc, char **argv) {
CallHook(loadedModules, WUMS_HOOK_RELOCATIONS_DONE);
}
// TODO: Implement Application ends hook
// CallHook(loadedModules, WUMS_HOOK_FINI_WUT);
// CallHook(loadedModules, WUMS_HOOK_INIT_WUT);

View File

@ -132,12 +132,19 @@ public:
return this->export_name;
}
bool isInitBeforeEntrypoint() const {
return this->initBeforeEntrypoint;
bool isSkipEntrypoint() const {
return this->skipEntrypoint;
}
void setInitBeforeEntrypoint(bool value) {
this->initBeforeEntrypoint = value;
bool isInitBeforeRelocationDoneHook() const {
return this->initBeforeRelocationDoneHook;
}
void setSkipEntrypoint(bool value) {
this->skipEntrypoint = value;
}
void setInitBeforeRelocationDoneHook(bool value) {
this->initBeforeRelocationDoneHook = value;
}
private:
@ -155,5 +162,6 @@ private:
uint32_t startAddress = 0;
uint32_t endAddress = 0;
uint32_t entrypoint = 0;
bool initBeforeEntrypoint = false;
bool skipEntrypoint = false;
bool initBeforeRelocationDoneHook = false;
};

View File

@ -189,10 +189,15 @@ std::optional<ModuleData> ModuleDataFactory::load(std::string path, uint32_t *de
if (key.compare("export_name") == 0) {
DEBUG_FUNCTION_LINE("export_name = %s", value.c_str());
moduleData.setExportName(value);
} else if (key.compare("initBeforeEntrypoint") == 0) {
} else if (key.compare("skipEntrypoint") == 0) {
if (value.compare("true") == 0) {
DEBUG_FUNCTION_LINE("initBeforeEntrypoint = %s", value.c_str());
moduleData.setInitBeforeEntrypoint(true);
DEBUG_FUNCTION_LINE("skipEntrypoint = %s", value.c_str());
moduleData.setSkipEntrypoint(true);
}
} else if (key.compare("initBeforeRelocationDoneHook") == 0) {
if (value.compare("true") == 0) {
DEBUG_FUNCTION_LINE("initBeforeRelocationDoneHook = %s", value.c_str());
moduleData.setInitBeforeRelocationDoneHook(true);
}
}
if (key.compare("wums") == 0) {

View File

@ -71,7 +71,8 @@ bool ModuleDataPersistence::saveModuleData(module_information_t *moduleInformati
module_data->startAddress = module.getStartAddress();
module_data->endAddress = module.getEndAddress();
module_data->entrypoint = module.getEntrypoint();
module_data->initBeforeEntrypoint = module.isInitBeforeEntrypoint();
module_data->skipEntrypoint = module.isSkipEntrypoint();
module_data->initBeforeRelocationDoneHook = module.isInitBeforeRelocationDoneHook();
moduleInformation->number_used_modules++;
@ -105,7 +106,8 @@ std::vector<ModuleData> ModuleDataPersistence::loadModuleData(module_information
moduleData.setStartAddress(module_data->startAddress);
moduleData.setEndAddress(module_data->endAddress);
moduleData.setExportName(module_data->module_export_name);
moduleData.setInitBeforeEntrypoint(module_data->initBeforeEntrypoint);
moduleData.setSkipEntrypoint(module_data->skipEntrypoint);
moduleData.setInitBeforeRelocationDoneHook(module_data->initBeforeRelocationDoneHook);
for (uint32_t j = 0; j < EXPORT_ENTRY_LIST_LENGTH; j++) {
export_data_t *export_entry = &(module_data->export_entries[j]);