diff --git a/source/tegraexplorer/emmc.c b/source/tegraexplorer/emmc.c index f5892a4..2bee822 100644 --- a/source/tegraexplorer/emmc.c +++ b/source/tegraexplorer/emmc.c @@ -102,13 +102,12 @@ void disconnect_mmc(){ switch (currentlyMounted){ case SYSMMC: sdmmc_storage_end(&storage); - currentlyMounted = -1; break; case EMUMMC: emummc_storage_end(&storage); - currentlyMounted = -1; break; } + currentlyMounted = -1; } int dump_biskeys(){ diff --git a/source/tegraexplorer/fs.c b/source/tegraexplorer/fs.c index 4cd5c5d..a753dd8 100644 --- a/source/tegraexplorer/fs.c +++ b/source/tegraexplorer/fs.c @@ -9,6 +9,7 @@ #include "../gfx/gfx.h" #include "../utils/util.h" #include "io.h" +#include "script.h" fs_entry *fileobjects; char rootpath[10] = ""; @@ -18,7 +19,7 @@ u8 clipboardhelper = 0; extern const char sizevalues[4][3]; extern int launch_payload(char *path); -menu_item explfilemenu[10] = { +menu_item explfilemenu[11] = { {"-- File Menu --", COLOR_BLUE, -1, 0}, {"FILE", COLOR_GREEN, -1, 0}, {"\nSIZE", COLOR_VIOLET, -1, 0}, @@ -28,6 +29,7 @@ menu_item explfilemenu[10] = { {"Move to clipboard", COLOR_BLUE, MOVE, 1}, {"\nDelete file\n", COLOR_RED, DELETE, 1}, {"Launch Payload", COLOR_ORANGE, PAYLOAD, 1}, + {"Launch Script", COLOR_BLUE, SCRIPT, 1}, {"View Hex", COLOR_GREEN, HEXVIEW, 1} }; @@ -309,7 +311,12 @@ int filemenu(fs_entry file){ else explfilemenu[8].property = -1; - temp = makemenu(explfilemenu, 10); + if (strstr(file.name, ".tegrascript") != NULL) + explfilemenu[9].property = 1; + else + explfilemenu[9].property = -1; + + temp = makemenu(explfilemenu, 11); switch (temp){ case COPY: @@ -324,6 +331,9 @@ int filemenu(fs_entry file){ case PAYLOAD: launch_payload(getnextloc(currentpath, file.name)); break; + case SCRIPT: + ParseScript(getnextloc(currentpath, file.name)); + break; case HEXVIEW: viewbytes(getnextloc(currentpath, file.name)); break; diff --git a/source/tegraexplorer/fs.h b/source/tegraexplorer/fs.h index 11f6467..a3edb09 100644 --- a/source/tegraexplorer/fs.h +++ b/source/tegraexplorer/fs.h @@ -34,6 +34,7 @@ enum filemenuoptions { MOVE, DELETE, PAYLOAD, + SCRIPT, HEXVIEW }; diff --git a/source/tegraexplorer/script.c b/source/tegraexplorer/script.c new file mode 100644 index 0000000..d0e744b --- /dev/null +++ b/source/tegraexplorer/script.c @@ -0,0 +1,191 @@ +#include +#include "../mem/heap.h" +#include "gfx.h" +#include "fs.h" +#include "io.h" +#include "emmc.h" +#include "../utils/types.h" +#include "../libs/fatfs/ff.h" +#include "../utils/sprintf.h" +#include "../utils/btn.h" +#include "../gfx/gfx.h" +#include "../utils/util.h" +#include "script.h" + +char func[11] = "", args[2][128] = {"", ""}; +int res; +script_parts parts[] = { + {"COPY", Part_Copy, 2}, + {"COPY-R", Part_RecursiveCopy, 2}, + {"MKDIR", Part_MakeFolder, 1}, + {"CON_MMC", Part_ConnectMMC, 1}, + {"MNT_MMC", Part_MountMMC, 1}, + {"PRINT", Part_Print, 1}, + {"ERRPRINT", Part_ErrorPrint, 0}, + {"EXIT", Part_Exit, 0}, + {"PAUSE", Part_WaitOnUser, 0}, + {"NULL", NULL, -1} +}; + +int Part_Copy(){ + return copy(args[0], args[1], true, false); +} + +int Part_RecursiveCopy(){ + return copy_recursive(args[0], args[1]); +} + +int Part_MakeFolder(){ + return f_mkdir(args[0]); +} + +int Part_ConnectMMC(){ + if (strcmpcheck(args[0], "SYSMMC")) + connect_mmc(SYSMMC); + if (strcmpcheck(args[0], "EMUMMC")) + connect_mmc(EMUMMC); + + return 0; +} + +int Part_MountMMC(){ + return mount_mmc(args[0], 2); +} + +int Part_Print(){ + RESETCOLOR; + gfx_printf(args[0]); + gfx_printf("\n"); + return 0; +} + +int Part_ErrorPrint(){ + gfx_printf("Errorcode: %d\n", res); + return 0; +} + +bool forceExit = false; +int Part_Exit(){ + forceExit = true; + return 0; +} + +int Part_WaitOnUser(){ + return (btn_wait() & BTN_POWER); +} + +int ParsePart(){ + int i; + for (i = 0; parts[i].arg_amount != -1; i++){ + if (strcmpcheck(func, parts[i].name)) + return i; + } + return -1; +} + +FIL in; +UINT endByte = 0; + +char GetNextByte(){ + char single; + f_read(&in, &single, sizeof(char), &endByte); + + if (sizeof(char) != endByte) + forceExit = true; + + return single; +} + +void ParseScript(char* path){ + char currentchar; + int strlength; + bool inifstatement = false; + forceExit = false; + + clearscreen(); + + res = f_open(&in, path, FA_READ | FA_OPEN_EXISTING); + if (res != FR_OK){ + message(COLOR_RED, "File Opening Failed\nErrcode %d", res); + return; + } + + while (1){ + currentchar = GetNextByte(); + + if (endByte == 0 || currentchar == (char)EOF) + break; + + switch(currentchar){ + case '{': + if (!inifstatement) + while (currentchar != '}') + currentchar = GetNextByte(); + + break; + case '}': + if (inifstatement) + inifstatement = false; + + break; + case '<': + strlength = 0; + currentchar = GetNextByte(); + + while (currentchar != '>'){ + func[strlength++] = currentchar; + currentchar = GetNextByte(); + } + func[strlength] = '\0'; + + res = ParsePart(); + if (res == -1) + return; + + for (int i = 0; i < parts[res].arg_amount; i++){ + while (currentchar != 0x22) + currentchar = GetNextByte(); + + strlength = 0; + currentchar = GetNextByte(); + while (currentchar != 0x22){ + args[i][strlength++] = currentchar; + currentchar = GetNextByte(); + } + args[i][strlength] = '\0'; + + if (i < parts[res].arg_amount) + currentchar = GetNextByte(); + } + res = parts[res].handler(); + break; + case '$': + strlength = 0; + currentchar = GetNextByte(); + + while (currentchar != '$'){ + func[strlength++] = currentchar; + currentchar = GetNextByte(); + } + func[strlength] = '\0'; + + if (strcmpcheck(func, "ERROR") || strcmpcheck(func, "TRUE")){ + if (res) + inifstatement = true; + } + else if (strcmpcheck(func, "NOERROR") || strcmpcheck(func, "FALSE")){ + if (!res) + inifstatement = true; + } + + if (inifstatement) + while(currentchar != '{') + currentchar = GetNextByte(); + + break; + + } + } + + f_close(&in); +} \ No newline at end of file diff --git a/source/tegraexplorer/script.h b/source/tegraexplorer/script.h new file mode 100644 index 0000000..5f12374 --- /dev/null +++ b/source/tegraexplorer/script.h @@ -0,0 +1,21 @@ +#pragma once +#define strcmpcheck(x, y) (!strcmp(x, y)) + +typedef int (*part_handler)(); +typedef struct _script_parts { + char name[11]; + part_handler handler; + short arg_amount; +} script_parts; + +void ParseScript(char* path); +int Part_WaitOnUser(); +int Part_Exit(); +int Part_ErrorPrint(); +int Part_Print(); +int Part_MountMMC(); +int Part_ConnectMMC(); +int Part_MakeFolder(); +int Part_RecursiveCopy(); +int Testing_Part_Handler(); +int Part_Copy(); \ No newline at end of file diff --git a/source/tegraexplorer/te.c b/source/tegraexplorer/te.c index a30fa37..6830acc 100644 --- a/source/tegraexplorer/te.c +++ b/source/tegraexplorer/te.c @@ -115,6 +115,8 @@ void te_main(){ mainmenu[6].property = -2; } + disconnect_mmc(); + while (1){ fillmainmenu(); res = makemenu(mainmenu, MAINMENU_AMOUNT);