diff --git a/src/ElfUtils.h b/src/ElfUtils.h index 11182e6..a196e64 100644 --- a/src/ElfUtils.h +++ b/src/ElfUtils.h @@ -24,10 +24,6 @@ extern "C" { #endif -int32_t LoadFileToMem(const char *relativefilepath, char **fileOut, uint32_t *sizeOut); -uint32_t load_loader_elf_from_sd(unsigned char *baseAddress, const char *relativePath); -uint32_t load_loader_elf(unsigned char *baseAddress, char *elf_data, uint32_t fileSize); - #define R_PPC_NONE 0 #define R_PPC_ADDR32 1 #define R_PPC_ADDR16_LO 4 diff --git a/src/main.cpp b/src/main.cpp index 9109baf..9559e44 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -31,11 +31,9 @@ #include #include -#include "main.h" #include "kernel.h" #include "dynamic.h" #include "utils/logger.h" -#include "utils/utils.h" bool doRelocation(std::vector &relocData, relocation_trampolin_entry_t *tramp_data, uint32_t tramp_length); diff --git a/src/main.h b/src/main.h deleted file mode 100644 index 6449b0d..0000000 --- a/src/main.h +++ /dev/null @@ -1,16 +0,0 @@ -//Main.h -#ifndef _MAIN_H_ -#define _MAIN_H_ - - -/* Main */ -#ifdef __cplusplus -extern "C" { -#endif - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/module/DynamicLinkingHelper.cpp b/src/module/DynamicLinkingHelper.cpp deleted file mode 100644 index b30328d..0000000 --- a/src/module/DynamicLinkingHelper.cpp +++ /dev/null @@ -1,107 +0,0 @@ -#include "DynamicLinkingHelper.h" -#include -#include -#include -#include -#include "utils/logger.h" -#include "common/module_defines.h" - -dyn_linking_function_t *DynamicLinkingHelper::getOrAddFunctionEntryByName(dyn_linking_relocation_data_t *data, const char *functionName) { - if (data == NULL) { - return NULL; - } - 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]); - 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."); - return NULL; - } - strncpy(curEntry->functionName, functionName, DYN_LINK_FUNCTION_NAME_LENGTH); - result = curEntry; - break; - } - if (strncmp(curEntry->functionName, functionName, DYN_LINK_FUNCTION_NAME_LENGTH) == 0) { - result = curEntry; - break; - } - } - return result; -} - -dyn_linking_import_t *DynamicLinkingHelper::getOrAddFunctionImportByName(dyn_linking_relocation_data_t *data, const char *importName) { - return getOrAddImport(data, importName, false); -} - -dyn_linking_import_t *DynamicLinkingHelper::getOrAddDataImportByName(dyn_linking_relocation_data_t *data, const char *importName) { - return getOrAddImport(data, importName, true); -} - -dyn_linking_import_t *DynamicLinkingHelper::getOrAddImport(dyn_linking_relocation_data_t *data, const char *importName, bool isData) { - if (importName == NULL || data == NULL) { - 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]); - if (strlen(curEntry->importName) == 0) { - if (strlen(importName) > DYN_LINK_IMPORT_NAME_LENGTH) { - DEBUG_FUNCTION_LINE("Failed to add Import, it's too long."); - return NULL; - } - strncpy(curEntry->importName, importName, DYN_LINK_IMPORT_NAME_LENGTH); - curEntry->isData = isData; - result = curEntry; - break; - } - if (strncmp(curEntry->importName, importName, DYN_LINK_IMPORT_NAME_LENGTH) == 0 && (curEntry->isData == isData)) { - return curEntry; - } - } - return result; -} - -bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, 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, - std::string name, 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.", DYN_LINK_IMPORT_LIST_LENGTH); - return false; - } - - dyn_linking_function_t *functionInfo = DynamicLinkingHelper::getOrAddFunctionEntryByName(linking_data, name.c_str()); - if (functionInfo == NULL) { - DEBUG_FUNCTION_LINE("Getting import info failed. Probably maximum of %d function to be relocated reached.", DYN_LINK_FUNCTION_LIST_LENGTH); - return false; - } - - return addReloationEntry(linking_entries, linking_entry_length, type, offset, addend, destination, functionInfo, importInfoGbl); -} - -bool DynamicLinkingHelper::addReloationEntry(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]); - if (curEntry->functionEntry != NULL) { - continue; - } - curEntry->type = type; - curEntry->offset = offset; - curEntry->addend = addend; - curEntry->destination = destination; - curEntry->functionEntry = functionName; - curEntry->importEntry = importInfo; - - return true; - } - return false; -} diff --git a/src/module/DynamicLinkingHelper.h b/src/module/DynamicLinkingHelper.h deleted file mode 100644 index 0d999f7..0000000 --- a/src/module/DynamicLinkingHelper.h +++ /dev/null @@ -1,64 +0,0 @@ -#pragma once - -#include "common/dynamic_linking_defines.h" -#include "utils/logger.h" -#include -#include -#include "RelocationData.h" - -class DynamicLinkingHelper { -public: - /** - Gets the function entry for a given function name. If the function name is not present in the list, it will be added. - - \param functionName Name of the function - \return Returns a pointer to the entry which contains the functionName. Null on error or if the list full. - **/ - static dyn_linking_function_t *getOrAddFunctionEntryByName(dyn_linking_relocation_data_t *data, const char *functionName); - - /** - Gets the function import entry for a given function name. If the import is not present in the list, it will be added. - This will return entries for _function_ imports. - - \param importName Name of the function - \return Returns a pointer to the function import entry which contains the importName. Null on error or if the list full. - **/ - static dyn_linking_import_t *getOrAddFunctionImportByName(dyn_linking_relocation_data_t *data, const char *importName); - - - /** - Gets the data import entry for a given data name. If the import is not present in the list, it will be added. - This will return entries for _data_ imports. - - \param importName Name of the data - \return Returns a pointer to the data import entry which contains the importName. Null on error or if the list full. - **/ - static dyn_linking_import_t *getOrAddDataImportByName(dyn_linking_relocation_data_t *data, const char *importName); - - - /** - Gets the import entry for a given data name and type. If the import is not present in the list, it will be added. - This will return entries for _data_ and _function_ imports, depending on the isData parameter. - - \param importName Name of the data - \param isData Set this to true to return a data import - - \return Returns a pointer to the data import entry which contains the importName. Null on error or if the list full. - **/ - static dyn_linking_import_t *getOrAddImport(dyn_linking_relocation_data_t *data, const char *importName, bool isData); - - static bool addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, 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, - ImportRPLInformation *rplInfo); - - static bool - addReloationEntry(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() { - } - - ~DynamicLinkingHelper() { - } -}; diff --git a/src/module/ModuleDataFactory.cpp b/src/module/ModuleDataFactory.cpp index 232d96a..edb0a6f 100644 --- a/src/module/ModuleDataFactory.cpp +++ b/src/module/ModuleDataFactory.cpp @@ -21,7 +21,6 @@ #include #include "ModuleDataFactory.h" #include "elfio/elfio.hpp" -#include "utils/utils.h" #include "../ElfUtils.h" using namespace ELFIO; diff --git a/src/utils/utils.c b/src/utils/utils.c deleted file mode 100644 index f09244c..0000000 --- a/src/utils/utils.c +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include -#include -#include "utils/logger.h" - -// https://gist.github.com/ccbrown/9722406 -void dumpHex(const void *data, size_t size) { - char ascii[17]; - size_t i, j; - ascii[16] = '\0'; - DEBUG_FUNCTION_LINE("0x%08X (0x0000): ", data); - for (i = 0; i < size; ++i) { - WHBLogPrintf("%02X ", ((unsigned char *) data)[i]); - if (((unsigned char *) data)[i] >= ' ' && ((unsigned char *) data)[i] <= '~') { - ascii[i % 16] = ((unsigned char *) data)[i]; - } else { - ascii[i % 16] = '.'; - } - if ((i + 1) % 8 == 0 || i + 1 == size) { - WHBLogPrintf(" "); - if ((i + 1) % 16 == 0) { - WHBLogPrintf("| %s \n", ascii); - if (i + 1 < size) { - DEBUG_FUNCTION_LINE("0x%08X (0x%04X); ", data + i + 1, i + 1); - } - } else if (i + 1 == size) { - ascii[(i + 1) % 16] = '\0'; - if ((i + 1) % 16 <= 8) { - WHBLogPrintf(" "); - } - for (j = (i + 1) % 16; j < 16; ++j) { - WHBLogPrintf(" "); - } - WHBLogPrintf("| %s \n", ascii); - } - } - } -} diff --git a/src/utils/utils.h b/src/utils/utils.h deleted file mode 100644 index 1d00f98..0000000 --- a/src/utils/utils.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef __UTILS_H_ -#define __UTILS_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define LIMIT(x, min, max) \ - ({ \ - typeof( x ) _x = x; \ - typeof( min ) _min = min; \ - typeof( max ) _max = max; \ - ( ( ( _x ) < ( _min ) ) ? ( _min ) : ( ( _x ) > ( _max ) ) ? ( _max) : ( _x ) ); \ -}) - -#define DegToRad(a) ( (a) * 0.01745329252f ) -#define RadToDeg(a) ( (a) * 57.29577951f ) - -#define ALIGN4(x) (((x) + 3) & ~3) -#define ALIGN32(x) (((x) + 31) & ~31) - -#define le16(i) ((((uint16_t) ((i) & 0xFF)) << 8) | ((uint16_t) (((i) & 0xFF00) >> 8))) -#define le32(i) ((((uint32_t)le16((i) & 0xFFFF)) << 16) | ((uint32_t)le16(((i) & 0xFFFF0000) >> 16))) -#define le64(i) ((((uint64_t)le32((i) & 0xFFFFFFFFLL)) << 32) | ((uint64_t)le32(((i) & 0xFFFFFFFF00000000LL) >> 32))) - -//Needs to have log_init() called beforehand. -void dumpHex(const void *data, size_t size); - -#ifdef __cplusplus -} -#endif - -#endif // __UTILS_H_