From: pwpiwi Date: Sat, 4 Mar 2017 11:48:37 +0000 (+0100) Subject: Merge pull request #221 from jamchamb/clean-mfu-dump X-Git-Tag: v3.0.0~61 X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/commitdiff_plain/23bd68f94403a60a33b8d55b5a61f00ba53c2544?hp=f76d6fae10cc472dd874f71da353272069a53d01 Merge pull request #221 from jamchamb/clean-mfu-dump Clean mfu dump output --- diff --git a/client/cmdhfmfu.c b/client/cmdhfmfu.c index 25a073d3..b7cf0fcd 100644 --- a/client/cmdhfmfu.c +++ b/client/cmdhfmfu.c @@ -7,6 +7,7 @@ //----------------------------------------------------------------------------- // High frequency MIFARE ULTRALIGHT (C) commands //----------------------------------------------------------------------------- +#include #include "loclass/des.h" #include "cmdhfmfu.h" #include "cmdhfmf.h" @@ -1230,6 +1231,7 @@ int CmdHF14AMfUDump(const char *Cmd){ bool manualPages = false; uint8_t startPage = 0; char tempStr[50]; + unsigned char cleanASCII[4]; while(param_getchar(Cmd, cmdp) != 0x00) { @@ -1372,7 +1374,7 @@ int CmdHF14AMfUDump(const char *Cmd){ PrintAndLog("---------------------------------"); for (i = 0; i < Pages; ++i) { if ( i < 3 ) { - PrintAndLog("%02d/0x%02X | %s| | ", i+startPage, i+startPage, sprint_hex(data + i * 4, 4)); + PrintAndLog("%3d/0x%02X | %s| | ", i+startPage, i+startPage, sprint_hex(data + i * 4, 4)); continue; } switch(i){ @@ -1419,7 +1421,12 @@ int CmdHF14AMfUDump(const char *Cmd){ case 43: tmplockbit = bit2[9]; break; //auth1 default: break; } - PrintAndLog("%02d/0x%02X | %s| %d | %.4s", i+startPage, i+startPage, sprint_hex(data + i * 4, 4), tmplockbit, data+i*4); + + // convert unprintable characters and line breaks to dots + memcpy(cleanASCII, data+i*4, 4); + clean_ascii(cleanASCII, 4); + + PrintAndLog("%3d/0x%02X | %s| %d | %.4s", i+startPage, i+startPage, sprint_hex(data + i * 4, 4), tmplockbit, cleanASCII); } PrintAndLog("---------------------------------"); diff --git a/client/util.c b/client/util.c index 374ae397..e80f5cc9 100644 --- a/client/util.c +++ b/client/util.c @@ -8,6 +8,7 @@ // utilities //----------------------------------------------------------------------------- +#include #include "util.h" #define MAX_BIN_BREAK_LENGTH (3072+384+1) @@ -581,3 +582,12 @@ void rol(uint8_t *data, const size_t len){ } data[len-1] = first; } + + +// Replace unprintable characters with a dot in char buffer +void clean_ascii(unsigned char *buf, size_t len) { + for (size_t i = 0; i < len; i++) { + if (!isprint(buf[i])) + buf[i] = '.'; + } +} diff --git a/client/util.h b/client/util.h index 8c0ed950..fde06540 100644 --- a/client/util.h +++ b/client/util.h @@ -76,3 +76,5 @@ void xor(unsigned char *dst, unsigned char *src, size_t len); int32_t le24toh(uint8_t data[3]); uint32_t le32toh (uint8_t *data); void rol(uint8_t *data, const size_t len); + +void clean_ascii(unsigned char *buf, size_t len);