mirror of
https://github.com/wiiu-env/EnvironmentLoader.git
synced 2024-11-27 08:14:14 +01:00
Remove unused code
This commit is contained in:
parent
7eb5d075f3
commit
65e460606f
@ -4,112 +4,10 @@
|
|||||||
#include <coreinit/debug.h>
|
#include <coreinit/debug.h>
|
||||||
#include <coreinit/dynload.h>
|
#include <coreinit/dynload.h>
|
||||||
#include <coreinit/memdefaultheap.h>
|
#include <coreinit/memdefaultheap.h>
|
||||||
#include <whb/file.h>
|
|
||||||
#include <whb/log.h>
|
|
||||||
#include <whb/sdcard.h>
|
|
||||||
|
|
||||||
#include "ElfUtils.h"
|
#include "ElfUtils.h"
|
||||||
#include "elfio/elfio.hpp"
|
#include "elfio/elfio.hpp"
|
||||||
|
|
||||||
int32_t LoadFileToMem(const char *relativefilepath, char **fileOut, uint32_t *sizeOut) {
|
|
||||||
char path[256];
|
|
||||||
int result = 0;
|
|
||||||
char *sdRootPath = nullptr;
|
|
||||||
if (!WHBMountSdCard()) {
|
|
||||||
DEBUG_FUNCTION_LINE("Failed to mount SD Card...");
|
|
||||||
result = -1;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
sdRootPath = WHBGetSdCardMountPath();
|
|
||||||
sprintf(path, "%s/%s", sdRootPath, relativefilepath);
|
|
||||||
|
|
||||||
DEBUG_FUNCTION_LINE("Loading file %s.", path);
|
|
||||||
|
|
||||||
*fileOut = WHBReadWholeFile(path, sizeOut);
|
|
||||||
if (!(*fileOut)) {
|
|
||||||
result = -2;
|
|
||||||
DEBUG_FUNCTION_LINE("WHBReadWholeFile(%s) returned NULL", path);
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
exit:
|
|
||||||
WHBUnmountSdCard();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t load_loader_elf_from_sd(unsigned char *baseAddress, const char *relativePath) {
|
|
||||||
char *elf_data = nullptr;
|
|
||||||
uint32_t fileSize = 0;
|
|
||||||
if (LoadFileToMem(relativePath, &elf_data, &fileSize) != 0) {
|
|
||||||
OSFatal("Failed to load hook_payload.elf from the SD Card.");
|
|
||||||
}
|
|
||||||
uint32_t result = load_loader_elf(baseAddress, elf_data, fileSize);
|
|
||||||
|
|
||||||
MEMFreeToDefaultHeap((void *) elf_data);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t load_loader_elf(unsigned char *baseAddress, char *elf_data, uint32_t fileSize) {
|
|
||||||
ELFIO::Elf32_Ehdr *ehdr;
|
|
||||||
ELFIO::Elf32_Phdr *phdrs;
|
|
||||||
uint8_t *image;
|
|
||||||
int32_t i;
|
|
||||||
|
|
||||||
ehdr = (ELFIO::Elf32_Ehdr *) elf_data;
|
|
||||||
|
|
||||||
if (ehdr->e_phoff == 0 || ehdr->e_phnum == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ehdr->e_phentsize != sizeof(ELFIO::Elf32_Phdr)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
phdrs = (ELFIO::Elf32_Phdr *) (elf_data + ehdr->e_phoff);
|
|
||||||
|
|
||||||
for (i = 0; i < ehdr->e_phnum; i++) {
|
|
||||||
if (phdrs[i].p_type != PT_LOAD) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (phdrs[i].p_filesz > phdrs[i].p_memsz) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!phdrs[i].p_filesz) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t p_paddr = phdrs[i].p_paddr + (uint32_t) baseAddress;
|
|
||||||
image = (uint8_t *) (elf_data + phdrs[i].p_offset);
|
|
||||||
|
|
||||||
memcpy((void *) p_paddr, image, phdrs[i].p_filesz);
|
|
||||||
DCFlushRange((void *) p_paddr, phdrs[i].p_filesz);
|
|
||||||
|
|
||||||
if (phdrs[i].p_flags & PF_X) {
|
|
||||||
ICInvalidateRange((void *) p_paddr, phdrs[i].p_memsz);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//! clear BSS
|
|
||||||
auto *shdr = (ELFIO::Elf32_Shdr *) (elf_data + ehdr->e_shoff);
|
|
||||||
for (i = 0; i < ehdr->e_shnum; i++) {
|
|
||||||
const char *section_name = ((const char *) elf_data) + shdr[ehdr->e_shstrndx].sh_offset + shdr[i].sh_name;
|
|
||||||
if (section_name[0] == '.' && section_name[1] == 'b' && section_name[2] == 's' && section_name[3] == 's') {
|
|
||||||
memset((void *) (shdr[i].sh_addr + baseAddress), 0, shdr[i].sh_size);
|
|
||||||
DCFlushRange((void *) (shdr[i].sh_addr + baseAddress), shdr[i].sh_size);
|
|
||||||
} else if (section_name[0] == '.' && section_name[1] == 's' && section_name[2] == 'b' && section_name[3] == 's' && section_name[4] == 's') {
|
|
||||||
memset((void *) (shdr[i].sh_addr + baseAddress), 0, shdr[i].sh_size);
|
|
||||||
DCFlushRange((void *) (shdr[i].sh_addr + baseAddress), shdr[i].sh_size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ehdr->e_entry;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool ElfUtils::doRelocation(std::vector<std::shared_ptr<RelocationData>> &relocData, relocation_trampolin_entry_t *tramp_data, uint32_t tramp_length) {
|
bool ElfUtils::doRelocation(std::vector<std::shared_ptr<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 functionName = curReloc->getName();
|
||||||
|
@ -12,11 +12,6 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#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);
|
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
#define R_PPC_NONE 0
|
#define R_PPC_NONE 0
|
||||||
#define R_PPC_ADDR32 1
|
#define R_PPC_ADDR32 1
|
||||||
|
Loading…
Reference in New Issue
Block a user