From a934a39236b3604e0e6ecebbee2b3b4d9c16bf06 Mon Sep 17 00:00:00 2001 From: Khairul Azhar Kasmiran Date: Mon, 8 Jun 2020 19:29:21 +0800 Subject: [PATCH] pfc: Support n# (#17011) ##print --- libr/util/format.c | 11 ++++++----- test/db/cmd/cmd_pf2 | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/libr/util/format.c b/libr/util/format.c index a2c2ca8408..817bbcc49b 100644 --- a/libr/util/format.c +++ b/libr/util/format.c @@ -1869,19 +1869,20 @@ static char *get_format_type(const char fmt, const char arg) { case 'Z': type = strdup ("char*"); break; + case 'n': case 'N': switch (arg) { case '1': - type = strdup ("uint8_t"); + type = strdup (fmt == 'n' ? "int8_t" : "uint8_t"); break; case '2': - type = strdup ("uint16_t"); + type = strdup (fmt == 'n' ? "int16_t" : "uint16_t"); break; case '4': - type = strdup ("uint32_t"); + type = strdup (fmt == 'n' ? "int32_t" : "uint32_t"); break; case '8': - type = strdup ("uint64_t"); + type = strdup (fmt == 'n' ? "int64_t" : "uint64_t"); break; } break; @@ -2326,7 +2327,7 @@ R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len, /* c struct */ if (MUSTSEESTRUCT) { - char *type = get_format_type (tmp, tmp == 'N' ? arg[1] : 0); // TODO tmp == 'n' + char *type = get_format_type (tmp, (tmp == 'n' || tmp == 'N') ? arg[1] : 0); if (type) { p->cb_printf ("%*c%s %s; // ", ident, ' ', type, fieldname); } else { diff --git a/test/db/cmd/cmd_pf2 b/test/db/cmd/cmd_pf2 index 9ef8d91b05..6de83048ba 100644 --- a/test/db/cmd/cmd_pf2 +++ b/test/db/cmd/cmd_pf2 @@ -498,3 +498,32 @@ EXPECT=<