mirror of
https://github.com/wiiu-env/WiiUPluginSystem.git
synced 2024-11-16 15:49:23 +01:00
[Loader] Added loading file from SDCard and print it
This commit is contained in:
parent
679b90cb9f
commit
ea24c2c557
@ -6,5 +6,5 @@ int __entry_menu(int argc, char **argv)
|
||||
//! *******************************************************************
|
||||
//! * Jump to our application *
|
||||
//! *******************************************************************
|
||||
return Menu_Main();
|
||||
return Menu_Main(argc,argv);
|
||||
}
|
||||
|
@ -7,23 +7,56 @@
|
||||
|
||||
#include <dynamic_libs/os_functions.h>
|
||||
#include <dynamic_libs/socket_functions.h>
|
||||
#include <dynamic_libs/fs_functions.h>
|
||||
#include <utils/logger.h>
|
||||
#include <fs/FSUtils.h>
|
||||
#include <fs/sd_fat_devoptab.h>
|
||||
#include <system/exception_handler.h>
|
||||
#include "common/common.h"
|
||||
|
||||
#include "main.h"
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
/* Entry point */
|
||||
extern "C" int Menu_Main(void){
|
||||
extern "C" int Menu_Main(int argc, char **argv){
|
||||
InitOSFunctionPointers();
|
||||
InitSocketFunctionPointers(); //For logging
|
||||
InitFSFunctionPointers();
|
||||
|
||||
log_init();
|
||||
|
||||
setup_os_exceptions();
|
||||
|
||||
DEBUG_FUNCTION_LINE("Application started.\n");
|
||||
DEBUG_FUNCTION_LINE("Mount SD partition\n");
|
||||
|
||||
int res = 0;
|
||||
if((res = mount_sd_fat("sd")) >= 0){
|
||||
DEBUG_FUNCTION_LINE("Mounting successful\n");
|
||||
loadAndProcessElf("sd:/example_plugin.mod");
|
||||
}
|
||||
|
||||
DEBUG_FUNCTION_LINE("Application is ending now.\n");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void loadAndProcessElf(const char * elfPath){
|
||||
u8 * elfData = NULL;
|
||||
u32 elfDataSize = 0;
|
||||
DEBUG_FUNCTION_LINE("Reading elf from path: %s\n",elfPath);
|
||||
|
||||
int result = FSUtils::LoadFileToMem(elfPath, &elfData, &elfDataSize);
|
||||
if(result < 0){
|
||||
DEBUG_FUNCTION_LINE("Loading failed. Make sure the file is on the SDCard.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
DEBUG_FUNCTION_LINE("Loaded file. Position: %08X Size: %d\n",elfData,elfDataSize);
|
||||
|
||||
u32 dump_size = 0x80;
|
||||
if(elfDataSize >= dump_size){
|
||||
DEBUG_FUNCTION_LINE("Hexdump of the first %08X bytes: \n",dump_size);
|
||||
dumpHex(elfData,dump_size);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,7 +10,8 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
//! C wrapper for our C++ functions
|
||||
int Menu_Main(void);
|
||||
int Menu_Main(int argc, char **argv);
|
||||
void loadAndProcessElf(const char * elfPath);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
40
loader/src/utils.cpp
Normal file
40
loader/src/utils.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#include <utils/logger.h>
|
||||
|
||||
#include "utils.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';
|
||||
for (i = 0; i < size; ++i) {
|
||||
log_printf("%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) {
|
||||
log_printf(" ");
|
||||
if ((i+1) % 16 == 0) {
|
||||
log_printf("| %s \n", ascii);
|
||||
} else if (i+1 == size) {
|
||||
ascii[(i+1) % 16] = '\0';
|
||||
if ((i+1) % 16 <= 8) {
|
||||
log_printf(" ");
|
||||
}
|
||||
for (j = (i+1) % 16; j < 16; ++j) {
|
||||
log_printf(" ");
|
||||
}
|
||||
log_printf("| %s \n", ascii);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
15
loader/src/utils.h
Normal file
15
loader/src/utils.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef _OWN_UTILS_H_
|
||||
#define _OWN_UTILS_H_
|
||||
|
||||
/* Main */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void dumpHex(const void* data, size_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user