From 3d26b00fce20b80b423f7c15e1975eb50166fc5e Mon Sep 17 00:00:00 2001 From: Dmitry Timoshkov Date: Tue, 10 Jul 2018 11:41:54 +0800 Subject: [PATCH] winedump: Use common binary dumper for typelib. This is an adapted code from dump.c. Signed-off-by: Dmitry Timoshkov Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- tools/winedump/tlb.c | 52 +++++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/tools/winedump/tlb.c b/tools/winedump/tlb.c index d2883598d7b..5d009fcedbe 100644 --- a/tools/winedump/tlb.c +++ b/tools/winedump/tlb.c @@ -283,25 +283,47 @@ static void print_ctl2(const char *name) printf("\n"); } -static void dump_binary(int n) +static int tlb_isprint(unsigned char c) { - int i; + return c >= 32; +} - for(i = 1; i <= n; i++) { - switch(i & 0x0f) { - case 0: - printf("%02x\n", tlb_read_byte()); - break; - case 1: - print_offset(); - /* fall through */ - default: - printf("%02x ", tlb_read_byte()); +static void dump_binary(int size) +{ + const unsigned char *ptr; + int i, j; + + if (!size) return; + + ptr = tlb_read(size); + if (!ptr) return; + + print_offset(); + printf("%08x: ", offset - size); + + for (i = 0; i < size; i++) + { + printf("%02x%c", ptr[i], (i % 16 == 7) ? '-' : ' '); + if ((i % 16) == 15) + { + printf( " " ); + for (j = 0; j < 16; j++) + printf("%c", tlb_isprint(ptr[i-15+j]) ? ptr[i-15+j] : '.'); + if (i < size-1) + { + printf("\n"); + print_offset(); + printf("%08x: ", offset - size + i + 1); + } } } - - if(n&0x0f) - printf("\n"); + if (i % 16) + { + printf("%*s ", 3 * (16-(i%16)), ""); + for (j = 0; j < i % 16; j++) + printf("%c", tlb_isprint(ptr[i-(i%16)+j]) ? ptr[i-(i%16)+j] : '.'); + } + printf("\n"); } static int dump_msft_varflags(void)