Formatting

This commit is contained in:
Maschell 2021-09-23 18:38:29 +02:00
parent 30d7e3b7bd
commit 4542bc4d1a
21 changed files with 99 additions and 73 deletions

View File

@ -60,14 +60,16 @@ dyn_linking_import_t *DynamicLinkingHelper::getOrAddImport(dyn_linking_relocatio
return result; 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(), return addRelocationEntry(linking_data, linking_entries, linking_entry_length, relocationData.getType(),
relocationData.getOffset(), relocationData.getAddend(), relocationData.getDestination(), relocationData.getOffset(), relocationData.getAddend(), relocationData.getDestination(),
relocationData.getName(), relocationData.getName(),
relocationData.getImportRPLInformation()); 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, 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) { const std::string &name, const ImportRPLInformation &rplInfo) {
dyn_linking_import_t *importInfoGbl = DynamicLinkingHelper::getOrAddImport(linking_data, rplInfo.getName().c_str(), rplInfo.isData()); dyn_linking_import_t *importInfoGbl = DynamicLinkingHelper::getOrAddImport(linking_data, rplInfo.getName().c_str(), rplInfo.isData());
if (importInfoGbl == nullptr) { if (importInfoGbl == nullptr) {
@ -85,7 +87,8 @@ bool DynamicLinkingHelper::addRelocationEntry(dyn_linking_relocation_data_t *lin
importInfoGbl); 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) { dyn_linking_import_t *importInfo) {
for (uint32_t i = 0; i < linking_entry_length; i++) { for (uint32_t i = 0; i < linking_entry_length; i++) {
dyn_linking_relocation_entry_t *curEntry = &(linking_entries[i]); dyn_linking_relocation_entry_t *curEntry = &(linking_entries[i]);

View File

@ -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, 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, 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); const ImportRPLInformation &rplInfo);
static bool 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: private:
DynamicLinkingHelper() = default; DynamicLinkingHelper() = default;

View File

@ -4,7 +4,8 @@
#include "ElfUtils.h" #include "ElfUtils.h"
// See https://github.com/decaf-emu/decaf-emu/blob/43366a34e7b55ab9d19b2444aeb0ccd46ac77dea/src/libdecaf/src/cafe/loader/cafe_loader_reloc.cpp#L144 // 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) { if (type == R_PPC_NONE) {
return true; return true;
} }

View File

@ -42,5 +42,6 @@ extern "C" {
class ElfUtils { class ElfUtils {
public: 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);
}; };

View File

@ -35,19 +35,16 @@ static volatile int log_lock __attribute__((section(".data"))) = 0;
typedef uint16_t sa_family_t; typedef uint16_t sa_family_t;
struct in_addr struct in_addr {
{
unsigned int s_addr; unsigned int s_addr;
}; };
struct sockaddr struct sockaddr {
{
sa_family_t sa_family; sa_family_t sa_family;
char sa_data[]; char sa_data[];
}; };
struct sockaddr_in struct sockaddr_in {
{
unsigned short sin_family; unsigned short sin_family;
unsigned short sin_port; unsigned short sin_port;
struct in_addr sin_addr; struct in_addr sin_addr;
@ -57,9 +54,13 @@ struct sockaddr_in
typedef uint32_t socklen_t; typedef uint32_t socklen_t;
extern int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen); 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 socket(int domain, int type, int protocol);
extern int socketclose(int sockfd); 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 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); extern uint32_t htonl(uint32_t val);
void log_init() { void log_init() {

View File

@ -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 // 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) { if (type == R_PPC_NONE) {
return true; return true;
} }

View File

@ -47,5 +47,6 @@ uint32_t load_loader_elf(unsigned char *baseAddress, char *elf_data, uint32_t fi
class ElfUtils { class ElfUtils {
public: 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);
}; };

View File

@ -1,4 +1,5 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint>
#include <wums/defines/module_defines.h> #include <wums/defines/module_defines.h>

View File

@ -83,7 +83,8 @@ int main(int argc, char **argv) {
uint32_t destination_address = ((uint32_t) gModuleData + (sizeof(module_information_t) + 0x0000FFFF)) & 0xFFFF0000; uint32_t destination_address = ((uint32_t) gModuleData + (sizeof(module_information_t) + 0x0000FFFF)) & 0xFFFF0000;
memset((void *) gModuleData, 0, sizeof(module_information_t)); memset((void *) gModuleData, 0, sizeof(module_information_t));
DEBUG_FUNCTION_LINE("Trying to run %s", setupModules.GetFilepath(i)); 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) { if (!moduleData) {
DEBUG_FUNCTION_LINE("Failed to load %s", setupModules.GetFilepath(i)); DEBUG_FUNCTION_LINE("Failed to load %s", setupModules.GetFilepath(i));
continue; continue;
@ -117,7 +118,8 @@ int main(int argc, char **argv) {
uint32_t destination_address = ((uint32_t) gModuleData + (sizeof(module_information_t) + 0x0000FFFF)) & 0xFFFF0000; uint32_t destination_address = ((uint32_t) gModuleData + (sizeof(module_information_t) + 0x0000FFFF)) & 0xFFFF0000;
for (int i = 0; i < modules.GetFilecount(); i++) { for (int i = 0; i < modules.GetFilecount(); i++) {
DEBUG_FUNCTION_LINE("Loading module %s", modules.GetFilepath(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) { if (moduleData) {
DEBUG_FUNCTION_LINE("Successfully loaded %s", modules.GetFilepath(i)); DEBUG_FUNCTION_LINE("Successfully loaded %s", modules.GetFilepath(i));

View File

@ -64,12 +64,15 @@ dyn_linking_import_t *DynamicLinkingHelper::getOrAddImport(dyn_linking_relocatio
return result; 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,
return addReloationEntry(linking_data, linking_entries, linking_entry_length, relocationData.getType(), relocationData.getOffset(), relocationData.getAddend(), relocationData.getDestination(), relocationData.getName(), const RelocationData &relocationData) {
return addReloationEntry(linking_data, linking_entries, linking_entry_length, relocationData.getType(), relocationData.getOffset(), relocationData.getAddend(), relocationData.getDestination(),
relocationData.getName(),
relocationData.getImportRPLInformation()); 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) { std::string name, const ImportRPLInformation &rplInfo) {
dyn_linking_import_t *importInfoGbl = DynamicLinkingHelper::getOrAddImport(linking_data, rplInfo.getName().c_str(), rplInfo.isData()); dyn_linking_import_t *importInfoGbl = DynamicLinkingHelper::getOrAddImport(linking_data, rplInfo.getName().c_str(), rplInfo.isData());
if (importInfoGbl == NULL) { if (importInfoGbl == NULL) {
@ -87,7 +90,8 @@ bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_data_t *link
importInfoGbl); 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) { dyn_linking_import_t *importInfo) {
for (uint32_t i = 0; i < linking_entry_length; i++) { for (uint32_t i = 0; i < linking_entry_length; i++) {
dyn_linking_relocation_entry_t *curEntry = &(linking_entries[i]); dyn_linking_relocation_entry_t *curEntry = &(linking_entries[i]);

View File

@ -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 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); const ImportRPLInformation &rplInfo);
static bool 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: private:
DynamicLinkingHelper() = default; DynamicLinkingHelper() = default;

View File

@ -141,6 +141,7 @@ public:
void setSkipEntrypoint(bool value) { void setSkipEntrypoint(bool value) {
this->skipEntrypoint = value; this->skipEntrypoint = value;
} }
void setInitBeforeRelocationDoneHook(bool value) { void setInitBeforeRelocationDoneHook(bool value) {
this->initBeforeRelocationDoneHook = value; this->initBeforeRelocationDoneHook = value;
} }

View File

@ -26,7 +26,8 @@
using namespace ELFIO; 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; elfio reader;
ModuleData moduleData; ModuleData moduleData;
@ -280,7 +281,8 @@ std::vector<RelocationData> ModuleDataFactory::getImportRelocationData(elfio &re
return result; 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(); uint32_t sec_num = reader.sections.size();
for (uint32_t i = 0; i < sec_num; ++i) { for (uint32_t i = 0; i < sec_num; ++i) {

View File

@ -26,9 +26,11 @@
class ModuleDataFactory { class ModuleDataFactory {
public: 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); static std::vector<RelocationData> getImportRelocationData(ELFIO::elfio &reader, uint8_t **destinations);
}; };

View File

@ -2,5 +2,6 @@
#include "utils/StringTools.h" #include "utils/StringTools.h"
std::string RelocationData::toString() const { 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());
} }