From 4664af265f618073860b6348e145eb3268e95d68 Mon Sep 17 00:00:00 2001 From: "fix94.1" Date: Wed, 22 Aug 2012 19:09:21 +0000 Subject: [PATCH] -made exit to neek2o more safe to use (codedumps should be gone) --- source/loader/nk.c | 86 +++++++++++++++++++++------------------ source/loader/nk.h | 1 + source/loader/sys.c | 25 ++++++++---- source/loader/sys.h | 16 +++++--- source/menu/menu_game.cpp | 5 ++- source/menu/menu_home.cpp | 6 ++- source/menu/menu_main.cpp | 3 +- 7 files changed, 84 insertions(+), 58 deletions(-) diff --git a/source/loader/nk.c b/source/loader/nk.c index 3bcc7aea..dca78c2b 100644 --- a/source/loader/nk.c +++ b/source/loader/nk.c @@ -35,6 +35,8 @@ bool checked = false; bool neek = false; +u32 kernelSize = 0; +void *Kernel = NULL; bool neek2o(void) { @@ -48,66 +50,72 @@ bool neek2o(void) return neek; } +bool Load_Neek2o_Kernel() +{ + if(neek2o()) + return true; + + FILE *file = NULL; + file = fopen("usb1:/sneek/kernel.bin", "rb"); + if(!file) + file = fopen("sd:/sneek/kernel.bin", "rb"); + if(file) + { + fseek(file , 0 , SEEK_END); + kernelSize = ftell(file); + rewind(file); + Kernel = malloc(kernelSize); + if(!Kernel) + { + fclose(file); + return false; + } + fread(Kernel, 1, kernelSize, file); + fclose(file); + return true; + } + return false; +} + s32 Launch_nk(u64 TitleID, const char *nandpath) { if(neek2o()) { - SYS_ResetSystem(SYS_RESTART, 0, 0); + SYS_ResetSystem(SYS_RESTART, 0, 0); return 1; } + memcpy((void*)0x91000000, Kernel, kernelSize); + DCFlushRange((void*)0x91000000, kernelSize); + free(Kernel); - FILE *file = NULL; - long fsize; - - file = fopen( "usb1:/sneek/kernel.bin", "rb" ); - - if(!file) - file = fopen( "sd:/sneek/kernel.bin", "rb" ); - - if(file) - { - fseek(file , 0 , SEEK_END); - fsize = ftell(file); - rewind(file); - fread((void *)0x91000000, 1, fsize, file); - DCFlushRange((void *)0x91000000, fsize); - } - else - return 0; - - fclose(file); - memcfg *MC = (memcfg*)malloc(sizeof(memcfg)); if(MC == NULL) return 0; - memset(MC, 0, sizeof(memcfg)); - MC->magic = 0x666c6f77; MC->titleid = TitleID; - + if(nandpath != NULL) { strcpy(MC->nandpath, nandpath); MC->config |= NCON_EXT_NAND_PATH; } - memcpy((void *)0x81200000, MC, sizeof(memcfg)); - DCFlushRange((void *)(0x81200000), sizeof(memcfg)); + DCFlushRange((void *)(0x81200000), sizeof(memcfg)); free(MC); - + /*** Thnx giantpune! ***/ - void *mini = MEM1_memalign(32, armboot_size); - if(!mini) - return 0; - - memcpy(mini, armboot, armboot_size); - DCFlushRange(mini, armboot_size); - *(u32*)0xc150f000 = 0x424d454d; - asm volatile("eieio"); - *(u32*)0xc150f004 = MEM_VIRTUAL_TO_PHYSICAL(mini); - asm volatile("eieio"); - IOS_ReloadIOS(0xfe); + void *mini = MEM1_memalign(32, armboot_size); + if(!mini) + return 0; + + memcpy(mini, armboot, armboot_size); + DCFlushRange(mini, armboot_size); + *(u32*)0xc150f000 = 0x424d454d; + asm volatile("eieio"); + *(u32*)0xc150f004 = MEM_VIRTUAL_TO_PHYSICAL(mini); + asm volatile("eieio"); + IOS_ReloadIOS(0xfe); MEM1_free(mini); return 1; } diff --git a/source/loader/nk.h b/source/loader/nk.h index 58f9ac06..1d6d3ff3 100644 --- a/source/loader/nk.h +++ b/source/loader/nk.h @@ -25,6 +25,7 @@ extern "C" { #endif /* __cplusplus */ s32 Launch_nk(u64 TitleID, const char *nandpath); +bool Load_Neek2o_Kernel(); bool neek2o(void); #ifdef __cplusplus diff --git a/source/loader/sys.c b/source/loader/sys.c index 22a9500f..e67d592a 100644 --- a/source/loader/sys.c +++ b/source/loader/sys.c @@ -12,22 +12,24 @@ #include "mload.h" #include "sys.h" #include "channel/channel_launcher.h" +#include "loader/nk.h" #include "gecko/gecko.h" #include "memory/mem2.hpp" #include "memory/memory.h" #include "wiiuse/wpad.h" /* Variables */ -static bool reset = false; -static bool shutdown = false; +bool reset = false; +bool shutdown = false; bool exiting = false; -static bool priiloader_def = false; -static bool return_to_hbc = false; -static bool return_to_menu = false; -static bool return_to_priiloader = false; -static bool return_to_disable = false; -static bool return_to_bootmii = false; +bool priiloader_def = false; +bool return_to_hbc = false; +bool return_to_menu = false; +bool return_to_priiloader = false; +bool return_to_disable = false; +bool return_to_bootmii = false; +bool return_to_neek2o = false; extern void __exception_closeall(); extern u32 __PADDisableRecalibration(s32 disable); @@ -85,6 +87,7 @@ void Sys_ExitTo(int option) return_to_priiloader = option == EXIT_TO_PRIILOADER; return_to_disable = option == EXIT_TO_DISABLE; return_to_bootmii = option == EXIT_TO_BOOTMII; + return_to_neek2o = option == EXIT_TO_NEEK2O; //magic word to force wii menu in priiloader. if(return_to_menu) @@ -114,6 +117,12 @@ void Sys_Exit(void) /* Shutdown Inputs */ Close_Inputs(); + if(return_to_neek2o) + { + Launch_nk(0x1000144574641LL, NULL); + while(1); + } + WII_Initialize(); if(return_to_menu || return_to_priiloader || priiloader_def) Sys_LoadMenu(); diff --git a/source/loader/sys.h b/source/loader/sys.h index 8e8a1f19..f361149a 100644 --- a/source/loader/sys.h +++ b/source/loader/sys.h @@ -14,12 +14,16 @@ extern "C" { #define RETURN_CHANNEL 0x0001000857494948ULL #define SYSTEM_MENU 0x0000000100000002ULL -#define PRIILOADER_DEF 0 -#define EXIT_TO_MENU 1 -#define EXIT_TO_HBC 2 -#define EXIT_TO_PRIILOADER 3 -#define EXIT_TO_DISABLE 4 -#define EXIT_TO_BOOTMII 5 +enum +{ + PRIILOADER_DEF = 0, + EXIT_TO_MENU, + EXIT_TO_HBC, + EXIT_TO_PRIILOADER, + EXIT_TO_DISABLE, + EXIT_TO_BOOTMII, + EXIT_TO_NEEK2O, +}; /* Prototypes */ void Sys_Init(void); diff --git a/source/menu/menu_game.cpp b/source/menu/menu_game.cpp index a9c1a9a4..3a9d5530 100644 --- a/source/menu/menu_game.cpp +++ b/source/menu/menu_game.cpp @@ -1087,12 +1087,13 @@ void CMenu::_launchChannel(dir_discHdr *hdr) if(useNK2o && !emu_disabled) { - cleanup(true); - if(!Launch_nk(gameTitle, emuPath.c_str())) + if(!Load_Neek2o_Kernel()) { error(_t("errneek1", L"Cannot launch neek2o. Verify your neek2o setup")); Sys_LoadMenu(); } + cleanup(); + Launch_nk(gameTitle, emuPath.c_str()); while(1); } else diff --git a/source/menu/menu_home.cpp b/source/menu/menu_home.cpp index d7669611..bcf5b629 100644 --- a/source/menu/menu_home.cpp +++ b/source/menu/menu_home.cpp @@ -139,11 +139,13 @@ bool CMenu::_ExitTo(void) } else if(m_btnMgr.selected(m_homeBtnExitToNeek)) { - if(!Launch_nk(0x1000144574641LL, NULL)) + if(!Load_Neek2o_Kernel()) { error(sfmt("errneek1", L"Cannot launch neek2o. Verify your neek2o setup")); exitHandler(2); - } + } + else + exitHandler(5); break; } } diff --git a/source/menu/menu_main.cpp b/source/menu/menu_main.cpp index 86572318..39a2abb5 100644 --- a/source/menu/menu_main.cpp +++ b/source/menu/menu_main.cpp @@ -241,8 +241,9 @@ void CMenu::exitHandler(int ExitTo) else Sys_ExitTo(EXIT_TO_HBC); } + else if(ExitTo == 5) //Neek2o kernel + Sys_ExitTo(EXIT_TO_NEEK2O); } - m_reload = (BTN_B_HELD || m_disable_exit); if(m_exit) {