Skip to content

Commit

Permalink
added support for mcp hook iosuhax version
Browse files Browse the repository at this point in the history
  • Loading branch information
FIX94 committed Dec 12, 2016
1 parent 97ef903 commit da206d8
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/dynamic_libs/os_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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)
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
7 changes: 7 additions & 0 deletions src/dynamic_libs/os_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Expand All @@ -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);

Expand Down
44 changes: 43 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit da206d8

Please sign in to comment.