diff options
author | szszszsz <szszszsz@users.noreply.github.com> | 2016-11-26 19:51:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-26 19:51:11 +0100 |
commit | f60f2cf0144a91769a5fc00fac1314d2e00cdf0d (patch) | |
tree | ad2a4513b1ad01b225a519ac10cafa3e583a26a1 /misc.cc | |
parent | d841239bc9ece1ce969c293783219cceb001fc67 (diff) | |
parent | cdd16f3f184b2745094da39de3f815aea6633fdb (diff) | |
download | libnitrokey-f60f2cf0144a91769a5fc00fac1314d2e00cdf0d.tar.gz libnitrokey-f60f2cf0144a91769a5fc00fac1314d2e00cdf0d.tar.bz2 |
Merge pull request #52 from Nitrokey/14-storage_commands
Support Nitrokey Storage
Diffstat (limited to 'misc.cc')
-rw-r--r-- | misc.cc | 21 |
1 files changed, 18 insertions, 3 deletions
@@ -34,6 +34,7 @@ std::vector<uint8_t> hex_string_to_byte(const char* hexString){ return data; }; +#include <cctype> std::string hexdump(const char *p, size_t size, bool print_header) { std::stringstream out; char formatbuf[128]; @@ -45,9 +46,23 @@ std::string hexdump(const char *p, size_t size, bool print_header) { out << formatbuf; } - for (const char *le = p + 16; p < le && p < pend; p++) { - snprintf(formatbuf, 128, "%02x ", uint8_t(*p)); - out << formatbuf; + const char* pp = p; + for (const char *le = p + 16; p < le; p++) { + if (p < pend){ + snprintf(formatbuf, 128, "%02x ", uint8_t(*p)); + out << formatbuf; + } else { + out << "-- "; + } + + } + out << "\t"; + + for (const char *le = pp + 16; pp < le && pp < pend; pp++) { + if (std::isgraph(*pp)) + out << uint8_t(*pp); + else + out << '.'; } out << std::endl; } |