diff --git a/src/dynamic_libs/os_functions.c b/src/dynamic_libs/os_functions.c index 93c4f5f..d9f59d7 100644 --- a/src/dynamic_libs/os_functions.c +++ b/src/dynamic_libs/os_functions.c @@ -75,6 +75,7 @@ EXPORT_DECL(int, OSScreenPutFontEx, unsigned int bufferNum, unsigned int posX, u EXPORT_DECL(int, OSScreenEnableEx, unsigned int bufferNum, int enable); EXPORT_DECL(int, IOS_Ioctl,int fd, unsigned int request, void *input_buffer,unsigned int input_buffer_len, void *output_buffer, unsigned int output_buffer_len); +EXPORT_DECL(int, IOS_IoctlAsync,int fd, unsigned int request, void *input_buffer,unsigned int input_buffer_len, void *output_buffer, unsigned int output_buffer_len, void *cb, void *cbarg); EXPORT_DECL(int, IOS_Open,char *path, unsigned int mode); EXPORT_DECL(int, IOS_Close,int fd); @@ -94,6 +95,12 @@ EXPORT_DECL(int , MEMCreateExpHeapEx, void* address, unsigned int size, unsigned EXPORT_DECL(void *, MEMDestroyExpHeap, int heap); EXPORT_DECL(void, MEMFreeToExpHeap, int heap, void* ptr); +//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +//! MCP functions +//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +EXPORT_DECL(int, MCP_Open, void); +EXPORT_DECL(int, MCP_Close, int handle); + //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //! Loader functions (not real rpl) //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- @@ -150,6 +157,11 @@ void InitOSFunctionPointers(void) OS_FIND_EXPORT(coreinit_handle, OSLockMutex); OS_FIND_EXPORT(coreinit_handle, OSUnlockMutex); OS_FIND_EXPORT(coreinit_handle, OSTryLockMutex); + //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + //! MCP functions + //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + OS_FIND_EXPORT(coreinit_handle, MCP_Open); + OS_FIND_EXPORT(coreinit_handle, MCP_Close); //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //! Memory functions @@ -171,6 +183,7 @@ void InitOSFunctionPointers(void) //! Other function addresses //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- OS_FIND_EXPORT(coreinit_handle, IOS_Ioctl); + OS_FIND_EXPORT(coreinit_handle, IOS_IoctlAsync); OS_FIND_EXPORT(coreinit_handle, IOS_Open); OS_FIND_EXPORT(coreinit_handle, IOS_Close); } diff --git a/src/dynamic_libs/os_functions.h b/src/dynamic_libs/os_functions.h index 11c46b6..d11c6e0 100644 --- a/src/dynamic_libs/os_functions.h +++ b/src/dynamic_libs/os_functions.h @@ -95,6 +95,12 @@ extern void (* OSLockMutex)(void* mutex); extern void (* OSUnlockMutex)(void* mutex); extern int (* OSTryLockMutex)(void* mutex); +//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +//! MCP functions +//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +extern int (* MCP_Open)(void); +extern int (* MCP_Close)(int handle); + //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //! System functions //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- @@ -106,6 +112,7 @@ extern void (* ICInvalidateRange)(const void *addr, u32 length); extern void* (* OSEffectiveToPhysical)(const void*); extern int (* __os_snprintf)(char* s, int n, const char * format, ...); extern int (*IOS_Ioctl)(int fd, unsigned int request, void *input_buffer,unsigned int input_buffer_len, void *output_buffer, unsigned int output_buffer_len); +extern int (*IOS_IoctlAsync)(int fd, unsigned int request, void *input_buffer,unsigned int input_buffer_len, void *output_buffer, unsigned int output_buffer_len, void *cb, void *cbarg); extern int (*IOS_Open)(char *path, unsigned int mode); extern int (*IOS_Close)(int fd); diff --git a/src/main.c b/src/main.c index ab68275..cef6945 100644 --- a/src/main.c +++ b/src/main.c @@ -83,6 +83,43 @@ void console_printf(const char *format, ...) OSScreenFlipBuffersEx(1); } +//just to be able to call async +void someFunc(void *arg) +{ + (void)arg; +} + +static int mcp_hook_fd = -1; +int MCPHookOpen() +{ + //take over mcp thread + mcp_hook_fd = MCP_Open(); + if(mcp_hook_fd < 0) + return -1; + IOS_IoctlAsync(mcp_hook_fd, 0x62, (void*)0, 0, (void*)0, 0, someFunc, (void*)0); + //let wupserver start up + sleep(1); + if(IOSUHAX_Open("/dev/mcp") < 0) + { + MCP_Close(mcp_hook_fd); + mcp_hook_fd = -1; + return -1; + } + return 0; +} + +void MCPHookClose() +{ + if(mcp_hook_fd < 0) + return; + //close down wupserver, return control to mcp + IOSUHAX_Close(); + //wait for mcp to return + sleep(1); + MCP_Close(mcp_hook_fd); + mcp_hook_fd = -1; +} + /* Entry point */ int Menu_Main(void) { @@ -117,6 +154,8 @@ int Menu_Main(void) int iosuhaxMount = 0; int res = IOSUHAX_Open(NULL); + if(res < 0) + res = MCPHookOpen(); if(res < 0) { log_printf("IOSUHAX_open failed\n"); @@ -253,7 +292,10 @@ int Menu_Main(void) unmount_fs("storage_mlc"); unmount_fs("storage_usb"); IOSUHAX_FSA_Close(fsaFd); - IOSUHAX_Close(); + if(mcp_hook_fd >= 0) + MCPHookClose(); + else + IOSUHAX_Close(); } else {