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
This commit is contained in:
parent
18649ad666
commit
1cb18df8b4
3 changed files with 88 additions and 14 deletions
|
|
@ -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", " <base>", "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 <base>\n");
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
{
|
||||
|
|
|
|||
|
|
@ -357,3 +357,53 @@ EXPECT=<<EOF
|
|||
0x00000000 mov dword [rbp - 0x78], 16762435
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=ahi 10 and 10u imm (x86_32)
|
||||
ARGS=-a x86 -b 32
|
||||
FILE=-
|
||||
CMDS=<<EOF
|
||||
e asm.bytes=false
|
||||
"wa cmp eax, -1"
|
||||
pd 1
|
||||
ahi 10
|
||||
pd 1
|
||||
ahi 10u
|
||||
pd 1
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
0x00000000 cmp eax, 0xffffffff
|
||||
0x00000000 cmp eax, -1
|
||||
0x00000000 cmp eax, 4294967295
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=ahi 10 and 10u imm (x86_64)
|
||||
ARGS=-a x86 -b 64
|
||||
FILE=-
|
||||
CMDS=<<EOF
|
||||
e asm.bytes=false
|
||||
"wa cmp eax, -1"
|
||||
pd 1
|
||||
ahi 10
|
||||
pd 1
|
||||
ahi 10u
|
||||
pd 1
|
||||
?e
|
||||
ah-
|
||||
"wa cmp rax, -1"
|
||||
pd 1
|
||||
ahi 10
|
||||
pd 1
|
||||
ahi 10u
|
||||
pd 1
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
0x00000000 cmp eax, 0xffffffff
|
||||
0x00000000 cmp eax, -1
|
||||
0x00000000 cmp eax, 4294967295
|
||||
|
||||
0x00000000 cmp rax, 0xffffffffffffffff
|
||||
0x00000000 cmp rax, -1
|
||||
0x00000000 cmp rax, 18446744073709551615
|
||||
EOF
|
||||
RUN
|
||||
|
|
|
|||
Loading…
Reference in a new issue