diff --git a/loader/src/entry.c b/loader/src/entry.c index 5f5d1cb..4fd911f 100644 --- a/loader/src/entry.c +++ b/loader/src/entry.c @@ -6,5 +6,5 @@ int __entry_menu(int argc, char **argv) //! ******************************************************************* //! * Jump to our application * //! ******************************************************************* - return Menu_Main(); + return Menu_Main(argc,argv); } diff --git a/loader/src/main.cpp b/loader/src/main.cpp index 8c19fda..25f7df4 100644 --- a/loader/src/main.cpp +++ b/loader/src/main.cpp @@ -7,23 +7,56 @@ #include #include +#include #include +#include +#include #include +#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); + } + +} diff --git a/loader/src/main.h b/loader/src/main.h index 270959f..dbd62a9 100644 --- a/loader/src/main.h +++ b/loader/src/main.h @@ -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 } diff --git a/loader/src/utils.cpp b/loader/src/utils.cpp new file mode 100644 index 0000000..ef365b1 --- /dev/null +++ b/loader/src/utils.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include +#include + +#include + +#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); + } + } + } +} \ No newline at end of file diff --git a/loader/src/utils.h b/loader/src/utils.h new file mode 100644 index 0000000..ac94926 --- /dev/null +++ b/loader/src/utils.h @@ -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