raw load file

This commit is contained in:
merlokk 2018-11-29 13:21:38 +02:00
parent 21118ed6b8
commit 0ffddd8470
2 changed files with 33 additions and 4 deletions

View file

@ -283,10 +283,38 @@ out:
return retval;
}
int loadFileJSON(const char *preferredName, const char *suffix, void* data, size_t* datalen) {
//stub - for merlokk ;)
int loadFileJSON(const char *preferredName, const char *suffix, void* data, size_t maxdatalen, size_t* datalen) {
datalen = 0;
return 1;
json_t *root;
json_error_t error;
if ( preferredName == NULL ) return 1;
if ( suffix == NULL ) return 1;
int retval = 0;
int size = sizeof(char) * (strlen(preferredName) + strlen(suffix) + 10);
char * fileName = calloc(size, sizeof(char));
sprintf(fileName,"%s.%s", preferredName, suffix);
root = json_load_file(fileName, 0, &error);
if (!root) {
PrintAndLog("ERROR: json (%s) error on line %d: %s", fileName, error.line, error.text);
retval = 2;
goto out;
}
if (!json_is_object(root)) {
PrintAndLog("ERROR: Invalid json (%s) format. root must be an object.", fileName);
retval = 3;
goto out;
}
JsonLoadBufAsHex(root, "$.raw", data, maxdatalen, datalen);
out:
json_decref(root);
free(fileName);
return retval;
}
#else //if we're on ARM

View file

@ -122,10 +122,11 @@ extern int loadFileEML(const char *preferredName, const char *suffix, void* data
* @param preferredName
* @param suffix the file suffix. Leave out the ".".
* @param data The data array to store the loaded bytes from file
* @param maxdatalen maximum size of data array in bytes
* @param datalen the number of bytes loaded from file
* @return 0 for ok, 1 for failz
*/
extern int loadFileJSON(const char *preferredName, const char *suffix, void* data, size_t* datalen);
extern int loadFileJSON(const char *preferredName, const char *suffix, void* data, size_t maxdatalen, size_t* datalen);
#define PrintAndLogDevice(level, format, args...) PrintAndLogEx(level, format , ## args)
#else