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

Add jpg, svg, pdf.... extensions for 'w' graph output format #10109

Merged
merged 3 commits into from May 17, 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
17 changes: 10 additions & 7 deletions libr/core/cconfig.c
Expand Up @@ -1748,7 +1748,7 @@ static int cb_scrstrconv(void *user, void *data) {
static int cb_graphformat(void *user, void *data) {
RConfigNode *node = (RConfigNode *) data;
if (!strcmp (node->value, "?")) {
r_cons_printf ("dot\ngml\ngmlfcn\n");
r_cons_printf ("png\njpg\npdf\nps\nsvg\njson\n");
return false;
}
return true;
Expand Down Expand Up @@ -2275,9 +2275,10 @@ static char *getViewerPath() {
return NULL;
}

R_API char* r_core_graph_cmd(char *r2_cmd) {
R_API char* r_core_graph_cmd(RCore *core, char *r2_cmd) {
char *cmd = NULL;
char *xdotPath = r_file_path ("xdot");
const char *ext = r_config_get (core->config, "graph.extension");
if (r_file_exists (xdotPath)) {
cmd = r_str_newf ("%s > a.dot;!xdot a.dot", r2_cmd);
} else {
Expand All @@ -2286,7 +2287,7 @@ R_API char* r_core_graph_cmd(char *r2_cmd) {
R_FREE (dotPath);
char *viewer = getViewerPath();
if (viewer) {
cmd = r_str_newf ("%s > a.dot;!dot -Tgif -oa.gif a.dot;!%s a.gif", r2_cmd, viewer);
cmd = r_str_newf ("%s > a.dot;!dot -T%s -oa.%s a.dot;!%s a.%s", r2_cmd, ext, ext, viewer, ext);
free (viewer);
} else {
cmd = "?e cannot find a valid picture viewer";
Expand Down Expand Up @@ -2716,11 +2717,8 @@ R_API int r_core_config_init(RCore *core) {
SETCB ("dbg.trace", "false", &cb_trace, "Trace program execution (see asm.trace)");
SETICB ("dbg.trace.tag", 0, &cb_tracetag, "Trace tag");

/* cmd */
char *cmd = r_core_graph_cmd ("ag $$");
r_config_set (cfg, "cmd.graph", cmd);
free (cmd);

/* 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");
Expand Down Expand Up @@ -2818,6 +2816,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)");
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 All @@ -2836,6 +2835,10 @@ 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
17 changes: 15 additions & 2 deletions libr/core/cmd_anal.c
Expand Up @@ -5784,7 +5784,7 @@ static void cmd_agraph_print(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 ("aggd");
char *cmd = r_core_graph_cmd (core, "aggd");
if (cmd && *cmd) {
r_core_cmd0 (core, cmd);
}
Expand Down Expand Up @@ -5852,7 +5852,7 @@ 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 ("agfd");
char *cmd = r_core_graph_cmd (core, "agfd");
if (cmd && *cmd) {
r_core_cmd0 (core, cmd);
}
Expand Down Expand Up @@ -6069,6 +6069,19 @@ static void cmd_anal_graph(RCore *core, const char *input) {
}
}
break;
case 'w':// "agw"
if (r_config_get_i (core->config, "graph.web")) {
r_core_cmd0 (core, "=H /graph/");
} else {
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;
case '?': // "ag?"
r_core_cmd_help (core, help_msg_ag);
break;
Expand Down
2 changes: 1 addition & 1 deletion libr/include/r_core.h
Expand Up @@ -246,7 +246,7 @@ R_API void r_core_wait(RCore *core);
R_API RCore *r_core_ncast(ut64 p);
R_API RCore *r_core_cast(void *p);
R_API int r_core_config_init(RCore *core);
R_API char* r_core_graph_cmd(char *r2_cmd);
R_API char* r_core_graph_cmd(RCore *core, char *r2_cmd);
R_API int r_core_prompt(RCore *core, int sync);
R_API int r_core_prompt_exec(RCore *core);
R_API int r_core_lines_initcache (RCore *core, ut64 start_addr, ut64 end_addr);
Expand Down