Compare commits
90 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
82a4d03985 | ||
|
|
195d9797fe | ||
|
|
15e1210179 | ||
|
|
e892e69929 | ||
|
|
7e8e3ece66 | ||
|
|
b5a9d94d35 | ||
|
|
f95b6e399f | ||
|
|
6551930233 | ||
|
|
c2a2694baf | ||
|
|
03df13f34c | ||
|
|
070f9c676d | ||
|
|
7dc3500a17 | ||
|
|
97bbe2a333 | ||
|
|
a6eaa1ec51 | ||
|
|
f93cc0ff44 | ||
|
|
ee145ca9aa | ||
|
|
8832b240a4 | ||
|
|
744f90611a | ||
|
|
440a921980 | ||
|
|
d0799e3cd1 | ||
|
|
5b32937f8f | ||
|
|
f438827263 | ||
|
|
0e60746179 | ||
|
|
0e39c8dda9 | ||
|
|
45a732c388 | ||
|
|
034384622f | ||
|
|
9efbbc9317 | ||
|
|
30afcddd3a | ||
|
|
38f349618f | ||
|
|
33a64abfb0 | ||
|
|
c4783fc2ca | ||
|
|
887972d67c | ||
|
|
9aff029ee4 | ||
|
|
bfcdc2ffd5 | ||
|
|
e4ae9d9d7c | ||
|
|
d255dcf665 | ||
|
|
f1a4b05524 | ||
|
|
d5c23ebf96 | ||
|
|
4e1368faaf | ||
|
|
2d6411f60a | ||
|
|
7191743f5d | ||
|
|
9d36f741d9 | ||
|
|
ff618bc285 | ||
|
|
c60eb4b722 | ||
|
|
6aed4ad7b3 | ||
|
|
761ceb7dbe | ||
|
|
3f6d1b532c | ||
|
|
144dc3a3f5 | ||
|
|
5cb50722cf | ||
|
|
7c7dd7178f | ||
|
|
d93b50205a | ||
|
|
405cb46b77 | ||
|
|
7f7c2e65ee | ||
|
|
c2df3d80dd | ||
|
|
a3b876ea3e | ||
|
|
4309194a11 | ||
|
|
ae57cb1e63 | ||
|
|
a86294218c | ||
|
|
eecefd634c | ||
|
|
37ce49a31f | ||
|
|
ab061cf0b3 | ||
|
|
1a2fd158e9 | ||
|
|
eb8652c6ec | ||
|
|
9885308bce | ||
|
|
1410fa185f | ||
|
|
6724f364b5 | ||
|
|
008d3ab494 | ||
|
|
00bd1cd083 | ||
|
|
6af2bb63b8 | ||
|
|
02504c8a36 | ||
|
|
ef76834ef4 | ||
|
|
6d75aa688c | ||
|
|
225a17116c | ||
|
|
e1f4c24686 | ||
|
|
3e8cd67129 | ||
|
|
697fc3a086 | ||
|
|
6518f37b1c | ||
|
|
81e97fa820 | ||
|
|
12802bf371 | ||
|
|
d1678be654 | ||
|
|
2a78d3c924 | ||
|
|
d4010ba04d | ||
|
|
7b6c19f820 | ||
|
|
3274d18b83 | ||
|
|
472c0e293a | ||
|
|
2e61413627 | ||
|
|
ebe9815b7b | ||
|
|
7f85f00db8 | ||
|
|
8151afb446 | ||
|
|
c0f930e75d |
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 := 0
|
LPVERSION_MINOR := 5
|
||||||
LPVERSION_BUGFX := 0
|
LPVERSION_BUGFX := 1
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
|
|||||||
20
README.md
20
README.md
@@ -9,16 +9,24 @@ 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
|
||||||
- Deleting, copying or moving files
|
- Interact with files
|
||||||
- Launching payloads
|
- 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
|
- Dumping your current firmware to sd
|
||||||
|
- Formatting the sd card
|
||||||
|
|
||||||
## Screenshot
|
## 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
|
# 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
|
||||||
|
|||||||
BIN
example.png
BIN
example.png
Binary file not shown.
|
Before Width: | Height: | Size: 25 KiB |
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -509,10 +514,10 @@ void gfx_set_rect_grey(const u8 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos
|
|||||||
}
|
}
|
||||||
|
|
||||||
void gfx_box(int x0, int y0, int x1, int y1, u32 color){
|
void gfx_box(int x0, int y0, int x1, int y1, u32 color){
|
||||||
int i = y0;
|
for (int x = x0; x < x1 + 1; x++){
|
||||||
while(y1 >= i){
|
for (int y = y0; y < y1 + 1; y++){
|
||||||
gfx_line(x0, i, x1, i, color);
|
gfx_set_pixel(x, y, color);
|
||||||
i++;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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,8 +151,8 @@ 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)
|
||||||
sector_cache = (sector_cache_t *)malloc(sizeof(sector_cache_t) * MAX_SEC_CACHE_ENTRIES);
|
sector_cache = (sector_cache_t *)malloc(sizeof(sector_cache_t) * MAX_SEC_CACHE_ENTRIES);
|
||||||
@@ -179,6 +180,7 @@ DRESULT disk_read (
|
|||||||
secindex++;
|
secindex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
//system_part (pdrv == 1) ? system_part_sys : system_part_usr
|
//system_part (pdrv == 1) ? system_part_sys : system_part_usr
|
||||||
if (nx_emmc_part_read(&storage, system_part, sector, count, buff)) {
|
if (nx_emmc_part_read(&storage, system_part, sector, count, buff)) {
|
||||||
u32 tweak_exp = 0;
|
u32 tweak_exp = 0;
|
||||||
@@ -195,10 +197,12 @@ DRESULT disk_read (
|
|||||||
|
|
||||||
// fatfs will never pull more than a cluster
|
// fatfs will never pull more than a cluster
|
||||||
_emmc_xts(9, 8, 0, tweak, regen_tweak, tweak_exp, prev_cluster, buff, buff, count * 0x200);
|
_emmc_xts(9, 8, 0, tweak, regen_tweak, tweak_exp, prev_cluster, buff, buff, count * 0x200);
|
||||||
|
/*
|
||||||
if (needs_cache_sector) {
|
if (needs_cache_sector) {
|
||||||
memcpy(sector_cache[s].cached_sector, buff, 0x200);
|
memcpy(sector_cache[s].cached_sector, buff, 0x200);
|
||||||
memcpy(sector_cache[s].tweak, tweak, 0x10);
|
memcpy(sector_cache[s].tweak, tweak, 0x10);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
prev_sector = sector + count - 1;
|
prev_sector = sector + count - 1;
|
||||||
return RES_OK;
|
return RES_OK;
|
||||||
}
|
}
|
||||||
@@ -209,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 */
|
||||||
|
|||||||
@@ -38,14 +38,14 @@
|
|||||||
#include "utils/dirlist.h"
|
#include "utils/dirlist.h"
|
||||||
#include "utils/sprintf.h"
|
#include "utils/sprintf.h"
|
||||||
#include "utils/util.h"
|
#include "utils/util.h"
|
||||||
#include "tegraexplorer/te.h"
|
#include "tegraexplorer/mainmenu.h"
|
||||||
|
|
||||||
//#include "keys/keys.h"
|
//#include "keys/keys.h"
|
||||||
|
|
||||||
sdmmc_t sd_sdmmc;
|
sdmmc_t sd_sdmmc;
|
||||||
sdmmc_storage_t sd_storage;
|
sdmmc_storage_t sd_storage;
|
||||||
__attribute__ ((aligned (16))) FATFS sd_fs;
|
__attribute__ ((aligned (16))) FATFS sd_fs;
|
||||||
static bool sd_mounted;
|
bool sd_mounted, sd_inited;
|
||||||
volatile nyx_storage_t *nyx_str = (nyx_storage_t *)NYX_STORAGE_ADDR;
|
volatile nyx_storage_t *nyx_str = (nyx_storage_t *)NYX_STORAGE_ADDR;
|
||||||
hekate_config h_cfg;
|
hekate_config h_cfg;
|
||||||
boot_cfg_t __attribute__((section ("._boot_cfg"))) b_cfg;
|
boot_cfg_t __attribute__((section ("._boot_cfg"))) b_cfg;
|
||||||
@@ -58,9 +58,11 @@ bool sd_mount()
|
|||||||
if (!sdmmc_storage_init_sd(&sd_storage, &sd_sdmmc, SDMMC_1, SDMMC_BUS_WIDTH_4, 11))
|
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!");
|
EPRINTF("Failed to init SD card.\nMake sure that it is inserted.\nOr that SD reader is properly seated!");
|
||||||
|
sd_inited = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
sd_inited = true;
|
||||||
int res = 0;
|
int res = 0;
|
||||||
res = f_mount(&sd_fs, "sd:", 1);
|
res = f_mount(&sd_fs, "sd:", 1);
|
||||||
if (res == FR_OK)
|
if (res == FR_OK)
|
||||||
@@ -84,6 +86,7 @@ void sd_unmount()
|
|||||||
f_mount(NULL, "sd:", 1);
|
f_mount(NULL, "sd:", 1);
|
||||||
sdmmc_storage_end(&sd_storage);
|
sdmmc_storage_end(&sd_storage);
|
||||||
sd_mounted = false;
|
sd_mounted = false;
|
||||||
|
sd_inited = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
113
source/tegraexplorer/common/common.h
Normal file
113
source/tegraexplorer/common/common.h
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
extern const char *gfx_file_size_names[];
|
||||||
|
extern const char *menu_sd_states[];
|
||||||
|
extern const char *emmc_fs_entries[];
|
||||||
|
extern const char *utils_err_codes[];
|
||||||
|
extern const char *pkg2names[];
|
||||||
|
extern const char *mainmenu_credits;
|
||||||
|
|
||||||
|
enum utils_err_codes_te_call {
|
||||||
|
ERR_SAME_LOC = 50,
|
||||||
|
ERR_DISK_WRITE_FAILED,
|
||||||
|
ERR_EMPTY_CLIPBOARD,
|
||||||
|
ERR_FOLDER_ROOT = 54,
|
||||||
|
ERR_DEST_PART_OF_SRC,
|
||||||
|
ERR_PART_NOT_FOUND,
|
||||||
|
ERR_BISKEY_DUMP_FAILED,
|
||||||
|
ERR_MEM_ALLOC_FAILED,
|
||||||
|
ERR_EMMC_READ_FAILED,
|
||||||
|
ERR_EMMC_WRITE_FAILED,
|
||||||
|
ERR_FILE_TOO_BIG_FOR_DEST,
|
||||||
|
ERR_SD_EJECTED,
|
||||||
|
ERR_PARSE_FAIL,
|
||||||
|
ERR_CANNOT_COPY_FILE_TO_FS_PART,
|
||||||
|
ERR_NO_DESTENATION
|
||||||
|
};
|
||||||
|
|
||||||
|
extern const char *utils_err_codes_te[];
|
||||||
|
|
||||||
|
enum mainmenu_main_return {
|
||||||
|
MAIN_SDCARD = 0,
|
||||||
|
MAIN_EMMC_SAF,
|
||||||
|
MAIN_EMMC_SYS,
|
||||||
|
MAIN_EMMC_USR,
|
||||||
|
MAIN_EMUMMC_SAF,
|
||||||
|
MAIN_EMUMMC_SYS,
|
||||||
|
MAIN_EMUMMC_USR,
|
||||||
|
MAIN_MOUNT_SD,
|
||||||
|
MAIN_TOOLS,
|
||||||
|
MAIN_SD_FORMAT,
|
||||||
|
MAIN_CREDITS,
|
||||||
|
MAIN_EXIT
|
||||||
|
};
|
||||||
|
|
||||||
|
extern menu_entry mainmenu_main[];
|
||||||
|
|
||||||
|
enum mainmenu_shutdown_return {
|
||||||
|
SHUTDOWN_REBOOT_RCM = 1,
|
||||||
|
SHUTDOWN_REBOOT_NORMAL,
|
||||||
|
SHUTDOWN_POWER_OFF,
|
||||||
|
SHUTDOWN_HEKATE,
|
||||||
|
SHUTDOWN_AMS
|
||||||
|
};
|
||||||
|
|
||||||
|
extern menu_entry mainmenu_shutdown[];
|
||||||
|
|
||||||
|
enum mainmenu_tools_return {
|
||||||
|
TOOLS_DISPLAY_INFO = 1,
|
||||||
|
TOOLS_DISPLAY_GPIO,
|
||||||
|
TOOLS_DUMPFIRMWARE,
|
||||||
|
TOOLS_DUMPUSERSAVE
|
||||||
|
};
|
||||||
|
|
||||||
|
extern menu_entry mainmenu_tools[];
|
||||||
|
|
||||||
|
enum mainmenu_format_return {
|
||||||
|
FORMAT_ALL_FAT32 = 1,
|
||||||
|
FORMAT_EMUMMC
|
||||||
|
};
|
||||||
|
|
||||||
|
extern menu_entry mainmenu_format[];
|
||||||
|
|
||||||
|
enum mmc_types {
|
||||||
|
SYSMMC = 1,
|
||||||
|
EMUMMC
|
||||||
|
};
|
||||||
|
|
||||||
|
extern menu_entry utils_mmcChoice[];
|
||||||
|
|
||||||
|
enum fs_menu_file_return {
|
||||||
|
FILE_COPY = 4,
|
||||||
|
FILE_MOVE,
|
||||||
|
FILE_DELETE,
|
||||||
|
FILE_PAYLOAD,
|
||||||
|
FILE_SCRIPT,
|
||||||
|
FILE_HEXVIEW,
|
||||||
|
FILE_DUMPBIS
|
||||||
|
};
|
||||||
|
|
||||||
|
extern menu_entry fs_menu_file[];
|
||||||
|
|
||||||
|
enum fs_menu_folder_return {
|
||||||
|
DIR_EXITFOLDER = 2,
|
||||||
|
DIR_COPYFOLDER,
|
||||||
|
DIR_DELETEFOLDER
|
||||||
|
};
|
||||||
|
|
||||||
|
extern menu_entry fs_menu_folder[];
|
||||||
|
|
||||||
|
enum fs_menu_startdir_return {
|
||||||
|
FILEMENU_RETURN = 0,
|
||||||
|
FILEMENU_CLIPBOARD,
|
||||||
|
FILEMENU_CURFOLDER
|
||||||
|
};
|
||||||
|
|
||||||
|
extern menu_entry fs_menu_startdir[];
|
||||||
|
|
||||||
|
extern gpt_entry_rule gpt_fs_rules[];
|
||||||
|
|
||||||
|
extern menu_entry mmcmenu_start[];
|
||||||
|
|
||||||
|
extern menu_entry mmcmenu_filemenu[];
|
||||||
67
source/tegraexplorer/common/strings.c
Normal file
67
source/tegraexplorer/common/strings.c
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
const char *gfx_file_size_names[] = {
|
||||||
|
"B ",
|
||||||
|
"KB",
|
||||||
|
"MB",
|
||||||
|
"GB"
|
||||||
|
};
|
||||||
|
|
||||||
|
const char *menu_sd_states[] = {
|
||||||
|
"\nUnmount SD",
|
||||||
|
"\nMount SD"
|
||||||
|
};
|
||||||
|
|
||||||
|
const char *emmc_fs_entries[] = {
|
||||||
|
"SAFE",
|
||||||
|
"SYSTEM",
|
||||||
|
"USER"
|
||||||
|
};
|
||||||
|
|
||||||
|
const char *utils_err_codes[] = {
|
||||||
|
"OK",
|
||||||
|
"I/O ERROR",
|
||||||
|
"NO DISK",
|
||||||
|
"NOT READY",
|
||||||
|
"NO FILE",
|
||||||
|
"NO PATH",
|
||||||
|
"PATH INVALID",
|
||||||
|
"ACCESS DENIED",
|
||||||
|
"ACCESS DENIED",
|
||||||
|
"INVALID PTR",
|
||||||
|
"PROTECTED",
|
||||||
|
"INVALID DRIVE",
|
||||||
|
"NO MEM",
|
||||||
|
"NO FAT",
|
||||||
|
"MKFS ABORT"
|
||||||
|
};
|
||||||
|
|
||||||
|
const char *utils_err_codes_te[] = { // these start at 50
|
||||||
|
"SAME LOC",
|
||||||
|
"DISK WRITE FAILED",
|
||||||
|
"EMPTY CLIPBOARD",
|
||||||
|
"DEFENITION OF INSANITY",
|
||||||
|
"FOLDER ROOT",
|
||||||
|
"DEST PART OF SRC",
|
||||||
|
"PART NOT FOUND",
|
||||||
|
"BISKEY DUMP FAILED",
|
||||||
|
"MEM ALLOC FAILED",
|
||||||
|
"EMMC READ FAILED",
|
||||||
|
"EMMC WRITE FAILED",
|
||||||
|
"FILE TOO BIG FOR DEST",
|
||||||
|
"SD EJECTED",
|
||||||
|
"PARSING FAILED",
|
||||||
|
"CANNOT COPY FILE TO FS PART",
|
||||||
|
"NO DESTENATION"
|
||||||
|
};
|
||||||
|
|
||||||
|
const char *pkg2names[] = {
|
||||||
|
"BCPKG2-1-Normal-Main",
|
||||||
|
"BCPKG2-2-Normal-Sub",
|
||||||
|
"BCPKG2-3-SafeMode-Main",
|
||||||
|
"BCPKG2-4-SafeMode-Sub",
|
||||||
|
"BCPKG2-5-Repair-Main",
|
||||||
|
"BCPKG2-6-Repair-Sub"
|
||||||
|
};
|
||||||
|
|
||||||
|
const char *mainmenu_credits = "\nTegraexplorer, made by:\nSuch Meme, Many Skill\n\nProject based on:\nLockpick_RCM\nHekate\n\nCool people:\nshchmue\ndennthecafebabe\nDax";
|
||||||
92
source/tegraexplorer/common/structs.c
Normal file
92
source/tegraexplorer/common/structs.c
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
#include "common.h"
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
menu_entry mainmenu_main[] = {
|
||||||
|
{"[SD:/] SD CARD", COLOR_GREEN, ISMENU},
|
||||||
|
{"[EMMC:/] EMMC", COLOR_ORANGE, ISMENU},
|
||||||
|
{"[EMMC:/] EMUMMC", COLOR_BLUE, ISMENU},
|
||||||
|
{"\nMount/Unmount SD", COLOR_WHITE, ISMENU},
|
||||||
|
{"Tools", COLOR_VIOLET, ISMENU},
|
||||||
|
{"SD format", COLOR_VIOLET, ISMENU},
|
||||||
|
{"\nCredits", COLOR_WHITE, ISMENU},
|
||||||
|
{"Exit", COLOR_WHITE, ISMENU}
|
||||||
|
};
|
||||||
|
|
||||||
|
menu_entry mainmenu_shutdown[] = {
|
||||||
|
{"Back", COLOR_WHITE, ISMENU},
|
||||||
|
{"\nReboot to RCM", COLOR_VIOLET, ISMENU},
|
||||||
|
{"Reboot normally", COLOR_ORANGE, ISMENU},
|
||||||
|
{"Power off\n", COLOR_BLUE, ISMENU},
|
||||||
|
{"Reboot to Hekate", COLOR_GREEN, ISMENU},
|
||||||
|
{"Reboot to Atmosphere", COLOR_GREEN, ISMENU}
|
||||||
|
};
|
||||||
|
|
||||||
|
menu_entry mainmenu_tools[] = {
|
||||||
|
{"Back", COLOR_WHITE, ISMENU},
|
||||||
|
{"\nDisplay Console Info", COLOR_GREEN, ISMENU},
|
||||||
|
{"Display GPIO pins", COLOR_VIOLET, ISMENU},
|
||||||
|
{"Dump Firmware", COLOR_BLUE, ISMENU},
|
||||||
|
{"Dump User Saves", COLOR_YELLOW, ISMENU}
|
||||||
|
};
|
||||||
|
|
||||||
|
menu_entry mainmenu_format[] = {
|
||||||
|
{"Back\n", COLOR_WHITE, ISMENU},
|
||||||
|
{"Format entire SD to FAT32", COLOR_RED, ISMENU},
|
||||||
|
{"Format for EmuMMC setup (FAT32/RAW)", COLOR_RED, ISMENU}
|
||||||
|
};
|
||||||
|
|
||||||
|
menu_entry utils_mmcChoice[] = {
|
||||||
|
{"Back\n", COLOR_WHITE, ISMENU},
|
||||||
|
{"SysMMC", COLOR_ORANGE, ISMENU},
|
||||||
|
{"EmuMMC", COLOR_BLUE, ISMENU}
|
||||||
|
};
|
||||||
|
|
||||||
|
menu_entry fs_menu_file[] = {
|
||||||
|
{NULL, COLOR_GREEN, ISMENU | ISSKIP},
|
||||||
|
{NULL, COLOR_VIOLET, ISMENU | ISSKIP},
|
||||||
|
{NULL, COLOR_VIOLET, ISMENU | ISSKIP},
|
||||||
|
{"\n\n\nBack", COLOR_WHITE, ISMENU},
|
||||||
|
{"\nCopy to clipboard", COLOR_BLUE, ISMENU},
|
||||||
|
{"Move to clipboard", COLOR_BLUE, ISMENU},
|
||||||
|
{"\nDelete file\n", COLOR_RED, ISMENU},
|
||||||
|
{"Launch Payload", COLOR_ORANGE, ISMENU},
|
||||||
|
{"Launch Script", COLOR_YELLOW, ISMENU},
|
||||||
|
{"View Hex", COLOR_GREEN, ISMENU},
|
||||||
|
{"\nExtract BIS", COLOR_YELLOW, ISMENU}
|
||||||
|
};
|
||||||
|
|
||||||
|
menu_entry fs_menu_folder[] = {
|
||||||
|
{NULL, COLOR_VIOLET, ISMENU | ISSKIP},
|
||||||
|
{"\nBack", COLOR_WHITE, ISMENU},
|
||||||
|
{"Return to main menu\n", COLOR_BLUE, ISMENU},
|
||||||
|
{"Copy to clipboard", COLOR_VIOLET, ISMENU},
|
||||||
|
{"Delete folder", COLOR_RED, ISMENU}
|
||||||
|
};
|
||||||
|
|
||||||
|
menu_entry fs_menu_startdir[] = {
|
||||||
|
{"Folder -> previous folder ", COLOR_ORANGE, ISMENU},
|
||||||
|
{"Clipboard -> Current folder ", COLOR_ORANGE, ISMENU},
|
||||||
|
{"Current folder menu ", COLOR_ORANGE, ISMENU}
|
||||||
|
};
|
||||||
|
|
||||||
|
gpt_entry_rule gpt_fs_rules[] = {
|
||||||
|
{"PRODINFOF", 0 | isFS},
|
||||||
|
{"SAFE", 1 | isFS },
|
||||||
|
{"SYSTEM", 2 | isFS},
|
||||||
|
{"USER", 3 | isFS},
|
||||||
|
{NULL, 0}
|
||||||
|
};
|
||||||
|
|
||||||
|
menu_entry mmcmenu_start[] = {
|
||||||
|
{"Back", COLOR_ORANGE, ISMENU},
|
||||||
|
{"Dump File Partitions", COLOR_ORANGE, ISMENU},
|
||||||
|
{"Clipboard -> Partition\n", COLOR_ORANGE, ISMENU},
|
||||||
|
{"BOOT0/1", COLOR_BLUE, isBOOT | ISMENU}
|
||||||
|
};
|
||||||
|
|
||||||
|
menu_entry mmcmenu_filemenu[] = {
|
||||||
|
{"Part:", COLOR_ORANGE, ISSKIP | ISMENU},
|
||||||
|
{NULL, COLOR_VIOLET, ISSKIP | ISMENU},
|
||||||
|
{"\nBack", COLOR_WHITE, ISMENU},
|
||||||
|
{"Dump to SD", COLOR_YELLOW, ISMENU}
|
||||||
|
};
|
||||||
54
source/tegraexplorer/common/types.h
Normal file
54
source/tegraexplorer/common/types.h
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "../../utils/types.h"
|
||||||
|
|
||||||
|
#define ISDIR (1 << 0)
|
||||||
|
#define ISARC (1 << 1)
|
||||||
|
|
||||||
|
#define ISHIDE (1 << 8)
|
||||||
|
#define ISMENU (1 << 9)
|
||||||
|
#define ISSKIP (1 << 10)
|
||||||
|
|
||||||
|
#define ISGB (1 << 7)
|
||||||
|
#define ISMB (1 << 6)
|
||||||
|
#define ISKB (1 << 5)
|
||||||
|
#define ISB (1 << 4)
|
||||||
|
|
||||||
|
#define SETBIT(object, shift, value) ((value) ? (object |= shift) : (object &= ~shift))
|
||||||
|
|
||||||
|
/* Bit table for property as a file:
|
||||||
|
0000 0001: Directory bit
|
||||||
|
0000 0010: Archive bit (or hideme)
|
||||||
|
0001 0000: Size component is a Byte
|
||||||
|
0010 0000: Size component is a KiloByte
|
||||||
|
0100 0000: Size component is a MegaByte
|
||||||
|
1000 0000: Size component is a GigaByte : note that this won't surpass gigabytes, but i don't expect people to have a single file that's a terrabyte big
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define COPY_MODE_PRINT 0x1
|
||||||
|
#define COPY_MODE_CANCEL 0x2
|
||||||
|
#define BUFSIZE 32768
|
||||||
|
|
||||||
|
#define OPERATIONCOPY 0x2
|
||||||
|
#define OPERATIONMOVE 0x4
|
||||||
|
|
||||||
|
#define PART_BOOT 0x1
|
||||||
|
#define PART_PKG2 0x2
|
||||||
|
|
||||||
|
#define BOOT0_ARG 0x80
|
||||||
|
#define BOOT1_ARG 0x40
|
||||||
|
#define BCPKG2_1_ARG 0x20
|
||||||
|
#define BCPKG2_3_ARG 0x10
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char *name;
|
||||||
|
u32 storage;
|
||||||
|
u16 property;
|
||||||
|
} menu_entry;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const char *name;
|
||||||
|
u8 property;
|
||||||
|
} gpt_entry_rule;
|
||||||
|
|
||||||
|
#define isFS 0x80
|
||||||
|
#define isBOOT 0x2
|
||||||
@@ -1,34 +1,42 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "../mem/heap.h"
|
|
||||||
#include "gfx.h"
|
|
||||||
#include "fs.h"
|
|
||||||
#include "emmc.h"
|
#include "emmc.h"
|
||||||
#include "../utils/types.h"
|
#include "../../mem/heap.h"
|
||||||
#include "../libs/fatfs/ff.h"
|
#include "../../utils/types.h"
|
||||||
#include "../utils/sprintf.h"
|
#include "../../libs/fatfs/ff.h"
|
||||||
#include "../utils/btn.h"
|
#include "../../utils/sprintf.h"
|
||||||
#include "../gfx/gfx.h"
|
#include "../../utils/btn.h"
|
||||||
#include "../utils/util.h"
|
#include "../../gfx/gfx.h"
|
||||||
#include "../hos/pkg1.h"
|
#include "../../utils/util.h"
|
||||||
#include "../storage/sdmmc.h"
|
#include "../../hos/pkg1.h"
|
||||||
#include "../storage/nx_emmc.h"
|
#include "../../storage/sdmmc.h"
|
||||||
#include "../sec/tsec.h"
|
#include "../../storage/nx_emmc.h"
|
||||||
#include "../soc/t210.h"
|
#include "../../sec/tsec.h"
|
||||||
#include "../soc/fuse.h"
|
#include "../../soc/t210.h"
|
||||||
#include "../mem/mc.h"
|
#include "../../soc/fuse.h"
|
||||||
#include "../sec/se.h"
|
#include "../../mem/mc.h"
|
||||||
#include "../soc/hw_init.h"
|
#include "../../sec/se.h"
|
||||||
#include "../mem/emc.h"
|
#include "../../soc/hw_init.h"
|
||||||
#include "../mem/sdram.h"
|
#include "../../mem/emc.h"
|
||||||
|
#include "../../mem/sdram.h"
|
||||||
|
#include "../../storage/emummc.h"
|
||||||
|
#include "../../config/config.h"
|
||||||
|
#include "../common/common.h"
|
||||||
|
#include "../gfx/gfxutils.h"
|
||||||
|
#include "../../utils/list.h"
|
||||||
|
#include "../../mem/heap.h"
|
||||||
|
|
||||||
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(sys_gpt);
|
||||||
|
LIST_INIT(emu_gpt);
|
||||||
|
|
||||||
u8 bis_key[4][32];
|
u8 bis_key[4][32];
|
||||||
short pkg1ver;
|
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); };
|
||||||
|
|
||||||
@@ -44,38 +52,79 @@ static void _generate_kek(u32 ks, const void *key_source, void *master_key, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
void print_biskeys(){
|
void print_biskeys(){
|
||||||
gfx_printf("\n");
|
gfx_printf("Bis_Key_00\n");
|
||||||
gfx_hexdump(0, bis_key[0], 32);
|
gfx_hexdump(0, bis_key[0], 32);
|
||||||
|
gfx_printf("Bis_Key_01\n");
|
||||||
gfx_hexdump(0, bis_key[1], 32);
|
gfx_hexdump(0, bis_key[1], 32);
|
||||||
|
gfx_printf("Bis_Key_02 & 03\n");
|
||||||
gfx_hexdump(0, bis_key[2], 32);
|
gfx_hexdump(0, bis_key[2], 32);
|
||||||
}
|
}
|
||||||
|
|
||||||
int mount_emmc(char *partition, int biskeynumb){
|
pkg1_info returnpkg1info(){
|
||||||
f_unmount("emmc:");
|
return pkg1inf;
|
||||||
|
}
|
||||||
|
|
||||||
|
int connect_part(const char *partition){
|
||||||
|
sdmmc_storage_set_mmc_partition(&storage, 0);
|
||||||
|
|
||||||
|
system_part = nx_emmc_part_find(selectGpt(currentlyMounted), partition);
|
||||||
|
if (!system_part) {
|
||||||
|
gfx_errDisplay("connect_mmc_part", ERR_PART_NOT_FOUND, 0);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int mount_mmc(const char *partition, const int biskeynumb){
|
||||||
|
int res;
|
||||||
|
f_unmount("emmc:");
|
||||||
|
|
||||||
se_aes_key_set(8, bis_key[biskeynumb] + 0x00, 0x10);
|
se_aes_key_set(8, bis_key[biskeynumb] + 0x00, 0x10);
|
||||||
se_aes_key_set(9, bis_key[biskeynumb] + 0x10, 0x10);
|
se_aes_key_set(9, bis_key[biskeynumb] + 0x10, 0x10);
|
||||||
|
|
||||||
system_part = nx_emmc_part_find(&gpt, partition);
|
if (connect_part(partition))
|
||||||
if (!system_part) {
|
return 1;
|
||||||
gfx_printf("Failed to locate %s partition.", partition);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (f_mount(&emmc, "emmc:", 1)) {
|
if ((res = f_mount(&emmc, "emmc:", 1))) {
|
||||||
gfx_printf("Mount failed of %s.", partition);
|
gfx_errDisplay("mount_mmc", res, 0);
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
short returnpkg1ver(){
|
void connect_mmc(short mmctype){
|
||||||
return pkg1ver;
|
if (mmctype != currentlyMounted){
|
||||||
|
disconnect_mmc();
|
||||||
|
h_cfg.emummc_force_disable = 0;
|
||||||
|
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(){
|
||||||
@@ -84,7 +133,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);
|
||||||
@@ -167,43 +216,36 @@ int dump_biskeys(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
sdmmc_storage_set_mmc_partition(&storage, 0);
|
sdmmc_storage_set_mmc_partition(&storage, 0);
|
||||||
// Parse eMMC GPT.
|
nx_emmc_gpt_parse(&sys_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;
|
||||||
|
strcpy(pkg1inf.id, pkg1_id->id);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
void dumpEmuGpt(){
|
||||||
system_part = nx_emmc_part_find(&gpt, "SYSTEM");
|
connect_mmc(EMUMMC);
|
||||||
if (!system_part) {
|
emummc_storage_set_mmc_partition(&storage, 0);
|
||||||
gfx_printf("Failed to locate SYSTEM partition.");
|
nx_emmc_gpt_parse(&emu_gpt, &storage);
|
||||||
return -1;
|
}
|
||||||
|
|
||||||
|
link_t *selectGpt(short mmcType){
|
||||||
|
switch(mmcType){
|
||||||
|
case SYSMMC:
|
||||||
|
return &sys_gpt;
|
||||||
|
case EMUMMC:
|
||||||
|
return &emu_gpt;
|
||||||
}
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (f_mount(&emmc_sys, "system:", 1)) {
|
int checkGptRules(char *in){
|
||||||
gfx_printf("Mount failed of SYSTEM.");
|
for (int i = 0; gpt_fs_rules[i].name != NULL; i++){
|
||||||
return -1;
|
if (!strcmp(in, gpt_fs_rules[i].name))
|
||||||
|
return gpt_fs_rules[i].property;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
pkg1ver = pkg1_id->kb;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,24 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "../../utils/types.h"
|
||||||
|
#include "../../utils/list.h"
|
||||||
|
|
||||||
|
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();
|
||||||
|
int connect_part(const char *partition);
|
||||||
|
void dumpEmuGpt();
|
||||||
|
link_t *selectGpt(short mmcType);
|
||||||
|
int checkGptRules(char *in);
|
||||||
|
|
||||||
static const u8 zeros[0x10] = {0};
|
static const u8 zeros[0x10] = {0};
|
||||||
|
|
||||||
@@ -40,4 +53,11 @@ 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
|
||||||
|
};
|
||||||
|
*/
|
||||||
184
source/tegraexplorer/emmc/emmcdumppart.c
Normal file
184
source/tegraexplorer/emmc/emmcdumppart.c
Normal file
@@ -0,0 +1,184 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include "emmcoperations.h"
|
||||||
|
#include "../../gfx/gfx.h"
|
||||||
|
#include "../gfx/gfxutils.h"
|
||||||
|
#include "../../utils/types.h"
|
||||||
|
#include "emmc.h"
|
||||||
|
#include "../../storage/emummc.h"
|
||||||
|
#include "../common/common.h"
|
||||||
|
#include "../../libs/fatfs/ff.h"
|
||||||
|
#include "../../utils/sprintf.h"
|
||||||
|
#include "../../utils/btn.h"
|
||||||
|
#include "../../mem/heap.h"
|
||||||
|
#include "../../storage/nx_emmc.h"
|
||||||
|
#include "../common/types.h"
|
||||||
|
#include "../utils/utils.h"
|
||||||
|
#include "../fs/fsutils.h"
|
||||||
|
|
||||||
|
extern sdmmc_storage_t storage;
|
||||||
|
extern emmc_part_t *system_part;
|
||||||
|
|
||||||
|
int emmcDumpPart(char *path, sdmmc_storage_t *mmcstorage, emmc_part_t *part){
|
||||||
|
FIL fp;
|
||||||
|
u8 *buf;
|
||||||
|
u32 lba_curr = part->lba_start;
|
||||||
|
u32 bytesWritten = 0;
|
||||||
|
u32 totalSectors = part->lba_end - part->lba_start + 1;
|
||||||
|
u64 totalSize = (u64)((u64)totalSectors << 9);
|
||||||
|
u32 num = 0;
|
||||||
|
u32 pct = 0;
|
||||||
|
int res;
|
||||||
|
|
||||||
|
gfx_printf("Initializing\r");
|
||||||
|
buf = calloc(BUFSIZE, sizeof(u8));
|
||||||
|
|
||||||
|
if (!buf){
|
||||||
|
gfx_errDisplay("dump_emmc_part", ERR_MEM_ALLOC_FAILED, 1);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((res = f_open(&fp, path, FA_CREATE_ALWAYS | FA_WRITE))){
|
||||||
|
gfx_errDisplay("dump_emmc_part", res, 2);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
f_lseek(&fp, totalSize);
|
||||||
|
f_lseek(&fp, 0);
|
||||||
|
|
||||||
|
while (totalSectors > 0){
|
||||||
|
num = MIN(totalSectors, 64);
|
||||||
|
if (!emummc_storage_read(mmcstorage, lba_curr, num, buf)){
|
||||||
|
gfx_errDisplay("dump_emmc_part", ERR_EMMC_READ_FAILED, 3);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if ((res = f_write(&fp, buf, num * NX_EMMC_BLOCKSIZE, NULL))){
|
||||||
|
gfx_errDisplay("dump_emmc_part", res, 4);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
pct = (u64)((u64)(lba_curr - part->lba_start) * 100u) / (u64)(part->lba_end - part->lba_start);
|
||||||
|
gfx_printf("Progress: %d%%\r", pct);
|
||||||
|
|
||||||
|
lba_curr += num;
|
||||||
|
totalSectors -= num;
|
||||||
|
bytesWritten += num * NX_EMMC_BLOCKSIZE;
|
||||||
|
}
|
||||||
|
gfx_printf(" \r");
|
||||||
|
f_close(&fp);
|
||||||
|
free(buf);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int existsCheck(char *path){
|
||||||
|
int res = 0;
|
||||||
|
|
||||||
|
if (fsutil_checkfile(path)){
|
||||||
|
gfx_printf("File already exists! Overwrite?\nVol +/- to cancel\n");
|
||||||
|
res = gfx_makewaitmenu("Power to continue", 3);
|
||||||
|
gfx_printf("\r \r");
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
int dump_emmc_parts(u16 parts, u8 mmctype){
|
||||||
|
char *path;
|
||||||
|
char basepath[] = "sd:/tegraexplorer/partition_dumps";
|
||||||
|
f_mkdir("sd:/tegraexplorer");
|
||||||
|
f_mkdir("sd:/tegraexplorer/partition_dumps");
|
||||||
|
|
||||||
|
connect_mmc(mmctype);
|
||||||
|
gfx_clearscreen();
|
||||||
|
|
||||||
|
if (parts & PART_BOOT){
|
||||||
|
emmc_part_t bootPart;
|
||||||
|
const u32 BOOT_PART_SIZE = storage.ext_csd.boot_mult << 17;
|
||||||
|
memset(&bootPart, 0, sizeof(bootPart));
|
||||||
|
|
||||||
|
bootPart.lba_start = 0;
|
||||||
|
bootPart.lba_end = (BOOT_PART_SIZE / NX_EMMC_BLOCKSIZE) - 1;
|
||||||
|
|
||||||
|
for (int i = 0; i < 2; i++){
|
||||||
|
strcpy(bootPart.name, "BOOT");
|
||||||
|
bootPart.name[4] = (u8)('0' + i);
|
||||||
|
bootPart.name[5] = 0;
|
||||||
|
|
||||||
|
emummc_storage_set_mmc_partition(&storage, i + 1);
|
||||||
|
utils_copystring(fsutil_getnextloc(basepath, bootPart.name), &path);
|
||||||
|
|
||||||
|
if (!existsCheck(path))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
gfx_printf("Dumping %s\n", bootPart.name);
|
||||||
|
|
||||||
|
dump_emmc_part(path, &storage, &bootPart);
|
||||||
|
free(path);
|
||||||
|
}
|
||||||
|
emummc_storage_set_mmc_partition(&storage, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parts & PART_PKG2){
|
||||||
|
for (int i = 0; i < 6; i++){
|
||||||
|
utils_copystring(fsutil_getnextloc(basepath, pkg2names[i]), &path);
|
||||||
|
gfx_printf("Dumping %s\n", pkg2names[i]);
|
||||||
|
|
||||||
|
emmcDumpSpecific(pkg2names[i], path);
|
||||||
|
free(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx_printf("\nDone!");
|
||||||
|
btn_wait();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
int emmcDumpBoot(char *basePath){
|
||||||
|
emmc_part_t bootPart;
|
||||||
|
const u32 BOOT_PART_SIZE = storage.ext_csd.boot_mult << 17;
|
||||||
|
char *path;
|
||||||
|
memset(&bootPart, 0, sizeof(emmc_part_t));
|
||||||
|
|
||||||
|
bootPart.lba_start = 0;
|
||||||
|
bootPart.lba_end = (BOOT_PART_SIZE / NX_EMMC_BLOCKSIZE) - 1;
|
||||||
|
|
||||||
|
for (int i = 0; i < 2; i++){
|
||||||
|
strcpy(bootPart.name, "BOOT");
|
||||||
|
bootPart.name[4] = (u8)('0' + i);
|
||||||
|
bootPart.name[5] = 0;
|
||||||
|
|
||||||
|
emummc_storage_set_mmc_partition(&storage, i + 1);
|
||||||
|
utils_copystring(fsutil_getnextloc(basePath, bootPart.name), &path);
|
||||||
|
|
||||||
|
if (!existsCheck(path))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
SWAPCOLOR(COLOR_BLUE);
|
||||||
|
gfx_printf("Dumping %s\n", bootPart.name);
|
||||||
|
RESETCOLOR;
|
||||||
|
|
||||||
|
emmcDumpPart(path, &storage, &bootPart);
|
||||||
|
free(path);
|
||||||
|
}
|
||||||
|
emummc_storage_set_mmc_partition(&storage, 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int emmcDumpSpecific(char *part, char *path){
|
||||||
|
if (!existsCheck(path))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
emummc_storage_set_mmc_partition(&storage, 0);
|
||||||
|
if (connect_part(part)){
|
||||||
|
gfx_errDisplay("dump_emmc_specific", ERR_PART_NOT_FOUND, 0);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SWAPCOLOR(COLOR_VIOLET);
|
||||||
|
gfx_printf("Dumping %s\n", part);
|
||||||
|
RESETCOLOR;
|
||||||
|
emmcDumpPart(path, &storage, system_part);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
171
source/tegraexplorer/emmc/emmcmenu.c
Normal file
171
source/tegraexplorer/emmc/emmcmenu.c
Normal file
@@ -0,0 +1,171 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include "emmc.h"
|
||||||
|
#include "../../mem/heap.h"
|
||||||
|
#include "../../utils/types.h"
|
||||||
|
#include "../../libs/fatfs/ff.h"
|
||||||
|
#include "../../utils/btn.h"
|
||||||
|
#include "../../gfx/gfx.h"
|
||||||
|
#include "../../utils/util.h"
|
||||||
|
#include "../../storage/nx_emmc.h"
|
||||||
|
#include "../../mem/mc.h"
|
||||||
|
#include "../../mem/emc.h"
|
||||||
|
#include "../../storage/emummc.h"
|
||||||
|
#include "../../config/config.h"
|
||||||
|
#include "../common/common.h"
|
||||||
|
#include "../gfx/gfxutils.h"
|
||||||
|
#include "../../utils/list.h"
|
||||||
|
#include "../../mem/heap.h"
|
||||||
|
#include "emmcmenu.h"
|
||||||
|
#include "../fs/fsreader.h"
|
||||||
|
#include "../utils/utils.h"
|
||||||
|
#include "../gfx/menu.h"
|
||||||
|
#include "../fs/fsmenu.h"
|
||||||
|
#include "emmcoperations.h"
|
||||||
|
#include "../fs/fsutils.h"
|
||||||
|
|
||||||
|
menu_entry *mmcMenuEntries = NULL;
|
||||||
|
extern sdmmc_storage_t storage;
|
||||||
|
extern emmc_part_t *system_part;
|
||||||
|
extern char *clipboard;
|
||||||
|
extern u8 clipboardhelper;
|
||||||
|
|
||||||
|
|
||||||
|
void addEntry(emmc_part_t *part, u8 property, int spot){
|
||||||
|
if (mmcMenuEntries[spot].name != NULL){
|
||||||
|
free(mmcMenuEntries[spot].name);
|
||||||
|
}
|
||||||
|
|
||||||
|
utils_copystring(part->name, &mmcMenuEntries[spot].name);
|
||||||
|
|
||||||
|
if (property & isFS){
|
||||||
|
mmcMenuEntries[spot].storage = (u32)(property & 0x7F);
|
||||||
|
mmcMenuEntries[spot].property = ISDIR;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
u64 size = 0;
|
||||||
|
int sizes = 0;
|
||||||
|
mmcMenuEntries[spot].property = 0;
|
||||||
|
size = (part->lba_end + 1 - part->lba_start) * NX_EMMC_BLOCKSIZE;
|
||||||
|
|
||||||
|
while (size > 1024){
|
||||||
|
size /= 1024;
|
||||||
|
sizes++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sizes > 3)
|
||||||
|
sizes = 0;
|
||||||
|
|
||||||
|
mmcMenuEntries[spot].property |= (1 << (4 + sizes));
|
||||||
|
mmcMenuEntries[spot].storage = (u32)size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int fillMmcMenu(short mmcType){
|
||||||
|
int count = 4, i;
|
||||||
|
|
||||||
|
if (mmcMenuEntries != NULL)
|
||||||
|
clearfileobjects(&mmcMenuEntries);
|
||||||
|
|
||||||
|
link_t *gpt = selectGpt(mmcType);
|
||||||
|
|
||||||
|
LIST_FOREACH_ENTRY(emmc_part_t, part, gpt, link)
|
||||||
|
count++;
|
||||||
|
|
||||||
|
createfileobjects(count, &mmcMenuEntries);
|
||||||
|
|
||||||
|
for (i = 0; i < 4; i++){
|
||||||
|
utils_copystring(mmcmenu_start[i].name, &mmcMenuEntries[i].name);
|
||||||
|
mmcMenuEntries[i].property = mmcmenu_start[i].property;
|
||||||
|
mmcMenuEntries[i].storage = mmcmenu_start[i].storage;
|
||||||
|
}
|
||||||
|
|
||||||
|
LIST_FOREACH_ENTRY(emmc_part_t, part, gpt, link){
|
||||||
|
addEntry(part, checkGptRules(part->name), i++);
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
int handleEntries(short mmcType, menu_entry part){
|
||||||
|
int res = 0;
|
||||||
|
|
||||||
|
if (part.property & ISDIR){
|
||||||
|
if (!mount_mmc(part.name, part.storage))
|
||||||
|
fileexplorer("emmc:/", 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (mmcmenu_filemenu[1].name != NULL)
|
||||||
|
free(mmcmenu_filemenu[1].name);
|
||||||
|
|
||||||
|
utils_copystring(part.name, &mmcmenu_filemenu[1].name);
|
||||||
|
|
||||||
|
if ((menu_make(mmcmenu_filemenu, 4, "-- RAW PARTITION --")) < 3)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
f_mkdir("sd:/tegraexplorer");
|
||||||
|
f_mkdir("sd:/tegraexplorer/partition_dumps");
|
||||||
|
|
||||||
|
gfx_clearscreen();
|
||||||
|
|
||||||
|
if (part.property & isBOOT){
|
||||||
|
res = emmcDumpBoot("sd:/tegraexplorer/partition_dumps");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//gfx_printf("Dumping %s...\n", part.name);
|
||||||
|
res = emmcDumpSpecific(part.name, fsutil_getnextloc("sd:/tegraexplorer/partition_dumps", part.name));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!res){
|
||||||
|
gfx_printf("\nDone!");
|
||||||
|
btn_wait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int makeMmcMenu(short mmcType){
|
||||||
|
int count, selection;
|
||||||
|
count = fillMmcMenu(mmcType);
|
||||||
|
connect_mmc(mmcType);
|
||||||
|
while (1){
|
||||||
|
selection = menu_make(mmcMenuEntries, count, (mmcType == SYSMMC) ? "-- SYSMMC --" : "-- EMUMMC --");
|
||||||
|
|
||||||
|
switch(selection){
|
||||||
|
case -1:
|
||||||
|
case 0:
|
||||||
|
return 0;
|
||||||
|
case 1:
|
||||||
|
gfx_clearscreen();
|
||||||
|
f_mkdir("sd:/tegraexplorer");
|
||||||
|
f_mkdir("sd:/tegraexplorer/partition_dumps");
|
||||||
|
|
||||||
|
for (int i = 0; i < count; i++){
|
||||||
|
if (mmcMenuEntries[i].property & ISMENU || mmcMenuEntries[i].property & ISDIR)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
//gfx_printf("Dumping %s...\n", mmcMenuEntries[i].name);
|
||||||
|
emmcDumpSpecific(mmcMenuEntries[i].name, fsutil_getnextloc("sd:/tegraexplorer/partition_dumps", mmcMenuEntries[i].name));
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx_printf("\nDone!");
|
||||||
|
btn_wait();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
if (!(clipboardhelper & ISDIR) && (clipboardhelper & OPERATIONCOPY)){
|
||||||
|
gfx_clearscreen();
|
||||||
|
if (!mmcFlashFile(clipboard, mmcType)){
|
||||||
|
gfx_printf("\nDone!");
|
||||||
|
btn_wait();
|
||||||
|
}
|
||||||
|
clipboardhelper = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
gfx_errDisplay("mmcMenu", ERR_EMPTY_CLIPBOARD, 0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
handleEntries(mmcType, mmcMenuEntries[selection]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
3
source/tegraexplorer/emmc/emmcmenu.h
Normal file
3
source/tegraexplorer/emmc/emmcmenu.h
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
int makeMmcMenu(short mmcType);
|
||||||
10
source/tegraexplorer/emmc/emmcoperations.h
Normal file
10
source/tegraexplorer/emmc/emmcoperations.h
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "../../utils/types.h"
|
||||||
|
#include "../../storage/nx_emmc.h"
|
||||||
|
|
||||||
|
int emmcDumpSpecific(char *part, char *path);
|
||||||
|
int emmcDumpBoot(char *basePath);
|
||||||
|
int mmcFlashFile(char *path, short mmcType);
|
||||||
|
|
||||||
|
int emmcDumpPart(char *path, sdmmc_storage_t *mmcstorage, emmc_part_t *part);
|
||||||
|
int emmcRestorePart(char *path, sdmmc_storage_t *mmcstorage, emmc_part_t *part);
|
||||||
229
source/tegraexplorer/emmc/emmcrestorepart.c
Normal file
229
source/tegraexplorer/emmc/emmcrestorepart.c
Normal file
@@ -0,0 +1,229 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include "emmcoperations.h"
|
||||||
|
#include "../../gfx/gfx.h"
|
||||||
|
#include "../gfx/gfxutils.h"
|
||||||
|
#include "../../utils/types.h"
|
||||||
|
#include "emmc.h"
|
||||||
|
#include "../../storage/emummc.h"
|
||||||
|
#include "../common/common.h"
|
||||||
|
#include "../../libs/fatfs/ff.h"
|
||||||
|
#include "../../utils/sprintf.h"
|
||||||
|
#include "../../utils/btn.h"
|
||||||
|
#include "../../mem/heap.h"
|
||||||
|
#include "../../storage/nx_emmc.h"
|
||||||
|
#include "../common/types.h"
|
||||||
|
#include "../utils/utils.h"
|
||||||
|
#include "../fs/fsutils.h"
|
||||||
|
|
||||||
|
extern sdmmc_storage_t storage;
|
||||||
|
extern emmc_part_t *system_part;
|
||||||
|
|
||||||
|
int emmcRestorePart(char *path, sdmmc_storage_t *mmcstorage, emmc_part_t *part){
|
||||||
|
FIL fp;
|
||||||
|
FILINFO fno;
|
||||||
|
u8 *buf;
|
||||||
|
u32 lba_curr = part->lba_start;
|
||||||
|
u32 bytesWritten = 0;
|
||||||
|
u32 totalSectorsDest = part->lba_end - part->lba_start + 1;
|
||||||
|
u64 totalSizeDest = (u64)((u64)totalSectorsDest << 9);
|
||||||
|
u64 totalSize;
|
||||||
|
u32 num = 0;
|
||||||
|
u32 pct = 0;
|
||||||
|
int res;
|
||||||
|
|
||||||
|
gfx_printf("Initializing\r");
|
||||||
|
|
||||||
|
buf = calloc(16384, sizeof(u8));
|
||||||
|
|
||||||
|
if (!buf){
|
||||||
|
gfx_errDisplay("restore_emmc_part", ERR_MEM_ALLOC_FAILED, 1);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((res = f_stat(path, &fno))){
|
||||||
|
gfx_errDisplay("restore_emmc_part", res, 2);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
totalSize = fno.fsize;
|
||||||
|
u64 totalSectors = totalSize / NX_EMMC_BLOCKSIZE;
|
||||||
|
|
||||||
|
if (totalSize > totalSizeDest){
|
||||||
|
gfx_errDisplay("restore_emmc_part", ERR_FILE_TOO_BIG_FOR_DEST, 3);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx_printf("Flashing %s\n", part->name);
|
||||||
|
|
||||||
|
if (totalSize < totalSizeDest){
|
||||||
|
SWAPCOLOR(COLOR_ORANGE);
|
||||||
|
gfx_printf("File is too small for destenation.\nDo you want to flash it anyway?\n\nVol +/- to Cancel\n");
|
||||||
|
u8 btnres = gfx_makewaitmenu(
|
||||||
|
"Power to Confirm",
|
||||||
|
2
|
||||||
|
);
|
||||||
|
|
||||||
|
RESETCOLOR;
|
||||||
|
|
||||||
|
if (!btnres){
|
||||||
|
gfx_printf("\nCancelled: %s\n\n", part->name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
gfx_printf("\nFlashing %s\n", part->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((res = f_open(&fp, path, FA_OPEN_ALWAYS | FA_READ))){
|
||||||
|
gfx_errDisplay("restore_emmc_part", res, 4);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (totalSectors > 0){
|
||||||
|
num = MIN(totalSectors, 32);
|
||||||
|
|
||||||
|
if ((res = f_read(&fp, buf, num * NX_EMMC_BLOCKSIZE, NULL))){
|
||||||
|
gfx_errDisplay("restore_emmc_part", res, 5);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!emummc_storage_write(mmcstorage, lba_curr, num, buf)){
|
||||||
|
gfx_errDisplay("restore_emmc_part", ERR_EMMC_WRITE_FAILED, 2);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
lba_curr += num;
|
||||||
|
totalSectors -= num;
|
||||||
|
bytesWritten += num * NX_EMMC_BLOCKSIZE;
|
||||||
|
|
||||||
|
pct = (u64)((u64)(bytesWritten) * 100u) / (u64)(fno.fsize);
|
||||||
|
gfx_printf("Progress: %d%%\r", pct);
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx_printf(" \r");
|
||||||
|
f_close(&fp);
|
||||||
|
free(buf);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// function replaced by new mmc implementation. Will be removed at some point
|
||||||
|
/*
|
||||||
|
int restore_emmc_file(char *path, const char *target, u8 partition, u8 mmctype){
|
||||||
|
connect_mmc(mmctype);
|
||||||
|
|
||||||
|
if (partition){
|
||||||
|
emmc_part_t bootPart;
|
||||||
|
const u32 BOOT_PART_SIZE = storage.ext_csd.boot_mult << 17;
|
||||||
|
memset(&bootPart, 0, sizeof(bootPart));
|
||||||
|
|
||||||
|
bootPart.lba_start = 0;
|
||||||
|
bootPart.lba_end = (BOOT_PART_SIZE / NX_EMMC_BLOCKSIZE) - 1;
|
||||||
|
|
||||||
|
strcpy(bootPart.name, target);
|
||||||
|
|
||||||
|
emummc_storage_set_mmc_partition(&storage, partition);
|
||||||
|
restore_emmc_part(path, &storage, &bootPart);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (connect_part(target)){
|
||||||
|
gfx_errDisplay("restore_emmc_part", ERR_PART_NOT_FOUND, 0);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
restore_emmc_part(path, &storage, system_part);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int restore_bis_using_file(char *path, u8 mmctype){
|
||||||
|
f_mkdir("sd:/tegraexplorer");
|
||||||
|
f_mkdir("sd:/tegraexplorer/bis");
|
||||||
|
gfx_clearscreen();
|
||||||
|
|
||||||
|
if (extract_bis_file(path, "sd:/tegraexplorer/bis"))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
SWAPBGCOLOR(COLOR_RED);
|
||||||
|
SWAPCOLOR(COLOR_DEFAULT);
|
||||||
|
gfx_printf("\nAre you sure you want to flash these files\nThis could leave your switch unbootable!\nTarget is SysMMC\n\nVol +/- to cancel\n");
|
||||||
|
if (!gfx_makewaitmenu(
|
||||||
|
"Power to confirm",
|
||||||
|
10
|
||||||
|
))
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
RESETCOLOR;
|
||||||
|
|
||||||
|
gfx_printf("\nRestoring BIS...\n\n");
|
||||||
|
|
||||||
|
restore_emmc_file("sd:/tegraexplorer/bis/BOOT0.bin", "BOOT0", 1, mmctype);
|
||||||
|
restore_emmc_file("sd:/tegraexplorer/bis/BOOT1.bin", "BOOT1", 2, mmctype);
|
||||||
|
restore_emmc_file("sd:/tegraexplorer/bis/BCPKG2-1-Normal-Main", pkg2names[0], 0, mmctype);
|
||||||
|
restore_emmc_file("sd:/tegraexplorer/bis/BCPKG2-1-Normal-Main", pkg2names[1], 0, mmctype);
|
||||||
|
restore_emmc_file("sd:/tegraexplorer/bis/BCPKG2-3-SafeMode-Main", pkg2names[2], 0, mmctype);
|
||||||
|
restore_emmc_file("sd:/tegraexplorer/bis/BCPKG2-3-SafeMode-Main", pkg2names[3], 0, mmctype);
|
||||||
|
|
||||||
|
gfx_printf("\n\nDone!\nPress any button to return");
|
||||||
|
btn_wait();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
emmc_part_t *mmcFindPart(char *path, short mmcType){
|
||||||
|
char *filename, *extention, *path_local;
|
||||||
|
emmc_part_t *part;
|
||||||
|
|
||||||
|
utils_copystring(path, &path_local);
|
||||||
|
filename = strrchr(path_local, '/') + 1;
|
||||||
|
extention = strrchr(path_local, '.');
|
||||||
|
|
||||||
|
if (extention != NULL)
|
||||||
|
*extention = '\0';
|
||||||
|
|
||||||
|
if (checkGptRules(filename)){
|
||||||
|
gfx_errDisplay("mmcFindPart", ERR_CANNOT_COPY_FILE_TO_FS_PART, 1);
|
||||||
|
free(path_local);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
part = nx_emmc_part_find(selectGpt(mmcType), filename);
|
||||||
|
|
||||||
|
if (part != NULL){
|
||||||
|
emummc_storage_set_mmc_partition(&storage, 0);
|
||||||
|
free(path_local);
|
||||||
|
return part;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strcmp(filename, "BOOT0") || !strcmp(filename, "BOOT1")){
|
||||||
|
const u32 BOOT_PART_SIZE = storage.ext_csd.boot_mult << 17;
|
||||||
|
part = calloc(1, sizeof(emmc_part_t));
|
||||||
|
|
||||||
|
part->lba_start = 0;
|
||||||
|
part->lba_end = (BOOT_PART_SIZE / NX_EMMC_BLOCKSIZE) - 1;
|
||||||
|
|
||||||
|
strcpy(part->name, filename);
|
||||||
|
|
||||||
|
emummc_storage_set_mmc_partition(&storage, (!strcmp(filename, "BOOT0")) ? 1 : 2);
|
||||||
|
free(path_local);
|
||||||
|
return part;
|
||||||
|
}
|
||||||
|
|
||||||
|
//gfx_printf("Path: %s\nFilename: %s", path, filename);
|
||||||
|
//btn_wait();
|
||||||
|
gfx_errDisplay("mmcFindPart", ERR_NO_DESTENATION, 2);
|
||||||
|
free(path_local);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int mmcFlashFile(char *path, short mmcType){
|
||||||
|
emmc_part_t *part;
|
||||||
|
int res;
|
||||||
|
|
||||||
|
part = mmcFindPart(path, mmcType);
|
||||||
|
if (part != NULL){
|
||||||
|
res = emmcRestorePart(path, &storage, part);
|
||||||
|
emummc_storage_set_mmc_partition(&storage, 0);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
@@ -1,394 +0,0 @@
|
|||||||
#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"
|
|
||||||
|
|
||||||
fs_entry fileobjects[500];
|
|
||||||
char rootpath[10] = "";
|
|
||||||
char *currentpath = "";
|
|
||||||
char *clipboard = "";
|
|
||||||
u8 clipboardhelper = 0;
|
|
||||||
extern const char sizevalues[4][3];
|
|
||||||
extern int launch_payload(char *path);
|
|
||||||
|
|
||||||
menu_item explfilemenu[9] = {
|
|
||||||
{"-- File Menu --", COLOR_BLUE, -1, 0},
|
|
||||||
{"FILE", COLOR_GREEN, -1, 0},
|
|
||||||
{"\nSIZE", 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},
|
|
||||||
{"\nDelete file\n", COLOR_RED, DELETE, 1},
|
|
||||||
{"Launch Payload", COLOR_ORANGE, PAYLOAD, 1},
|
|
||||||
{"View Hex", COLOR_GREEN, HEXVIEW, 1}
|
|
||||||
};
|
|
||||||
|
|
||||||
void writecurpath(const char *in){
|
|
||||||
if (currentpath != NULL)
|
|
||||||
free(currentpath);
|
|
||||||
|
|
||||||
size_t len = strlen(in) + 1;
|
|
||||||
currentpath = (char*) malloc (len);
|
|
||||||
strcpy(currentpath, in);
|
|
||||||
|
|
||||||
strcpy(currentpath, in);
|
|
||||||
}
|
|
||||||
|
|
||||||
void writeclipboard(const char *in, bool move, bool folder){
|
|
||||||
if (clipboard != NULL)
|
|
||||||
free(clipboard);
|
|
||||||
|
|
||||||
clipboardhelper = 0;
|
|
||||||
|
|
||||||
if (move)
|
|
||||||
clipboardhelper |= (OPERATIONMOVE);
|
|
||||||
else
|
|
||||||
clipboardhelper |= (OPERATIONCOPY);
|
|
||||||
|
|
||||||
if (folder)
|
|
||||||
clipboardhelper |= (ISDIR);
|
|
||||||
|
|
||||||
size_t len = strlen(in) + 1;
|
|
||||||
clipboard = (char*) malloc (len);
|
|
||||||
strcpy(clipboard, in);
|
|
||||||
|
|
||||||
strcpy(clipboard, in);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *getnextloc(char *current, char *add){
|
|
||||||
char *ret;
|
|
||||||
size_t size = strlen(current) + strlen(add) + 1;
|
|
||||||
ret = (char*) malloc (size);
|
|
||||||
if (!strcmp(rootpath, current))
|
|
||||||
sprintf(ret, "%s%s", current, add);
|
|
||||||
else
|
|
||||||
sprintf(ret, "%s/%s", current, add);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *getprevloc(char *current){
|
|
||||||
char *ret, *temp;
|
|
||||||
size_t size = strlen(current) + 1;
|
|
||||||
|
|
||||||
ret = (char*) malloc (size);
|
|
||||||
strcpy(ret, current);
|
|
||||||
|
|
||||||
temp = strrchr(ret, '/');
|
|
||||||
memset(temp, '\0', 1);
|
|
||||||
|
|
||||||
if (strlen(rootpath) > strlen(ret))
|
|
||||||
strcpy(ret, rootpath);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 *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);
|
|
||||||
|
|
||||||
gfx_printf("Note:\nTo stop the transfer hold Vol-\n\n%s\nProgress: ", outstring);
|
|
||||||
|
|
||||||
if (clipboardhelper & OPERATIONMOVE){
|
|
||||||
if (strcmp(rootpath, "emmc:/"))
|
|
||||||
f_rename(path, outstring);
|
|
||||||
else
|
|
||||||
message("\nMoving in emummc is not allowed!", COLOR_RED);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (clipboardhelper & OPERATIONCOPY) {
|
|
||||||
res = copy(path, outstring, true);
|
|
||||||
if (res){
|
|
||||||
gfx_printf("\n\n%kSomething went wrong while copying!\n\nErrcode: %d%k", COLOR_RED, res, COLOR_WHITE);
|
|
||||||
btn_wait();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
|
||||||
message("\nClipboard is empty!", COLOR_RED);
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
int sizes = 0;
|
|
||||||
fileobjects[spot].property = 0;
|
|
||||||
|
|
||||||
if (fileobjects[spot].name != NULL){
|
|
||||||
free(fileobjects[spot].name);
|
|
||||||
fileobjects[spot].name = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
fileobjects[spot].name = (char*) malloc (length);
|
|
||||||
strlcpy(fileobjects[spot].name, name, length);
|
|
||||||
|
|
||||||
if (isfol)
|
|
||||||
fileobjects[spot].property |= (ISDIR);
|
|
||||||
else {
|
|
||||||
size = getfilesize(getnextloc(currentpath, name));
|
|
||||||
|
|
||||||
while (size > 1024){
|
|
||||||
size /= 1024;
|
|
||||||
sizes++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sizes > 3)
|
|
||||||
sizes = 0;
|
|
||||||
|
|
||||||
fileobjects[spot].property |= (1 << (4 + sizes));
|
|
||||||
fileobjects[spot].size = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isarc)
|
|
||||||
fileobjects[spot].property |= (ISARC);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (!f_readdir(&dir, &fno) && fno.fname[0] && folderamount < 500){
|
|
||||||
addobject(fno.fname, folderamount++, (fno.fattrib & AM_DIR), (fno.fattrib & AM_ARC));
|
|
||||||
}
|
|
||||||
|
|
||||||
f_closedir(&dir);
|
|
||||||
return folderamount;
|
|
||||||
}
|
|
||||||
|
|
||||||
int delfile(const char *path, const char *filename){
|
|
||||||
char *tempmessage;
|
|
||||||
size_t tempmessagesize = strlen(filename) + 65;
|
|
||||||
tempmessage = (char*) malloc (tempmessagesize);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void filemenu(const char *startpath){
|
|
||||||
int amount, res, tempint;
|
|
||||||
char temp[100];
|
|
||||||
strcpy(rootpath, startpath);
|
|
||||||
writecurpath(startpath);
|
|
||||||
amount = readfolder(currentpath);
|
|
||||||
|
|
||||||
if (strcmp(rootpath, "emmc:/"))
|
|
||||||
explfilemenu[5].property = 1;
|
|
||||||
else
|
|
||||||
explfilemenu[5].property = -1;
|
|
||||||
|
|
||||||
while (1){
|
|
||||||
res = makefilemenu(fileobjects, amount, 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (res == 0)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (fileobjects[res - 1].property & ISDIR){
|
|
||||||
writecurpath(getnextloc(currentpath, fileobjects[res - 1].name));
|
|
||||||
amount = 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "../utils/types.h"
|
|
||||||
|
|
||||||
#define ISDIR (1 << 0)
|
|
||||||
#define ISARC (1 << 1)
|
|
||||||
|
|
||||||
#define ISGB (1 << 7)
|
|
||||||
#define ISMB (1 << 6)
|
|
||||||
#define ISKB (1 << 5)
|
|
||||||
#define ISB (1 << 4)
|
|
||||||
|
|
||||||
#define OPERATIONCOPY (1 << 1)
|
|
||||||
#define OPERATIONMOVE (1 << 2)
|
|
||||||
|
|
||||||
#define BUFSIZE 32768
|
|
||||||
|
|
||||||
/* Bit table for property:
|
|
||||||
0000 0001: Directory bit
|
|
||||||
0000 0010: Archive bit
|
|
||||||
0001 0000: Size component is a Byte
|
|
||||||
0010 0000: Size component is a KiloByte
|
|
||||||
0100 0000: Size component is a MegaByte
|
|
||||||
1000 0000: Size component is a GigaByte : note that this won't surpass gigabytes, but i don't expect people to have a single file that's a terrabyte big
|
|
||||||
*/
|
|
||||||
|
|
||||||
typedef struct _fs_entry {
|
|
||||||
char* name;
|
|
||||||
u16 size;
|
|
||||||
u8 property;
|
|
||||||
} fs_entry;
|
|
||||||
|
|
||||||
enum filemenuoptions {
|
|
||||||
COPY = 1,
|
|
||||||
MOVE,
|
|
||||||
DELETE,
|
|
||||||
PAYLOAD,
|
|
||||||
HEXVIEW
|
|
||||||
};
|
|
||||||
|
|
||||||
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);
|
|
||||||
7
source/tegraexplorer/fs/entrymenu.h
Normal file
7
source/tegraexplorer/fs/entrymenu.h
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "../common/types.h"
|
||||||
|
|
||||||
|
int filemenu(menu_entry file);
|
||||||
|
void copyfile(const char *src_in, const char *outfolder);
|
||||||
|
int foldermenu();
|
||||||
|
void copyfolder(char *in, char *out);
|
||||||
184
source/tegraexplorer/fs/filemenu.c
Normal file
184
source/tegraexplorer/fs/filemenu.c
Normal file
@@ -0,0 +1,184 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include "entrymenu.h"
|
||||||
|
#include "../common/common.h"
|
||||||
|
#include "../../libs/fatfs/ff.h"
|
||||||
|
#include "../../utils/btn.h"
|
||||||
|
#include "../../gfx/gfx.h"
|
||||||
|
#include "fsutils.h"
|
||||||
|
#include "fsactions.h"
|
||||||
|
#include "../utils/utils.h"
|
||||||
|
#include "../gfx/gfxutils.h"
|
||||||
|
#include "../../mem/heap.h"
|
||||||
|
#include "fsreader.h"
|
||||||
|
#include "../gfx/menu.h"
|
||||||
|
#include "../common/types.h"
|
||||||
|
#include "../../utils/sprintf.h"
|
||||||
|
#include "../script/parser.h"
|
||||||
|
#include "../emmc/emmcoperations.h"
|
||||||
|
|
||||||
|
extern char *currentpath;
|
||||||
|
extern char *clipboard;
|
||||||
|
extern u8 clipboardhelper;
|
||||||
|
extern int launch_payload(char *path);
|
||||||
|
|
||||||
|
int delfile(const char *path, const char *filename){
|
||||||
|
gfx_clearscreen();
|
||||||
|
SWAPCOLOR(COLOR_ORANGE);
|
||||||
|
gfx_printf("Are you sure you want to delete:\n%s\n\nPress vol+/- to cancel\n", filename);
|
||||||
|
if (gfx_makewaitmenu("Press power to delete", 3)){
|
||||||
|
f_unlink(path);
|
||||||
|
fsreader_readfolder(currentpath);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void viewbytes(char *path){
|
||||||
|
FIL in;
|
||||||
|
u8 print[2048];
|
||||||
|
u32 size;
|
||||||
|
QWORD offset = 0;
|
||||||
|
int res;
|
||||||
|
|
||||||
|
gfx_clearscreen();
|
||||||
|
if ((res = f_open(&in, path, FA_READ | FA_OPEN_EXISTING))){
|
||||||
|
gfx_errDisplay("viewbytes", res, 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
msleep(200);
|
||||||
|
|
||||||
|
while (1){
|
||||||
|
f_lseek(&in, offset * 16);
|
||||||
|
|
||||||
|
if ((res = f_read(&in, &print, 2048 * sizeof(u8), &size))){
|
||||||
|
gfx_errDisplay("viewbytes", res, 2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx_con_setpos(0, 31);
|
||||||
|
gfx_hexdump(offset * 16, print, size * sizeof(u8));
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
void copyfile(const char *src_in, const char *outfolder){
|
||||||
|
char *in, *out, *filename;
|
||||||
|
int res;
|
||||||
|
|
||||||
|
gfx_clearscreen();
|
||||||
|
utils_copystring(src_in, &in);
|
||||||
|
utils_copystring(strrchr(in, '/') + 1, &filename);
|
||||||
|
utils_copystring(fsutil_getnextloc(outfolder, filename), &out);
|
||||||
|
|
||||||
|
gfx_printf("Note:\nTo stop the transfer hold Vol-\n\n%s\nProgress: ", filename);
|
||||||
|
|
||||||
|
if (!strcmp(in, out)){
|
||||||
|
gfx_errDisplay("gfxcopy", ERR_SAME_LOC, 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clipboardhelper & OPERATIONMOVE){
|
||||||
|
if ((res = f_rename(in, out))){
|
||||||
|
gfx_errDisplay("gfxcopy", res, 2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (clipboardhelper & OPERATIONCOPY) {
|
||||||
|
if (fsact_copy(in, out, COPY_MODE_CANCEL | COPY_MODE_PRINT))
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
gfx_errDisplay("gfxcopy", ERR_EMPTY_CLIPBOARD, 3);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(in);
|
||||||
|
free(out);
|
||||||
|
free(filename);
|
||||||
|
fsreader_readfolder(currentpath);
|
||||||
|
}
|
||||||
|
|
||||||
|
int filemenu(menu_entry file){
|
||||||
|
int temp;
|
||||||
|
FILINFO attribs;
|
||||||
|
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
if (fs_menu_file[i].name != NULL)
|
||||||
|
free(fs_menu_file[i].name);
|
||||||
|
|
||||||
|
utils_copystring(file.name, &fs_menu_file[0].name);
|
||||||
|
fs_menu_file[1].name = malloc(16);
|
||||||
|
fs_menu_file[2].name = malloc(16);
|
||||||
|
|
||||||
|
for (temp = 4; temp < 8; temp++)
|
||||||
|
if ((file.property & (1 << temp)))
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
sprintf(fs_menu_file[1].name, "\nSize: %d %s", file.storage, gfx_file_size_names[temp - 4]);
|
||||||
|
|
||||||
|
if (f_stat(fsutil_getnextloc(currentpath, file.name), &attribs))
|
||||||
|
SETBIT(fs_menu_file[2].property, ISHIDE, 1);
|
||||||
|
else {
|
||||||
|
SETBIT(fs_menu_file[2].property, ISHIDE, 0);
|
||||||
|
sprintf(fs_menu_file[2].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' : '-');
|
||||||
|
}
|
||||||
|
|
||||||
|
SETBIT(fs_menu_file[7].property, ISHIDE, !(strstr(file.name, ".bin") != NULL && file.property & ISKB));
|
||||||
|
SETBIT(fs_menu_file[8].property, ISHIDE, !(strstr(file.name, ".te") != NULL));
|
||||||
|
SETBIT(fs_menu_file[10].property, ISHIDE, !(strstr(file.name, ".bis") != NULL));
|
||||||
|
|
||||||
|
temp = menu_make(fs_menu_file, 11, "-- File Menu --");
|
||||||
|
|
||||||
|
switch (temp){
|
||||||
|
case FILE_COPY:
|
||||||
|
fsreader_writeclipboard(fsutil_getnextloc(currentpath, file.name), OPERATIONCOPY);
|
||||||
|
break;
|
||||||
|
case FILE_MOVE:
|
||||||
|
fsreader_writeclipboard(fsutil_getnextloc(currentpath, file.name), OPERATIONMOVE);
|
||||||
|
break;
|
||||||
|
case FILE_DELETE:
|
||||||
|
delfile(fsutil_getnextloc(currentpath, file.name), file.name);
|
||||||
|
break;
|
||||||
|
case FILE_PAYLOAD:
|
||||||
|
launch_payload(fsutil_getnextloc(currentpath, file.name));
|
||||||
|
break;
|
||||||
|
case FILE_SCRIPT:
|
||||||
|
//ParseScript(fsutil_getnextloc(currentpath, file.name));
|
||||||
|
runScript(fsutil_getnextloc(currentpath, file.name));
|
||||||
|
fsreader_readfolder(currentpath);
|
||||||
|
break;
|
||||||
|
case FILE_HEXVIEW:
|
||||||
|
viewbytes(fsutil_getnextloc(currentpath, file.name));
|
||||||
|
break;
|
||||||
|
case FILE_DUMPBIS:
|
||||||
|
gfx_clearscreen();
|
||||||
|
extract_bis_file(fsutil_getnextloc(currentpath, file.name), currentpath);
|
||||||
|
fsreader_readfolder(currentpath);
|
||||||
|
btn_wait();
|
||||||
|
break;
|
||||||
|
case -1:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
90
source/tegraexplorer/fs/foldermenu.c
Normal file
90
source/tegraexplorer/fs/foldermenu.c
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include "entrymenu.h"
|
||||||
|
#include "../common/common.h"
|
||||||
|
#include "../../libs/fatfs/ff.h"
|
||||||
|
#include "../../mem/heap.h"
|
||||||
|
#include "../gfx/menu.h"
|
||||||
|
#include "fsreader.h"
|
||||||
|
#include "../gfx/gfxutils.h"
|
||||||
|
#include "fsactions.h"
|
||||||
|
#include "fsutils.h"
|
||||||
|
#include "../../utils/sprintf.h"
|
||||||
|
|
||||||
|
extern char *currentpath;
|
||||||
|
extern char *clipboard;
|
||||||
|
extern u8 clipboardhelper;
|
||||||
|
|
||||||
|
void copyfolder(char *in, char *out){
|
||||||
|
int res;
|
||||||
|
|
||||||
|
res = strlen(in);
|
||||||
|
if ((*(in + res - 1) == '/')){
|
||||||
|
gfx_errDisplay("copyfolder", ERR_FOLDER_ROOT, 1);
|
||||||
|
}
|
||||||
|
else if (strstr(out, in) != NULL){
|
||||||
|
gfx_errDisplay("copyfolder", ERR_DEST_PART_OF_SRC, 2);
|
||||||
|
}
|
||||||
|
else if (!strcmp(in, out)){
|
||||||
|
gfx_errDisplay("copyfolder", ERR_SAME_LOC, 3);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
gfx_clearscreen();
|
||||||
|
gfx_printf("\nCopying folder, please wait\n");
|
||||||
|
fsact_copy_recursive(in, out);
|
||||||
|
fsreader_readfolder(currentpath);
|
||||||
|
}
|
||||||
|
|
||||||
|
clipboardhelper = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int foldermenu(){
|
||||||
|
int res;
|
||||||
|
FILINFO attribs;
|
||||||
|
|
||||||
|
if (fs_menu_folder[0].name != NULL)
|
||||||
|
free(fs_menu_folder[0].name);
|
||||||
|
|
||||||
|
fs_menu_folder[0].name = malloc(16);
|
||||||
|
|
||||||
|
res = strlen(currentpath);
|
||||||
|
|
||||||
|
SETBIT(fs_menu_folder[3].property, ISHIDE, (*(currentpath + res - 1) == '/'));
|
||||||
|
SETBIT(fs_menu_folder[4].property, ISHIDE, (*(currentpath + res - 1) == '/'));
|
||||||
|
|
||||||
|
if (f_stat(currentpath, &attribs))
|
||||||
|
SETBIT(fs_menu_folder[0].property, ISHIDE, 1);
|
||||||
|
else {
|
||||||
|
SETBIT(fs_menu_folder[0].property, ISHIDE, 0);
|
||||||
|
sprintf(fs_menu_folder[0].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 = menu_make(fs_menu_folder, 5, currentpath);
|
||||||
|
|
||||||
|
switch (res){
|
||||||
|
case DIR_EXITFOLDER:
|
||||||
|
case -1:
|
||||||
|
return -1;
|
||||||
|
case DIR_COPYFOLDER:
|
||||||
|
fsreader_writeclipboard(currentpath, OPERATIONCOPY | ISDIR);
|
||||||
|
break;
|
||||||
|
case DIR_DELETEFOLDER:
|
||||||
|
gfx_clearscreen();
|
||||||
|
gfx_printf("Do you want to delete this folder?\nThe entire folder, with all subcontents\n will be deleted!!!\n\nPress vol+/- to cancel\n");
|
||||||
|
if (gfx_makewaitmenu("Press power to contine...", 3)){
|
||||||
|
gfx_clearscreen();
|
||||||
|
gfx_printf("\nDeleting folder, please wait...\n");
|
||||||
|
|
||||||
|
fsact_del_recursive(currentpath);
|
||||||
|
|
||||||
|
fsreader_writecurpath(fsutil_getprevloc(currentpath));
|
||||||
|
fsreader_readfolder(currentpath);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
193
source/tegraexplorer/fs/fsactions.c
Normal file
193
source/tegraexplorer/fs/fsactions.c
Normal file
@@ -0,0 +1,193 @@
|
|||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "fsactions.h"
|
||||||
|
#include "../common/common.h"
|
||||||
|
#include "../../libs/fatfs/ff.h"
|
||||||
|
#include "../../gfx/gfx.h"
|
||||||
|
#include "../gfx/gfxutils.h"
|
||||||
|
#include "../utils/utils.h"
|
||||||
|
#include "../../mem/heap.h"
|
||||||
|
#include "../../utils/btn.h"
|
||||||
|
#include "fsutils.h"
|
||||||
|
|
||||||
|
int fsact_copy(const char *locin, const char *locout, u8 options){
|
||||||
|
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)){
|
||||||
|
gfx_errDisplay("copy", ERR_SAME_LOC, 1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((res = f_open(&in, locin, FA_READ | FA_OPEN_EXISTING))){
|
||||||
|
gfx_errDisplay("copy", res, 2);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (f_stat(locin, &in_info)){
|
||||||
|
gfx_errDisplay("copy", res, 3);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (f_open(&out, locout, FA_CREATE_ALWAYS | FA_WRITE)){
|
||||||
|
gfx_errDisplay("copy", res, 4);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
buff = malloc (BUFSIZE);
|
||||||
|
sizeoffile = f_size(&in);
|
||||||
|
totalsize = sizeoffile;
|
||||||
|
|
||||||
|
while (sizeoffile > 0){
|
||||||
|
if ((res = f_read(&in, buff, (sizeoffile > BUFSIZE) ? BUFSIZE : sizeoffile, &temp1))){
|
||||||
|
gfx_errDisplay("copy", res, 5);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((res = f_write(&out, buff, (sizeoffile > BUFSIZE) ? BUFSIZE : sizeoffile, &temp2))){
|
||||||
|
gfx_errDisplay("copy", res, 6);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (temp1 != temp2){
|
||||||
|
gfx_errDisplay("copy", ERR_DISK_WRITE_FAILED, 7);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sizeoffile -= temp1;
|
||||||
|
sizecopied += temp1;
|
||||||
|
|
||||||
|
if (options & COPY_MODE_PRINT && 10 > i++){
|
||||||
|
gfx_printf("%k[%d%%]%k", COLOR_GREEN, ((sizecopied * 100) / totalsize) ,COLOR_WHITE);
|
||||||
|
gfx_con_setpos(x, y);
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
|
||||||
|
if (options & COPY_MODE_CANCEL)
|
||||||
|
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))){
|
||||||
|
gfx_errDisplay("copy", res, 8);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
f_stat(locin, &in_info); //somehow stops fatfs from being weird
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fsact_del_recursive(char *path){
|
||||||
|
DIR dir;
|
||||||
|
FILINFO fno;
|
||||||
|
int res;
|
||||||
|
u32 x, y;
|
||||||
|
char *localpath = NULL;
|
||||||
|
|
||||||
|
gfx_con_getpos(&x, &y);
|
||||||
|
utils_copystring(path, &localpath);
|
||||||
|
|
||||||
|
if ((res = f_opendir(&dir, localpath))){
|
||||||
|
gfx_errDisplay("del_recursive", res, 1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!f_readdir(&dir, &fno) && fno.fname[0]){
|
||||||
|
if (fno.fattrib & AM_DIR){
|
||||||
|
fsact_del_recursive(fsutil_getnextloc(localpath, fno.fname));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
SWAPCOLOR(COLOR_RED);
|
||||||
|
gfx_printf("\r");
|
||||||
|
gfx_printandclear(fno.fname, 37);
|
||||||
|
|
||||||
|
if ((res = f_unlink(fsutil_getnextloc(localpath, fno.fname)))){
|
||||||
|
gfx_errDisplay("del_recursive", res, 2);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
f_closedir(&dir);
|
||||||
|
|
||||||
|
if ((res = f_unlink(localpath))){
|
||||||
|
gfx_errDisplay("del_recursive", res, 3);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(localpath);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fsact_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);
|
||||||
|
|
||||||
|
utils_copystring(path, &startpath);
|
||||||
|
utils_copystring(strrchr(path, '/') + 1, &destfoldername);
|
||||||
|
utils_copystring(fsutil_getnextloc(dstpath, destfoldername), &destpath);
|
||||||
|
|
||||||
|
if ((res = f_opendir(&dir, startpath))){
|
||||||
|
gfx_errDisplay("copy_recursive", res, 1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
f_mkdir(destpath);
|
||||||
|
|
||||||
|
while (!f_readdir(&dir, &fno) && fno.fname[0]){
|
||||||
|
if (fno.fattrib & AM_DIR){
|
||||||
|
fsact_copy_recursive(fsutil_getnextloc(startpath, fno.fname), destpath);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
SWAPCOLOR(COLOR_GREEN);
|
||||||
|
gfx_printf("\r");
|
||||||
|
gfx_printandclear(fno.fname, 37);
|
||||||
|
|
||||||
|
utils_copystring(fsutil_getnextloc(startpath, fno.fname), &temp);
|
||||||
|
|
||||||
|
if ((res = fsact_copy(temp, fsutil_getnextloc(destpath, fno.fname), COPY_MODE_PRINT))){
|
||||||
|
gfx_errDisplay("copy_recursive", res, 2);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
f_closedir(&dir);
|
||||||
|
|
||||||
|
if ((res = (f_stat(startpath, &fno)))){
|
||||||
|
gfx_errDisplay("copy_recursive", res, 3);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((res = f_chmod(destpath, fno.fattrib, 0x3A))){
|
||||||
|
gfx_errDisplay("copy_recursive", res, 4);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(startpath);
|
||||||
|
free(destpath);
|
||||||
|
free(destfoldername);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
6
source/tegraexplorer/fs/fsactions.h
Normal file
6
source/tegraexplorer/fs/fsactions.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "../../utils/types.h"
|
||||||
|
|
||||||
|
int fsact_copy(const char *locin, const char *locout, u8 options);
|
||||||
|
int fsact_del_recursive(char *path);
|
||||||
|
int fsact_copy_recursive(char *path, char *dstpath);
|
||||||
110
source/tegraexplorer/fs/fsextractbis.c
Normal file
110
source/tegraexplorer/fs/fsextractbis.c
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
#include "fsutils.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include "../../gfx/gfx.h"
|
||||||
|
#include "../gfx/gfxutils.h"
|
||||||
|
#include "../../utils/types.h"
|
||||||
|
#include "../../storage/emummc.h"
|
||||||
|
#include "../common/common.h"
|
||||||
|
#include "../../libs/fatfs/ff.h"
|
||||||
|
#include "../../utils/sprintf.h"
|
||||||
|
#include "../../utils/btn.h"
|
||||||
|
#include "../../mem/heap.h"
|
||||||
|
#include "../../storage/nx_emmc.h"
|
||||||
|
#include "../common/types.h"
|
||||||
|
#include "../utils/utils.h"
|
||||||
|
#include "fsactions.h"
|
||||||
|
|
||||||
|
u32 DecodeInt(u8* data) {
|
||||||
|
u32 out = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
out |= (data[i] << ((3 - i) * 8));
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
void copy_fil_size(FIL* in_src, FIL* out_src, int size_src){
|
||||||
|
u8* buff;
|
||||||
|
buff = calloc(16384, sizeof(u8));
|
||||||
|
|
||||||
|
int size = size_src;
|
||||||
|
int copysize;
|
||||||
|
|
||||||
|
while (size > 0){
|
||||||
|
copysize = MIN(16834, size);
|
||||||
|
f_read(in_src, buff, copysize, NULL);
|
||||||
|
f_write(out_src, buff, copysize, NULL);
|
||||||
|
size -= copysize;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(buff);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gen_part(int size, FIL* in, char *path){
|
||||||
|
FIL out;
|
||||||
|
|
||||||
|
f_open(&out, path, FA_WRITE | FA_CREATE_ALWAYS);
|
||||||
|
copy_fil_size(in, &out, size);
|
||||||
|
f_close(&out);
|
||||||
|
}
|
||||||
|
|
||||||
|
int extract_bis_file(char *path, char *outfolder){
|
||||||
|
FIL in;
|
||||||
|
int res;
|
||||||
|
u8 version[0x10];
|
||||||
|
u8 args;
|
||||||
|
u8 temp[0x4];
|
||||||
|
u32 filesizes[4];
|
||||||
|
char *tempPath;
|
||||||
|
|
||||||
|
if ((res = f_open(&in, path, FA_READ | FA_OPEN_EXISTING))){
|
||||||
|
gfx_errDisplay("extract_bis_file", res, 0);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
f_read(&in, version, 0x10, NULL);
|
||||||
|
f_read(&in, &args, 1, NULL);
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++){
|
||||||
|
f_read(&in, temp, 4, NULL);
|
||||||
|
filesizes[i] = DecodeInt(temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx_printf("Version: %s\n\n", version);
|
||||||
|
|
||||||
|
if (args & BOOT0_ARG){
|
||||||
|
gfx_printf("\nExtracting BOOT0\n");
|
||||||
|
gen_part(filesizes[0], &in, fsutil_getnextloc(outfolder, "BOOT0.bin"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args & BOOT1_ARG){
|
||||||
|
gfx_printf("Extracting BOOT1\n");
|
||||||
|
gen_part(filesizes[1], &in, fsutil_getnextloc(outfolder, "BOOT1.bin"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args & BCPKG2_1_ARG){
|
||||||
|
utils_copystring(fsutil_getnextloc(outfolder, "BCPKG2-1-Normal-Main"), &tempPath);
|
||||||
|
gfx_printf("Extracting BCPKG2_1/2\n");
|
||||||
|
|
||||||
|
gen_part(filesizes[2], &in, tempPath);
|
||||||
|
fsact_copy(tempPath, fsutil_getnextloc(outfolder, "BCPKG2-2-Normal-Sub"), COPY_MODE_PRINT);
|
||||||
|
RESETCOLOR;
|
||||||
|
free(tempPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args & BCPKG2_3_ARG){
|
||||||
|
utils_copystring(fsutil_getnextloc(outfolder, "BCPKG2-3-SafeMode-Main"), &tempPath);
|
||||||
|
gfx_printf("Extracting BCPKG2_3/4\n");
|
||||||
|
|
||||||
|
gen_part(filesizes[3], &in, tempPath);
|
||||||
|
fsact_copy(tempPath, fsutil_getnextloc(outfolder, "BCPKG2-4-SafeMode-Sub"), COPY_MODE_PRINT);
|
||||||
|
RESETCOLOR;
|
||||||
|
free(tempPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx_printf("\n\nDone!\n");
|
||||||
|
|
||||||
|
f_close(&in);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
122
source/tegraexplorer/fs/fsmenu.c
Normal file
122
source/tegraexplorer/fs/fsmenu.c
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include "fsmenu.h"
|
||||||
|
#include "fsreader.h"
|
||||||
|
#include "../gfx/menu.h"
|
||||||
|
#include "../gfx/gfxutils.h"
|
||||||
|
#include "fsutils.h"
|
||||||
|
#include "../common/common.h"
|
||||||
|
#include "../../libs/fatfs/ff.h"
|
||||||
|
#include "entrymenu.h"
|
||||||
|
|
||||||
|
extern char *currentpath;
|
||||||
|
extern char *clipboard;
|
||||||
|
extern u8 clipboardhelper;
|
||||||
|
int lastentry = 0;
|
||||||
|
|
||||||
|
void fileexplorer(const char *startpath, int type){
|
||||||
|
int res;
|
||||||
|
|
||||||
|
if (lastentry > 0 && lastentry == type)
|
||||||
|
clipboardhelper = 0;
|
||||||
|
|
||||||
|
if (clipboardhelper & OPERATIONMOVE)
|
||||||
|
clipboardhelper = 0;
|
||||||
|
|
||||||
|
lastentry = type;
|
||||||
|
|
||||||
|
fsreader_writecurpath(startpath);
|
||||||
|
fsreader_readfolder(currentpath);
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (strcmp(rootpath, "emmc:/"))
|
||||||
|
explfilemenu[6].property = 1;
|
||||||
|
else
|
||||||
|
explfilemenu[6].property = -1;
|
||||||
|
*/
|
||||||
|
|
||||||
|
while (1){
|
||||||
|
res = menu_make(fsreader_files, fsutil_getfileobjamount(fsreader_files), currentpath);
|
||||||
|
switch (res){
|
||||||
|
case FILEMENU_RETURN:
|
||||||
|
if (!strcmp(startpath, currentpath))
|
||||||
|
return;
|
||||||
|
else {
|
||||||
|
fsreader_writecurpath(fsutil_getprevloc(currentpath));
|
||||||
|
fsreader_readfolder(currentpath);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case FILEMENU_CLIPBOARD:
|
||||||
|
if (clipboardhelper & ISDIR)
|
||||||
|
copyfolder(clipboard, currentpath);
|
||||||
|
else
|
||||||
|
copyfile(clipboard, currentpath);
|
||||||
|
clipboardhelper = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FILEMENU_CURFOLDER:
|
||||||
|
if (foldermenu())
|
||||||
|
return;
|
||||||
|
break;
|
||||||
|
case -1:
|
||||||
|
return;
|
||||||
|
|
||||||
|
default:
|
||||||
|
if(fsreader_files[res].property & ISDIR){
|
||||||
|
fsreader_writecurpath(fsutil_getnextloc(currentpath, fsreader_files[res].name));
|
||||||
|
fsreader_readfolder(currentpath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if(filemenu(fsreader_files[res]))
|
||||||
|
return;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
while (1){
|
||||||
|
res = makefilemenu(fileobjects, getfileobjamount(), currentpath);
|
||||||
|
if (res < 1){
|
||||||
|
switch (res){
|
||||||
|
case -2:
|
||||||
|
if (!strcmp(rootpath, currentpath))
|
||||||
|
breakfree = true;
|
||||||
|
else {
|
||||||
|
writecurpath(getprevloc(currentpath));
|
||||||
|
readfolder(currentpath);
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
readfolder(currentpath);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
filemenu(fileobjects[res - 1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (breakfree)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
3
source/tegraexplorer/fs/fsmenu.h
Normal file
3
source/tegraexplorer/fs/fsmenu.h
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
void fileexplorer(const char *startpath, int type);
|
||||||
106
source/tegraexplorer/fs/fsreader.c
Normal file
106
source/tegraexplorer/fs/fsreader.c
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
#include "fsreader.h"
|
||||||
|
#include "../common/types.h"
|
||||||
|
#include "../common/common.h"
|
||||||
|
#include "fsutils.h"
|
||||||
|
#include "../../utils/types.h"
|
||||||
|
#include "../../libs/fatfs/ff.h"
|
||||||
|
#include "../gfx/gfxutils.h"
|
||||||
|
#include "../utils/utils.h"
|
||||||
|
#include "../../mem/heap.h"
|
||||||
|
|
||||||
|
menu_entry *fsreader_files = NULL;
|
||||||
|
char *currentpath = NULL;
|
||||||
|
char *clipboard = NULL;
|
||||||
|
u8 clipboardhelper = 0;
|
||||||
|
|
||||||
|
void fsreader_writecurpath(const char *in){
|
||||||
|
if (currentpath != NULL)
|
||||||
|
free(currentpath);
|
||||||
|
|
||||||
|
utils_copystring(in, ¤tpath);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fsreader_writeclipboard(const char *in, u8 args){
|
||||||
|
if (clipboard != NULL)
|
||||||
|
free(clipboard);
|
||||||
|
|
||||||
|
clipboardhelper = args;
|
||||||
|
|
||||||
|
utils_copystring(in, &clipboard);
|
||||||
|
}
|
||||||
|
|
||||||
|
void clearfileobjects(menu_entry **menu){
|
||||||
|
if ((*menu) != NULL){
|
||||||
|
for (int i = 0; (*menu)[i].name != NULL; i++){
|
||||||
|
free((*menu)[i].name);
|
||||||
|
(*menu)[i].name = NULL;
|
||||||
|
}
|
||||||
|
free((*menu));
|
||||||
|
(*menu) = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void createfileobjects(int size, menu_entry **menu){
|
||||||
|
(*menu) = calloc (size + 1, sizeof(menu_entry));
|
||||||
|
(*menu)[size].name = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void addobject(char* name, int spot, u8 attribs){
|
||||||
|
u64 size = 0;
|
||||||
|
int sizes = 0;
|
||||||
|
fsreader_files[spot].property = 0;
|
||||||
|
|
||||||
|
if (fsreader_files[spot].name != NULL){
|
||||||
|
free(fsreader_files[spot].name);
|
||||||
|
fsreader_files[spot].name = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
utils_copystring(name, &(fsreader_files[spot].name));
|
||||||
|
|
||||||
|
if (attribs & AM_DIR)
|
||||||
|
fsreader_files[spot].property |= (ISDIR);
|
||||||
|
else {
|
||||||
|
size = fsutil_getfilesize(fsutil_getnextloc(currentpath, name));
|
||||||
|
|
||||||
|
while (size > 1024){
|
||||||
|
size /= 1024;
|
||||||
|
sizes++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sizes > 3)
|
||||||
|
sizes = 0;
|
||||||
|
|
||||||
|
fsreader_files[spot].property |= (1 << (4 + sizes));
|
||||||
|
fsreader_files[spot].storage = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (attribs & AM_ARC)
|
||||||
|
fsreader_files[spot].property |= (ISARC);
|
||||||
|
}
|
||||||
|
|
||||||
|
int fsreader_readfolder(const char *path){
|
||||||
|
DIR dir;
|
||||||
|
FILINFO fno;
|
||||||
|
int folderamount, res;
|
||||||
|
|
||||||
|
clearfileobjects(&fsreader_files);
|
||||||
|
createfileobjects(fsutil_getfolderentryamount(path) + 3, &fsreader_files);
|
||||||
|
|
||||||
|
for (folderamount = 0; folderamount < 3; folderamount++){
|
||||||
|
utils_copystring(fs_menu_startdir[folderamount].name, &(fsreader_files[folderamount].name));
|
||||||
|
fsreader_files[folderamount].storage = fs_menu_startdir[folderamount].storage;
|
||||||
|
fsreader_files[folderamount].property = fs_menu_startdir[folderamount].property;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((res = f_opendir(&dir, path))){
|
||||||
|
gfx_errDisplay("readfolder", res, 0);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!f_readdir(&dir, &fno) && fno.fname[0]){
|
||||||
|
addobject(fno.fname, folderamount++, fno.fattrib);
|
||||||
|
}
|
||||||
|
|
||||||
|
f_closedir(&dir);
|
||||||
|
return folderamount;
|
||||||
|
}
|
||||||
10
source/tegraexplorer/fs/fsreader.h
Normal file
10
source/tegraexplorer/fs/fsreader.h
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "../common/types.h"
|
||||||
|
|
||||||
|
extern menu_entry *fsreader_files;
|
||||||
|
void fsreader_writecurpath(const char *in);
|
||||||
|
void fsreader_writeclipboard(const char *in, u8 args);
|
||||||
|
int fsreader_readfolder(const char *path);
|
||||||
|
|
||||||
|
void createfileobjects(int size, menu_entry **menu);
|
||||||
|
void clearfileobjects(menu_entry **menu);
|
||||||
90
source/tegraexplorer/fs/fsutils.c
Normal file
90
source/tegraexplorer/fs/fsutils.c
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include "fsutils.h"
|
||||||
|
#include "../utils/utils.h"
|
||||||
|
#include "../common/types.h"
|
||||||
|
#include "../../utils/types.h"
|
||||||
|
#include "../../libs/fatfs/ff.h"
|
||||||
|
#include "../../mem/heap.h"
|
||||||
|
#include "../../utils/sprintf.h"
|
||||||
|
#include "../gfx/gfxutils.h"
|
||||||
|
|
||||||
|
char *fsutil_getnextloc(const char *current, const char *add){
|
||||||
|
static char *ret;
|
||||||
|
|
||||||
|
if (ret != NULL){
|
||||||
|
free(ret);
|
||||||
|
ret = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t size = strlen(current) + strlen(add) + 2;
|
||||||
|
ret = (char*) malloc (size);
|
||||||
|
|
||||||
|
if (current[strlen(current) - 1] == '/')
|
||||||
|
sprintf(ret, "%s%s", current, add);
|
||||||
|
else
|
||||||
|
sprintf(ret, "%s/%s", current, add);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *fsutil_getprevloc(char *current){
|
||||||
|
static char *ret;
|
||||||
|
char *temp;
|
||||||
|
|
||||||
|
if (ret != NULL){
|
||||||
|
free(ret);
|
||||||
|
ret = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
utils_copystring(current, &ret);
|
||||||
|
temp = strrchr(ret, '/');
|
||||||
|
|
||||||
|
if (*(temp - 1) == ':')
|
||||||
|
temp++;
|
||||||
|
|
||||||
|
*temp = '\0';
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fsutil_getfileobjamount(menu_entry *entries){
|
||||||
|
int amount = 0;
|
||||||
|
|
||||||
|
while (entries[amount].name != NULL)
|
||||||
|
amount++;
|
||||||
|
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fsutil_checkfile(char* path){
|
||||||
|
FRESULT fr;
|
||||||
|
FILINFO fno;
|
||||||
|
|
||||||
|
fr = f_stat(path, &fno);
|
||||||
|
|
||||||
|
return !(fr & FR_NO_FILE);
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 fsutil_getfilesize(char *path){
|
||||||
|
FILINFO fno;
|
||||||
|
f_stat(path, &fno);
|
||||||
|
return fno.fsize;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fsutil_getfolderentryamount(const char *path){
|
||||||
|
DIR dir;
|
||||||
|
FILINFO fno;
|
||||||
|
int folderamount = 0, res;
|
||||||
|
|
||||||
|
if ((res = f_opendir(&dir, path))){
|
||||||
|
gfx_errDisplay("fsutil_getdircount", res, 0);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!f_readdir(&dir, &fno) && fno.fname[0]){
|
||||||
|
folderamount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
f_closedir(&dir);
|
||||||
|
return folderamount;
|
||||||
|
}
|
||||||
11
source/tegraexplorer/fs/fsutils.h
Normal file
11
source/tegraexplorer/fs/fsutils.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "../common/types.h"
|
||||||
|
#include "../../utils/types.h"
|
||||||
|
|
||||||
|
char *fsutil_getnextloc(const char *current, const char *add);
|
||||||
|
char *fsutil_getprevloc(char *current);
|
||||||
|
int fsutil_getfileobjamount(menu_entry *entries);
|
||||||
|
bool fsutil_checkfile(char* path);
|
||||||
|
u64 fsutil_getfilesize(char *path);
|
||||||
|
int fsutil_getfolderentryamount(const char *path);
|
||||||
|
int extract_bis_file(char *path, char *outfolder);
|
||||||
@@ -1,207 +0,0 @@
|
|||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include "../gfx/gfx.h"
|
|
||||||
#include "te.h"
|
|
||||||
#include "../utils/btn.h"
|
|
||||||
#include "../utils/util.h"
|
|
||||||
#include "gfx.h"
|
|
||||||
#include "fs.h"
|
|
||||||
#include "../mem/minerva.h"
|
|
||||||
|
|
||||||
const char fixedoptions[3][50] = {
|
|
||||||
"Folder -> previous folder ",
|
|
||||||
"Clipboard -> Current folder ",
|
|
||||||
"Return to main menu "
|
|
||||||
};
|
|
||||||
|
|
||||||
const char sizevalues[4][3] = {
|
|
||||||
"B ",
|
|
||||||
"KB",
|
|
||||||
"MB",
|
|
||||||
"GB"
|
|
||||||
};
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
int message(char* message, u32 color){
|
|
||||||
clearscreen();
|
|
||||||
gfx_printf("%k%s%k", color, message, COLOR_DEFAULT);
|
|
||||||
return btn_wait();
|
|
||||||
}
|
|
||||||
|
|
||||||
int makemenu(menu_item menu[], int menuamount){
|
|
||||||
int currentpos = 1, i, res;
|
|
||||||
clearscreen();
|
|
||||||
|
|
||||||
while (1){
|
|
||||||
gfx_con_setpos(0, 31);
|
|
||||||
|
|
||||||
if (currentpos == 1){
|
|
||||||
while (currentpos < menuamount && menu[currentpos - 1].property < 1)
|
|
||||||
currentpos++;
|
|
||||||
}
|
|
||||||
if (currentpos == menuamount){
|
|
||||||
while (currentpos > 1 && menu[currentpos - 1].property < 1)
|
|
||||||
currentpos--;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < menuamount; i++){
|
|
||||||
if (menu[i].property < 0)
|
|
||||||
continue;
|
|
||||||
if (i == currentpos - 1)
|
|
||||||
gfx_printf("%k%K%s%K\n", COLOR_DEFAULT, COLOR_WHITE, menu[i].name, COLOR_DEFAULT);
|
|
||||||
else
|
|
||||||
gfx_printf("%k%s\n", menu[i].color, menu[i].name);
|
|
||||||
}
|
|
||||||
gfx_printf("\n%k%s", COLOR_WHITE, menuamount);
|
|
||||||
|
|
||||||
res = btn_wait();
|
|
||||||
|
|
||||||
if (res & BTN_VOL_UP && currentpos > 1){
|
|
||||||
currentpos--;
|
|
||||||
while(menu[currentpos - 1].property < 1 && currentpos > 1)
|
|
||||||
currentpos--;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (res & BTN_VOL_DOWN && currentpos < menuamount){
|
|
||||||
currentpos++;
|
|
||||||
while(menu[currentpos - 1].property < 1 && currentpos < menuamount)
|
|
||||||
currentpos++;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (res & BTN_POWER)
|
|
||||||
return menu[currentpos - 1].internal_function;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void printbytes(u8 print[], u32 size, u32 offset){
|
|
||||||
gfx_con_setpos(0, 31);
|
|
||||||
gfx_hexdump(offset, print, size * sizeof(u8));
|
|
||||||
}
|
|
||||||
|
|
||||||
int makewaitmenu(char *initialmessage, char *hiddenmessage, int timer){
|
|
||||||
clearscreen();
|
|
||||||
int res;
|
|
||||||
u32 start = get_tmr_s();
|
|
||||||
|
|
||||||
gfx_printf(initialmessage);
|
|
||||||
|
|
||||||
while(1){
|
|
||||||
res = btn_read();
|
|
||||||
|
|
||||||
if (res & BTN_VOL_DOWN || res & BTN_VOL_UP)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (start + timer > get_tmr_s())
|
|
||||||
gfx_printf("\r<Wait %d seconds> ", timer + start - get_tmr_s());
|
|
||||||
|
|
||||||
else if (res & BTN_POWER)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
else
|
|
||||||
gfx_printf("\r%k%s%k", COLOR_RED, hiddenmessage, COLOR_WHITE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void printfsentry(fs_entry file, bool highlight, bool refresh){
|
|
||||||
int size = 0;
|
|
||||||
char *display;
|
|
||||||
int length;
|
|
||||||
|
|
||||||
display = (char*) malloc (38);
|
|
||||||
memset(display + 37, '\0', 1);
|
|
||||||
|
|
||||||
if (strlen(file.name) > 37){
|
|
||||||
strlcpy(display, file.name, 37);
|
|
||||||
memset(display + 34, '.', 3);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
strcpy(display, file.name);
|
|
||||||
|
|
||||||
if (highlight)
|
|
||||||
gfx_printf("%K%k", COLOR_WHITE, COLOR_DEFAULT);
|
|
||||||
else
|
|
||||||
gfx_printf("%K%k", COLOR_DEFAULT, COLOR_WHITE);
|
|
||||||
|
|
||||||
if (file.property & ISDIR)
|
|
||||||
gfx_printf("%s\n", display);
|
|
||||||
else {
|
|
||||||
for (size = 4; size < 8; size++)
|
|
||||||
if ((file.property & (1 << size)))
|
|
||||||
break;
|
|
||||||
|
|
||||||
gfx_printf("%k%s%K", COLOR_VIOLET, display, COLOR_DEFAULT);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (refresh){
|
|
||||||
length = strlen(display);
|
|
||||||
for (int i = 0; i < (42 - length); i++)
|
|
||||||
gfx_printf(" ");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(file.property & ISDIR))
|
|
||||||
gfx_printf("\a%d\e%s", file.size, sizevalues[size - 4]);
|
|
||||||
|
|
||||||
free(display);
|
|
||||||
}
|
|
||||||
|
|
||||||
int makefilemenu(fs_entry *files, int amount, char *path){
|
|
||||||
int currentpos = -2, i, res = 0, offset = 0, quickoffset = 300;
|
|
||||||
u32 timer;
|
|
||||||
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);
|
|
||||||
while (1){
|
|
||||||
gfx_con_setpos(0, 47);
|
|
||||||
timer = get_tmr_ms();
|
|
||||||
for (i = -3 + offset; i < amount && i < 60 + offset; i++){
|
|
||||||
if (i < 0){
|
|
||||||
if (i == currentpos - 1)
|
|
||||||
gfx_printf("%k%K%s%K\n", COLOR_ORANGE, COLOR_WHITE, fixedoptions[i + 3], COLOR_DEFAULT);
|
|
||||||
else
|
|
||||||
gfx_printf("%k%K%s\n", COLOR_ORANGE, COLOR_DEFAULT, fixedoptions[i + 3]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
printfsentry(files[i], (i == currentpos - 1), refresh);
|
|
||||||
}
|
|
||||||
refresh = false;
|
|
||||||
gfx_printf("\n%k%K %s %s\n\nTime taken for screen draw: %dms ", COLOR_BLUE, COLOR_DEFAULT, (offset + 60 < amount) ? "v" : " ", (offset > 0) ? "^" : " ", get_tmr_ms() - timer);
|
|
||||||
|
|
||||||
if (quickoffset == 300)
|
|
||||||
res = btn_wait();
|
|
||||||
else {
|
|
||||||
msleep(quickoffset);
|
|
||||||
res = btn_read();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (res == 0)
|
|
||||||
quickoffset = 300;
|
|
||||||
else if (quickoffset > 46)
|
|
||||||
quickoffset -= 45;
|
|
||||||
|
|
||||||
if ((res & BTN_VOL_UP) && currentpos > -2){
|
|
||||||
currentpos--;
|
|
||||||
if (offset != 0 && currentpos < offset - 2){
|
|
||||||
offset--;
|
|
||||||
refresh = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ((res & BTN_VOL_DOWN) && currentpos < amount){
|
|
||||||
currentpos++;
|
|
||||||
if (currentpos - offset > 60){
|
|
||||||
offset++;
|
|
||||||
refresh = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (res & BTN_POWER)
|
|
||||||
return currentpos;
|
|
||||||
}
|
|
||||||
minerva_periodic_training();
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "te.h"
|
|
||||||
#include "fs.h"
|
|
||||||
|
|
||||||
int makemenu(menu_item menu[], int menuamount);
|
|
||||||
int message(char* message, u32 color);
|
|
||||||
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);
|
|
||||||
134
source/tegraexplorer/gfx/gfxutils.c
Normal file
134
source/tegraexplorer/gfx/gfxutils.c
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
#include "gfxutils.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include "menu.h"
|
||||||
|
#include "../../gfx/gfx.h"
|
||||||
|
#include "../../power/max17050.h"
|
||||||
|
#include "../../utils/btn.h"
|
||||||
|
#include "../../utils/util.h"
|
||||||
|
#include "../../mem/heap.h"
|
||||||
|
#include "../common/common.h"
|
||||||
|
|
||||||
|
int printerrors = true;
|
||||||
|
|
||||||
|
void gfx_clearscreen(){
|
||||||
|
int battery = 0;
|
||||||
|
max17050_get_property(MAX17050_RepSOC, &battery);
|
||||||
|
|
||||||
|
gfx_clear_grey(0x1B);
|
||||||
|
SWAPCOLOR(COLOR_DEFAULT);
|
||||||
|
SWAPBGCOLOR(COLOR_WHITE);
|
||||||
|
|
||||||
|
gfx_box(0, 1263, 719, 1279, COLOR_WHITE);
|
||||||
|
gfx_con_setpos(0, 1263);
|
||||||
|
gfx_printf("Move: Vol+/- | Select: Pow | Battery: %3d%%", battery >> 8);
|
||||||
|
|
||||||
|
gfx_box(0, 0, 719, 15, COLOR_WHITE);
|
||||||
|
gfx_con_setpos(0, 0);
|
||||||
|
gfx_printf("Tegraexplorer v1.5.1\n");
|
||||||
|
|
||||||
|
RESETCOLOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
int gfx_message(u32 color, const char* message, ...){
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, message);
|
||||||
|
|
||||||
|
gfx_clearscreen();
|
||||||
|
SWAPCOLOR(color);
|
||||||
|
|
||||||
|
gfx_vprintf(message, ap);
|
||||||
|
|
||||||
|
va_end(ap);
|
||||||
|
return btn_wait();
|
||||||
|
}
|
||||||
|
|
||||||
|
int gfx_errDisplay(char *src_func, int err, int loc){
|
||||||
|
if (!printerrors)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
gfx_clearscreen();
|
||||||
|
SWAPCOLOR(COLOR_ORANGE);
|
||||||
|
gfx_printf("\nAn error occured:\n\n");
|
||||||
|
gfx_printf("Function: %s\nErrcode: %d\n", src_func, err);
|
||||||
|
|
||||||
|
if (err < 15)
|
||||||
|
gfx_printf("Desc: %s\n", utils_err_codes[err]);
|
||||||
|
else if (err >= ERR_SAME_LOC && err <= ERR_NO_DESTENATION)
|
||||||
|
gfx_printf("Desc: %s\n", utils_err_codes_te[err - 50]);
|
||||||
|
|
||||||
|
if (loc)
|
||||||
|
gfx_printf("Loc: %d\n", loc);
|
||||||
|
|
||||||
|
gfx_printf("\nPress any button to return");
|
||||||
|
|
||||||
|
RESETCOLOR;
|
||||||
|
|
||||||
|
while (btn_read() != 0);
|
||||||
|
|
||||||
|
return btn_wait();
|
||||||
|
}
|
||||||
|
|
||||||
|
int gfx_makewaitmenu(char *hiddenmessage, int timer){
|
||||||
|
int res;
|
||||||
|
u32 start = get_tmr_s();
|
||||||
|
|
||||||
|
while (btn_read() != 0);
|
||||||
|
|
||||||
|
while(1){
|
||||||
|
res = btn_read();
|
||||||
|
|
||||||
|
if (res & BTN_VOL_DOWN || res & BTN_VOL_UP)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (start + timer > get_tmr_s())
|
||||||
|
gfx_printf("\r<Wait %d seconds> ", timer + start - get_tmr_s());
|
||||||
|
|
||||||
|
else if (res & BTN_POWER)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
else
|
||||||
|
gfx_printf("\r%s", hiddenmessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void gfx_printlength(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 gfx_printandclear(char *in, int length){
|
||||||
|
u32 x, y;
|
||||||
|
|
||||||
|
gfx_printlength(length, in);
|
||||||
|
gfx_con_getpos(&x, &y);
|
||||||
|
RESETCOLOR;
|
||||||
|
|
||||||
|
for (int i = (703 - x) / 16; i > 0; i--)
|
||||||
|
gfx_printf(" ");
|
||||||
|
|
||||||
|
gfx_con_setpos(x, y);
|
||||||
|
|
||||||
|
//gfx_box(x, y, 719, y + 16, COLOR_DEFAULT);
|
||||||
|
/*
|
||||||
|
u8 color = 0x1B;
|
||||||
|
gfx_set_rect_grey(&color, 719 - x, 16, x, y);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void gfx_printfilesize(int size, char *type){
|
||||||
|
SWAPCOLOR(COLOR_VIOLET);
|
||||||
|
gfx_printf("\a%4d\e%s", size, type);
|
||||||
|
RESETCOLOR;
|
||||||
|
}
|
||||||
17
source/tegraexplorer/gfx/gfxutils.h
Normal file
17
source/tegraexplorer/gfx/gfxutils.h
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "../../gfx/gfx.h"
|
||||||
|
#include "../../utils/types.h"
|
||||||
|
|
||||||
|
#define SWAPCOLOR(color) gfx_printf("%k", color)
|
||||||
|
#define SWAPBGCOLOR(color) gfx_printf("%K", color)
|
||||||
|
#define RESETCOLOR gfx_printf("%k%K", COLOR_WHITE, COLOR_DEFAULT)
|
||||||
|
|
||||||
|
void gfx_clearscreen();
|
||||||
|
int gfx_message(u32 color, const char* message, ...);
|
||||||
|
int gfx_errDisplay(char *src_func, int err, int loc);
|
||||||
|
int gfx_makewaitmenu(char *hiddenmessage, int timer);
|
||||||
|
void gfx_printlength(int size, char *toprint);
|
||||||
|
void gfx_printandclear(char *in, int length);
|
||||||
|
void gfx_printfilesize(int size, char *type);
|
||||||
|
|
||||||
|
extern int printerrors;
|
||||||
165
source/tegraexplorer/gfx/menu.c
Normal file
165
source/tegraexplorer/gfx/menu.c
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
#include "menu.h"
|
||||||
|
#include "gfxutils.h"
|
||||||
|
#include "../common/types.h"
|
||||||
|
#include "../../utils/btn.h"
|
||||||
|
#include "../common/common.h"
|
||||||
|
#include "../../utils/util.h"
|
||||||
|
#include "../../mem/minerva.h"
|
||||||
|
#include "../../soc/gpio.h"
|
||||||
|
|
||||||
|
extern void sd_unmount();
|
||||||
|
extern bool sd_inited;
|
||||||
|
|
||||||
|
void _printentry(menu_entry entry, bool highlighted, bool refresh){
|
||||||
|
int size;
|
||||||
|
u32 color = (entry.property & ISMENU) ? entry.storage : ((entry.property & ISDIR) ? COLOR_WHITE : COLOR_VIOLET);
|
||||||
|
/*
|
||||||
|
if (entry.property & ISMENU)
|
||||||
|
SWAPCOLOR(entry.storage);
|
||||||
|
else if (entry.property & ISDIR)
|
||||||
|
SWAPCOLOR(COLOR_WHITE);
|
||||||
|
else {
|
||||||
|
SWAPCOLOR(COLOR_VIOLET);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!(entry.property & ISMENU && entry.property & ISDIR)){
|
||||||
|
for (size = 4; size < 8; size++)
|
||||||
|
if ((entry.property & (1 << size)))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (highlighted){
|
||||||
|
SWAPBGCOLOR(COLOR_WHITE);
|
||||||
|
if ((entry.property & ISMENU) ? entry.storage == COLOR_WHITE : entry.property & ISDIR)
|
||||||
|
SWAPCOLOR(COLOR_DEFAULT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
SWAPBGCOLOR(COLOR_DEFAULT);
|
||||||
|
*/
|
||||||
|
SWAPCOLOR((highlighted) ? COLOR_DEFAULT : color);
|
||||||
|
SWAPBGCOLOR((highlighted) ? color : COLOR_DEFAULT);
|
||||||
|
|
||||||
|
|
||||||
|
if (refresh)
|
||||||
|
gfx_printandclear(entry.name, 37);
|
||||||
|
else
|
||||||
|
gfx_printlength(37, entry.name);
|
||||||
|
|
||||||
|
if (entry.property & ISDIR || entry.property & ISMENU)
|
||||||
|
gfx_printf("\n");
|
||||||
|
else {
|
||||||
|
SWAPCOLOR(COLOR_BLUE);
|
||||||
|
SWAPBGCOLOR(COLOR_DEFAULT);
|
||||||
|
gfx_printf("\a%d\e%s", entry.storage, gfx_file_size_names[size - 4]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int menu_make(menu_entry *entries, int amount, char *toptext){
|
||||||
|
int currentpos = 0, res = 0, offset = 0, delay = 300, minscreen = 0, maxscreen = 59, calculatedamount = 0;
|
||||||
|
u32 scrolltimer, timer;
|
||||||
|
bool refresh = false;
|
||||||
|
|
||||||
|
gfx_clearscreen();
|
||||||
|
|
||||||
|
for (int i = 0; i < amount; i++)
|
||||||
|
if (!(entries[i].property & ISMENU))
|
||||||
|
calculatedamount++;
|
||||||
|
|
||||||
|
gfx_con_setpos(512, 0);
|
||||||
|
if (calculatedamount){
|
||||||
|
SWAPCOLOR(COLOR_DEFAULT);
|
||||||
|
SWAPBGCOLOR(COLOR_WHITE);
|
||||||
|
gfx_printf("%3d entries\n", calculatedamount);
|
||||||
|
RESETCOLOR;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
gfx_printf("\n");
|
||||||
|
|
||||||
|
SWAPCOLOR(COLOR_GREEN);
|
||||||
|
gfx_printlength(42, toptext);
|
||||||
|
RESETCOLOR;
|
||||||
|
|
||||||
|
while (!(res & BTN_POWER)){
|
||||||
|
gfx_con_setpos(0, 47);
|
||||||
|
timer = get_tmr_ms();
|
||||||
|
refresh = false;
|
||||||
|
|
||||||
|
if (!currentpos){
|
||||||
|
while (currentpos < amount && entries[currentpos].property & (ISSKIP | ISHIDE))
|
||||||
|
currentpos++;
|
||||||
|
}
|
||||||
|
if (currentpos == amount - 1){
|
||||||
|
while (currentpos >= 1 && entries[currentpos].property & (ISSKIP | ISHIDE))
|
||||||
|
currentpos--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentpos > maxscreen){
|
||||||
|
offset += currentpos - maxscreen;
|
||||||
|
minscreen += currentpos - maxscreen;
|
||||||
|
maxscreen += currentpos - maxscreen;
|
||||||
|
refresh = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentpos < minscreen){
|
||||||
|
offset -= minscreen - currentpos;
|
||||||
|
maxscreen -= minscreen - currentpos;
|
||||||
|
minscreen -= minscreen - currentpos;
|
||||||
|
refresh = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0 + offset; i < amount && i < 60 + offset; i++)
|
||||||
|
if (!(entries[i].property & ISHIDE))
|
||||||
|
_printentry(entries[i], (i == currentpos), refresh);
|
||||||
|
|
||||||
|
gfx_printf("\n%k%K %s %s\n\nTime taken for screen draw: %dms", COLOR_BLUE, COLOR_DEFAULT, (offset + 60 < amount) ? "v" : " ", (offset > 0) ? "^" : " ", get_tmr_ms() - timer);
|
||||||
|
|
||||||
|
while (btn_read() & BTN_POWER);
|
||||||
|
|
||||||
|
res = 0;
|
||||||
|
while (!res){
|
||||||
|
if (sd_inited && !!gpio_read(GPIO_PORT_Z, GPIO_PIN_1)){
|
||||||
|
gfx_errDisplay("menu", ERR_SD_EJECTED, 0);
|
||||||
|
sd_unmount();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
res = btn_read();
|
||||||
|
|
||||||
|
if (!res)
|
||||||
|
delay = 300;
|
||||||
|
|
||||||
|
if (delay < 300){
|
||||||
|
scrolltimer = get_tmr_ms();
|
||||||
|
while (res){
|
||||||
|
if (scrolltimer + delay <= get_tmr_ms())
|
||||||
|
break;
|
||||||
|
|
||||||
|
res = btn_read();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (delay > 46 && res)
|
||||||
|
delay -= 45;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (res & BTN_VOL_UP && currentpos >= 1){
|
||||||
|
currentpos--;
|
||||||
|
while(entries[currentpos].property & (ISSKIP | ISHIDE) && currentpos >= 1)
|
||||||
|
currentpos--;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (res & BTN_VOL_DOWN && currentpos < amount - 1){
|
||||||
|
currentpos++;
|
||||||
|
while(entries[currentpos].property & (ISSKIP | ISHIDE) && currentpos < amount - 1)
|
||||||
|
currentpos++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
minerva_periodic_training();
|
||||||
|
//return (mode) ? currentpos : entries[currentpos].property;
|
||||||
|
return currentpos;
|
||||||
|
}
|
||||||
4
source/tegraexplorer/gfx/menu.h
Normal file
4
source/tegraexplorer/gfx/menu.h
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "../common/types.h"
|
||||||
|
|
||||||
|
int menu_make(menu_entry *entries, int amount, char *toptext);
|
||||||
186
source/tegraexplorer/mainmenu.c
Normal file
186
source/tegraexplorer/mainmenu.c
Normal file
@@ -0,0 +1,186 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "mainmenu.h"
|
||||||
|
#include "../utils/util.h"
|
||||||
|
#include "utils/tools.h"
|
||||||
|
#include "../utils/btn.h"
|
||||||
|
#include "emmc/emmc.h"
|
||||||
|
#include "../storage/emummc.h"
|
||||||
|
#include "script/functions.h"
|
||||||
|
|
||||||
|
#include "common/common.h"
|
||||||
|
#include "gfx/menu.h"
|
||||||
|
|
||||||
|
#include "utils/utils.h"
|
||||||
|
#include "gfx/gfxutils.h"
|
||||||
|
#include "fs/fsutils.h"
|
||||||
|
#include "fs/fsmenu.h"
|
||||||
|
#include "emmc/emmcoperations.h"
|
||||||
|
#include "emmc/emmcmenu.h"
|
||||||
|
|
||||||
|
extern bool sd_mount();
|
||||||
|
extern void sd_unmount();
|
||||||
|
extern int launch_payload(char *path);
|
||||||
|
extern bool sd_inited;
|
||||||
|
extern bool sd_mounted;
|
||||||
|
|
||||||
|
int res = 0, meter = 0;
|
||||||
|
|
||||||
|
void MainMenu_SDCard(){
|
||||||
|
fileexplorer("SD:/", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainMenu_EMMC(){
|
||||||
|
gfx_clearscreen();
|
||||||
|
gfx_printf("You're about to enter EMMC\nModifying anything here\n can result in a BRICK!\n\nPlease only continue\n if you know what you're doing\n\nPress Vol+/- to return\n");
|
||||||
|
if (gfx_makewaitmenu("Press Power to enter", 4)){
|
||||||
|
/*
|
||||||
|
connect_mmc(SYSMMC);
|
||||||
|
|
||||||
|
if (!mount_mmc(emmc_fs_entries[res - 2], res - 1))
|
||||||
|
fileexplorer("emmc:/", 1);
|
||||||
|
*/
|
||||||
|
makeMmcMenu(SYSMMC);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainMenu_EMUMMC(){
|
||||||
|
/*
|
||||||
|
connect_mmc(EMUMMC);
|
||||||
|
|
||||||
|
if (!mount_mmc(emmc_fs_entries[res - 5], res - 4))
|
||||||
|
fileexplorer("emmc:/", 1);
|
||||||
|
*/
|
||||||
|
makeMmcMenu(EMUMMC);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainMenu_MountSD(){
|
||||||
|
(sd_mounted) ? sd_unmount() : sd_mount();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainMenu_Tools(){
|
||||||
|
//res = makemenu(toolsmenu, 8);
|
||||||
|
res = menu_make(mainmenu_tools, 5, "-- Tools Menu --");
|
||||||
|
|
||||||
|
switch(res){
|
||||||
|
case TOOLS_DISPLAY_INFO:
|
||||||
|
displayinfo();
|
||||||
|
break;
|
||||||
|
case TOOLS_DISPLAY_GPIO:
|
||||||
|
displaygpio();
|
||||||
|
//makeMmcMenu(SYSMMC);
|
||||||
|
break;
|
||||||
|
case TOOLS_DUMPFIRMWARE:
|
||||||
|
dumpfirmware(SYSMMC);
|
||||||
|
break;
|
||||||
|
case TOOLS_DUMPUSERSAVE:
|
||||||
|
if ((res = utils_mmcMenu()) > 0)
|
||||||
|
dumpusersaves(res);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainMenu_SDFormat(){
|
||||||
|
//res = makemenu(formatmenu, 4);
|
||||||
|
res = menu_make(mainmenu_format, 3, "-- Format Menu --");
|
||||||
|
|
||||||
|
if (res > 0){
|
||||||
|
gfx_clearscreen();
|
||||||
|
gfx_printf("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");
|
||||||
|
if(gfx_makewaitmenu("Press Power to continue", 10)){
|
||||||
|
if (format(res)){
|
||||||
|
sd_unmount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainMenu_Credits(){
|
||||||
|
if (++meter >= 3)
|
||||||
|
gfx_errDisplay("credits", 53, 0);
|
||||||
|
gfx_message(COLOR_WHITE, mainmenu_credits);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainMenu_Exit(){
|
||||||
|
if (sd_mounted){
|
||||||
|
SETBIT(mainmenu_shutdown[4].property, ISHIDE, !fsutil_checkfile("/bootloader/update.bin"));
|
||||||
|
SETBIT(mainmenu_shutdown[5].property, ISHIDE, !fsutil_checkfile("/atmosphere/reboot_payload.bin"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (int i = 4; i <= 5; i++)
|
||||||
|
SETBIT(mainmenu_shutdown[i].property, ISHIDE, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
res = menu_make(mainmenu_shutdown, 6, "-- Shutdown Menu --");
|
||||||
|
|
||||||
|
switch(res){
|
||||||
|
case SHUTDOWN_REBOOT_RCM:
|
||||||
|
reboot_rcm();
|
||||||
|
|
||||||
|
case SHUTDOWN_REBOOT_NORMAL:
|
||||||
|
reboot_normal();
|
||||||
|
|
||||||
|
case SHUTDOWN_POWER_OFF:
|
||||||
|
power_off();
|
||||||
|
|
||||||
|
case SHUTDOWN_HEKATE:
|
||||||
|
launch_payload("/bootloader/update.bin");
|
||||||
|
|
||||||
|
case SHUTDOWN_AMS:
|
||||||
|
launch_payload("/atmosphere/reboot_payload.bin");
|
||||||
|
} //todo declock bpmp
|
||||||
|
}
|
||||||
|
|
||||||
|
func_void_ptr mainmenu_functions[] = {
|
||||||
|
MainMenu_SDCard,
|
||||||
|
MainMenu_EMMC,
|
||||||
|
MainMenu_EMUMMC,
|
||||||
|
MainMenu_MountSD,
|
||||||
|
MainMenu_Tools,
|
||||||
|
MainMenu_SDFormat,
|
||||||
|
MainMenu_Credits,
|
||||||
|
MainMenu_Exit,
|
||||||
|
};
|
||||||
|
|
||||||
|
void RunMenuOption(int option){
|
||||||
|
if (option != 7)
|
||||||
|
meter = 0;
|
||||||
|
if (option > 0)
|
||||||
|
mainmenu_functions[option - 1]();
|
||||||
|
}
|
||||||
|
void te_main(){
|
||||||
|
int setter;
|
||||||
|
|
||||||
|
if (dump_biskeys() == -1){
|
||||||
|
gfx_errDisplay("dump_biskey", ERR_BISKEY_DUMP_FAILED, 0);
|
||||||
|
mainmenu_main[1].property |= ISHIDE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (emummc_load_cfg()){
|
||||||
|
mainmenu_main[2].property |= ISHIDE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
dumpEmuGpt();
|
||||||
|
|
||||||
|
disconnect_mmc();
|
||||||
|
|
||||||
|
while (1){
|
||||||
|
//fillmainmenu();
|
||||||
|
|
||||||
|
setter = sd_mounted;
|
||||||
|
|
||||||
|
if (emu_cfg.enabled){
|
||||||
|
SETBIT(mainmenu_main[2].property, ISHIDE, !setter);
|
||||||
|
}
|
||||||
|
|
||||||
|
SETBIT(mainmenu_main[0].property, ISHIDE, !setter);
|
||||||
|
mainmenu_main[3].name = (menu_sd_states[!setter]);
|
||||||
|
|
||||||
|
setter = sd_inited;
|
||||||
|
SETBIT(mainmenu_main[5].property, ISHIDE, !setter);
|
||||||
|
|
||||||
|
res = menu_make(mainmenu_main, 8, "-- Main Menu --") + 1;
|
||||||
|
RunMenuOption(res);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../utils/types.h"
|
#include "../utils/types.h"
|
||||||
|
|
||||||
#define MAINMENU_AMOUNT 7
|
#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"
|
|
||||||
|
|
||||||
|
/*
|
||||||
typedef struct _menu_item {
|
typedef struct _menu_item {
|
||||||
char name[50];
|
char name[50];
|
||||||
u32 color;
|
u32 color;
|
||||||
@@ -11,10 +11,15 @@ typedef struct _menu_item {
|
|||||||
short property;
|
short property;
|
||||||
} menu_item;
|
} menu_item;
|
||||||
|
|
||||||
|
|
||||||
enum mainmenu_return {
|
enum mainmenu_return {
|
||||||
SD_CARD = 1,
|
SD_CARD = 1,
|
||||||
|
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,
|
||||||
@@ -33,14 +38,16 @@ enum shutdownmenu_return {
|
|||||||
enum toolsmenu_return {
|
enum toolsmenu_return {
|
||||||
DISPLAY_INFO = 1,
|
DISPLAY_INFO = 1,
|
||||||
DISPLAY_GPIO,
|
DISPLAY_GPIO,
|
||||||
DUMPFIRMWARE
|
DUMPFIRMWARE,
|
||||||
|
DUMPUSERSAVE,
|
||||||
|
DUMP_BOOT,
|
||||||
|
RESTORE_BOOT
|
||||||
};
|
};
|
||||||
|
|
||||||
enum formatmenu_return {
|
enum formatmenu_return {
|
||||||
FORMAT_ALL_FAT32,
|
FORMAT_EMUMMC = 0,
|
||||||
FORMAT_EMUMMC
|
FORMAT_ALL_FAT32
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
//menu_item mainmenu[MAINMENU_AMOUNT];
|
|
||||||
|
|
||||||
void te_main();
|
void te_main();
|
||||||
582
source/tegraexplorer/script/functions.c
Normal file
582
source/tegraexplorer/script/functions.c
Normal file
@@ -0,0 +1,582 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "../../mem/heap.h"
|
||||||
|
#include "../gfx/gfxutils.h"
|
||||||
|
#include "../emmc/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 "parser.h"
|
||||||
|
#include "../common/common.h"
|
||||||
|
#include "../fs/fsactions.h"
|
||||||
|
#include "variables.h"
|
||||||
|
#include "../utils/utils.h"
|
||||||
|
#include "functions.h"
|
||||||
|
#include "../fs/fsutils.h"
|
||||||
|
#include "../../utils/sprintf.h"
|
||||||
|
#include "../fs/fsactions.h"
|
||||||
|
#include "../emmc/emmcoperations.h"
|
||||||
|
#include "../emmc/emmcmenu.h"
|
||||||
|
|
||||||
|
extern FIL scriptin;
|
||||||
|
extern char **argv;
|
||||||
|
extern u32 argc;
|
||||||
|
extern int forceExit;
|
||||||
|
extern short currentlyMounted;
|
||||||
|
|
||||||
|
int parseIntInput(char *in, int *out){
|
||||||
|
if (in[0] == '@'){
|
||||||
|
if (str_int_find(in, out))
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
*out = atoi(in);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
int parseJmpInput(char *in, u64 *out){
|
||||||
|
if (in[0] == '?'){
|
||||||
|
if (str_jmp_find(in, out))
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
int parseStringInput(char *in, char **out){
|
||||||
|
if (in[0] == '$'){
|
||||||
|
if (str_str_find(in, out))
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
*out = in;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 currentcolor = COLOR_WHITE;
|
||||||
|
int part_printf(){
|
||||||
|
char *toprint;
|
||||||
|
if (parseStringInput(argv[0], &toprint))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
SWAPCOLOR(currentcolor);
|
||||||
|
gfx_printf(toprint);
|
||||||
|
gfx_printf("\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_print_int(){
|
||||||
|
int toprint;
|
||||||
|
if (parseIntInput(argv[0], &toprint))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
SWAPCOLOR(currentcolor);
|
||||||
|
gfx_printf("%s: %d\n", argv[0], toprint);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_Wait(){
|
||||||
|
int arg;
|
||||||
|
u32 begintime;
|
||||||
|
SWAPCOLOR(currentcolor);
|
||||||
|
|
||||||
|
if (parseIntInput(argv[0], &arg))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
begintime = get_tmr_s();
|
||||||
|
|
||||||
|
while (begintime + arg > get_tmr_s()){
|
||||||
|
gfx_printf("\r<Wait %d seconds> ", (begintime + arg) - get_tmr_s());
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx_printf("\r \r");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_Check(){
|
||||||
|
int left, right;
|
||||||
|
if (parseIntInput(argv[0], &left))
|
||||||
|
return -1;
|
||||||
|
if (parseIntInput(argv[2], &right))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (!strcmp(argv[1], "=="))
|
||||||
|
return (left == right);
|
||||||
|
else if (!strcmp(argv[1], "!="))
|
||||||
|
return (left != right);
|
||||||
|
else if (!strcmp(argv[1], ">="))
|
||||||
|
return (left >= right);
|
||||||
|
else if (!strcmp(argv[1], "<="))
|
||||||
|
return (left <= right);
|
||||||
|
else if (!strcmp(argv[1], ">"))
|
||||||
|
return (left > right);
|
||||||
|
else if (!strcmp(argv[1], "<"))
|
||||||
|
return (left < right);
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_if(){
|
||||||
|
int condition;
|
||||||
|
if (parseIntInput(argv[0], &condition))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
getfollowingchar('{');
|
||||||
|
|
||||||
|
if (!condition)
|
||||||
|
skipbrackets();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (condition)
|
||||||
|
return 0;
|
||||||
|
else {
|
||||||
|
skipbrackets();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_if_args(){
|
||||||
|
int condition;
|
||||||
|
if ((condition = part_Check()) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
getfollowingchar('{');
|
||||||
|
|
||||||
|
if (!condition)
|
||||||
|
skipbrackets();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_Math(){
|
||||||
|
int left, right;
|
||||||
|
if (parseIntInput(argv[0], &left))
|
||||||
|
return -1;
|
||||||
|
if (parseIntInput(argv[2], &right))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
switch (argv[1][0]){
|
||||||
|
case '+':
|
||||||
|
return left + right;
|
||||||
|
case '-':
|
||||||
|
return left - right;
|
||||||
|
case '*':
|
||||||
|
return left * right;
|
||||||
|
case '/':
|
||||||
|
return left / right;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_SetInt(){
|
||||||
|
int out;
|
||||||
|
parseIntInput(argv[0], &out);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_SetString(){
|
||||||
|
char *arg0;
|
||||||
|
if (parseStringInput(argv[0], &arg0))
|
||||||
|
return -1;
|
||||||
|
if (argv[1][0] != '$')
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
str_str_add(argv[1], arg0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_SetStringIndex(){
|
||||||
|
int index;
|
||||||
|
char *out;
|
||||||
|
if (parseIntInput(argv[0], &index))
|
||||||
|
return -1;
|
||||||
|
if (argv[1][0] != '$')
|
||||||
|
return -1;
|
||||||
|
if (str_str_index(index, &out))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
str_str_add(argv[1], out);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_goto(){
|
||||||
|
int target = 0;
|
||||||
|
if (parseIntInput(argv[0], &target))
|
||||||
|
return -1;
|
||||||
|
f_lseek(&scriptin, target);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_invert(){
|
||||||
|
int arg;
|
||||||
|
if (parseIntInput(argv[0], &arg))
|
||||||
|
return -1;
|
||||||
|
return (arg) ? 0 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_fs_exists(){
|
||||||
|
char *path;
|
||||||
|
if (parseStringInput(argv[0], &path))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return fsutil_checkfile(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_ConnectMMC(){
|
||||||
|
char *arg;
|
||||||
|
parseStringInput(argv[0], &arg);
|
||||||
|
|
||||||
|
if (!strcmp(arg, "SYSMMC"))
|
||||||
|
connect_mmc(SYSMMC);
|
||||||
|
else if (!strcmp(arg, "EMUMMC"))
|
||||||
|
connect_mmc(EMUMMC);
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_MountMMC(){
|
||||||
|
char *arg;
|
||||||
|
parseStringInput(argv[0], &arg);
|
||||||
|
return mount_mmc(arg, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_Pause(){
|
||||||
|
int res;
|
||||||
|
|
||||||
|
while (btn_read() != 0);
|
||||||
|
|
||||||
|
res = btn_wait();
|
||||||
|
|
||||||
|
str_int_add("@BTN_POWER", (res & BTN_POWER));
|
||||||
|
str_int_add("@BTN_VOL+", (res & BTN_VOL_UP));
|
||||||
|
str_int_add("@BTN_VOL-", (res & BTN_VOL_DOWN));
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_addstrings(){
|
||||||
|
char *combined, *left, *middle;
|
||||||
|
if (parseStringInput(argv[0], &left))
|
||||||
|
return -1;
|
||||||
|
if (parseStringInput(argv[1], &middle))
|
||||||
|
return -1;
|
||||||
|
if (argv[2][0] != '$')
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
combined = calloc(strlen(left) + strlen(middle) + 1, sizeof(char));
|
||||||
|
sprintf(combined, "%s%s", left, middle);
|
||||||
|
|
||||||
|
str_str_add(argv[2], combined);
|
||||||
|
free(combined);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_setColor(){
|
||||||
|
char *arg;
|
||||||
|
if (parseStringInput(argv[0], &arg))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (!strcmp(arg, "RED"))
|
||||||
|
currentcolor = COLOR_RED;
|
||||||
|
else if (!strcmp(arg, "ORANGE"))
|
||||||
|
currentcolor = COLOR_ORANGE;
|
||||||
|
else if (!strcmp(arg, "YELLOW"))
|
||||||
|
currentcolor = COLOR_YELLOW;
|
||||||
|
else if (!strcmp(arg, "GREEN"))
|
||||||
|
currentcolor = COLOR_GREEN;
|
||||||
|
else if (!strcmp(arg, "BLUE"))
|
||||||
|
currentcolor = COLOR_BLUE;
|
||||||
|
else if (!strcmp(arg, "VIOLET"))
|
||||||
|
currentcolor = COLOR_VIOLET;
|
||||||
|
else if (!strcmp(arg, "WHITE"))
|
||||||
|
currentcolor = COLOR_WHITE;
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_Exit(){
|
||||||
|
forceExit = true;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_fs_Move(){
|
||||||
|
char *left, *right;
|
||||||
|
|
||||||
|
if (parseStringInput(argv[0], &left))
|
||||||
|
return -1;
|
||||||
|
if (parseStringInput(argv[1], &right))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
int res;
|
||||||
|
res = f_rename(left, right);
|
||||||
|
if (res)
|
||||||
|
res = f_rename(left, right);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_fs_Delete(){
|
||||||
|
char *arg;
|
||||||
|
|
||||||
|
if (parseStringInput(argv[0], &arg))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
int res;
|
||||||
|
res = f_unlink(arg);
|
||||||
|
if (res)
|
||||||
|
res = f_unlink(arg);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_fs_DeleteRecursive(){
|
||||||
|
char *arg;
|
||||||
|
|
||||||
|
if (parseStringInput(argv[0], &arg))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return fsact_del_recursive(arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_fs_Copy(){
|
||||||
|
char *left, *right;
|
||||||
|
|
||||||
|
if (parseStringInput(argv[0], &left))
|
||||||
|
return -1;
|
||||||
|
if (parseStringInput(argv[1], &right))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return fsact_copy(left, right, COPY_MODE_PRINT);
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_fs_CopyRecursive(){
|
||||||
|
char *left, *right;
|
||||||
|
|
||||||
|
if (parseStringInput(argv[0], &left))
|
||||||
|
return -1;
|
||||||
|
if (parseStringInput(argv[1], &right))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return fsact_copy_recursive(left, right);
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_fs_MakeDir(){
|
||||||
|
char *arg;
|
||||||
|
|
||||||
|
if (parseStringInput(argv[0], &arg))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
int res;
|
||||||
|
res = f_mkdir(arg);
|
||||||
|
if (res)
|
||||||
|
res = f_mkdir(arg);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
DIR dir;
|
||||||
|
FILINFO fno;
|
||||||
|
int isdirvalid = false;
|
||||||
|
int part_fs_OpenDir(){
|
||||||
|
char *path;
|
||||||
|
|
||||||
|
if (parseStringInput(argv[0], &path))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (f_opendir(&dir, path))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
isdirvalid = true;
|
||||||
|
str_int_add("@ISDIRVALID", isdirvalid);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_fs_CloseDir(){
|
||||||
|
if (!isdirvalid)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
f_closedir(&dir);
|
||||||
|
isdirvalid = false;
|
||||||
|
str_int_add("@ISDIRVALID", isdirvalid);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_fs_ReadDir(){
|
||||||
|
if (!isdirvalid)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (!f_readdir(&dir, &fno) && fno.fname[0]){
|
||||||
|
str_str_add("$FILENAME", fno.fname);
|
||||||
|
str_int_add("@ISDIR", (fno.fattrib & AM_DIR) ? 1 : 0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
part_fs_CloseDir();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_setPrintPos(){
|
||||||
|
int left, right;
|
||||||
|
|
||||||
|
if (parseIntInput(argv[0], &left))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (parseIntInput(argv[1], &right))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (left > 42)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (right > 78)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
gfx_con_setpos(left * 16, right * 16);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_stringcompare(){
|
||||||
|
char *left, *right;
|
||||||
|
|
||||||
|
if (parseStringInput(argv[0], &left))
|
||||||
|
return -1;
|
||||||
|
if (parseStringInput(argv[1], &right))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return (strcmp(left, right)) ? 0 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_fs_combinePath(){
|
||||||
|
char *combined, *left, *middle;
|
||||||
|
if (parseStringInput(argv[0], &left))
|
||||||
|
return -1;
|
||||||
|
if (parseStringInput(argv[1], &middle))
|
||||||
|
return -1;
|
||||||
|
if (argv[2][0] != '$')
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
combined = fsutil_getnextloc(left, middle);
|
||||||
|
|
||||||
|
str_str_add(argv[2], combined);
|
||||||
|
free(combined);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_mmc_dumpPart(){
|
||||||
|
char *left, *right;
|
||||||
|
|
||||||
|
if (parseStringInput(argv[0], &left))
|
||||||
|
return -1;
|
||||||
|
if (parseStringInput(argv[1], &right))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (!strcmp(left, "BOOT")){
|
||||||
|
return emmcDumpBoot(right);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return emmcDumpSpecific(left, right);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_mmc_restorePart(){
|
||||||
|
char *path;
|
||||||
|
|
||||||
|
if (parseStringInput(argv[0], &path))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (currentlyMounted < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return mmcFlashFile(path, currentlyMounted);
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_fs_extractBisFile(){
|
||||||
|
char *path, *outfolder;
|
||||||
|
|
||||||
|
if (parseStringInput(argv[0], &path))
|
||||||
|
return -1;
|
||||||
|
if (parseStringInput(argv[1], &outfolder))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return extract_bis_file(path, outfolder);
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_clearscreen(){
|
||||||
|
gfx_clearscreen();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int part_getPos(){
|
||||||
|
return (int)f_tell(&scriptin);
|
||||||
|
}
|
||||||
|
|
||||||
|
str_fnc_struct functions[] = {
|
||||||
|
{"printf", part_printf, 1},
|
||||||
|
{"printInt", part_print_int, 1},
|
||||||
|
{"setPrintPos", part_setPrintPos, 2},
|
||||||
|
{"clearscreen", part_clearscreen, 0},
|
||||||
|
{"if", part_if, 1},
|
||||||
|
{"if", part_if_args, 3}, // function overloading
|
||||||
|
{"math", part_Math, 3},
|
||||||
|
{"check", part_Check, 3},
|
||||||
|
{"setInt", part_SetInt, 1},
|
||||||
|
{"goto", part_goto, 1},
|
||||||
|
{"setString", part_SetString, 2},
|
||||||
|
{"setStringIndex", part_SetStringIndex, 2},
|
||||||
|
{"setColor", part_setColor, 1},
|
||||||
|
{"combineStrings", part_addstrings, 3},
|
||||||
|
{"compareStrings", part_stringcompare, 2},
|
||||||
|
{"invert", part_invert, 1},
|
||||||
|
{"fs_exists", part_fs_exists, 1},
|
||||||
|
{"fs_move", part_fs_Move, 2},
|
||||||
|
{"fs_mkdir", part_fs_MakeDir, 1},
|
||||||
|
{"fs_del", part_fs_Delete, 1},
|
||||||
|
{"fs_delRecursive", part_fs_DeleteRecursive, 1},
|
||||||
|
{"fs_copy", part_fs_Copy, 2},
|
||||||
|
{"fs_copyRecursive", part_fs_CopyRecursive, 2},
|
||||||
|
{"fs_openDir", part_fs_OpenDir, 1},
|
||||||
|
{"fs_closeDir", part_fs_CloseDir, 0},
|
||||||
|
{"fs_readDir", part_fs_ReadDir, 0},
|
||||||
|
{"fs_combinePath", part_fs_combinePath, 3},
|
||||||
|
{"fs_extractBisFile", part_fs_extractBisFile, 2},
|
||||||
|
{"mmc_connect", part_ConnectMMC, 1},
|
||||||
|
{"mmc_mount", part_MountMMC, 1},
|
||||||
|
{"mmc_dumpPart", part_mmc_dumpPart, 2},
|
||||||
|
{"mmc_restorePart", part_mmc_restorePart, 1},
|
||||||
|
{"getPosition", part_getPos, 0},
|
||||||
|
{"pause", part_Pause, 0},
|
||||||
|
{"wait", part_Wait, 1},
|
||||||
|
{"exit", part_Exit, 0},
|
||||||
|
{NULL, NULL, 0}
|
||||||
|
};
|
||||||
|
|
||||||
|
int run_function(char *func_name, int *out){
|
||||||
|
for (u32 i = 0; functions[i].key != NULL; i++){
|
||||||
|
if (!strcmp(functions[i].key, func_name)){
|
||||||
|
if (argc != functions[i].arg_count)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
*out = functions[i].value();
|
||||||
|
return (*out < 0) ? -1 : 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
13
source/tegraexplorer/script/functions.h
Normal file
13
source/tegraexplorer/script/functions.h
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "../../utils/types.h"
|
||||||
|
|
||||||
|
typedef void (*func_void_ptr)();
|
||||||
|
typedef int (*func_int_ptr)();
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char *key;
|
||||||
|
func_int_ptr value;
|
||||||
|
u8 arg_count;
|
||||||
|
} str_fnc_struct;
|
||||||
|
|
||||||
|
int run_function(char *func_name, int *out);
|
||||||
310
source/tegraexplorer/script/parser.c
Normal file
310
source/tegraexplorer/script/parser.c
Normal file
@@ -0,0 +1,310 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include "../../mem/heap.h"
|
||||||
|
#include "../gfx/gfxutils.h"
|
||||||
|
#include "../emmc/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 "parser.h"
|
||||||
|
#include "../common/common.h"
|
||||||
|
#include "../fs/fsactions.h"
|
||||||
|
#include "functions.h"
|
||||||
|
#include "variables.h"
|
||||||
|
#include "../fs/fsreader.h"
|
||||||
|
#include "../utils/utils.h"
|
||||||
|
|
||||||
|
u32 countchars(char* in, char target) {
|
||||||
|
u32 len = strlen(in);
|
||||||
|
u32 count = 0;
|
||||||
|
for (u32 i = 0; i < len; i++) {
|
||||||
|
if (in[i] == '"'){
|
||||||
|
i++;
|
||||||
|
while (in[i] != '"'){
|
||||||
|
i++;
|
||||||
|
if (i >= len)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (in[i] == target)
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
char **argv = NULL;
|
||||||
|
u32 argc;
|
||||||
|
u32 splitargs(char* in) {
|
||||||
|
// arg like '5, "6", @arg7'
|
||||||
|
u32 i, current = 0, count = 1, len = strlen(in), curcount = 0;
|
||||||
|
|
||||||
|
if ((count += countchars(in, ',')) < 0){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (argv != NULL) {
|
||||||
|
for (i = 0; argv[i] != NULL; i++)
|
||||||
|
free(argv[i]);
|
||||||
|
free(argv);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
argv = calloc(count + 1, sizeof(char*));
|
||||||
|
|
||||||
|
for (i = 0; i < count; i++)
|
||||||
|
argv[i] = calloc(128, sizeof(char));
|
||||||
|
|
||||||
|
|
||||||
|
for (i = 0; i < len && curcount < count; i++) {
|
||||||
|
if (in[i] == ',') {
|
||||||
|
curcount++;
|
||||||
|
current = 0;
|
||||||
|
}
|
||||||
|
else if (in[i] == '@' || in[i] == '$' || in[i] == '?') {
|
||||||
|
while (in[i] != ',' && in[i] != ' ' && in[i] != ')' && i < len) {
|
||||||
|
argv[curcount][current++] = in[i++];
|
||||||
|
}
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
else if ((in[i] >= '0' && in[i] <= '9') || (in[i] >= '<' && in[i] <= '>') || in[i] == '+' || in[i] == '-' || in[i] == '*' || in[i] == '/')
|
||||||
|
argv[curcount][current++] = in[i];
|
||||||
|
else if (in[i] == '"') {
|
||||||
|
i++;
|
||||||
|
while (in[i] != '"') {
|
||||||
|
argv[curcount][current++] = in[i++];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
FIL scriptin;
|
||||||
|
UINT endByte = 0;
|
||||||
|
int forceExit = false;
|
||||||
|
char currentchar = 0;
|
||||||
|
|
||||||
|
char getnextchar(){
|
||||||
|
f_read(&scriptin, ¤tchar, sizeof(char), &endByte);
|
||||||
|
|
||||||
|
if (sizeof(char) != endByte)
|
||||||
|
forceExit = true;
|
||||||
|
|
||||||
|
//gfx_printf("|%c|", currentchar);
|
||||||
|
return currentchar;
|
||||||
|
}
|
||||||
|
|
||||||
|
void getfollowingchar(char end){
|
||||||
|
while (currentchar != end && !f_eof(&scriptin)){
|
||||||
|
if (currentchar == '"'){
|
||||||
|
while (getnextchar() != '"' && !f_eof(&scriptin));
|
||||||
|
}
|
||||||
|
getnextchar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void getnextvalidchar(){
|
||||||
|
while ((!((currentchar >= '?' && currentchar <= 'Z') || (currentchar >= 'a' && currentchar <= 'z') || currentchar == '#') && !f_eof(&scriptin)) /*|| currentchar == ';' */)
|
||||||
|
getnextchar();
|
||||||
|
}
|
||||||
|
|
||||||
|
char *makestr(u32 size, char ignore){
|
||||||
|
char *str;
|
||||||
|
u32 count = 0;
|
||||||
|
|
||||||
|
str = calloc(size + 1, sizeof(char));
|
||||||
|
for (u32 i = 0; i < size; i++){
|
||||||
|
getnextchar();
|
||||||
|
if (ignore != 0 && ignore == currentchar)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
str[count++] = currentchar;
|
||||||
|
}
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *readtilchar(char end, char ignore){
|
||||||
|
FSIZE_t offset, size;
|
||||||
|
|
||||||
|
offset = f_tell(&scriptin);
|
||||||
|
getfollowingchar(end);
|
||||||
|
size = f_tell(&scriptin) - offset;
|
||||||
|
|
||||||
|
if (size <= 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
f_lseek(&scriptin, offset - 1);
|
||||||
|
|
||||||
|
return makestr((u32)size, ignore);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char *funcbuff = NULL;
|
||||||
|
void functionparser(){
|
||||||
|
char *unsplitargs;
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (funcbuff != NULL)
|
||||||
|
free(funcbuff);
|
||||||
|
*/
|
||||||
|
|
||||||
|
funcbuff = readtilchar('(', ' ');
|
||||||
|
|
||||||
|
getfollowingchar('(');
|
||||||
|
getnextchar();
|
||||||
|
|
||||||
|
unsplitargs = readtilchar(')', 0);
|
||||||
|
|
||||||
|
if (unsplitargs != NULL){
|
||||||
|
argc = splitargs(unsplitargs);
|
||||||
|
getnextchar();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
argc = 0;
|
||||||
|
}
|
||||||
|
getnextchar();
|
||||||
|
|
||||||
|
free(unsplitargs);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *gettargetvar(){
|
||||||
|
char *variable = NULL;
|
||||||
|
|
||||||
|
variable = readtilchar('=', ' ');
|
||||||
|
|
||||||
|
getfollowingchar('=');
|
||||||
|
getnextchar();
|
||||||
|
|
||||||
|
return variable;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mainparser(){
|
||||||
|
char *variable = NULL;
|
||||||
|
int res, out = 0;
|
||||||
|
|
||||||
|
getnextvalidchar();
|
||||||
|
|
||||||
|
if (f_eof(&scriptin))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (currentchar == '#'){
|
||||||
|
getfollowingchar('\n');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentchar == '@'){
|
||||||
|
variable = gettargetvar();
|
||||||
|
getnextvalidchar();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (currentchar == '?'){
|
||||||
|
char *jumpname;
|
||||||
|
jumpname = readtilchar(';', ' ');
|
||||||
|
getnextchar();
|
||||||
|
str_jmp_add(jumpname, f_tell(&scriptin));
|
||||||
|
getfollowingchar('\n');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
functionparser();
|
||||||
|
|
||||||
|
res = run_function(funcbuff, &out);
|
||||||
|
if (res < 0){
|
||||||
|
printerrors = true;
|
||||||
|
//gfx_printf("%s|%s|%d", funcbuff, argv[0], argc);
|
||||||
|
//btn_wait();
|
||||||
|
gfx_errDisplay("mainparser", ERR_PARSE_FAIL, f_tell(&scriptin));
|
||||||
|
forceExit = true;
|
||||||
|
//gfx_printf("Func: %s\nArg1: %s\n", funcbuff, argv[0]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
str_int_add("@RESULT", out);
|
||||||
|
|
||||||
|
if (variable != NULL)
|
||||||
|
str_int_add(variable, out);
|
||||||
|
}
|
||||||
|
|
||||||
|
//gfx_printf("\nGoing to next func %c\n", currentchar);
|
||||||
|
|
||||||
|
if (funcbuff != NULL){
|
||||||
|
free(funcbuff);
|
||||||
|
funcbuff = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argv != NULL) {
|
||||||
|
for (int i = 0; argv[i] != NULL; i++)
|
||||||
|
free(argv[i]);
|
||||||
|
free(argv);
|
||||||
|
argv = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (variable != NULL){
|
||||||
|
free(variable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void skipbrackets(){
|
||||||
|
u32 bracketcounter = 0;
|
||||||
|
|
||||||
|
getfollowingchar('{');
|
||||||
|
getnextchar();
|
||||||
|
|
||||||
|
while ((currentchar != '}' || bracketcounter != 0) && !f_eof(&scriptin)){
|
||||||
|
if (currentchar == '{')
|
||||||
|
bracketcounter++;
|
||||||
|
else if (currentchar == '}')
|
||||||
|
bracketcounter--;
|
||||||
|
|
||||||
|
getnextchar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extern u32 currentcolor;
|
||||||
|
extern char *currentpath;
|
||||||
|
void runScript(char *path){
|
||||||
|
int res;
|
||||||
|
char *path_local = NULL;
|
||||||
|
forceExit = false;
|
||||||
|
currentchar = 0;
|
||||||
|
currentcolor = COLOR_WHITE;
|
||||||
|
gfx_clearscreen();
|
||||||
|
utils_copystring(path, &path_local);
|
||||||
|
|
||||||
|
res = f_open(&scriptin, path, FA_READ | FA_OPEN_EXISTING);
|
||||||
|
if (res != FR_OK){
|
||||||
|
gfx_errDisplay("ParseScript", res, 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
printerrors = false;
|
||||||
|
|
||||||
|
//add builtin vars
|
||||||
|
str_int_add("@EMUMMC", emu_cfg.enabled);
|
||||||
|
str_int_add("@RESULT", 0);
|
||||||
|
str_int_add("@BTN_POWER", 0);
|
||||||
|
str_int_add("@BTN_VOL+", 0);
|
||||||
|
str_int_add("@BTN_VOL-", 0);
|
||||||
|
str_str_add("$CURRENTPATH", currentpath);
|
||||||
|
|
||||||
|
//str_int_printall();
|
||||||
|
|
||||||
|
while (!f_eof(&scriptin) && !forceExit){
|
||||||
|
mainparser();
|
||||||
|
}
|
||||||
|
|
||||||
|
printerrors = true;
|
||||||
|
//str_int_printall();
|
||||||
|
|
||||||
|
f_close(&scriptin);
|
||||||
|
str_int_clear();
|
||||||
|
//str_jmp_clear();
|
||||||
|
str_str_clear();
|
||||||
|
free(path_local);
|
||||||
|
//btn_wait();
|
||||||
|
}
|
||||||
5
source/tegraexplorer/script/parser.h
Normal file
5
source/tegraexplorer/script/parser.h
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
void runScript(char *path);
|
||||||
|
void skipbrackets();
|
||||||
|
void getfollowingchar(char end);
|
||||||
250
source/tegraexplorer/script/variables.c
Normal file
250
source/tegraexplorer/script/variables.c
Normal file
@@ -0,0 +1,250 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include "../../mem/heap.h"
|
||||||
|
#include "../gfx/gfxutils.h"
|
||||||
|
#include "../emmc/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 "parser.h"
|
||||||
|
#include "../common/common.h"
|
||||||
|
#include "../fs/fsactions.h"
|
||||||
|
#include "variables.h"
|
||||||
|
#include "../utils/utils.h"
|
||||||
|
|
||||||
|
static dict_str_int *str_int_table = NULL;
|
||||||
|
static dict_str_str *str_str_table = NULL;
|
||||||
|
//static dict_str_loc *str_jmp_table = NULL;
|
||||||
|
|
||||||
|
int str_int_add(char *key, int value){
|
||||||
|
char *key_local;
|
||||||
|
dict_str_int *keyvaluepair;
|
||||||
|
|
||||||
|
utils_copystring(key, &key_local);
|
||||||
|
|
||||||
|
keyvaluepair = calloc(1, sizeof(dict_str_int));
|
||||||
|
keyvaluepair->key = key_local;
|
||||||
|
keyvaluepair->value = value;
|
||||||
|
keyvaluepair->next = NULL;
|
||||||
|
|
||||||
|
if (str_int_table == NULL){
|
||||||
|
str_int_table = keyvaluepair;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dict_str_int *temp;
|
||||||
|
temp = str_int_table;
|
||||||
|
while (temp != NULL){
|
||||||
|
if (!strcmp(temp->key, key_local)){
|
||||||
|
free(keyvaluepair);
|
||||||
|
free(key_local);
|
||||||
|
temp->value = value;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (temp->next == NULL){
|
||||||
|
temp->next = keyvaluepair;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
temp = temp->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int str_int_find(char *key, int *out){
|
||||||
|
dict_str_int *temp;
|
||||||
|
temp = str_int_table;
|
||||||
|
while (temp != NULL){
|
||||||
|
if (!strcmp(temp->key, key)){
|
||||||
|
*out = temp->value;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
temp = temp->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void str_int_clear(){
|
||||||
|
dict_str_int *cur, *next;
|
||||||
|
cur = str_int_table;
|
||||||
|
|
||||||
|
while (cur != NULL){
|
||||||
|
next = cur->next;
|
||||||
|
free(cur->key);
|
||||||
|
free(cur);
|
||||||
|
cur = next;
|
||||||
|
}
|
||||||
|
str_int_table = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void str_int_printall(){
|
||||||
|
dict_str_int *temp;
|
||||||
|
temp = str_int_table;
|
||||||
|
while (temp != NULL){
|
||||||
|
gfx_printf("%s -> %d\n", temp->key, temp->value);
|
||||||
|
temp = temp->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
int str_jmp_add(char *key, u64 value){
|
||||||
|
char *key_local;
|
||||||
|
dict_str_loc *keyvaluepair;
|
||||||
|
|
||||||
|
//gfx_printf("Adding |%s|\n", key_local);
|
||||||
|
|
||||||
|
utils_copystring(key, &key_local);
|
||||||
|
|
||||||
|
keyvaluepair = calloc(1, sizeof(dict_str_loc));
|
||||||
|
keyvaluepair->key = key_local;
|
||||||
|
keyvaluepair->value = value;
|
||||||
|
keyvaluepair->next = NULL;
|
||||||
|
|
||||||
|
if (str_jmp_table == NULL){
|
||||||
|
str_jmp_table = keyvaluepair;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dict_str_loc *temp;
|
||||||
|
temp = str_jmp_table;
|
||||||
|
while (temp != NULL){
|
||||||
|
if (!strcmp(temp->key, key_local)){
|
||||||
|
free(keyvaluepair);
|
||||||
|
free(key_local);
|
||||||
|
|
||||||
|
temp->value = value;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (temp->next == NULL){
|
||||||
|
temp->next = keyvaluepair;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
temp = temp->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int str_jmp_find(char *key, u64 *out){
|
||||||
|
dict_str_loc *temp;
|
||||||
|
temp = str_jmp_table;
|
||||||
|
//gfx_printf("Searching |%s|\n", key);
|
||||||
|
while (temp != NULL){
|
||||||
|
if (!strcmp(temp->key, key)){
|
||||||
|
//gfx_printf("Key found!\n", temp->value);
|
||||||
|
*out = temp->value;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
temp = temp->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
//gfx_printf("no key!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void str_jmp_clear(){
|
||||||
|
dict_str_loc *cur, *next;
|
||||||
|
cur = str_jmp_table;
|
||||||
|
|
||||||
|
while (cur != NULL){
|
||||||
|
next = cur->next;
|
||||||
|
free(cur->key);
|
||||||
|
free(cur);
|
||||||
|
cur = next;
|
||||||
|
}
|
||||||
|
str_jmp_table = NULL;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
int str_str_add(char *key, char *value){
|
||||||
|
char *key_local, *value_local;
|
||||||
|
dict_str_str *keyvaluepair;
|
||||||
|
//gfx_printf("Adding |%s|\n", key_local);
|
||||||
|
utils_copystring(value, &value_local);
|
||||||
|
utils_copystring(key, &key_local);
|
||||||
|
|
||||||
|
keyvaluepair = calloc(1, sizeof(dict_str_str));
|
||||||
|
keyvaluepair->key = key_local;
|
||||||
|
keyvaluepair->value = value_local;
|
||||||
|
keyvaluepair->next = NULL;
|
||||||
|
|
||||||
|
if (str_str_table == NULL){
|
||||||
|
str_str_table = keyvaluepair;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dict_str_str *temp;
|
||||||
|
temp = str_str_table;
|
||||||
|
while (temp != NULL){
|
||||||
|
if (!strcmp(temp->key, key_local)){
|
||||||
|
free(keyvaluepair);
|
||||||
|
free(key_local);
|
||||||
|
|
||||||
|
free(temp->value);
|
||||||
|
temp->value = value_local;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (temp->next == NULL){
|
||||||
|
temp->next = keyvaluepair;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
temp = temp->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int str_str_find(char *key, char **out){
|
||||||
|
dict_str_str *temp;
|
||||||
|
temp = str_str_table;
|
||||||
|
|
||||||
|
while (temp != NULL){
|
||||||
|
if (!strcmp(temp->key, key)){
|
||||||
|
*out = temp->value;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
temp = temp->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int str_str_index(int index, char **out){
|
||||||
|
dict_str_str *temp;
|
||||||
|
temp = str_str_table;
|
||||||
|
|
||||||
|
for (int i = 0; i < index; i++){
|
||||||
|
if (temp == NULL)
|
||||||
|
return -1;
|
||||||
|
temp = temp->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (temp == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
*out = temp->value;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void str_str_clear(){
|
||||||
|
dict_str_str *cur, *next;
|
||||||
|
cur = str_str_table;
|
||||||
|
|
||||||
|
while (cur != NULL){
|
||||||
|
next = cur->next;
|
||||||
|
free(cur->key);
|
||||||
|
free(cur->value);
|
||||||
|
free(cur);
|
||||||
|
cur = next;
|
||||||
|
}
|
||||||
|
str_str_table = NULL;
|
||||||
|
}
|
||||||
34
source/tegraexplorer/script/variables.h
Normal file
34
source/tegraexplorer/script/variables.h
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "../../utils/types.h"
|
||||||
|
|
||||||
|
typedef struct _dict_str_int {
|
||||||
|
char *key;
|
||||||
|
int value;
|
||||||
|
struct _dict_str_int *next;
|
||||||
|
} dict_str_int;
|
||||||
|
|
||||||
|
typedef struct _dict_str_str {
|
||||||
|
char *key;
|
||||||
|
char *value;
|
||||||
|
struct _dict_str_str *next;
|
||||||
|
} dict_str_str;
|
||||||
|
|
||||||
|
typedef struct _dict_str_loc {
|
||||||
|
char *key;
|
||||||
|
u64 value;
|
||||||
|
struct _dict_str_loc *next;
|
||||||
|
} dict_str_loc;
|
||||||
|
|
||||||
|
int str_int_add(char *key, int value);
|
||||||
|
int str_int_find(char *key, int *out);
|
||||||
|
void str_int_clear();
|
||||||
|
void str_int_printall();
|
||||||
|
/*
|
||||||
|
int str_jmp_add(char *key, u64 value);
|
||||||
|
int str_jmp_find(char *key, u64 *out);
|
||||||
|
void str_jmp_clear();
|
||||||
|
*/
|
||||||
|
int str_str_add(char *key, char *value);
|
||||||
|
int str_str_find(char *key, char **out);
|
||||||
|
int str_str_index(int index, char **out);
|
||||||
|
void str_str_clear();
|
||||||
@@ -1,192 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "te.h"
|
|
||||||
#include "gfx.h"
|
|
||||||
#include "../utils/util.h"
|
|
||||||
#include "tools.h"
|
|
||||||
#include "fs.h"
|
|
||||||
#include "../utils/btn.h"
|
|
||||||
#include "emmc.h"
|
|
||||||
|
|
||||||
extern bool sd_mount();
|
|
||||||
extern void sd_unmount();
|
|
||||||
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},
|
|
||||||
{"\nMount/Unmount SD", COLOR_WHITE, MOUNT_SD, 1},
|
|
||||||
{"Tools", COLOR_VIOLET, TOOLS, 1},
|
|
||||||
{"SD format", COLOR_VIOLET, SD_FORMAT, 1},
|
|
||||||
{"\nCredits", COLOR_WHITE, CREDITS, 1},
|
|
||||||
{"Exit", COLOR_WHITE, EXIT, 1}
|
|
||||||
};
|
|
||||||
|
|
||||||
menu_item shutdownmenu[7] = {
|
|
||||||
{"-- EXIT --\n", COLOR_ORANGE, -1, 0},
|
|
||||||
{"Back", COLOR_WHITE, -1, 1},
|
|
||||||
{"\nReboot to RCM", COLOR_VIOLET, REBOOT_RCM, 1},
|
|
||||||
{"Reboot normally", COLOR_ORANGE, REBOOT_NORMAL, 1},
|
|
||||||
{"Power off\n", COLOR_BLUE, POWER_OFF, 1},
|
|
||||||
{"Reboot to Hekate", COLOR_GREEN, HEKATE, -1},
|
|
||||||
{"Reboot to Atmosphere", COLOR_GREEN, AMS, -1}
|
|
||||||
};
|
|
||||||
|
|
||||||
menu_item toolsmenu[5] = {
|
|
||||||
{"-- 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}
|
|
||||||
};
|
|
||||||
|
|
||||||
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}
|
|
||||||
};
|
|
||||||
|
|
||||||
void fillmainmenu(){
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < MAINMENU_AMOUNT; i++){
|
|
||||||
switch (i + 1) {
|
|
||||||
case 1:
|
|
||||||
if (sd_mounted)
|
|
||||||
mainmenu[i].property = 1;
|
|
||||||
else
|
|
||||||
mainmenu[i].property = -1;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
if (sd_mounted){
|
|
||||||
mainmenu[i].property = 2;
|
|
||||||
strcpy(mainmenu[i].name, "\nUnmount SD");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
mainmenu[i].property = 1;
|
|
||||||
strcpy(mainmenu[i].name, "\nMount SD");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
if (sd_mounted)
|
|
||||||
mainmenu[i].property = 1;
|
|
||||||
else
|
|
||||||
mainmenu[i].property = -1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void te_main(){
|
|
||||||
int res;
|
|
||||||
|
|
||||||
dump_biskeys();
|
|
||||||
mount_emmc("SYSTEM", 2);
|
|
||||||
|
|
||||||
sd_mounted = sd_mount();
|
|
||||||
|
|
||||||
while (1){
|
|
||||||
fillmainmenu();
|
|
||||||
res = makemenu(mainmenu, MAINMENU_AMOUNT);
|
|
||||||
|
|
||||||
switch(res){
|
|
||||||
case SD_CARD:
|
|
||||||
filemenu("SD:/");
|
|
||||||
break;
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
sd_mounted = sd_mount();
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TOOLS:
|
|
||||||
res = makemenu(toolsmenu, 5);
|
|
||||||
|
|
||||||
switch(res){
|
|
||||||
case DISPLAY_INFO:
|
|
||||||
displayinfo();
|
|
||||||
break;
|
|
||||||
case DISPLAY_GPIO:
|
|
||||||
displaygpio();
|
|
||||||
break;
|
|
||||||
case DUMPFIRMWARE:
|
|
||||||
dumpfirmware();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SD_FORMAT:
|
|
||||||
res = makemenu(formatmenu, 4);
|
|
||||||
|
|
||||||
switch(res){
|
|
||||||
case FORMAT_ALL_FAT32:
|
|
||||||
if (makewaitmenu("Are you sure you want to format your sd?\nThis action is irreversible!\n\nPress Vol+/- to cancel\n", "Press Power to continue", 10))
|
|
||||||
format(1);
|
|
||||||
break;
|
|
||||||
case FORMAT_EMUMMC:
|
|
||||||
if (makewaitmenu("Are you sure you want to format your sd?\nThis action is irreversible!\n\nPress Vol+/- to cancel\n", "Press Power to continue", 10))
|
|
||||||
format(0);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CREDITS:
|
|
||||||
message(CREDITS_MESSAGE, COLOR_WHITE);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case EXIT:
|
|
||||||
if (sd_mounted){
|
|
||||||
if (checkfile("/bootloader/update.bin"))
|
|
||||||
shutdownmenu[5].property = 1;
|
|
||||||
else
|
|
||||||
shutdownmenu[5].property = -1;
|
|
||||||
|
|
||||||
if (checkfile("/atmosphere/reboot_payload.bin"))
|
|
||||||
shutdownmenu[6].property = 1;
|
|
||||||
else
|
|
||||||
shutdownmenu[6].property = -1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
shutdownmenu[5].property = -1;
|
|
||||||
shutdownmenu[6].property = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
res = makemenu(shutdownmenu, 7);
|
|
||||||
|
|
||||||
switch(res){
|
|
||||||
case REBOOT_RCM:
|
|
||||||
reboot_rcm();
|
|
||||||
|
|
||||||
case REBOOT_NORMAL:
|
|
||||||
reboot_normal();
|
|
||||||
|
|
||||||
case POWER_OFF:
|
|
||||||
power_off();
|
|
||||||
|
|
||||||
case HEKATE:
|
|
||||||
launch_payload("/bootloader/update.bin");
|
|
||||||
|
|
||||||
case AMS:
|
|
||||||
launch_payload("/atmosphere/reboot_payload.bin");
|
|
||||||
} //todo declock bpmp
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
void displayinfo();
|
|
||||||
void displaygpio();
|
|
||||||
void format(int mode);
|
|
||||||
int dumpfirmware();
|
|
||||||
@@ -1,32 +1,48 @@
|
|||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
#include "gfx.h"
|
#include "../gfx/gfxutils.h"
|
||||||
#include "../libs/fatfs/ff.h"
|
#include "../../libs/fatfs/ff.h"
|
||||||
#include "../gfx/gfx.h"
|
#include "../../gfx/gfx.h"
|
||||||
#include "../utils/btn.h"
|
#include "../../utils/btn.h"
|
||||||
#include "../soc/gpio.h"
|
#include "../../soc/gpio.h"
|
||||||
#include "../utils/util.h"
|
#include "../../utils/util.h"
|
||||||
#include "../utils/types.h"
|
#include "../../utils/types.h"
|
||||||
#include "../libs/fatfs/diskio.h"
|
#include "../../libs/fatfs/diskio.h"
|
||||||
#include "../storage/sdmmc.h"
|
#include "../../storage/sdmmc.h"
|
||||||
#include "../utils/sprintf.h"
|
#include "../../utils/sprintf.h"
|
||||||
#include "emmc.h"
|
#include "../../soc/fuse.h"
|
||||||
#include "fs.h"
|
#include "../emmc/emmc.h"
|
||||||
|
#include "../common/common.h"
|
||||||
|
#include "../fs/fsactions.h"
|
||||||
|
|
||||||
extern bool sd_mount();
|
extern bool sd_mount();
|
||||||
extern void sd_unmount();
|
extern void sd_unmount();
|
||||||
extern sdmmc_storage_t sd_storage;
|
extern sdmmc_storage_t sd_storage;
|
||||||
|
|
||||||
void displayinfo(){
|
void displayinfo(){
|
||||||
clearscreen();
|
gfx_clearscreen();
|
||||||
|
|
||||||
FATFS *fs;
|
FATFS *fs;
|
||||||
DWORD fre_clust, fre_sect, tot_sect;
|
DWORD fre_clust, fre_sect, tot_sect;
|
||||||
u32 capacity;
|
u32 capacity;
|
||||||
|
u8 fuse_count = 0;
|
||||||
|
pkg1_info pkg1 = returnpkg1info();
|
||||||
int res;
|
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\nPKG1 id: %s\n\n", fuse_count, pkg1.ver, pkg1.id);
|
||||||
print_biskeys();
|
print_biskeys();
|
||||||
|
|
||||||
|
RESETCOLOR;
|
||||||
|
gfx_printf("\n-----\n\n");
|
||||||
|
|
||||||
|
SWAPCOLOR(COLOR_BLUE);
|
||||||
|
|
||||||
if (!sd_mount()){
|
if (!sd_mount()){
|
||||||
gfx_printf("SD mount failed!\nFailed to display SD info\n");
|
gfx_printf("SD mount failed!\nFailed to display SD info\n");
|
||||||
}
|
}
|
||||||
@@ -44,14 +60,15 @@ 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);
|
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");
|
gfx_printf("Press any key to continue");
|
||||||
btn_wait();
|
btn_wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
void displaygpio(){
|
void displaygpio(){
|
||||||
int res;
|
int res;
|
||||||
clearscreen();
|
gfx_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);
|
msleep(200);
|
||||||
while (1){
|
while (1){
|
||||||
msleep(10);
|
msleep(10);
|
||||||
@@ -69,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;
|
||||||
@@ -78,20 +95,22 @@ 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();
|
gfx_clearscreen();
|
||||||
|
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 making sd:/tegraexplorer %d\n", ret);
|
gfx_printf("Creating sd:/tegraexplorer %d\n", ret);
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
@@ -106,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 = fsact_copy(syspath, sdpath, 0);
|
||||||
|
|
||||||
gfx_printf("%d %s\r", ++amount, fno.fname);
|
gfx_printf("%d %s\r", ++amount, fno.fname);
|
||||||
|
|
||||||
@@ -124,32 +143,63 @@ int dumpfirmware(){
|
|||||||
return fail;
|
return fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
void format(int mode){
|
void dumpusersaves(int mmc){
|
||||||
clearscreen();
|
int res;
|
||||||
|
|
||||||
|
connect_mmc(mmc);
|
||||||
|
mount_mmc("USER", 2);
|
||||||
|
gfx_clearscreen();
|
||||||
|
|
||||||
|
res = f_mkdir("sd:/tegraexplorer");
|
||||||
|
gfx_printf("Creating sd:/tegraexplorer, res: %d\nCopying:\n", res);
|
||||||
|
|
||||||
|
SWAPCOLOR(COLOR_GREEN);
|
||||||
|
|
||||||
|
res = fsact_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){
|
||||||
|
gfx_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 = 16 * 512;
|
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;
|
||||||
|
|
||||||
if (mode == 0){
|
if (mode == FORMAT_EMUMMC){
|
||||||
if (totalsectors < 61145088){
|
if (totalsectors < 83886080){
|
||||||
gfx_printf("%k\nNot enough free space for emummc!", COLOR_RED);
|
gfx_printf("%kYou seem to be running this on a <=32GB SD\nNot enough free space for emummc!", COLOR_RED);
|
||||||
fatalerror = true;
|
fatalerror = true;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
if (!fatalerror){
|
totalsectors -= plist[1];
|
||||||
plist[0] = totalsectors - 61145088;
|
alignedsectors = (totalsectors / 2048) * 2048;
|
||||||
gfx_printf("\nStarting SD partitioning:\nTotalSectors: %d\nPartition1 (SD): %d\nPartition2 (EMUMMC): %d\n", totalsectors, plist[0], plist[1]);
|
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 {
|
||||||
@@ -191,9 +241,9 @@ void 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();
|
||||||
|
return fatalerror;
|
||||||
}
|
}
|
||||||
7
source/tegraexplorer/utils/tools.h
Normal file
7
source/tegraexplorer/utils/tools.h
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
void displayinfo();
|
||||||
|
void displaygpio();
|
||||||
|
int format(int mode);
|
||||||
|
int dumpfirmware(int mmc);
|
||||||
|
void dumpusersaves(int mmc);
|
||||||
19
source/tegraexplorer/utils/utils.c
Normal file
19
source/tegraexplorer/utils/utils.c
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include "utils.h"
|
||||||
|
#include "../common/common.h"
|
||||||
|
#include "../gfx/menu.h"
|
||||||
|
#include "../../storage/emummc.h"
|
||||||
|
#include "../../mem/heap.h"
|
||||||
|
|
||||||
|
int utils_mmcMenu(){
|
||||||
|
if (emu_cfg.enabled)
|
||||||
|
return menu_make(utils_mmcChoice, 3, "-- Choose MMC --");
|
||||||
|
else
|
||||||
|
return SYSMMC;
|
||||||
|
}
|
||||||
|
|
||||||
|
void utils_copystring(const char *in, char **out){
|
||||||
|
int len = strlen(in) + 1;
|
||||||
|
*out = (char *) malloc (len);
|
||||||
|
strcpy(*out, in);
|
||||||
|
}
|
||||||
4
source/tegraexplorer/utils/utils.h
Normal file
4
source/tegraexplorer/utils/utils.h
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
int utils_mmcMenu();
|
||||||
|
void utils_copystring(const char *in, char **out);
|
||||||
Reference in New Issue
Block a user