mirror of
https://github.com/suchmememanyskill/TegraExplorer.git
synced 2024-12-26 11:26:05 +00:00
[Script] add last bits
Fixed: Scripts should free at the end Added: ncaGetType, saveSign Modified: pathCombine can now take 2+ args to combine
This commit is contained in:
parent
c9fdb650c3
commit
12136d9289
9 changed files with 132 additions and 18 deletions
|
@ -78,6 +78,9 @@ void RunScript(char *path, FSEntry_t entry){
|
|||
if (!script)
|
||||
return;
|
||||
|
||||
if (((entry.size >= 64 && entry.sizeDef == 1) || entry.sizeDef >= 2) && !TConf.minervaEnabled)
|
||||
return;
|
||||
|
||||
gfx_clearscreen();
|
||||
scriptCtx_t ctx = createScriptCtx();
|
||||
ctx.script = runLexar(script, size);
|
||||
|
@ -88,10 +91,11 @@ void RunScript(char *path, FSEntry_t entry){
|
|||
|
||||
printError(mainLoop(&ctx));
|
||||
|
||||
freeVariableVector(&ctx.varDict);
|
||||
freeDictVector(&ctx.varDict);
|
||||
lexarVectorClear(&ctx.script);
|
||||
gfx_printf("\nend of script");
|
||||
hidWait();
|
||||
|
||||
gfx_printf("\nScript done!\nPress any key");
|
||||
hidWait();
|
||||
}
|
||||
|
||||
void RenameFile(char *path, FSEntry_t entry){
|
||||
|
|
51
source/keys/save.c
Normal file
51
source/keys/save.c
Normal file
|
@ -0,0 +1,51 @@
|
|||
#include "save.h"
|
||||
#include <utils/types.h>
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include <sec/se.h>
|
||||
#include <mem/heap.h>
|
||||
#include "../err.h"
|
||||
|
||||
ErrCode_t saveCommit(const char *path){
|
||||
FIL file;
|
||||
int res;
|
||||
u8 *buf, hash[0x20], *cmac_data, cmac[0x10];
|
||||
const u32 hashed_data_size = 0x3D00, cmac_data_size = 0x200;
|
||||
|
||||
buf = malloc(hashed_data_size);
|
||||
cmac_data = malloc(cmac_data_size);
|
||||
|
||||
if ((res = f_open(&file, path, FA_OPEN_EXISTING | FA_READ | FA_WRITE))){
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
f_lseek(&file, 0x300);
|
||||
if ((res = f_read(&file, buf, hashed_data_size, NULL))){
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
se_calc_sha256_oneshot(hash, buf, hashed_data_size);
|
||||
|
||||
f_lseek(&file, 0x108);
|
||||
if ((res = f_write(&file, hash, sizeof(hash), NULL))){
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
f_lseek(&file, 0x100);
|
||||
if ((res = f_read(&file, cmac_data, cmac_data_size, NULL))){
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
se_aes_cmac(8, cmac, 0x10, cmac_data, cmac_data_size);
|
||||
|
||||
f_lseek(&file, 0);
|
||||
|
||||
if ((res = f_write(&file, cmac, sizeof(cmac), NULL))){
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
out_free:;
|
||||
free(buf);
|
||||
free(cmac_data);
|
||||
f_close(&file);
|
||||
return newErrCode(res);
|
||||
}
|
4
source/keys/save.h
Normal file
4
source/keys/save.h
Normal file
|
@ -0,0 +1,4 @@
|
|||
#pragma once
|
||||
#include "../err.h"
|
||||
|
||||
ErrCode_t saveCommit(const char *path);
|
|
@ -16,11 +16,16 @@
|
|||
#include "../storage/emummc.h"
|
||||
#include "../fs/readers/folderReader.h"
|
||||
#include "../utils/utils.h"
|
||||
#include "../keys/keys.h"
|
||||
#include "../storage/emmcfile.h"
|
||||
#include "../keys/nca.h"
|
||||
#include "../keys/save.h"
|
||||
#include "../tegraexplorer/tconf.h"
|
||||
|
||||
#define scriptFunction(name) Variable_t name(scriptCtx_t *ctx, Variable_t *vars, u32 varLen)
|
||||
|
||||
#define varInt(i) newVar(IntType, 0, i)
|
||||
#define varStr(s) newVar(StringType, 1, .stringType = s)
|
||||
|
||||
scriptFunction(funcIf) {
|
||||
setCurIndentInstruction(ctx, (vars[0].integerType == 0), 0, -1);
|
||||
|
@ -267,7 +272,23 @@ scriptFunction(funcMakeMenu){
|
|||
|
||||
// Args: Str, Str
|
||||
scriptFunction(funcCombinePath){
|
||||
return newVar(StringType, 1, .stringType = CombinePaths(vars[0].stringType, vars[1].stringType));
|
||||
if (varLen <= 1)
|
||||
return NullVar;
|
||||
|
||||
for (int i = 0; i < varLen; i++){
|
||||
if (vars[i].varType != StringType)
|
||||
return ErrVar(ERRINVALIDTYPE);
|
||||
}
|
||||
|
||||
char *res = CpyStr(vars[0].stringType);
|
||||
|
||||
for (int i = 1; i < varLen; i++){
|
||||
char *temp = CombinePaths(res, vars[i].stringType);
|
||||
free(res);
|
||||
res = temp;
|
||||
}
|
||||
|
||||
return varStr(res);
|
||||
}
|
||||
|
||||
// Args: Str
|
||||
|
@ -300,6 +321,9 @@ scriptFunction(funcMmcConnect){
|
|||
|
||||
// Args: Str
|
||||
scriptFunction(funcMmcMount){
|
||||
if (!TConf.keysDumped)
|
||||
return ErrVar(ERRFATALFUNCFAIL);
|
||||
|
||||
return varInt((mountMMCPart(vars[0].stringType).err));
|
||||
}
|
||||
|
||||
|
@ -354,6 +378,20 @@ scriptFunction(funcMmcRestore){
|
|||
return varInt((DumpOrWriteEmmcPart(vars[0].stringType, vars[1].stringType, 1, vars[2].integerType).err));
|
||||
}
|
||||
|
||||
scriptFunction(funcGetNcaType){
|
||||
if (!TConf.keysDumped)
|
||||
return ErrVar(ERRFATALFUNCFAIL);
|
||||
|
||||
return varInt((GetNcaType(vars[0].stringType)));
|
||||
}
|
||||
|
||||
scriptFunction(funcSignSave){
|
||||
if (!TConf.keysDumped)
|
||||
return ErrVar(ERRFATALFUNCFAIL);
|
||||
|
||||
return varInt((saveCommit(vars[0].stringType).err));
|
||||
}
|
||||
|
||||
u8 fiveInts[] = {IntType, IntType, IntType, IntType, IntType};
|
||||
u8 singleIntArray[] = { IntArrayType };
|
||||
u8 singleInt[] = { IntType };
|
||||
|
@ -390,7 +428,7 @@ functionStruct_t scriptFunctions[] = {
|
|||
{"version", funcGetVer, 0, NULL},
|
||||
{"menu", funcMakeMenu, 2, MenuArgs}, // for the optional arg
|
||||
{"menu", funcMakeMenu, 3, MenuArgs},
|
||||
{"pathCombine", funcCombinePath, 2, twoStrings},
|
||||
{"pathCombine", funcCombinePath, varArgs, NULL},
|
||||
{"pathEscFolder", funcEscFolder, 1, singleStr},
|
||||
{"fileMove", funcFileMove, 2, twoStrings},
|
||||
{"fileCopy", funcFileCopy, 2, twoStrings},
|
||||
|
@ -403,8 +441,9 @@ functionStruct_t scriptFunctions[] = {
|
|||
{"dirDel", funcDelDir, 1, singleStr},
|
||||
{"mmcDump", funcMmcDump, 2, mmcReadWrite},
|
||||
{"mmcRestore", funcMmcRestore, 3, mmcReadWrite},
|
||||
{"ncaGetType", funcGetNcaType, 1, singleStr},
|
||||
{"saveSign", funcSignSave, 1, singleStr},
|
||||
// Left from old: keyboard(?)
|
||||
// Should implement still: saveSign, getNcaType
|
||||
};
|
||||
|
||||
Variable_t executeFunction(scriptCtx_t* ctx, char* func_name, lexarToken_t *start, u32 len) {
|
||||
|
|
|
@ -78,13 +78,15 @@ scriptResult_t mainLoop(scriptCtx_t* ctx) {
|
|||
void printToken(lexarToken_t* token) {
|
||||
switch (token->token) {
|
||||
case Variable:
|
||||
case VariableAssignment:
|
||||
case Function:
|
||||
case FunctionAssignment:
|
||||
case ArrayVariable:
|
||||
case ArrayVariableAssignment:
|
||||
case Function:
|
||||
gfx_printf("%s", token->text);
|
||||
break;
|
||||
case FunctionAssignment:
|
||||
case VariableAssignment:
|
||||
case ArrayVariableAssignment:
|
||||
gfx_printf("%s=", token->text);
|
||||
break;
|
||||
case StrLit:
|
||||
//printf("%d: '%s'\n", vec.tokens[i].token, vec.tokens[i].text);
|
||||
gfx_printf("\"%s\"", token->text);
|
||||
|
@ -100,12 +102,24 @@ void printToken(lexarToken_t* token) {
|
|||
}
|
||||
}
|
||||
|
||||
char *ErrorText[] = {
|
||||
"Bad operator",
|
||||
"Double not",
|
||||
"Syntax err",
|
||||
"Invalid type",
|
||||
"No var",
|
||||
"No func",
|
||||
"Inactive indent",
|
||||
"Div by 0",
|
||||
"Func fail"
|
||||
};
|
||||
|
||||
void printError(scriptResult_t res) {
|
||||
if (res.resCode) {
|
||||
if (res.resCode == ERRESCSCRIPT)
|
||||
return;
|
||||
|
||||
gfx_printf("Error %d found!\nNear: ", res.resCode);
|
||||
gfx_printf("Error found! %s\nNear: ", ErrorText[res.resCode - 1]);
|
||||
for (int i = 0; i < res.len; i++) {
|
||||
printToken(&res.nearToken[i]);
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ void freeVariable(Variable_t dv) {
|
|||
case StringArrayType:;
|
||||
char** strArray = vecGetArray(char**, dv.vectorType);
|
||||
for (u32 i = 0; i < dv.vectorType.count; i++){
|
||||
FREE(strArray[i]);
|
||||
free(strArray[i]);
|
||||
}
|
||||
|
||||
case IntArrayType:
|
||||
|
|
|
@ -118,11 +118,13 @@ void GptMenu(u8 MMCType){
|
|||
DrawError(err);
|
||||
}
|
||||
else {
|
||||
if (TConf.curExplorerLoc > LOC_SD)
|
||||
ResetCopyParams();
|
||||
if (TConf.keysDumped){
|
||||
if (TConf.curExplorerLoc > LOC_SD)
|
||||
ResetCopyParams();
|
||||
|
||||
TConf.curExplorerLoc = LOC_EMMC;
|
||||
FileExplorer("bis:/");
|
||||
TConf.curExplorerLoc = LOC_EMMC;
|
||||
FileExplorer("bis:/");
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -22,6 +22,7 @@ void SetKeySlots(){
|
|||
// Not for bis but whatever
|
||||
se_aes_key_set(6, dumpedKeys.header_key + 0x00, 0x10);
|
||||
se_aes_key_set(7, dumpedKeys.header_key + 0x10, 0x10);
|
||||
se_aes_key_set(8, dumpedKeys.save_mac_key, 0x10);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -141,8 +141,7 @@ void EnterMainMenu(){
|
|||
// -- Explore --
|
||||
mainMenuEntries[MainBrowseSd].hide = !sd_mounted;
|
||||
mainMenuEntries[MainMountSd].name = (sd_mounted) ? "Unmount SD" : "Mount SD";
|
||||
mainMenuEntries[MainBrowseEmmc].hide = !TConf.keysDumped;
|
||||
mainMenuEntries[MainBrowseEmummc].hide = (!TConf.keysDumped || !emu_cfg.enabled || !sd_mounted);
|
||||
mainMenuEntries[MainBrowseEmummc].hide = (!emu_cfg.enabled || !sd_mounted);
|
||||
|
||||
// -- Tools --
|
||||
mainMenuEntries[MainPartitionSd].hide = (!is_sd_inited || sd_get_card_removed());
|
||||
|
|
Loading…
Reference in a new issue