mirror of
https://github.com/wiiu-env/WUMSLoader.git
synced 2024-11-23 08:19:16 +01:00
Formatting
This commit is contained in:
parent
30d7e3b7bd
commit
4542bc4d1a
@ -9,7 +9,7 @@ dyn_linking_function_t *DynamicLinkingHelper::getOrAddFunctionEntryByName(dyn_li
|
||||
return nullptr;
|
||||
}
|
||||
dyn_linking_function_t *result = nullptr;
|
||||
for (auto & function : data->functions) {
|
||||
for (auto &function: data->functions) {
|
||||
dyn_linking_function_t *curEntry = &function;
|
||||
if (strlen(curEntry->functionName) == 0) {
|
||||
if (strlen(functionName) > DYN_LINK_FUNCTION_NAME_LENGTH) {
|
||||
@ -41,7 +41,7 @@ dyn_linking_import_t *DynamicLinkingHelper::getOrAddImport(dyn_linking_relocatio
|
||||
return nullptr;
|
||||
}
|
||||
dyn_linking_import_t *result = nullptr;
|
||||
for (auto & import : data->imports) {
|
||||
for (auto &import: data->imports) {
|
||||
dyn_linking_import_t *curEntry = &import;
|
||||
if (strlen(curEntry->importName) == 0) {
|
||||
if (strlen(importName) > DYN_LINK_IMPORT_NAME_LENGTH) {
|
||||
@ -60,15 +60,17 @@ dyn_linking_import_t *DynamicLinkingHelper::getOrAddImport(dyn_linking_relocatio
|
||||
return result;
|
||||
}
|
||||
|
||||
bool DynamicLinkingHelper::addRelocationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, const RelocationData &relocationData) {
|
||||
bool DynamicLinkingHelper::addRelocationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length,
|
||||
const RelocationData &relocationData) {
|
||||
return addRelocationEntry(linking_data, linking_entries, linking_entry_length, relocationData.getType(),
|
||||
relocationData.getOffset(), relocationData.getAddend(), relocationData.getDestination(),
|
||||
relocationData.getName(),
|
||||
relocationData.getImportRPLInformation());
|
||||
}
|
||||
|
||||
bool DynamicLinkingHelper::addRelocationEntry(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) {
|
||||
bool DynamicLinkingHelper::addRelocationEntry(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) {
|
||||
dyn_linking_import_t *importInfoGbl = DynamicLinkingHelper::getOrAddImport(linking_data, rplInfo.getName().c_str(), rplInfo.isData());
|
||||
if (importInfoGbl == nullptr) {
|
||||
DEBUG_FUNCTION_LINE("Getting import info failed. Probably maximum of %d rpl files to import reached.\n", DYN_LINK_IMPORT_LIST_LENGTH);
|
||||
@ -85,7 +87,8 @@ bool DynamicLinkingHelper::addRelocationEntry(dyn_linking_relocation_data_t *lin
|
||||
importInfoGbl);
|
||||
}
|
||||
|
||||
bool DynamicLinkingHelper::addRelocationEntry(dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, void *destination, dyn_linking_function_t *functionName,
|
||||
bool DynamicLinkingHelper::addRelocationEntry(dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, void *destination,
|
||||
dyn_linking_function_t *functionName,
|
||||
dyn_linking_import_t *importInfo) {
|
||||
for (uint32_t i = 0; i < linking_entry_length; i++) {
|
||||
dyn_linking_relocation_entry_t *curEntry = &(linking_entries[i]);
|
||||
|
@ -49,11 +49,14 @@ public:
|
||||
|
||||
static bool addRelocationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, const RelocationData &relocationData);
|
||||
|
||||
static bool addRelocationEntry(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
|
||||
addRelocationEntry(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
|
||||
addRelocationEntry(dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, void *destination, dyn_linking_function_t *functionName, dyn_linking_import_t *importInfo);
|
||||
addRelocationEntry(dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, void *destination,
|
||||
dyn_linking_function_t *functionName, dyn_linking_import_t *importInfo);
|
||||
|
||||
private:
|
||||
DynamicLinkingHelper() = default;
|
||||
|
@ -4,7 +4,8 @@
|
||||
#include "ElfUtils.h"
|
||||
|
||||
// See https://github.com/decaf-emu/decaf-emu/blob/43366a34e7b55ab9d19b2444aeb0ccd46ac77dea/src/libdecaf/src/cafe/loader/cafe_loader_reloc.cpp#L144
|
||||
bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, RelocationType reloc_type) {
|
||||
bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length,
|
||||
RelocationType reloc_type) {
|
||||
if (type == R_PPC_NONE) {
|
||||
return true;
|
||||
}
|
||||
|
@ -42,5 +42,6 @@ extern "C" {
|
||||
class ElfUtils {
|
||||
|
||||
public:
|
||||
static bool elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, RelocationType reloc_type);
|
||||
static bool elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length,
|
||||
RelocationType reloc_type);
|
||||
};
|
||||
|
@ -34,21 +34,21 @@ std::vector<ModuleData> ModuleDataPersistence::loadModuleData(module_information
|
||||
|
||||
moduleData.setExportName(module_data->module_export_name);
|
||||
|
||||
for (auto & export_entry : module_data->export_entries) {
|
||||
for (auto &export_entry: module_data->export_entries) {
|
||||
if (export_entry.address == 0) {
|
||||
continue;
|
||||
}
|
||||
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_entry : module_data->hook_entries) {
|
||||
for (auto &hook_entry: module_data->hook_entries) {
|
||||
if (hook_entry.target == 0) {
|
||||
continue;
|
||||
}
|
||||
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) {
|
||||
if (linking_entry.destination == nullptr) {
|
||||
break;
|
||||
}
|
||||
|
@ -43,13 +43,13 @@ extern "C" int _start(int argc, char **argv) {
|
||||
|
||||
DEBUG_FUNCTION_LINE_VERBOSE("Call real one\n");
|
||||
log_deinit();
|
||||
|
||||
|
||||
return ((int (*)(int, char **)) (*(unsigned int *) 0x1005E040))(argc, argv);
|
||||
}
|
||||
|
||||
bool doRelocation(std::vector<RelocationData> &relocData, relocation_trampolin_entry_t *tramp_data, uint32_t tramp_length, bool skipAllocReplacement) {
|
||||
std::map<std::string, OSDynLoad_Module> moduleCache;
|
||||
for (auto const &curReloc : relocData) {
|
||||
for (auto const &curReloc: relocData) {
|
||||
std::string functionName = curReloc.getName();
|
||||
std::string rplName = curReloc.getImportRPLInformation().getName();
|
||||
uint32_t functionAddress = 0;
|
||||
@ -113,7 +113,7 @@ bool doRelocation(std::vector<RelocationData> &relocData, relocation_trampolin_e
|
||||
bool ResolveRelocations(std::vector<ModuleData> &loadedModules, bool skipMemoryMappingModule) {
|
||||
bool wasSuccessful = true;
|
||||
|
||||
for (auto &curModule : loadedModules) {
|
||||
for (auto &curModule: loadedModules) {
|
||||
DEBUG_FUNCTION_LINE_VERBOSE("Let's do the relocations for %s\n", curModule.getExportName().c_str());
|
||||
if (wasSuccessful) {
|
||||
std::vector<RelocationData> relocData = curModule.getRelocationDataList();
|
||||
@ -155,7 +155,7 @@ extern "C" void doStart(int argc, char **argv) {
|
||||
std::vector<ModuleData> loadedModules = OrderModulesByDependencies(loadedModulesUnordered);
|
||||
|
||||
bool applicationEndHookLoaded = false;
|
||||
for (auto &curModule : loadedModules) {
|
||||
for (auto &curModule: loadedModules) {
|
||||
if (curModule.getExportName() == "homebrew_applicationendshook") {
|
||||
DEBUG_FUNCTION_LINE_VERBOSE("We have ApplicationEndsHook Module!\n");
|
||||
applicationEndHookLoaded = true;
|
||||
@ -164,8 +164,8 @@ extern "C" void doStart(int argc, char **argv) {
|
||||
}
|
||||
|
||||
// Make sure WUMS_HOOK_APPLICATION_ENDS and WUMS_HOOK_FINI_WUT are called
|
||||
for (auto &curModule : loadedModules) {
|
||||
for (auto &curHook : curModule.getHookDataList()) {
|
||||
for (auto &curModule: loadedModules) {
|
||||
for (auto &curHook: curModule.getHookDataList()) {
|
||||
if (curHook.getType() == WUMS_HOOK_APPLICATION_ENDS || curHook.getType() == WUMS_HOOK_FINI_WUT_DEVOPTAB) {
|
||||
if (!applicationEndHookLoaded) {
|
||||
OSFatal_printf("%s requires module homebrew_applicationendshook", curModule.getExportName().c_str());
|
||||
@ -181,7 +181,7 @@ extern "C" void doStart(int argc, char **argv) {
|
||||
DEBUG_FUNCTION_LINE_VERBOSE("Resolve relocations without replacing alloc functions\n");
|
||||
ResolveRelocations(loadedModules, true);
|
||||
|
||||
for (auto &curModule : loadedModules) {
|
||||
for (auto &curModule: loadedModules) {
|
||||
if (curModule.isInitBeforeRelocationDoneHook()) {
|
||||
CallHook(curModule, WUMS_HOOK_INIT_WUT_MALLOC);
|
||||
CallHook(curModule, WUMS_HOOK_INIT_WUT_NEWLIB);
|
||||
@ -209,7 +209,7 @@ extern "C" void doStart(int argc, char **argv) {
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &curModule : loadedModules) {
|
||||
for (auto &curModule: loadedModules) {
|
||||
if (!curModule.isInitBeforeRelocationDoneHook()) {
|
||||
CallHook(curModule, WUMS_HOOK_INIT_WUT_MALLOC);
|
||||
CallHook(curModule, WUMS_HOOK_INIT_WUT_NEWLIB);
|
||||
@ -246,7 +246,7 @@ std::vector<ModuleData> OrderModulesByDependencies(const std::vector<ModuleData>
|
||||
while (true) {
|
||||
bool canBreak = true;
|
||||
bool weDidSomething = false;
|
||||
for (auto const &curModule : loadedModules) {
|
||||
for (auto const &curModule: loadedModules) {
|
||||
if (std::find(loadedModulesEntrypoints.begin(), loadedModulesEntrypoints.end(), curModule.getEntrypoint()) != loadedModulesEntrypoints.end()) {
|
||||
// DEBUG_FUNCTION_LINE("%s [%08X] is already loaded\n", curModule.getExportName().c_str(), curModule.getEntrypoint());
|
||||
continue;
|
||||
@ -254,7 +254,7 @@ std::vector<ModuleData> OrderModulesByDependencies(const std::vector<ModuleData>
|
||||
canBreak = false;
|
||||
DEBUG_FUNCTION_LINE_VERBOSE("Check if we can load %s\n", curModule.getExportName().c_str());
|
||||
std::vector<std::string> importsFromOtherModules;
|
||||
for (const auto& curReloc: curModule.getRelocationDataList()) {
|
||||
for (const auto &curReloc: curModule.getRelocationDataList()) {
|
||||
std::string curRPL = curReloc.getImportRPLInformation().getName();
|
||||
if (curRPL.rfind("homebrew", 0) == 0) {
|
||||
if (std::find(importsFromOtherModules.begin(), importsFromOtherModules.end(), curRPL) != importsFromOtherModules.end()) {
|
||||
@ -266,7 +266,7 @@ std::vector<ModuleData> OrderModulesByDependencies(const std::vector<ModuleData>
|
||||
}
|
||||
}
|
||||
bool canLoad = true;
|
||||
for (auto &curImportRPL : importsFromOtherModules) {
|
||||
for (auto &curImportRPL: importsFromOtherModules) {
|
||||
if (std::find(loadedModulesExportNames.begin(), loadedModulesExportNames.end(), curImportRPL) != loadedModulesExportNames.end()) {
|
||||
|
||||
} else {
|
||||
|
@ -28,12 +28,12 @@ void CallHook(const std::vector<ModuleData> &modules, wums_hook_type_t type) {
|
||||
}
|
||||
|
||||
void CallHook(const ModuleData &module, wums_hook_type_t type) {
|
||||
if(!module.relocationsDone){
|
||||
if (!module.relocationsDone) {
|
||||
DEBUG_FUNCTION_LINE("Hook not called because the relocations failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto &curHook : module.getHookDataList()) {
|
||||
for (auto &curHook: module.getHookDataList()) {
|
||||
auto func_ptr = (uint32_t) curHook.getTarget();
|
||||
if (func_ptr == 0) {
|
||||
DEBUG_FUNCTION_LINE("Hook ptr was NULL\n");
|
||||
|
@ -35,31 +35,32 @@ static volatile int log_lock __attribute__((section(".data"))) = 0;
|
||||
|
||||
typedef uint16_t sa_family_t;
|
||||
|
||||
struct in_addr
|
||||
{
|
||||
unsigned int s_addr;
|
||||
struct in_addr {
|
||||
unsigned int s_addr;
|
||||
};
|
||||
|
||||
struct sockaddr
|
||||
{
|
||||
sa_family_t sa_family;
|
||||
char sa_data[];
|
||||
struct sockaddr {
|
||||
sa_family_t sa_family;
|
||||
char sa_data[];
|
||||
};
|
||||
|
||||
struct sockaddr_in
|
||||
{
|
||||
unsigned short sin_family;
|
||||
unsigned short sin_port;
|
||||
struct in_addr sin_addr;
|
||||
char sin_zero[8];
|
||||
struct sockaddr_in {
|
||||
unsigned short sin_family;
|
||||
unsigned short sin_port;
|
||||
struct in_addr sin_addr;
|
||||
char sin_zero[8];
|
||||
};
|
||||
|
||||
typedef uint32_t socklen_t;
|
||||
|
||||
extern int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen);
|
||||
|
||||
extern int socket(int domain, int type, int protocol);
|
||||
|
||||
extern int socketclose(int sockfd);
|
||||
|
||||
extern int sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen);
|
||||
|
||||
extern uint32_t htonl(uint32_t val);
|
||||
|
||||
void log_init() {
|
||||
@ -77,11 +78,11 @@ void log_init() {
|
||||
}
|
||||
|
||||
void log_deinit() {
|
||||
if (log_socket < 0){
|
||||
if (log_socket < 0) {
|
||||
return;
|
||||
}
|
||||
if(socketclose(log_socket) != 0) {
|
||||
return;
|
||||
if (socketclose(log_socket) != 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,7 +108,8 @@ uint32_t load_loader_elf(unsigned char *baseAddress, char *elf_data, uint32_t fi
|
||||
}
|
||||
|
||||
// See https://github.com/decaf-emu/decaf-emu/blob/43366a34e7b55ab9d19b2444aeb0ccd46ac77dea/src/libdecaf/src/cafe/loader/cafe_loader_reloc.cpp#L144
|
||||
bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, RelocationType reloc_type) {
|
||||
bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length,
|
||||
RelocationType reloc_type) {
|
||||
if (type == R_PPC_NONE) {
|
||||
return true;
|
||||
}
|
||||
|
@ -47,5 +47,6 @@ uint32_t load_loader_elf(unsigned char *baseAddress, char *elf_data, uint32_t fi
|
||||
class ElfUtils {
|
||||
|
||||
public:
|
||||
static bool elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, RelocationType reloc_type);
|
||||
static bool elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length,
|
||||
RelocationType reloc_type);
|
||||
};
|
||||
|
@ -1,8 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <wums/defines/module_defines.h>
|
||||
|
||||
#define MEMORY_REGION_START 0x00800000
|
||||
#define MEMORY_REGION_START 0x00800000
|
||||
#define MEMORY_REGION_SIZE 0x00800000
|
||||
|
||||
#define MEMORY_REGION_USABLE_HEAP_START (MEMORY_REGION_START + 0x00080000)
|
||||
|
@ -42,13 +42,13 @@ extern "C" uint32_t textStart();
|
||||
extern "C" void _SYSLaunchMenuWithCheckingAccount(nn::act::SlotNo slot);
|
||||
|
||||
bool doRelocation(std::vector<RelocationData> &relocData, relocation_trampolin_entry_t *tramp_data, uint32_t tramp_length) {
|
||||
for (auto const &curReloc : relocData) {
|
||||
for (auto const &curReloc: relocData) {
|
||||
std::string functionName = curReloc.getName();
|
||||
std::string rplName = curReloc.getImportRPLInformation().getName();
|
||||
int32_t isData = curReloc.getImportRPLInformation().isData();
|
||||
OSDynLoad_Module rplHandle = nullptr;
|
||||
|
||||
if(OSDynLoad_IsModuleLoaded(rplName.c_str(), &rplHandle) != OS_DYNLOAD_OK) {
|
||||
if (OSDynLoad_IsModuleLoaded(rplName.c_str(), &rplHandle) != OS_DYNLOAD_OK) {
|
||||
// only acquire if not already loaded.
|
||||
OSDynLoad_Acquire(rplName.c_str(), &rplHandle);
|
||||
}
|
||||
@ -83,7 +83,8 @@ int main(int argc, char **argv) {
|
||||
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));
|
||||
std::optional<ModuleData> moduleData = ModuleDataFactory::load(setupModules.GetFilepath(i), &destination_address, textSectionStart - destination_address, 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;
|
||||
@ -117,7 +118,8 @@ int main(int argc, char **argv) {
|
||||
uint32_t destination_address = ((uint32_t) gModuleData + (sizeof(module_information_t) + 0x0000FFFF)) & 0xFFFF0000;
|
||||
for (int i = 0; i < modules.GetFilecount(); i++) {
|
||||
DEBUG_FUNCTION_LINE("Loading module %s", modules.GetFilepath(i));
|
||||
std::optional<ModuleData> moduleData = ModuleDataFactory::load(modules.GetFilepath(i), &destination_address, MEMORY_REGION_USABLE_END - destination_address, gModuleData->trampolines, DYN_LINK_TRAMPOLIN_LIST_LENGTH);
|
||||
std::optional<ModuleData> moduleData = ModuleDataFactory::load(modules.GetFilepath(i), &destination_address, MEMORY_REGION_USABLE_END - destination_address, gModuleData->trampolines,
|
||||
DYN_LINK_TRAMPOLIN_LIST_LENGTH);
|
||||
|
||||
if (moduleData) {
|
||||
DEBUG_FUNCTION_LINE("Successfully loaded %s", modules.GetFilepath(i));
|
||||
|
@ -64,12 +64,15 @@ dyn_linking_import_t *DynamicLinkingHelper::getOrAddImport(dyn_linking_relocatio
|
||||
return result;
|
||||
}
|
||||
|
||||
bool DynamicLinkingHelper::addRelocationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, const RelocationData &relocationData) {
|
||||
return addReloationEntry(linking_data, linking_entries, linking_entry_length, relocationData.getType(), relocationData.getOffset(), relocationData.getAddend(), relocationData.getDestination(), relocationData.getName(),
|
||||
bool DynamicLinkingHelper::addRelocationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length,
|
||||
const RelocationData &relocationData) {
|
||||
return addReloationEntry(linking_data, linking_entries, linking_entry_length, relocationData.getType(), relocationData.getOffset(), relocationData.getAddend(), relocationData.getDestination(),
|
||||
relocationData.getName(),
|
||||
relocationData.getImportRPLInformation());
|
||||
}
|
||||
|
||||
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,
|
||||
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) {
|
||||
dyn_linking_import_t *importInfoGbl = DynamicLinkingHelper::getOrAddImport(linking_data, rplInfo.getName().c_str(), rplInfo.isData());
|
||||
if (importInfoGbl == NULL) {
|
||||
@ -87,7 +90,8 @@ bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_data_t *link
|
||||
importInfoGbl);
|
||||
}
|
||||
|
||||
bool DynamicLinkingHelper::addRelocationEntry(dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, void *destination, dyn_linking_function_t *functionName,
|
||||
bool DynamicLinkingHelper::addRelocationEntry(dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, void *destination,
|
||||
dyn_linking_function_t *functionName,
|
||||
dyn_linking_import_t *importInfo) {
|
||||
for (uint32_t i = 0; i < linking_entry_length; i++) {
|
||||
dyn_linking_relocation_entry_t *curEntry = &(linking_entries[i]);
|
||||
|
@ -49,11 +49,13 @@ public:
|
||||
|
||||
static bool addRelocationEntry(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, std::string name,
|
||||
const ImportRPLInformation &rplInfo);
|
||||
|
||||
static bool
|
||||
addRelocationEntry(dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, void *destination, dyn_linking_function_t *functionName, dyn_linking_import_t *importInfo);
|
||||
addRelocationEntry(dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, void *destination,
|
||||
dyn_linking_function_t *functionName, dyn_linking_import_t *importInfo);
|
||||
|
||||
private:
|
||||
DynamicLinkingHelper() = default;
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
std::string ModuleData::toString() const {
|
||||
std::string res = StringTools::strfmt("Entrypoint %08X, bss: %08X (%d), bss: %08X (%d)\n", getEntrypoint(), getBSSAddr(), getBSSSize(), getSBSSAddr(), getSBSSSize());
|
||||
for (auto const &reloc : relocation_data_list) {
|
||||
for (auto const &reloc: relocation_data_list) {
|
||||
res += reloc.toString();
|
||||
}
|
||||
return res;
|
||||
|
@ -141,6 +141,7 @@ public:
|
||||
void setSkipEntrypoint(bool value) {
|
||||
this->skipEntrypoint = value;
|
||||
}
|
||||
|
||||
void setInitBeforeRelocationDoneHook(bool value) {
|
||||
this->initBeforeRelocationDoneHook = value;
|
||||
}
|
||||
|
@ -26,7 +26,8 @@
|
||||
|
||||
using namespace ELFIO;
|
||||
|
||||
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) {
|
||||
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;
|
||||
ModuleData moduleData;
|
||||
|
||||
@ -60,7 +61,7 @@ std::optional<ModuleData> ModuleDataFactory::load(const std::string& path, uint3
|
||||
uint32_t sectionSize = psec->get_size();
|
||||
|
||||
totalSize += sectionSize;
|
||||
if(totalSize > maximum_size){
|
||||
if (totalSize > maximum_size) {
|
||||
DEBUG_FUNCTION_LINE("Couldn't load setup module because it's too big.");
|
||||
return {};
|
||||
}
|
||||
@ -131,7 +132,7 @@ std::optional<ModuleData> ModuleDataFactory::load(const std::string& path, uint3
|
||||
}
|
||||
std::vector<RelocationData> relocationData = getImportRelocationData(reader, destinations);
|
||||
|
||||
for (auto const &reloc : relocationData) {
|
||||
for (auto const &reloc: relocationData) {
|
||||
moduleData.addRelocationData(reloc);
|
||||
}
|
||||
|
||||
@ -280,7 +281,8 @@ std::vector<RelocationData> ModuleDataFactory::getImportRelocationData(elfio &re
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ModuleDataFactory::linkSection(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) {
|
||||
bool ModuleDataFactory::linkSection(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) {
|
||||
uint32_t sec_num = reader.sections.size();
|
||||
|
||||
for (uint32_t i = 0; i < sec_num; ++i) {
|
||||
|
@ -26,9 +26,11 @@
|
||||
|
||||
class ModuleDataFactory {
|
||||
public:
|
||||
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 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);
|
||||
|
||||
static std::vector<RelocationData> getImportRelocationData(ELFIO::elfio &reader, uint8_t **destinations);
|
||||
};
|
||||
|
@ -18,7 +18,7 @@ bool ModuleDataPersistence::saveModuleData(module_information_t *moduleInformati
|
||||
DEBUG_FUNCTION_LINE("Saving reloation data for module at %08X", module.getEntrypoint());
|
||||
// Relocation
|
||||
std::vector<RelocationData> relocationData = module.getRelocationDataList();
|
||||
for (auto const &reloc : relocationData) {
|
||||
for (auto const &reloc: relocationData) {
|
||||
if (!DynamicLinkingHelper::addRelocationEntry(&(moduleInformation->linking_data), module_data->linking_entries,
|
||||
DYN_LINK_RELOCATION_LIST_LENGTH, reloc)) {
|
||||
DEBUG_FUNCTION_LINE("Failed to add relocation entry\n");
|
||||
@ -27,9 +27,9 @@ bool ModuleDataPersistence::saveModuleData(module_information_t *moduleInformati
|
||||
}
|
||||
|
||||
std::vector<ExportData> exportData = module.getExportDataList();
|
||||
for (auto const &curExport : exportData) {
|
||||
for (auto const &curExport: exportData) {
|
||||
bool found = false;
|
||||
for (auto &export_entry : module_data->export_entries) {
|
||||
for (auto &export_entry: module_data->export_entries) {
|
||||
if (export_entry.address == 0) {
|
||||
export_entry.type = curExport.getType();
|
||||
export_entry.name[0] = '\0';
|
||||
@ -46,9 +46,9 @@ bool ModuleDataPersistence::saveModuleData(module_information_t *moduleInformati
|
||||
}
|
||||
|
||||
std::vector<HookData> hookData = module.getHookDataList();
|
||||
for (auto const &curHook : hookData) {
|
||||
for (auto const &curHook: hookData) {
|
||||
bool found = false;
|
||||
for (auto &hook_entry : module_data->hook_entries) {
|
||||
for (auto &hook_entry: module_data->hook_entries) {
|
||||
if (hook_entry.target == 0) {
|
||||
hook_entry.type = curHook.getType();
|
||||
hook_entry.target = (uint32_t) curHook.getTarget();
|
||||
@ -109,7 +109,7 @@ std::vector<ModuleData> ModuleDataPersistence::loadModuleData(module_information
|
||||
moduleData.setSkipEntrypoint(module_data->skipEntrypoint);
|
||||
moduleData.setInitBeforeRelocationDoneHook(module_data->initBeforeRelocationDoneHook);
|
||||
|
||||
for (auto &export_entrie : module_data->export_entries) {
|
||||
for (auto &export_entrie: module_data->export_entries) {
|
||||
export_data_t *export_entry = &export_entrie;
|
||||
if (export_entry->address == 0) {
|
||||
continue;
|
||||
@ -117,14 +117,14 @@ 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)));
|
||||
}
|
||||
|
||||
for (auto &hook_entry : module_data->hook_entries) {
|
||||
for (auto &hook_entry: module_data->hook_entries) {
|
||||
if (hook_entry.target == 0) {
|
||||
continue;
|
||||
}
|
||||
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) {
|
||||
if (linking_entry.destination == nullptr) {
|
||||
break;
|
||||
}
|
||||
|
@ -2,5 +2,6 @@
|
||||
#include "utils/StringTools.h"
|
||||
|
||||
std::string RelocationData::toString() const {
|
||||
return StringTools::strfmt("%s destination: %08X offset: %08X type: %02X addend: %d rplName: %s isData: %d \n", name.c_str(), destination, offset, type, addend, rplInfo.getName().c_str(), rplInfo.isData());
|
||||
return StringTools::strfmt("%s destination: %08X offset: %08X type: %02X addend: %d rplName: %s isData: %d \n", name.c_str(), destination, offset, type, addend, rplInfo.getName().c_str(),
|
||||
rplInfo.isData());
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public:
|
||||
sectionSize(o2.sectionSize) {
|
||||
}
|
||||
|
||||
SectionInfo& operator=(const SectionInfo& other) = default;
|
||||
SectionInfo &operator=(const SectionInfo &other) = default;
|
||||
|
||||
|
||||
virtual ~SectionInfo() = default;
|
||||
|
Loading…
Reference in New Issue
Block a user