mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2024-11-11 01:55:38 +08:00
save raw
This commit is contained in:
parent
64df44d186
commit
cc6cd93ea7
2 changed files with 34 additions and 2 deletions
|
@ -136,8 +136,39 @@ out:
|
|||
}
|
||||
|
||||
int saveFileJSON(const char *preferredName, const char *suffix, uint8_t* data, size_t datalen) {
|
||||
//stub - for merlokk ;)
|
||||
return 1;
|
||||
if ( preferredName == NULL ) return 1;
|
||||
if ( suffix == NULL ) return 1;
|
||||
if ( data == NULL ) return 1;
|
||||
|
||||
int retval = 0;
|
||||
int size = sizeof(char) * (strlen(preferredName) + strlen(suffix) + 10);
|
||||
char * fileName = calloc(size, sizeof(char));
|
||||
int num = 1;
|
||||
sprintf(fileName,"%s.%s", preferredName, suffix);
|
||||
while (fileExists(fileName)) {
|
||||
sprintf(fileName,"%s-%d.%s", preferredName, num, suffix);
|
||||
num++;
|
||||
}
|
||||
|
||||
json_t *root = json_object();
|
||||
JsonSaveStr(root, "Created", "proxmark3");
|
||||
JsonSaveBufAsHexCompact(root, "raw", data, datalen);
|
||||
|
||||
int res = json_dump_file(root, fileName, JSON_INDENT(2));
|
||||
if (res) {
|
||||
PrintAndLog("ERROR: can't save the file: %s", fileName);
|
||||
json_decref(root);
|
||||
retval = 200;
|
||||
goto out;
|
||||
}
|
||||
PrintAndLog("File `%s` saved.", fileName);
|
||||
|
||||
// free json object
|
||||
json_decref(root);
|
||||
|
||||
out:
|
||||
free(fileName);
|
||||
return retval;
|
||||
}
|
||||
|
||||
int loadFile(const char *preferredName, const char *suffix, void* data, size_t* datalen) {
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#include <sys/stat.h>
|
||||
#include <stdarg.h>
|
||||
#include "../ui.h"
|
||||
#include "../emv/emvjson.h"
|
||||
|
||||
int fileExists(const char *filename);
|
||||
|
||||
|
|
Loading…
Reference in a new issue