From d91923accc8db32695cdda918b8afad87b7989fb Mon Sep 17 00:00:00 2001 From: HookedBehemoth Date: Mon, 16 Mar 2020 00:25:15 +0100 Subject: [PATCH] Fix ticket listing and minor libnx update --- source/KeyCollection.cpp | 19 +++++++++--------- source/KeyLocation.cpp | 2 +- source/nx/es.c | 42 ++++++++++++++++------------------------ source/nx/es.h | 8 ++++++-- source/nx/set_ext.c | 26 ------------------------- source/nx/set_ext.h | 12 ------------ 6 files changed, 33 insertions(+), 76 deletions(-) delete mode 100644 source/nx/set_ext.c delete mode 100644 source/nx/set_ext.h diff --git a/source/KeyCollection.cpp b/source/KeyCollection.cpp index 897eb5b..44fb084 100644 --- a/source/KeyCollection.cpp +++ b/source/KeyCollection.cpp @@ -35,7 +35,6 @@ extern "C" { #include "nx/es.h" - #include "nx/set_ext.h" } #define TITLEKEY_BUFFER_SIZE 0x40000 @@ -486,7 +485,7 @@ void KeyCollection::derive_keys() { FRESULT fr; FIL save_file; - fsOpenBisStorage(&storage, FsBisStorageId_System); + fsOpenBisStorage(&storage, FsBisPartitionId_System); if (f_mount(&fs, "", 1) || f_chdir("/save") || f_open(&save_file, "8000000000000043", FA_READ | FA_OPEN_EXISTING)) @@ -592,7 +591,7 @@ void KeyCollection::get_titlekeys() { esInitialize(); esCountCommonTicket(&common_count); esCountPersonalizedTicket(&personalized_count); - NcmRightsId common_rights_ids[common_count], personalized_rights_ids[personalized_count]; + RightsId common_rights_ids[common_count], personalized_rights_ids[personalized_count]; esListCommonTicket(&ids_written, common_rights_ids, sizeof(common_rights_ids)); esListPersonalizedTicket(&ids_written, personalized_rights_ids, sizeof(personalized_rights_ids)); esExit(); @@ -608,27 +607,27 @@ void KeyCollection::get_titlekeys() { std::unordered_set rights_ids; for (size_t i = 0; i < common_count; i++) { for (size_t j = 0; j < 0x10; j++) { - sprintf(&rights_id_string[j*2], "%02x", common_rights_ids[i].rights_id.c[j]); + sprintf(&rights_id_string[j*2], "%02x", common_rights_ids[i].c[j]); } rights_ids.insert(rights_id_string); } for (size_t i = 0; i < personalized_count; i++) { for (size_t j = 0; j < 0x10; j++) { - sprintf(&rights_id_string[j*2], "%02x", personalized_rights_ids[i].rights_id.c[j]); + sprintf(&rights_id_string[j*2], "%02x", personalized_rights_ids[i].c[j]); } rights_ids.insert(rights_id_string); } // get extended eticket RSA key from PRODINFO - u8 eticket_data[0x244] = {}; + SetCalRsa2048DeviceKey eticket_data = {}; setcalInitialize(); - setcalGetEticketDeviceKey(eticket_data); + setcalGetEticketDeviceKey(&eticket_data); setcalExit(); byte_vector dec_keypair = eticket_rsa_kek.aes_decrypt_ctr( - byte_vector(eticket_data + 0x14, eticket_data + 0x244), - byte_vector(eticket_data + 4, eticket_data + 0x14) + byte_vector(eticket_data.key + 0x10, eticket_data.key + 0x240), + byte_vector(eticket_data.key, eticket_data.key + 0x10) ); // public exponent must be 65537 == 0x10001 (big endian) @@ -646,7 +645,7 @@ void KeyCollection::get_titlekeys() { // map of all found rights ids and corresponding titlekeys std::unordered_map titlekeys; - fsOpenBisStorage(&storage, FsBisStorageId_System); + fsOpenBisStorage(&storage, FsBisPartitionId_System); if (f_mount(&fs, "", 1) || f_chdir("/save")) return; if (f_open(&save_file, "80000000000000e1", FA_READ | FA_OPEN_EXISTING)) return; while ((common_count != 0) && (titlekeys_dumped < common_count)) { diff --git a/source/KeyLocation.cpp b/source/KeyLocation.cpp index ba5cee7..eb1fe27 100644 --- a/source/KeyLocation.cpp +++ b/source/KeyLocation.cpp @@ -101,7 +101,7 @@ void KeyLocation::get_from_memory(u64 tid, u8 seg_mask) { void KeyLocation::get_keyblobs() { FsStorage boot0; - fsOpenBisStorage(&boot0, FsBisStorageId_Boot0); + fsOpenBisStorage(&boot0, FsBisPartitionId_BootPartition1Root); data.resize(0x200 * KNOWN_KEYBLOBS); fsStorageRead(&boot0, KEYBLOB_OFFSET, data.data(), data.size()); fsStorageClose(&boot0); diff --git a/source/nx/es.c b/source/nx/es.c index fbd7dca..ed0c6f0 100644 --- a/source/nx/es.c +++ b/source/nx/es.c @@ -17,56 +17,48 @@ void _esCleanup() { serviceClose(&g_esSrv); } -Result esCountCommonTicket(u32 *num_tickets) +Result esCountCommonTicket(u32 *out_count) { - struct { - u32 num_tickets; - } out; + u32 num_tickets; - Result rc = serviceDispatchOut(&g_esSrv, 9, out); - if (R_SUCCEEDED(rc) && num_tickets) *num_tickets = out.num_tickets; + Result rc = serviceDispatchOut(&g_esSrv, 9, num_tickets); + if (R_SUCCEEDED(rc) && out_count) *out_count = num_tickets; return rc; } -Result esCountPersonalizedTicket(u32 *num_tickets) +Result esCountPersonalizedTicket(u32 *out_count) { - struct { - u32 num_tickets; - } out; + u32 num_tickets; - Result rc = serviceDispatchOut(&g_esSrv, 10, out); - if (R_SUCCEEDED(rc) && num_tickets) *num_tickets = out.num_tickets; + Result rc = serviceDispatchOut(&g_esSrv, 10, num_tickets); + if (R_SUCCEEDED(rc) && out_count) *out_count = num_tickets; return rc; } -Result esListCommonTicket(u32 *numRightsIdsWritten, NcmRightsId *outBuf, size_t bufSize) +Result esListCommonTicket(u32 *numRightsIdsWritten, RightsId *outBuf, size_t bufSize) { - struct { - u32 num_rights_ids_written; - } out; + u32 num_rights_ids_written; - Result rc = serviceDispatchInOut(&g_esSrv, 11, *numRightsIdsWritten, out, + Result rc = serviceDispatchOut(&g_esSrv, 11, num_rights_ids_written, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, .buffers = { { outBuf, bufSize } }, ); - if (R_SUCCEEDED(rc) && numRightsIdsWritten) *numRightsIdsWritten = out.num_rights_ids_written; + if (R_SUCCEEDED(rc) && numRightsIdsWritten) *numRightsIdsWritten = num_rights_ids_written; return rc; } -Result esListPersonalizedTicket(u32 *numRightsIdsWritten, NcmRightsId *outBuf, size_t bufSize) +Result esListPersonalizedTicket(u32 *numRightsIdsWritten, RightsId *outBuf, size_t bufSize) { - struct { - u32 num_rights_ids_written; - } out; + u32 num_rights_ids_written; - Result rc = serviceDispatchInOut(&g_esSrv, 12, *numRightsIdsWritten, out, + Result rc = serviceDispatchOut(&g_esSrv, 12, num_rights_ids_written, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, .buffers = { { outBuf, bufSize } }, ); - if (R_SUCCEEDED(rc) && numRightsIdsWritten) *numRightsIdsWritten = out.num_rights_ids_written; + if (R_SUCCEEDED(rc) && numRightsIdsWritten) *numRightsIdsWritten = num_rights_ids_written; return rc; -} \ No newline at end of file +} diff --git a/source/nx/es.h b/source/nx/es.h index f1ad03a..a43e22d 100644 --- a/source/nx/es.h +++ b/source/nx/es.h @@ -3,10 +3,14 @@ #include #include +typedef struct { + u8 c[0x10]; +} RightsId; + Result esInitialize(); void esExit(); Result esCountCommonTicket(u32 *num_tickets); //9 Result esCountPersonalizedTicket(u32 *num_tickets); // 10 -Result esListCommonTicket(u32 *numRightsIdsWritten, NcmRightsId *outBuf, size_t bufSize); -Result esListPersonalizedTicket(u32 *numRightsIdsWritten, NcmRightsId *outBuf, size_t bufSize); \ No newline at end of file +Result esListCommonTicket(u32 *numRightsIdsWritten, RightsId *outBuf, size_t bufSize); +Result esListPersonalizedTicket(u32 *numRightsIdsWritten, RightsId *outBuf, size_t bufSize); diff --git a/source/nx/set_ext.c b/source/nx/set_ext.c deleted file mode 100644 index 2ccef6c..0000000 --- a/source/nx/set_ext.c +++ /dev/null @@ -1,26 +0,0 @@ -#include "set_ext.h" - -#include "../service_guard.h" - -#include -#include - -static Service g_setcalSrv; - -NX_GENERATE_SERVICE_GUARD(setcal); - -Result _setcalInitialize() { - return smGetService(&g_setcalSrv, "set:cal"); -} - -void _setcalCleanup() { - serviceClose(&g_setcalSrv); -} - -Result setcalGetEticketDeviceKey(void *key) -{ - return serviceDispatch(&g_setcalSrv, 21, - .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, - .buffers = { { key, 0x244 } }, - ); -} \ No newline at end of file diff --git a/source/nx/set_ext.h b/source/nx/set_ext.h deleted file mode 100644 index 9777cd6..0000000 --- a/source/nx/set_ext.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include - -Result setcalInitialize(void); -void setcalExit(void); - -/** - * @brief Gets the extended ETicket RSA-2048 Key from CAL0 - * @param key Pointer to 0x244-byte output buffer. - */ -Result setcalGetEticketDeviceKey(void *key); \ No newline at end of file