1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-11-24 21:02:04 +00:00

safety push

This commit is contained in:
suchmememanyskill 2021-07-21 01:30:08 +02:00
parent 27350c0a5f
commit d7ebd9fdbe
5 changed files with 44 additions and 1 deletions

View file

@ -104,3 +104,6 @@ $(BUILDDIR)/$(TARGET)/%.o: $(BDKDIR)/%.c
$(BUILDDIR)/$(TARGET)/%.o: $(BDKDIR)/%.S
@mkdir -p "$(@D)"
$(CC) $(CFLAGS) -c $< -o $@
$(SOURCEDIR)/script/builtin.c: scripts/*.te
@py te2c.py source/script/builtin scripts

View file

@ -70,6 +70,16 @@ ClassFunction(stringIndexGet) {
return newStringVariablePtr(a, 0, 0);
}
ClassFunction(stringMinusInt){
u32 baseStrLen = strlen(caller->string.value);
if (baseStrLen < args[0]->integer.value){
SCRIPT_FATAL_ERR("Index of string out of range");
}
char* newStr = calloc(baseStrLen - args[0]->integer.value + 1, 1);
memcpy(newStr, caller->string.value, baseStrLen - args[0]->integer.value);
return newStringVariablePtr(newStr, 0, 1);
}
u8 strOneIntArg[] = { IntClass };
u8 oneStringArg[] = { StringClass };
@ -79,6 +89,7 @@ ClassFunctionTableEntry_t stringFunctions[] = {
{"len", getStringLength, 0, 0},
{"bytes", stringBytes, 0, 0},
{"get", stringIndexGet, 1, strOneIntArg},
{"-", stringMinusInt, 1, strOneIntArg},
};
Variable_t getStringMember(Variable_t* var, char* memberName) {

View file

@ -226,6 +226,25 @@ ClassFunction(eqArray){
return newIntVariablePtr(!res);
}
ClassFunction(arrayFind){
Variable_t *arg = (*args);
if (caller->solvedArray.vector.count <= arg->solvedArray.vector.count || arg->variableType != caller->variableType){
return newIntVariablePtr(-1);
}
u8 step = (arg->variableType == ByteArrayClass) ? 1 : 8;
char *haystack = caller->solvedArray.vector.data;
void *needle = arg->solvedArray.vector.data;
for (int i = 0; i < caller->solvedArray.vector.count - arg->solvedArray.vector.count; i++){
if (!memcmp(haystack + (i * step), needle, step * arg->solvedArray.vector.count)){
return newIntVariablePtr(i);
}
}
return newIntVariablePtr(-1);
}
ClassFunctionTableEntry_t arrayFunctions[] = {
{"get", getArrayIdx, 1, anotherOneIntArg },
{"len", getArrayLen, 0, 0},
@ -239,6 +258,8 @@ ClassFunctionTableEntry_t arrayFunctions[] = {
{"bytestostr", bytesToStr, 0, 0},
{"==", eqArray, 1, oneByteArrayClass},
{"==", eqArray, 1, oneIntArrayClass},
{"find", arrayFind, 1, oneByteArrayClass},
{"find", arrayFind, 1, oneIntArrayClass},
};
Variable_t getArrayMember(Variable_t* var, char* memberName) {

View file

@ -274,6 +274,13 @@ void freeVariableInternal(Variable_t* referencedTarget) {
}
FREE(referencedTarget->dictionary.vector.data);
break;
case SaveClass:;
#ifndef WIN32
save_free_contexts(&referencedTarget->save->saveCtx);
f_close(&referencedTarget->save->saveFile);
FREE(referencedTarget->save);
#endif // !WIN32
break;
}
}

View file

@ -65,3 +65,4 @@ def te2c(dest: str, path: str, suffix: str=".te"):
if __name__ == "__main__":
te2c(dest=sys.argv[1], path=sys.argv[2])
print("converting .te files done!")