summaryrefslogtreecommitdiff
path: root/utils/imxtools/sbtools/sb.c
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2013-08-06 19:30:05 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2013-08-06 21:24:38 +0200
commitc0aba07f1a4221e0aee10f7fddc47dde29e5282e (patch)
tree6c19e8b1b61ebbb620efdadd01370aeb0d1ea6ec /utils/imxtools/sbtools/sb.c
parent97459def3c34d338d3ced9bd2b55f8902573aa19 (diff)
downloadrockbox-c0aba07f1a4221e0aee10f7fddc47dde29e5282e.tar.gz
rockbox-c0aba07f1a4221e0aee10f7fddc47dde29e5282e.zip
sbtools: fix output printing
The code used printf instead of the provided printf functions, resulting in strange output. Change-Id: I2c7c2531d8d54ecdea97e8c189d18d351320ca7d
Diffstat (limited to 'utils/imxtools/sbtools/sb.c')
-rw-r--r--utils/imxtools/sbtools/sb.c29
1 files changed, 25 insertions, 4 deletions
diff --git a/utils/imxtools/sbtools/sb.c b/utils/imxtools/sbtools/sb.c
index df3622940f..218ea5a6f7 100644
--- a/utils/imxtools/sbtools/sb.c
+++ b/utils/imxtools/sbtools/sb.c
@@ -674,6 +674,25 @@ struct sb_file_t *sb_read_file_ex(const char *filename, size_t offset, size_t si
674 #undef fatal 674 #undef fatal
675} 675}
676 676
677struct printer_t
678{
679 void *user;
680 sb_color_printf cprintf;
681 const char *color;
682 bool error;
683};
684
685static void sb_printer(void *user, const char *fmt, ...)
686{
687 struct printer_t *p = user;
688 va_list args;
689 va_start(args, fmt);
690 char buffer[1024];
691 vsnprintf(buffer, sizeof(buffer), fmt, args);
692 p->cprintf(p->user, p->error, p->color, "%s", buffer);
693 va_end(args);
694}
695
677struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, bool raw_mode, void *u, 696struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, bool raw_mode, void *u,
678 sb_color_printf cprintf, enum sb_error_t *err) 697 sb_color_printf cprintf, enum sb_error_t *err)
679{ 698{
@@ -686,8 +705,9 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, bool raw_mode, voi
686 cprintf(u, true, GREY, __VA_ARGS__); \ 705 cprintf(u, true, GREY, __VA_ARGS__); \
687 sb_free(sb_file); \ 706 sb_free(sb_file); \
688 return NULL; } while(0) 707 return NULL; } while(0)
708 struct printer_t printer = {.user = u, .cprintf = cprintf, .color = OFF, .error = false };
689 #define print_hex(c, p, len, nl) \ 709 #define print_hex(c, p, len, nl) \
690 do { printf(c, ""); print_hex(p, len, nl); } while(0) 710 do { printer.color = c; print_hex(&printer, sb_printer, p, len, nl); } while(0)
691 711
692 struct sha_1_params_t sha_1_params; 712 struct sha_1_params_t sha_1_params;
693 sb_file = xmalloc(sizeof(struct sb_file_t)); 713 sb_file = xmalloc(sizeof(struct sb_file_t));
@@ -798,8 +818,8 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, bool raw_mode, voi
798 { 818 {
799 printf(RED, " Key %d\n", i), 819 printf(RED, " Key %d\n", i),
800 printf(GREEN, " Key: "); 820 printf(GREEN, " Key: ");
801 printf(YELLOW, ""); 821 printer.color = YELLOW;
802 print_key(&g_key_array[i], true); 822 print_key(&printer, sb_printer, &g_key_array[i], true);
803 printf(GREEN, " CBC-MAC: "); 823 printf(GREEN, " CBC-MAC: ");
804 /* check it */ 824 /* check it */
805 byte zero[16]; 825 byte zero[16];
@@ -1137,8 +1157,9 @@ void sb_free(struct sb_file_t *file)
1137void sb_dump(struct sb_file_t *file, void *u, sb_color_printf cprintf) 1157void sb_dump(struct sb_file_t *file, void *u, sb_color_printf cprintf)
1138{ 1158{
1139 #define printf(c, ...) cprintf(u, false, c, __VA_ARGS__) 1159 #define printf(c, ...) cprintf(u, false, c, __VA_ARGS__)
1160 struct printer_t printer = {.user = u, .cprintf = cprintf, .color = OFF, .error = false };
1140 #define print_hex(c, p, len, nl) \ 1161 #define print_hex(c, p, len, nl) \
1141 do { printf(c, ""); print_hex(p, len, nl); } while(0) 1162 do { printer.color = c; print_hex(&printer, sb_printer, p, len, nl); } while(0)
1142 1163
1143 #define TREE RED 1164 #define TREE RED
1144 #define HEADER GREEN 1165 #define HEADER GREEN