Skip to content

Commit

Permalink
Make bp usage check not depend on opex string (#3315)
Browse files Browse the repository at this point in the history
In all instructions in all existing tests, the result of can_affect_bp()
is equal to what the opex check would determine, so we can avoid the
overhead of opex here.
  • Loading branch information
thestr4ng3r committed Jan 22, 2023
1 parent bbc5457 commit ead6016
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions librz/analysis/fcn.c
Original file line number Diff line number Diff line change
Expand Up @@ -2122,9 +2122,6 @@ static bool can_affect_bp(RzAnalysis *analysis, RzAnalysisOp *op) {
static void __analysis_fcn_check_bp_use(RzAnalysis *analysis, RzAnalysisFunction *fcn) {
RzListIter *iter;
RzAnalysisBlock *bb;
char str_to_find[40] = "\"type\":\"reg\",\"value\":\"";
char *pos;
strncat(str_to_find, analysis->reg->name[RZ_REG_NAME_BP], 39);
if (!fcn) {
return;
}
Expand All @@ -2138,7 +2135,7 @@ static void __analysis_fcn_check_bp_use(RzAnalysis *analysis, RzAnalysisFunction
(void)analysis->iob.read_at(analysis->iob.io, bb->addr, (ut8 *)buf, bb->size);
int idx = 0;
for (at = bb->addr; at < end;) {
rz_analysis_op(analysis, &op, at, buf + idx, bb->size - idx, RZ_ANALYSIS_OP_MASK_VAL | RZ_ANALYSIS_OP_MASK_OPEX);
rz_analysis_op(analysis, &op, at, buf + idx, bb->size - idx, RZ_ANALYSIS_OP_MASK_VAL);
if (op.size < 1) {
op.size = 1;
}
Expand All @@ -2165,25 +2162,14 @@ static void __analysis_fcn_check_bp_use(RzAnalysis *analysis, RzAnalysisFunction
case RZ_ANALYSIS_OP_TYPE_SUB:
case RZ_ANALYSIS_OP_TYPE_XOR:
case RZ_ANALYSIS_OP_TYPE_SHL:
// op.dst is not filled for these operations, so for now, check for bp as dst looks like this; in the future it may be just replaced with call to can_affect_bp
pos = op.opex.ptr ? strstr(op.opex.ptr, str_to_find) : NULL;
if (pos && pos - op.opex.ptr < 60) {
fcn->bp_frame = false;
rz_analysis_op_fini(&op);
free(buf);
return;
}
break;
case RZ_ANALYSIS_OP_TYPE_XCHG:
if (op.opex.ptr && strstr(op.opex.ptr, str_to_find)) {
if (can_affect_bp(analysis, &op)) {
fcn->bp_frame = false;
rz_analysis_op_fini(&op);
free(buf);
return;
}
break;
case RZ_ANALYSIS_OP_TYPE_POP:
break;
default:
break;
}
Expand Down

0 comments on commit ead6016

Please sign in to comment.