From f93cc0ff44f500ec74a403b946eb003cc77fb58c Mon Sep 17 00:00:00 2001 From: "Such Meme, Many Skill" Date: Sat, 4 Apr 2020 16:49:47 +0200 Subject: [PATCH 1/6] Get a basic gpt menu --- source/tegraexplorer/common/common.h | 6 +- source/tegraexplorer/common/structs.c | 23 +++-- source/tegraexplorer/common/types.h | 9 +- source/tegraexplorer/emmc/emmc.c | 26 +++++- source/tegraexplorer/emmc/emmc.h | 3 + source/tegraexplorer/emmc/emmcmenu.c | 118 ++++++++++++++++++++++++++ source/tegraexplorer/emmc/emmcmenu.h | 3 + source/tegraexplorer/fs/fsreader.c | 24 +++--- source/tegraexplorer/fs/fsreader.h | 5 +- source/tegraexplorer/mainmenu.c | 33 +++---- 10 files changed, 209 insertions(+), 41 deletions(-) create mode 100644 source/tegraexplorer/emmc/emmcmenu.c create mode 100644 source/tegraexplorer/emmc/emmcmenu.h diff --git a/source/tegraexplorer/common/common.h b/source/tegraexplorer/common/common.h index d163e58..1197fac 100644 --- a/source/tegraexplorer/common/common.h +++ b/source/tegraexplorer/common/common.h @@ -104,4 +104,8 @@ enum fs_menu_startdir_return { FILEMENU_CURFOLDER }; -extern menu_entry fs_menu_startdir[]; \ No newline at end of file +extern menu_entry fs_menu_startdir[]; + +extern gpt_entry_rule gpt_fs_rules[]; + +extern menu_entry mmcmenu_start[]; \ No newline at end of file diff --git a/source/tegraexplorer/common/structs.c b/source/tegraexplorer/common/structs.c index 7e6f531..12febb6 100644 --- a/source/tegraexplorer/common/structs.c +++ b/source/tegraexplorer/common/structs.c @@ -2,13 +2,9 @@ #include "types.h" menu_entry mainmenu_main[] = { - {"[SD:/] SD CARD\n", COLOR_GREEN, ISMENU}, - {"[SAFE:/] EMMC", COLOR_ORANGE, ISMENU}, - {"[SYSTEM:/] EMMC", COLOR_ORANGE, ISMENU}, - {"[USER:/] EMMC", COLOR_ORANGE, ISMENU}, - {"\n[SAFE:/] EMUMMC", COLOR_BLUE, ISMENU}, - {"[SYSTEM:/] EMUMMC", COLOR_BLUE, ISMENU}, - {"[USER:/] EMUMMC", COLOR_BLUE, ISMENU}, + {"[SD:/] SD CARD", COLOR_GREEN, ISMENU}, + {"[EMMC:/] EMMC", COLOR_ORANGE, ISMENU}, + {"[EMMC:/] EMUMMC", COLOR_BLUE, ISMENU}, {"\nMount/Unmount SD", COLOR_WHITE, ISMENU}, {"Tools", COLOR_VIOLET, ISMENU}, {"SD format", COLOR_VIOLET, ISMENU}, @@ -73,4 +69,17 @@ menu_entry fs_menu_startdir[] = { {"Folder -> previous folder ", COLOR_ORANGE, ISMENU}, {"Clipboard -> Current folder ", COLOR_ORANGE, ISMENU}, {"Current folder menu ", COLOR_ORANGE, ISMENU} +}; + +gpt_entry_rule gpt_fs_rules[] = { + {"PRODINFOF", 0 | isFS}, + {"SAFE", 1 | isFS }, + {"SYSTEM", 2 | isFS}, + {"USER", 3 | isFS}, + {NULL, 0} +}; + +menu_entry mmcmenu_start[] = { + {"Back", COLOR_ORANGE, ISMENU}, + {"RESERVED\n", COLOR_ORANGE, ISMENU} }; \ No newline at end of file diff --git a/source/tegraexplorer/common/types.h b/source/tegraexplorer/common/types.h index 05a9441..699cb87 100644 --- a/source/tegraexplorer/common/types.h +++ b/source/tegraexplorer/common/types.h @@ -43,4 +43,11 @@ typedef struct { char *name; u32 storage; u16 property; -} menu_entry; \ No newline at end of file +} menu_entry; + +typedef struct { + const char *name; + u8 property; +} gpt_entry_rule; + +#define isFS 0x80 \ No newline at end of file diff --git a/source/tegraexplorer/emmc/emmc.c b/source/tegraexplorer/emmc/emmc.c index 60b2fc2..62cc751 100644 --- a/source/tegraexplorer/emmc/emmc.c +++ b/source/tegraexplorer/emmc/emmc.c @@ -22,13 +22,16 @@ #include "../../config/config.h" #include "../common/common.h" #include "../gfx/gfxutils.h" +#include "../../utils/list.h" +#include "../../mem/heap.h" sdmmc_storage_t storage; emmc_part_t *system_part; sdmmc_t sdmmc; extern hekate_config h_cfg; __attribute__ ((aligned (16))) FATFS emmc; -LIST_INIT(gpt); +LIST_INIT(sys_gpt); +LIST_INIT(emu_gpt); u8 bis_key[4][32]; pkg1_info pkg1inf = {-1, ""}; @@ -64,7 +67,7 @@ pkg1_info returnpkg1info(){ int connect_part(const char *partition){ sdmmc_storage_set_mmc_partition(&storage, 0); - system_part = nx_emmc_part_find(&gpt, partition); + system_part = nx_emmc_part_find(selectGpt(currentlyMounted), partition); if (!system_part) { gfx_errDisplay("connect_mmc_part", ERR_PART_NOT_FOUND, 0); return 1; @@ -213,8 +216,7 @@ int dump_biskeys(){ } sdmmc_storage_set_mmc_partition(&storage, 0); - // Parse eMMC GPT. - nx_emmc_gpt_parse(&gpt, &storage); + nx_emmc_gpt_parse(&sys_gpt, &storage); se_aes_key_set(8, bis_key[2] + 0x00, 0x10); se_aes_key_set(9, bis_key[2] + 0x10, 0x10); @@ -222,4 +224,20 @@ int dump_biskeys(){ pkg1inf.ver = pkg1_id->kb; strcpy(pkg1inf.id, pkg1_id->id); return 0; +} + +void dumpEmuGpt(){ + connect_mmc(EMUMMC); + sdmmc_storage_set_mmc_partition(&storage, 0); + nx_emmc_gpt_parse(&emu_gpt, &storage); +} + +link_t *selectGpt(short mmcType){ + switch(mmcType){ + case SYSMMC: + return &sys_gpt; + case EMUMMC: + return &emu_gpt; + } + return NULL; } \ No newline at end of file diff --git a/source/tegraexplorer/emmc/emmc.h b/source/tegraexplorer/emmc/emmc.h index 5410bb4..2bbb03c 100644 --- a/source/tegraexplorer/emmc/emmc.h +++ b/source/tegraexplorer/emmc/emmc.h @@ -1,5 +1,6 @@ #pragma once #include "../../utils/types.h" +#include "../../utils/list.h" typedef struct _pkg1_info { short ver; @@ -15,6 +16,8 @@ int mount_mmc(const char *partition, const int biskeynumb); void connect_mmc(short mmctype); void disconnect_mmc(); int connect_part(const char *partition); +void dumpEmuGpt(); +link_t *selectGpt(short mmcType); static const u8 zeros[0x10] = {0}; diff --git a/source/tegraexplorer/emmc/emmcmenu.c b/source/tegraexplorer/emmc/emmcmenu.c new file mode 100644 index 0000000..61c94af --- /dev/null +++ b/source/tegraexplorer/emmc/emmcmenu.c @@ -0,0 +1,118 @@ +#include +#include "emmc.h" +#include "../../mem/heap.h" +#include "../../utils/types.h" +#include "../../libs/fatfs/ff.h" +#include "../../utils/sprintf.h" +#include "../../utils/btn.h" +#include "../../gfx/gfx.h" +#include "../../utils/util.h" +#include "../../hos/pkg1.h" +#include "../../storage/sdmmc.h" +#include "../../storage/nx_emmc.h" +#include "../../sec/tsec.h" +#include "../../soc/t210.h" +#include "../../soc/fuse.h" +#include "../../mem/mc.h" +#include "../../sec/se.h" +#include "../../soc/hw_init.h" +#include "../../mem/emc.h" +#include "../../mem/sdram.h" +#include "../../storage/emummc.h" +#include "../../config/config.h" +#include "../common/common.h" +#include "../gfx/gfxutils.h" +#include "../../utils/list.h" +#include "../../mem/heap.h" +#include "emmcmenu.h" +#include "../fs/fsreader.h" +#include "../utils/utils.h" +#include "../gfx/menu.h" +#include "../fs/fsmenu.h" + +menu_entry *mmcMenuEntries = NULL; + +int checkGptRules(char *in){ + for (int i = 0; gpt_fs_rules[i].name != NULL; i++){ + if (!strcmp(in, gpt_fs_rules[i].name)) + return gpt_fs_rules[i].property; + } + return 0; +} + +void addEntry(emmc_part_t *part, u8 property, int spot){ + if (mmcMenuEntries[spot].name != NULL){ + free(mmcMenuEntries[spot].name); + } + + utils_copystring(part->name, &mmcMenuEntries[spot].name); + + if (property & isFS){ + mmcMenuEntries[spot].storage = (u32)(property & 0x7F); + mmcMenuEntries[spot].property = ISDIR; + } + else { + u64 size = 0; + int sizes = 0; + mmcMenuEntries[spot].property = 0; + size = (part->lba_end + 1 - part->lba_start) * NX_EMMC_BLOCKSIZE; + + while (size > 1024){ + size /= 1024; + sizes++; + } + + if (sizes > 3) + sizes = 0; + + mmcMenuEntries[spot].property |= (1 << (4 + sizes)); + mmcMenuEntries[spot].storage = (u32)size; + } +} + +int fillMmcMenu(short mmcType){ + int count = 2, i; + + if (mmcMenuEntries != NULL) + clearfileobjects(&mmcMenuEntries); + + link_t *gpt = selectGpt(mmcType); + + LIST_FOREACH_ENTRY(emmc_part_t, part, gpt, link) + count++; + + createfileobjects(count, &mmcMenuEntries); + + for (i = 0; i < 2; i++){ + utils_copystring(mmcmenu_start[i].name, &mmcMenuEntries[i].name); + mmcMenuEntries[i].property = mmcmenu_start[i].property; + mmcMenuEntries[i].storage = mmcmenu_start[i].storage; + } + + LIST_FOREACH_ENTRY(emmc_part_t, part, gpt, link){ + addEntry(part, checkGptRules(part->name), i++); + } + + return count; +} + +int makeMmcMenu(short mmcType){ + int count, selection; + count = fillMmcMenu(mmcType); + connect_mmc(mmcType); + while (1){ + selection = menu_make(mmcMenuEntries, count, (mmcType == SYSMMC) ? "-- SYSMMC --" : "-- EMUMMC --"); + + switch(selection){ + case 0: + return 0; + case 1: + break; //stubbed + default: + if (mmcMenuEntries[selection].property & ISDIR){ + if (!mount_mmc(mmcMenuEntries[selection].name, mmcMenuEntries[selection].storage)) + fileexplorer("emmc:/", 1); + } + } + } +} \ No newline at end of file diff --git a/source/tegraexplorer/emmc/emmcmenu.h b/source/tegraexplorer/emmc/emmcmenu.h new file mode 100644 index 0000000..7f4e131 --- /dev/null +++ b/source/tegraexplorer/emmc/emmcmenu.h @@ -0,0 +1,3 @@ +#pragma once + +int makeMmcMenu(short mmcType); \ No newline at end of file diff --git a/source/tegraexplorer/fs/fsreader.c b/source/tegraexplorer/fs/fsreader.c index f2089dc..4ed1e61 100644 --- a/source/tegraexplorer/fs/fsreader.c +++ b/source/tegraexplorer/fs/fsreader.c @@ -29,20 +29,20 @@ void fsreader_writeclipboard(const char *in, u8 args){ utils_copystring(in, &clipboard); } -void clearfileobjects(){ - if (fsreader_files != NULL){ - for (int i = 0; fsreader_files[i].name != NULL; i++){ - free(fsreader_files[i].name); - fsreader_files[i].name = NULL; +void clearfileobjects(menu_entry **menu){ + if ((*menu) != NULL){ + for (int i = 0; (*menu)[i].name != NULL; i++){ + free((*menu)[i].name); + (*menu)[i].name = NULL; } - free(fsreader_files); - fsreader_files = NULL; + free((*menu)); + (*menu) = NULL; } } -void createfileobjects(int size){ - fsreader_files = calloc (size + 1, sizeof(menu_entry)); - fsreader_files[size].name = NULL; +void createfileobjects(int size, menu_entry **menu){ + (*menu) = calloc (size + 1, sizeof(menu_entry)); + (*menu)[size].name = NULL; } void addobject(char* name, int spot, u8 attribs){ @@ -83,8 +83,8 @@ int fsreader_readfolder(const char *path){ FILINFO fno; int folderamount, res; - clearfileobjects(); - createfileobjects(fsutil_getfolderentryamount(path) + 3); + clearfileobjects(&fsreader_files); + createfileobjects(fsutil_getfolderentryamount(path) + 3, &fsreader_files); for (folderamount = 0; folderamount < 3; folderamount++){ utils_copystring(fs_menu_startdir[folderamount].name, &(fsreader_files[folderamount].name)); diff --git a/source/tegraexplorer/fs/fsreader.h b/source/tegraexplorer/fs/fsreader.h index e7356dd..fa5bedd 100644 --- a/source/tegraexplorer/fs/fsreader.h +++ b/source/tegraexplorer/fs/fsreader.h @@ -4,4 +4,7 @@ extern menu_entry *fsreader_files; void fsreader_writecurpath(const char *in); void fsreader_writeclipboard(const char *in, u8 args); -int fsreader_readfolder(const char *path); \ No newline at end of file +int fsreader_readfolder(const char *path); + +void createfileobjects(int size, menu_entry **menu); +void clearfileobjects(menu_entry **menu); \ No newline at end of file diff --git a/source/tegraexplorer/mainmenu.c b/source/tegraexplorer/mainmenu.c index 5991df2..3acd1f7 100644 --- a/source/tegraexplorer/mainmenu.c +++ b/source/tegraexplorer/mainmenu.c @@ -16,6 +16,7 @@ #include "fs/fsutils.h" #include "fs/fsmenu.h" #include "emmc/emmcoperations.h" +#include "emmc/emmcmenu.h" extern bool sd_mount(); extern void sd_unmount(); @@ -33,18 +34,24 @@ void MainMenu_EMMC(){ gfx_clearscreen(); gfx_printf("You're about to enter EMMC\nModifying anything here\n can result in a BRICK!\n\nPlease only continue\n if you know what you're doing\n\nPress Vol+/- to return\n"); if (gfx_makewaitmenu("Press Power to enter", 4)){ + /* connect_mmc(SYSMMC); if (!mount_mmc(emmc_fs_entries[res - 2], res - 1)) fileexplorer("emmc:/", 1); + */ + makeMmcMenu(SYSMMC); } } void MainMenu_EMUMMC(){ + /* connect_mmc(EMUMMC); if (!mount_mmc(emmc_fs_entries[res - 5], res - 4)) - fileexplorer("emmc:/", 1); + fileexplorer("emmc:/", 1); + */ + makeMmcMenu(EMUMMC); } void MainMenu_MountSD(){ @@ -61,6 +68,7 @@ void MainMenu_Tools(){ break; case TOOLS_DISPLAY_GPIO: displaygpio(); + //makeMmcMenu(SYSMMC); break; case TOOLS_DUMPFIRMWARE: dumpfirmware(SYSMMC); @@ -130,10 +138,6 @@ void MainMenu_Exit(){ func_void_ptr mainmenu_functions[] = { MainMenu_SDCard, MainMenu_EMMC, - MainMenu_EMMC, - MainMenu_EMMC, - MainMenu_EMUMMC, - MainMenu_EMUMMC, MainMenu_EMUMMC, MainMenu_MountSD, MainMenu_Tools, @@ -143,7 +147,7 @@ func_void_ptr mainmenu_functions[] = { }; void RunMenuOption(int option){ - if (option != 11) + if (option != 7) meter = 0; if (option > 0) mainmenu_functions[option - 1](); @@ -153,14 +157,14 @@ void te_main(){ if (dump_biskeys() == -1){ gfx_errDisplay("dump_biskey", ERR_BISKEY_DUMP_FAILED, 0); - for (int i = 1; i <= 3; i++) - mainmenu_main[i].property |= ISHIDE; + mainmenu_main[1].property |= ISHIDE; } if (emummc_load_cfg()){ - for (int i = 4; i <= 6; i++) - mainmenu_main[i].property |= ISHIDE; + mainmenu_main[2].property |= ISHIDE; } + else + dumpEmuGpt(); disconnect_mmc(); @@ -170,17 +174,16 @@ void te_main(){ setter = sd_mounted; if (emu_cfg.enabled){ - for (int i = 4; i <= 6; i++) - SETBIT(mainmenu_main[i].property, ISHIDE, !setter); + SETBIT(mainmenu_main[2].property, ISHIDE, !setter); } SETBIT(mainmenu_main[0].property, ISHIDE, !setter); - mainmenu_main[7].name = (menu_sd_states[!setter]); + mainmenu_main[3].name = (menu_sd_states[!setter]); setter = sd_inited; - SETBIT(mainmenu_main[9].property, ISHIDE, !setter); + SETBIT(mainmenu_main[5].property, ISHIDE, !setter); - res = menu_make(mainmenu_main, 12, "-- Main Menu --") + 1; + res = menu_make(mainmenu_main, 8, "-- Main Menu --") + 1; RunMenuOption(res); } } \ No newline at end of file From a6eaa1ec518c49ff176483232a22fb59a590932d Mon Sep 17 00:00:00 2001 From: "Such Meme, Many Skill" Date: Sat, 4 Apr 2020 18:40:27 +0200 Subject: [PATCH 2/6] Implement dumping of partitions --- source/tegraexplorer/common/common.h | 4 +- source/tegraexplorer/common/structs.c | 10 ++++- source/tegraexplorer/common/types.h | 3 +- source/tegraexplorer/emmc/emmcdumpbis.c | 48 +++++++++++++++++----- source/tegraexplorer/emmc/emmcmenu.c | 34 +++++++++++++-- source/tegraexplorer/emmc/emmcoperations.h | 3 +- source/tegraexplorer/gfx/menu.c | 1 - 7 files changed, 85 insertions(+), 18 deletions(-) diff --git a/source/tegraexplorer/common/common.h b/source/tegraexplorer/common/common.h index 1197fac..c8d1947 100644 --- a/source/tegraexplorer/common/common.h +++ b/source/tegraexplorer/common/common.h @@ -108,4 +108,6 @@ extern menu_entry fs_menu_startdir[]; extern gpt_entry_rule gpt_fs_rules[]; -extern menu_entry mmcmenu_start[]; \ No newline at end of file +extern menu_entry mmcmenu_start[]; + +extern menu_entry mmcmenu_filemenu[]; \ No newline at end of file diff --git a/source/tegraexplorer/common/structs.c b/source/tegraexplorer/common/structs.c index 12febb6..6fa0f43 100644 --- a/source/tegraexplorer/common/structs.c +++ b/source/tegraexplorer/common/structs.c @@ -81,5 +81,13 @@ gpt_entry_rule gpt_fs_rules[] = { menu_entry mmcmenu_start[] = { {"Back", COLOR_ORANGE, ISMENU}, - {"RESERVED\n", COLOR_ORANGE, ISMENU} + {"RESERVED\n", COLOR_ORANGE, ISMENU}, + {"BOOT0/1", COLOR_BLUE, isBOOT | ISMENU} +}; + +menu_entry mmcmenu_filemenu[] = { + {"Part:", COLOR_ORANGE, ISSKIP | ISMENU}, + {NULL, COLOR_VIOLET, ISSKIP | ISMENU}, + {"\nBack", COLOR_WHITE, ISMENU}, + {"Dump to SD", COLOR_YELLOW, ISMENU} }; \ No newline at end of file diff --git a/source/tegraexplorer/common/types.h b/source/tegraexplorer/common/types.h index 699cb87..7d9814e 100644 --- a/source/tegraexplorer/common/types.h +++ b/source/tegraexplorer/common/types.h @@ -50,4 +50,5 @@ typedef struct { u8 property; } gpt_entry_rule; -#define isFS 0x80 \ No newline at end of file +#define isFS 0x80 +#define isBOOT 0x2 \ No newline at end of file diff --git a/source/tegraexplorer/emmc/emmcdumpbis.c b/source/tegraexplorer/emmc/emmcdumpbis.c index 35f21a6..563d174 100644 --- a/source/tegraexplorer/emmc/emmcdumpbis.c +++ b/source/tegraexplorer/emmc/emmcdumpbis.c @@ -68,11 +68,24 @@ int dump_emmc_part(char *path, sdmmc_storage_t *mmcstorage, emmc_part_t *part){ return 0; } +int existsCheck(char *path){ + int res = 0; + + if (fsutil_checkfile(path)){ + gfx_printf("File already exists! Overwrite?\nVol +/- to cancel\n"); + res = gfx_makewaitmenu("Power to continue", 3); + gfx_printf("\r \r"); + return res; + } + + return 1; +} + int dump_emmc_parts(u16 parts, u8 mmctype){ char *path; - char basepath[] = "sd:/tegraexplorer/dumps"; + char basepath[] = "sd:/tegraexplorer/partition_dumps"; f_mkdir("sd:/tegraexplorer"); - f_mkdir("sd:/tegraexplorer/dumps"); + f_mkdir("sd:/tegraexplorer/partition_dumps"); connect_mmc(mmctype); gfx_clearscreen(); @@ -92,29 +105,44 @@ int dump_emmc_parts(u16 parts, u8 mmctype){ emummc_storage_set_mmc_partition(&storage, i + 1); utils_copystring(fsutil_getnextloc(basepath, bootPart.name), &path); + + if (!existsCheck(path)) + continue; + gfx_printf("Dumping %s\n", bootPart.name); dump_emmc_part(path, &storage, &bootPart); free(path); } + emummc_storage_set_mmc_partition(&storage, 0); } if (parts & PART_PKG2){ for (int i = 0; i < 6; i++){ - if (connect_part(pkg2names[i])){ - gfx_errDisplay("dump_emmc_parts", ERR_PART_NOT_FOUND, 0); - return -1; - } + utils_copystring(fsutil_getnextloc(basepath, pkg2names[i]), &path); + gfx_printf("Dumping %s\n", pkg2names[i]); - utils_copystring(fsutil_getnextloc(basepath, system_part->name), &path); - gfx_printf("Dumping %s\n", system_part->name); - - dump_emmc_part(path, &storage, system_part); + dump_emmc_specific(pkg2names[i], path); free(path); } } gfx_printf("\nDone!"); btn_wait(); + return 0; +} + +int dump_emmc_specific(char *part, char *path){ + if (!existsCheck(path)) + return 0; + + emummc_storage_set_mmc_partition(&storage, 0); + if (connect_part(part)){ + gfx_errDisplay("dump_emmc_specific", ERR_PART_NOT_FOUND, 0); + return 1; + } + + dump_emmc_part(path, &storage, system_part); + return 0; } \ No newline at end of file diff --git a/source/tegraexplorer/emmc/emmcmenu.c b/source/tegraexplorer/emmc/emmcmenu.c index 61c94af..080f19e 100644 --- a/source/tegraexplorer/emmc/emmcmenu.c +++ b/source/tegraexplorer/emmc/emmcmenu.c @@ -29,6 +29,8 @@ #include "../utils/utils.h" #include "../gfx/menu.h" #include "../fs/fsmenu.h" +#include "emmcoperations.h" +#include "../fs/fsutils.h" menu_entry *mmcMenuEntries = NULL; @@ -71,7 +73,7 @@ void addEntry(emmc_part_t *part, u8 property, int spot){ } int fillMmcMenu(short mmcType){ - int count = 2, i; + int count = 3, i; if (mmcMenuEntries != NULL) clearfileobjects(&mmcMenuEntries); @@ -83,7 +85,7 @@ int fillMmcMenu(short mmcType){ createfileobjects(count, &mmcMenuEntries); - for (i = 0; i < 2; i++){ + for (i = 0; i < 3; i++){ utils_copystring(mmcmenu_start[i].name, &mmcMenuEntries[i].name); mmcMenuEntries[i].property = mmcmenu_start[i].property; mmcMenuEntries[i].storage = mmcmenu_start[i].storage; @@ -112,7 +114,33 @@ int makeMmcMenu(short mmcType){ if (mmcMenuEntries[selection].property & ISDIR){ if (!mount_mmc(mmcMenuEntries[selection].name, mmcMenuEntries[selection].storage)) fileexplorer("emmc:/", 1); - } + } + else { + if (mmcmenu_filemenu[1].name != NULL) + free(mmcmenu_filemenu[1].name); + + utils_copystring(mmcMenuEntries[selection].name, &mmcmenu_filemenu[1].name); + + if ((menu_make(mmcmenu_filemenu, 4, "-- RAW PARTITION --")) < 3){ + break; + } + + if (mmcMenuEntries[selection].property & isBOOT){ + dump_emmc_parts(PART_BOOT, (u8)mmcType); + } + else { + f_mkdir("sd:/tegraexplorer"); + f_mkdir("sd:/tegraexplorer/partition_dumps"); + + gfx_clearscreen(); + gfx_printf("Dumping %s...\n", mmcMenuEntries[selection].name); + + if (!dump_emmc_specific(mmcMenuEntries[selection].name, fsutil_getnextloc("sd:/tegraexplorer/partition_dumps", mmcMenuEntries[selection].name))){ + gfx_printf("\nDone!"); + btn_wait(); + } + } + } } } } \ No newline at end of file diff --git a/source/tegraexplorer/emmc/emmcoperations.h b/source/tegraexplorer/emmc/emmcoperations.h index 05f5e0e..64eb784 100644 --- a/source/tegraexplorer/emmc/emmcoperations.h +++ b/source/tegraexplorer/emmc/emmcoperations.h @@ -2,4 +2,5 @@ #include "../../utils/types.h" int dump_emmc_parts(u16 parts, u8 mmctype); -int restore_bis_using_file(char *path, u8 mmctype); \ No newline at end of file +int restore_bis_using_file(char *path, u8 mmctype); +int dump_emmc_specific(char *part, char *path); \ No newline at end of file diff --git a/source/tegraexplorer/gfx/menu.c b/source/tegraexplorer/gfx/menu.c index a85e6df..4fd7c46 100644 --- a/source/tegraexplorer/gfx/menu.c +++ b/source/tegraexplorer/gfx/menu.c @@ -6,7 +6,6 @@ #include "../../utils/util.h" #include "../../mem/minerva.h" #include "../../soc/gpio.h" -#include "gfxutils.h" extern void sd_unmount(); extern bool sd_inited; From 97bbe2a3333fce25b656b753c8e5484045322879 Mon Sep 17 00:00:00 2001 From: "Such Meme, Many Skill" Date: Sat, 4 Apr 2020 22:15:13 +0200 Subject: [PATCH 3/6] Add partition restoring via clipboard --- source/tegraexplorer/common/common.h | 4 +- source/tegraexplorer/common/strings.c | 4 +- source/tegraexplorer/common/structs.c | 2 +- source/tegraexplorer/emmc/emmcmenu.c | 129 ++++++++++++++++----- source/tegraexplorer/emmc/emmcoperations.h | 4 +- source/tegraexplorer/emmc/emmcrestorebis.c | 1 + source/tegraexplorer/gfx/gfxutils.c | 2 +- 7 files changed, 111 insertions(+), 35 deletions(-) diff --git a/source/tegraexplorer/common/common.h b/source/tegraexplorer/common/common.h index c8d1947..b0e97d0 100644 --- a/source/tegraexplorer/common/common.h +++ b/source/tegraexplorer/common/common.h @@ -21,7 +21,9 @@ enum utils_err_codes_te_call { ERR_EMMC_WRITE_FAILED, ERR_FILE_TOO_BIG_FOR_DEST, ERR_SD_EJECTED, - ERR_PARSE_FAIL + ERR_PARSE_FAIL, + ERR_CANNOT_COPY_FILE_TO_FS_PART, + ERR_NO_DESTENATION }; extern const char *utils_err_codes_te[]; diff --git a/source/tegraexplorer/common/strings.c b/source/tegraexplorer/common/strings.c index 5d25aee..86297f6 100644 --- a/source/tegraexplorer/common/strings.c +++ b/source/tegraexplorer/common/strings.c @@ -50,7 +50,9 @@ const char *utils_err_codes_te[] = { // these start at 50 "EMMC WRITE FAILED", "FILE TOO BIG FOR DEST", "SD EJECTED", - "PARSING FAILED" + "PARSING FAILED", + "CANNOT COPY FILE TO FS PART", + "NO DESTENATION" }; const char *pkg2names[] = { diff --git a/source/tegraexplorer/common/structs.c b/source/tegraexplorer/common/structs.c index 6fa0f43..89fc0ff 100644 --- a/source/tegraexplorer/common/structs.c +++ b/source/tegraexplorer/common/structs.c @@ -81,7 +81,7 @@ gpt_entry_rule gpt_fs_rules[] = { menu_entry mmcmenu_start[] = { {"Back", COLOR_ORANGE, ISMENU}, - {"RESERVED\n", COLOR_ORANGE, ISMENU}, + {"Clipboard -> Partition\n", COLOR_ORANGE, ISMENU}, {"BOOT0/1", COLOR_BLUE, isBOOT | ISMENU} }; diff --git a/source/tegraexplorer/emmc/emmcmenu.c b/source/tegraexplorer/emmc/emmcmenu.c index 080f19e..e5357cf 100644 --- a/source/tegraexplorer/emmc/emmcmenu.c +++ b/source/tegraexplorer/emmc/emmcmenu.c @@ -33,6 +33,10 @@ #include "../fs/fsutils.h" menu_entry *mmcMenuEntries = NULL; +extern sdmmc_storage_t storage; +extern emmc_part_t *system_part; +extern char *clipboard; +extern u8 clipboardhelper; int checkGptRules(char *in){ for (int i = 0; gpt_fs_rules[i].name != NULL; i++){ @@ -98,6 +102,90 @@ int fillMmcMenu(short mmcType){ return count; } +int handleEntries(short mmcType, menu_entry part){ + if (part.property & ISDIR){ + if (!mount_mmc(part.name, part.storage)) + fileexplorer("emmc:/", 1); + } + else { + if (mmcmenu_filemenu[1].name != NULL) + free(mmcmenu_filemenu[1].name); + + utils_copystring(part.name, &mmcmenu_filemenu[1].name); + + if ((menu_make(mmcmenu_filemenu, 4, "-- RAW PARTITION --")) < 3) + return 0; + + if (part.property & isBOOT){ + dump_emmc_parts(PART_BOOT, (u8)mmcType); + } + else { + f_mkdir("sd:/tegraexplorer"); + f_mkdir("sd:/tegraexplorer/partition_dumps"); + + gfx_clearscreen(); + gfx_printf("Dumping %s...\n", part.name); + + if (!dump_emmc_specific(part.name, fsutil_getnextloc("sd:/tegraexplorer/partition_dumps", part.name))){ + gfx_printf("\nDone!"); + btn_wait(); + } + } + } + + return 0; +} + +emmc_part_t *mmcFindPart(char *path, short mmcType){ + char *filename, *extention; + emmc_part_t *part; + filename = strrchr(path, '/') + 1; + extention = strrchr(path, '.'); + + if (extention != NULL) + *extention = '\0'; + + if (checkGptRules(filename)){ + gfx_errDisplay("mmcFindPart", ERR_CANNOT_COPY_FILE_TO_FS_PART, 1); + return NULL; + } + + part = nx_emmc_part_find(selectGpt(mmcType), filename); + + if (part != NULL){ + emummc_storage_set_mmc_partition(&storage, 0); + return part; + } + + if (!strcmp(filename, "BOOT0") || !strcmp(filename, "BOOT1")){ + const u32 BOOT_PART_SIZE = storage.ext_csd.boot_mult << 17; + part = calloc(1, sizeof(emmc_part_t)); + + part->lba_start = 0; + part->lba_end = (BOOT_PART_SIZE / NX_EMMC_BLOCKSIZE) - 1; + + strcpy(part->name, filename); + + emummc_storage_set_mmc_partition(&storage, (!strcmp(filename, "BOOT0")) ? 1 : 2); + return part; + } + + //gfx_printf("Path: %s\nFilename: %s", path, filename); + //btn_wait(); + gfx_errDisplay("mmcFindPart", ERR_NO_DESTENATION, 2); + return NULL; +} + +int mmcFlashFile(char *path, short mmcType){ + emmc_part_t *part; + part = mmcFindPart(path, mmcType); + if (part != NULL){ + return restore_emmc_part(path, &storage, part); + } + clipboardhelper = 0; + return 1; +} + int makeMmcMenu(short mmcType){ int count, selection; count = fillMmcMenu(mmcType); @@ -109,38 +197,19 @@ int makeMmcMenu(short mmcType){ case 0: return 0; case 1: + if (!(clipboardhelper & ISDIR) && (clipboardhelper & OPERATIONCOPY)){ + gfx_clearscreen(); + if (!mmcFlashFile(clipboard, mmcType)){ + gfx_printf("\nDone!"); + btn_wait(); + } + } + else + gfx_errDisplay("mmcMenu", ERR_EMPTY_CLIPBOARD, 0); break; //stubbed default: - if (mmcMenuEntries[selection].property & ISDIR){ - if (!mount_mmc(mmcMenuEntries[selection].name, mmcMenuEntries[selection].storage)) - fileexplorer("emmc:/", 1); - } - else { - if (mmcmenu_filemenu[1].name != NULL) - free(mmcmenu_filemenu[1].name); - - utils_copystring(mmcMenuEntries[selection].name, &mmcmenu_filemenu[1].name); - - if ((menu_make(mmcmenu_filemenu, 4, "-- RAW PARTITION --")) < 3){ - break; - } - - if (mmcMenuEntries[selection].property & isBOOT){ - dump_emmc_parts(PART_BOOT, (u8)mmcType); - } - else { - f_mkdir("sd:/tegraexplorer"); - f_mkdir("sd:/tegraexplorer/partition_dumps"); - - gfx_clearscreen(); - gfx_printf("Dumping %s...\n", mmcMenuEntries[selection].name); - - if (!dump_emmc_specific(mmcMenuEntries[selection].name, fsutil_getnextloc("sd:/tegraexplorer/partition_dumps", mmcMenuEntries[selection].name))){ - gfx_printf("\nDone!"); - btn_wait(); - } - } - } + handleEntries(mmcType, mmcMenuEntries[selection]); + break; } } } \ No newline at end of file diff --git a/source/tegraexplorer/emmc/emmcoperations.h b/source/tegraexplorer/emmc/emmcoperations.h index 64eb784..a616860 100644 --- a/source/tegraexplorer/emmc/emmcoperations.h +++ b/source/tegraexplorer/emmc/emmcoperations.h @@ -1,6 +1,8 @@ #pragma once #include "../../utils/types.h" +#include "../../storage/nx_emmc.h" int dump_emmc_parts(u16 parts, u8 mmctype); int restore_bis_using_file(char *path, u8 mmctype); -int dump_emmc_specific(char *part, char *path); \ No newline at end of file +int dump_emmc_specific(char *part, char *path); +int restore_emmc_part(char *path, sdmmc_storage_t *mmcstorage, emmc_part_t *part); \ No newline at end of file diff --git a/source/tegraexplorer/emmc/emmcrestorebis.c b/source/tegraexplorer/emmc/emmcrestorebis.c index 10ddefd..176d4ba 100644 --- a/source/tegraexplorer/emmc/emmcrestorebis.c +++ b/source/tegraexplorer/emmc/emmcrestorebis.c @@ -105,6 +105,7 @@ int restore_emmc_part(char *path, sdmmc_storage_t *mmcstorage, emmc_part_t *part return 0; } +// function replaced by new mmc implementation. Will be removed at some point int restore_emmc_file(char *path, const char *target, u8 partition, u8 mmctype){ connect_mmc(mmctype); diff --git a/source/tegraexplorer/gfx/gfxutils.c b/source/tegraexplorer/gfx/gfxutils.c index 72a04f9..cf58a7a 100644 --- a/source/tegraexplorer/gfx/gfxutils.c +++ b/source/tegraexplorer/gfx/gfxutils.c @@ -54,7 +54,7 @@ int gfx_errDisplay(char *src_func, int err, int loc){ if (err < 15) gfx_printf("Desc: %s\n", utils_err_codes[err]); - else if (err >= ERR_SAME_LOC && err <= ERR_PARSE_FAIL) + else if (err >= ERR_SAME_LOC && err <= ERR_NO_DESTENATION) gfx_printf("Desc: %s\n", utils_err_codes_te[err - 50]); if (loc) From 7dc3500a17844e4160149bfdab40a701fa94b60d Mon Sep 17 00:00:00 2001 From: "Such Meme, Many Skill" Date: Sat, 4 Apr 2020 23:41:09 +0200 Subject: [PATCH 4/6] [script] add mmc_dumpPart() and mmc_restorePart() --- source/tegraexplorer/emmc/emmcdumpbis.c | 33 ++++++++++++++++++++-- source/tegraexplorer/emmc/emmcmenu.c | 27 ++++++++++-------- source/tegraexplorer/emmc/emmcmenu.h | 3 +- source/tegraexplorer/emmc/emmcoperations.h | 5 ++-- source/tegraexplorer/script/functions.c | 33 ++++++++++++++++++++++ 5 files changed, 85 insertions(+), 16 deletions(-) diff --git a/source/tegraexplorer/emmc/emmcdumpbis.c b/source/tegraexplorer/emmc/emmcdumpbis.c index 563d174..c11f157 100644 --- a/source/tegraexplorer/emmc/emmcdumpbis.c +++ b/source/tegraexplorer/emmc/emmcdumpbis.c @@ -122,7 +122,7 @@ int dump_emmc_parts(u16 parts, u8 mmctype){ utils_copystring(fsutil_getnextloc(basepath, pkg2names[i]), &path); gfx_printf("Dumping %s\n", pkg2names[i]); - dump_emmc_specific(pkg2names[i], path); + emmcDumpSpecific(pkg2names[i], path); free(path); } } @@ -132,7 +132,36 @@ int dump_emmc_parts(u16 parts, u8 mmctype){ return 0; } -int dump_emmc_specific(char *part, char *path){ +int emmcDumpBoot(char *basePath){ + emmc_part_t bootPart; + const u32 BOOT_PART_SIZE = storage.ext_csd.boot_mult << 17; + char *path; + memset(&bootPart, 0, sizeof(emmc_part_t)); + + bootPart.lba_start = 0; + bootPart.lba_end = (BOOT_PART_SIZE / NX_EMMC_BLOCKSIZE) - 1; + + for (int i = 0; i < 2; i++){ + strcpy(bootPart.name, "BOOT"); + bootPart.name[4] = (u8)('0' + i); + bootPart.name[5] = 0; + + emummc_storage_set_mmc_partition(&storage, i + 1); + utils_copystring(fsutil_getnextloc(basePath, bootPart.name), &path); + + if (!existsCheck(path)) + continue; + + gfx_printf("Dumping %s\n", bootPart.name); + + dump_emmc_part(path, &storage, &bootPart); + free(path); + } + emummc_storage_set_mmc_partition(&storage, 0); + return 0; +} + +int emmcDumpSpecific(char *part, char *path){ if (!existsCheck(path)) return 0; diff --git a/source/tegraexplorer/emmc/emmcmenu.c b/source/tegraexplorer/emmc/emmcmenu.c index e5357cf..2fdf955 100644 --- a/source/tegraexplorer/emmc/emmcmenu.c +++ b/source/tegraexplorer/emmc/emmcmenu.c @@ -103,6 +103,8 @@ int fillMmcMenu(short mmcType){ } int handleEntries(short mmcType, menu_entry part){ + int res = 0; + if (part.property & ISDIR){ if (!mount_mmc(part.name, part.storage)) fileexplorer("emmc:/", 1); @@ -116,20 +118,22 @@ int handleEntries(short mmcType, menu_entry part){ if ((menu_make(mmcmenu_filemenu, 4, "-- RAW PARTITION --")) < 3) return 0; + f_mkdir("sd:/tegraexplorer"); + f_mkdir("sd:/tegraexplorer/partition_dumps"); + + gfx_clearscreen(); + if (part.property & isBOOT){ - dump_emmc_parts(PART_BOOT, (u8)mmcType); + res = emmcDumpBoot("sd:/tegraexplorer/partition_dumps"); } else { - f_mkdir("sd:/tegraexplorer"); - f_mkdir("sd:/tegraexplorer/partition_dumps"); - - gfx_clearscreen(); gfx_printf("Dumping %s...\n", part.name); + res = emmcDumpSpecific(part.name, fsutil_getnextloc("sd:/tegraexplorer/partition_dumps", part.name)); + } - if (!dump_emmc_specific(part.name, fsutil_getnextloc("sd:/tegraexplorer/partition_dumps", part.name))){ - gfx_printf("\nDone!"); - btn_wait(); - } + if (!res){ + gfx_printf("\nDone!"); + btn_wait(); } } @@ -182,7 +186,6 @@ int mmcFlashFile(char *path, short mmcType){ if (part != NULL){ return restore_emmc_part(path, &storage, part); } - clipboardhelper = 0; return 1; } @@ -194,6 +197,7 @@ int makeMmcMenu(short mmcType){ selection = menu_make(mmcMenuEntries, count, (mmcType == SYSMMC) ? "-- SYSMMC --" : "-- EMUMMC --"); switch(selection){ + case -1: case 0: return 0; case 1: @@ -203,10 +207,11 @@ int makeMmcMenu(short mmcType){ gfx_printf("\nDone!"); btn_wait(); } + clipboardhelper = 0; } else gfx_errDisplay("mmcMenu", ERR_EMPTY_CLIPBOARD, 0); - break; //stubbed + break; default: handleEntries(mmcType, mmcMenuEntries[selection]); break; diff --git a/source/tegraexplorer/emmc/emmcmenu.h b/source/tegraexplorer/emmc/emmcmenu.h index 7f4e131..b5830f7 100644 --- a/source/tegraexplorer/emmc/emmcmenu.h +++ b/source/tegraexplorer/emmc/emmcmenu.h @@ -1,3 +1,4 @@ #pragma once -int makeMmcMenu(short mmcType); \ No newline at end of file +int makeMmcMenu(short mmcType); +int mmcFlashFile(char *path, short mmcType); \ No newline at end of file diff --git a/source/tegraexplorer/emmc/emmcoperations.h b/source/tegraexplorer/emmc/emmcoperations.h index a616860..97c49e5 100644 --- a/source/tegraexplorer/emmc/emmcoperations.h +++ b/source/tegraexplorer/emmc/emmcoperations.h @@ -4,5 +4,6 @@ int dump_emmc_parts(u16 parts, u8 mmctype); int restore_bis_using_file(char *path, u8 mmctype); -int dump_emmc_specific(char *part, char *path); -int restore_emmc_part(char *path, sdmmc_storage_t *mmcstorage, emmc_part_t *part); \ No newline at end of file +int emmcDumpSpecific(char *part, char *path); +int restore_emmc_part(char *path, sdmmc_storage_t *mmcstorage, emmc_part_t *part); +int emmcDumpBoot(char *basePath); \ No newline at end of file diff --git a/source/tegraexplorer/script/functions.c b/source/tegraexplorer/script/functions.c index 0efd63a..2b584e8 100644 --- a/source/tegraexplorer/script/functions.c +++ b/source/tegraexplorer/script/functions.c @@ -19,11 +19,14 @@ #include "../fs/fsutils.h" #include "../../utils/sprintf.h" #include "../fs/fsactions.h" +#include "../emmc/emmcoperations.h" +#include "../emmc/emmcmenu.h" extern FIL scriptin; extern char **argv; extern u32 argc; extern int forceExit; +extern short currentlyMounted; int parseIntInput(char *in, int *out){ if (in[0] == '@'){ @@ -462,6 +465,34 @@ int part_fs_combinePath(){ return 0; } +int part_mmc_dumpPart(){ + char *left, *right; + + if (parseStringInput(argv[0], &left)) + return -1; + if (parseStringInput(argv[1], &right)) + return -1; + + if (!strcmp(left, "BOOT")){ + return emmcDumpBoot(right); + } + else { + return emmcDumpSpecific(left, right); + } +} + +int part_mmc_restorePart(){ + char *path; + + if (parseStringInput(argv[0], &path)) + return -1; + + if (currentlyMounted < 0) + return -1; + + return mmcFlashFile(path, currentlyMounted); +} + str_fnc_struct functions[] = { {"printf", part_printf, 1}, {"printInt", part_print_int, 1}, @@ -490,6 +521,8 @@ str_fnc_struct functions[] = { {"fs_combinePath", part_fs_combinePath, 3}, {"mmc_connect", part_ConnectMMC, 1}, {"mmc_mount", part_MountMMC, 1}, + {"mmc_dumpPart", part_mmc_dumpPart, 2}, + {"mmc_restorePart", part_mmc_restorePart, 1}, {"pause", part_Pause, 0}, {"wait", part_Wait, 1}, {"exit", part_Exit, 0}, From 070f9c676d557693185be80139f000dd37b02ffd Mon Sep 17 00:00:00 2001 From: "Such Meme, Many Skill" Date: Sun, 5 Apr 2020 00:22:23 +0200 Subject: [PATCH 5/6] Bugfixes + relocate tools: dump bis --- source/tegraexplorer/common/common.h | 3 +- source/tegraexplorer/common/structs.c | 4 +-- source/tegraexplorer/emmc/emmcdumpbis.c | 7 +++++ source/tegraexplorer/emmc/emmcmenu.c | 36 +++++++++++++++++----- source/tegraexplorer/emmc/emmcoperations.h | 1 - source/tegraexplorer/mainmenu.c | 5 +-- 6 files changed, 40 insertions(+), 16 deletions(-) diff --git a/source/tegraexplorer/common/common.h b/source/tegraexplorer/common/common.h index b0e97d0..99df700 100644 --- a/source/tegraexplorer/common/common.h +++ b/source/tegraexplorer/common/common.h @@ -59,8 +59,7 @@ enum mainmenu_tools_return { TOOLS_DISPLAY_INFO = 1, TOOLS_DISPLAY_GPIO, TOOLS_DUMPFIRMWARE, - TOOLS_DUMPUSERSAVE, - TOOLS_DUMP_BOOT + TOOLS_DUMPUSERSAVE }; extern menu_entry mainmenu_tools[]; diff --git a/source/tegraexplorer/common/structs.c b/source/tegraexplorer/common/structs.c index 89fc0ff..acb2319 100644 --- a/source/tegraexplorer/common/structs.c +++ b/source/tegraexplorer/common/structs.c @@ -26,8 +26,7 @@ menu_entry mainmenu_tools[] = { {"\nDisplay Console Info", COLOR_GREEN, ISMENU}, {"Display GPIO pins", COLOR_VIOLET, ISMENU}, {"Dump Firmware", COLOR_BLUE, ISMENU}, - {"Dump User Saves", COLOR_YELLOW, ISMENU}, - {"Dump bis", COLOR_ORANGE, ISMENU} + {"Dump User Saves", COLOR_YELLOW, ISMENU} }; menu_entry mainmenu_format[] = { @@ -81,6 +80,7 @@ gpt_entry_rule gpt_fs_rules[] = { menu_entry mmcmenu_start[] = { {"Back", COLOR_ORANGE, ISMENU}, + {"Dump File Partitions", COLOR_ORANGE, ISMENU}, {"Clipboard -> Partition\n", COLOR_ORANGE, ISMENU}, {"BOOT0/1", COLOR_BLUE, isBOOT | ISMENU} }; diff --git a/source/tegraexplorer/emmc/emmcdumpbis.c b/source/tegraexplorer/emmc/emmcdumpbis.c index c11f157..36955dc 100644 --- a/source/tegraexplorer/emmc/emmcdumpbis.c +++ b/source/tegraexplorer/emmc/emmcdumpbis.c @@ -81,6 +81,7 @@ int existsCheck(char *path){ return 1; } +/* int dump_emmc_parts(u16 parts, u8 mmctype){ char *path; char basepath[] = "sd:/tegraexplorer/partition_dumps"; @@ -131,6 +132,7 @@ int dump_emmc_parts(u16 parts, u8 mmctype){ btn_wait(); return 0; } +*/ int emmcDumpBoot(char *basePath){ emmc_part_t bootPart; @@ -152,7 +154,9 @@ int emmcDumpBoot(char *basePath){ if (!existsCheck(path)) continue; + SWAPCOLOR(COLOR_BLUE); gfx_printf("Dumping %s\n", bootPart.name); + RESETCOLOR; dump_emmc_part(path, &storage, &bootPart); free(path); @@ -171,6 +175,9 @@ int emmcDumpSpecific(char *part, char *path){ return 1; } + SWAPCOLOR(COLOR_VIOLET); + gfx_printf("Dumping %s\n", part); + RESETCOLOR; dump_emmc_part(path, &storage, system_part); return 0; diff --git a/source/tegraexplorer/emmc/emmcmenu.c b/source/tegraexplorer/emmc/emmcmenu.c index 2fdf955..2f663a0 100644 --- a/source/tegraexplorer/emmc/emmcmenu.c +++ b/source/tegraexplorer/emmc/emmcmenu.c @@ -77,7 +77,7 @@ void addEntry(emmc_part_t *part, u8 property, int spot){ } int fillMmcMenu(short mmcType){ - int count = 3, i; + int count = 4, i; if (mmcMenuEntries != NULL) clearfileobjects(&mmcMenuEntries); @@ -89,7 +89,7 @@ int fillMmcMenu(short mmcType){ createfileobjects(count, &mmcMenuEntries); - for (i = 0; i < 3; i++){ + for (i = 0; i < 4; i++){ utils_copystring(mmcmenu_start[i].name, &mmcMenuEntries[i].name); mmcMenuEntries[i].property = mmcmenu_start[i].property; mmcMenuEntries[i].storage = mmcmenu_start[i].storage; @@ -127,7 +127,7 @@ int handleEntries(short mmcType, menu_entry part){ res = emmcDumpBoot("sd:/tegraexplorer/partition_dumps"); } else { - gfx_printf("Dumping %s...\n", part.name); + //gfx_printf("Dumping %s...\n", part.name); res = emmcDumpSpecific(part.name, fsutil_getnextloc("sd:/tegraexplorer/partition_dumps", part.name)); } @@ -141,16 +141,19 @@ int handleEntries(short mmcType, menu_entry part){ } emmc_part_t *mmcFindPart(char *path, short mmcType){ - char *filename, *extention; + char *filename, *extention, *path_local; emmc_part_t *part; - filename = strrchr(path, '/') + 1; - extention = strrchr(path, '.'); + + utils_copystring(path, &path_local); + filename = strrchr(path_local, '/') + 1; + extention = strrchr(path_local, '.'); if (extention != NULL) *extention = '\0'; if (checkGptRules(filename)){ gfx_errDisplay("mmcFindPart", ERR_CANNOT_COPY_FILE_TO_FS_PART, 1); + free(path_local); return NULL; } @@ -158,6 +161,7 @@ emmc_part_t *mmcFindPart(char *path, short mmcType){ if (part != NULL){ emummc_storage_set_mmc_partition(&storage, 0); + free(path_local); return part; } @@ -171,12 +175,14 @@ emmc_part_t *mmcFindPart(char *path, short mmcType){ strcpy(part->name, filename); emummc_storage_set_mmc_partition(&storage, (!strcmp(filename, "BOOT0")) ? 1 : 2); + free(path_local); return part; } //gfx_printf("Path: %s\nFilename: %s", path, filename); //btn_wait(); gfx_errDisplay("mmcFindPart", ERR_NO_DESTENATION, 2); + free(path_local); return NULL; } @@ -201,6 +207,22 @@ int makeMmcMenu(short mmcType){ case 0: return 0; case 1: + gfx_clearscreen(); + f_mkdir("sd:/tegraexplorer"); + f_mkdir("sd:/tegraexplorer/partition_dumps"); + + for (int i = 0; i < count; i++){ + if (mmcMenuEntries[i].property & ISMENU || mmcMenuEntries[i].property & ISDIR) + continue; + + //gfx_printf("Dumping %s...\n", mmcMenuEntries[i].name); + emmcDumpSpecific(mmcMenuEntries[i].name, fsutil_getnextloc("sd:/tegraexplorer/partition_dumps", mmcMenuEntries[i].name)); + } + + gfx_printf("\nDone!"); + btn_wait(); + break; + case 2: if (!(clipboardhelper & ISDIR) && (clipboardhelper & OPERATIONCOPY)){ gfx_clearscreen(); if (!mmcFlashFile(clipboard, mmcType)){ @@ -211,7 +233,7 @@ int makeMmcMenu(short mmcType){ } else gfx_errDisplay("mmcMenu", ERR_EMPTY_CLIPBOARD, 0); - break; + break; default: handleEntries(mmcType, mmcMenuEntries[selection]); break; diff --git a/source/tegraexplorer/emmc/emmcoperations.h b/source/tegraexplorer/emmc/emmcoperations.h index 97c49e5..3fed9ae 100644 --- a/source/tegraexplorer/emmc/emmcoperations.h +++ b/source/tegraexplorer/emmc/emmcoperations.h @@ -2,7 +2,6 @@ #include "../../utils/types.h" #include "../../storage/nx_emmc.h" -int dump_emmc_parts(u16 parts, u8 mmctype); int restore_bis_using_file(char *path, u8 mmctype); int emmcDumpSpecific(char *part, char *path); int restore_emmc_part(char *path, sdmmc_storage_t *mmcstorage, emmc_part_t *part); diff --git a/source/tegraexplorer/mainmenu.c b/source/tegraexplorer/mainmenu.c index 3acd1f7..acc8672 100644 --- a/source/tegraexplorer/mainmenu.c +++ b/source/tegraexplorer/mainmenu.c @@ -60,7 +60,7 @@ void MainMenu_MountSD(){ void MainMenu_Tools(){ //res = makemenu(toolsmenu, 8); - res = menu_make(mainmenu_tools, 6, "-- Tools Menu --"); + res = menu_make(mainmenu_tools, 5, "-- Tools Menu --"); switch(res){ case TOOLS_DISPLAY_INFO: @@ -78,9 +78,6 @@ void MainMenu_Tools(){ dumpusersaves(res); break; - case TOOLS_DUMP_BOOT: - dump_emmc_parts(PART_BOOT | PART_PKG2, SYSMMC); - break; } } From 03df13f34c85a8a9906a20cf07e08f17b6af9d90 Mon Sep 17 00:00:00 2001 From: "Such Meme, Many Skill" Date: Sun, 5 Apr 2020 00:33:12 +0200 Subject: [PATCH 6/6] don't forget to reset the clipboard helper --- source/tegraexplorer/fs/filemenu.c | 1 - source/tegraexplorer/fs/fsmenu.c | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/source/tegraexplorer/fs/filemenu.c b/source/tegraexplorer/fs/filemenu.c index 8a52f0e..ee1dbf7 100644 --- a/source/tegraexplorer/fs/filemenu.c +++ b/source/tegraexplorer/fs/filemenu.c @@ -111,7 +111,6 @@ void copyfile(const char *src_in, const char *outfolder){ free(out); free(filename); fsreader_readfolder(currentpath); - clipboardhelper = 0; } int filemenu(menu_entry file){ diff --git a/source/tegraexplorer/fs/fsmenu.c b/source/tegraexplorer/fs/fsmenu.c index 7a56e8b..91f30e9 100644 --- a/source/tegraexplorer/fs/fsmenu.c +++ b/source/tegraexplorer/fs/fsmenu.c @@ -48,6 +48,7 @@ void fileexplorer(const char *startpath, int type){ copyfolder(clipboard, currentpath); else copyfile(clipboard, currentpath); + clipboardhelper = 0; break; case FILEMENU_CURFOLDER: