Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a3b876ea3e | ||
|
|
4309194a11 | ||
|
|
ae57cb1e63 | ||
|
|
a86294218c | ||
|
|
eecefd634c | ||
|
|
37ce49a31f | ||
|
|
ab061cf0b3 | ||
|
|
1a2fd158e9 | ||
|
|
eb8652c6ec | ||
|
|
9885308bce | ||
|
|
1410fa185f | ||
|
|
6724f364b5 | ||
|
|
008d3ab494 | ||
|
|
00bd1cd083 | ||
|
|
6af2bb63b8 | ||
|
|
02504c8a36 | ||
|
|
ef76834ef4 | ||
|
|
6d75aa688c | ||
|
|
225a17116c | ||
|
|
e1f4c24686 | ||
|
|
3e8cd67129 | ||
|
|
697fc3a086 |
12
.github/FUNDING.yml
vendored
Normal file
12
.github/FUNDING.yml
vendored
Normal 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']
|
||||||
4
Makefile
4
Makefile
@@ -10,8 +10,8 @@ include $(DEVKITARM)/base_rules
|
|||||||
|
|
||||||
IPL_LOAD_ADDR := 0x40003000
|
IPL_LOAD_ADDR := 0x40003000
|
||||||
LPVERSION_MAJOR := 2
|
LPVERSION_MAJOR := 2
|
||||||
LPVERSION_MINOR := 1
|
LPVERSION_MINOR := 3
|
||||||
LPVERSION_BUGFX := 0
|
LPVERSION_BUGFX := 1
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
|
|||||||
@@ -9,11 +9,13 @@ Navigate around the menu's using the vol+, vol- and power buttons
|
|||||||
|
|
||||||
## Functions
|
## Functions
|
||||||
- Navigate the SD card
|
- Navigate the SD card
|
||||||
- Navigate the System partition of your sysnand
|
- Navigate the System partition of your sysnand/sysmmc
|
||||||
- Interact with files
|
- Interact with files
|
||||||
- Deleting, copying or moving files
|
- Deleting, copying or moving files
|
||||||
- Launching payloads files
|
- Launching payloads files
|
||||||
- Viewing the hex data of a file
|
- Viewing the hex data of a file
|
||||||
|
- Interacting with folders
|
||||||
|
- Deleting or copying folders
|
||||||
- Dumping your current firmware to sd
|
- Dumping your current firmware to sd
|
||||||
- Formatting the sd card
|
- Formatting the sd card
|
||||||
|
|
||||||
@@ -24,7 +26,7 @@ For general CFW support, go to the [Nintendo Homebrew](https://discord.gg/C29hYv
|
|||||||
For question specifically for TegraExplorer, go to [my discord](https://discord.gg/aH9rsuP)
|
For question specifically for TegraExplorer, go to [my discord](https://discord.gg/aH9rsuP)
|
||||||
|
|
||||||
# Credits
|
# 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:
|
Lots of help from:
|
||||||
- shchmue
|
- shchmue
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ void gfx_putc(char c)
|
|||||||
|
|
||||||
for (u32 i = 0; i < 16; i+=2)
|
for (u32 i = 0; i < 16; i+=2)
|
||||||
{
|
{
|
||||||
u8 v = *cbuf++;
|
u8 v = *cbuf;
|
||||||
for (u32 k = 0; k < 2; k++)
|
for (u32 k = 0; k < 2; k++)
|
||||||
{
|
{
|
||||||
for (u32 j = 0; j < 8; j++)
|
for (u32 j = 0; j < 8; j++)
|
||||||
@@ -213,6 +213,7 @@ void gfx_putc(char c)
|
|||||||
fb += gfx_ctxt.stride - 16;
|
fb += gfx_ctxt.stride - 16;
|
||||||
v = *cbuf;
|
v = *cbuf;
|
||||||
}
|
}
|
||||||
|
cbuf++;
|
||||||
}
|
}
|
||||||
gfx_con.x += 16;
|
gfx_con.x += 16;
|
||||||
if (gfx_con.x >= gfx_ctxt.width - 16) {
|
if (gfx_con.x >= gfx_ctxt.width - 16) {
|
||||||
@@ -329,15 +330,10 @@ void gfx_put_big_sep()
|
|||||||
gfx_con.fntsz = prevFontSize;
|
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;
|
int fill, fcnt;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
while(*fmt)
|
while(*fmt)
|
||||||
{
|
{
|
||||||
if(*fmt == '%')
|
if(*fmt == '%')
|
||||||
@@ -389,7 +385,7 @@ void gfx_printf(const char *fmt, ...)
|
|||||||
gfx_putc('%');
|
gfx_putc('%');
|
||||||
break;
|
break;
|
||||||
case '\0':
|
case '\0':
|
||||||
goto out;
|
return;
|
||||||
default:
|
default:
|
||||||
gfx_putc('%');
|
gfx_putc('%');
|
||||||
gfx_putc(*fmt);
|
gfx_putc(*fmt);
|
||||||
@@ -400,8 +396,17 @@ void gfx_printf(const char *fmt, ...)
|
|||||||
gfx_putc(*fmt);
|
gfx_putc(*fmt);
|
||||||
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);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#define _GFX_H_
|
#define _GFX_H_
|
||||||
|
|
||||||
#include "../../common/common_gfx.h"
|
#include "../../common/common_gfx.h"
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
#define EPRINTF(text) gfx_printf("%k"text"%k\n", 0xFFFF0000, 0xFFCCCCCC)
|
#define EPRINTF(text) gfx_printf("%k"text"%k\n", 0xFFFF0000, 0xFFCCCCCC)
|
||||||
#define EPRINTFARGS(text, args...) gfx_printf("%k"text"%k\n", 0xFFFF0000, args, 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_putc(char c);
|
||||||
void gfx_puts(const char *s);
|
void gfx_puts(const char *s);
|
||||||
void gfx_printf(const char *fmt, ...);
|
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_hexdump(u32 base, const u8 *buf, u32 len);
|
||||||
|
|
||||||
void gfx_set_pixel(u32 x, u32 y, u32 color);
|
void gfx_set_pixel(u32 x, u32 y, u32 color);
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
#include "../../sec/se.h"
|
#include "../../sec/se.h"
|
||||||
#include "../../storage/nx_emmc.h"
|
#include "../../storage/nx_emmc.h"
|
||||||
#include "../../storage/sdmmc.h"
|
#include "../../storage/sdmmc.h"
|
||||||
|
#include "../../storage/emummc.h"
|
||||||
|
|
||||||
extern sdmmc_storage_t sd_storage;
|
extern sdmmc_storage_t sd_storage;
|
||||||
extern sdmmc_storage_t storage;
|
extern sdmmc_storage_t storage;
|
||||||
@@ -150,7 +151,7 @@ DRESULT disk_read (
|
|||||||
__attribute__ ((aligned (16))) static u8 tweak[0x10];
|
__attribute__ ((aligned (16))) static u8 tweak[0x10];
|
||||||
__attribute__ ((aligned (16))) static u64 prev_cluster = -1;
|
__attribute__ ((aligned (16))) static u64 prev_cluster = -1;
|
||||||
__attribute__ ((aligned (16))) static u32 prev_sector = 0;
|
__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 (secindex == 0 || clear_sector_cache) {
|
||||||
if (!sector_cache)
|
if (!sector_cache)
|
||||||
@@ -212,20 +213,46 @@ DRESULT disk_read (
|
|||||||
|
|
||||||
DRESULT disk_write (
|
DRESULT disk_write (
|
||||||
BYTE pdrv, /* Physical drive number to identify the drive */
|
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 */
|
DWORD sector, /* Start sector in LBA */
|
||||||
UINT count /* Number of sectors to write */
|
UINT count /* Number of sectors to write */
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (pdrv == 1)
|
switch (pdrv){
|
||||||
return RES_WRPRT;
|
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))
|
if (prev_cluster != sector / 0x20) { // sector in different cluster than last read
|
||||||
return sdmmc_storage_write(&sd_storage, sector, count, (void *)buff) ? RES_OK : RES_ERROR;
|
prev_cluster = sector / 0x20;
|
||||||
u8 *buf = (u8 *)SDMMC_UPPER_BUFFER; //TODO: define this somewhere.
|
tweak_exp = sector % 0x20;
|
||||||
memcpy(buf, buff, 512 * count);
|
} else if (sector > prev_sector) { // sector in same cluster and past last sector
|
||||||
if (sdmmc_storage_write(&sd_storage, sector, count, buf))
|
tweak_exp = sector - prev_sector - 1;
|
||||||
return RES_OK;
|
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;
|
return RES_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ typedef enum {
|
|||||||
DSTATUS disk_initialize (BYTE pdrv);
|
DSTATUS disk_initialize (BYTE pdrv);
|
||||||
DSTATUS disk_status (BYTE pdrv);
|
DSTATUS disk_status (BYTE pdrv);
|
||||||
DRESULT disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count);
|
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);
|
DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,8 @@
|
|||||||
#include "ff.h" /* Declarations of FatFs API */
|
#include "ff.h" /* Declarations of FatFs API */
|
||||||
#include "diskio.h" /* Declarations of device I/O functions */
|
#include "diskio.h" /* Declarations of device I/O functions */
|
||||||
#include "../../gfx/gfx.h"
|
#include "../../gfx/gfx.h"
|
||||||
|
#include "../../storage/sdmmc.h"
|
||||||
|
extern sdmmc_storage_t sd_storage;
|
||||||
|
|
||||||
#define EFSPRINTF(text, ...) print_error(); gfx_printf("%k"text"%k\n", 0xFFFFFF00, 0xFFFFFFFF);
|
#define EFSPRINTF(text, ...) print_error(); gfx_printf("%k"text"%k\n", 0xFFFFFF00, 0xFFFFFFFF);
|
||||||
//#define EFSPRINTF(...)
|
//#define EFSPRINTF(...)
|
||||||
@@ -6105,17 +6107,19 @@ FRESULT f_fdisk (
|
|||||||
void* work /* Pointer to the working buffer (null: use heap memory) */
|
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;
|
BYTE s_hd, e_hd, *p, *buf = (BYTE*)work;
|
||||||
DSTATUS stat;
|
DSTATUS stat;
|
||||||
DWORD sz_disk, sz_part, s_part;
|
DWORD sz_disk, p_sect, b_cyl, b_sect;
|
||||||
FRESULT res;
|
FRESULT res;
|
||||||
|
|
||||||
|
BYTE *empty_buff;
|
||||||
|
empty_buff = ff_memcalloc(sizeof(BYTE), 16384);
|
||||||
|
|
||||||
stat = disk_initialize(pdrv);
|
stat = disk_initialize(pdrv);
|
||||||
if (stat & STA_NOINIT) return FR_NOT_READY;
|
if (stat & STA_NOINIT) return FR_NOT_READY;
|
||||||
if (stat & STA_PROTECT) return FR_WRITE_PROTECTED;
|
if (stat & STA_PROTECT) return FR_WRITE_PROTECTED;
|
||||||
if (disk_ioctl(pdrv, GET_SECTOR_COUNT, &sz_disk)) return FR_DISK_ERR;
|
sz_disk = sd_storage.csd.capacity;
|
||||||
|
|
||||||
buf = (BYTE*)work;
|
buf = (BYTE*)work;
|
||||||
#if FF_USE_LFN == 3
|
#if FF_USE_LFN == 3
|
||||||
@@ -6132,20 +6136,25 @@ FRESULT f_fdisk (
|
|||||||
|
|
||||||
/* Create partition table */
|
/* Create partition table */
|
||||||
mem_set(buf, 0, FF_MAX_SS);
|
mem_set(buf, 0, FF_MAX_SS);
|
||||||
p = buf + MBR_Table; b_cyl = 0;
|
p = buf + MBR_Table; b_cyl = 0, b_sect = 0;
|
||||||
for (i = 0; i < 4; i++, p += SZ_PTE) {
|
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_sect = szt[i]; /* Number of sectors */
|
||||||
if (p_cyl == 0) continue;
|
|
||||||
s_part = (DWORD)sz_cyl * b_cyl;
|
if (p_sect == 0)
|
||||||
sz_part = (DWORD)sz_cyl * p_cyl;
|
continue;
|
||||||
if (i == 0) { /* Exclude first track of cylinder 0 */
|
|
||||||
|
if (i == 0) { /* Exclude first 16MiB of sd */
|
||||||
s_hd = 1;
|
s_hd = 1;
|
||||||
s_part += 32768; sz_part -= 32768;
|
b_sect += 32768; p_sect -= 32768;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
s_hd = 0;
|
s_hd = 0;
|
||||||
}
|
|
||||||
e_cyl = b_cyl + p_cyl - 1; /* End cylinder */
|
b_cyl = b_sect / sz_cyl;
|
||||||
if (e_cyl >= tot_cyl) LEAVE_MKFS(FR_INVALID_PARAMETER);
|
e_cyl = ((b_sect + p_sect) / sz_cyl) - 1; /* End cylinder */
|
||||||
|
|
||||||
|
if (e_cyl >= tot_cyl)
|
||||||
|
LEAVE_MKFS(FR_INVALID_PARAMETER);
|
||||||
|
|
||||||
|
|
||||||
/* Set partition table */
|
/* Set partition table */
|
||||||
@@ -6156,12 +6165,17 @@ FRESULT f_fdisk (
|
|||||||
p[5] = e_hd; /* End head */
|
p[5] = e_hd; /* End head */
|
||||||
p[6] = (BYTE)(((e_cyl >> 2) & 0xC0) | 63); /* End sector */
|
p[6] = (BYTE)(((e_cyl >> 2) & 0xC0) | 63); /* End sector */
|
||||||
p[7] = (BYTE)e_cyl; /* End cylinder */
|
p[7] = (BYTE)e_cyl; /* End cylinder */
|
||||||
st_dword(p + 8, s_part); /* Start sector in LBA */
|
st_dword(p + 8, b_sect); /* Start sector in LBA */
|
||||||
st_dword(p + 12, sz_part); /* Number of sectors */
|
st_dword(p + 12, p_sect); /* Number of sectors */
|
||||||
/* Next partition */
|
/* Next partition */
|
||||||
b_cyl += p_cyl;
|
b_sect += p_sect;
|
||||||
|
|
||||||
|
for (int cursect = 0; cursect < 1024; cursect++){
|
||||||
|
disk_write(pdrv, empty_buff, b_sect + (32 * cursect), 32);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
st_word(p, 0xAA55); /* MBR signature (always at offset 510) */
|
st_word(p, 0xAA55); /* MBR signature (always at offset 510) */
|
||||||
|
ff_memfree(empty_buff);
|
||||||
|
|
||||||
/* Write it to the MBR */
|
/* Write it to the MBR */
|
||||||
res = (disk_write(pdrv, buf, 0, 1) == RES_OK && disk_ioctl(pdrv, CTRL_SYNC, 0) == RES_OK) ? FR_OK : FR_DISK_ERR;
|
res = (disk_write(pdrv, buf, 0, 1) == RES_OK && disk_ioctl(pdrv, CTRL_SYNC, 0) == RES_OK) ? FR_OK : FR_DISK_ERR;
|
||||||
|
|||||||
@@ -321,6 +321,7 @@ DWORD ff_wtoupper (DWORD uni); /* Unicode upper-case conversion */
|
|||||||
#endif
|
#endif
|
||||||
#if FF_USE_LFN == 3 /* Dynamic memory allocation */
|
#if FF_USE_LFN == 3 /* Dynamic memory allocation */
|
||||||
void* ff_memalloc (UINT msize); /* Allocate memory block */
|
void* ff_memalloc (UINT msize); /* Allocate memory block */
|
||||||
|
void* ff_memcalloc (UINT msize, UINT amount);
|
||||||
void ff_memfree (void* mblock); /* Free memory block */
|
void ff_memfree (void* mblock); /* Free memory block */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,10 @@ void* ff_memalloc ( /* Returns pointer to the allocated memory block (null if no
|
|||||||
return malloc(msize); /* Allocate a new memory block with POSIX API */
|
return malloc(msize); /* Allocate a new memory block with POSIX API */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void* ff_memcalloc (UINT msize, UINT amount){
|
||||||
|
return calloc(amount, msize);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
/* Free a memory block */
|
/* Free a memory block */
|
||||||
|
|||||||
@@ -52,10 +52,10 @@ boot_cfg_t __attribute__((section ("._boot_cfg"))) b_cfg;
|
|||||||
|
|
||||||
bool return_sd_mounted(int value){
|
bool return_sd_mounted(int value){
|
||||||
switch(value){
|
switch(value){
|
||||||
case 1:
|
case 10:
|
||||||
return sd_mounted;
|
|
||||||
case 7:
|
|
||||||
return sd_inited;
|
return sd_inited;
|
||||||
|
default:
|
||||||
|
return sd_mounted;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ u32 minerva_init()
|
|||||||
{
|
{
|
||||||
u32 curr_ram_idx = 0;
|
u32 curr_ram_idx = 0;
|
||||||
|
|
||||||
|
minerva_cfg = NULL;
|
||||||
mtc_config_t *mtc_cfg = (mtc_config_t *)&nyx_str->mtc_cfg;
|
mtc_config_t *mtc_cfg = (mtc_config_t *)&nyx_str->mtc_cfg;
|
||||||
|
|
||||||
// Set table to nyx storage.
|
// Set table to nyx storage.
|
||||||
|
|||||||
@@ -139,7 +139,6 @@ out:
|
|||||||
|
|
||||||
int emummc_storage_end(sdmmc_storage_t *storage)
|
int emummc_storage_end(sdmmc_storage_t *storage)
|
||||||
{
|
{
|
||||||
sd_unmount();
|
|
||||||
sdmmc_storage_end(storage);
|
sdmmc_storage_end(storage);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -74,5 +74,5 @@ int nx_emmc_part_write(sdmmc_storage_t *storage, emmc_part_t *part, u32 sector_o
|
|||||||
// The last LBA is inclusive.
|
// The last LBA is inclusive.
|
||||||
if (part->lba_start + sector_off > part->lba_end)
|
if (part->lba_start + sector_off > part->lba_end)
|
||||||
return 0;
|
return 0;
|
||||||
return sdmmc_storage_write(storage, part->lba_start + sector_off, num_sectors, buf);
|
return emummc_storage_write(storage, part->lba_start + sector_off, num_sectors, buf);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,15 +20,20 @@
|
|||||||
#include "../soc/hw_init.h"
|
#include "../soc/hw_init.h"
|
||||||
#include "../mem/emc.h"
|
#include "../mem/emc.h"
|
||||||
#include "../mem/sdram.h"
|
#include "../mem/sdram.h"
|
||||||
|
#include "../storage/emummc.h"
|
||||||
|
#include "../config/config.h"
|
||||||
|
|
||||||
sdmmc_storage_t storage;
|
sdmmc_storage_t storage;
|
||||||
emmc_part_t *system_part;
|
emmc_part_t *system_part;
|
||||||
sdmmc_t sdmmc;
|
sdmmc_t sdmmc;
|
||||||
|
extern hekate_config h_cfg;
|
||||||
__attribute__ ((aligned (16))) FATFS emmc;
|
__attribute__ ((aligned (16))) FATFS emmc;
|
||||||
LIST_INIT(gpt);
|
LIST_INIT(gpt);
|
||||||
|
|
||||||
u8 bis_key[4][32];
|
u8 bis_key[4][32];
|
||||||
short pkg1ver = -1;
|
pkg1_info pkg1inf = {-1, ""};
|
||||||
|
short currentlyMounted = -1;
|
||||||
|
|
||||||
|
|
||||||
static bool _key_exists(const void *data) { return memcmp(data, zeros, 0x10); };
|
static bool _key_exists(const void *data) { return memcmp(data, zeros, 0x10); };
|
||||||
|
|
||||||
@@ -52,7 +57,11 @@ void print_biskeys(){
|
|||||||
gfx_hexdump(0, bis_key[2], 32);
|
gfx_hexdump(0, bis_key[2], 32);
|
||||||
}
|
}
|
||||||
|
|
||||||
int mount_emmc(char *partition, int biskeynumb){
|
pkg1_info returnpkg1info(){
|
||||||
|
return pkg1inf;
|
||||||
|
}
|
||||||
|
|
||||||
|
int mount_mmc(const char *partition, const int biskeynumb){
|
||||||
f_unmount("emmc:");
|
f_unmount("emmc:");
|
||||||
|
|
||||||
se_aes_key_set(8, bis_key[biskeynumb] + 0x00, 0x10);
|
se_aes_key_set(8, bis_key[biskeynumb] + 0x00, 0x10);
|
||||||
@@ -72,12 +81,36 @@ int mount_emmc(char *partition, int biskeynumb){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
short returnpkg1ver(){
|
void connect_mmc(short mmctype){
|
||||||
return pkg1ver;
|
if (mmctype != currentlyMounted){
|
||||||
|
disconnect_mmc();
|
||||||
|
switch (mmctype){
|
||||||
|
case SYSMMC:
|
||||||
|
sdmmc_storage_init_mmc(&storage, &sdmmc, SDMMC_4, SDMMC_BUS_WIDTH_8, 4);
|
||||||
|
h_cfg.emummc_force_disable = 1;
|
||||||
|
currentlyMounted = SYSMMC;
|
||||||
|
break;
|
||||||
|
case EMUMMC:
|
||||||
|
if (emummc_storage_init_mmc(&storage, &sdmmc)){
|
||||||
|
h_cfg.emummc_force_disable = 0;
|
||||||
|
currentlyMounted = EMUMMC;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void disconnect_emmc(){
|
void disconnect_mmc(){
|
||||||
sdmmc_storage_end(&storage);
|
f_unmount("emmc:");
|
||||||
|
switch (currentlyMounted){
|
||||||
|
case SYSMMC:
|
||||||
|
sdmmc_storage_end(&storage);
|
||||||
|
break;
|
||||||
|
case EMUMMC:
|
||||||
|
emummc_storage_end(&storage);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
currentlyMounted = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int dump_biskeys(){
|
int dump_biskeys(){
|
||||||
@@ -86,7 +119,7 @@ int dump_biskeys(){
|
|||||||
|
|
||||||
int retries = 0;
|
int retries = 0;
|
||||||
|
|
||||||
sdmmc_storage_init_mmc(&storage, &sdmmc, SDMMC_4, SDMMC_BUS_WIDTH_8, 4);
|
connect_mmc(SYSMMC);
|
||||||
|
|
||||||
// Read package1.
|
// Read package1.
|
||||||
u8 *pkg1 = (u8 *)malloc(0x40000);
|
u8 *pkg1 = (u8 *)malloc(0x40000);
|
||||||
@@ -171,41 +204,11 @@ int dump_biskeys(){
|
|||||||
sdmmc_storage_set_mmc_partition(&storage, 0);
|
sdmmc_storage_set_mmc_partition(&storage, 0);
|
||||||
// Parse eMMC GPT.
|
// Parse eMMC GPT.
|
||||||
nx_emmc_gpt_parse(&gpt, &storage);
|
nx_emmc_gpt_parse(&gpt, &storage);
|
||||||
/*
|
|
||||||
char part_name[37] = "SYSTEM";
|
|
||||||
|
|
||||||
// todo: menu selection for this
|
|
||||||
|
|
||||||
u32 bis_key_index = 0;
|
|
||||||
if (strcmp(part_name, "PRODINFOF") == 0)
|
|
||||||
bis_key_index = 0;
|
|
||||||
else if (strcmp(part_name, "SAFE") == 0)
|
|
||||||
bis_key_index = 1;
|
|
||||||
else if (strcmp(part_name, "SYSTEM") == 0)
|
|
||||||
bis_key_index = 2;
|
|
||||||
else if (strcmp(part_name, "USER") == 0)
|
|
||||||
bis_key_index = 3;
|
|
||||||
else {
|
|
||||||
gfx_printf("Partition name %s unrecognized.", part_name);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
se_aes_key_set(8, bis_key[2] + 0x00, 0x10);
|
se_aes_key_set(8, bis_key[2] + 0x00, 0x10);
|
||||||
se_aes_key_set(9, bis_key[2] + 0x10, 0x10);
|
se_aes_key_set(9, bis_key[2] + 0x10, 0x10);
|
||||||
|
|
||||||
/*
|
pkg1inf.ver = pkg1_id->kb;
|
||||||
system_part = nx_emmc_part_find(&gpt, "SYSTEM");
|
strcpy(pkg1inf.id, pkg1_id->id);
|
||||||
if (!system_part) {
|
|
||||||
gfx_printf("Failed to locate SYSTEM partition.");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (f_mount(&emmc_sys, "system:", 1)) {
|
|
||||||
gfx_printf("Mount failed of SYSTEM.");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
pkg1ver = pkg1_id->kb;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
typedef struct _pkg1_info {
|
||||||
|
short ver;
|
||||||
|
char id[16];
|
||||||
|
} pkg1_info;
|
||||||
|
|
||||||
//int mount_emmc_partition(const char *part, int logicnumb);
|
//int mount_emmc_partition(const char *part, int logicnumb);
|
||||||
int dump_biskeys();
|
int dump_biskeys();
|
||||||
void print_biskeys();
|
void print_biskeys();
|
||||||
int mount_emmc(char *partition, int biskeynumb);
|
pkg1_info returnpkg1info();
|
||||||
short returnpkg1ver();
|
|
||||||
void disconnect_emmc();
|
int mount_mmc(const char *partition, const int biskeynumb);
|
||||||
|
void connect_mmc(short mmctype);
|
||||||
|
void disconnect_mmc();
|
||||||
|
|
||||||
|
|
||||||
static const u8 zeros[0x10] = {0};
|
static const u8 zeros[0x10] = {0};
|
||||||
|
|
||||||
@@ -40,4 +48,9 @@ static const u8 bis_key_source[3][0x20] = {
|
|||||||
{
|
{
|
||||||
0x52, 0xC2, 0xE9, 0xEB, 0x09, 0xE3, 0xEE, 0x29, 0x32, 0xA1, 0x0C, 0x1F, 0xB6, 0xA0, 0x92, 0x6C,
|
0x52, 0xC2, 0xE9, 0xEB, 0x09, 0xE3, 0xEE, 0x29, 0x32, 0xA1, 0x0C, 0x1F, 0xB6, 0xA0, 0x92, 0x6C,
|
||||||
0x4D, 0x12, 0xE1, 0x4B, 0x2A, 0x47, 0x4C, 0x1C, 0x09, 0xCB, 0x03, 0x59, 0xF0, 0x15, 0xF4, 0xE4}
|
0x4D, 0x12, 0xE1, 0x4B, 0x2A, 0x47, 0x4C, 0x1C, 0x09, 0xCB, 0x03, 0x59, 0xF0, 0x15, 0xF4, 0xE4}
|
||||||
|
};
|
||||||
|
|
||||||
|
enum mmc_types {
|
||||||
|
SYSMMC = 0,
|
||||||
|
EMUMMC
|
||||||
};
|
};
|
||||||
@@ -8,8 +8,10 @@
|
|||||||
#include "../utils/btn.h"
|
#include "../utils/btn.h"
|
||||||
#include "../gfx/gfx.h"
|
#include "../gfx/gfx.h"
|
||||||
#include "../utils/util.h"
|
#include "../utils/util.h"
|
||||||
|
#include "io.h"
|
||||||
|
#include "script.h"
|
||||||
|
|
||||||
fs_entry fileobjects[500];
|
fs_entry *fileobjects;
|
||||||
char rootpath[10] = "";
|
char rootpath[10] = "";
|
||||||
char *currentpath = "";
|
char *currentpath = "";
|
||||||
char *clipboard = "";
|
char *clipboard = "";
|
||||||
@@ -17,18 +19,29 @@ u8 clipboardhelper = 0;
|
|||||||
extern const char sizevalues[4][3];
|
extern const char sizevalues[4][3];
|
||||||
extern int launch_payload(char *path);
|
extern int launch_payload(char *path);
|
||||||
|
|
||||||
menu_item explfilemenu[9] = {
|
menu_item explfilemenu[11] = {
|
||||||
{"-- File Menu --", COLOR_BLUE, -1, 0},
|
{"-- File Menu --", COLOR_BLUE, -1, 0},
|
||||||
{"FILE", COLOR_GREEN, -1, 0},
|
{"FILE", COLOR_GREEN, -1, 0},
|
||||||
{"\nSIZE", COLOR_VIOLET, -1, 0},
|
{"\nSIZE", COLOR_VIOLET, -1, 0},
|
||||||
|
{"ATTRIB", COLOR_VIOLET, -1, 0},
|
||||||
{"\n\n\nBack", COLOR_WHITE, -1, 1},
|
{"\n\n\nBack", COLOR_WHITE, -1, 1},
|
||||||
{"\nCopy to clipboard", COLOR_BLUE, COPY, 1},
|
{"\nCopy to clipboard", COLOR_BLUE, COPY, 1},
|
||||||
{"Move to clipboard", COLOR_BLUE, MOVE, 1},
|
{"Move to clipboard", COLOR_BLUE, MOVE, 1},
|
||||||
{"\nDelete file\n", COLOR_RED, DELETE, 1},
|
{"\nDelete file\n", COLOR_RED, DELETE, 1},
|
||||||
{"Launch Payload", COLOR_ORANGE, PAYLOAD, 1},
|
{"Launch Payload", COLOR_ORANGE, PAYLOAD, 1},
|
||||||
|
{"Launch Script", COLOR_YELLOW, SCRIPT, 1},
|
||||||
{"View Hex", COLOR_GREEN, HEXVIEW, 1}
|
{"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){
|
void writecurpath(const char *in){
|
||||||
if (currentpath != NULL)
|
if (currentpath != NULL)
|
||||||
free(currentpath);
|
free(currentpath);
|
||||||
@@ -61,8 +74,14 @@ void writeclipboard(const char *in, bool move, bool folder){
|
|||||||
strcpy(clipboard, in);
|
strcpy(clipboard, in);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *getnextloc(char *current, char *add){
|
char *getnextloc(const char *current, const char *add){
|
||||||
char *ret;
|
static char *ret;
|
||||||
|
|
||||||
|
if (ret != NULL){
|
||||||
|
free(ret);
|
||||||
|
ret = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
size_t size = strlen(current) + strlen(add) + 1;
|
size_t size = strlen(current) + strlen(add) + 1;
|
||||||
ret = (char*) malloc (size);
|
ret = (char*) malloc (size);
|
||||||
if (!strcmp(rootpath, current))
|
if (!strcmp(rootpath, current))
|
||||||
@@ -74,7 +93,14 @@ char *getnextloc(char *current, char *add){
|
|||||||
}
|
}
|
||||||
|
|
||||||
char *getprevloc(char *current){
|
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;
|
size_t size = strlen(current) + 1;
|
||||||
|
|
||||||
ret = (char*) malloc (size);
|
ret = (char*) malloc (size);
|
||||||
@@ -89,166 +115,58 @@ char *getprevloc(char *current){
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int getfileobjamount(){
|
||||||
|
int amount = 0;
|
||||||
|
|
||||||
|
while (fileobjects[amount].name != NULL)
|
||||||
|
amount++;
|
||||||
|
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
|
||||||
fs_entry getfileobj(int spot){
|
fs_entry getfileobj(int spot){
|
||||||
return fileobjects[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){
|
void copyfile(const char *path, const char *outfolder){
|
||||||
char *filename = strrchr(path, '/');
|
char *filename = strrchr(path, '/') + 1;
|
||||||
char *outstring;
|
char *outstring;
|
||||||
size_t outstringsize = strlen(filename) + strlen(outfolder) + 2;
|
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
clearscreen();
|
clearscreen();
|
||||||
|
makestring(getnextloc(outfolder, filename), &outstring);
|
||||||
outstring = (char*) malloc (outstringsize);
|
|
||||||
|
|
||||||
if (strcmp(rootpath, outfolder))
|
|
||||||
sprintf(outstring, "%s/%s", outfolder, filename + 1);
|
|
||||||
else
|
|
||||||
sprintf(outstring, "%s%s", outfolder, filename + 1);
|
|
||||||
|
|
||||||
gfx_printf("Note:\nTo stop the transfer hold Vol-\n\n%s\nProgress: ", outstring);
|
gfx_printf("Note:\nTo stop the transfer hold Vol-\n\n%s\nProgress: ", outstring);
|
||||||
|
|
||||||
if (clipboardhelper & OPERATIONMOVE){
|
if (!strcmp(path, outstring)){
|
||||||
if (strcmp(rootpath, "emmc:/"))
|
message(COLOR_RED, "\nIn and out are the same!");
|
||||||
|
}
|
||||||
|
else if (clipboardhelper & OPERATIONMOVE){
|
||||||
|
if (strcmp(rootpath, "emmc:/")){
|
||||||
f_rename(path, outstring);
|
f_rename(path, outstring);
|
||||||
|
readfolder(currentpath);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
message("\nMoving in emummc is not allowed!", COLOR_RED);
|
message(COLOR_RED, "\nMoving in emummc is not allowed!");
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (clipboardhelper & OPERATIONCOPY) {
|
else if (clipboardhelper & OPERATIONCOPY) {
|
||||||
res = copy(path, outstring, true);
|
res = copy(path, outstring, true, true);
|
||||||
if (res){
|
if (res){
|
||||||
gfx_printf("\n\n%kSomething went wrong while copying!\n\nErrcode: %d%k", COLOR_RED, res, COLOR_WHITE);
|
gfx_printf("\n\n%kSomething went wrong while copying!\n\nErrcode: %d%k", COLOR_RED, res, COLOR_WHITE);
|
||||||
btn_wait();
|
btn_wait();
|
||||||
}
|
}
|
||||||
|
readfolder(currentpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
message("\nClipboard is empty!", COLOR_RED);
|
message(COLOR_RED, "\nClipboard is empty!");
|
||||||
}
|
}
|
||||||
|
|
||||||
free (outstring);
|
free (outstring);
|
||||||
clipboardhelper = 0;
|
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){
|
void addobject(char* name, int spot, bool isfol, bool isarc){
|
||||||
size_t length = strlen(name) + 1;
|
size_t length = strlen(name) + 1;
|
||||||
u64 size = 0;
|
u64 size = 0;
|
||||||
@@ -284,18 +202,36 @@ void addobject(char* name, int spot, bool isfol, bool isarc){
|
|||||||
fileobjects[spot].property |= (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){
|
int readfolder(const char *path){
|
||||||
DIR dir;
|
DIR dir;
|
||||||
FILINFO fno;
|
FILINFO fno;
|
||||||
int folderamount = 0, res;
|
int folderamount = 0, res;
|
||||||
|
|
||||||
if (res = f_opendir(&dir, path)){
|
clearfileobjects();
|
||||||
char errmes[50] = "";
|
createfileobjects(getfolderentryamount(path));
|
||||||
sprintf(errmes, "Error during f_opendir: %d", res);
|
|
||||||
message(errmes, COLOR_RED);
|
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));
|
addobject(fno.fname, folderamount++, (fno.fattrib & AM_DIR), (fno.fattrib & AM_ARC));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,89 +247,207 @@ 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);
|
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)){
|
if (makewaitmenu(tempmessage, "Press power to delete", 3)){
|
||||||
f_unlink(path);
|
f_unlink(path);
|
||||||
return readfolder(currentpath);
|
readfolder(currentpath);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void filemenu(const char *startpath){
|
void copyfolder(char *in, char *out){
|
||||||
int amount, res, tempint;
|
bool fatalerror = false;
|
||||||
char temp[100];
|
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;
|
||||||
|
|
||||||
|
if (strstr(file.name, ".tegrascript") != NULL)
|
||||||
|
explfilemenu[9].property = 1;
|
||||||
|
else
|
||||||
|
explfilemenu[9].property = -1;
|
||||||
|
|
||||||
|
temp = makemenu(explfilemenu, 11);
|
||||||
|
|
||||||
|
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 SCRIPT:
|
||||||
|
ParseScript(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:/"))
|
if (!strcmp(rootpath, "emmc:/") && !strcmp(startpath, "emmc:/"))
|
||||||
clipboardhelper = 0;
|
clipboardhelper = 0;
|
||||||
|
|
||||||
strcpy(rootpath, startpath);
|
strcpy(rootpath, startpath);
|
||||||
writecurpath(startpath);
|
writecurpath(startpath);
|
||||||
amount = readfolder(currentpath);
|
readfolder(currentpath);
|
||||||
|
|
||||||
if (strcmp(rootpath, "emmc:/"))
|
if (strcmp(rootpath, "emmc:/"))
|
||||||
explfilemenu[5].property = 1;
|
explfilemenu[6].property = 1;
|
||||||
else
|
else
|
||||||
explfilemenu[5].property = -1;
|
explfilemenu[6].property = -1;
|
||||||
|
|
||||||
while (1){
|
while (1){
|
||||||
res = makefilemenu(fileobjects, amount, currentpath);
|
res = makefilemenu(fileobjects, getfileobjamount(), currentpath);
|
||||||
if (res < 1){
|
if (res < 1){
|
||||||
if (res == -2){
|
switch (res){
|
||||||
if (!strcmp(rootpath, currentpath))
|
case -2:
|
||||||
|
if (!strcmp(rootpath, currentpath))
|
||||||
|
breakfree = true;
|
||||||
|
else {
|
||||||
|
writecurpath(getprevloc(currentpath));
|
||||||
|
readfolder(currentpath);
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
else {
|
|
||||||
writecurpath(getprevloc(currentpath));
|
|
||||||
amount = readfolder(currentpath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (res == -1){
|
|
||||||
copyfile(clipboard, currentpath);
|
|
||||||
amount = readfolder(currentpath);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (res == 0)
|
case -1:
|
||||||
break;
|
if (clipboardhelper & ISDIR)
|
||||||
|
copyfolder(clipboard, currentpath);
|
||||||
|
else
|
||||||
|
copyfile(clipboard, currentpath);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0:
|
||||||
|
tempint = foldermenu();
|
||||||
|
|
||||||
|
if (tempint == -1)
|
||||||
|
breakfree = true;
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (fileobjects[res - 1].property & ISDIR){
|
if (fileobjects[res - 1].property & ISDIR){
|
||||||
writecurpath(getnextloc(currentpath, fileobjects[res - 1].name));
|
writecurpath(getnextloc(currentpath, fileobjects[res - 1].name));
|
||||||
amount = readfolder(currentpath);
|
readfolder(currentpath);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
strlcpy(explfilemenu[1].name, fileobjects[res - 1].name, 43);
|
filemenu(fileobjects[res - 1]);
|
||||||
|
|
||||||
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 && fileobjects[res - 1].size & ISKB){
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (breakfree)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -34,11 +34,16 @@ enum filemenuoptions {
|
|||||||
MOVE,
|
MOVE,
|
||||||
DELETE,
|
DELETE,
|
||||||
PAYLOAD,
|
PAYLOAD,
|
||||||
|
SCRIPT,
|
||||||
HEXVIEW
|
HEXVIEW
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum foldermenuoptions {
|
||||||
|
EXITFOLDER = 1,
|
||||||
|
DELETEFOLDER,
|
||||||
|
COPYFOLDER
|
||||||
|
};
|
||||||
|
|
||||||
int readfolder(const char *path);
|
int readfolder(const char *path);
|
||||||
void filemenu();
|
void fileexplorer(const char *startpath);
|
||||||
bool checkfile(char* path);
|
char *getnextloc(const char *current, const char *add);
|
||||||
u64 getfilesize(char *path);
|
|
||||||
int copy(const char *locin, const char *locout, bool print);
|
|
||||||
@@ -8,11 +8,12 @@
|
|||||||
#include "gfx.h"
|
#include "gfx.h"
|
||||||
#include "fs.h"
|
#include "fs.h"
|
||||||
#include "../mem/minerva.h"
|
#include "../mem/minerva.h"
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
const char fixedoptions[3][50] = {
|
const char fixedoptions[3][50] = {
|
||||||
"Folder -> previous folder ",
|
"Folder -> previous folder ",
|
||||||
"Clipboard -> Current folder ",
|
"Clipboard -> Current folder ",
|
||||||
"Return to main menu "
|
"Current folder menu "
|
||||||
};
|
};
|
||||||
|
|
||||||
const char sizevalues[4][3] = {
|
const char sizevalues[4][3] = {
|
||||||
@@ -26,12 +27,19 @@ void clearscreen(){
|
|||||||
gfx_clear_grey(0x1B);
|
gfx_clear_grey(0x1B);
|
||||||
gfx_box(0, 0, 719, 15, COLOR_WHITE);
|
gfx_box(0, 0, 719, 15, COLOR_WHITE);
|
||||||
gfx_con_setpos(0, 0);
|
gfx_con_setpos(0, 0);
|
||||||
gfx_printf("%k%KTegraexplorer v1.1.0%k%K\n", COLOR_DEFAULT, COLOR_WHITE, COLOR_WHITE, COLOR_DEFAULT);
|
gfx_printf("%k%KTegraexplorer v1.3.1%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();
|
clearscreen();
|
||||||
gfx_printf("%k%s%k", color, message, COLOR_DEFAULT);
|
SWAPCOLOR(color);
|
||||||
|
|
||||||
|
gfx_vprintf(message, ap);
|
||||||
|
|
||||||
|
va_end(ap);
|
||||||
return btn_wait();
|
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){
|
void printfsentry(fs_entry file, bool highlight, bool refresh){
|
||||||
int size = 0;
|
int size = 0;
|
||||||
char *display;
|
char *display;
|
||||||
@@ -123,6 +147,7 @@ void printfsentry(fs_entry file, bool highlight, bool refresh){
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
strcpy(display, file.name);
|
strcpy(display, file.name);
|
||||||
|
|
||||||
|
|
||||||
if (highlight)
|
if (highlight)
|
||||||
gfx_printf("%K%k", COLOR_WHITE, COLOR_DEFAULT);
|
gfx_printf("%K%k", COLOR_WHITE, COLOR_DEFAULT);
|
||||||
@@ -164,7 +189,7 @@ int makefilemenu(fs_entry *files, int amount, char *path){
|
|||||||
bool refresh = false;
|
bool refresh = false;
|
||||||
clearscreen();
|
clearscreen();
|
||||||
gfx_con_setpos(544, 0);
|
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){
|
while (1){
|
||||||
gfx_con_setpos(0, 47);
|
gfx_con_setpos(0, 47);
|
||||||
timer = get_tmr_ms();
|
timer = get_tmr_ms();
|
||||||
|
|||||||
@@ -6,8 +6,9 @@
|
|||||||
#define RESETCOLOR gfx_printf("%k%K", COLOR_WHITE, COLOR_DEFAULT)
|
#define RESETCOLOR gfx_printf("%k%K", COLOR_WHITE, COLOR_DEFAULT)
|
||||||
|
|
||||||
int makemenu(menu_item menu[], int menuamount);
|
int makemenu(menu_item menu[], int menuamount);
|
||||||
int message(char* message, u32 color);
|
int message(u32 color, const char* message, ...);
|
||||||
void clearscreen();
|
void clearscreen();
|
||||||
int makefilemenu(fs_entry *files, int amount, char *path);
|
int makefilemenu(fs_entry *files, int amount, char *path);
|
||||||
void printbytes(u8 print[], u32 size, u32 offset);
|
void printbytes(u8 print[], u32 size, u32 offset);
|
||||||
int makewaitmenu(char *initialmessage, char *hiddenmessage, int timer);
|
int makewaitmenu(char *initialmessage, char *hiddenmessage, int timer);
|
||||||
|
void gfx_print_length(int size, char *toprint);
|
||||||
|
|||||||
255
source/tegraexplorer/io.c
Normal file
255
source/tegraexplorer/io.c
Normal file
@@ -0,0 +1,255 @@
|
|||||||
|
#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 ((res = 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;
|
||||||
|
|
||||||
|
f_stat(locin, &in_info); //somehow stops fatfs from being weird
|
||||||
|
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;
|
||||||
|
u32 x, y;
|
||||||
|
char *localpath = NULL;
|
||||||
|
|
||||||
|
gfx_con_getpos(&x, &y);
|
||||||
|
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, y, 719, y + 16, 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;
|
||||||
|
u32 x, y;
|
||||||
|
char *startpath = NULL, *destpath = NULL, *destfoldername = NULL, *temp = NULL;
|
||||||
|
|
||||||
|
gfx_con_getpos(&x, &y);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
while (!f_readdir(&dir, &fno) && fno.fname[0]){
|
||||||
|
if (fno.fattrib & AM_DIR){
|
||||||
|
copy_recursive(getnextloc(startpath, fno.fname), destpath);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
gfx_box(0, y, 719, y + 16, 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 (f_stat(startpath, &fno))
|
||||||
|
return 22;
|
||||||
|
|
||||||
|
if ((res = f_chmod(destpath, fno.fattrib, 0x3A)))
|
||||||
|
return res;
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
10
source/tegraexplorer/io.h
Normal file
10
source/tegraexplorer/io.h
Normal 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);
|
||||||
277
source/tegraexplorer/script.c
Normal file
277
source/tegraexplorer/script.c
Normal file
@@ -0,0 +1,277 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include "../mem/heap.h"
|
||||||
|
#include "gfx.h"
|
||||||
|
#include "fs.h"
|
||||||
|
#include "io.h"
|
||||||
|
#include "emmc.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 "../storage/emummc.h"
|
||||||
|
#include "script.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
char func[11] = "", args[2][128] = {"", ""};
|
||||||
|
int res, errcode;
|
||||||
|
const int scriptver = 131;
|
||||||
|
bool forceExit = false;
|
||||||
|
u32 currentcolor;
|
||||||
|
|
||||||
|
void Part_SetColor(){
|
||||||
|
if (strcmpcheck(args[0], "RED"))
|
||||||
|
currentcolor = COLOR_RED;
|
||||||
|
else if (strcmpcheck(args[0], "ORANGE"))
|
||||||
|
currentcolor = COLOR_ORANGE;
|
||||||
|
else if (strcmpcheck(args[0], "YELLOW"))
|
||||||
|
currentcolor = COLOR_YELLOW;
|
||||||
|
else if (strcmpcheck(args[0], "GREEN"))
|
||||||
|
currentcolor = COLOR_GREEN;
|
||||||
|
else if (strcmpcheck(args[0], "BLUE"))
|
||||||
|
currentcolor = COLOR_BLUE;
|
||||||
|
else if (strcmpcheck(args[0], "VIOLET"))
|
||||||
|
currentcolor = COLOR_VIOLET;
|
||||||
|
else if (strcmpcheck(args[0], "WHITE"))
|
||||||
|
currentcolor = COLOR_WHITE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Part_Wait(){
|
||||||
|
int waitamount, begintime;
|
||||||
|
SWAPCOLOR(currentcolor);
|
||||||
|
|
||||||
|
waitamount = atoi(args[0]);
|
||||||
|
begintime = get_tmr_s();
|
||||||
|
|
||||||
|
while (begintime + waitamount > get_tmr_s()){
|
||||||
|
gfx_printf("\r<Wait %d seconds> ", (begintime + waitamount) - get_tmr_s());
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx_printf("\r \r");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Part_VersionCheck(){
|
||||||
|
int givenversion = atoi(args[0]);
|
||||||
|
|
||||||
|
if (givenversion > scriptver){
|
||||||
|
gfx_printf("Script required version is too high\nUpdate TegraExplorer!");
|
||||||
|
btn_wait();
|
||||||
|
forceExit = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Part_Move(){
|
||||||
|
errcode = f_rename(args[0], args[1]);
|
||||||
|
if (errcode)
|
||||||
|
f_rename(args[0], args[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Part_Delete(){
|
||||||
|
errcode = f_unlink(args[0]);
|
||||||
|
if (errcode)
|
||||||
|
f_unlink(args[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Part_DeleteRecursive(){
|
||||||
|
errcode = del_recursive(args[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Part_Copy(){
|
||||||
|
errcode = copy(args[0], args[1], true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Part_RecursiveCopy(){
|
||||||
|
errcode = copy_recursive(args[0], args[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Part_MakeFolder(){
|
||||||
|
errcode = f_mkdir(args[0]);
|
||||||
|
if (errcode)
|
||||||
|
f_mkdir(args[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Part_ConnectMMC(){
|
||||||
|
if (strcmpcheck(args[0], "SYSMMC"))
|
||||||
|
connect_mmc(SYSMMC);
|
||||||
|
if (strcmpcheck(args[0], "EMUMMC"))
|
||||||
|
connect_mmc(EMUMMC);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Part_MountMMC(){
|
||||||
|
errcode = mount_mmc(args[0], 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Part_Print(){
|
||||||
|
RESETCOLOR;
|
||||||
|
SWAPCOLOR(currentcolor);
|
||||||
|
gfx_printf("%s\n", args[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Part_ErrorPrint(){
|
||||||
|
RESETCOLOR;
|
||||||
|
SWAPCOLOR(COLOR_RED);
|
||||||
|
gfx_printf("Errorcode: %d\n", errcode);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Part_Exit(){
|
||||||
|
forceExit = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
u8 buttons_pressed = 0;
|
||||||
|
void Part_WaitOnUser(){
|
||||||
|
buttons_pressed = btn_wait();
|
||||||
|
}
|
||||||
|
|
||||||
|
script_parts parts[] = {
|
||||||
|
{"COPY", Part_Copy, 2},
|
||||||
|
{"COPY-R", Part_RecursiveCopy, 2},
|
||||||
|
{"MKDIR", Part_MakeFolder, 1},
|
||||||
|
{"CON_MMC", Part_ConnectMMC, 1},
|
||||||
|
{"MNT_MMC", Part_MountMMC, 1},
|
||||||
|
{"PRINT", Part_Print, 1},
|
||||||
|
{"ERRPRINT", Part_ErrorPrint, 0},
|
||||||
|
{"EXIT", Part_Exit, 0},
|
||||||
|
{"PAUSE", Part_WaitOnUser, 0},
|
||||||
|
{"DEL", Part_Delete, 1},
|
||||||
|
{"DEL-R", Part_DeleteRecursive, 1},
|
||||||
|
{"MOVE", Part_Move, 2},
|
||||||
|
{"VERSION", Part_VersionCheck, 1},
|
||||||
|
{"WAIT", Part_Wait, 1},
|
||||||
|
{"COLOR", Part_SetColor, 1},
|
||||||
|
{"NULL", NULL, -1}
|
||||||
|
};
|
||||||
|
|
||||||
|
int ParsePart(){
|
||||||
|
int i;
|
||||||
|
for (i = 0; parts[i].arg_amount != -1; i++){
|
||||||
|
if (strcmpcheck(func, parts[i].name))
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
gfx_printf("Parsing error...\nPress any key to continue");
|
||||||
|
btn_wait();
|
||||||
|
forceExit = true;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
FIL in;
|
||||||
|
UINT endByte = 0;
|
||||||
|
|
||||||
|
char GetNextByte(){
|
||||||
|
char single;
|
||||||
|
f_read(&in, &single, sizeof(char), &endByte);
|
||||||
|
|
||||||
|
if (sizeof(char) != endByte)
|
||||||
|
forceExit = true;
|
||||||
|
|
||||||
|
return single;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParseScript(char* path){
|
||||||
|
char currentchar;
|
||||||
|
int strlength;
|
||||||
|
bool inifstatement = false;
|
||||||
|
forceExit = false;
|
||||||
|
currentcolor = COLOR_WHITE;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!forceExit){
|
||||||
|
currentchar = GetNextByte();
|
||||||
|
|
||||||
|
if (endByte == 0 || currentchar == (char)EOF)
|
||||||
|
break;
|
||||||
|
|
||||||
|
switch(currentchar){
|
||||||
|
case '{':
|
||||||
|
if (!inifstatement)
|
||||||
|
while (currentchar != '}')
|
||||||
|
currentchar = GetNextByte();
|
||||||
|
|
||||||
|
break;
|
||||||
|
case '}':
|
||||||
|
if (inifstatement)
|
||||||
|
inifstatement = false;
|
||||||
|
|
||||||
|
break;
|
||||||
|
case '<':
|
||||||
|
strlength = 0;
|
||||||
|
currentchar = GetNextByte();
|
||||||
|
|
||||||
|
while (currentchar != '>'){
|
||||||
|
func[strlength++] = currentchar;
|
||||||
|
currentchar = GetNextByte();
|
||||||
|
}
|
||||||
|
func[strlength] = '\0';
|
||||||
|
|
||||||
|
res = ParsePart();
|
||||||
|
if (res == -1)
|
||||||
|
break;
|
||||||
|
|
||||||
|
for (int i = 0; i < parts[res].arg_amount; i++){
|
||||||
|
while (currentchar != 0x22)
|
||||||
|
currentchar = GetNextByte();
|
||||||
|
|
||||||
|
strlength = 0;
|
||||||
|
currentchar = GetNextByte();
|
||||||
|
while (currentchar != 0x22){
|
||||||
|
args[i][strlength++] = currentchar;
|
||||||
|
currentchar = GetNextByte();
|
||||||
|
}
|
||||||
|
args[i][strlength] = '\0';
|
||||||
|
|
||||||
|
if (i < parts[res].arg_amount)
|
||||||
|
currentchar = GetNextByte();
|
||||||
|
}
|
||||||
|
parts[res].handler();
|
||||||
|
break;
|
||||||
|
case '$':
|
||||||
|
strlength = 0;
|
||||||
|
currentchar = GetNextByte();
|
||||||
|
|
||||||
|
while (currentchar != '$'){
|
||||||
|
func[strlength++] = currentchar;
|
||||||
|
currentchar = GetNextByte();
|
||||||
|
}
|
||||||
|
func[strlength] = '\0';
|
||||||
|
|
||||||
|
if (strcmpcheck(func, "ERROR") || strcmpcheck(func, "TRUE")){
|
||||||
|
inifstatement = (errcode);
|
||||||
|
}
|
||||||
|
else if (strcmpcheck(func, "NOERROR") || strcmpcheck(func, "FALSE")){
|
||||||
|
inifstatement = (!errcode);
|
||||||
|
}
|
||||||
|
else if (strcmpcheck(func, "BTN_POWER")){
|
||||||
|
inifstatement = (buttons_pressed & BTN_POWER);
|
||||||
|
}
|
||||||
|
else if (strcmpcheck(func, "BTN_VOL+")){
|
||||||
|
inifstatement = (buttons_pressed & BTN_VOL_UP);
|
||||||
|
}
|
||||||
|
else if (strcmpcheck(func, "BTN_VOL-")){
|
||||||
|
inifstatement = (buttons_pressed & BTN_VOL_DOWN);
|
||||||
|
}
|
||||||
|
else if (strcmpcheck(func, "EMUMMC")){
|
||||||
|
inifstatement = (emu_cfg.enabled);
|
||||||
|
}
|
||||||
|
else if (strcmpcheck(func, "NOEMUMMC")){
|
||||||
|
inifstatement = (!emu_cfg.enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inifstatement)
|
||||||
|
while(currentchar != '{')
|
||||||
|
currentchar = GetNextByte();
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
f_close(&in);
|
||||||
|
}
|
||||||
11
source/tegraexplorer/script.h
Normal file
11
source/tegraexplorer/script.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
#define strcmpcheck(x, y) (!strcmp(x, y))
|
||||||
|
|
||||||
|
typedef void (*part_handler)();
|
||||||
|
typedef struct _script_parts {
|
||||||
|
char name[11];
|
||||||
|
part_handler handler;
|
||||||
|
short arg_amount;
|
||||||
|
} script_parts;
|
||||||
|
|
||||||
|
void ParseScript(char* path);
|
||||||
@@ -5,8 +5,10 @@
|
|||||||
#include "../utils/util.h"
|
#include "../utils/util.h"
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
#include "fs.h"
|
#include "fs.h"
|
||||||
|
#include "io.h"
|
||||||
#include "../utils/btn.h"
|
#include "../utils/btn.h"
|
||||||
#include "emmc.h"
|
#include "emmc.h"
|
||||||
|
#include "../storage/emummc.h"
|
||||||
|
|
||||||
extern bool sd_mount();
|
extern bool sd_mount();
|
||||||
extern void sd_unmount();
|
extern void sd_unmount();
|
||||||
@@ -18,6 +20,9 @@ menu_item mainmenu[MAINMENU_AMOUNT] = {
|
|||||||
{"[SYSTEM:/] EMMC", COLOR_ORANGE, EMMC_SYS, 1},
|
{"[SYSTEM:/] EMMC", COLOR_ORANGE, EMMC_SYS, 1},
|
||||||
{"[USER:/] EMMC", COLOR_ORANGE, EMMC_USR, 1},
|
{"[USER:/] EMMC", COLOR_ORANGE, EMMC_USR, 1},
|
||||||
{"[SAFE:/] EMMC", COLOR_ORANGE, EMMC_SAF, 1},
|
{"[SAFE:/] EMMC", COLOR_ORANGE, EMMC_SAF, 1},
|
||||||
|
{"\n[SYSTEM:/] EMUMMC", COLOR_BLUE, EMUMMC_SYS, 1},
|
||||||
|
{"[USER:/] EMUMMC", COLOR_BLUE, EMUMMC_USR, 1},
|
||||||
|
{"[SAFE:/] EMUMMC", COLOR_BLUE, EMUMMC_SAF, 1},
|
||||||
{"\nMount/Unmount SD", COLOR_WHITE, MOUNT_SD, 1},
|
{"\nMount/Unmount SD", COLOR_WHITE, MOUNT_SD, 1},
|
||||||
{"Tools", COLOR_VIOLET, TOOLS, 1},
|
{"Tools", COLOR_VIOLET, TOOLS, 1},
|
||||||
{"SD format", COLOR_VIOLET, SD_FORMAT, 1},
|
{"SD format", COLOR_VIOLET, SD_FORMAT, 1},
|
||||||
@@ -35,12 +40,13 @@ menu_item shutdownmenu[7] = {
|
|||||||
{"Reboot to Atmosphere", COLOR_GREEN, AMS, -1}
|
{"Reboot to Atmosphere", COLOR_GREEN, AMS, -1}
|
||||||
};
|
};
|
||||||
|
|
||||||
menu_item toolsmenu[5] = {
|
menu_item toolsmenu[6] = {
|
||||||
{"-- TOOLS --\n", COLOR_VIOLET, -1, 0},
|
{"-- TOOLS --\n", COLOR_VIOLET, -1, 0},
|
||||||
{"Back", COLOR_WHITE, -1, 1},
|
{"Back", COLOR_WHITE, -1, 1},
|
||||||
{"\nDisplay Console Info", COLOR_GREEN, DISPLAY_INFO, 1},
|
{"\nDisplay Console Info", COLOR_GREEN, DISPLAY_INFO, 1},
|
||||||
{"Display GPIO pins", COLOR_VIOLET, DISPLAY_GPIO, 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] = {
|
menu_item formatmenu[4] = {
|
||||||
@@ -50,6 +56,12 @@ menu_item formatmenu[4] = {
|
|||||||
{"Format for EmuMMC setup (FAT32/RAW)", COLOR_RED, FORMAT_EMUMMC, 1}
|
{"Format for EmuMMC setup (FAT32/RAW)", COLOR_RED, FORMAT_EMUMMC, 1}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
menu_item mmcChoice[3] = {
|
||||||
|
{"Back\n", COLOR_WHITE, -1, 1},
|
||||||
|
{"SysMMC", COLOR_ORANGE, SYSMMC, 1},
|
||||||
|
{"EmuMMC", COLOR_BLUE, EMUMMC, 1}
|
||||||
|
};
|
||||||
|
|
||||||
const char emmc_entries[3][8] = {
|
const char emmc_entries[3][8] = {
|
||||||
"SAFE",
|
"SAFE",
|
||||||
"SYSTEM",
|
"SYSTEM",
|
||||||
@@ -61,14 +73,19 @@ void fillmainmenu(){
|
|||||||
|
|
||||||
for (i = 0; i < MAINMENU_AMOUNT; i++){
|
for (i = 0; i < MAINMENU_AMOUNT; i++){
|
||||||
switch (i + 1) {
|
switch (i + 1) {
|
||||||
case 1:
|
case 5:
|
||||||
|
case 6:
|
||||||
case 7:
|
case 7:
|
||||||
|
if (mainmenu[i].property == -2)
|
||||||
|
continue;
|
||||||
|
case 1:
|
||||||
|
case 10:
|
||||||
if (return_sd_mounted(i + 1))
|
if (return_sd_mounted(i + 1))
|
||||||
mainmenu[i].property = 1;
|
mainmenu[i].property = 1;
|
||||||
else
|
else
|
||||||
mainmenu[i].property = -1;
|
mainmenu[i].property = -1;
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 8:
|
||||||
if (return_sd_mounted(1)){
|
if (return_sd_mounted(1)){
|
||||||
mainmenu[i].property = 2;
|
mainmenu[i].property = 2;
|
||||||
strcpy(mainmenu[i].name, "\nUnmount SD");
|
strcpy(mainmenu[i].name, "\nUnmount SD");
|
||||||
@@ -86,34 +103,56 @@ void te_main(){
|
|||||||
int res;
|
int res;
|
||||||
|
|
||||||
if (dump_biskeys() == -1){
|
if (dump_biskeys() == -1){
|
||||||
message("Biskeys failed to dump!\nEmmc will not be mounted!", COLOR_RED);
|
message(COLOR_RED, "Biskeys failed to dump!\nEmmc will not be mounted!");
|
||||||
mainmenu[1].property = -1;
|
mainmenu[1].property = -1;
|
||||||
mainmenu[2].property = -1;
|
mainmenu[2].property = -1;
|
||||||
mainmenu[3].property = -1;
|
mainmenu[3].property = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (emummc_load_cfg()){
|
||||||
|
mainmenu[4].property = -2;
|
||||||
|
mainmenu[5].property = -2;
|
||||||
|
mainmenu[6].property = -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
disconnect_mmc();
|
||||||
|
|
||||||
while (1){
|
while (1){
|
||||||
fillmainmenu();
|
fillmainmenu();
|
||||||
res = makemenu(mainmenu, MAINMENU_AMOUNT);
|
res = makemenu(mainmenu, MAINMENU_AMOUNT);
|
||||||
|
|
||||||
switch(res){
|
switch(res){
|
||||||
case SD_CARD:
|
case SD_CARD:
|
||||||
filemenu("SD:/");
|
fileexplorer("SD:/");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EMMC_SAF:
|
case EMMC_SAF:
|
||||||
case EMMC_SYS:
|
case EMMC_SYS:
|
||||||
case EMMC_USR:
|
case EMMC_USR:
|
||||||
|
|
||||||
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 (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)){
|
connect_mmc(SYSMMC);
|
||||||
filemenu("emmc:/");
|
if (!mount_mmc(emmc_entries[res - 2], res - 1)){
|
||||||
|
fileexplorer("emmc:/");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
message(COLOR_RED, "EMMC failed to mount!");
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case EMUMMC_SAF:
|
||||||
|
case EMUMMC_SYS:
|
||||||
|
case EMUMMC_USR:
|
||||||
|
|
||||||
|
connect_mmc(EMUMMC);
|
||||||
|
if (!mount_mmc(emmc_entries[res - 5], res - 4)){
|
||||||
|
fileexplorer("emmc:/");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
message("EMMC failed to mount!", COLOR_RED);
|
message(COLOR_RED, "EMUMMC failed to mount!");
|
||||||
}
|
|
||||||
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case MOUNT_SD:
|
case MOUNT_SD:
|
||||||
if (return_sd_mounted(1))
|
if (return_sd_mounted(1))
|
||||||
@@ -124,7 +163,7 @@ void te_main(){
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case TOOLS:
|
case TOOLS:
|
||||||
res = makemenu(toolsmenu, 5);
|
res = makemenu(toolsmenu, 6);
|
||||||
|
|
||||||
switch(res){
|
switch(res){
|
||||||
case DISPLAY_INFO:
|
case DISPLAY_INFO:
|
||||||
@@ -134,7 +173,28 @@ void te_main(){
|
|||||||
displaygpio();
|
displaygpio();
|
||||||
break;
|
break;
|
||||||
case DUMPFIRMWARE:
|
case DUMPFIRMWARE:
|
||||||
dumpfirmware();
|
/*
|
||||||
|
if (mainmenu[4].property >= 0){
|
||||||
|
res = makemenu(mmcChoice, 3);
|
||||||
|
|
||||||
|
if (res >= 0)
|
||||||
|
dumpfirmware(res);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
*/
|
||||||
|
dumpfirmware(SYSMMC);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case DUMPUSERSAVE:
|
||||||
|
if (mainmenu[4].property >= 0){
|
||||||
|
res = makemenu(mmcChoice, 3);
|
||||||
|
|
||||||
|
if (res >= 0)
|
||||||
|
dumpusersaves(res);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
dumpusersaves(SYSMMC);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -153,7 +213,7 @@ void te_main(){
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case CREDITS:
|
case CREDITS:
|
||||||
message(CREDITS_MESSAGE, COLOR_WHITE);
|
message(COLOR_WHITE, CREDITS_MESSAGE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EXIT:
|
case EXIT:
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../utils/types.h"
|
#include "../utils/types.h"
|
||||||
|
|
||||||
#define MAINMENU_AMOUNT 9
|
#define MAINMENU_AMOUNT 12
|
||||||
#define CREDITS_MESSAGE "\nTegraexplorer, made by:\nSuch Meme, Many Skill\n\nProject based on:\nLockpick_RCM\nHekate\n\nCool people:\nshchmue\ndennthecafebabe\nDax"
|
#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 {
|
typedef struct _menu_item {
|
||||||
@@ -16,6 +16,9 @@ enum mainmenu_return {
|
|||||||
EMMC_SAF,
|
EMMC_SAF,
|
||||||
EMMC_SYS,
|
EMMC_SYS,
|
||||||
EMMC_USR,
|
EMMC_USR,
|
||||||
|
EMUMMC_SAF,
|
||||||
|
EMUMMC_SYS,
|
||||||
|
EMUMMC_USR,
|
||||||
MOUNT_SD,
|
MOUNT_SD,
|
||||||
TOOLS,
|
TOOLS,
|
||||||
SD_FORMAT,
|
SD_FORMAT,
|
||||||
@@ -34,7 +37,8 @@ enum shutdownmenu_return {
|
|||||||
enum toolsmenu_return {
|
enum toolsmenu_return {
|
||||||
DISPLAY_INFO = 1,
|
DISPLAY_INFO = 1,
|
||||||
DISPLAY_GPIO,
|
DISPLAY_GPIO,
|
||||||
DUMPFIRMWARE
|
DUMPFIRMWARE,
|
||||||
|
DUMPUSERSAVE
|
||||||
};
|
};
|
||||||
|
|
||||||
enum formatmenu_return {
|
enum formatmenu_return {
|
||||||
@@ -42,6 +46,4 @@ enum formatmenu_return {
|
|||||||
FORMAT_ALL_FAT32
|
FORMAT_ALL_FAT32
|
||||||
};
|
};
|
||||||
|
|
||||||
//menu_item mainmenu[MAINMENU_AMOUNT];
|
|
||||||
|
|
||||||
void te_main();
|
void te_main();
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
#include "../soc/fuse.h"
|
#include "../soc/fuse.h"
|
||||||
#include "emmc.h"
|
#include "emmc.h"
|
||||||
#include "fs.h"
|
#include "fs.h"
|
||||||
|
#include "io.h"
|
||||||
|
|
||||||
extern bool sd_mount();
|
extern bool sd_mount();
|
||||||
extern void sd_unmount();
|
extern void sd_unmount();
|
||||||
@@ -24,6 +25,7 @@ void displayinfo(){
|
|||||||
DWORD fre_clust, fre_sect, tot_sect;
|
DWORD fre_clust, fre_sect, tot_sect;
|
||||||
u32 capacity;
|
u32 capacity;
|
||||||
u8 fuse_count = 0;
|
u8 fuse_count = 0;
|
||||||
|
pkg1_info pkg1 = returnpkg1info();
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
for (u32 i = 0; i < 32; i++){
|
for (u32 i = 0; i < 32; i++){
|
||||||
@@ -33,7 +35,7 @@ void displayinfo(){
|
|||||||
|
|
||||||
SWAPCOLOR(COLOR_ORANGE);
|
SWAPCOLOR(COLOR_ORANGE);
|
||||||
|
|
||||||
gfx_printf("Fuse count: %d\nPKG1 version: %d\n\n", fuse_count, returnpkg1ver());
|
gfx_printf("Fuse count: %d\nPKG1 version: %d\nPKG1 id: %s\n\n", fuse_count, pkg1.ver, pkg1.id);
|
||||||
print_biskeys();
|
print_biskeys();
|
||||||
|
|
||||||
RESETCOLOR;
|
RESETCOLOR;
|
||||||
@@ -84,7 +86,7 @@ void displaygpio(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int dumpfirmware(){
|
int dumpfirmware(int mmc){
|
||||||
DIR dir;
|
DIR dir;
|
||||||
FILINFO fno;
|
FILINFO fno;
|
||||||
bool fail = false;
|
bool fail = false;
|
||||||
@@ -93,13 +95,14 @@ int dumpfirmware(){
|
|||||||
char sdfolderpath[100] = "";
|
char sdfolderpath[100] = "";
|
||||||
char syspath[100] = "";
|
char syspath[100] = "";
|
||||||
char sdpath[100] = "";
|
char sdpath[100] = "";
|
||||||
short pkg1ver = returnpkg1ver();
|
pkg1_info pkg1 = returnpkg1info();
|
||||||
u32 timer = get_tmr_s();
|
u32 timer = get_tmr_s();
|
||||||
|
|
||||||
clearscreen();
|
clearscreen();
|
||||||
mount_emmc("SYSTEM", 2);
|
connect_mmc(mmc);
|
||||||
|
mount_mmc("SYSTEM", 2);
|
||||||
|
|
||||||
gfx_printf("PKG1 version: %d\n", pkg1ver);
|
gfx_printf("PKG1 version: %d\n", pkg1.ver);
|
||||||
|
|
||||||
ret = f_mkdir("sd:/tegraexplorer");
|
ret = f_mkdir("sd:/tegraexplorer");
|
||||||
gfx_printf("Creating sd:/tegraexplorer %d\n", ret);
|
gfx_printf("Creating sd:/tegraexplorer %d\n", ret);
|
||||||
@@ -107,7 +110,7 @@ int dumpfirmware(){
|
|||||||
ret = f_mkdir("sd:/tegraexplorer/Firmware");
|
ret = f_mkdir("sd:/tegraexplorer/Firmware");
|
||||||
gfx_printf("Creating sd:/tegraexplorer/Firmware %d\n", ret);
|
gfx_printf("Creating sd:/tegraexplorer/Firmware %d\n", ret);
|
||||||
|
|
||||||
sprintf(sdfolderpath, "sd:/tegraexplorer/Firmware/%d", pkg1ver);
|
sprintf(sdfolderpath, "sd:/tegraexplorer/Firmware/%d (%s)", pkg1.ver, pkg1.id);
|
||||||
ret = f_mkdir(sdfolderpath);
|
ret = f_mkdir(sdfolderpath);
|
||||||
gfx_printf("Creating %s %d\n", sdfolderpath, ret);
|
gfx_printf("Creating %s %d\n", sdfolderpath, ret);
|
||||||
|
|
||||||
@@ -122,7 +125,7 @@ int dumpfirmware(){
|
|||||||
else
|
else
|
||||||
sprintf(syspath, "%s/%s", path, fno.fname);
|
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);
|
gfx_printf("%d %s\r", ++amount, fno.fname);
|
||||||
|
|
||||||
@@ -140,19 +143,47 @@ int dumpfirmware(){
|
|||||||
return fail;
|
return fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dumpusersaves(int mmc){
|
||||||
|
int res;
|
||||||
|
|
||||||
|
connect_mmc(mmc);
|
||||||
|
mount_mmc("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){
|
int format(int mode){
|
||||||
clearscreen();
|
clearscreen();
|
||||||
int res;
|
int res;
|
||||||
bool fatalerror = false;
|
bool fatalerror = false;
|
||||||
DWORD plist[] = {666, 61145088};
|
DWORD plist[] = {666, 61145088};
|
||||||
u32 timer, totalsectors;
|
u32 timer, totalsectors, alignedsectors, extrasectors;
|
||||||
BYTE work[FF_MAX_SS];
|
BYTE work[FF_MAX_SS];
|
||||||
DWORD clustsize = 32768;
|
DWORD clustsize = 32768;
|
||||||
BYTE formatoptions = 0;
|
BYTE formatoptions = 0;
|
||||||
formatoptions |= (FM_FAT32);
|
formatoptions |= (FM_FAT32);
|
||||||
//formatoptions |= (FM_SFD);
|
//formatoptions |= (FM_SFD);
|
||||||
|
|
||||||
disconnect_emmc();
|
disconnect_mmc();
|
||||||
|
|
||||||
timer = get_tmr_s();
|
timer = get_tmr_s();
|
||||||
totalsectors = sd_storage.csd.capacity;
|
totalsectors = sd_storage.csd.capacity;
|
||||||
@@ -163,8 +194,12 @@ int format(int mode){
|
|||||||
fatalerror = true;
|
fatalerror = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
plist[0] = totalsectors - 61145088;
|
totalsectors -= plist[1];
|
||||||
gfx_printf("\nStarting SD partitioning:\nTotalSectors: %d\nPartition1 (SD): %d\nPartition2 (EMUMMC): %d\n", totalsectors, plist[0], 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 {
|
else {
|
||||||
@@ -206,8 +241,7 @@ int format(int mode){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dump_biskeys();
|
connect_mmc(SYSMMC);
|
||||||
mount_emmc("SYSTEM", 2);
|
|
||||||
|
|
||||||
gfx_printf("\nPress any button to return%k\nTotal time taken: %ds", COLOR_WHITE, (get_tmr_s() - timer));
|
gfx_printf("\nPress any button to return%k\nTotal time taken: %ds", COLOR_WHITE, (get_tmr_s() - timer));
|
||||||
btn_wait();
|
btn_wait();
|
||||||
|
|||||||
@@ -3,4 +3,5 @@
|
|||||||
void displayinfo();
|
void displayinfo();
|
||||||
void displaygpio();
|
void displaygpio();
|
||||||
int format(int mode);
|
int format(int mode);
|
||||||
int dumpfirmware();
|
int dumpfirmware(int mmc);
|
||||||
|
void dumpusersaves(int mmc);
|
||||||
Reference in New Issue
Block a user