Compare commits

...

21 Commits
1.0.0 ... 1.2.0

Author SHA1 Message Date
Such Meme, Many Skill
6724f364b5 Implement Tool for dumping User:/save
+ Finalize readme for release of 1.2.0
2020-01-07 21:53:02 +01:00
Such Meme, Many Skill
008d3ab494 Add file attributes to menus
+ fix a few misc things
+ bump version (readme isn't updated yet)
2020-01-07 15:28:23 +01:00
Such Meme, Many Skill
00bd1cd083 Split fs.c file
+ Misc changes to code in io.c
2020-01-06 18:42:57 +01:00
Such Meme, Many Skill
6af2bb63b8 Stop using an int to indicate dir size 2020-01-06 17:40:05 +01:00
Such Meme, Many Skill
02504c8a36 Make emmc writable + merge hekate fixes 2020-01-06 14:24:29 +01:00
Such Meme, Many Skill
ef76834ef4 Implement folder copy
+ Change error messaging internally
+ inproved recursive file deletion
2020-01-04 20:18:26 +01:00
Such Meme, Many Skill
6d75aa688c (Attempt at) dynamic folder memory allocation 2020-01-04 13:20:28 +01:00
Such Meme, Many Skill
225a17116c Fix memory leakage of getnextloc() and getprevloc() 2020-01-04 01:00:11 +01:00
Such Meme, Many Skill
e1f4c24686 Implement folder options (Delete folder) 2020-01-02 00:38:36 +01:00
suchmememanyskill
3e8cd67129 Add ko-fi link 2019-12-27 00:47:14 +01:00
Such Meme, Many Skill
697fc3a086 Do partition alignment, bump version to v1.1.1 2019-12-26 23:07:18 +01:00
Such Meme, Many Skill
6518f37b1c Bump version 2019-12-22 21:44:03 +01:00
Such Meme, Many Skill
81e97fa820 Mount other emmc parts 2019-12-22 12:10:59 +01:00
Such Meme, Many Skill
12802bf371 Make the user able to format without a valid partition 2019-12-20 21:00:47 +01:00
Such Meme, Many Skill
d1678be654 Make format options more clear 2019-12-18 16:14:14 +01:00
Such Meme, Many Skill
2a78d3c924 Fix folder scrolling issues 2019-12-18 16:02:45 +01:00
Such Meme, Many Skill
d4010ba04d Update Readme with support discords 2019-12-17 13:53:49 +01:00
Such Meme, Many Skill
7b6c19f820 Add check for <32gb sd cards for partitioning 2019-12-17 13:50:02 +01:00
Such Meme, Many Skill
3274d18b83 Add boot safety check, Add payload launching safety check
+ Add version info
2019-12-17 13:43:32 +01:00
Such Meme, Many Skill
472c0e293a Spice up Console Info menu 2019-12-16 23:31:29 +01:00
Such Meme, Many Skill
2e61413627 Reformat to 32k clusters instead of 8k clusters 2019-12-12 18:46:27 +01:00
21 changed files with 778 additions and 292 deletions

12
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1,12 @@
# These are supported funding model platforms
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: suchmememanyskill
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

View File

@@ -10,7 +10,7 @@ include $(DEVKITARM)/base_rules
IPL_LOAD_ADDR := 0x40003000
LPVERSION_MAJOR := 2
LPVERSION_MINOR := 0
LPVERSION_MINOR := 2
LPVERSION_BUGFX := 0
################################################################################

View File

@@ -9,16 +9,24 @@ Navigate around the menu's using the vol+, vol- and power buttons
## Functions
- Navigate the SD card
- Navigate the System partition of your sysnand
- Navigate the System partition of your sysnand/sysmmc
- Interact with files
- Deleting, copying or moving files
- Launching payloads files
- Viewing the hex data of a file
- Interacting with folders
- Deleting or copying folders
- Dumping your current firmware to sd
- Formatting the sd card
## Support
For general CFW support, go to the [Nintendo Homebrew](https://discord.gg/C29hYvh) discord
For question specifically for TegraExplorer, go to [my discord](https://discord.gg/aH9rsuP)
# Credits
Based on [Lockpick_RCM](https://github.com/shchmue/Lockpick_RCM), and thus based on [Hekate](https://github.com/CTCaer/hekate)
Based on [Lockpick_RCM](https://github.com/shchmue/Lockpick_RCM), and thus also based on [Hekate](https://github.com/CTCaer/hekate)
Lots of help from:
- shchmue

View File

@@ -188,7 +188,7 @@ void gfx_putc(char c)
for (u32 i = 0; i < 16; i+=2)
{
u8 v = *cbuf++;
u8 v = *cbuf;
for (u32 k = 0; k < 2; k++)
{
for (u32 j = 0; j < 8; j++)
@@ -213,6 +213,7 @@ void gfx_putc(char c)
fb += gfx_ctxt.stride - 16;
v = *cbuf;
}
cbuf++;
}
gfx_con.x += 16;
if (gfx_con.x >= gfx_ctxt.width - 16) {
@@ -329,15 +330,10 @@ void gfx_put_big_sep()
gfx_con.fntsz = prevFontSize;
}
void gfx_printf(const char *fmt, ...)
void gfx_vprintf(const char *fmt, va_list ap)
{
if (gfx_con.mute)
return;
va_list ap;
int fill, fcnt;
va_start(ap, fmt);
while(*fmt)
{
if(*fmt == '%')
@@ -389,7 +385,7 @@ void gfx_printf(const char *fmt, ...)
gfx_putc('%');
break;
case '\0':
goto out;
return;
default:
gfx_putc('%');
gfx_putc(*fmt);
@@ -400,8 +396,17 @@ void gfx_printf(const char *fmt, ...)
gfx_putc(*fmt);
fmt++;
}
}
void gfx_printf(const char *fmt, ...)
{
if (gfx_con.mute)
return;
va_list ap;
va_start(ap, fmt);
gfx_vprintf(fmt, ap);
out:
va_end(ap);
}

View File

@@ -20,6 +20,7 @@
#define _GFX_H_
#include "../../common/common_gfx.h"
#include <stdarg.h>
#define EPRINTF(text) gfx_printf("%k"text"%k\n", 0xFFFF0000, 0xFFCCCCCC)
#define EPRINTFARGS(text, args...) gfx_printf("%k"text"%k\n", 0xFFFF0000, args, 0xFFCCCCCC)
@@ -37,6 +38,7 @@ void gfx_con_setpos(u32 x, u32 y);
void gfx_putc(char c);
void gfx_puts(const char *s);
void gfx_printf(const char *fmt, ...);
void gfx_vprintf(const char *fmt, va_list ap);
void gfx_hexdump(u32 base, const u8 *buf, u32 len);
void gfx_set_pixel(u32 x, u32 y, u32 color);

View File

@@ -150,8 +150,8 @@ DRESULT disk_read (
__attribute__ ((aligned (16))) static u8 tweak[0x10];
__attribute__ ((aligned (16))) static u64 prev_cluster = -1;
__attribute__ ((aligned (16))) static u32 prev_sector = 0;
bool needs_cache_sector = false;
//bool needs_cache_sector = false;
/*
if (secindex == 0 || clear_sector_cache) {
if (!sector_cache)
sector_cache = (sector_cache_t *)malloc(sizeof(sector_cache_t) * MAX_SEC_CACHE_ENTRIES);
@@ -179,6 +179,7 @@ DRESULT disk_read (
secindex++;
}
}
*/
//system_part (pdrv == 1) ? system_part_sys : system_part_usr
if (nx_emmc_part_read(&storage, system_part, sector, count, buff)) {
u32 tweak_exp = 0;
@@ -195,10 +196,12 @@ DRESULT disk_read (
// fatfs will never pull more than a cluster
_emmc_xts(9, 8, 0, tweak, regen_tweak, tweak_exp, prev_cluster, buff, buff, count * 0x200);
/*
if (needs_cache_sector) {
memcpy(sector_cache[s].cached_sector, buff, 0x200);
memcpy(sector_cache[s].tweak, tweak, 0x10);
}
*/
prev_sector = sector + count - 1;
return RES_OK;
}
@@ -209,20 +212,46 @@ DRESULT disk_read (
DRESULT disk_write (
BYTE pdrv, /* Physical drive number to identify the drive */
const BYTE *buff, /* Data to be written */
BYTE *buff, /* Data to be written */
DWORD sector, /* Start sector in LBA */
UINT count /* Number of sectors to write */
)
{
if (pdrv == 1)
return RES_WRPRT;
switch (pdrv){
case 0:
if (((u32)buff >= DRAM_START) && !((u32)buff % 8))
return sdmmc_storage_write(&sd_storage, sector, count, (void *)buff) ? RES_OK : RES_ERROR;
u8 *buf = (u8 *)SDMMC_UPPER_BUFFER; //TODO: define this somewhere.
memcpy(buf, buff, 512 * count);
if (sdmmc_storage_write(&sd_storage, sector, count, buf))
return RES_OK;
return RES_ERROR;
case 1:;
__attribute__ ((aligned (16))) static u8 tweak[0x10];
__attribute__ ((aligned (16))) static u64 prev_cluster = -1;
__attribute__ ((aligned (16))) static u32 prev_sector = 0;
u32 tweak_exp = 0;
bool regen_tweak = true;
if (((u32)buff >= DRAM_START) && !((u32)buff % 8))
return sdmmc_storage_write(&sd_storage, sector, count, (void *)buff) ? RES_OK : RES_ERROR;
u8 *buf = (u8 *)SDMMC_UPPER_BUFFER; //TODO: define this somewhere.
memcpy(buf, buff, 512 * count);
if (sdmmc_storage_write(&sd_storage, sector, count, buf))
return RES_OK;
if (prev_cluster != sector / 0x20) { // sector in different cluster than last read
prev_cluster = sector / 0x20;
tweak_exp = sector % 0x20;
} else if (sector > prev_sector) { // sector in same cluster and past last sector
tweak_exp = sector - prev_sector - 1;
regen_tweak = false;
} else { // sector in same cluster and before or same as last sector
tweak_exp = sector % 0x20;
}
if (_emmc_xts(9, 8, 1, tweak, regen_tweak, tweak_exp, prev_cluster, buff, buff, count * 0x200)){
if (nx_emmc_part_write(&storage, system_part, sector, count, buff)){
prev_sector = sector + count - 1;
return RES_OK;
}
}
return RES_ERROR;
}
return RES_ERROR;
}

View File

@@ -31,7 +31,7 @@ typedef enum {
DSTATUS disk_initialize (BYTE pdrv);
DSTATUS disk_status (BYTE pdrv);
DRESULT disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count);
DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count);
DRESULT disk_write (BYTE pdrv, BYTE* buff, DWORD sector, UINT count);
DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);

View File

@@ -6105,10 +6105,10 @@ FRESULT f_fdisk (
void* work /* Pointer to the working buffer (null: use heap memory) */
)
{
UINT i, n, sz_cyl, tot_cyl, b_cyl, e_cyl, p_cyl;
UINT i, n, sz_cyl, tot_cyl, e_cyl;
BYTE s_hd, e_hd, *p, *buf = (BYTE*)work;
DSTATUS stat;
DWORD sz_disk, sz_part, s_part;
DWORD sz_disk, sz_part, s_part, p_cyl, b_cyl;
FRESULT res;
@@ -6134,17 +6134,17 @@ FRESULT f_fdisk (
mem_set(buf, 0, FF_MAX_SS);
p = buf + MBR_Table; b_cyl = 0;
for (i = 0; i < 4; i++, p += SZ_PTE) {
p_cyl = (szt[i] <= 100U) ? (DWORD)tot_cyl * (szt[i] / 100) : szt[i] / sz_cyl; /* Number of cylinders */
p_cyl = (szt[i] <= 100U) ? (DWORD)tot_cyl * (szt[i] / 100) : szt[i]; // sz_cyl; /* Number of cylinders */
if (p_cyl == 0) continue;
s_part = (DWORD)sz_cyl * b_cyl;
sz_part = (DWORD)sz_cyl * p_cyl;
s_part = /*(DWORD)sz_cyl * */ b_cyl;
sz_part = /* (DWORD)sz_cyl * */ p_cyl;
if (i == 0) { /* Exclude first track of cylinder 0 */
s_hd = 1;
s_part += 32768; sz_part -= 32768;
} else {
s_hd = 0;
}
e_cyl = b_cyl + p_cyl - 1; /* End cylinder */
e_cyl = (b_cyl + p_cyl - 1) / sz_cyl; /* End cylinder */
if (e_cyl >= tot_cyl) LEAVE_MKFS(FR_INVALID_PARAMETER);

View File

@@ -45,11 +45,20 @@
sdmmc_t sd_sdmmc;
sdmmc_storage_t sd_storage;
__attribute__ ((aligned (16))) FATFS sd_fs;
static bool sd_mounted;
static bool sd_mounted, sd_inited;
volatile nyx_storage_t *nyx_str = (nyx_storage_t *)NYX_STORAGE_ADDR;
hekate_config h_cfg;
boot_cfg_t __attribute__((section ("._boot_cfg"))) b_cfg;
bool return_sd_mounted(int value){
switch(value){
case 1:
return sd_mounted;
case 7:
return sd_inited;
}
}
bool sd_mount()
{
if (sd_mounted)
@@ -58,9 +67,11 @@ bool sd_mount()
if (!sdmmc_storage_init_sd(&sd_storage, &sd_sdmmc, SDMMC_1, SDMMC_BUS_WIDTH_4, 11))
{
EPRINTF("Failed to init SD card.\nMake sure that it is inserted.\nOr that SD reader is properly seated!");
sd_inited = false;
}
else
{
sd_inited = true;
int res = 0;
res = f_mount(&sd_fs, "sd:", 1);
if (res == FR_OK)
@@ -84,6 +95,7 @@ void sd_unmount()
f_mount(NULL, "sd:", 1);
sdmmc_storage_end(&sd_storage);
sd_mounted = false;
sd_inited = false;
}
}

View File

@@ -32,6 +32,7 @@ u32 minerva_init()
{
u32 curr_ram_idx = 0;
minerva_cfg = NULL;
mtc_config_t *mtc_cfg = (mtc_config_t *)&nyx_str->mtc_cfg;
// Set table to nyx storage.

View File

@@ -28,7 +28,7 @@ __attribute__ ((aligned (16))) FATFS emmc;
LIST_INIT(gpt);
u8 bis_key[4][32];
short pkg1ver;
short pkg1ver = -1;
static bool _key_exists(const void *data) { return memcmp(data, zeros, 0x10); };
@@ -44,9 +44,11 @@ static void _generate_kek(u32 ks, const void *key_source, void *master_key, cons
}
void print_biskeys(){
gfx_printf("\n");
gfx_printf("Bis_Key_00\n");
gfx_hexdump(0, bis_key[0], 32);
gfx_printf("Bis_Key_01\n");
gfx_hexdump(0, bis_key[1], 32);
gfx_printf("Bis_Key_02 & 03\n");
gfx_hexdump(0, bis_key[2], 32);
}
@@ -75,6 +77,7 @@ short returnpkg1ver(){
}
void disconnect_emmc(){
f_unmount("emmc:");
sdmmc_storage_end(&storage);
}

View File

@@ -8,8 +8,9 @@
#include "../utils/btn.h"
#include "../gfx/gfx.h"
#include "../utils/util.h"
#include "io.h"
fs_entry fileobjects[500];
fs_entry *fileobjects;
char rootpath[10] = "";
char *currentpath = "";
char *clipboard = "";
@@ -17,10 +18,11 @@ u8 clipboardhelper = 0;
extern const char sizevalues[4][3];
extern int launch_payload(char *path);
menu_item explfilemenu[9] = {
menu_item explfilemenu[10] = {
{"-- File Menu --", COLOR_BLUE, -1, 0},
{"FILE", COLOR_GREEN, -1, 0},
{"\nSIZE", COLOR_VIOLET, -1, 0},
{"ATTRIB", COLOR_VIOLET, -1, 0},
{"\n\n\nBack", COLOR_WHITE, -1, 1},
{"\nCopy to clipboard", COLOR_BLUE, COPY, 1},
{"Move to clipboard", COLOR_BLUE, MOVE, 1},
@@ -29,6 +31,15 @@ menu_item explfilemenu[9] = {
{"View Hex", COLOR_GREEN, HEXVIEW, 1}
};
menu_item explfoldermenu[6] = {
{"-- Folder Menu --\n", COLOR_BLUE, -1, 0},
{"ATTRIB", COLOR_VIOLET, -1, 0},
{"\n\nBack", COLOR_WHITE, -1, 1},
{"Return to main menu\n", COLOR_BLUE, EXITFOLDER, 1},
{"Copy to clipboard", COLOR_VIOLET, COPYFOLDER, 1},
{"Delete folder", COLOR_RED, DELETEFOLDER, 1}
};
void writecurpath(const char *in){
if (currentpath != NULL)
free(currentpath);
@@ -61,8 +72,14 @@ void writeclipboard(const char *in, bool move, bool folder){
strcpy(clipboard, in);
}
char *getnextloc(char *current, char *add){
char *ret;
char *getnextloc(const char *current, const char *add){
static char *ret;
if (ret != NULL){
free(ret);
ret = NULL;
}
size_t size = strlen(current) + strlen(add) + 1;
ret = (char*) malloc (size);
if (!strcmp(rootpath, current))
@@ -74,7 +91,14 @@ char *getnextloc(char *current, char *add){
}
char *getprevloc(char *current){
char *ret, *temp;
static char *ret;
char *temp;
if (ret != NULL){
free(ret);
ret = NULL;
}
size_t size = strlen(current) + 1;
ret = (char*) malloc (size);
@@ -89,166 +113,58 @@ char *getprevloc(char *current){
return ret;
}
int getfileobjamount(){
int amount = 0;
while (fileobjects[amount].name != NULL)
amount++;
return amount;
}
fs_entry getfileobj(int spot){
return fileobjects[spot];
}
bool checkfile(char* path){
FRESULT fr;
FILINFO fno;
fr = f_stat(path, &fno);
if (fr & FR_NO_FILE)
return false;
else
return true;
}
void viewbytes(char *path){
FIL in;
u8 print[2048];
u32 size;
QWORD offset = 0;
int res;
clearscreen();
res = f_open(&in, path, FA_READ | FA_OPEN_EXISTING);
if (res != FR_OK){
message("File Opening Failed", COLOR_RED);
return;
}
msleep(200);
while (1){
f_lseek(&in, offset * 16);
res = f_read(&in, &print, 2048 * sizeof(u8), &size);
if (res != FR_OK){
message("Reading Failed", COLOR_RED);
return;
}
printbytes(print, size, offset * 16);
res = btn_read();
if (!res)
res = btn_wait();
if (res & BTN_VOL_DOWN && 2048 * sizeof(u8) == size)
offset++;
if (res & BTN_VOL_UP && offset > 0)
offset--;
if (res & BTN_POWER)
break;
}
f_close(&in);
}
int copy(const char *locin, const char *locout, bool print){
FIL in, out;
u64 sizeoffile, sizecopied = 0, totalsize;
UINT temp1, temp2;
u8 *buff;
unsigned int x, y, i = 0;
gfx_con_getpos(&x, &y);
if (!strcmp(locin, locout)){
return 3;
}
if (f_open(&in, locin, FA_READ | FA_OPEN_EXISTING)){
return 1;
}
if (f_open(&out, locout, FA_CREATE_ALWAYS | FA_WRITE)){
return 2;
}
buff = malloc (BUFSIZE);
sizeoffile = f_size(&in);
totalsize = sizeoffile;
while (sizeoffile > 0){
if (f_read(&in, buff, (sizeoffile > BUFSIZE) ? BUFSIZE : sizeoffile, &temp1))
return 3;
if (f_write(&out, buff, (sizeoffile > BUFSIZE) ? BUFSIZE : sizeoffile, &temp2))
return 4;
if (temp1 != temp2)
return 5;
sizeoffile -= temp1;
sizecopied += temp1;
if (print && 10 > i++){
gfx_printf("%k[%d%%/100%%]%k", COLOR_GREEN, ((sizecopied * 100) / totalsize) ,COLOR_WHITE);
gfx_con_setpos(x, y);
i = 0;
if (btn_read() & BTN_VOL_DOWN){
f_unlink(locout);
break;
}
}
}
f_close(&in);
f_close(&out);
free(buff);
return 0;
}
void copyfile(const char *path, const char *outfolder){
char *filename = strrchr(path, '/');
char *filename = strrchr(path, '/') + 1;
char *outstring;
size_t outstringsize = strlen(filename) + strlen(outfolder) + 2;
int res;
clearscreen();
outstring = (char*) malloc (outstringsize);
if (strcmp(rootpath, outfolder))
sprintf(outstring, "%s/%s", outfolder, filename + 1);
else
sprintf(outstring, "%s%s", outfolder, filename + 1);
makestring(getnextloc(outfolder, filename), &outstring);
gfx_printf("Note:\nTo stop the transfer hold Vol-\n\n%s\nProgress: ", outstring);
if (clipboardhelper & OPERATIONMOVE){
if (strcmp(rootpath, "emmc:/"))
if (!strcmp(path, outstring)){
message(COLOR_RED, "\nIn and out are the same!");
}
else if (clipboardhelper & OPERATIONMOVE){
if (strcmp(rootpath, "emmc:/")){
f_rename(path, outstring);
readfolder(currentpath);
}
else
message("\nMoving in emummc is not allowed!", COLOR_RED);
message(COLOR_RED, "\nMoving in emummc is not allowed!");
}
else if (clipboardhelper & OPERATIONCOPY) {
res = copy(path, outstring, true);
res = copy(path, outstring, true, true);
if (res){
gfx_printf("\n\n%kSomething went wrong while copying!\n\nErrcode: %d%k", COLOR_RED, res, COLOR_WHITE);
btn_wait();
}
readfolder(currentpath);
}
else {
message("\nClipboard is empty!", COLOR_RED);
message(COLOR_RED, "\nClipboard is empty!");
}
free (outstring);
clipboardhelper = 0;
}
u64 getfilesize(char *path){
FILINFO fno;
f_stat(path, &fno);
return fno.fsize;
}
void addobject(char* name, int spot, bool isfol, bool isarc){
size_t length = strlen(name) + 1;
u64 size = 0;
@@ -284,18 +200,36 @@ void addobject(char* name, int spot, bool isfol, bool isarc){
fileobjects[spot].property |= (ISARC);
}
void clearfileobjects(){
if (fileobjects != NULL){
for (int i = 0; fileobjects[i].name != NULL; i++){
free(fileobjects[i].name);
fileobjects[i].name = NULL;
}
free(fileobjects);
fileobjects = NULL;
}
}
void createfileobjects(int size){
fileobjects = calloc (size + 1, sizeof(fs_entry));
fileobjects[size].name = NULL;
}
int readfolder(const char *path){
DIR dir;
FILINFO fno;
int folderamount = 0, res;
if (res = f_opendir(&dir, path)){
char errmes[50] = "";
sprintf(errmes, "Error during f_opendir: %d", res);
message(errmes, COLOR_RED);
clearfileobjects();
createfileobjects(getfolderentryamount(path));
if ((res = f_opendir(&dir, path))){
message(COLOR_RED, "Error during f_opendir: %d", res);
return -1;
}
while (!f_readdir(&dir, &fno) && fno.fname[0] && folderamount < 500){
while (!f_readdir(&dir, &fno) && fno.fname[0]){
addobject(fno.fname, folderamount++, (fno.fattrib & AM_DIR), (fno.fattrib & AM_ARC));
}
@@ -311,84 +245,199 @@ int delfile(const char *path, const char *filename){
sprintf(tempmessage, "Are you sure you want to delete:\n%s\n\nPress vol+/- to cancel\n", filename);
if (makewaitmenu(tempmessage, "Press power to delete", 3)){
f_unlink(path);
return readfolder(currentpath);
readfolder(currentpath);
return 0;
}
else
return -1;
}
void filemenu(const char *startpath){
int amount, res, tempint;
char temp[100];
void copyfolder(char *in, char *out){
bool fatalerror = false;
int res;
if (!strcmp(in, rootpath)){
message(COLOR_RED, "\nIn is root\nAborting!");
fatalerror = true;
}
if (strstr(out, in) != NULL && !fatalerror){
message(COLOR_RED, "\nOut is a part of in!\nAborting!");
fatalerror = true;
}
if (!strcmp(in, out) && !fatalerror){
message(COLOR_RED, "\nIn is the same as out!\nAborting!");
fatalerror = true;
}
if (!fatalerror){
clearscreen();
gfx_printf("\nCopying folder, please wait\n");
if ((res = copy_recursive(in, out)))
message(COLOR_RED, "copy_recursive() failed!\nErrcode %d", res);
readfolder(currentpath);
}
clipboardhelper = 0;
}
int filemenu(fs_entry file){
int temp;
FILINFO attribs;
strlcpy(explfilemenu[1].name, file.name, 43);
for (temp = 4; temp < 8; temp++)
if ((file.property & (1 << temp)))
break;
sprintf(explfilemenu[2].name, "\nSize: %d %s", file.size, sizevalues[temp - 4]);
if (f_stat(getnextloc(currentpath, file.name), &attribs))
explfilemenu[3].property = -1;
else {
explfilemenu[3].property = 0;
sprintf(explfilemenu[3].name, "Attribs: %c%c%c%c",
(attribs.fattrib & AM_RDO) ? 'R' : '-',
(attribs.fattrib & AM_SYS) ? 'S' : '-',
(attribs.fattrib & AM_HID) ? 'H' : '-',
(attribs.fattrib & AM_ARC) ? 'A' : '-');
}
if (strstr(file.name, ".bin") != NULL && file.size & ISKB){
explfilemenu[8].property = 1;
}
else
explfilemenu[8].property = -1;
temp = makemenu(explfilemenu, 10);
switch (temp){
case COPY:
writeclipboard(getnextloc(currentpath, file.name), false, false);
break;
case MOVE:
writeclipboard(getnextloc(currentpath, file.name), true, false);
break;
case DELETE:
delfile(getnextloc(currentpath, file.name), file.name);
break;
case PAYLOAD:
launch_payload(getnextloc(currentpath, file.name));
break;
case HEXVIEW:
viewbytes(getnextloc(currentpath, file.name));
break;
}
return 0;
}
int foldermenu(){
int res;
FILINFO attribs;
if (!strcmp(rootpath, currentpath)){
explfoldermenu[4].property = -1;
explfoldermenu[5].property = -1;
}
else {
explfoldermenu[4].property = 1;
explfoldermenu[5].property = 1;
}
if (f_stat(currentpath, &attribs))
explfoldermenu[1].property = -1;
else {
explfoldermenu[1].property = 0;
sprintf(explfoldermenu[1].name, "Attribs: %c%c%c%c",
(attribs.fattrib & AM_RDO) ? 'R' : '-',
(attribs.fattrib & AM_SYS) ? 'S' : '-',
(attribs.fattrib & AM_HID) ? 'H' : '-',
(attribs.fattrib & AM_ARC) ? 'A' : '-');
}
res = makemenu(explfoldermenu, 6);
switch (res){
case EXITFOLDER:
return -1;
case DELETEFOLDER:
if (makewaitmenu("Do you want to delete this folder?\nThe entire folder, with all subcontents\n will be deleted!!!\n\nPress vol+/- to cancel\n", "Press power to contine...", 3)){
clearscreen();
gfx_printf("\nDeleting folder, please wait...\n");
if ((res = del_recursive(currentpath))){
message(COLOR_RED, "Error during del_recursive()! %d", res);
}
writecurpath(getprevloc(currentpath));
readfolder(currentpath);
}
break;
case COPYFOLDER:
writeclipboard(currentpath, false, true);
break;
}
return 0;
}
void fileexplorer(const char *startpath){
int res, tempint;
bool breakfree = false;
if (!strcmp(rootpath, "emmc:/") && !strcmp(startpath, "emmc:/"))
clipboardhelper = 0;
strcpy(rootpath, startpath);
writecurpath(startpath);
amount = readfolder(currentpath);
readfolder(currentpath);
if (strcmp(rootpath, "emmc:/"))
explfilemenu[5].property = 1;
explfilemenu[6].property = 1;
else
explfilemenu[5].property = -1;
explfilemenu[6].property = -1;
while (1){
res = makefilemenu(fileobjects, amount, currentpath);
res = makefilemenu(fileobjects, getfileobjamount(), currentpath);
if (res < 1){
if (res == -2){
if (!strcmp(rootpath, currentpath))
break;
else {
writecurpath(getprevloc(currentpath));
amount = readfolder(currentpath);
}
}
if (res == -1){
copyfile(clipboard, currentpath);
amount = readfolder(currentpath);
}
switch (res){
case -2:
if (!strcmp(rootpath, currentpath))
breakfree = true;
else {
writecurpath(getprevloc(currentpath));
readfolder(currentpath);
}
if (res == 0)
break;
break;
case -1:
if (clipboardhelper & ISDIR)
copyfolder(clipboard, currentpath);
else
copyfile(clipboard, currentpath);
break;
case 0:
tempint = foldermenu();
if (tempint == -1)
breakfree = true;
break;
}
}
else {
if (fileobjects[res - 1].property & ISDIR){
writecurpath(getnextloc(currentpath, fileobjects[res - 1].name));
amount = readfolder(currentpath);
readfolder(currentpath);
}
else {
strlcpy(explfilemenu[1].name, fileobjects[res - 1].name, 43);
for (tempint = 4; tempint < 8; tempint++)
if ((fileobjects[res - 1].property & (1 << tempint)))
break;
sprintf(temp, "\nSize: %d %s", fileobjects[res - 1].size, sizevalues[tempint - 4]);
strcpy(explfilemenu[2].name, temp);
if (strstr(fileobjects[res - 1].name, ".bin") != NULL)
explfilemenu[7].property = 1;
else
explfilemenu[7].property = -1;
tempint = makemenu(explfilemenu, 9);
switch (tempint){
case COPY:
writeclipboard(getnextloc(currentpath, fileobjects[res - 1].name), false, false);
break;
case MOVE:
writeclipboard(getnextloc(currentpath, fileobjects[res - 1].name), true, false);
break;
case DELETE:
if ((tempint = delfile(getnextloc(currentpath, fileobjects[res - 1].name), fileobjects[res - 1].name)) != -1)
amount = tempint;
break;
case PAYLOAD:
launch_payload(getnextloc(currentpath, fileobjects[res - 1].name));
break;
case HEXVIEW:
viewbytes(getnextloc(currentpath, fileobjects[res - 1].name));
break;
}
filemenu(fileobjects[res - 1]);
}
}
if (breakfree)
break;
}
}

View File

@@ -37,8 +37,12 @@ enum filemenuoptions {
HEXVIEW
};
enum foldermenuoptions {
EXITFOLDER = 1,
DELETEFOLDER,
COPYFOLDER
};
int readfolder(const char *path);
void filemenu();
bool checkfile(char* path);
u64 getfilesize(char *path);
int copy(const char *locin, const char *locout, bool print);
void fileexplorer(const char *startpath);
char *getnextloc(const char *current, const char *add);

View File

@@ -8,11 +8,12 @@
#include "gfx.h"
#include "fs.h"
#include "../mem/minerva.h"
#include <stdarg.h>
const char fixedoptions[3][50] = {
"Folder -> previous folder ",
"Clipboard -> Current folder ",
"Return to main menu "
"Current folder menu "
};
const char sizevalues[4][3] = {
@@ -26,12 +27,19 @@ void clearscreen(){
gfx_clear_grey(0x1B);
gfx_box(0, 0, 719, 15, COLOR_WHITE);
gfx_con_setpos(0, 0);
gfx_printf("%k%KTegraexplorer%k%K\n", COLOR_DEFAULT, COLOR_WHITE, COLOR_WHITE, COLOR_DEFAULT);
gfx_printf("%k%KTegraexplorer v1.2.0%k%K\n", COLOR_DEFAULT, COLOR_WHITE, COLOR_WHITE, COLOR_DEFAULT);
}
int message(char* message, u32 color){
int message(u32 color, const char* message, ...){
va_list ap;
va_start(ap, message);
clearscreen();
gfx_printf("%k%s%k", color, message, COLOR_DEFAULT);
SWAPCOLOR(color);
gfx_vprintf(message, ap);
va_end(ap);
return btn_wait();
}
@@ -109,6 +117,22 @@ int makewaitmenu(char *initialmessage, char *hiddenmessage, int timer){
}
}
void gfx_print_length(int size, char *toprint){
char *temp;
temp = (char*) malloc (size + 1);
if (strlen(toprint) > size){
strlcpy(temp, toprint, size);
memset(temp + size - 3, '.', 3);
memset(temp + size, '\0', 1);
}
else
strcpy(temp, toprint);
gfx_printf("%s", temp);
free(temp);
}
void printfsentry(fs_entry file, bool highlight, bool refresh){
int size = 0;
char *display;
@@ -124,29 +148,37 @@ void printfsentry(fs_entry file, bool highlight, bool refresh){
else
strcpy(display, file.name);
if (highlight)
gfx_printf("%K%k", COLOR_WHITE, COLOR_DEFAULT);
else
gfx_printf("%K%k", COLOR_DEFAULT, COLOR_WHITE);
RESETCOLOR;
if (file.property & ISDIR)
gfx_printf("%s\n", display);
gfx_printf("%s", display);
else {
for (size = 4; size < 8; size++)
if ((file.property & (1 << size)))
break;
gfx_printf("%k%s%K", COLOR_VIOLET, display, COLOR_DEFAULT);
SWAPCOLOR(COLOR_VIOLET);
gfx_printf("%s", display);
}
RESETCOLOR;
if (refresh){
length = strlen(display);
for (int i = 0; i < (42 - length); i++)
gfx_printf(" ");
}
if (!(file.property & ISDIR))
if (file.property & ISDIR)
gfx_printf("\n");
else {
SWAPCOLOR(COLOR_BLUE);
gfx_printf("\a%d\e%s", file.size, sizevalues[size - 4]);
}
free(display);
}
@@ -157,7 +189,7 @@ int makefilemenu(fs_entry *files, int amount, char *path){
bool refresh = false;
clearscreen();
gfx_con_setpos(544, 0);
gfx_printf("%K%k%d / 500\n%K%k%s%k\n\n", COLOR_WHITE, COLOR_DEFAULT, amount, COLOR_DEFAULT, COLOR_GREEN, path, COLOR_DEFAULT);
gfx_printf("%K%k%d files\n%K%k%s%k\n\n", COLOR_WHITE, COLOR_DEFAULT, amount, COLOR_DEFAULT, COLOR_GREEN, path, COLOR_DEFAULT);
while (1){
gfx_con_setpos(0, 47);
timer = get_tmr_ms();

View File

@@ -2,9 +2,13 @@
#include "te.h"
#include "fs.h"
#define SWAPCOLOR(color) gfx_printf("%k", color)
#define RESETCOLOR gfx_printf("%k%K", COLOR_WHITE, COLOR_DEFAULT)
int makemenu(menu_item menu[], int menuamount);
int message(char* message, u32 color);
int message(u32 color, const char* message, ...);
void clearscreen();
int makefilemenu(fs_entry *files, int amount, char *path);
void printbytes(u8 print[], u32 size, u32 offset);
int makewaitmenu(char *initialmessage, char *hiddenmessage, int timer);
void gfx_print_length(int size, char *toprint);

248
source/tegraexplorer/io.c Normal file
View File

@@ -0,0 +1,248 @@
#include <string.h>
#include "../mem/heap.h"
#include "gfx.h"
#include "fs.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 "io.h"
bool checkfile(char* path){
FRESULT fr;
FILINFO fno;
fr = f_stat(path, &fno);
return !(fr & FR_NO_FILE);
}
void viewbytes(char *path){
FIL in;
u8 print[2048];
u32 size;
QWORD offset = 0;
int res;
clearscreen();
res = f_open(&in, path, FA_READ | FA_OPEN_EXISTING);
if (res != FR_OK){
message(COLOR_RED, "File Opening Failed\nErrcode %d", res);
return;
}
msleep(200);
while (1){
f_lseek(&in, offset * 16);
res = f_read(&in, &print, 2048 * sizeof(u8), &size);
if (res != FR_OK){
message(COLOR_RED, "Reading Failed!\nErrcode %d", res);
return;
}
printbytes(print, size, offset * 16);
res = btn_read();
if (!res)
res = btn_wait();
if (res & BTN_VOL_DOWN && 2048 * sizeof(u8) == size)
offset++;
if (res & BTN_VOL_UP && offset > 0)
offset--;
if (res & BTN_POWER)
break;
}
f_close(&in);
}
int copy(const char *locin, const char *locout, bool print, bool canCancel){
FIL in, out;
FILINFO in_info;
u64 sizeoffile, sizecopied = 0, totalsize;
UINT temp1, temp2;
u8 *buff;
unsigned int x, y, i = 0;
int res;
gfx_con_getpos(&x, &y);
if (!strcmp(locin, locout)){
return 21;
}
if (f_open(&in, locin, FA_READ | FA_OPEN_EXISTING)){
return 22;
}
if (f_stat(locin, &in_info))
return 22;
if (f_open(&out, locout, FA_CREATE_ALWAYS | FA_WRITE)){
return 23;
}
buff = malloc (BUFSIZE);
sizeoffile = f_size(&in);
totalsize = sizeoffile;
while (sizeoffile > 0){
if ((res = f_read(&in, buff, (sizeoffile > BUFSIZE) ? BUFSIZE : sizeoffile, &temp1)))
return res;
if ((res = f_write(&out, buff, (sizeoffile > BUFSIZE) ? BUFSIZE : sizeoffile, &temp2)))
return res;
if (temp1 != temp2)
return 24;
sizeoffile -= temp1;
sizecopied += temp1;
if (print && 10 > i++){
gfx_printf("%k[%d%%]%k", COLOR_GREEN, ((sizecopied * 100) / totalsize) ,COLOR_WHITE);
gfx_con_setpos(x, y);
i = 0;
if (canCancel)
if (btn_read() & BTN_VOL_DOWN){
f_unlink(locout);
break;
}
}
}
f_close(&in);
f_close(&out);
free(buff);
if ((res = f_chmod(locout, in_info.fattrib, 0x3A)))
return res;
return 0;
}
u64 getfilesize(char *path){
FILINFO fno;
f_stat(path, &fno);
return fno.fsize;
}
int getfolderentryamount(const char *path){
DIR dir;
FILINFO fno;
int folderamount = 0;
if ((f_opendir(&dir, path))){
return -1;
}
while (!f_readdir(&dir, &fno) && fno.fname[0]){
folderamount++;
}
f_closedir(&dir);
return folderamount;
}
void makestring(char *in, char **out){
*out = (char *) malloc (strlen(in) + 1);
strcpy(*out, in);
}
int del_recursive(char *path){
DIR dir;
FILINFO fno;
int res;
char *localpath = NULL;
makestring(path, &localpath);
if ((res = f_opendir(&dir, localpath))){
message(COLOR_RED, "Error during f_opendir: %d", res);
return -1;
}
while (!f_readdir(&dir, &fno) && fno.fname[0]){
if (fno.fattrib & AM_DIR)
del_recursive(getnextloc(localpath, fno.fname));
else {
gfx_box(0, 47, 719, 63, COLOR_DEFAULT);
SWAPCOLOR(COLOR_RED);
gfx_printf("\r");
gfx_print_length(37, fno.fname);
gfx_printf(" ");
if ((res = f_unlink(getnextloc(localpath, fno.fname))))
return res;
}
}
f_closedir(&dir);
if ((res = f_unlink(localpath))){
return res;
}
free(localpath);
return 0;
}
int copy_recursive(char *path, char *dstpath){
DIR dir;
FILINFO fno;
int res;
char *startpath = NULL, *destpath = NULL, *destfoldername = NULL, *temp = NULL;
makestring(path, &startpath);
makestring(strrchr(path, '/') + 1, &destfoldername);
destpath = (char*) malloc (strlen(dstpath) + strlen(destfoldername) + 2);
sprintf(destpath, (dstpath[strlen(dstpath) - 1] == '/') ? "%s%s" : "%s/%s", dstpath, destfoldername);
if ((res = f_opendir(&dir, startpath))){
message(COLOR_RED, "Error during f_opendir: %d", res);
return 21;
}
f_mkdir(destpath);
if (f_stat(startpath, &fno))
return 22;
while (!f_readdir(&dir, &fno) && fno.fname[0]){
if (fno.fattrib & AM_DIR){
copy_recursive(getnextloc(startpath, fno.fname), destpath);
}
else {
gfx_box(0, 47, 719, 63, COLOR_DEFAULT);
SWAPCOLOR(COLOR_GREEN);
gfx_printf("\r");
gfx_print_length(37, fno.fname);
gfx_printf(" ");
makestring(getnextloc(startpath, fno.fname), &temp);
if ((res = copy(temp, getnextloc(destpath, fno.fname), true, false))){
return res;
}
free(temp);
}
}
f_closedir(&dir);
free(startpath);
free(destpath);
free(destfoldername);
if ((res = f_chmod(destpath, fno.fattrib, 0x3A)))
return res;
return 0;
}

10
source/tegraexplorer/io.h Normal file
View File

@@ -0,0 +1,10 @@
#pragma once
bool checkfile(char* path);
void viewbytes(char *path);
int copy(const char *locin, const char *locout, bool print, bool canCancel);
u64 getfilesize(char *path);
int getfolderentryamount(const char *path);
void makestring(char *in, char **out);
int del_recursive(char *path);
int copy_recursive(char *path, char *dstpath);

View File

@@ -5,17 +5,20 @@
#include "../utils/util.h"
#include "tools.h"
#include "fs.h"
#include "io.h"
#include "../utils/btn.h"
#include "emmc.h"
extern bool sd_mount();
extern void sd_unmount();
extern bool return_sd_mounted(int value);
extern int launch_payload(char *path);
bool sd_mounted;
menu_item mainmenu[MAINMENU_AMOUNT] = {
{"[SD:/] SD CARD", COLOR_GREEN, SD_CARD, 1},
{"[SYSTEM:/] EMMC", COLOR_GREEN, EMMC_SYS, 1},
{"[SD:/] SD CARD\n", COLOR_GREEN, SD_CARD, 1},
{"[SYSTEM:/] EMMC", COLOR_ORANGE, EMMC_SYS, 1},
{"[USER:/] EMMC", COLOR_ORANGE, EMMC_USR, 1},
{"[SAFE:/] EMMC", COLOR_ORANGE, EMMC_SAF, 1},
{"\nMount/Unmount SD", COLOR_WHITE, MOUNT_SD, 1},
{"Tools", COLOR_VIOLET, TOOLS, 1},
{"SD format", COLOR_VIOLET, SD_FORMAT, 1},
@@ -33,19 +36,26 @@ menu_item shutdownmenu[7] = {
{"Reboot to Atmosphere", COLOR_GREEN, AMS, -1}
};
menu_item toolsmenu[5] = {
menu_item toolsmenu[6] = {
{"-- TOOLS --\n", COLOR_VIOLET, -1, 0},
{"Back", COLOR_WHITE, -1, 1},
{"\nDisplay Console Info", COLOR_GREEN, DISPLAY_INFO, 1},
{"Display GPIO pins", COLOR_VIOLET, DISPLAY_GPIO, 1},
{"Dump Firmware", COLOR_BLUE, DUMPFIRMWARE, 1}
{"Dump Firmware", COLOR_BLUE, DUMPFIRMWARE, 1},
{"Dump User Saves", COLOR_YELLOW, DUMPUSERSAVE, 1}
};
menu_item formatmenu[4] = {
{"-- FORMAT SD --\n", COLOR_RED, -1, 0},
{"Back\n", COLOR_WHITE, -1, 1},
{"Format to FAT32", COLOR_RED, FORMAT_ALL_FAT32, 1},
{"Format for EmuMMC setup", COLOR_RED, FORMAT_EMUMMC, 1}
{"Format entire SD to FAT32", COLOR_RED, FORMAT_ALL_FAT32, 1},
{"Format for EmuMMC setup (FAT32/RAW)", COLOR_RED, FORMAT_EMUMMC, 1}
};
const char emmc_entries[3][8] = {
"SAFE",
"SYSTEM",
"USER"
};
void fillmainmenu(){
@@ -54,14 +64,14 @@ void fillmainmenu(){
for (i = 0; i < MAINMENU_AMOUNT; i++){
switch (i + 1) {
case 1:
case 5:
if (sd_mounted)
case 7:
if (return_sd_mounted(i + 1))
mainmenu[i].property = 1;
else
mainmenu[i].property = -1;
break;
case 3:
if (sd_mounted){
case 5:
if (return_sd_mounted(1)){
mainmenu[i].property = 2;
strcpy(mainmenu[i].name, "\nUnmount SD");
}
@@ -77,10 +87,12 @@ void fillmainmenu(){
void te_main(){
int res;
dump_biskeys();
mount_emmc("SYSTEM", 2);
sd_mounted = sd_mount();
if (dump_biskeys() == -1){
message(COLOR_RED, "Biskeys failed to dump!\nEmmc will not be mounted!");
mainmenu[1].property = -1;
mainmenu[2].property = -1;
mainmenu[3].property = -1;
}
while (1){
fillmainmenu();
@@ -88,30 +100,33 @@ void te_main(){
switch(res){
case SD_CARD:
filemenu("SD:/");
fileexplorer("SD:/");
break;
case EMMC_SAF:
case EMMC_SYS:
if (makewaitmenu("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", "Press Power to enter", 4))
filemenu("emmc:/");
break;
/*
case EMMC_USR:
mount_emmc("USER", 2);
filemenu("emmc:/");
break;
*/
case MOUNT_SD:
if (sd_mounted){
sd_mounted = false;
sd_unmount();
if (makewaitmenu("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", "Press Power to enter", 4)){
if (!mount_emmc(emmc_entries[res - 2], res - 1)){
fileexplorer("emmc:/");
}
else
sd_mounted = sd_mount();
message(COLOR_RED, "EMMC failed to mount!");
}
break;
case MOUNT_SD:
if (return_sd_mounted(1))
sd_unmount();
else
sd_mount();
break;
case TOOLS:
res = makemenu(toolsmenu, 5);
res = makemenu(toolsmenu, 6);
switch(res){
case DISPLAY_INFO:
@@ -123,6 +138,9 @@ void te_main(){
case DUMPFIRMWARE:
dumpfirmware();
break;
case DUMPUSERSAVE:
dumpusersaves();
break;
}
break;
@@ -133,7 +151,6 @@ void te_main(){
if(makewaitmenu("Are you sure you want to format your sd?\nThis will delete everything on your SD card\nThis action is irreversible!\n\nPress Vol+/- to cancel\n", "Press Power to continue", 10)){
if (format(res)){
sd_unmount();
sd_mounted = false;
}
}
}
@@ -141,11 +158,11 @@ void te_main(){
break;
case CREDITS:
message(CREDITS_MESSAGE, COLOR_WHITE);
message(COLOR_WHITE, CREDITS_MESSAGE);
break;
case EXIT:
if (sd_mounted){
if (return_sd_mounted(1)){
if (checkfile("/bootloader/update.bin"))
shutdownmenu[5].property = 1;
else

View File

@@ -1,7 +1,7 @@
#pragma once
#include "../utils/types.h"
#define MAINMENU_AMOUNT 7
#define MAINMENU_AMOUNT 9
#define CREDITS_MESSAGE "\nTegraexplorer, made by:\nSuch Meme, Many Skill\n\nProject based on:\nLockpick_RCM\nHekate\n\nCool people:\nshchmue\ndennthecafebabe\nDax"
typedef struct _menu_item {
@@ -13,6 +13,7 @@ typedef struct _menu_item {
enum mainmenu_return {
SD_CARD = 1,
EMMC_SAF,
EMMC_SYS,
EMMC_USR,
MOUNT_SD,
@@ -33,7 +34,8 @@ enum shutdownmenu_return {
enum toolsmenu_return {
DISPLAY_INFO = 1,
DISPLAY_GPIO,
DUMPFIRMWARE
DUMPFIRMWARE,
DUMPUSERSAVE
};
enum formatmenu_return {

View File

@@ -9,8 +9,10 @@
#include "../libs/fatfs/diskio.h"
#include "../storage/sdmmc.h"
#include "../utils/sprintf.h"
#include "../soc/fuse.h"
#include "emmc.h"
#include "fs.h"
#include "io.h"
extern bool sd_mount();
extern void sd_unmount();
@@ -22,11 +24,24 @@ void displayinfo(){
FATFS *fs;
DWORD fre_clust, fre_sect, tot_sect;
u32 capacity;
u8 fuse_count = 0;
int res;
gfx_printf("Biskeys:\n");
for (u32 i = 0; i < 32; i++){
if ((fuse_read_odm(7) >> i) & 1)
fuse_count++;
}
SWAPCOLOR(COLOR_ORANGE);
gfx_printf("Fuse count: %d\nPKG1 version: %d\n\n", fuse_count, returnpkg1ver());
print_biskeys();
RESETCOLOR;
gfx_printf("\n-----\n\n");
SWAPCOLOR(COLOR_BLUE);
if (!sd_mount()){
gfx_printf("SD mount failed!\nFailed to display SD info\n");
}
@@ -44,6 +59,7 @@ void displayinfo(){
gfx_printf("First partition on SD:\nSectors: %d\nSpace total: %d MB\nSpace free: %d MB\n\n", tot_sect, tot_sect / 2048, fre_sect / 2048);
}
RESETCOLOR;
gfx_printf("Press any key to continue");
btn_wait();
}
@@ -51,7 +67,7 @@ void displayinfo(){
void displaygpio(){
int res;
clearscreen();
gfx_printf("Updates gpio pins ever 50ms:\nPress power to exit");
gfx_printf("Updates gpio pins every 50ms:\nPress power to exit");
msleep(200);
while (1){
msleep(10);
@@ -82,6 +98,7 @@ int dumpfirmware(){
u32 timer = get_tmr_s();
clearscreen();
mount_emmc("SYSTEM", 2);
gfx_printf("PKG1 version: %d\n", pkg1ver);
@@ -106,7 +123,7 @@ int dumpfirmware(){
else
sprintf(syspath, "%s/%s", path, fno.fname);
ret = copy(syspath, sdpath, false);
ret = copy(syspath, sdpath, false, false);
gfx_printf("%d %s\r", ++amount, fno.fname);
@@ -124,14 +141,41 @@ int dumpfirmware(){
return fail;
}
void dumpusersaves(){
int res;
mount_emmc("USER", 2);
clearscreen();
res = f_mkdir("sd:/tegraexplorer");
gfx_printf("Creating sd:/tegraexplorer, res: %d\nCopying:\n", res);
SWAPCOLOR(COLOR_GREEN);
res = copy_recursive("emmc:/save", "sd:/tegraexplorer");
SWAPCOLOR(COLOR_ORANGE);
gfx_printf("\rResult copy_recursive() %d\n\n", res);
if (res){
SWAPCOLOR(COLOR_RED);
gfx_printf("Dump failed!\n");
}
else
gfx_printf("Saves are located in SD:/tegraexplorer/save\n");
gfx_printf("Press any key to continue");
btn_wait();
}
int format(int mode){
clearscreen();
int res;
bool fatalerror = false;
DWORD plist[] = {666, 61145088};
u32 timer, totalsectors;
u32 timer, totalsectors, alignedsectors, extrasectors;
BYTE work[FF_MAX_SS];
DWORD clustsize = 16 * 512;
DWORD clustsize = 32768;
BYTE formatoptions = 0;
formatoptions |= (FM_FAT32);
//formatoptions |= (FM_SFD);
@@ -142,14 +186,17 @@ int format(int mode){
totalsectors = sd_storage.csd.capacity;
if (mode == 0){
if (totalsectors < 61145088){
gfx_printf("%k\nNot enough free space for emummc!", COLOR_RED);
if (totalsectors < 83886080){
gfx_printf("%kYou seem to be running this on a <=32GB SD\nNot enough free space for emummc!", COLOR_RED);
fatalerror = true;
}
if (!fatalerror){
plist[0] = totalsectors - 61145088;
gfx_printf("\nStarting SD partitioning:\nTotalSectors: %d\nPartition1 (SD): %d\nPartition2 (EMUMMC): %d\n", totalsectors, plist[0], plist[1]);
else {
totalsectors -= plist[1];
alignedsectors = (totalsectors / 2048) * 2048;
extrasectors = totalsectors - alignedsectors;
plist[0] = alignedsectors;
plist[1] += extrasectors;
gfx_printf("\nStarting SD partitioning:\nTotalSectors: %d\nPartition1 (SD): %d\nPartition2 (EMUMMC): %d\n", plist[0] + plist[1], plist[0], plist[1]);
}
}
else {

View File

@@ -4,3 +4,4 @@ void displayinfo();
void displaygpio();
int format(int mode);
int dumpfirmware();
void dumpusersaves();