Add RAnal.Stack.RESET and handle it for arm64

This commit is contained in:
pancake 2016-05-11 12:59:32 +02:00
parent 45093ffb49
commit 3d89f2cc21
4 changed files with 23 additions and 2 deletions

View File

@ -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";
}

View File

@ -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:

View File

@ -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)

View File

@ -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,
};