Mercurial > dropbear
comparison dbutil.c @ 1764:a339b1c4b9f2
Print ascii in printhex too
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Mon, 26 Oct 2020 22:51:44 +0800 |
parents | dfbe947bdf0d |
children | 870f6e386a0b |
comparison
equal
deleted
inserted
replaced
1760:2406a9987810 | 1764:a339b1c4b9f2 |
---|---|
383 execv(usershell, argv); | 383 execv(usershell, argv); |
384 } | 384 } |
385 | 385 |
386 #if DEBUG_TRACE | 386 #if DEBUG_TRACE |
387 void printhex(const char * label, const unsigned char * buf, int len) { | 387 void printhex(const char * label, const unsigned char * buf, int len) { |
388 | 388 int i, j; |
389 int i; | |
390 | 389 |
391 fprintf(stderr, "%s\n", label); | 390 fprintf(stderr, "%s\n", label); |
392 for (i = 0; i < len; i++) { | 391 /* for each 16 byte line */ |
393 fprintf(stderr, "%02x", buf[i]); | 392 for (j = 0; j < len; j += 16) { |
394 if (i % 16 == 15) { | 393 const int linelen = MIN(16, len - j); |
395 fprintf(stderr, "\n"); | 394 |
396 } | 395 /* print hex digits */ |
397 else if (i % 2 == 1) { | 396 for (i = 0; i < 16; i++) { |
398 fprintf(stderr, " "); | 397 if (i < linelen) { |
399 } | 398 fprintf(stderr, "%02x", buf[j+i]); |
400 } | 399 } else { |
401 fprintf(stderr, "\n"); | 400 fprintf(stderr, " "); |
401 } | |
402 // separator between pairs | |
403 if (i % 2 ==1) { | |
404 fprintf(stderr, " "); | |
405 } | |
406 } | |
407 | |
408 /* print characters */ | |
409 fprintf(stderr, " "); | |
410 for (i = 0; i < linelen; i++) { | |
411 char c = buf[j+i]; | |
412 if (!isprint(c)) { | |
413 c = '.'; | |
414 } | |
415 fputc(c, stderr); | |
416 } | |
417 fprintf(stderr, "\n"); | |
418 } | |
402 } | 419 } |
403 | 420 |
404 void printmpint(const char *label, mp_int *mp) { | 421 void printmpint(const char *label, mp_int *mp) { |
405 buffer *buf = buf_new(1000); | 422 buffer *buf = buf_new(1000); |
406 buf_putmpint(buf, mp); | 423 buf_putmpint(buf, mp); |