Skip to content

Commit 7b273b7

Browse files
committed
tegraex
1 parent a31b4d2 commit 7b273b7

33 files changed

+765
-531
lines changed

Hakupayload/source/tegraexplorer/common/common.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ enum utils_err_codes_te_call {
2121
ERR_EMMC_WRITE_FAILED,
2222
ERR_FILE_TOO_BIG_FOR_DEST,
2323
ERR_SD_EJECTED,
24-
ERR_PARSE_FAIL,
24+
ERR_SCRIPT_LOOKUP_FAIL,
2525
ERR_CANNOT_COPY_FILE_TO_FS_PART,
26-
ERR_NO_DESTINATION
26+
ERR_NO_DESTINATION,
27+
ERR_INI_PARSE_FAIL,
28+
ERR_IN_FUNC
2729
};
2830

2931
extern const char *utils_err_codes_te[];
@@ -58,8 +60,7 @@ extern menu_entry mainmenu_shutdown[];
5860
enum mainmenu_tools_return {
5961
TOOLS_DISPLAY_INFO = 1,
6062
TOOLS_DISPLAY_GPIO,
61-
TOOLS_DUMPFIRMWARE,
62-
TOOLS_DUMPUSERSAVE
63+
TOOLS_DUMPFIRMWARE
6364
};
6465

6566
extern menu_entry mainmenu_tools[];
@@ -86,7 +87,8 @@ enum fs_menu_file_return {
8687
FILE_PAYLOAD,
8788
FILE_SCRIPT,
8889
FILE_HEXVIEW,
89-
FILE_DUMPBIS
90+
FILE_DUMPBIS,
91+
FILE_SIGN
9092
};
9193

9294
extern menu_entry fs_menu_file[];

