Permalink
Browse files

added support for mcp hook iosuhax version

  • Loading branch information...
1 parent 97ef903 commit da206d887cf3c92fe5fcde8e6668e524b7dc301b @FIX94 committed Dec 12, 2016
Showing with 63 additions and 1 deletion.
  1. +13 −0 src/dynamic_libs/os_functions.c
  2. +7 −0 src/dynamic_libs/os_functions.h
  3. +43 −1 src/main.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);
@@ -95,6 +96,12 @@ 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)
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
EXPORT_DECL(int, LiWaitIopComplete, int unknown_syscall_arg_r3, int * remaining_bytes);
@@ -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);
}
@@ -96,6 +96,12 @@ 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
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
extern u64 (* OSGetTitleID)(void);
@@ -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);
View
@@ -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)
{
@@ -118,6 +155,8 @@ int Menu_Main(void)
int res = IOSUHAX_Open(NULL);
if(res < 0)
+ res = MCPHookOpen();
+ if(res < 0)
{
log_printf("IOSUHAX_open failed\n");
mount_sd_fat("sd");
@@ -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
{

0 comments on commit da206d8

Please sign in to comment.