diff --git a/src/ElfUtils.h b/src/ElfUtils.h index a196e64..06f57af 100644 --- a/src/ElfUtils.h +++ b/src/ElfUtils.h @@ -17,7 +17,7 @@ #pragma once -#include +#include #include "common/relocation_defines.h" #ifdef __cplusplus diff --git a/src/common/dynamic_linking_defines.h b/src/common/dynamic_linking_defines.h index e81a0cb..7f5102e 100644 --- a/src/common/dynamic_linking_defines.h +++ b/src/common/dynamic_linking_defines.h @@ -17,8 +17,8 @@ #pragma once -#include -#include +#include +#include #ifdef __cplusplus extern "C" { @@ -38,21 +38,21 @@ typedef struct _dyn_linking_function_t { } dyn_linking_function_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; } dyn_linking_import_t; typedef struct _dyn_linking_relocation_entry_t { - dyn_linking_function_t *functionEntry = NULL; - dyn_linking_import_t *importEntry = NULL; + dyn_linking_function_t *functionEntry = nullptr; + dyn_linking_import_t *importEntry = nullptr; void *destination = NULL; - char type; - size_t offset; - int32_t addend; + char type{}; + size_t offset{}; + int32_t addend{}; } dyn_linking_relocation_entry_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_relocation_data_t; diff --git a/src/common/module_defines.h b/src/common/module_defines.h index 743d42b..2795c91 100644 --- a/src/common/module_defines.h +++ b/src/common/module_defines.h @@ -17,8 +17,8 @@ #pragma once -#include -#include +#include +#include #include "dynamic_linking_defines.h" #include "relocation_defines.h" diff --git a/src/kernel.cpp b/src/kernel.cpp index ac28086..abce1eb 100644 --- a/src/kernel.cpp +++ b/src/kernel.cpp @@ -15,9 +15,9 @@ * along with this program. If not, see . ****************************************************************************/ -#include -#include -#include +#include +#include +#include #include #include diff --git a/src/main.cpp b/src/main.cpp index fb64e8e..506d486 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,7 +15,7 @@ * along with this program. If not, see . ****************************************************************************/ -#include +#include #include #include #include @@ -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 bool doProcUI = (argc >= 1 && std::string(argv[0]) != "safe.rpx"); - uint64_t *cfwLaunchedWithPtr = (uint64_t *) 0x00FFFFF8; + auto *cfwLaunchedWithPtr = (uint64_t *) 0x00FFFFF8; *cfwLaunchedWithPtr = OSGetTitleID(); uint32_t ApplicationMemoryEnd; @@ -120,7 +120,7 @@ int do_start(int argc, char **argv) { 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)); moduleDataStartAddress = (moduleDataStartAddress + 0x10000) & 0xFFFF0000; @@ -182,7 +182,7 @@ int do_start(int argc, char **argv) { bool doRelocation(const std::vector &relocData, relocation_trampolin_entry_t *tramp_data, uint32_t tramp_length) { for (auto const &curReloc : relocData) { - RelocationData cur = curReloc; + const RelocationData& cur = curReloc; std::string functionName = cur.getName(); std::string rplName = cur.getImportRPLInformation().getName(); int32_t isData = cur.getImportRPLInformation().isData(); @@ -210,7 +210,7 @@ void SplashScreen(const char *message, int32_t durationInMs) { OSScreenInit(); uint32_t screen_buf0_size = OSScreenGetBufferSizeEx(SCREEN_TV); 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_DRC, (void *) (screenBuffer + screen_buf0_size)); diff --git a/src/module/ImportRPLInformation.h b/src/module/ImportRPLInformation.h index 152087f..bb3926f 100644 --- a/src/module/ImportRPLInformation.h +++ b/src/module/ImportRPLInformation.h @@ -24,13 +24,12 @@ class ImportRPLInformation { public: - ImportRPLInformation(std::string name, bool isData = false) { + explicit ImportRPLInformation(std::string name, bool isData = false) { this->name = name; this->_isData = isData; } - ~ImportRPLInformation() { - } + ~ImportRPLInformation() = default; static std::optional createImportRPLInformation(std::string rawSectionName) { std::string fimport = ".fimport_"; @@ -38,7 +37,7 @@ public: bool data = false; - std::string rplName = ""; + std::string rplName; if (rawSectionName.size() < fimport.size()) { return {}; @@ -54,11 +53,11 @@ public: return ImportRPLInformation(rplName, data); } - std::string getName() const { + [[nodiscard]] std::string getName() const { return name; } - bool isData() const { + [[nodiscard]] bool isData() const { return _isData; } diff --git a/src/module/ModuleData.h b/src/module/ModuleData.h index b726f55..002b01f 100644 --- a/src/module/ModuleData.h +++ b/src/module/ModuleData.h @@ -23,11 +23,9 @@ class ModuleData { public: - ModuleData() { - } + ModuleData() = default; - ~ModuleData() { - } + ~ModuleData() = default; void setBSSLocation(uint32_t addr, uint32_t size) { this->bssAddr = addr; @@ -47,31 +45,31 @@ public: relocation_data_list.push_back(relocation_data); } - const std::vector &getRelocationDataList() const { + [[nodiscard]] const std::vector &getRelocationDataList() const { return relocation_data_list; } - uint32_t getBSSAddr() const { + [[nodiscard]] uint32_t getBSSAddr() const { return bssAddr; } - uint32_t getBSSSize() const { + [[nodiscard]] uint32_t getBSSSize() const { return bssSize; } - uint32_t getSBSSAddr() const { + [[nodiscard]] uint32_t getSBSSAddr() const { return sbssAddr; } - uint32_t getSBSSSize() const { + [[nodiscard]] uint32_t getSBSSSize() const { return sbssSize; } - uint32_t getEntrypoint() const { + [[nodiscard]] uint32_t getEntrypoint() const { return entrypoint; } - std::string toString() const; + [[nodiscard]] std::string toString() const; private: std::vector relocation_data_list; diff --git a/src/module/ModuleDataFactory.cpp b/src/module/ModuleDataFactory.cpp index cbd02fd..d890d5d 100644 --- a/src/module/ModuleDataFactory.cpp +++ b/src/module/ModuleDataFactory.cpp @@ -37,7 +37,7 @@ std::optional ModuleDataFactory::load(const std::string &path, uint3 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; for (uint32_t i = 0; i < sec_num; ++i) { @@ -73,7 +73,7 @@ std::optional ModuleDataFactory::load(const std::string &path, uint3 if ((psec->get_type() == SHT_PROGBITS || psec->get_type() == SHT_NOBITS) && (psec->get_flags() & SHF_ALLOC)) { 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; @@ -106,10 +106,10 @@ std::optional ModuleDataFactory::load(const std::string &path, uint3 } //nextAddress = ROUNDUP(destination + sectionSize,0x100); - if (psec->get_name().compare(".bss") == 0) { + if (psec->get_name() == ".bss") { moduleData.setBSSLocation(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); DEBUG_FUNCTION_LINE("Saved %s section info. Location: %08X size: %08X", psec->get_name().c_str(), destination, sectionSize); } @@ -180,7 +180,7 @@ std::vector ModuleDataFactory::getImportRelocationData(const elf break; } - uint32_t adjusted_sym_value = (uint32_t) sym_value; + auto adjusted_sym_value = (uint32_t) sym_value; if (adjusted_sym_value < 0xC0000000) { continue; } @@ -223,7 +223,7 @@ bool ModuleDataFactory::linkSection(const elfio &reader, uint32_t section_index, 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) { adjusted_sym_value -= 0x02000000; adjusted_sym_value += base_text; diff --git a/src/module/RelocationData.h b/src/module/RelocationData.h index bef1d79..e8f2012 100644 --- a/src/module/RelocationData.h +++ b/src/module/RelocationData.h @@ -31,34 +31,33 @@ public: this->name = name; } - ~RelocationData() { - } + ~RelocationData() = default; - char getType() const { + [[nodiscard]] char getType() const { return type; } - size_t getOffset() const { + [[nodiscard]] size_t getOffset() const { return offset; } - int32_t getAddend() const { + [[nodiscard]] int32_t getAddend() const { return addend; } - void *getDestination() const { + [[nodiscard]] void *getDestination() const { return destination; } - std::string getName() const { + [[nodiscard]] std::string getName() const { return name; } - ImportRPLInformation getImportRPLInformation() const { + [[nodiscard]] ImportRPLInformation getImportRPLInformation() const { return rplInfo; } - std::string toString() const; + [[nodiscard]] std::string toString() const; private: char type;