From 39eecc917e09cd03c10c3063af19067dd0f6f42e Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 27 Jul 2023 19:38:51 +0200 Subject: [PATCH] improved the messages reported when loading json files fails. Usually because we have reserved the wrong size memory --- client/src/cmdhfmf.c | 12 ++++++------ client/src/fileutils.c | 19 ++++++++++++------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/client/src/cmdhfmf.c b/client/src/cmdhfmf.c index 10e305912..92001d760 100644 --- a/client/src/cmdhfmf.c +++ b/client/src/cmdhfmf.c @@ -4318,13 +4318,17 @@ int CmdHF14AMfELoad(const char *Cmd) { return PM3_EINVARG; } - PrintAndLogEx(INFO, "%d blocks ( %u bytes ) to upload", block_cnt, block_cnt * block_width); + PrintAndLogEx(INFO, "Upload " _YELLOW_("%u") " blocks " _YELLOW_("%u") " bytes", block_cnt, block_cnt * block_width); if (numblks > 0) { block_cnt = MIN(numblks, block_cnt); - PrintAndLogEx(INFO, "overriding number of blocks, will use %d blocks ( %u bytes )", block_cnt, block_cnt * block_width); + PrintAndLogEx(INFO, "overriding number of blocks, will use " _YELLOW_("%u") " blocks " _YELLOW_("%u") " bytes", block_cnt, block_cnt * block_width); } + // ICEMAN: bug. if device has been using ICLASS commands, + // the device needs to load the HF fpga image. It takes 1.5 second. + set_fpga_mode(2); + // use RDV4 spiffs if (use_spiffs && IfPm3Flash() == false) { PrintAndLogEx(WARNING, "Device not compiled to support spiffs"); @@ -4355,10 +4359,6 @@ int CmdHF14AMfELoad(const char *Cmd) { return PM3_SUCCESS; } - // ICEMAN: bug. if device has been using ICLASS commands, - // the device needs to load the HF fpga image. It takes 1.5 second. - set_fpga_mode(2); - uint8_t *data = NULL; size_t bytes_read = 0; int res = pm3_load_dump(filename, (void **)&data, &bytes_read, (block_width * block_cnt + hdr_len)); diff --git a/client/src/fileutils.c b/client/src/fileutils.c index 9a56b4eba..1aa27ca7f 100644 --- a/client/src/fileutils.c +++ b/client/src/fileutils.c @@ -2085,6 +2085,9 @@ int pm3_load_dump(const char *fn, void **pdump, size_t *dumplen, size_t maxdumpl } case EML: { res = loadFileEML_safe(fn, pdump, dumplen); + if (res == PM3_ESOFT) { + PrintAndLogEx(WARNING, "file IO failed"); + } break; } case JSON: { @@ -2094,8 +2097,15 @@ int pm3_load_dump(const char *fn, void **pdump, size_t *dumplen, size_t maxdumpl return PM3_EMALLOC; } res = loadFileJSON(fn, *pdump, maxdumplen, dumplen, NULL); - if (res != PM3_SUCCESS) { - free(*pdump); + if (res == PM3_SUCCESS) + return res; + + free(*pdump); + + if (res == PM3_ESOFT) { + PrintAndLogEx(WARNING, "JSON objects failed to load"); + } else if (res == PM3_EMALLOC) { + PrintAndLogEx(WARNING, "Wrong size of allocated memory. Check your parameters"); } break; } @@ -2109,11 +2119,6 @@ int pm3_load_dump(const char *fn, void **pdump, size_t *dumplen, size_t maxdumpl } } - if (res != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "file not found or locked `" _YELLOW_("%s") "`", fn); - return PM3_EFILE; - } - return res; }