1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-11-22 20:06:43 +00:00

[script] add operators, add reboot to payload

- Add a function to reboot to payload
- Add an "Empty array" variable type that is created when you try to assign []. This will get filled with a valid entry upon first addition
- Adds operator string array plus string
This commit is contained in:
suchmememanyskill 2021-01-10 16:32:50 +01:00
parent 3f80693d9e
commit 963987d639
3 changed files with 70 additions and 23 deletions

View file

@ -132,42 +132,44 @@ Variable_t getVarFromToken(scriptCtx_t* ctx, lexarToken_t* tokens, int* index, u
val = executeFunction(ctx, tokens[i - 2].text, &tokens[i], argCount); val = executeFunction(ctx, tokens[i - 2].text, &tokens[i], argCount);
//val = IntValue(1);
i += argCount; i += argCount;
} }
ELIFTX(LSBracket) { ELIFTX(LSBracket) {
i++; i++;
int argCount = distanceBetweenTokens(&tokens[i], maxLen - 1, LSBracket, RSBracket); int argCount = distanceBetweenTokens(&tokens[i], maxLen - 1, LSBracket, RSBracket);
if (argCount <= 0) if (argCount < 0)
return ErrValue(ERRSYNTAX); return ErrValue(ERRSYNTAX);
// ArrayVars should be a Vector_t containing Variable_t's. Not implemented yet! val.varType = EmptyArrayType;
Vector_t arrayVars = extractVars(ctx, &tokens[i], argCount);
Variable_t* variables = vecGetArray(Variable_t*, arrayVars);
int type = variables[0].varType;
if (!(type == StringType || type == IntType))
return ErrValue(ERRINVALIDTYPE);
val.varType = (type + 2); if (argCount > 0){
val.free = 1; Vector_t arrayVars = extractVars(ctx, &tokens[i], argCount);
val.vectorType = newVec((type == IntType) ? sizeof(int) : sizeof(char*), arrayVars.count); Variable_t* variables = vecGetArray(Variable_t*, arrayVars);
int type = variables[0].varType;
if (!(type == StringType || type == IntType))
return ErrValue(ERRINVALIDTYPE);
for (int i = 0; i < arrayVars.count; i++) { val.varType = (type + 2);
if (variables[i].varType != type) val.free = 1;
return ErrValue(ERRINVALIDTYPE); // Free-ing issue!! val.vectorType = newVec((type == IntType) ? sizeof(int) : sizeof(char*), arrayVars.count);
if (type == StringType) { for (int j = 0; j < arrayVars.count; j++) {
char* temp = CpyStr(variables[i].stringType); if (variables[j].varType != type)
vecAddElement(&val.vectorType, temp); return ErrValue(ERRINVALIDTYPE); // Free-ing issue!!
}
else { if (type == StringType) {
vecAddElement(&val.vectorType, variables[i].integerType); char* temp = CpyStr(variables[j].stringType);
vecAddElement(&val.vectorType, temp);
}
else {
vecAddElement(&val.vectorType, variables[j].integerType);
}
} }
i += argCount;
freeVariableVector(&arrayVars);
} }
i += argCount;
freeVariableVector(&arrayVars);
} }
ELIFTX(LBracket) { ELIFTX(LBracket) {
i++; i++;
@ -397,6 +399,43 @@ Variable_t solveEquation(scriptCtx_t* ctx, lexarToken_t* tokens, u32 len, u8 sho
else else
return ErrValue(ERRBADOPERATOR); return ErrValue(ERRBADOPERATOR);
} }
else if (res.varType == EmptyArrayType && localOpToken == Plus){
res.free = 1;
res.varType = val.varType + 2;
if (val.varType == IntType){
res.vectorType = newVec(sizeof(int), 4);
vecAddElem(&res.vectorType, val.integerType);
}
else if (val.varType == StringType) {
res.vectorType = newVec(sizeof(char*), 4);
char *temp = CpyStr(val.stringType);
vecAddElem(&res.vectorType, temp);
}
else
return ErrValue(ERRBADOPERATOR);
freeVariable(val);
}
else if (res.varType == StringArrayType && val.varType == StringType){
if (localOpToken == Plus){
Vector_t new = vecCopy(&res.vectorType);
vecDefArray(char **, strings, new);
for (int j = 0; j < new.count; j++){
strings[j] = CpyStr(strings[j]);
}
freeVariable(res);
char *temp = CpyStr(val.stringType);
vecAddElem(&new, temp);
res.free = 1;
res.vectorType = new;
}
else
return ErrValue(ERRBADOPERATOR);
}
else else
return ErrValue(ERRBADOPERATOR); return ErrValue(ERRBADOPERATOR);
} }

View file

@ -396,6 +396,12 @@ scriptFunction(funcGetMs){
return varInt(get_tmr_ms()); return varInt(get_tmr_ms());
} }
extern int launch_payload(char *path);
scriptFunction(funcLaunchPayload){
return varInt(launch_payload(vars[0].stringType));
}
u8 fiveInts[] = {IntType, IntType, IntType, IntType, IntType}; u8 fiveInts[] = {IntType, IntType, IntType, IntType, IntType};
u8 singleIntArray[] = { IntArrayType }; u8 singleIntArray[] = { IntArrayType };
u8 singleInt[] = { IntType }; u8 singleInt[] = { IntType };
@ -448,6 +454,7 @@ functionStruct_t scriptFunctions[] = {
{"ncaGetType", funcGetNcaType, 1, singleStr}, {"ncaGetType", funcGetNcaType, 1, singleStr},
{"saveSign", funcSignSave, 1, singleStr}, {"saveSign", funcSignSave, 1, singleStr},
{"timerMs", funcGetMs, 0, NULL}, {"timerMs", funcGetMs, 0, NULL},
{"launchPayload", funcLaunchPayload, 1, singleStr},
// Left from old: keyboard(?) // Left from old: keyboard(?)
}; };

View file

@ -74,6 +74,7 @@ enum Variables {
DictType, DictType,
NullType, NullType,
ErrType, ErrType,
EmptyArrayType,
}; };
typedef struct { // this is to keep track of how many {} we passed. Keep an internal var with the "indentation level", +1 for {, -1 for }. have an array with the following def on what to do (on func: enter, set indentation & jump back, on while, jump to while, use while as if, on if simply set true or false) typedef struct { // this is to keep track of how many {} we passed. Keep an internal var with the "indentation level", +1 for {, -1 for }. have an array with the following def on what to do (on func: enter, set indentation & jump back, on while, jump to while, use while as if, on if simply set true or false)