mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 21:33:47 -07:00
split saveFileJSONex
This commit is contained in:
parent
44c60b45eb
commit
e38f8e2d82
2 changed files with 18 additions and 9 deletions
|
@ -288,22 +288,15 @@ int saveFile(const char *preferredName, const char *suffix, const void *data, si
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// dump file (normally, we also got preference file, etc)
|
int prepareJSON(json_t *root, JSONFileType ftype, uint8_t *data, size_t datalen, bool verbose, void (*callback)(json_t *)) {
|
||||||
int saveFileJSON(const char *preferredName, JSONFileType ftype, uint8_t *data, size_t datalen, void (*callback)(json_t *)) {
|
|
||||||
return saveFileJSONex(preferredName, ftype, data, datalen, true, callback, spDump);
|
|
||||||
}
|
|
||||||
int saveFileJSONex(const char *preferredName, JSONFileType ftype, uint8_t *data, size_t datalen, bool verbose, void (*callback)(json_t *), savePaths_t e_save_path) {
|
|
||||||
|
|
||||||
if (ftype != jsfCustom) {
|
if (ftype != jsfCustom) {
|
||||||
if (data == NULL || datalen == 0) {
|
if (data == NULL || datalen == 0) {
|
||||||
return PM3_EINVARG;
|
return PM3_EINVARG;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int retval = PM3_SUCCESS;
|
|
||||||
char path[PATH_MAX_LENGTH] = {0};
|
char path[PATH_MAX_LENGTH] = {0};
|
||||||
|
|
||||||
json_t *root = json_object();
|
|
||||||
JsonSaveStr(root, "Created", "proxmark3");
|
JsonSaveStr(root, "Created", "proxmark3");
|
||||||
switch (ftype) {
|
switch (ftype) {
|
||||||
case jsfRaw: {
|
case jsfRaw: {
|
||||||
|
@ -771,15 +764,30 @@ int saveFileJSONex(const char *preferredName, JSONFileType ftype, uint8_t *data,
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
return PM3_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
// dump file (normally, we also got preference file, etc)
|
||||||
|
int saveFileJSON(const char *preferredName, JSONFileType ftype, uint8_t *data, size_t datalen, void (*callback)(json_t *)) {
|
||||||
|
return saveFileJSONex(preferredName, ftype, data, datalen, true, callback, spDump);
|
||||||
|
}
|
||||||
|
int saveFileJSONex(const char *preferredName, JSONFileType ftype, uint8_t *data, size_t datalen, bool verbose, void (*callback)(json_t *), savePaths_t e_save_path) {
|
||||||
|
|
||||||
|
int retval = PM3_SUCCESS;
|
||||||
char *fn = newfilenamemcopyEx(preferredName, ".json", e_save_path);
|
char *fn = newfilenamemcopyEx(preferredName, ".json", e_save_path);
|
||||||
if (fn == NULL) {
|
if (fn == NULL) {
|
||||||
return PM3_EMALLOC;
|
return PM3_EMALLOC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
json_t *root = json_object();
|
||||||
|
retval = prepareJSON(root, ftype, data, datalen, verbose, callback);
|
||||||
|
if (retval != PM3_SUCCESS) {
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
if (json_dump_file(root, fn, JSON_INDENT(2))) {
|
if (json_dump_file(root, fn, JSON_INDENT(2))) {
|
||||||
PrintAndLogEx(FAILED, "error, can't save the file `" _YELLOW_("%s") "`", fn);
|
PrintAndLogEx(FAILED, "error, can't save the file `" _YELLOW_("%s") "`", fn);
|
||||||
retval = 200;
|
retval = PM3_ESOFT;
|
||||||
free(fn);
|
free(fn);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,6 +141,7 @@ int saveFileJSON(const char *preferredName, JSONFileType ftype, uint8_t *data, s
|
||||||
int saveFileJSONex(const char *preferredName, JSONFileType ftype, uint8_t *data, size_t datalen, bool verbose, void (*callback)(json_t *), savePaths_t e_save_path);
|
int saveFileJSONex(const char *preferredName, JSONFileType ftype, uint8_t *data, size_t datalen, bool verbose, void (*callback)(json_t *), savePaths_t e_save_path);
|
||||||
int saveFileJSONroot(const char *preferredName, void *root, size_t flags, bool verbose);
|
int saveFileJSONroot(const char *preferredName, void *root, size_t flags, bool verbose);
|
||||||
int saveFileJSONrootEx(const char *preferredName, const void *root, size_t flags, bool verbose, bool overwrite);
|
int saveFileJSONrootEx(const char *preferredName, const void *root, size_t flags, bool verbose, bool overwrite);
|
||||||
|
int prepareJSON(json_t *root, JSONFileType ftype, uint8_t *data, size_t datalen, bool verbose, void (*callback)(json_t *));
|
||||||
/** STUB
|
/** STUB
|
||||||
* @brief Utility function to save WAVE data to a file. This method takes a preferred name, but if that
|
* @brief Utility function to save WAVE data to a file. This method takes a preferred name, but if that
|
||||||
* file already exists, it tries with another name until it finds something suitable.
|
* file already exists, it tries with another name until it finds something suitable.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue