mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 05:13:46 -07:00
fileutils should be searching for json
This commit is contained in:
parent
76791bde0a
commit
e9fba19915
1 changed files with 33 additions and 25 deletions
|
@ -944,22 +944,31 @@ int loadFileJSON(const char *preferredName, void *data, size_t maxdatalen, size_
|
||||||
int loadFileJSONex(const char *preferredName, void *data, size_t maxdatalen, size_t *datalen, bool verbose, void (*callback)(json_t *)) {
|
int loadFileJSONex(const char *preferredName, void *data, size_t maxdatalen, size_t *datalen, bool verbose, void (*callback)(json_t *)) {
|
||||||
|
|
||||||
if (data == NULL) return PM3_EINVARG;
|
if (data == NULL) return PM3_EINVARG;
|
||||||
char *fileName = filenamemcopy(preferredName, ".json");
|
|
||||||
if (fileName == NULL) return PM3_EMALLOC;
|
|
||||||
|
|
||||||
*datalen = 0;
|
*datalen = 0;
|
||||||
json_error_t error;
|
|
||||||
int retval = PM3_SUCCESS;
|
int retval = PM3_SUCCESS;
|
||||||
|
|
||||||
json_t *root = json_load_file(fileName, 0, &error);
|
char *path;
|
||||||
|
int res = searchFile(&path, RESOURCES_SUBDIR, preferredName, ".json", false);
|
||||||
|
if (res != PM3_SUCCESS) {
|
||||||
|
return PM3_EFILE;
|
||||||
|
}
|
||||||
|
|
||||||
|
json_error_t error;
|
||||||
|
json_t *root = json_load_file(path, 0, &error);
|
||||||
|
if (verbose)
|
||||||
|
PrintAndLogEx(SUCCESS, "loaded from JSON file " _YELLOW_("%s"), path);
|
||||||
|
|
||||||
|
free(path);
|
||||||
|
|
||||||
if (!root) {
|
if (!root) {
|
||||||
PrintAndLogEx(ERR, "ERROR: json " _YELLOW_("%s") " error on line %d: %s", fileName, error.line, error.text);
|
PrintAndLogEx(ERR, "ERROR: json " _YELLOW_("%s") " error on line %d: %s", preferredName, error.line, error.text);
|
||||||
retval = PM3_ESOFT;
|
retval = PM3_ESOFT;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!json_is_object(root)) {
|
if (!json_is_object(root)) {
|
||||||
PrintAndLogEx(ERR, "ERROR: Invalid json " _YELLOW_("%s") " format. root must be an object.", fileName);
|
PrintAndLogEx(ERR, "ERROR: Invalid json " _YELLOW_("%s") " format. root must be an object.", preferredName);
|
||||||
retval = PM3_ESOFT;
|
retval = PM3_ESOFT;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -980,11 +989,11 @@ int loadFileJSONex(const char *preferredName, void *data, size_t maxdatalen, siz
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
char path[30] = {0};
|
char blocks[30] = {0};
|
||||||
sprintf(path, "$.blocks.%d", i);
|
sprintf(blocks, "$.blocks.%d", i);
|
||||||
|
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
JsonLoadBufAsHex(root, path, &udata[sptr], 16, &len);
|
JsonLoadBufAsHex(root, blocks, &udata[sptr], 16, &len);
|
||||||
if (!len)
|
if (!len)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1002,11 +1011,11 @@ int loadFileJSONex(const char *preferredName, void *data, size_t maxdatalen, siz
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
char path[30] = {0};
|
char blocks[30] = {0};
|
||||||
sprintf(path, "$.blocks.%d", i);
|
sprintf(blocks, "$.blocks.%d", i);
|
||||||
|
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
JsonLoadBufAsHex(root, path, &udata[sptr], 4, &len);
|
JsonLoadBufAsHex(root, blocks, &udata[sptr], 4, &len);
|
||||||
if (!len)
|
if (!len)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1024,11 +1033,11 @@ int loadFileJSONex(const char *preferredName, void *data, size_t maxdatalen, siz
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
char path[30] = {0};
|
char blocks[30] = {0};
|
||||||
sprintf(path, "$.blocks.%zu", i);
|
sprintf(blocks, "$.blocks.%zu", i);
|
||||||
|
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
JsonLoadBufAsHex(root, path, &udata[sptr], 4, &len);
|
JsonLoadBufAsHex(root, blocks, &udata[sptr], 4, &len);
|
||||||
if (!len)
|
if (!len)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1046,11 +1055,11 @@ int loadFileJSONex(const char *preferredName, void *data, size_t maxdatalen, siz
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
char path[30] = {0};
|
char blocks[30] = {0};
|
||||||
sprintf(path, "$.blocks.%zu", i);
|
sprintf(blocks, "$.blocks.%zu", i);
|
||||||
|
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
JsonLoadBufAsHex(root, path, &udata[sptr], 8, &len);
|
JsonLoadBufAsHex(root, blocks, &udata[sptr], 8, &len);
|
||||||
if (!len)
|
if (!len)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1067,11 +1076,11 @@ int loadFileJSONex(const char *preferredName, void *data, size_t maxdatalen, siz
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
char path[30] = {0};
|
char blocks[30] = {0};
|
||||||
sprintf(path, "$.blocks.%zu", i);
|
sprintf(blocks, "$.blocks.%zu", i);
|
||||||
|
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
JsonLoadBufAsHex(root, path, &udata[sptr], 4, &len);
|
JsonLoadBufAsHex(root, blocks, &udata[sptr], 4, &len);
|
||||||
if (!len)
|
if (!len)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1079,15 +1088,14 @@ int loadFileJSONex(const char *preferredName, void *data, size_t maxdatalen, siz
|
||||||
}
|
}
|
||||||
*datalen = sptr;
|
*datalen = sptr;
|
||||||
}
|
}
|
||||||
if (verbose)
|
|
||||||
PrintAndLogEx(SUCCESS, "loaded from JSON file " _YELLOW_("%s"), fileName);
|
out:
|
||||||
|
|
||||||
if (callback != NULL) {
|
if (callback != NULL) {
|
||||||
(*callback)(root);
|
(*callback)(root);
|
||||||
}
|
}
|
||||||
out:
|
|
||||||
json_decref(root);
|
json_decref(root);
|
||||||
free(fileName);
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue