diff --git a/libr/anal/op.c b/libr/anal/op.c index 04f2d68896..7d148daa24 100644 --- a/libr/anal/op.c +++ b/libr/anal/op.c @@ -418,6 +418,8 @@ R_API const char *r_anal_stackop_tostring (int s) { return "get"; case R_ANAL_STACK_SET: return "set"; + case R_ANAL_STACK_RESET: + return "reset"; } return "unk"; } diff --git a/libr/anal/p/anal_arm_cs.c b/libr/anal/p/anal_arm_cs.c index c955add0de..2babd4a50b 100644 --- a/libr/anal/p/anal_arm_cs.c +++ b/libr/anal/p/anal_arm_cs.c @@ -855,6 +855,15 @@ static void anop64 (RAnalOp *op, cs_insn *insn) { break; case ARM64_INS_SUB: op->type = R_ANAL_OP_TYPE_SUB; + if (REGID64(0) == ARM64_REG_SP) { + if (REGID64(1) == ARM64_REG_SP) { + op->stackop = R_ANAL_STACK_INC; + op->stackptr = IMM64(2); + } else { + op->stackop = R_ANAL_STACK_RESET; + op->stackptr = 0; + } + } break; case ARM64_INS_ADD: op->type = R_ANAL_OP_TYPE_ADD; @@ -864,6 +873,11 @@ static void anop64 (RAnalOp *op, cs_insn *insn) { op->type = R_ANAL_OP_TYPE_CMOV; break; case ARM64_INS_MOV: + if (REGID64(0) == ARM64_REG_SP) { + op->stackop = R_ANAL_STACK_RESET; + op->stackptr = 0; + } + /* fallthru */ case ARM64_INS_MOVI: case ARM64_INS_MOVK: case ARM64_INS_MOVN: diff --git a/libr/core/disasm.c b/libr/core/disasm.c index e775590de6..1a01f42ec4 100644 --- a/libr/core/disasm.c +++ b/libr/core/disasm.c @@ -1425,12 +1425,16 @@ static void handle_print_cycles(RCore *core, RDisasmState *ds) { static void handle_print_stackptr(RCore *core, RDisasmState *ds) { if (ds->show_stackptr) { r_cons_printf ("%5d%s", ds->stackptr, - ds->analop.type==R_ANAL_OP_TYPE_CALL?">": + ds->analop.type == R_ANAL_OP_TYPE_CALL?">": ds->analop.stackop == R_ANAL_STACK_ALIGN? "=": ds->stackptr > ds->ostackptr? "+": ds->stackptr < ds->ostackptr? "-": " "); ds->ostackptr = ds->stackptr; - ds->stackptr += ds->analop.stackptr; + if (ds->analop.stackop == R_ANAL_STACK_RESET) { + ds->stackptr = 0; + } else { + ds->stackptr += ds->analop.stackptr; + } /* XXX if we reset the stackptr 'ret 0x4' has not effect. * Use RAnalFunction->RAnalOp->stackptr? */ if (ds->analop.type == R_ANAL_OP_TYPE_RET) diff --git a/libr/include/r_anal.h b/libr/include/r_anal.h index 71fd5a0018..8486cb23dc 100644 --- a/libr/include/r_anal.h +++ b/libr/include/r_anal.h @@ -526,6 +526,7 @@ enum { R_ANAL_STACK_INC, R_ANAL_STACK_GET, R_ANAL_STACK_SET, + R_ANAL_STACK_RESET, R_ANAL_STACK_ALIGN, };