From d4c5fbdf0f80a19ecfa4b553b6267641210a8e43 Mon Sep 17 00:00:00 2001 From: cathery Date: Thu, 7 Nov 2019 21:27:13 +0300 Subject: [PATCH] hiddbg: Add hiddbgIsHdlsVirtualDeviceAttached (#345) --- nx/include/switch/services/hiddbg.h | 3 +++ nx/source/services/hiddbg.c | 35 +++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/nx/include/switch/services/hiddbg.h b/nx/include/switch/services/hiddbg.h index c5c6c5b7..c429e394 100644 --- a/nx/include/switch/services/hiddbg.h +++ b/nx/include/switch/services/hiddbg.h @@ -182,6 +182,9 @@ Result hiddbgAttachHdlsWorkBuffer(void); /// Exit Hdls, must be called at some point prior to hiddbgExit. Only available with [7.0.0+]. Result hiddbgReleaseHdlsWorkBuffer(void); +/// Checks if the given HdlsHandle is still attached, where the result is written to isAttached. Only available with [7.0.0+]. +Result hiddbgIsHdlsVirtualDeviceAttached(u64 HdlsHandle, bool *isAttached); + /// Gets state for \ref HiddbgHdlsNpadAssignment. Only available with [7.0.0+]. Result hiddbgDumpHdlsNpadAssignmentState(HiddbgHdlsNpadAssignment *state); diff --git a/nx/source/services/hiddbg.c b/nx/source/services/hiddbg.c index 8494c316..a7499062 100644 --- a/nx/source/services/hiddbg.c +++ b/nx/source/services/hiddbg.c @@ -392,6 +392,41 @@ Result hiddbgReleaseHdlsWorkBuffer(void) { return rc; } +Result hiddbgIsHdlsVirtualDeviceAttached(u64 HdlsHandle, bool *isAttached) { + Result rc = 0; + + if (hosversionBefore(7,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + if (!g_hiddbgHdlsInitialized) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + + rc = _hiddbgCmdNoIO(327); + if (R_FAILED(rc)) return rc; + if (isAttached) { + *isAttached = false; + if (hosversionBefore(9,0,0)) { + HiddbgHdlsStateListV7 *stateList = (HiddbgHdlsStateListV7*)(g_hiddbgHdlsTmem.src_addr); + for (s32 i=0; itotal_entries; i++) { + if (stateList->entries[i].HdlsHandle == HdlsHandle) { + *isAttached = true; + break; + } + } + } + else { + HiddbgHdlsStateList *stateList = (HiddbgHdlsStateList*)(g_hiddbgHdlsTmem.src_addr); + for (s32 i=0; itotal_entries; i++) { + if (stateList->entries[i].HdlsHandle == HdlsHandle) { + *isAttached = true; + break; + } + } + } + } + return rc; +} + Result hiddbgDumpHdlsNpadAssignmentState(HiddbgHdlsNpadAssignment *state) { Result rc=0;