6363static u8 aptHomeButtonState ;
6464static u32 aptFlags ;
6565static u32 aptParameters [0x1000 /4 ];
66- static u8 aptChainloadFlags ;
6766static u64 aptChainloadTid ;
67+ static u8 aptChainloadDeliverArg [0x300 ];
68+ static u32 aptChainloadDeliverArgSize = sizeof (aptChainloadDeliverArg );
69+ static u8 aptChainloadHmac [0x20 ];
6870static u8 aptChainloadMediatype ;
71+ static u8 aptChainloadFlags ;
6972
7073typedef enum
7174{
@@ -315,6 +318,9 @@ static void aptClearJumpToHome(void)
315318void aptClearChainloader (void )
316319{
317320 aptFlags &= ~FLAG_CHAINLOAD ;
321+ aptChainloadDeliverArgSize = sizeof (aptChainloadDeliverArg );
322+ memset (aptChainloadDeliverArg , 0 , sizeof (aptChainloadDeliverArg ));
323+ memset (aptChainloadHmac , 0 , sizeof (aptChainloadHmac ));
318324}
319325
320326void aptSetChainloader (u64 programID , u8 mediatype )
@@ -325,6 +331,14 @@ void aptSetChainloader(u64 programID, u8 mediatype)
325331 aptChainloadMediatype = mediatype ;
326332}
327333
334+ void aptSetChainloaderToCaller (void )
335+ {
336+ aptFlags |= FLAG_CHAINLOAD ;
337+ aptChainloadFlags = 1 ;
338+ aptChainloadTid = 0 ;
339+ aptChainloadMediatype = 0 ;
340+ }
341+
328342void aptSetChainloaderToSelf (void )
329343{
330344 aptFlags |= FLAG_CHAINLOAD ;
@@ -333,6 +347,20 @@ void aptSetChainloaderToSelf(void)
333347 aptChainloadMediatype = 0 ;
334348}
335349
350+ void aptSetChainloaderArgs (const void * deliverArg , size_t deliverArgSize , const void * hmac )
351+ {
352+ if (deliverArgSize >= sizeof (aptChainloadDeliverArg ))
353+ deliverArgSize = sizeof (aptChainloadDeliverArg );
354+
355+ aptChainloadDeliverArgSize = deliverArgSize ;
356+ memcpy (aptChainloadDeliverArg , deliverArg , deliverArgSize );
357+
358+ if (hmac != NULL )
359+ memcpy (aptChainloadHmac , hmac , sizeof (aptChainloadHmac ));
360+ else
361+ memset (aptChainloadHmac , 0 , sizeof (aptChainloadHmac ));
362+ }
363+
336364extern void (* __system_retAddr )(void );
337365
338366static void aptExitProcess (void )
@@ -370,10 +398,8 @@ void aptExit(void)
370398 if (R_SUCCEEDED (APT_IsRegistered (aptGetMenuAppID (), & hmRegistered )) && hmRegistered )
371399 {
372400 // Normal, sane chainload
373- u8 param [0x300 ] = {0 };
374- u8 hmac [0x20 ] = {0 };
375401 APT_PrepareToDoApplicationJump (aptChainloadFlags , aptChainloadTid , aptChainloadMediatype );
376- APT_DoApplicationJump (param , sizeof ( param ), hmac );
402+ APT_DoApplicationJump (aptChainloadDeliverArg , aptChainloadDeliverArgSize , aptChainloadHmac );
377403 }
378404 else
379405 {
@@ -1430,7 +1456,7 @@ Result APT_GetSharedFont(Handle* fontHandle, u32* mapAddr)
14301456 return ret ;
14311457}
14321458
1433- Result APT_ReceiveDeliverArg (const void * param , size_t paramSize , const void * hmac , u64 * sender , bool * received )
1459+ Result APT_ReceiveDeliverArg (void * param , size_t paramSize , void * hmac , u64 * sender , bool * received )
14341460{
14351461 u32 cmdbuf [16 ];
14361462 cmdbuf [0 ]= IPC_MakeHeader (0x35 ,2 ,0 ); // 0x350080
0 commit comments