Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added data graph (aga) + partial support for diff graph (agd) output formats #10117

Merged
merged 4 commits into from May 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions libr/anal/diff.c
Expand Up @@ -239,10 +239,16 @@ R_API int r_anal_diff_fcn(RAnal *anal, RList *fcns, RList *fcns2) {
maxsize = fcn2_size;
minsize = fcn_size;
}
if ((fcn2->type != R_ANAL_FCN_TYPE_FCN
&& fcn2->type != R_ANAL_FCN_TYPE_SYM) ||
fcn2->diff->type != R_ANAL_DIFF_TYPE_NULL ||
(maxsize * anal->diff_thfcn > minsize)) {
if (maxsize * anal->diff_thfcn > minsize) {
eprintf ("Exceeded anal threshold while diffing %s and %s\n", fcn->name, fcn2->name);
continue;
}
if (fcn2->diff->type != R_ANAL_DIFF_TYPE_NULL) {
eprintf ("Function %s already diffed\n", fcn2->name);
continue;
}
if ((fcn2->type != R_ANAL_FCN_TYPE_FCN && fcn2->type != R_ANAL_FCN_TYPE_SYM)) {
eprintf ("Function %s type not supported\n", fcn2->name);
continue;
}
r_diff_buffers_distance (NULL, fcn->fingerprint, fcn_size, fcn2->fingerprint, fcn2_size, NULL, &t);
Expand Down
32 changes: 32 additions & 0 deletions libr/core/canal.c
Expand Up @@ -1708,6 +1708,38 @@ R_API int r_core_print_bb_gml(RCore *core, RAnalFunction *fcn) {
return true;
}

R_API void r_core_anal_datarefs(RCore *core, ut64 addr) {
RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, addr, -1);
if (fcn) {
bool found = false;
const char *me = fcn->name;
RListIter *iter;
RAnalRef *ref;
RList *refs = r_anal_fcn_get_refs (core->anal, fcn);
r_list_foreach (refs, iter, ref) {
RBinObject *obj = r_bin_cur_object (core->bin);
RBinSection *binsec = r_bin_get_section_at (obj, ref->addr, true);
if (binsec->is_data) {
if (!found) {
r_cons_printf ("ag-\n");
r_cons_printf ("agn %s\n", me);
found = true;
}
RFlagItem *item = r_flag_get_i (core->flags, ref->addr);
const char *dst = item? item->name: sdb_fmt ("0x%08"PFMT64x, ref->addr);
r_cons_printf ("agn %s\n", dst);
r_cons_printf ("age %s %s\n", me, dst);
}
}
if (!found) {
eprintf ("No data refs in this function.\n");
}
r_list_free (refs);
} else {
eprintf ("Not in a function. Use 'df' to define it.\n");
}
}

R_API void r_core_anal_coderefs(RCore *core, ut64 addr) {
RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, addr, -1);
if (fcn) {
Expand Down
63 changes: 60 additions & 3 deletions libr/core/cmd_anal.c
Expand Up @@ -6051,11 +6051,68 @@ static void cmd_anal_graph(RCore *core, const char *input) {
r_core_anal_graph (core, r_num_math (core->num, input + 1), R_CORE_ANAL_GRAPHLINES);
break;
case 'a': // "aga"
r_core_anal_graph (core, r_num_math (core->num, input + 1), 0);
switch (input[1]) {
case 'v':
case 't':
case 'k':
case 'w':
case 'g':
case 'j':
case 'J':
case 'd':
case ' ': {
char *cmd = r_str_newf ("ag-; .aga* %lld; agg%c;",
input[2] ? r_num_math (core->num, input + 2) : core->offset, input[1]);
if (cmd && *cmd) {
r_core_cmd0 (core, cmd);
}
free (cmd);
break;
}
case 0:
r_core_cmd0 (core, "ag-; .aga* $$; agg;");
break;
case '*': {
ut64 addr = input[2]? r_num_math (core->num, input + 2): core->offset;
r_core_anal_datarefs (core, addr);
break;
}
default:
eprintf ("Usage: see ag?\n");
break;
}
break;
case 'd': // "agd"
r_core_anal_graph (core, r_num_math (core->num, input + 1),
R_CORE_ANAL_GRAPHBODY | R_CORE_ANAL_GRAPHDIFF);
switch (input[1]) {
case 'v':
case 't':
case 'j':
case 'J':
case 'g':
case 'k':
case '*':
case ' ':
case 0:
eprintf ("Currently the only supported formats for the diff graph are 'agdd' and 'agdw'\n");
break;
case 'd': {
ut64 addr = input[2]? r_num_math (core->num, input + 2): core->offset;
r_core_gdiff_fcn (core, addr, core->offset);
r_core_anal_graph (core, addr, R_CORE_ANAL_GRAPHBODY | R_CORE_ANAL_GRAPHDIFF);
break;
}
case 'w': {
char *cmdargs = r_str_newf ("agdd %lld",
input[2] ? r_num_math (core->num, input + 2) : core->offset);
char *cmd = r_core_graph_cmd (core, cmdargs);
if (cmd && *cmd) {
r_core_cmd0 (core, cmd);
}
free (cmd);
free (cmdargs);
break;
}
}
break;
case 'v': // "agv"
if (r_config_get_i (core->config, "graph.web")) {
Expand Down
8 changes: 8 additions & 0 deletions libr/core/gdiff.c
Expand Up @@ -11,6 +11,14 @@ R_API int r_core_gdiff_fcn(RCore *c, ut64 addr, ut64 addr2) {
RList *la, *lb;
RAnalFunction *fa = r_anal_get_fcn_at (c->anal, addr, 0);
RAnalFunction *fb = r_anal_get_fcn_at (c->anal, addr2, 0);
RAnalBlock *bb;
RListIter *iter;
r_list_foreach (fa->bbs, iter, bb) {
r_anal_diff_fingerprint_bb (c->anal, bb);
}
r_list_foreach (fb->bbs, iter, bb) {
r_anal_diff_fingerprint_bb (c->anal, bb);
}
la = r_list_new ();
r_list_append (la, fa);
lb = r_list_new ();
Expand Down
1 change: 1 addition & 0 deletions libr/include/r_core.h
Expand Up @@ -412,6 +412,7 @@ R_API void r_core_anal_hint_list (RAnal *a, int mode);
R_API int r_core_anal_search(RCore *core, ut64 from, ut64 to, ut64 ref, int mode);
R_API int r_core_anal_search_xrefs(RCore *core, ut64 from, ut64 to, int rad);
R_API int r_core_anal_data (RCore *core, ut64 addr, int count, int depth, int wordsize);
R_API void r_core_anal_datarefs(RCore *core, ut64 addr);
R_API void r_core_anal_coderefs(RCore *core, ut64 addr);
R_API void r_core_anal_codexrefs(RCore *core, ut64 addr);
R_API void r_core_anal_callgraph(RCore *core, ut64 addr, int fmt);
Expand Down