From: iceman1001 Date: Mon, 16 Jan 2017 13:47:24 +0000 (+0100) Subject: ADD: sprint_ascii function. X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/commitdiff_plain/1cc80785e55ed476b817b806ea8d6028367a4f7e?ds=sidebyside ADD: sprint_ascii function. --- diff --git a/client/util.c b/client/util.c index c07981fe..76c8d6d8 100644 --- a/client/util.c +++ b/client/util.c @@ -196,6 +196,20 @@ char *sprint_hex_ascii(const uint8_t *data, const size_t len) { return buf; } +char *sprint_ascii(const uint8_t *data, const size_t len) { + static char buf[1024]; + char *tmp = buf; + memset(buf, 0x00, 1024); + size_t max_len = (len > 1010) ? 1010 : len; + size_t i = 0; + while(i < max_len){ + char c = data[i]; + tmp[i] = ((c < 32) || (c == 127)) ? '.' : c; + ++i; + } + return buf; +} + void num_to_bytes(uint64_t n, size_t len, uint8_t* dest) { while (len--) { dest[len] = n & 0xFF; diff --git a/client/util.h b/client/util.h index 701662c3..b158ec0a 100644 --- a/client/util.h +++ b/client/util.h @@ -105,6 +105,7 @@ char *sprint_hex(const uint8_t * data, const size_t len); char *sprint_bin(const uint8_t * data, const size_t len); char *sprint_bin_break(const uint8_t *data, const size_t len, const uint8_t breaks); char *sprint_hex_ascii(const uint8_t *data, const size_t len); +char *sprint_ascii(const uint8_t *data, const size_t len); void num_to_bytes(uint64_t n, size_t len, uint8_t* dest); uint64_t bytes_to_num(uint8_t* src, size_t len);