From fbfbd3ef7cb03d08852be6d18e9789d740db3777 Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 9 Oct 2021 00:54:48 +0200 Subject: [PATCH] Add IOSUHAX_read_otp and IOSUHAX_ODM_GetDiscKey --- include/iosuhax.h | 4 ++++ source/iosuhax.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/include/iosuhax.h b/include/iosuhax.h index b8439b8..b3a2559 100644 --- a/include/iosuhax.h +++ b/include/iosuhax.h @@ -70,6 +70,10 @@ int IOSUHAX_kern_write32(uint32_t address, uint32_t value); int IOSUHAX_kern_read32(uint32_t address, uint32_t *out_buffer, uint32_t count); +int IOSUHAX_read_otp(uint8_t * out_buffer, uint32_t size); + +int IOSUHAX_ODM_GetDiscKey(uint8_t * discKey); + int IOSUHAX_SVC(uint32_t svc_id, uint32_t *args, uint32_t arg_cnt); int IOSUHAX_FSA_Open(); diff --git a/source/iosuhax.c b/source/iosuhax.c index c06aa71..66ea8fb 100644 --- a/source/iosuhax.c +++ b/source/iosuhax.c @@ -35,6 +35,7 @@ #define IOCTL_REPEATED_WRITE 0x05 #define IOCTL_KERN_READ32 0x06 #define IOCTL_KERN_WRITE32 0x07 +#define IOCTL_READ_OTP 0x08 #define IOCTL_FSA_OPEN 0x40 #define IOCTL_FSA_CLOSE 0x41 @@ -115,6 +116,26 @@ int IOSUHAX_memwrite(uint32_t address, const uint8_t *buffer, uint32_t size) { return res; } +int IOSUHAX_ODM_GetDiscKey(uint8_t * discKey){ + int res = -1; + if(discKey == NULL){ + return -2; + } + int odm_handle = IOS_Open("/dev/odm", 1); + res = odm_handle; + if (odm_handle >= 0) { + uint32_t io_buffer[0x20 / 4]; + // disc encryption key, only works with patched IOSU + io_buffer[0] = 3; + res = IOS_Ioctl(odm_handle, 0x06, io_buffer, 0x14, io_buffer, 0x20); + if (res == 0) { + memcpy(discKey, io_buffer, 16); + } + IOS_Close(odm_handle); + } + return res; +} + int IOSUHAX_memread(uint32_t address, uint8_t *out_buffer, uint32_t size) { if (iosuhaxHandle < 0) return iosuhaxHandle; @@ -162,6 +183,22 @@ int IOSUHAX_kern_write32(uint32_t address, uint32_t value) { return IOS_Ioctl(iosuhaxHandle, IOCTL_KERN_WRITE32, io_buf, 2 * sizeof(uint32_t), 0, 0); } +int IOSUHAX_read_otp(uint8_t * out_buffer, uint32_t size) { + if (iosuhaxHandle < 0) { + return iosuhaxHandle; + } + + ALIGN(0x20) uint32_t io_buf[0x400 >> 2]; + + int res = IOS_Ioctl(iosuhaxHandle, IOCTL_READ_OTP, 0, 0, io_buf, 0x400); + + if (res >= 0){ + memcpy(out_buffer, io_buf, size > 0x400 ? 0x400 : size); + } + + return res; +} + int IOSUHAX_kern_read32(uint32_t address, uint32_t *out_buffer, uint32_t count) { if (iosuhaxHandle < 0) return iosuhaxHandle;