Hakupayload/source/tegraexplorer/common/strings.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ const char *utils_err_codes_te[] = { // these start at 50
5050
"EMMC WRITE FAILED",
5151
"FILE TOO BIG FOR DEST",
5252
"SD EJECTED",
53-
"PARSING FAILED",
53+
"FUNC LOOKUP FAIL",
5454
"CANNOT COPY FILE TO FS PART",
55-
"NO DESTINATION"
55+
"NO DESTINATION",
56+
"INI PARSE FAIL",
57+
"ERR IN FUNC"
5658
};
5759
/*
5860
const char *pkg2names[] = {

Hakupayload/source/tegraexplorer/common/structs.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ menu_entry fs_menu_file[] = {
5353
{"Lanzar Payload", COLOR_ORANGE, ISMENU},
5454
{"Lanzar Script", COLOR_YELLOW, ISMENU},
5555
{"Visor Hex", COLOR_GREEN, ISMENU},
56-
{"\nExtraer BIS", COLOR_YELLOW, ISMENU}
56+
{"\nExtraer BIS", COLOR_YELLOW, ISMENU},
57+
{"Sign Save", COLOR_ORANGE, {ISMENU}}
58+
5759
};
5860

5961
menu_entry fs_menu_folder[] = {

Hakupayload/source/tegraexplorer/common/types.h

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
#pragma once
22
#include "../../utils/types.h"
33

4-
#define ISDIR (1 << 0)
5-
#define ISARC (1 << 1)
4+
#define BIT(n) (1U << n)
65

7-
#define ISHIDE (1 << 8)
8-
#define ISMENU (1 << 9)
9-
#define ISSKIP (1 << 10)
10-
11-
#define ISGB (1 << 7)
12-
#define ISMB (1 << 6)
13-
#define ISKB (1 << 5)
14-
#define ISB (1 << 4)
15-
#define ISNULL (1 << 3)
6+
#define ISDIR BIT(0)
7+
#define ISMENU BIT(1)
8+
#define SETSIZE(x) (x << 2)
9+
#define ISNULL BIT(4)
10+
#define ISHIDE BIT(5)
11+
#define ISSKIP BIT(6)
1612

1713
#define SETBIT(object, shift, value) ((value) ? (object |= shift) : (object &= ~shift))
1814

@@ -27,7 +23,7 @@
2723

2824
#define COPY_MODE_PRINT 0x1
2925
#define COPY_MODE_CANCEL 0x2
30-
#define BUFSIZE 32768
26+
#define BUFSIZE 65536 //32768
3127

3228
#define OPERATIONCOPY 0x2
3329
#define OPERATIONMOVE 0x4
@@ -43,7 +39,17 @@
4339
typedef struct {
4440
char *name;
4541
u32 storage;
46-
u16 property;
42+
union {
43+
u8 property;
44+
struct {
45+
u8 isDir:1;
46+
u8 isMenu:1;
47+
u8 size:2;
48+
u8 isNull:1;
49+
u8 isHide:1;
50+
u8 isSkip:1;
51+
};
52+
};
4753
} menu_entry;
4854

4955
typedef struct {

Hakupayload/source/tegraexplorer/emmc/emmcdumppart.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ int emmcDumpPart(char *path, sdmmc_storage_t *mmcstorage, emmc_part_t *part){
4545
f_lseek(&fp, 0);
4646

4747
while (totalSectors > 0){
48-
num = MIN(totalSectors, 64);
48+
num = MIN(totalSectors, 128);
4949
if (!emummc_storage_read(mmcstorage, lba_curr, num, buf)){
5050
gfx_errDisplay("dump_emmc_part", ERR_EMMC_READ_FAILED, 3);
5151
return -1;

Hakupayload/source/tegraexplorer/emmc/emmcmenu.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
#include "../../utils/list.h"
1717
#include "../../mem/heap.h"
1818
#include "emmcmenu.h"
19-
#include "../fs/fsreader.h"
2019
#include "../utils/utils.h"
2120
#include "../gfx/menu.h"
2221
#include "../fs/fsmenu.h"
2322
#include "emmcoperations.h"
2423
#include "../fs/fsutils.h"
24+
#include "../utils/menuUtils.h"
2525

2626
menu_entry *mmcMenuEntries = NULL;
2727
extern sdmmc_storage_t storage;
@@ -30,21 +30,18 @@ extern char *clipboard;
3030
extern u8 clipboardhelper;
3131

3232

33-
void addEntry(emmc_part_t *part, u8 property, int spot){
34-
if (mmcMenuEntries[spot].name != NULL){
35-
free(mmcMenuEntries[spot].name);
36-
}
37-
38-
utils_copystring(part->name, &mmcMenuEntries[spot].name);
33+
void addEntry(emmc_part_t *part, u8 property_GPT, int spot){
34+
u32 storage = 0;
35+
u8 property = 0;
3936

40-
if (property & isFS){
41-
mmcMenuEntries[spot].storage = (u32)(property & 0x7F);
42-
mmcMenuEntries[spot].property = ISDIR;
37+
if (property_GPT & isFS){
38+
storage = (u32)(property_GPT & 0x7F);
39+
property = ISDIR;
4340
}
4441
else {
4542
u64 size = 0;
46-
int sizes = 0;
47-
mmcMenuEntries[spot].property = 0;
43+
u32 sizes = 0;
44+
4845
size = (u64)(part->lba_end + 1 - part->lba_start);
4946
size *= (u64)NX_EMMC_BLOCKSIZE;
5047

@@ -54,31 +51,30 @@ void addEntry(emmc_part_t *part, u8 property, int spot){
5451
}
5552

5653
if (sizes > 3)
57-
sizes = 0;
54+
sizes = 3;
5855

59-
mmcMenuEntries[spot].property |= (1 << (4 + sizes));
60-
mmcMenuEntries[spot].storage = (u32)size;
56+
property |= SETSIZE(sizes);
57+
storage = (u32)size;
6158
}
59+
60+
mu_copySingle(part->name, storage, property, &mmcMenuEntries[spot]);
6261
}
6362

6463
int fillMmcMenu(short mmcType){
6564
int count = 4, i;
6665

6766
if (mmcMenuEntries != NULL)
68-
clearfileobjects(&mmcMenuEntries);
67+
mu_clearObjects(&mmcMenuEntries);
6968

7069
link_t *gpt = selectGpt(mmcType);
7170

7271
LIST_FOREACH_ENTRY(emmc_part_t, part, gpt, link)
7372
count++;
7473

75-
createfileobjects(count, &mmcMenuEntries);
74+
mu_createObjects(count, &mmcMenuEntries);
7675

77-
for (i = 0; i < 4; i++){
78-
utils_copystring(mmcmenu_start[i].name, &mmcMenuEntries[i].name);
79-
mmcMenuEntries[i].property = mmcmenu_start[i].property;
80-
mmcMenuEntries[i].storage = mmcmenu_start[i].storage;
81-
}
76+
for (i = 0; i < 4; i++)
77+
mu_copySingle(mmcmenu_start[i].name, mmcmenu_start[i].storage, mmcmenu_start[i].property, &mmcMenuEntries[i]);
8278

8379
LIST_FOREACH_ENTRY(emmc_part_t, part, gpt, link){
8480
addEntry(part, checkGptRules(part->name), i++);
@@ -99,10 +95,14 @@ int handleEntries(short mmcType, menu_entry part){
9995
fileexplorer("emmc:/", 1);
10096
}
10197
else {
98+
/*
10299
if (mmcmenu_filemenu[1].name != NULL)
103100
free(mmcmenu_filemenu[1].name);
104101
105102
utils_copystring(part.name, &mmcmenu_filemenu[1].name);
103+
*/
104+
105+
mu_copySingle(part.name, mmcmenu_filemenu[1].storage, mmcmenu_filemenu[1].property, &mmcmenu_filemenu[1]);
106106

