mirror of
https://github.com/radareorg/radare2.git
synced 2024-12-03 02:41:08 +00:00
Support overlapping basic blocks in anal.endsize ##anal
* af-* uses r_anal_del_jmprefs() instead * anal.endsize supports overlapping basic blocks * Further specify cond in r_anal_trim_jmprefs() * Add x86 checks
This commit is contained in:
parent
7f1877abe2
commit
68122dc27e
@ -1565,9 +1565,24 @@ R_API void r_anal_trim_jmprefs(RAnal *anal, RAnalFunction *fcn) {
|
||||
RAnalRef *ref;
|
||||
RList *refs = r_anal_fcn_get_refs (anal, fcn);
|
||||
RListIter *iter;
|
||||
const bool x86 = anal->cur->arch && !strcmp (anal->cur->arch, "x86"); // HACK
|
||||
|
||||
r_list_foreach (refs, iter, ref) {
|
||||
if (ref->type == R_ANAL_REF_TYPE_CODE && r_anal_fcn_is_in_offset (fcn, ref->addr)) {
|
||||
if (ref->type == R_ANAL_REF_TYPE_CODE && r_anal_fcn_is_in_offset (fcn, ref->addr)
|
||||
&& (!x86 || !r_anal_fcn_is_in_offset (fcn, ref->at))) {
|
||||
r_anal_xrefs_deln (anal, ref->at, ref->addr, ref->type);
|
||||
}
|
||||
}
|
||||
r_list_free (refs);
|
||||
}
|
||||
|
||||
R_API void r_anal_del_jmprefs(RAnal *anal, RAnalFunction *fcn) {
|
||||
RAnalRef *ref;
|
||||
RList *refs = r_anal_fcn_get_refs (anal, fcn);
|
||||
RListIter *iter;
|
||||
|
||||
r_list_foreach (refs, iter, ref) {
|
||||
if (ref->type == R_ANAL_REF_TYPE_CODE) {
|
||||
r_anal_xrefs_deln (anal, ref->at, ref->addr, ref->type);
|
||||
}
|
||||
}
|
||||
@ -1599,13 +1614,16 @@ R_API int r_anal_fcn(RAnal *anal, RAnalFunction *fcn, ut64 addr, ut8 *buf, ut64
|
||||
RListIter *iter;
|
||||
RAnalBlock *bb;
|
||||
ut64 endaddr = fcn->addr;
|
||||
const bool x86 = anal->cur->arch && !strcmp (anal->cur->arch, "x86");
|
||||
|
||||
// set function size as length of continuous sequence of bbs
|
||||
r_list_sort (fcn->bbs, &cmpaddr);
|
||||
r_list_foreach (fcn->bbs, iter, bb) {
|
||||
if (endaddr == bb->addr) {
|
||||
endaddr += bb->size;
|
||||
} else if (endaddr < bb->addr && bb->addr - endaddr < BB_ALIGN) {
|
||||
} else if ((endaddr < bb->addr && bb->addr - endaddr < BB_ALIGN)
|
||||
|| (anal->opt.jmpmid && x86 && endaddr > bb->addr
|
||||
&& bb->addr + bb->size > endaddr)) {
|
||||
endaddr = bb->addr + bb->size;
|
||||
} else {
|
||||
break;
|
||||
@ -1615,7 +1633,6 @@ R_API int r_anal_fcn(RAnal *anal, RAnalFunction *fcn, ut64 addr, ut8 *buf, ut64
|
||||
// fcn is not yet in anal => pass NULL
|
||||
r_anal_fcn_resize (NULL, fcn, endaddr - fcn->addr);
|
||||
#endif
|
||||
// TODO: unnecessary? add an option?
|
||||
r_anal_trim_jmprefs (anal, fcn);
|
||||
}
|
||||
return ret;
|
||||
|
@ -2204,7 +2204,7 @@ static int cmd_anal_fcn(RCore *core, const char *input) {
|
||||
RAnalFunction *f;
|
||||
RListIter *iter;
|
||||
r_list_foreach (core->anal->fcns, iter, f) {
|
||||
r_anal_trim_jmprefs (core->anal, f);
|
||||
r_anal_del_jmprefs (core->anal, f);
|
||||
}
|
||||
r_list_purge (core->anal->fcns);
|
||||
core->anal->fcn_tree = NULL;
|
||||
|
@ -1444,6 +1444,7 @@ R_API int r_anal_fcn_bb_overlaps(RAnalFunction *fcn, RAnalBlock *bb);
|
||||
R_API RAnalVar *r_anal_fcn_get_var(RAnalFunction *fs, int num, int dir);
|
||||
R_API void r_anal_fcn_fit_overlaps (RAnal *anal, RAnalFunction *fcn);
|
||||
R_API void r_anal_trim_jmprefs(RAnal *anal, RAnalFunction *fcn);
|
||||
R_API void r_anal_del_jmprefs(RAnal *anal, RAnalFunction *fcn);
|
||||
R_API RAnalFunction *r_anal_fcn_next(RAnal *anal, ut64 addr);
|
||||
R_API char *r_anal_fcn_to_string(RAnal *a, RAnalFunction* fs);
|
||||
R_API int r_anal_str_to_fcn(RAnal *a, RAnalFunction *f, const char *_str);
|
||||
|
Loading…
Reference in New Issue
Block a user