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

Ag argument handling + fix agj @ 0 #10175

Merged
merged 3 commits into from May 23, 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
11 changes: 6 additions & 5 deletions libr/core/canal.c
Expand Up @@ -1826,10 +1826,10 @@ R_API void r_core_anal_callgraph(RCore *core, ut64 addr, int fmt) {
if (base == UT64_MAX) {
base = fcni->addr;
}
if (from != UT64_MAX && addr < from) {
if (from != UT64_MAX && fcni->addr < from) {
continue;
}
if (to != UT64_MAX && addr > to) {
if (to != UT64_MAX && fcni->addr > to) {
continue;
}
if (addr != UT64_MAX && addr != fcni->addr) {
Expand Down Expand Up @@ -2721,6 +2721,7 @@ R_API int r_core_anal_graph(RCore *core, ut64 addr, int opts) {
if (!hc) {
return false;
}

r_config_save_num (hc, "asm.lines", "asm.bytes", "asm.dwarf", NULL);
//opts |= R_CORE_ANAL_GRAPHBODY;
r_config_set_i (core->config, "asm.lines", 0);
Expand Down Expand Up @@ -2753,8 +2754,8 @@ R_API int r_core_anal_graph(RCore *core, ut64 addr, int opts) {
r_list_foreach (core->anal->fcns, iter, fcni) {
if (fcni->type & (R_ANAL_FCN_TYPE_SYM | R_ANAL_FCN_TYPE_FCN |
R_ANAL_FCN_TYPE_LOC) &&
(!addr || r_anal_fcn_in (fcni, addr))) {
if (!addr && (from != UT64_MAX && to != UT64_MAX)) {
(addr == UT64_MAX || r_anal_fcn_in (fcni, addr))) {
if (addr == UT64_MAX && (from != UT64_MAX && to != UT64_MAX)) {
if (fcni->addr < from || fcni->addr > to) {
continue;
}
Expand All @@ -2763,7 +2764,7 @@ R_API int r_core_anal_graph(RCore *core, ut64 addr, int opts) {
r_cons_printf (",");
}
nodes += core_anal_graph_nodes (core, fcni, opts);
if (addr != 0) {
if (addr != UT64_MAX) {
break;
}
}
Expand Down
8 changes: 2 additions & 6 deletions libr/core/cconfig.c
Expand Up @@ -2719,7 +2719,6 @@ R_API int r_core_config_init(RCore *core) {


/* cmd */
r_config_desc (cfg, "cmd.graph", "Command executed by 'agv' command to view graphs");
SETPREF ("cmd.xterm", "xterm -bg black -fg gray -e", "xterm command to spawn with V@");
SETICB ("cmd.depth", 10, &cb_cmddepth, "Maximum command depth");
SETPREF ("cmd.bp", "", "Run when a breakpoint is hit");
Expand Down Expand Up @@ -2824,8 +2823,8 @@ R_API int r_core_config_init(RCore *core) {
SETPREF ("graph.font", "Courier", "Font for dot graphs");
SETPREF ("graph.offset", "false", "Show offsets in graphs");
SETPREF ("graph.web", "false", "Display graph in web browser (VV)");
SETI ("graph.from", UT64_MAX, "");
SETI ("graph.to", UT64_MAX, "");
SETI ("graph.from", UT64_MAX, "Lower bound address when drawing global graphs");
SETI ("graph.to", UT64_MAX, "Upper bound address when drawing global graphs");
SETI ("graph.scroll", 5, "Scroll speed in ascii-art graph");
SETPREF ("graph.invscroll", "false", "Invert scroll direction in ascii-art graph");
SETPREF ("graph.title", "", "Title of the graph");
Expand All @@ -2835,9 +2834,6 @@ R_API int r_core_config_init(RCore *core) {
SETPREF ("graph.gv.graph", "", "Graphviz global style attributes. (bgcolor=white)");
SETPREF ("graph.gv.current", "false", "Highlight the current node in graphviz graph.");
SETPREF ("graph.nodejmps", "true", "Enables shortcuts for every node.");
char *cmd = r_core_graph_cmd (core, "ag $$");
r_config_set (cfg, "cmd.graph", cmd);
free (cmd);

/* hud */
SETPREF ("hud.path", "", "Set a custom path for the HUD file");
Expand Down
74 changes: 50 additions & 24 deletions libr/core/cmd_anal.c
Expand Up @@ -5800,42 +5800,58 @@ static void cmd_anal_graph(RCore *core, const char *input) {
switch (input[0]) {
case 'f': // "agf"
switch (input[1]) {
case 0:// "agf"
case 0: // "agf"
r_core_visual_graph (core, NULL, NULL, false);
break;
case 'v':// "agfv"
case ' ':{ // "agf "
ut64 off_fcn = (*(input + 2)) ? r_num_math (core->num, input + 2) : core->offset;
RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, off_fcn, 0);
r_core_visual_graph (core, NULL, fcn, false);
break;
}
case 'v': // "agfv"
eprintf ("\rRendering graph...");
r_core_visual_graph (core, NULL, NULL, 1);
ut64 off_fcn = (*(input + 2)) ? r_num_math (core->num, input + 2) : core->offset;
RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, off_fcn, 0);
if (fcn) {
r_core_visual_graph (core, NULL, fcn, 1);
}
r_cons_enable_mouse (false);
r_cons_show_cursor (true);
break;
case 't':// "agft" - tiny graph
r_core_visual_graph (core, NULL, NULL, 2);
case 't': { // "agft" - tiny graph
ut64 off_fcn = (*(input + 2)) ? r_num_math (core->num, input + 2) : core->offset;
RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, off_fcn, 0);
r_core_visual_graph (core, NULL, fcn, 2);
break;
case 'd':// "agfd"
}
case 'd': // "agfd"
if (input[2] == 'm') {
r_core_anal_graph (core, r_num_math (core->num, input + 2),
r_core_anal_graph (core, r_num_math (core->num, input + 3),
R_CORE_ANAL_GRAPHLINES);
} else {
r_core_anal_graph (core, r_num_math (core->num, input + 1),
r_core_anal_graph (core, r_num_math (core->num, input + 2),
R_CORE_ANAL_GRAPHBODY);
}
break;
case 'j':// "agfj"
r_core_anal_graph (core, r_num_math (core->num, input + 1), R_CORE_ANAL_JSON);
case 'j': // "agfj"
r_core_anal_graph (core, r_num_math (core->num, input + 2), R_CORE_ANAL_JSON);
break;
case 'J':// "agfJ"
r_core_anal_graph (core, r_num_math (core->num, input + 1),
case 'J': // "agfJ"
r_core_anal_graph (core, r_num_math (core->num, input + 2),
R_CORE_ANAL_JSON | R_CORE_ANAL_JSON_FORMAT_DISASM);
case 'g':{// "agfg"
break;
case 'g':{ // "agfg"
ut64 off_fcn = (*(input + 2)) ? r_num_math (core->num, input + 2) : core->offset;
RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, off_fcn, 0);
r_core_print_bb_gml (core, fcn);
break;
}
case 'k':// "agfk"
r_core_cmd0 (core, "ag-; .agf*; aggk");
case 'k':{ // "agfk"
ut64 addr = (*(input + 2)) ? r_num_math (core->num, input + 2) : core->offset;
r_core_cmdf (core, "ag-; .agf* %lld; aggk", addr);
break;
}
case '*':{// "agf*"
ut64 off_fcn = (*(input + 2)) ? r_num_math (core->num, input + 2) : core->offset;
RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, off_fcn, 0);
Expand All @@ -5846,11 +5862,13 @@ static void cmd_anal_graph(RCore *core, const char *input) {
if (r_config_get_i (core->config, "graph.web")) {
r_core_cmd0 (core, "=H /graph/");
} else {
char *cmd = r_core_graph_cmd (core, "agfd");
char *cmdargs = r_str_newf ("agfd %lld", r_num_math (core->num, input + 2));
char *cmd = r_core_graph_cmd (core, cmdargs);
if (cmd && *cmd) {
r_core_cmd0 (core, cmd);
}
free (cmd);
free (cmdargs);
}
break;
default:
Expand Down Expand Up @@ -5971,10 +5989,14 @@ static void cmd_anal_graph(RCore *core, const char *input) {
break;
}
case '*': {
ut64 from = r_config_get_i (core->config, "graph.from");
ut64 to = r_config_get_i (core->config, "graph.to");
RListIter *it;
RAnalFunction *fcn;
r_list_foreach (core->anal->fcns, it, fcn) {
r_core_anal_coderefs (core, fcn->addr);
if ((from == UT64_MAX && to == UT64_MAX) || R_BETWEEN (from, fcn->addr, to)) {
r_core_anal_coderefs (core, fcn->addr);
}
}
break;
}
Expand Down Expand Up @@ -6085,14 +6107,14 @@ static void cmd_anal_graph(RCore *core, const char *input) {
break;
}
break;
case 'j': // "agj"
r_core_anal_graph (core, r_num_math (core->num, input + 1), R_CORE_ANAL_JSON);
case 'j': // "agj" alias for agfj
r_core_cmdf (core, "agfj%s", input + 1);
break;
case 'J': // "agJ"
r_core_anal_graph (core, r_num_math (core->num, input + 1), R_CORE_ANAL_JSON | R_CORE_ANAL_JSON_FORMAT_DISASM);
case 'J': // "agJ" alias for agfJ
r_core_cmdf (core, "agfJ%s", input + 1);
break;
case 'k': // "agk"
r_core_anal_graph (core, r_num_math (core->num, input + 1), R_CORE_ANAL_KEYVALUE);
case 'k': // "agk" alias for agfk
r_core_cmdf (core, "agfk%s", input + 1);
break;
case 'l': // "agl"
r_core_anal_graph (core, r_num_math (core->num, input + 1), R_CORE_ANAL_GRAPHLINES);
Expand Down Expand Up @@ -6145,10 +6167,14 @@ static void cmd_anal_graph(RCore *core, const char *input) {
break;
}
case '*': {
ut64 from = r_config_get_i (core->config, "graph.from");
ut64 to = r_config_get_i (core->config, "graph.to");
RListIter *it;
RAnalFunction *fcn;
r_list_foreach (core->anal->fcns, it, fcn) {
r_core_anal_datarefs (core, fcn->addr);
if ((from == UT64_MAX && to == UT64_MAX) || R_BETWEEN (from, fcn->addr, to)) {
r_core_anal_datarefs (core, fcn->addr);
}
}
break;
}
Expand Down
40 changes: 22 additions & 18 deletions libr/core/graph.c
Expand Up @@ -94,6 +94,7 @@ struct agraph_refresh_data {
RCore *core;
RAGraph *g;
RAnalFunction **fcn;
bool follow_offset;
int fs;
};

Expand Down Expand Up @@ -3191,27 +3192,29 @@ static int agraph_refresh(struct agraph_refresh_data *grd) {
g->is_instep = false;
}

if (r_io_is_valid_offset (core->io, core->offset, 0)) {
f = r_anal_get_fcn_in (core->anal, core->offset, 0);
if (!f) {
if (!g->is_dis) {
if (!r_cons_yesno ('y', "\rNo function at 0x%08"PFMT64x". Define it here (Y/n)? ", core->offset)) {
return 0;
if (grd->follow_offset) {
if (r_io_is_valid_offset (core->io, core->offset, 0)) {
f = r_anal_get_fcn_in (core->anal, core->offset, 0);
if (!f) {
if (!g->is_dis) {
if (!r_cons_yesno ('y', "\rNo function at 0x%08"PFMT64x". Define it here (Y/n)? ", core->offset)) {
return 0;
}
r_core_cmd0 (core, "af");
}
r_core_cmd0 (core, "af");
f = r_anal_get_fcn_in (core->anal, core->offset, 0);
g->need_reload_nodes = true;
}
f = r_anal_get_fcn_in (core->anal, core->offset, 0);
g->need_reload_nodes = true;
}
if (f && fcn && f != *fcn) {
*fcn = f;
g->need_reload_nodes = true;
g->force_update_seek = true;
if (f && fcn && f != *fcn) {
*fcn = f;
g->need_reload_nodes = true;
g->force_update_seek = true;
}
} else {
// TODO: maybe go back to avoid seeking from graph view to an scary place?
r_cons_message ("This is not a valid offset\n");
r_cons_flush ();
}
} else {
// TODO: maybe go back to avoid seeking from graph view to an scary place?
r_cons_message ("This is not a valid offset\n");
r_cons_flush ();
}

return agraph_print (g, grd->fs, core, *fcn);
Expand Down Expand Up @@ -3724,6 +3727,7 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int
grd->g = g;
grd->fs = is_interactive == 1;
grd->core = core;
grd->follow_offset = _fcn ? false : true;
grd->fcn = fcn != NULL? &fcn: NULL;
ret = agraph_refresh (grd);
if (!ret || is_interactive != 1) {
Expand Down
2 changes: 1 addition & 1 deletion libr/core/visual.c
Expand Up @@ -287,7 +287,7 @@ static int visual_help() {
" T enter textlog chat console (TT)\n"
" uU undo/redo seek\n"
" v visual function/vars code analysis menu\n"
" V (V)iew graph using cmd.graph (agv?)\n"
" V (V)iew interactive ascii art graph (agfv)\n"
" wW seek cursor to next/prev word\n"
" xX show xrefs/refs of current function from/to data/code\n"
" yY copy and paste selection\n"
Expand Down