From cc6cd93ea746d3c2ea6cb56f1a8d6c5c51539a72 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Wed, 14 Nov 2018 18:11:05 +0200 Subject: [PATCH] save raw --- client/loclass/fileutils.c | 35 +++++++++++++++++++++++++++++++++-- client/loclass/fileutils.h | 1 + 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/client/loclass/fileutils.c b/client/loclass/fileutils.c index 44bab0193..ac3660935 100644 --- a/client/loclass/fileutils.c +++ b/client/loclass/fileutils.c @@ -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) { diff --git a/client/loclass/fileutils.h b/client/loclass/fileutils.h index 40bd7cfeb..0893e01ea 100644 --- a/client/loclass/fileutils.h +++ b/client/loclass/fileutils.h @@ -47,6 +47,7 @@ #include #include #include "../ui.h" +#include "../emv/emvjson.h" int fileExists(const char *filename);