From 62205f9ab507cdceae94c77197b1b459f0276d39 Mon Sep 17 00:00:00 2001 From: Naim2000 Date: Tue, 7 Jan 2025 21:11:59 -0500 Subject: [PATCH] not going to need you anymore (2) --- source/title.c | 70 +++++++++++++++++++++++++++++++++----------------- source/title.h | 2 ++ 2 files changed, 48 insertions(+), 24 deletions(-) diff --git a/source/title.c b/source/title.c index dd5fcc4..f49fb13 100644 --- a/source/title.c +++ b/source/title.c @@ -4,10 +4,11 @@ #include #include #include +#include #include "title.h" +#include "nand.h" #include "sha1.h" -#include "aes.h" #include "utils.h" #include "otp.h" #include "malloc.h" @@ -184,6 +185,35 @@ err: return ret; } +s32 Title_GetTMDView(u64 tid, tmd_view** outbuf, u32* outlen) +{ + s32 ret; + u32 view_sz = 0; + + *outbuf = NULL; + *outlen = 0; + + ret = ES_GetTMDViewSize(tid, &view_sz); + if (ret < 0) + return ret; + + tmd_view* view = memalign32(view_sz); + if (!view) + return -1; + + ret = ES_GetTMDView(tid, (u8*) view, view_sz); + if (ret < 0) + goto fail; + + *outbuf = view; + *outlen = view_sz; + return 0; + +fail: + free(view); + return ret; +} + s32 Title_GetVersion(u64 tid, u16 *outbuf) { signed_blob *p_tmd = NULL; @@ -262,7 +292,7 @@ s32 Title_GetSize(u64 tid, u32 *outbuf) *outbuf = size; /* Free memory */ - free(p_tmd); + free(view); return 0; } @@ -361,45 +391,37 @@ bool Title_SharedContentPresent(tmd_content* content, SharedContent shared[], u3 bool Title_GetcIOSInfo(int IOS, cIOSInfo* out) { u64 titleID = 0x0000000100000000ULL | IOS; - ATTRIBUTE_ALIGN(0x20) char path[ISFS_MAXPATH]; + tmd_view* view = NULL; + u32 view_size = 0; + char path[ISFS_MAXPATH]; u32 size; cIOSInfo* buf = NULL; - u32 view_size = 0; - if (ES_GetTMDViewSize(titleID, &view_size) < 0) - return false; + s32 ret = Title_GetTMDView(titleID, &view, &view_size); + if (ret < 0) + return ret; - tmd_view* view = memalign32(view_size); - if (!view) - return false; - - if (ES_GetTMDView(titleID, (u8*)view, view_size) < 0) - goto fail; - - tmd_view_content* content0 = NULL; - - for (tmd_view_content* con = view->contents; con < view->contents + view->num_contents; con++) + u32 content0 = 0; + for (int i = 0; i < view->num_contents; i++) { - if (con->index == 0) - content0 = con; + if (view->contents[i].index == 0) { + content0 = view->contents[i].cid; + break; + } } + free(view); - if (!content0) - goto fail; - - sprintf(path, "/title/00000001/%08x/content/%08x.app", IOS, content0->cid); + sprintf(path, "/title/00000001/%08x/content/%08x.app", IOS, content0); buf = (cIOSInfo*)NANDLoadFile(path, &size); if (!buf || size != 0x40 || buf->hdr_magic != CIOS_INFO_MAGIC || buf->hdr_version != CIOS_INFO_VERSION) goto fail; *out = *buf; - free(view); free(buf); return true; fail: - free(view); free(buf); return false; } diff --git a/source/title.h b/source/title.h index e78614d..d872244 100644 --- a/source/title.h +++ b/source/title.h @@ -43,6 +43,7 @@ s32 Title_FakesignTik(signed_blob *); s32 Title_FakesignTMD(signed_blob *); s32 Title_GetList(u64 **, u32 *); s32 Title_GetTicketViews(u64, tikview **, u32 *); +s32 Title_GetTMDView(u64, tmd_view **, u32 *); s32 Title_GetTMD(u64, signed_blob **, u32 *); s32 Title_GetVersion(u64, u16 *); s32 Title_GetSysVersion(u64, u64 *); @@ -51,6 +52,7 @@ s32 Title_GetIOSVersions(u8 **, u32 *); s32 Title_GetSharedContents(SharedContent** out, u32* count); bool Title_SharedContentPresent(tmd_content* content, SharedContent shared[], u32 count); bool Title_GetcIOSInfo(int IOS, cIOSInfo*); + void Title_SetupCommonKeys(void); #endif