Skip to content

Commit

Permalink
Refactor: many small refactors of ag* commands in cmd_anal.c
Browse files Browse the repository at this point in the history
Refactor: solve merge conflict in cconfig.c

Refactor: other small refactorings in cmd_anal.c
  • Loading branch information
cyanpencil committed Aug 1, 2018
1 parent 280184c commit 106ae2e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion libr/core/cconfig.c
Expand Up @@ -2812,7 +2812,7 @@ R_API int r_core_config_init(RCore *core) {
/* graph */
SETPREF ("graph.comments", "true", "Show disasm comments in graph");
SETPREF ("graph.cmtright", "false", "Show comments at right");
SETCB ("graph.extension", "gif", &cb_graphformat, "Graph extension when using 'w' format (png, jpg, pdf, ps, svg, json)");
SETCB ("graph.gv.format", "gif", &cb_graphformat, "Graph image extension when using 'w' format (png, jpg, pdf, ps, svg, json)");
SETPREF ("graph.refs", "false", "Graph references in callgraphs (.agc*;aggi)");
SETI ("graph.edges", 2, "0=no edges, 1=simple edges, 2=avoid collisions");
SETI ("graph.layout", 0, "Graph layout (0=vertical, 1=horizontal)");
Expand Down
40 changes: 21 additions & 19 deletions libr/core/cmd_anal.c
Expand Up @@ -386,31 +386,31 @@ static const char *help_msg_afvs[] = {
static const char *help_msg_ag[] = {
"Usage:", "ag<graphtype><format> [addr]", "",
"Graph commands:", "", "",
"agc", "[format] [@ fcn addr]", "Function callgraph",
"agf", "[format] [@ fcn addr]", "Basic blocks function graph",
"agx", "[format] [@ addr]", "Cross references graph",
"agr", "[format] [@ fcn addr]", "References graph",
"aga", "[format] [@ fcn addr]", "Data references graph",
"agA", "[format]", "Global data references graph",
"agc", "[format] [@ fcn addr]", "Function callgraph",
"agC", "[format]", "Global callgraph",
"agd", "[format] [fcn addr]", "Diff graph",
"agf", "[format] [@ fcn addr]", "Basic blocks function graph",
"agi", "[format]", "Imports graph",
"agC", "[format]", "Global callgraph",
"agr", "[format] [@ fcn addr]", "References graph",
"agR", "[format]", "Global references graph",
"agA", "[format]", "Global data references graph",
"agx", "[format] [@ addr]", "Cross references graph",
"agg", "[format]", "Custom graph",
"ag-", "", "Clear the custom graph",
"agn", "[?] title body", "Add a node to the custom graph",
"age", "[?] title1 title2", "Add an edge to the custom graph",
"","","",
"Output formats:", "", "",
"<blank>", "", "Ascii art",
"v", "", "Interactive ascii art",
"t", "", "Tiny ascii art",
"*", "", "r2 commands",
"d", "", "Graphviz dot",
"j", "", "json ('J' for formatted disassembly)",
"g", "", "Graph Modelling Language (gml)",
"j", "", "json ('J' for formatted disassembly)",
"k", "", "SDB key-value",
"*", "", "r2 commands",
"w", " [path]", "Web/image display or save to path (see graph.extension and graph.web)",
"t", "", "Tiny ascii art",
"v", "", "Interactive ascii art",
"w", " [path]", "Write to path or display graph image (see graph.gv.format and graph.web)",
NULL
};

Expand Down Expand Up @@ -5762,7 +5762,7 @@ static char *getViewerPath() {

static char* graph_cmd(RCore *core, char *r2_cmd, const char *save_path) {
char *cmd = NULL;
const char *ext = r_config_get (core->config, "graph.extension");
const char *ext = r_config_get (core->config, "graph.gv.format");
char *dotPath = r_file_path ("dot");
if (!r_file_exists (dotPath)) {
free (dotPath);
Expand All @@ -5777,7 +5777,7 @@ static char* graph_cmd(RCore *core, char *r2_cmd, const char *save_path) {
cmd = r_str_newf ("%s > a.dot;!%s -T%s -oa.%s a.dot;!%s a.%s", r2_cmd, dotPath, ext, ext, viewer, ext);
free (viewer);
} else {
cmd = "?e cannot find a valid picture viewer";
eprintf ("Cannot find a valid picture viewer");
}
}
} else {
Expand Down Expand Up @@ -5942,14 +5942,16 @@ static void cmd_agraph_print(RCore *core, const char *input) {
}
break;
}
case 'd': // "aggd" - dot format
case 'd': { // "aggd" - dot format
const char *font = r_config_get (core->config, "graph.font");
r_cons_printf ("digraph code {\ngraph [bgcolor=white];\n"
"node [color=lightgray, style=filled shape=box "
"fontname=\"Courier\" fontsize=\"8\"];\n");
"fontname=\"%s\" fontsize=\"8\"];\n", font);
r_agraph_foreach (core->graph, agraph_print_node_dot, NULL);
r_agraph_foreach_edge (core->graph, agraph_print_edge_dot, NULL);
r_cons_printf ("}\n");
break;
}
case '*': // "agg*" -
r_agraph_foreach (core->graph, agraph_print_node, NULL);
r_agraph_foreach_edge (core->graph, agraph_print_edge, NULL);
Expand All @@ -5972,7 +5974,7 @@ static void cmd_agraph_print(RCore *core, const char *input) {
} else {
char *cmd = graph_cmd (core, "aggd", input + 1);
if (cmd && *cmd) {
if (*(input + 1)) {
if (input[1]) {
r_cons_printf ("Saving to file %s ...\n", input + 1);
r_cons_flush ();
}
Expand Down Expand Up @@ -6372,10 +6374,10 @@ static void cmd_anal_graph(RCore *core, const char *input) {
r_core_cmd0 (core, "=H /graph/");
} else {
char *cmdargs = r_str_newf ("agfd @ 0x%"PFMT64x, core->offset);
char *cmd = graph_cmd (core, cmdargs, input + 2);
char *cmd = graph_cmd (core, cmdargs, input + 1);
if (cmd && *cmd) {
if (*(input + 1)) {
r_cons_printf ("Saving to file %s ...\n", input + 2);
if (input[1]) {
r_cons_printf ("Saving to file %s ...\n", input + 1);
r_cons_flush ();
}
r_core_cmd0 (core, cmd);
Expand Down

0 comments on commit 106ae2e

Please sign in to comment.