From 46bf5297633d0b3964db75cf161c65a8b64f64ba Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 15 Apr 2021 18:27:24 +0200 Subject: [PATCH] change 'hf 15 restore' now supports EML/JSON --- CHANGELOG.md | 2 ++ client/src/cmdhf15.c | 34 +++++++++++++++++++++++++++++++--- client/src/fileutils.c | 4 ++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b51667f04..5c9b851a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] + - Change `hf 15 restore` - now also support EML/JSON (@iceman1001) + - Change - all commands now use cliparser (@iceman1001) - Change `lf t55xx restore` - now also support JSON (@iceman1001) - Change `hf mf csetuid` - adapted to accept 7byte uids. ~untested~ (@iceman1001) - Added `hf mf view/eload/cload` - now accepts bin/eml/json (@iceman1001) diff --git a/client/src/cmdhf15.c b/client/src/cmdhf15.c index e7be38aa1..9b1f9be52 100644 --- a/client/src/cmdhf15.c +++ b/client/src/cmdhf15.c @@ -1982,10 +1982,38 @@ static int CmdHF15Restore(const char *Cmd) { } PrintAndLogEx(INFO, "Using block size... %zu", blocksize); + // 4bytes * 256 blocks. Should be enough.. + uint8_t *data = calloc(4 * 256, sizeof(uint8_t)); + if (data == NULL) { + PrintAndLogEx(WARNING, "Fail, cannot allocate memory"); + return PM3_EMALLOC; + } + size_t datalen = 0; - uint8_t *data = NULL; - if (loadFile_safe(filename, ".bin", (void **)&data, &datalen) != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "could not find file " _YELLOW_("%s"), filename); + int res = PM3_SUCCESS; + DumpFileType_t dftype = getfiletype(filename); + switch (dftype) { + case BIN: { + res = loadFile_safe(filename, ".bin", (void **)&data, &datalen); + break; + } + case EML: { + res = loadFileEML_safe(filename, (void **)&data, &datalen); + break; + } + case JSON: { + res = loadFileJSON(filename, data, 256 * 4, &datalen, NULL); + break; + } + case DICTIONARY: { + PrintAndLogEx(ERR, "Error: Only BIN/JSON/EML formats allowed"); + free(data); + return PM3_EINVARG; + } + } + + if (res != PM3_SUCCESS) { + free(data); return PM3_EFILE; } diff --git a/client/src/fileutils.c b/client/src/fileutils.c index 24538497e..45185ea71 100644 --- a/client/src/fileutils.c +++ b/client/src/fileutils.c @@ -1210,6 +1210,10 @@ int loadFileJSONex(const char *preferredName, void *data, size_t maxdatalen, siz *datalen = sptr; } + if (!strcmp(ctype, "15693")) { + JsonLoadBufAsHex(root, "$.raw", udata, maxdatalen, datalen); + } + out: if (callback != NULL) {