Minor improvements

This commit is contained in:
Maschell 2020-12-01 13:06:40 +01:00
parent fe7521b8a6
commit c68e375567
5 changed files with 17 additions and 28 deletions

View File

@ -1,19 +1,16 @@
#include "DynamicLinkingHelper.h"
#include <stdio.h>
#include <string.h>
#include <vector>
#include "utils/logger.h"
#include <cstring>
dyn_linking_function_t *DynamicLinkingHelper::getOrAddFunctionEntryByName(dyn_linking_relocation_data_t *data, const char *functionName) {
if (data == NULL) {
return NULL;
if (data == nullptr) {
return nullptr;
}
if (functionName == NULL) {
return NULL;
}
dyn_linking_function_t *result = NULL;
for (int32_t i = 0; i < DYN_LINK_FUNCTION_LIST_LENGTH; i++) {
dyn_linking_function_t *curEntry = &(data->functions[i]);
for (auto & function : data->functions) {
dyn_linking_function_t *curEntry = &function;
if (strlen(curEntry->functionName) == 0) {
if (strlen(functionName) > DYN_LINK_FUNCTION_NAME_LENGTH) {
DEBUG_FUNCTION_LINE("Failed to add function name, it's too long.\n");
@ -44,8 +41,8 @@ dyn_linking_import_t *DynamicLinkingHelper::getOrAddImport(dyn_linking_relocatio
return NULL;
}
dyn_linking_import_t *result = NULL;
for (int32_t i = 0; i < DYN_LINK_IMPORT_LIST_LENGTH; i++) {
dyn_linking_import_t *curEntry = &(data->imports[i]);
for (auto & import : data->imports) {
dyn_linking_import_t *curEntry = &import;
if (strlen(curEntry->importName) == 0) {
if (strlen(importName) > DYN_LINK_IMPORT_NAME_LENGTH) {
DEBUG_FUNCTION_LINE("Failed to add Import, it's too long.\n");
@ -69,7 +66,7 @@ bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_data_t *link
}
bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, void *destination,
std::string name, const ImportRPLInformation &rplInfo) {
const std::string& name, const ImportRPLInformation &rplInfo) {
dyn_linking_import_t *importInfoGbl = DynamicLinkingHelper::getOrAddImport(linking_data, rplInfo.getName().c_str(), rplInfo.isData());
if (importInfoGbl == NULL) {
DEBUG_FUNCTION_LINE("Getting import info failed. Probably maximum of %d rpl files to import reached.\n", DYN_LINK_IMPORT_LIST_LENGTH);
@ -89,7 +86,7 @@ bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_entry_t *lin
dyn_linking_import_t *importInfo) {
for (uint32_t i = 0; i < linking_entry_length; i++) {
dyn_linking_relocation_entry_t *curEntry = &(linking_entries[i]);
if (curEntry->functionEntry != NULL) {
if (curEntry->functionEntry != nullptr) {
continue;
}
curEntry->type = type;

View File

@ -49,7 +49,7 @@ public:
static bool addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, const RelocationData &relocationData);
static bool addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, void *destination, std::string name,
static bool addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, void *destination, const std::string& name,
const ImportRPLInformation &rplInfo);
static bool

View File

@ -1,5 +1,3 @@
#include <stdio.h>
#include <string.h>
#include <coreinit/cache.h>
#include "utils/logger.h"

View File

@ -1,6 +1,5 @@
#include <wums.h>
#include "hooks.h"
#include "utils/logger.h"
#include "globals.h"
static const char **hook_names = (const char *[]) {
@ -21,7 +20,7 @@ void CallHook(const std::vector<ModuleData> &modules, wums_hook_type_t type) {
void CallHook(const ModuleData &module, wums_hook_type_t type) {
for (auto &curHook : module.getHookDataList()) {
uint32_t func_ptr = (uint32_t) curHook.getTarget();
auto func_ptr = (uint32_t) curHook.getTarget();
if (func_ptr == 0) {
DEBUG_FUNCTION_LINE("Hook ptr was NULL\n");
break;
@ -33,7 +32,7 @@ void CallHook(const ModuleData &module, wums_hook_type_t type) {
type == WUMS_HOOK_INIT_WUT ||
type == WUMS_HOOK_FINI_WUT)) {
DEBUG_FUNCTION_LINE("Calling hook of type %s [%d] %d for %s \n", hook_names[type], type, curHook.getType(), module.getExportName().c_str());
((void (*)(void)) ((uint32_t *) func_ptr))();
((void (*)()) ((uint32_t *) func_ptr))();
break;
} else if (type == WUMS_HOOK_INIT ||
type == WUMS_HOOK_RELOCATIONS_DONE) {

View File

@ -1,21 +1,16 @@
#include <stdio.h>
#include <string.h>
#include <cstring>
#include <elfio/elfio.hpp>
#include <proc_ui/procui.h>
#include <sysapp/launch.h>
#include <coreinit/foreground.h>
#include <coreinit/cache.h>
#include <coreinit/cache.h>
#include <coreinit/memorymap.h>
#include <nn/act/client_cpp.h>
#include <coreinit/dynload.h>
#include <whb/log.h>
#include <whb/log_udp.h>
#include <vector>
#include "fs/DirList.h"
#include "utils/logger.h"
#include "utils/utils.h"
#include "module/ModuleDataPersistence.h"
#include "module/ModuleDataFactory.h"
#include "ElfUtils.h"
@ -49,7 +44,7 @@ bool doRelocation(std::vector<RelocationData> &relocData, relocation_trampolin_e
std::string functionName = curReloc.getName();
std::string rplName = curReloc.getImportRPLInformation().getName();
int32_t isData = curReloc.getImportRPLInformation().isData();
OSDynLoad_Module rplHandle = 0;
OSDynLoad_Module rplHandle = nullptr;
OSDynLoad_Acquire(rplName.c_str(), &rplHandle);
uint32_t functionAddress = 0;
@ -79,10 +74,10 @@ int main(int argc, char **argv) {
setupModules.SortList();
for (int i = 0; i < setupModules.GetFilecount(); i++) {
uint32_t destination_address = ((uint32_t) gModuleData + (sizeof(module_information_t) + 0x0000FFFF)) & 0xFFFF0000;
memset((void *) gModuleData, 0, sizeof(module_information_t));
DEBUG_FUNCTION_LINE("Trying to run %s", setupModules.GetFilepath(i));
uint32_t destination_address = ((uint32_t) gModuleData + (sizeof(module_information_t) + 0x0000FFFF)) & 0xFFFF0000;
std::optional<ModuleData> moduleData = ModuleDataFactory::load(setupModules.GetFilepath(i), &destination_address, MEMORY_REGION_USABLE_END - textSectionStart, gModuleData->trampolines, DYN_LINK_TRAMPOLIN_LIST_LENGTH);
std::optional<ModuleData> moduleData = ModuleDataFactory::load(setupModules.GetFilepath(i), &destination_address, textSectionStart - destination_address, gModuleData->trampolines, DYN_LINK_TRAMPOLIN_LIST_LENGTH);
if (!moduleData) {
DEBUG_FUNCTION_LINE("Failed to load %s", setupModules.GetFilepath(i));
continue;