From 1cb18df8b4dfd2ec98ca6697b5efb9381e1d2f40 Mon Sep 17 00:00:00 2001 From: Khairul Azhar Kasmiran Date: Sat, 30 May 2020 01:31:22 +0800 Subject: [PATCH] ahi 10 does signed decimal with 32-bit gp regs + ahi 10u for unsigned decimal (#16970) * ahi 10 does signed decimal with x86 32-bit regs + ahi 10u for unsigned decimal * Use arch-independent r_reg api instead --- libr/core/cmd_anal.c | 31 +++++++++++++++------------ libr/parse/filter.c | 21 ++++++++++++++++++- test/db/cmd/cmd_ahi | 50 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 14 deletions(-) diff --git a/libr/core/cmd_anal.c b/libr/core/cmd_anal.c index b6243521c4..3b1cd38fcd 100644 --- a/libr/core/cmd_anal.c +++ b/libr/core/cmd_anal.c @@ -580,7 +580,7 @@ static const char *help_msg_ah[] = { "ahf", " 0x804840", "override fallback address for call", "ahF", " 0x10", "set stackframe size at current offset", "ahh", " 0x804840", "highlight this address offset in disasm", - "ahi", "[?] 10", "define numeric base for immediates (2, 8, 10, 16, i, p, S, s)", + "ahi", "[?] 10", "define numeric base for immediates (2, 8, 10, 10u, 16, i, p, S, s)", "ahj", "", "list hints in JSON", "aho", " call", "change opcode type (see aho?) (deprecated, moved to \"ahd\")", "ahp", " addr", "set pointer hint", @@ -593,11 +593,12 @@ static const char *help_msg_ah[] = { }; static const char *help_msg_ahi[] = { - "Usage:", "ahi [2|8|10|16|bodhipSs] [@ offset]", " Define numeric base", + "Usage:", "ahi [2|8|10|10u|16|bodhipSs] [@ offset]", " Define numeric base", "ahi", " ", "set numeric base (2, 8, 10, 16)", + "ahi", " 10|d", "set base to signed decimal (10), sign bit should depend on receiver size", + "ahi", " 10u|du", "set base to unsigned decimal (11)", "ahi", " b", "set base to binary (2)", "ahi", " o", "set base to octal (8)", - "ahi", " d", "set base to decimal (10)", "ahi", " h", "set base to hexadecimal (16)", "ahi", " i", "set base to IP address (32)", "ahi", " p", "set base to htons(port) (3)", @@ -7615,16 +7616,20 @@ static void cmd_anal_hint(RCore *core, const char *input) { } if (input[1] == ' ') { // You can either specify immbase with letters, or numbers - const int base = - (input[2] == 's') ? 1 : - (input[2] == 'b') ? 2 : - (input[2] == 'p') ? 3 : - (input[2] == 'o') ? 8 : - (input[2] == 'd') ? 10 : - (input[2] == 'h') ? 16 : - (input[2] == 'i') ? 32 : // ip address - (input[2] == 'S') ? 80 : // syscall - (int) r_num_math (core->num, input + 1); + int base; + if (r_str_startswith (input + 2, "10u") || r_str_startswith (input + 2, "du")) { + base = 11; + } else { + base = (input[2] == 's') ? 1 : + (input[2] == 'b') ? 2 : + (input[2] == 'p') ? 3 : + (input[2] == 'o') ? 8 : + (input[2] == 'd') ? 10 : + (input[2] == 'h') ? 16 : + (input[2] == 'i') ? 32 : // ip address + (input[2] == 'S') ? 80 : // syscall + (int) r_num_math (core->num, input + 1); + } r_anal_hint_set_immbase (core->anal, core->offset, base); } else if (input[1] != '?' && input[1] != '-') { eprintf ("|ERROR| Usage: ahi \n"); diff --git a/libr/parse/filter.c b/libr/parse/filter.c index 8b1bd232b4..5f08fae823 100644 --- a/libr/parse/filter.c +++ b/libr/parse/filter.c @@ -479,7 +479,26 @@ static bool filter(RParse *p, ut64 addr, RFlag *f, RAnalHint *hint, char *data, snprintf (num, sizeof (num), "0%o", (int)off); break; case 10: - snprintf (num, sizeof (num), "%" PFMT64d, (st64)off); + { + RList *regs = r_reg_get_list (p->analb.anal->reg, R_REG_TYPE_GPR); + RRegItem *reg; + RListIter *iter; + bool imm32 = false; + r_list_foreach (regs, iter, reg) { + if (reg->size == 32 && r_str_casestr (data, reg->name)) { + imm32 = true; + break; + } + } + if (imm32) { + snprintf (num, sizeof (num), "%"PFMT32d, (st32)off); + break; + } + snprintf (num, sizeof (num), "%"PFMT64d, (st64)off); + } + break; + case 11: + snprintf (num, sizeof (num), "%"PFMT64u, off); break; case 32: { diff --git a/test/db/cmd/cmd_ahi b/test/db/cmd/cmd_ahi index 879eca9c4a..3ecf4343e6 100644 --- a/test/db/cmd/cmd_ahi +++ b/test/db/cmd/cmd_ahi @@ -357,3 +357,53 @@ EXPECT=<