107107
if ((menu_make(mmcmenu_filemenu, 4, "-- RAW PARTITION --")) < 3)
108108
return 0;
@@ -112,7 +112,7 @@ int handleEntries(short mmcType, menu_entry part){
112112

113113
gfx_clearscreen();
114114

115-
if (part.property & isBOOT){
115+
if (part.isNull){
116116
res = emmcDumpBoot("sd:/tegraexplorer/partition_dumps");
117117
}
118118
else {
@@ -146,7 +146,7 @@ int makeMmcMenu(short mmcType){
146146
f_mkdir("sd:/tegraexplorer/partition_dumps");
147147

148148
for (int i = 0; i < count; i++){
149-
if (mmcMenuEntries[i].property & ISMENU || mmcMenuEntries[i].property & ISDIR)
149+
if (mmcMenuEntries[i].property & (ISMENU | ISDIR))
150150
continue;
151151

152152
//gfx_printf("Dumping %s...\n", mmcMenuEntries[i].name);
@@ -159,7 +159,7 @@ int makeMmcMenu(short mmcType){
159159
case 2:
160160
if (!(clipboardhelper & ISDIR) && (clipboardhelper & OPERATIONCOPY)){
161161
gfx_clearscreen();
162-
if (!mmcFlashFile(clipboard, mmcType)){
162+
if (!mmcFlashFile(clipboard, mmcType, true)){
163163
gfx_printf("\nDone!");
164164
hidWait();
165165
}

Hakupayload/source/tegraexplorer/emmc/emmcoperations.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
int emmcDumpSpecific(char *part, char *path);
66
int emmcDumpBoot(char *basePath);
7-
int mmcFlashFile(char *path, short mmcType);
7+
int mmcFlashFile(char *path, short mmcType, bool warnings);
88

99
int emmcDumpPart(char *path, sdmmc_storage_t *mmcstorage, emmc_part_t *part);
10-
int emmcRestorePart(char *path, sdmmc_storage_t *mmcstorage, emmc_part_t *part);
10+
int emmcRestorePart(char *path, sdmmc_storage_t *mmcstorage, emmc_part_t *part, bool warnings);

Hakupayload/source/tegraexplorer/emmc/emmcrestorepart.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
extern sdmmc_storage_t storage;
1818
extern emmc_part_t *system_part;
1919

20-
int emmcRestorePart(char *path, sdmmc_storage_t *mmcstorage, emmc_part_t *part){
20+
int emmcRestorePart(char *path, sdmmc_storage_t *mmcstorage, emmc_part_t *part, bool warnings){
2121
FIL fp;
2222
FILINFO fno;
2323
u8 *buf;
@@ -32,7 +32,7 @@ int emmcRestorePart(char *path, sdmmc_storage_t *mmcstorage, emmc_part_t *part){
3232

3333
gfx_printf("Initializing\r");
3434

35-
buf = calloc(16384, sizeof(u8));
35+
buf = calloc(BUFSIZE, sizeof(u8));
3636

3737
if (!buf){
3838
gfx_errDisplay("restore_emmc_part", ERR_MEM_ALLOC_FAILED, 1);
@@ -54,10 +54,10 @@ int emmcRestorePart(char *path, sdmmc_storage_t *mmcstorage, emmc_part_t *part){
5454

5555
gfx_printf("Flashing %s\n", part->name);
5656

57-
if (totalSize < totalSizeDest){
57+
if (totalSize < totalSizeDest && warnings){
5858
SWAPCOLOR(COLOR_ORANGE);
5959
gfx_printf("File is too small for destination.\nDo you want to flash it anyway?\n\nB to Cancel\n");
60-
u8 btnres = gfx_makewaitmenu(
60+
u32 btnres = gfx_makewaitmenu(
6161
"A to Confirm",
6262
3
6363
);
@@ -78,7 +78,7 @@ int emmcRestorePart(char *path, sdmmc_storage_t *mmcstorage, emmc_part_t *part){
7878
}
7979

8080
while (totalSectors > 0){
81-
num = MIN(totalSectors, 32);
81+
num = MIN(totalSectors, 128);
8282

8383
if ((res = f_read(&fp, buf, num * NX_EMMC_BLOCKSIZE, NULL))){
8484
gfx_errDisplay("restore_emmc_part", res, 5);
@@ -214,13 +214,13 @@ emmc_part_t *mmcFindPart(char *path, short mmcType){
214214
return NULL;
215215
}
216216

217-
int mmcFlashFile(char *path, short mmcType){
217+
int mmcFlashFile(char *path, short mmcType, bool warnings){
218218
emmc_part_t *part;
219219
int res;
220220

221221
part = mmcFindPart(path, mmcType);
222222
if (part != NULL){
223-
res = emmcRestorePart(path, &storage, part);
223+
res = emmcRestorePart(path, &storage, part, warnings);
224224
emummc_storage_set_mmc_partition(&storage, 0);
225225
return res;
226226
}

0 commit comments

Comments
 (0)