From 859ad2cc4cb9c3f0d4ec43aabc88ef34fdfd34b1 Mon Sep 17 00:00:00 2001 From: suchmememanyskill Date: Sun, 27 Dec 2020 23:33:23 +0100 Subject: [PATCH] Show EMMC/EMUMMC GPT --- source/fs/menus/explorer.c | 3 +- source/fs/menus/filemenu.c | 12 ++--- source/storage/gptmenu.c | 95 +++++++++++++++++++++++++++++++++ source/storage/gptmenu.h | 5 ++ source/storage/mountmanager.c | 49 +++++++++++------ source/storage/mountmanager.h | 5 +- source/tegraexplorer/mainmenu.c | 24 ++++----- 7 files changed, 157 insertions(+), 36 deletions(-) create mode 100644 source/storage/gptmenu.c create mode 100644 source/storage/gptmenu.h diff --git a/source/fs/menus/explorer.c b/source/fs/menus/explorer.c index d5004e1..94951cc 100644 --- a/source/fs/menus/explorer.c +++ b/source/fs/menus/explorer.c @@ -17,7 +17,7 @@ MenuEntry_t topEntries[] = { {.optionUnion = COLORTORGB(COLOR_GREEN) | SKIPBIT}, - {.optionUnion = COLORTORGB(COLOR_ORANGE), .name = "Back"}, + {.optionUnion = COLORTORGB(COLOR_ORANGE)}, {.optionUnion = COLORTORGB(COLOR_GREY) | SKIPBIT, .name = "Clipboard -> Current folder"}, {.optionUnion = COLORTORGB(COLOR_GREY) | SKIPBIT, .name = "Current folder options"} }; @@ -44,6 +44,7 @@ void FileExplorer(char *path){ while (1){ topEntries[2].optionUnion = (TConf.explorerCopyMode != CMODE_None) ? (COLORTORGB(COLOR_ORANGE)) : (COLORTORGB(COLOR_GREY) | SKIPBIT); + topEntries[1].name = (!strcmp(storedPath, path)) ? "<- Exit explorer" : "<- Folder back"; gfx_clearscreen(); gfx_printf("Loading...\r"); diff --git a/source/fs/menus/filemenu.c b/source/fs/menus/filemenu.c index ed2c585..7479a99 100644 --- a/source/fs/menus/filemenu.c +++ b/source/fs/menus/filemenu.c @@ -18,9 +18,9 @@ MenuEntry_t FileMenuEntries[] = { {.optionUnion = COLORTORGB(COLOR_VIOLET) | SKIPBIT}, // For the file Attribs {.optionUnion = HIDEBIT}, {.optionUnion = COLORTORGB(COLOR_WHITE), .name = "<- Back"}, - {.optionUnion = COLORTORGB(COLOR_BLUE), .name = "Copy to clipboard"}, + {.optionUnion = COLORTORGB(COLOR_BLUE), .name = "\nCopy to clipboard"}, {.optionUnion = COLORTORGB(COLOR_BLUE), .name = "Move to clipboard"}, - {.optionUnion = COLORTORGB(COLOR_BLUE), .name = "Rename file"}, + {.optionUnion = COLORTORGB(COLOR_BLUE), .name = "Rename file\n"}, {.optionUnion = COLORTORGB(COLOR_RED), .name = "Delete file"}, {.optionUnion = COLORTORGB(COLOR_GREEN), .name = "View hex"}, {.optionUnion = COLORTORGB(COLOR_ORANGE), .name = "Launch Payload"}, @@ -56,7 +56,7 @@ MenuEntry_t DeleteEntries[] = { }; void DeleteFile(char *path, FSEntry_t entry){ - gfx_con_setpos(384 + 16, 200 + 16 + 8 * 16); + gfx_con_setpos(384 + 16, 200 + 16 + 10 * 16); SETCOLOR(COLOR_RED, COLOR_DARKGREY); gfx_printf("Are you sure? "); @@ -82,10 +82,10 @@ menuPaths FileMenuPaths[] = { void FileMenu(char *path, FSEntry_t entry){ FileMenuEntries[1].name = entry.name; - FileMenuEntries[1].sizeUnion = entry.sizeUnion; - char attribs[15]; + FileMenuEntries[0].sizeUnion = entry.sizeUnion; + char attribs[16]; char *attribList = GetFileAttribs(entry); - sprintf(attribs, "Attribs:%s", attribList); + sprintf(attribs, "Attribs:%s\n", attribList); free(attribList); FileMenuEntries[2].name = attribs; diff --git a/source/storage/gptmenu.c b/source/storage/gptmenu.c new file mode 100644 index 0000000..78295cd --- /dev/null +++ b/source/storage/gptmenu.c @@ -0,0 +1,95 @@ +#include "gptmenu.h" +#include "../gfx/gfx.h" +#include "../gfx/menu.h" +#include "../gfx/gfxutils.h" +#include "../utils/vector.h" +#include "mountmanager.h" +#include +#include +#include "nx_emmc.h" +#include +#include "../fs/menus/explorer.h" +#include "../err.h" +#include "../tegraexplorer/tconf.h" + +MenuEntry_t GptMenuHeader[] = { + {.optionUnion = COLORTORGB(COLOR_ORANGE), .name = "<- Back"}, + {.optionUnion = COLORTORGB(COLOR_GREY) | SKIPBIT, .name = "Clipboard -> Partition"}, + {.optionUnion = COLORTORGB(COLOR_GREY) | SKIPBIT, .name = "\nBoot0/1"} // Should be blue when implemented +}; + +const char *GptFSEntries[] = { + "PRODINFOF", + "SAFE", + "SYSTEM", + "USER" +}; + +void GptMenu(u8 MMCType){ + if (connectMMC(MMCType)) + return; + + Vector_t GptMenu = newVec(sizeof(MenuEntry_t), 15); + GptMenu.count = 3; + memcpy(GptMenu.data, GptMenuHeader, sizeof(MenuEntry_t) * ARR_LEN(GptMenuHeader)); + + link_t *gpt = GetCurGPT(); + + LIST_FOREACH_ENTRY(emmc_part_t, part, gpt, link) { + MenuEntry_t entry = {.optionUnion = COLORTORGB(COLOR_VIOLET), .icon = 128, .name = part->name}; + u64 total = (part->lba_end - part->lba_start) / 2 + 1; + u8 type = 1; + while (total > 1024){ + total /= 1024; + type++; + } + + if (type > 3) + type = 3; + + entry.showSize = 1; + entry.size = total; + entry.sizeDef = type; + + for (int i = 0; i < ARR_LEN(GptFSEntries); i++){ + if (!strcmp(part->name, GptFSEntries[i])){ + entry.optionUnion = COLORTORGB(COLOR_WHITE); + entry.icon = 127; + break; + } + } + + vecAddElem(&GptMenu, entry); + } + + vecDefArray(MenuEntry_t*, entries, GptMenu); + int res = 0; + while (1){ + gfx_clearscreen(); + gfx_printf((MMCType == MMC_CONN_EMMC) ? "-- Emmc --\n\n" : "-- Emummc --\n\n"); + + res = newMenu(&GptMenu, res, 40, 20, ALWAYSREDRAW | ENABLEB, GptMenu.count); + + if (res < 3){ + break; + } + else if (entries[res].icon == 127){ + unmountMMCPart(); + ErrCode_t err = mountMMCPart(entries[res].name); + if (err.err){ + DrawError(err); + } + else { + if (TConf.curExplorerLoc > LOC_SD) + ResetCopyParams(); + TConf.curExplorerLoc = LOC_EMMC; + FileExplorer("bis:/"); + } + } + else { + DrawError(newErrCode(TE_ERR_UNIMPLEMENTED)); + } + } + + free(GptMenu.data); +} \ No newline at end of file diff --git a/source/storage/gptmenu.h b/source/storage/gptmenu.h new file mode 100644 index 0000000..d1bdbea --- /dev/null +++ b/source/storage/gptmenu.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +void GptMenu(u8 MMCType); \ No newline at end of file diff --git a/source/storage/mountmanager.c b/source/storage/mountmanager.c index dbde127..e977e98 100644 --- a/source/storage/mountmanager.c +++ b/source/storage/mountmanager.c @@ -6,6 +6,9 @@ #include #include #include "nx_emmc_bis.h" +#include "../config.h" + +extern hekate_config h_cfg; void SetKeySlots(){ if (TConf.keysDumped){ @@ -39,31 +42,45 @@ int connectMMC(u8 mmcType){ return 0; disconnectMMC(); - emu_cfg.enabled = (mmcType == MMC_CONN_EMMC) ? 0 : 1; + h_cfg.emummc_force_disable = (mmcType == MMC_CONN_EMMC) ? 1 : 0; int res = emummc_storage_init_mmc(&emmc_storage, &emmc_sdmmc); - if (!res) + if (!res){ TConf.currentMMCConnected = mmcType; + emummc_storage_set_mmc_partition(&emmc_storage, 0); + nx_emmc_gpt_parse(&curGpt, &emmc_storage); + } return res; // deal with the errors later lol } ErrCode_t mountMMCPart(const char *partition){ - if (TConf.connectedMMCMounted) - return newErrCode(0); + if (!TConf.connectedMMCMounted){ + emummc_storage_set_mmc_partition(&emmc_storage, 0); // why i have to do this twice beats me + + emmc_part_t *system_part = nx_emmc_part_find(&curGpt, partition); + if (!system_part) + return newErrCode(TE_ERR_PARTITION_NOT_FOUND); + + nx_emmc_bis_init(system_part); - emummc_storage_set_mmc_partition(&emmc_storage, 0); - - nx_emmc_gpt_parse(&curGpt, &emmc_storage); - emmc_part_t *system_part = nx_emmc_part_find(&curGpt, partition); - if (!system_part) - return newErrCode(TE_ERR_PARTITION_NOT_FOUND); - - nx_emmc_bis_init(system_part); + int res = 0; + if ((res = f_mount(&emmc_fs, "bis:", 1))) + return newErrCode(res); - int res = 0; - if ((res = f_mount(&emmc_fs, "bis:", 1))) - return newErrCode(res); + TConf.connectedMMCMounted = 1; + } - TConf.connectedMMCMounted = 1; return newErrCode(0); +} + +link_t *GetCurGPT(){ + if (TConf.currentMMCConnected != MMC_CONN_None) + return &curGpt; + return NULL; +} + +void unmountMMCPart(){ + if (TConf.connectedMMCMounted) + f_unmount("bis:"); + TConf.connectedMMCMounted = 0; } \ No newline at end of file diff --git a/source/storage/mountmanager.h b/source/storage/mountmanager.h index 88a0f80..926ac6e 100644 --- a/source/storage/mountmanager.h +++ b/source/storage/mountmanager.h @@ -1,5 +1,6 @@ #pragma once #include +#include #include "../err.h" enum { @@ -10,4 +11,6 @@ enum { int connectMMC(u8 mmcType); ErrCode_t mountMMCPart(const char *partition); -void SetKeySlots(); \ No newline at end of file +void SetKeySlots(); +void unmountMMCPart(); +link_t *GetCurGPT(); \ No newline at end of file diff --git a/source/tegraexplorer/mainmenu.c b/source/tegraexplorer/mainmenu.c index e65d17f..358332c 100644 --- a/source/tegraexplorer/mainmenu.c +++ b/source/tegraexplorer/mainmenu.c @@ -10,11 +10,14 @@ #include "tconf.h" #include "../keys/keys.h" #include "../storage/mountmanager.h" +#include "../storage/gptmenu.h" +#include "../storage/emummc.h" MenuEntry_t mainMenuEntries[] = { {.R = 255, .G = 255, .B = 255, .skip = 1, .name = "-- Main Menu --"}, {.G = 255, .name = "SD:/"}, - {.optionUnion = COLORTORGB(COLOR_YELLOW), .name = "emmc:/SYSTEM"}, + {.optionUnion = COLORTORGB(COLOR_YELLOW), .name = "Emmc"}, + {.optionUnion = COLORTORGB(COLOR_YELLOW), .name = "Emummc"}, {.B = 255, .G = 255, .name = "Test Controllers"}, {.R = 255, .name = "Cause an exception"}, {.optionUnion = COLORTORGB(COLOR_ORANGE), .name = "View dumped keys"}, @@ -33,16 +36,11 @@ void HandleSD(){ } void HandleEMMC(){ - if (connectMMC(MMC_CONN_EMMC)) - return; - - ErrCode_t err = mountMMCPart("SYSTEM"); - if (err.err){ - DrawError(err); - return; - } - - FileExplorer("bis:/"); + GptMenu(MMC_CONN_EMMC); +} + +void HandleEMUMMC(){ + GptMenu(MMC_CONN_EMUMMC); } void CrashTE(){ @@ -72,6 +70,7 @@ menuPaths mainMenuPaths[] = { NULL, HandleSD, HandleEMMC, + HandleEMUMMC, TestControllers, CrashTE, ViewKeys, @@ -81,7 +80,8 @@ menuPaths mainMenuPaths[] = { void EnterMainMenu(){ while (1){ mainMenuEntries[2].hide = !TConf.keysDumped; - mainMenuEntries[5].hide = !TConf.keysDumped; + mainMenuEntries[3].hide = (!TConf.keysDumped || !emu_cfg.enabled); + mainMenuEntries[6].hide = !TConf.keysDumped; FunctionMenuHandler(mainMenuEntries, ARR_LEN(mainMenuEntries), mainMenuPaths, ALWAYSREDRAW); } }