From 600004fecca1475a094d392286435056a67cdc58 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Tue, 21 Feb 2017 11:37:35 +0100 Subject: [PATCH] print ascii in print_hex() --- testprof/x86_prof.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/testprof/x86_prof.c b/testprof/x86_prof.c index 451a58c..f2bb914 100644 --- a/testprof/x86_prof.c +++ b/testprof/x86_prof.c @@ -5,15 +5,34 @@ prng_state yarrow_prng; void print_hex(const char* what, const void* v, const unsigned long l) { const unsigned char* p = v; - unsigned long x; + unsigned long x, y = 0, z; fprintf(stderr, "%s contents: \n", what); for (x = 0; x < l; ) { - fprintf(stderr, "%02x ", p[x]); - if (!(++x % 16)) { + fprintf(stderr, "%02X ", p[x]); + if (!(++x % 16) || x == l) { + if((x % 16) != 0) { + z = 16 - (x % 16); + if(z >= 8) + fprintf(stderr, " "); + for (; z != 0; --z) { + fprintf(stderr, " "); + } + } + fprintf(stderr, " | "); + for(; y < x; y++) { + if((y % 8) == 0) + fprintf(stderr, " "); + if(isgraph(p[y])) + fprintf(stderr, "%c", p[y]); + else + fprintf(stderr, "."); + } fprintf(stderr, "\n"); } + else if((x % 8) == 0) { + fprintf(stderr, " "); + } } - fprintf(stderr, "\n"); } int compare_testvector(const void* is, const unsigned long is_len, const void* should, const unsigned long should_len, const char* what, int which)