Return UNSUPPORTED_CFW in CheckVersion

This commit is contained in:
Maschell 2022-08-27 12:59:57 +02:00
parent 2ac50e4392
commit f0df840999
2 changed files with 23 additions and 7 deletions

View File

@ -19,6 +19,7 @@ typedef enum MochaUtilsStatus {
MOCHA_RESULT_NOT_FOUND = -0x06, MOCHA_RESULT_NOT_FOUND = -0x06,
MOCHA_RESULT_UNSUPPORTED_API_VERSION = -0x10, MOCHA_RESULT_UNSUPPORTED_API_VERSION = -0x10,
MOCHA_RESULT_UNSUPPORTED_COMMAND = -0x11, MOCHA_RESULT_UNSUPPORTED_COMMAND = -0x11,
MOCHA_RESULT_UNSUPPORTED_CFW = -0x12,
MOCHA_RESULT_LIB_UNINITIALIZED = -0x20, MOCHA_RESULT_LIB_UNINITIALIZED = -0x20,
MOCHA_RESULT_UNKNOWN_ERROR = -0x100, MOCHA_RESULT_UNKNOWN_ERROR = -0x100,
} MochaUtilsStatus; } MochaUtilsStatus;
@ -44,8 +45,9 @@ MochaUtilsStatus Mocha_DeinitLibrary();
* @param outVersion pointer to the variable where the version will be stored. * @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<br> * @return MOCHA_RESULT_SUCCESS: The API version has been store in the version ptr<br>
* MOCHA_RESULT_INVALID_ARGUMENT: invalid version pointer<br> * MOCHA_RESULT_INVALID_ARGUMENT: Invalid version pointer<br>
* MOCHA_RESULT_UNSUPPORTED_API_VERSION: Failed to get the API version caused by an outdated mocha version. * MOCHA_RESULT_UNSUPPORTED_API_VERSION: Failed to get the API version caused by an outdated mocha version.<br>
* MOCHA_RESULT_UNSUPPORTED_CFW: Failed to get the API version caused by not using a (compatible) CFW.
*/ */
MochaUtilsStatus Mocha_CheckAPIVersion(uint32_t *outVersion); MochaUtilsStatus Mocha_CheckAPIVersion(uint32_t *outVersion);

View File

@ -43,6 +43,8 @@ const char *Mocha_GetStatusStr(MochaUtilsStatus status) {
return "MOCHA_RESULT_UNSUPPORTED_API_VERSION"; return "MOCHA_RESULT_UNSUPPORTED_API_VERSION";
case MOCHA_RESULT_UNSUPPORTED_COMMAND: case MOCHA_RESULT_UNSUPPORTED_COMMAND:
return "MOCHA_RESULT_UNSUPPORTED_COMMAND"; return "MOCHA_RESULT_UNSUPPORTED_COMMAND";
case MOCHA_RESULT_UNSUPPORTED_CFW:
return "MOCHA_RESULT_UNSUPPORTED_CFW";
case MOCHA_RESULT_LIB_UNINITIALIZED: case MOCHA_RESULT_LIB_UNINITIALIZED:
return "MOCHA_RESULT_LIB_UNINITIALIZED"; return "MOCHA_RESULT_LIB_UNINITIALIZED";
case MOCHA_RESULT_UNKNOWN_ERROR: case MOCHA_RESULT_UNKNOWN_ERROR:
@ -101,11 +103,23 @@ MochaUtilsStatus Mocha_CheckAPIVersion(uint32_t *version) {
ALIGN_0x40 uint32_t io_buffer[0x40 / 4]; ALIGN_0x40 uint32_t io_buffer[0x40 / 4];
io_buffer[0] = IPC_CUSTOM_GET_MOCHA_API_VERSION; 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) { 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]; *version = io_buffer[1];
res = MOCHA_RESULT_SUCCESS; res = MOCHA_RESULT_SUCCESS;
} else { } else if (io_buffer[0] == 1) {
// Old MochaPayload returns success, but zero as magic word
res = MOCHA_RESULT_UNSUPPORTED_API_VERSION; res = MOCHA_RESULT_UNSUPPORTED_API_VERSION;
} else {
// No known implementations are known to trigger this
res = MOCHA_RESULT_UNSUPPORTED_CFW;
}
} else {
// 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); IOS_Close(mcpFd);