Implement support for WUMS 0.2

This commit is contained in:
Maschell 2021-09-17 16:22:54 +02:00
parent b17b522d6b
commit 74f7b8a662
11 changed files with 118 additions and 113 deletions

View File

@ -1,5 +1,5 @@
FROM wiiuenv/devkitppc:20210414 FROM wiiuenv/devkitppc:20210917
COPY --from=wiiuenv/wiiumodulesystem:20210219 /artifacts $DEVKITPRO COPY --from=wiiuenv/wiiumodulesystem:20210917 /artifacts $DEVKITPRO
WORKDIR project WORKDIR project

View File

@ -30,7 +30,6 @@ std::vector<ModuleData> ModuleDataPersistence::loadModuleData(module_information
moduleData.setStartAddress(module_data->startAddress); moduleData.setStartAddress(module_data->startAddress);
moduleData.setEndAddress(module_data->endAddress); moduleData.setEndAddress(module_data->endAddress);
moduleData.setSkipEntrypoint(module_data->skipEntrypoint); moduleData.setSkipEntrypoint(module_data->skipEntrypoint);
moduleData.setSkipWUTInit(module_data->skipWUTInit);
moduleData.setInitBeforeRelocationDoneHook(module_data->initBeforeRelocationDoneHook); moduleData.setInitBeforeRelocationDoneHook(module_data->initBeforeRelocationDoneHook);
moduleData.setExportName(module_data->module_export_name); moduleData.setExportName(module_data->module_export_name);
@ -42,12 +41,11 @@ std::vector<ModuleData> ModuleDataPersistence::loadModuleData(module_information
moduleData.addExportData(ExportData(static_cast<wums_entry_type_t>(export_entry.type), export_entry.name, reinterpret_cast<const void *>(export_entry.address))); moduleData.addExportData(ExportData(static_cast<wums_entry_type_t>(export_entry.type), export_entry.name, reinterpret_cast<const void *>(export_entry.address)));
} }
for (auto & hook_entrie : module_data->hook_entries) { for (auto & hook_entry : module_data->hook_entries) {
hook_data_t *hook_entry = &hook_entrie; if (hook_entry.target == 0) {
if (hook_entry->target == 0) {
continue; continue;
} }
moduleData.addHookData(HookData(static_cast<wums_hook_type_t>(hook_entry->type), reinterpret_cast<const void *>(hook_entry->target))); moduleData.addHookData(HookData(static_cast<wums_hook_type_t>(hook_entry.type), reinterpret_cast<const void *>(hook_entry.target)));
} }
for (auto & linking_entry : module_data->linking_entries) { for (auto & linking_entry : module_data->linking_entries) {

View File

@ -166,7 +166,7 @@ extern "C" void doStart(int argc, char **argv) {
// Make sure WUMS_HOOK_APPLICATION_ENDS and WUMS_HOOK_FINI_WUT are called // Make sure WUMS_HOOK_APPLICATION_ENDS and WUMS_HOOK_FINI_WUT are called
for (auto &curModule : loadedModules) { for (auto &curModule : loadedModules) {
for (auto &curHook : curModule.getHookDataList()) { for (auto &curHook : curModule.getHookDataList()) {
if (curHook.getType() == WUMS_HOOK_APPLICATION_ENDS || curHook.getType() == WUMS_HOOK_FINI_WUT) { if (curHook.getType() == WUMS_HOOK_APPLICATION_ENDS || curHook.getType() == WUMS_HOOK_FINI_WUT_DEVOPTAB) {
if (!applicationEndHookLoaded) { if (!applicationEndHookLoaded) {
OSFatal_printf("%s requires module homebrew_applicationendshook", curModule.getExportName().c_str()); OSFatal_printf("%s requires module homebrew_applicationendshook", curModule.getExportName().c_str());
} }
@ -183,9 +183,17 @@ extern "C" void doStart(int argc, char **argv) {
for (auto &curModule : loadedModules) { for (auto &curModule : loadedModules) {
if (curModule.isInitBeforeRelocationDoneHook()) { if (curModule.isInitBeforeRelocationDoneHook()) {
CallHook(loadedModules, WUMS_HOOK_INIT_WUT); CallHook(curModule, WUMS_HOOK_INIT_WUT_MALLOC);
CallHook(curModule, WUMS_HOOK_INIT_WUT_NEWLIB);
CallHook(curModule, WUMS_HOOK_INIT_WUT_STDCPP);
CallHook(curModule, WUMS_HOOK_INIT_WUT_DEVOPTAB);
CallHook(curModule, WUMS_HOOK_INIT_WUT_SOCKETS);
CallHook(curModule, WUMS_HOOK_INIT); CallHook(curModule, WUMS_HOOK_INIT);
CallHook(loadedModules, WUMS_HOOK_FINI_WUT); CallHook(curModule, WUMS_HOOK_FINI_WUT_SOCKETS);
CallHook(curModule, WUMS_HOOK_FINI_WUT_DEVOPTAB);
CallHook(curModule, WUMS_HOOK_FINI_WUT_STDCPP);
CallHook(curModule, WUMS_HOOK_FINI_WUT_NEWLIB);
CallHook(curModule, WUMS_HOOK_FINI_WUT_MALLOC);
} }
} }
@ -203,9 +211,17 @@ extern "C" void doStart(int argc, char **argv) {
for (auto &curModule : loadedModules) { for (auto &curModule : loadedModules) {
if (!curModule.isInitBeforeRelocationDoneHook()) { if (!curModule.isInitBeforeRelocationDoneHook()) {
CallHook(loadedModules, WUMS_HOOK_INIT_WUT); CallHook(curModule, WUMS_HOOK_INIT_WUT_MALLOC);
CallHook(curModule, WUMS_HOOK_INIT_WUT_NEWLIB);
CallHook(curModule, WUMS_HOOK_INIT_WUT_STDCPP);
CallHook(curModule, WUMS_HOOK_INIT_WUT_DEVOPTAB);
CallHook(curModule, WUMS_HOOK_INIT_WUT_SOCKETS);
CallHook(curModule, WUMS_HOOK_INIT); CallHook(curModule, WUMS_HOOK_INIT);
CallHook(loadedModules, WUMS_HOOK_FINI_WUT); CallHook(curModule, WUMS_HOOK_FINI_WUT_SOCKETS);
CallHook(curModule, WUMS_HOOK_FINI_WUT_DEVOPTAB);
CallHook(curModule, WUMS_HOOK_FINI_WUT_STDCPP);
CallHook(curModule, WUMS_HOOK_FINI_WUT_NEWLIB);
CallHook(curModule, WUMS_HOOK_FINI_WUT_MALLOC);
} }
} }
} else { } else {
@ -213,7 +229,11 @@ extern "C" void doStart(int argc, char **argv) {
ResolveRelocations(loadedModules, false); ResolveRelocations(loadedModules, false);
CallHook(loadedModules, WUMS_HOOK_RELOCATIONS_DONE); CallHook(loadedModules, WUMS_HOOK_RELOCATIONS_DONE);
} }
CallHook(loadedModules, WUMS_HOOK_INIT_WUT); CallHook(loadedModules, WUMS_HOOK_INIT_WUT_MALLOC);
CallHook(loadedModules, WUMS_HOOK_INIT_WUT_NEWLIB);
CallHook(loadedModules, WUMS_HOOK_INIT_WUT_STDCPP);
CallHook(loadedModules, WUMS_HOOK_INIT_WUT_DEVOPTAB);
CallHook(loadedModules, WUMS_HOOK_INIT_WUT_SOCKETS);
CallHook(loadedModules, WUMS_HOOK_APPLICATION_STARTS); CallHook(loadedModules, WUMS_HOOK_APPLICATION_STARTS);
//CallHook(loadedModules, WUMS_HOOK_FINI_WUT); //CallHook(loadedModules, WUMS_HOOK_FINI_WUT);
} }

View File

@ -3,12 +3,22 @@
#include "globals.h" #include "globals.h"
static const char **hook_names = (const char *[]) { static const char **hook_names = (const char *[]) {
"WUMS_HOOK_INIT_WUT_MALLOC",
"WUMS_HOOK_FINI_WUT_MALLOC",
"WUMS_HOOK_INIT_WUT_NEWLIB",
"WUMS_HOOK_FINI_WUT_NEWLIB",
"WUMS_HOOK_INIT_WUT_STDCPP",
"WUMS_HOOK_FINI_WUT_STDCPP",
"WUMS_HOOK_INIT_WUT_DEVOPTAB",
"WUMS_HOOK_FINI_WUT_DEVOPTAB",
"WUMS_HOOK_INIT_WUT_SOCKETS",
"WUMS_HOOK_FINI_WUT_SOCKETS",
"WUMS_HOOK_INIT", "WUMS_HOOK_INIT",
"WUMS_HOOK_APPLICATION_STARTS", "WUMS_HOOK_APPLICATION_STARTS",
"WUMS_HOOK_APPLICATION_ENDS", "WUMS_HOOK_APPLICATION_ENDS",
"WUMS_HOOK_INIT_WUT", "WUMS_HOOK_RELOCATIONS_DONE",
"WUMS_HOOK_FINI_WUT", "WUMS_HOOK_APPLICATION_REQUESTS_EXI"};
"WUMS_HOOK_RELOCATIONS_DONE"};
void CallHook(const std::vector<ModuleData> &modules, wums_hook_type_t type) { void CallHook(const std::vector<ModuleData> &modules, wums_hook_type_t type) {
DEBUG_FUNCTION_LINE_VERBOSE("Calling hook of type %s [%d] for all modules\n", hook_names[type], type); DEBUG_FUNCTION_LINE_VERBOSE("Calling hook of type %s [%d] for all modules\n", hook_names[type], type);
@ -23,11 +33,6 @@ void CallHook(const ModuleData &module, wums_hook_type_t type) {
return; return;
} }
if ((type == WUMS_HOOK_INIT_WUT || type == WUMS_HOOK_FINI_WUT) && module.isSkipWUTInit()) {
DEBUG_FUNCTION_LINE_VERBOSE("Skip WUMS_HOOK_INIT_WUT/WUMS_HOOK_FINI_WUT for %s\n", module.getExportName().c_str());
return;
}
for (auto &curHook : module.getHookDataList()) { for (auto &curHook : module.getHookDataList()) {
auto func_ptr = (uint32_t) curHook.getTarget(); auto func_ptr = (uint32_t) curHook.getTarget();
if (func_ptr == 0) { if (func_ptr == 0) {
@ -38,17 +43,30 @@ void CallHook(const ModuleData &module, wums_hook_type_t type) {
if (type == curHook.getType()) { if (type == curHook.getType()) {
if ((type == WUMS_HOOK_APPLICATION_STARTS || if ((type == WUMS_HOOK_APPLICATION_STARTS ||
type == WUMS_HOOK_APPLICATION_ENDS || type == WUMS_HOOK_APPLICATION_ENDS ||
type == WUMS_HOOK_INIT_WUT || type == WUMS_HOOK_INIT_WUT_MALLOC ||
type == WUMS_HOOK_FINI_WUT)) { type == WUMS_HOOK_FINI_WUT_MALLOC ||
DEBUG_FUNCTION_LINE_VERBOSE("Calling hook of type %s [%d] %d for %s \n", hook_names[type], type, curHook.getType(), module.getExportName().c_str()); type == WUMS_HOOK_INIT_WUT_NEWLIB ||
type == WUMS_HOOK_FINI_WUT_NEWLIB ||
type == WUMS_HOOK_INIT_WUT_STDCPP ||
type == WUMS_HOOK_FINI_WUT_STDCPP ||
type == WUMS_HOOK_INIT_WUT_DEVOPTAB ||
type == WUMS_HOOK_FINI_WUT_DEVOPTAB ||
type == WUMS_HOOK_INIT_WUT_SOCKETS ||
type == WUMS_HOOK_FINI_WUT_SOCKETS
)) {
DEBUG_FUNCTION_LINE_VERBOSE("Calling hook of type %s [%d] %d for %s: %08X\n", hook_names[type], type, curHook.getType(), module.getExportName().c_str(), curHook.getTarget());
((void (*)()) ((uint32_t *) func_ptr))(); ((void (*)()) ((uint32_t *) func_ptr))();
break; break;
} else if (type == WUMS_HOOK_INIT || } else if (type == WUMS_HOOK_INIT ||
type == WUMS_HOOK_RELOCATIONS_DONE) { type == WUMS_HOOK_RELOCATIONS_DONE) {
DEBUG_FUNCTION_LINE_VERBOSE("Calling hook of type %s [%d] %d for %s\n", hook_names[type], type, curHook.getType(), module.getExportName().c_str(), gModuleData); DEBUG_FUNCTION_LINE_VERBOSE("Calling hook of type %s [%d] %d for %s: %08X\n", hook_names[type], type, curHook.getType(), module.getExportName().c_str(), curHook.getTarget());
wums_app_init_args_t args; wums_app_init_args_t args;
args.module_information = gModuleData; args.module_information = gModuleData;
((void (*)(wums_app_init_args_t *)) ((uint32_t *) func_ptr))(&args); ((void (*)(wums_app_init_args_t *)) ((uint32_t *) func_ptr))(&args);
} else {
DEBUG_FUNCTION_LINE("#########################################\n");
DEBUG_FUNCTION_LINE("#########HOOK NOT IMPLEMENTED %d#########\n", type);
DEBUG_FUNCTION_LINE("#########################################\n");
} }
break; break;
} }

View File

@ -28,7 +28,9 @@ void OSFatal_printf(const char *format, ...);
log_printf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ log_printf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} while (0) } while (0)
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while(0) #define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...)do { \
log_printf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} while (0)
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -138,10 +138,6 @@ public:
return this->initBeforeRelocationDoneHook; return this->initBeforeRelocationDoneHook;
} }
[[nodiscard]] bool isSkipWUTInit() const {
return this->skipWUTInit;
}
void setSkipEntrypoint(bool value) { void setSkipEntrypoint(bool value) {
this->skipEntrypoint = value; this->skipEntrypoint = value;
} }
@ -149,10 +145,6 @@ public:
this->initBeforeRelocationDoneHook = value; this->initBeforeRelocationDoneHook = value;
} }
void setSkipWUTInit(bool value) {
this->skipWUTInit = value;
}
bool relocationsDone = false; bool relocationsDone = false;
private: private:
std::vector<RelocationData> relocation_data_list; std::vector<RelocationData> relocation_data_list;
@ -171,5 +163,4 @@ private:
uint32_t entrypoint = 0; uint32_t entrypoint = 0;
bool skipEntrypoint = false; bool skipEntrypoint = false;
bool initBeforeRelocationDoneHook = false; bool initBeforeRelocationDoneHook = false;
bool skipWUTInit = false;
}; };

View File

@ -21,16 +21,12 @@
#include <coreinit/cache.h> #include <coreinit/cache.h>
#include <wums.h> #include <wums.h>
#include "ModuleDataFactory.h" #include "ModuleDataFactory.h"
#include "elfio/elfio.hpp"
#include "utils/utils.h" #include "utils/utils.h"
#include "ElfUtils.h" #include "ElfUtils.h"
#include "SectionInfo.h"
#include "ExportData.h"
#include "HookData.h"
using namespace ELFIO; using namespace ELFIO;
std::optional<ModuleData> ModuleDataFactory::load(std::string path, uint32_t *destination_address_ptr, uint32_t maximum_size, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length) { std::optional<ModuleData> ModuleDataFactory::load(const std::string& path, uint32_t *destination_address_ptr, uint32_t maximum_size, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length) {
elfio reader; elfio reader;
ModuleData moduleData; ModuleData moduleData;
@ -42,7 +38,7 @@ std::optional<ModuleData> ModuleDataFactory::load(std::string path, uint32_t *de
uint32_t sec_num = reader.sections.size(); uint32_t sec_num = reader.sections.size();
uint8_t **destinations = (uint8_t **) malloc(sizeof(uint8_t *) * sec_num); auto **destinations = (uint8_t **) malloc(sizeof(uint8_t *) * sec_num);
uint32_t baseOffset = *destination_address_ptr; uint32_t baseOffset = *destination_address_ptr;
@ -69,7 +65,7 @@ std::optional<ModuleData> ModuleDataFactory::load(std::string path, uint32_t *de
return {}; return {};
} }
uint32_t address = (uint32_t) psec->get_address(); auto address = (uint32_t) psec->get_address();
destinations[psec->get_index()] = (uint8_t *) baseOffset; destinations[psec->get_index()] = (uint8_t *) baseOffset;
@ -102,18 +98,17 @@ std::optional<ModuleData> ModuleDataFactory::load(std::string path, uint32_t *de
} }
//nextAddress = ROUNDUP(destination + sectionSize,0x100); //nextAddress = ROUNDUP(destination + sectionSize,0x100);
if (psec->get_name().compare(".bss") == 0) { if (psec->get_name() == ".bss") {
moduleData.setBSSLocation(destination, sectionSize); moduleData.setBSSLocation(destination, sectionSize);
DEBUG_FUNCTION_LINE("Saved %s section info. Location: %08X size: %08X", psec->get_name().c_str(), destination, sectionSize); memset(reinterpret_cast<void *>(destination), 0, sectionSize);
} else if (psec->get_name().compare(".sbss") == 0) { } else if (psec->get_name() == ".sbss") {
moduleData.setSBSSLocation(destination, sectionSize); moduleData.setSBSSLocation(destination, sectionSize);
DEBUG_FUNCTION_LINE("Saved %s section info. Location: %08X size: %08X", psec->get_name().c_str(), destination, sectionSize); memset(reinterpret_cast<void *>(destination), 0, sectionSize);
} }
moduleData.addSectionInfo(SectionInfo(psec->get_name(), destination, sectionSize)); moduleData.addSectionInfo(SectionInfo(psec->get_name(), destination, sectionSize));
DEBUG_FUNCTION_LINE("Saved %s section info. Location: %08X size: %08X", psec->get_name().c_str(), destination, sectionSize); DEBUG_FUNCTION_LINE("Saved %s section info. Location: %08X size: %08X", psec->get_name().c_str(), destination, sectionSize);
if (endAddress < destination + sectionSize) { if (endAddress < destination + sectionSize) {
endAddress = destination + sectionSize; endAddress = destination + sectionSize;
} }
@ -143,8 +138,8 @@ std::optional<ModuleData> ModuleDataFactory::load(std::string path, uint32_t *de
std::optional<SectionInfo> secInfo = moduleData.getSectionInfo(".wums.exports"); std::optional<SectionInfo> secInfo = moduleData.getSectionInfo(".wums.exports");
if (secInfo && secInfo->getSize() > 0) { if (secInfo && secInfo->getSize() > 0) {
size_t entries_count = secInfo->getSize() / sizeof(wums_entry_t); size_t entries_count = secInfo->getSize() / sizeof(wums_entry_t);
wums_entry_t *entries = (wums_entry_t *) secInfo->getAddress(); auto *entries = (wums_entry_t *) secInfo->getAddress();
if (entries != NULL) { if (entries != nullptr) {
for (size_t j = 0; j < entries_count; j++) { for (size_t j = 0; j < entries_count; j++) {
wums_entry_t *exp = &entries[j]; wums_entry_t *exp = &entries[j];
DEBUG_FUNCTION_LINE("Saving export of type %08X, name %s, target: %08X"/*,pluginData.getPluginInformation()->getName().c_str()*/, exp->type, exp->name, (void *) exp->address); DEBUG_FUNCTION_LINE("Saving export of type %08X, name %s, target: %08X"/*,pluginData.getPluginInformation()->getName().c_str()*/, exp->type, exp->name, (void *) exp->address);
@ -157,8 +152,8 @@ std::optional<ModuleData> ModuleDataFactory::load(std::string path, uint32_t *de
secInfo = moduleData.getSectionInfo(".wums.hooks"); secInfo = moduleData.getSectionInfo(".wums.hooks");
if (secInfo && secInfo->getSize() > 0) { if (secInfo && secInfo->getSize() > 0) {
size_t entries_count = secInfo->getSize() / sizeof(wums_hook_t); size_t entries_count = secInfo->getSize() / sizeof(wums_hook_t);
wums_hook_t *hooks = (wums_hook_t *) secInfo->getAddress(); auto *hooks = (wums_hook_t *) secInfo->getAddress();
if (hooks != NULL) { if (hooks != nullptr) {
for (size_t j = 0; j < entries_count; j++) { for (size_t j = 0; j < entries_count; j++) {
wums_hook_t *hook = &hooks[j]; wums_hook_t *hook = &hooks[j];
DEBUG_FUNCTION_LINE("Saving hook of type %08X, target: %08X"/*,pluginData.getPluginInformation()->getName().c_str()*/, hook->type, hook->target); DEBUG_FUNCTION_LINE("Saving hook of type %08X, target: %08X"/*,pluginData.getPluginInformation()->getName().c_str()*/, hook->type, hook->target);
@ -170,8 +165,8 @@ std::optional<ModuleData> ModuleDataFactory::load(std::string path, uint32_t *de
secInfo = moduleData.getSectionInfo(".wums.meta"); secInfo = moduleData.getSectionInfo(".wums.meta");
if (secInfo && secInfo->getSize() > 0) { if (secInfo && secInfo->getSize() > 0) {
wums_entry_t *entries = (wums_entry_t *) secInfo->getAddress(); auto *entries = (wums_entry_t *) secInfo->getAddress();
if (entries != NULL) { if (entries != nullptr) {
char *curEntry = (char *) secInfo->getAddress(); char *curEntry = (char *) secInfo->getAddress();
while ((uint32_t) curEntry < (uint32_t) secInfo->getAddress() + secInfo->getSize()) { while ((uint32_t) curEntry < (uint32_t) secInfo->getAddress() + secInfo->getSize()) {
@ -180,7 +175,7 @@ std::optional<ModuleData> ModuleDataFactory::load(std::string path, uint32_t *de
continue; continue;
} }
auto firstFound = std::string(curEntry).find_first_of("="); auto firstFound = std::string(curEntry).find_first_of('=');
if (firstFound != std::string::npos) { if (firstFound != std::string::npos) {
curEntry[firstFound] = '\0'; curEntry[firstFound] = '\0';
std::string key(curEntry); std::string key(curEntry);
@ -203,16 +198,8 @@ std::optional<ModuleData> ModuleDataFactory::load(std::string path, uint32_t *de
} else { } else {
moduleData.setInitBeforeRelocationDoneHook(false); moduleData.setInitBeforeRelocationDoneHook(false);
} }
} else if (key == "skipwutInit") { } else if (key == "wums") {
if (value == "true") { if (value != "0.2") {
DEBUG_FUNCTION_LINE("skipwutInit = %s", value.c_str());
moduleData.setSkipWUTInit(true);
} else {
moduleData.setSkipWUTInit(false);
}
}
if (key == "wums") {
if (value != "0.1") {
DEBUG_FUNCTION_LINE("Warning: Ignoring module - Unsupported WUMS version: %s.\n", value.c_str()); DEBUG_FUNCTION_LINE("Warning: Ignoring module - Unsupported WUMS version: %s.\n", value.c_str());
return std::nullopt; return std::nullopt;
} }
@ -314,7 +301,7 @@ bool ModuleDataFactory::linkSection(elfio &reader, uint32_t section_index, uint3
break; break;
} }
uint32_t adjusted_sym_value = (uint32_t) sym_value; auto adjusted_sym_value = (uint32_t) sym_value;
if ((adjusted_sym_value >= 0x02000000) && adjusted_sym_value < 0x10000000) { if ((adjusted_sym_value >= 0x02000000) && adjusted_sym_value < 0x10000000) {
adjusted_sym_value -= 0x02000000; adjusted_sym_value -= 0x02000000;
adjusted_sym_value += base_text; adjusted_sym_value += base_text;

View File

@ -26,7 +26,7 @@
class ModuleDataFactory { class ModuleDataFactory {
public: public:
static std::optional<ModuleData> load(std::string path, uint32_t *destination_address_ptr, uint32_t maximum_size, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length); static std::optional<ModuleData> load(const std::string& path, uint32_t *destination_address_ptr, uint32_t maximum_size, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length);
static bool linkSection(ELFIO::elfio &reader, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length); static bool linkSection(ELFIO::elfio &reader, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length);

View File

@ -28,12 +28,12 @@ bool ModuleDataPersistence::saveModuleData(module_information_t *moduleInformati
std::vector<ExportData> exportData = module.getExportDataList(); std::vector<ExportData> exportData = module.getExportDataList();
for (auto const &curExport : exportData) { for (auto const &curExport : exportData) {
bool found = false; bool found = false;
for (uint32_t j = 0; j < EXPORT_ENTRY_LIST_LENGTH; j++) { for (auto &export_entry : module_data->export_entries) {
export_data_t *export_entry = &(module_data->export_entries[j]); if (export_entry.address == 0) {
if (export_entry->address == 0) { export_entry.type = curExport.getType();
export_entry->type = curExport.getType(); export_entry.name[0] = '\0';
strncpy(export_entry->name, curExport.getName().c_str(), EXPORT_MAXIMUM_NAME_LENGTH); strncat(export_entry.name, curExport.getName().c_str(), sizeof(export_entry.name) - 1);
export_entry->address = (uint32_t) curExport.getAddress(); export_entry.address = (uint32_t) curExport.getAddress();
found = true; found = true;
break; break;
} }
@ -47,11 +47,10 @@ bool ModuleDataPersistence::saveModuleData(module_information_t *moduleInformati
std::vector<HookData> hookData = module.getHookDataList(); std::vector<HookData> hookData = module.getHookDataList();
for (auto const &curHook : hookData) { for (auto const &curHook : hookData) {
bool found = false; bool found = false;
for (uint32_t j = 0; j < HOOK_ENTRY_LIST_LENGTH; j++) { for (auto &hook_entry : module_data->hook_entries) {
hook_data_t *hook_entry = &(module_data->hook_entries[j]); if (hook_entry.target == 0) {
if (hook_entry->target == 0) { hook_entry.type = curHook.getType();
hook_entry->type = curHook.getType(); hook_entry.target = (uint32_t) curHook.getTarget();
hook_entry->target = (uint32_t) curHook.getTarget();
found = true; found = true;
break; break;
} }
@ -73,7 +72,6 @@ bool ModuleDataPersistence::saveModuleData(module_information_t *moduleInformati
module_data->entrypoint = module.getEntrypoint(); module_data->entrypoint = module.getEntrypoint();
module_data->skipEntrypoint = module.isSkipEntrypoint(); module_data->skipEntrypoint = module.isSkipEntrypoint();
module_data->initBeforeRelocationDoneHook = module.isInitBeforeRelocationDoneHook(); module_data->initBeforeRelocationDoneHook = module.isInitBeforeRelocationDoneHook();
module_data->skipWUTInit = module.isSkipWUTInit();
moduleInformation->number_used_modules++; moduleInformation->number_used_modules++;
@ -85,7 +83,7 @@ bool ModuleDataPersistence::saveModuleData(module_information_t *moduleInformati
std::vector<ModuleData> ModuleDataPersistence::loadModuleData(module_information_t *moduleInformation) { std::vector<ModuleData> ModuleDataPersistence::loadModuleData(module_information_t *moduleInformation) {
std::vector<ModuleData> result; std::vector<ModuleData> result;
if (moduleInformation == NULL) { if (moduleInformation == nullptr) {
DEBUG_FUNCTION_LINE("moduleInformation == NULL\n"); DEBUG_FUNCTION_LINE("moduleInformation == NULL\n");
return result; return result;
} }
@ -110,48 +108,38 @@ std::vector<ModuleData> ModuleDataPersistence::loadModuleData(module_information
moduleData.setSkipEntrypoint(module_data->skipEntrypoint); moduleData.setSkipEntrypoint(module_data->skipEntrypoint);
moduleData.setInitBeforeRelocationDoneHook(module_data->initBeforeRelocationDoneHook); moduleData.setInitBeforeRelocationDoneHook(module_data->initBeforeRelocationDoneHook);
for (uint32_t j = 0; j < EXPORT_ENTRY_LIST_LENGTH; j++) { for (auto &export_entrie : module_data->export_entries) {
export_data_t *export_entry = &(module_data->export_entries[j]); export_data_t *export_entry = &export_entrie;
if (export_entry->address == 0) { if (export_entry->address == 0) {
continue; continue;
} }
moduleData.addExportData(ExportData(static_cast<wums_entry_type_t>(export_entry->type), export_entry->name, reinterpret_cast<const void *>(export_entry->address))); moduleData.addExportData(ExportData(static_cast<wums_entry_type_t>(export_entry->type), export_entry->name, reinterpret_cast<const void *>(export_entry->address)));
} }
for (uint32_t j = 0; j < HOOK_ENTRY_LIST_LENGTH; j++) { for (auto &hook_entry : module_data->hook_entries) {
hook_data_t *hook_entry = &(module_data->hook_entries[j]); if (hook_entry.target == 0) {
if (hook_entry->target == 0) {
continue; continue;
} }
moduleData.addHookData(HookData(static_cast<wums_hook_type_t>(hook_entry->type), reinterpret_cast<const void *>(hook_entry->target))); moduleData.addHookData(HookData(static_cast<wums_hook_type_t>(hook_entry.type), reinterpret_cast<const void *>(hook_entry.target)));
} }
for (uint32_t j = 0; j < DYN_LINK_RELOCATION_LIST_LENGTH; j++) { for (auto &linking_entry : module_data->linking_entries) {
dyn_linking_relocation_entry_t *linking_entry = &(module_data->linking_entries[j]); if (linking_entry.destination == nullptr) {
if (linking_entry->destination == 0) {
break; break;
} }
dyn_linking_import_t *importEntry = linking_entry->importEntry; dyn_linking_import_t *importEntry = linking_entry.importEntry;
if (importEntry == NULL) { if (importEntry == nullptr) {
DEBUG_FUNCTION_LINE("importEntry was NULL, skipping relocation entry\n"); DEBUG_FUNCTION_LINE("importEntry was NULL, skipping relocation entry\n");
continue; continue;
} }
if (importEntry->importName == NULL) { dyn_linking_function_t *functionEntry = linking_entry.functionEntry;
DEBUG_FUNCTION_LINE("importEntry->importName was NULL, skipping relocation entry\n");
continue;
}
dyn_linking_function_t *functionEntry = linking_entry->functionEntry;
if (functionEntry == NULL) { if (functionEntry == nullptr) {
DEBUG_FUNCTION_LINE("functionEntry was NULL, skipping relocation entry\n"); DEBUG_FUNCTION_LINE("functionEntry was NULL, skipping relocation entry\n");
continue; continue;
} }
if (functionEntry->functionName == NULL) {
DEBUG_FUNCTION_LINE("functionEntry->functionName was NULL, skipping relocation entry\n");
continue;
}
ImportRPLInformation rplInfo(importEntry->importName, importEntry->isData); ImportRPLInformation rplInfo(importEntry->importName, importEntry->isData);
RelocationData reloc(linking_entry->type, linking_entry->offset, linking_entry->addend, linking_entry->destination, functionEntry->functionName, rplInfo); RelocationData reloc(linking_entry.type, linking_entry.offset, linking_entry.addend, linking_entry.destination, functionEntry->functionName, rplInfo);
moduleData.addRelocationData(reloc); moduleData.addRelocationData(reloc);
} }

View File

@ -14,6 +14,10 @@ extern "C" {
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} while (0) } while (0)
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \
WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} while (0)
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -1,9 +1,6 @@
#include <string.h> #include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <whb/log.h>
#include <malloc.h>
#include "utils/logger.h" #include "utils/logger.h"
// https://gist.github.com/ccbrown/9722406 // https://gist.github.com/ccbrown/9722406
@ -11,30 +8,30 @@ void dumpHex(const void *data, size_t size) {
char ascii[17]; char ascii[17];
size_t i, j; size_t i, j;
ascii[16] = '\0'; ascii[16] = '\0';
DEBUG_FUNCTION_LINE("0x%08X (0x0000): ", data); DEBUG_FUNCTION_LINE_WRITE("0x%08X (0x0000): ", data);
for (i = 0; i < size; ++i) { for (i = 0; i < size; ++i) {
WHBLogPrintf("%02X ", ((unsigned char *) data)[i]); WHBLogWritef("%02X ", ((unsigned char *) data)[i]);
if (((unsigned char *) data)[i] >= ' ' && ((unsigned char *) data)[i] <= '~') { if (((unsigned char *) data)[i] >= ' ' && ((unsigned char *) data)[i] <= '~') {
ascii[i % 16] = ((unsigned char *) data)[i]; ascii[i % 16] = ((unsigned char *) data)[i];
} else { } else {
ascii[i % 16] = '.'; ascii[i % 16] = '.';
} }
if ((i + 1) % 8 == 0 || i + 1 == size) { if ((i + 1) % 8 == 0 || i + 1 == size) {
WHBLogPrintf(" "); WHBLogWritef(" ");
if ((i + 1) % 16 == 0) { if ((i + 1) % 16 == 0) {
WHBLogPrintf("| %s \n", ascii); WHBLogPrintf("| %s ", ascii);
if (i + 1 < size) { if (i + 1 < size) {
DEBUG_FUNCTION_LINE("0x%08X (0x%04X); ", data + i + 1, i + 1); DEBUG_FUNCTION_LINE_WRITE("0x%08X (0x%04X); ", data + i + 1, i + 1);
} }
} else if (i + 1 == size) { } else if (i + 1 == size) {
ascii[(i + 1) % 16] = '\0'; ascii[(i + 1) % 16] = '\0';
if ((i + 1) % 16 <= 8) { if ((i + 1) % 16 <= 8) {
WHBLogPrintf(" "); WHBLogWritef(" ");
} }
for (j = (i + 1) % 16; j < 16; ++j) { for (j = (i + 1) % 16; j < 16; ++j) {
WHBLogPrintf(" "); WHBLogWritef(" ");
} }
WHBLogPrintf("| %s \n", ascii); WHBLogPrintf("| %s ", ascii);
} }
} }
} }