mirror of
https://github.com/wiiu-env/CustomRPXLoader.git
synced 2024-11-22 09:59:17 +01:00
Code cleanup
This commit is contained in:
parent
c225cc7f25
commit
ba389535a9
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <cstdint>
|
||||||
#include "common/relocation_defines.h"
|
#include "common/relocation_defines.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <cstdint>
|
||||||
#include <stddef.h>
|
#include <cstddef>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -38,21 +38,21 @@ typedef struct _dyn_linking_function_t {
|
|||||||
} dyn_linking_function_t;
|
} dyn_linking_function_t;
|
||||||
|
|
||||||
typedef struct _dyn_linking_import_t {
|
typedef struct _dyn_linking_import_t {
|
||||||
char importName[DYN_LINK_IMPORT_NAME_LENGTH + 1];
|
char importName[DYN_LINK_IMPORT_NAME_LENGTH + 1]{};
|
||||||
bool isData = false;
|
bool isData = false;
|
||||||
} dyn_linking_import_t;
|
} dyn_linking_import_t;
|
||||||
|
|
||||||
typedef struct _dyn_linking_relocation_entry_t {
|
typedef struct _dyn_linking_relocation_entry_t {
|
||||||
dyn_linking_function_t *functionEntry = NULL;
|
dyn_linking_function_t *functionEntry = nullptr;
|
||||||
dyn_linking_import_t *importEntry = NULL;
|
dyn_linking_import_t *importEntry = nullptr;
|
||||||
void *destination = NULL;
|
void *destination = NULL;
|
||||||
char type;
|
char type{};
|
||||||
size_t offset;
|
size_t offset{};
|
||||||
int32_t addend;
|
int32_t addend{};
|
||||||
} dyn_linking_relocation_entry_t;
|
} dyn_linking_relocation_entry_t;
|
||||||
|
|
||||||
typedef struct _dyn_linking_relocation_data_t {
|
typedef struct _dyn_linking_relocation_data_t {
|
||||||
dyn_linking_function_t functions[DYN_LINK_FUNCTION_LIST_LENGTH];
|
dyn_linking_function_t functions[DYN_LINK_FUNCTION_LIST_LENGTH]{};
|
||||||
dyn_linking_import_t imports[DYN_LINK_IMPORT_LIST_LENGTH];
|
dyn_linking_import_t imports[DYN_LINK_IMPORT_LIST_LENGTH];
|
||||||
} dyn_linking_relocation_data_t;
|
} dyn_linking_relocation_data_t;
|
||||||
|
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <cstdint>
|
||||||
#include <stddef.h>
|
#include <cstddef>
|
||||||
#include "dynamic_linking_defines.h"
|
#include "dynamic_linking_defines.h"
|
||||||
#include "relocation_defines.h"
|
#include "relocation_defines.h"
|
||||||
|
|
||||||
|
@ -15,9 +15,9 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <cstdint>
|
||||||
#include <stdio.h>
|
#include <cstdio>
|
||||||
#include <string.h>
|
#include <cstring>
|
||||||
#include <coreinit/cache.h>
|
#include <coreinit/cache.h>
|
||||||
#include <coreinit/memorymap.h>
|
#include <coreinit/memorymap.h>
|
||||||
|
|
||||||
|
10
src/main.cpp
10
src/main.cpp
@ -15,7 +15,7 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <cstdint>
|
||||||
#include <coreinit/cache.h>
|
#include <coreinit/cache.h>
|
||||||
#include <coreinit/dynload.h>
|
#include <coreinit/dynload.h>
|
||||||
#include <coreinit/title.h>
|
#include <coreinit/title.h>
|
||||||
@ -111,7 +111,7 @@ int do_start(int argc, char **argv) {
|
|||||||
// in this case we don't want to do any ProcUi stuff on error, only on success
|
// in this case we don't want to do any ProcUi stuff on error, only on success
|
||||||
bool doProcUI = (argc >= 1 && std::string(argv[0]) != "safe.rpx");
|
bool doProcUI = (argc >= 1 && std::string(argv[0]) != "safe.rpx");
|
||||||
|
|
||||||
uint64_t *cfwLaunchedWithPtr = (uint64_t *) 0x00FFFFF8;
|
auto *cfwLaunchedWithPtr = (uint64_t *) 0x00FFFFF8;
|
||||||
*cfwLaunchedWithPtr = OSGetTitleID();
|
*cfwLaunchedWithPtr = OSGetTitleID();
|
||||||
|
|
||||||
uint32_t ApplicationMemoryEnd;
|
uint32_t ApplicationMemoryEnd;
|
||||||
@ -120,7 +120,7 @@ int do_start(int argc, char **argv) {
|
|||||||
|
|
||||||
ApplicationMemoryEnd = (ApplicationMemoryEnd + 0x100) & 0xFFFFFF00;
|
ApplicationMemoryEnd = (ApplicationMemoryEnd + 0x100) & 0xFFFFFF00;
|
||||||
|
|
||||||
module_information_t *gModuleData = (module_information_t *) ApplicationMemoryEnd;
|
auto *gModuleData = (module_information_t *) ApplicationMemoryEnd;
|
||||||
|
|
||||||
uint32_t moduleDataStartAddress = ((uint32_t) gModuleData + sizeof(module_information_t));
|
uint32_t moduleDataStartAddress = ((uint32_t) gModuleData + sizeof(module_information_t));
|
||||||
moduleDataStartAddress = (moduleDataStartAddress + 0x10000) & 0xFFFF0000;
|
moduleDataStartAddress = (moduleDataStartAddress + 0x10000) & 0xFFFF0000;
|
||||||
@ -182,7 +182,7 @@ int do_start(int argc, char **argv) {
|
|||||||
|
|
||||||
bool doRelocation(const std::vector<RelocationData> &relocData, relocation_trampolin_entry_t *tramp_data, uint32_t tramp_length) {
|
bool doRelocation(const std::vector<RelocationData> &relocData, relocation_trampolin_entry_t *tramp_data, uint32_t tramp_length) {
|
||||||
for (auto const &curReloc : relocData) {
|
for (auto const &curReloc : relocData) {
|
||||||
RelocationData cur = curReloc;
|
const RelocationData& cur = curReloc;
|
||||||
std::string functionName = cur.getName();
|
std::string functionName = cur.getName();
|
||||||
std::string rplName = cur.getImportRPLInformation().getName();
|
std::string rplName = cur.getImportRPLInformation().getName();
|
||||||
int32_t isData = cur.getImportRPLInformation().isData();
|
int32_t isData = cur.getImportRPLInformation().isData();
|
||||||
@ -210,7 +210,7 @@ void SplashScreen(const char *message, int32_t durationInMs) {
|
|||||||
OSScreenInit();
|
OSScreenInit();
|
||||||
uint32_t screen_buf0_size = OSScreenGetBufferSizeEx(SCREEN_TV);
|
uint32_t screen_buf0_size = OSScreenGetBufferSizeEx(SCREEN_TV);
|
||||||
uint32_t screen_buf1_size = OSScreenGetBufferSizeEx(SCREEN_DRC);
|
uint32_t screen_buf1_size = OSScreenGetBufferSizeEx(SCREEN_DRC);
|
||||||
uint8_t *screenBuffer = (uint8_t *) memalign(0x100, screen_buf0_size + screen_buf1_size);
|
auto *screenBuffer = (uint8_t *) memalign(0x100, screen_buf0_size + screen_buf1_size);
|
||||||
OSScreenSetBufferEx(SCREEN_TV, (void *) screenBuffer);
|
OSScreenSetBufferEx(SCREEN_TV, (void *) screenBuffer);
|
||||||
OSScreenSetBufferEx(SCREEN_DRC, (void *) (screenBuffer + screen_buf0_size));
|
OSScreenSetBufferEx(SCREEN_DRC, (void *) (screenBuffer + screen_buf0_size));
|
||||||
|
|
||||||
|
@ -24,13 +24,12 @@
|
|||||||
class ImportRPLInformation {
|
class ImportRPLInformation {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ImportRPLInformation(std::string name, bool isData = false) {
|
explicit ImportRPLInformation(std::string name, bool isData = false) {
|
||||||
this->name = name;
|
this->name = name;
|
||||||
this->_isData = isData;
|
this->_isData = isData;
|
||||||
}
|
}
|
||||||
|
|
||||||
~ImportRPLInformation() {
|
~ImportRPLInformation() = default;
|
||||||
}
|
|
||||||
|
|
||||||
static std::optional<ImportRPLInformation> createImportRPLInformation(std::string rawSectionName) {
|
static std::optional<ImportRPLInformation> createImportRPLInformation(std::string rawSectionName) {
|
||||||
std::string fimport = ".fimport_";
|
std::string fimport = ".fimport_";
|
||||||
@ -38,7 +37,7 @@ public:
|
|||||||
|
|
||||||
bool data = false;
|
bool data = false;
|
||||||
|
|
||||||
std::string rplName = "";
|
std::string rplName;
|
||||||
|
|
||||||
if (rawSectionName.size() < fimport.size()) {
|
if (rawSectionName.size() < fimport.size()) {
|
||||||
return {};
|
return {};
|
||||||
@ -54,11 +53,11 @@ public:
|
|||||||
return ImportRPLInformation(rplName, data);
|
return ImportRPLInformation(rplName, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getName() const {
|
[[nodiscard]] std::string getName() const {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isData() const {
|
[[nodiscard]] bool isData() const {
|
||||||
return _isData;
|
return _isData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,11 +23,9 @@
|
|||||||
|
|
||||||
class ModuleData {
|
class ModuleData {
|
||||||
public:
|
public:
|
||||||
ModuleData() {
|
ModuleData() = default;
|
||||||
}
|
|
||||||
|
|
||||||
~ModuleData() {
|
~ModuleData() = default;
|
||||||
}
|
|
||||||
|
|
||||||
void setBSSLocation(uint32_t addr, uint32_t size) {
|
void setBSSLocation(uint32_t addr, uint32_t size) {
|
||||||
this->bssAddr = addr;
|
this->bssAddr = addr;
|
||||||
@ -47,31 +45,31 @@ public:
|
|||||||
relocation_data_list.push_back(relocation_data);
|
relocation_data_list.push_back(relocation_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<RelocationData> &getRelocationDataList() const {
|
[[nodiscard]] const std::vector<RelocationData> &getRelocationDataList() const {
|
||||||
return relocation_data_list;
|
return relocation_data_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t getBSSAddr() const {
|
[[nodiscard]] uint32_t getBSSAddr() const {
|
||||||
return bssAddr;
|
return bssAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t getBSSSize() const {
|
[[nodiscard]] uint32_t getBSSSize() const {
|
||||||
return bssSize;
|
return bssSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t getSBSSAddr() const {
|
[[nodiscard]] uint32_t getSBSSAddr() const {
|
||||||
return sbssAddr;
|
return sbssAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t getSBSSSize() const {
|
[[nodiscard]] uint32_t getSBSSSize() const {
|
||||||
return sbssSize;
|
return sbssSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t getEntrypoint() const {
|
[[nodiscard]] uint32_t getEntrypoint() const {
|
||||||
return entrypoint;
|
return entrypoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string toString() const;
|
[[nodiscard]] std::string toString() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<RelocationData> relocation_data_list;
|
std::vector<RelocationData> relocation_data_list;
|
||||||
|
@ -37,7 +37,7 @@ std::optional<ModuleData> ModuleDataFactory::load(const std::string &path, uint3
|
|||||||
|
|
||||||
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 sizeOfModule = 0;
|
uint32_t sizeOfModule = 0;
|
||||||
for (uint32_t i = 0; i < sec_num; ++i) {
|
for (uint32_t i = 0; i < sec_num; ++i) {
|
||||||
@ -73,7 +73,7 @@ std::optional<ModuleData> ModuleDataFactory::load(const std::string &path, uint3
|
|||||||
|
|
||||||
if ((psec->get_type() == SHT_PROGBITS || psec->get_type() == SHT_NOBITS) && (psec->get_flags() & SHF_ALLOC)) {
|
if ((psec->get_type() == SHT_PROGBITS || psec->get_type() == SHT_NOBITS) && (psec->get_flags() & SHF_ALLOC)) {
|
||||||
uint32_t sectionSize = psec->get_size();
|
uint32_t sectionSize = psec->get_size();
|
||||||
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;
|
||||||
|
|
||||||
@ -106,10 +106,10 @@ std::optional<ModuleData> ModuleDataFactory::load(const std::string &path, uint3
|
|||||||
}
|
}
|
||||||
|
|
||||||
//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);
|
DEBUG_FUNCTION_LINE("Saved %s section info. Location: %08X size: %08X", psec->get_name().c_str(), destination, 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);
|
DEBUG_FUNCTION_LINE("Saved %s section info. Location: %08X size: %08X", psec->get_name().c_str(), destination, sectionSize);
|
||||||
}
|
}
|
||||||
@ -180,7 +180,7 @@ std::vector<RelocationData> ModuleDataFactory::getImportRelocationData(const elf
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t adjusted_sym_value = (uint32_t) sym_value;
|
auto adjusted_sym_value = (uint32_t) sym_value;
|
||||||
if (adjusted_sym_value < 0xC0000000) {
|
if (adjusted_sym_value < 0xC0000000) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -223,7 +223,7 @@ bool ModuleDataFactory::linkSection(const elfio &reader, uint32_t section_index,
|
|||||||
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;
|
||||||
|
@ -31,34 +31,33 @@ public:
|
|||||||
this->name = name;
|
this->name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
~RelocationData() {
|
~RelocationData() = default;
|
||||||
}
|
|
||||||
|
|
||||||
char getType() const {
|
[[nodiscard]] char getType() const {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t getOffset() const {
|
[[nodiscard]] size_t getOffset() const {
|
||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t getAddend() const {
|
[[nodiscard]] int32_t getAddend() const {
|
||||||
return addend;
|
return addend;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *getDestination() const {
|
[[nodiscard]] void *getDestination() const {
|
||||||
return destination;
|
return destination;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getName() const {
|
[[nodiscard]] std::string getName() const {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImportRPLInformation getImportRPLInformation() const {
|
[[nodiscard]] ImportRPLInformation getImportRPLInformation() const {
|
||||||
return rplInfo;
|
return rplInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string toString() const;
|
[[nodiscard]] std::string toString() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char type;
|
char type;
|
||||||
|
Loading…
Reference in New Issue
Block a user