From 635d3e664013b18a43a9c47f572d4cce60798815 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Tue, 27 Dec 2016 18:49:58 -0800 Subject: [PATCH] Add APT:ReceiveDeliverArg --- libctru/include/3ds/services/apt.h | 10 +++++++++ libctru/source/services/apt.c | 33 ++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/libctru/include/3ds/services/apt.h b/libctru/include/3ds/services/apt.h index 1dad9de..e8026d5 100644 --- a/libctru/include/3ds/services/apt.h +++ b/libctru/include/3ds/services/apt.h @@ -497,3 +497,13 @@ Result APT_StartSystemApplet(NS_APPID appID, const void* param, size_t paramSize * @brief mapAddr Pointer to write the mapping address of the system font memory block to. */ Result APT_GetSharedFont(Handle* fontHandle, u32* mapAddr); + +/** + * @brief Receives the deliver (launch) argument + * @param param Parameter buffer. + * @param paramSize Size of parameter buffer. + * @param hmac HMAC buffer (should be 0x20 bytes long). + * @param sender Pointer to output the sender's AppID to. + * @param received Pointer to output whether an argument was received to. + */ +Result APT_ReceiveDeliverArg(const void* param, size_t paramSize, const void* hmac, u64* sender, bool* received); diff --git a/libctru/source/services/apt.c b/libctru/source/services/apt.c index b7b9163..c7088f6 100644 --- a/libctru/source/services/apt.c +++ b/libctru/source/services/apt.c @@ -1079,3 +1079,36 @@ Result APT_GetSharedFont(Handle* fontHandle, u32* mapAddr) return ret; } + +Result APT_ReceiveDeliverArg(const void* param, size_t paramSize, const void* hmac, u64* sender, bool* received) +{ + u32 cmdbuf[16]; + cmdbuf[0]=IPC_MakeHeader(0x35,2,0); // 0x350080 + cmdbuf[1]=paramSize; + cmdbuf[2]=hmac ? 0x20 : 0; + + u32 saved_threadstorage[4]; + u32* staticbufs = getThreadStaticBuffers(); + saved_threadstorage[0]=staticbufs[0]; + saved_threadstorage[1]=staticbufs[1]; + saved_threadstorage[2]=staticbufs[2]; + saved_threadstorage[3]=staticbufs[3]; + staticbufs[0]=IPC_Desc_StaticBuffer(cmdbuf[1],0); + staticbufs[1]=(u32)param; + staticbufs[2]=IPC_Desc_StaticBuffer(cmdbuf[2],2); + staticbufs[3]=(u32)hmac; + + Result ret = aptSendCommand(cmdbuf); + staticbufs[0]=saved_threadstorage[0]; + staticbufs[1]=saved_threadstorage[1]; + staticbufs[2]=saved_threadstorage[2]; + staticbufs[3]=saved_threadstorage[3]; + + if (R_SUCCEEDED(ret)) + { + if (sender) *sender =cmdbuf[2] | ((u64)cmdbuf[3]<<32); + if (received) *received =cmdbuf[4] & 0xFF; + } + + return ret; +}