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] 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;