Skip to content

Commit

Permalink
Set POP return info if it writes to PC
Browse files Browse the repository at this point in the history
  • Loading branch information
Rot127 committed Dec 12, 2023
1 parent 96038ea commit 9a1c413
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions librz/analysis/p/analysis_arm_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,17 @@ static void anop64(ArmCSContext *ctx, RzAnalysisOp *op, cs_insn *insn) {
}
}

/**
* \brief Checks if a given intruction is a POP instruction which returns (writes to PC)
* and sets the analysis op data accordingly.
*/
inline static void set_pop_ret_info(const cs_insn *insn, RZ_BORROW RzAnalysisOp *op) {
if (rz_arm_cs_is_group_member(insn, ARM_GRP_RET)) {
op->eob = true;
op->type = RZ_ANALYSIS_OP_TYPE_RET;
}
}

static void anop32(RzAnalysis *a, csh handle, RzAnalysisOp *op, cs_insn *insn, bool thumb, const ut8 *buf, int len) {
ArmCSContext *ctx = (ArmCSContext *)a->plugin_data;
const ut64 addr = op->addr;
Expand Down Expand Up @@ -1261,6 +1272,7 @@ jmp $$ + 4 + ( [delta] * 2 )
op->type = RZ_ANALYSIS_OP_TYPE_POP;
op->stackop = RZ_ANALYSIS_STACK_DEC;
op->stackptr = -4LL * insn->detail->arm.op_count;
set_pop_ret_info(insn, op);
// fallthrough
case ARM_INS_FLDMDBX:
case ARM_INS_FLDMIAX:
Expand All @@ -1273,6 +1285,7 @@ jmp $$ + 4 + ( [delta] * 2 )
op->type = RZ_ANALYSIS_OP_TYPE_POP;
op->stackop = RZ_ANALYSIS_STACK_DEC;
op->stackptr = -4LL * (insn->detail->arm.op_count - 1);
set_pop_ret_info(insn, op);
break;
}
#endif
Expand Down Expand Up @@ -1530,6 +1543,7 @@ jmp $$ + 4 + ( [delta] * 2 )
op->type = RZ_ANALYSIS_OP_TYPE_POP;
op->stackop = RZ_ANALYSIS_STACK_DEC;
op->stackptr = -4LL * (insn->detail->arm.op_count - 1);
set_pop_ret_info(insn, op);
break;
}
#endif
Expand Down

0 comments on commit 9a1c413

Please sign in to comment.