diff --git a/include/mocha/mocha.h b/include/mocha/mocha.h index 99f8ba9..f70423f 100644 --- a/include/mocha/mocha.h +++ b/include/mocha/mocha.h @@ -12,6 +12,7 @@ typedef enum MochaUtilsStatus { MOCHA_RESULT_SUCCESS = 0, MOCHA_RESULT_INVALID_ARGUMENT = -0x01, MOCHA_RESULT_MAX_CLIENT = -0x02, + MOCHA_RESULT_NOT_FOUND = -0x06, MOCHA_RESULT_UNSUPPORTED_API_VERSION = -0x10, MOCHA_RESULT_UNSUPPORTED_COMMAND = -0x11, MOCHA_RESULT_LIB_UNINITIALIZED = -0x20, @@ -90,6 +91,17 @@ typedef struct WUDDiscKey { uint8_t key[0x10]; } WUDDiscKey; +/** + * Reads the disc key (used to decrypt the SI partition) of the inserted disc. + * + * @param discKey target buffer where the result will be stored. + * @return MOCHA_RESULT_SUCCESS: The disc key of the inserted disc has been read into the given buffer.
+ * MOCHA_RESULT_INVALID_ARGUMENT: The given discKey buffer was NULL
+ * MOCHA_RESULT_LIB_UNINITIALIZED: Library was not initialized. Call Mocha_InitLibrary() before using this function.
+ * MOCHA_RESULT_UNSUPPORTED_COMMAND: Command not supported by the currently loaded mocha version.
+ * MOCHA_RESULT_NOT_FOUND: Failed to obtain disc key, no disc inserted?. + * MOCHA_RESULT_UNKNOWN_ERROR: Unknown error. + */ MochaUtilsStatus Mocha_ODMGetDiscKey(WUDDiscKey *discKey); MochaUtilsStatus Mocha_SEEPROMRead(uint8_t *out_buffer, uint32_t offset, uint32_t size); diff --git a/source/utils.cpp b/source/utils.cpp index 906b62b..fe23eaa 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -170,11 +170,13 @@ MochaUtilsStatus Mocha_ODMGetDiscKey(WUDDiscKey *discKey) { if (odm_handle >= 0) { ALIGN_0x40 uint32_t io_buffer[0x40 / 4]; // disc encryption key, only works with patched IOSU - io_buffer[0] = 3; - - if (IOS_Ioctl(odm_handle, 0x06, io_buffer, 0x14, io_buffer, 0x20) == IOS_ERROR_OK) { + io_buffer[0] = 3; + IOSError ioctlResult = IOS_Ioctl(odm_handle, 0x06, io_buffer, 0x14, io_buffer, 0x20); + if (ioctlResult == IOS_ERROR_OK) { memcpy(discKey, io_buffer, 16); res = MOCHA_RESULT_SUCCESS; + } else if (ioctlResult == (IOSError) 0xFFF1EFFF) { + res = MOCHA_RESULT_NOT_FOUND; } IOS_Close(odm_handle); }