mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-02-13 18:57:12 +08:00
raw load file
This commit is contained in:
parent
21118ed6b8
commit
0ffddd8470
2 changed files with 33 additions and 4 deletions
|
@ -283,10 +283,38 @@ out:
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
int loadFileJSON(const char *preferredName, const char *suffix, void* data, size_t* datalen) {
|
int loadFileJSON(const char *preferredName, const char *suffix, void* data, size_t maxdatalen, size_t* datalen) {
|
||||||
//stub - for merlokk ;)
|
|
||||||
datalen = 0;
|
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
|
#else //if we're on ARM
|
||||||
|
|
|
@ -122,10 +122,11 @@ extern int loadFileEML(const char *preferredName, const char *suffix, void* data
|
||||||
* @param preferredName
|
* @param preferredName
|
||||||
* @param suffix the file suffix. Leave out the ".".
|
* @param suffix the file suffix. Leave out the ".".
|
||||||
* @param data The data array to store the loaded bytes from file
|
* @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
|
* @param datalen the number of bytes loaded from file
|
||||||
* @return 0 for ok, 1 for failz
|
* @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)
|
#define PrintAndLogDevice(level, format, args...) PrintAndLogEx(level, format , ## args)
|
||||||
#else
|
#else
|
||||||
|
|
Loading…
Reference in a new issue