From f0df840999467260f66ff26e84e5340375c9f10b Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 27 Aug 2022 12:59:57 +0200 Subject: [PATCH] Return UNSUPPORTED_CFW in CheckVersion --- include/mocha/mocha.h | 8 +++++--- source/utils.cpp | 22 ++++++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/include/mocha/mocha.h b/include/mocha/mocha.h index 936d5cc..988468d 100644 --- a/include/mocha/mocha.h +++ b/include/mocha/mocha.h @@ -19,6 +19,7 @@ typedef enum MochaUtilsStatus { MOCHA_RESULT_NOT_FOUND = -0x06, MOCHA_RESULT_UNSUPPORTED_API_VERSION = -0x10, MOCHA_RESULT_UNSUPPORTED_COMMAND = -0x11, + MOCHA_RESULT_UNSUPPORTED_CFW = -0x12, MOCHA_RESULT_LIB_UNINITIALIZED = -0x20, MOCHA_RESULT_UNKNOWN_ERROR = -0x100, } MochaUtilsStatus; @@ -43,9 +44,10 @@ MochaUtilsStatus Mocha_DeinitLibrary(); * * @param outVersion pointer to the variable where the version will be stored. * - * @return MOCHA_RESULT_SUCCESS: The API version has been store in the version ptr
- * MOCHA_RESULT_INVALID_ARGUMENT: invalid version pointer
- * MOCHA_RESULT_UNSUPPORTED_API_VERSION: Failed to get the API version caused by an outdated mocha version. + * @return MOCHA_RESULT_SUCCESS: The API version has been store in the version ptr
+ * MOCHA_RESULT_INVALID_ARGUMENT: Invalid version pointer
+ * MOCHA_RESULT_UNSUPPORTED_API_VERSION: Failed to get the API version caused by an outdated mocha version.
+ * MOCHA_RESULT_UNSUPPORTED_CFW: Failed to get the API version caused by not using a (compatible) CFW. */ MochaUtilsStatus Mocha_CheckAPIVersion(uint32_t *outVersion); diff --git a/source/utils.cpp b/source/utils.cpp index 4b6df26..c89d967 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -43,6 +43,8 @@ const char *Mocha_GetStatusStr(MochaUtilsStatus status) { return "MOCHA_RESULT_UNSUPPORTED_API_VERSION"; case MOCHA_RESULT_UNSUPPORTED_COMMAND: return "MOCHA_RESULT_UNSUPPORTED_COMMAND"; + case MOCHA_RESULT_UNSUPPORTED_CFW: + return "MOCHA_RESULT_UNSUPPORTED_CFW"; case MOCHA_RESULT_LIB_UNINITIALIZED: return "MOCHA_RESULT_LIB_UNINITIALIZED"; case MOCHA_RESULT_UNKNOWN_ERROR: @@ -101,11 +103,23 @@ MochaUtilsStatus Mocha_CheckAPIVersion(uint32_t *version) { ALIGN_0x40 uint32_t io_buffer[0x40 / 4]; io_buffer[0] = IPC_CUSTOM_GET_MOCHA_API_VERSION; - if (IOS_Ioctl(mcpFd, 100, io_buffer, 4, io_buffer, 8) == IOS_ERROR_OK && io_buffer[0] == 0xCAFEBABE) { - *version = io_buffer[1]; - res = MOCHA_RESULT_SUCCESS; + if (IOS_Ioctl(mcpFd, 100, io_buffer, 4, io_buffer, 8) == IOS_ERROR_OK) { + // IOCTL_100 hook is available + if (io_buffer[0] == 0xCAFEBABE) { + // Updated MochaPayload returns magic word + *version = io_buffer[1]; + res = MOCHA_RESULT_SUCCESS; + } else if (io_buffer[0] == 1) { + // Old MochaPayload returns success, but zero as magic word + res = MOCHA_RESULT_UNSUPPORTED_API_VERSION; + } else { + // No known implementations are known to trigger this + res = MOCHA_RESULT_UNSUPPORTED_CFW; + } } else { - res = MOCHA_RESULT_UNSUPPORTED_API_VERSION; + // If IOCTL_100 hook is not available the call returns -1 + // This is the case with old Mocha CFW or no CFW at all + res = MOCHA_RESULT_UNSUPPORTED_CFW; } IOS_Close(mcpFd);