mirror of
https://github.com/radareorg/radare2.git
synced 2024-12-11 23:16:05 +00:00
core/cmd_anal: implement ag-/agn/age/agg to work with core->graph
This commit is contained in:
parent
3d29108225
commit
4eedd69a91
@ -2290,6 +2290,10 @@ static void cmd_anal_graph(RCore *core, const char *input) {
|
||||
"agl", " [fcn name]", "output graphviz code using meta-data",
|
||||
"agt", " [addr]", "find paths from current offset to given address",
|
||||
"agf", " [addr]", "Show ASCII art graph of given function",
|
||||
"ag-", "", "Reset the current ASCII art graph",
|
||||
"agn", " title body", "Add a node to the current ASCII art graph",
|
||||
"age", " title1 title2", "Add an edge to the current ASCII art graph",
|
||||
"agg", "", "Print the current ASCII art graph",
|
||||
"agfl", " [fcn name]", "output graphviz code of function using meta-data",
|
||||
"agv", "[acdltfl] [a]", "view function using graphviz",
|
||||
NULL};
|
||||
@ -2298,6 +2302,68 @@ static void cmd_anal_graph(RCore *core, const char *input) {
|
||||
case 'f':
|
||||
r_core_cmd0 (core, "afg"); // afg should be deprecated imho
|
||||
break;
|
||||
case '-':
|
||||
r_agraph_reset (core->graph);
|
||||
break;
|
||||
case 'n':
|
||||
/* TODO: accept title and body with spaces (wrapped in "") */
|
||||
/* TODO: accept base64 body */
|
||||
input++;
|
||||
if (*input == ' ') {
|
||||
char *title, *body;
|
||||
int len;
|
||||
|
||||
input++;
|
||||
arg = r_str_tok (input, ' ', -1);
|
||||
if (arg) {
|
||||
len = arg - input;
|
||||
title = r_str_ndup (input, len);
|
||||
|
||||
input = arg;
|
||||
while (*input == ' ') input++;
|
||||
arg = r_str_tok (input, ' ', -1);
|
||||
len = arg ? arg - input : strlen (input);
|
||||
body = r_str_ndup (input, len);
|
||||
|
||||
r_agraph_add_node (core->graph, title, body);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'e':
|
||||
/* TODO: accept titles with spaces (wrapped in "") */
|
||||
input++;
|
||||
if (*input == ' ') {
|
||||
RANode *u, *v;
|
||||
char *title1, *title2;
|
||||
int len;
|
||||
|
||||
input++;
|
||||
arg = r_str_tok (input, ' ', -1);
|
||||
if (arg) {
|
||||
len = arg - input;
|
||||
title1 = r_str_ndup (input, len);
|
||||
|
||||
input = arg;
|
||||
while (*input == ' ') input++;
|
||||
arg = r_str_tok (input, ' ', -1);
|
||||
len = arg ? arg - input : strlen (input);
|
||||
title2 = r_str_ndup (input, len);
|
||||
|
||||
u = r_agraph_get_node (core->graph, title1);
|
||||
v = r_agraph_get_node (core->graph, title2);
|
||||
if (!u || !v) {
|
||||
r_cons_printf ("nodes not found!\n");
|
||||
break;
|
||||
}
|
||||
r_agraph_add_edge (core->graph, u, v);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'g':
|
||||
core->graph->can->linemode = 1;
|
||||
core->graph->can->color = r_config_get_i (core->config, "scr.color");
|
||||
r_agraph_print (core->graph);
|
||||
break;
|
||||
case 't':
|
||||
list = r_core_anal_graph_to (core, r_num_math (core->num, input+1), 0);
|
||||
if (list) {
|
||||
|
@ -906,6 +906,7 @@ R_API int r_core_init(RCore *core) {
|
||||
r_io_undo_enable (core->io, 1, 0); // TODO: configurable via eval
|
||||
core->fs = r_fs_new ();
|
||||
core->flags = r_flag_new ();
|
||||
core->graph = r_agraph_new (r_cons_canvas_new (1, 1));
|
||||
|
||||
r_bin_bind (core->bin, &(core->assembler->binb));
|
||||
r_bin_bind (core->bin, &(core->anal->binb));
|
||||
@ -994,6 +995,7 @@ R_API RCore *r_core_fini(RCore *c) {
|
||||
r_egg_free (c->egg);
|
||||
r_lib_free (c->lib);
|
||||
r_buf_free (c->yank_buf);
|
||||
r_agraph_free (c->graph);
|
||||
sdb_free (c->sdb);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -90,6 +90,7 @@ static void update_node_dimension(const RGraph *g, int is_small, int zoom) {
|
||||
n->w = strlen (SMALLNODE_TEXT);
|
||||
} else {
|
||||
n->w = r_str_bounds (n->body, &n->h);
|
||||
n->w = R_MAX (n->w, strlen (n->title));
|
||||
n->w += BORDER_WIDTH;
|
||||
n->h += BORDER_HEIGHT;
|
||||
/* scale node by zoom */
|
||||
@ -1656,7 +1657,7 @@ static void agraph_update_seek(RAGraph *g, RANode *n, int force) {
|
||||
}
|
||||
|
||||
static void agraph_print_node(const RAGraph *g, RANode *n) {
|
||||
const int cur = get_anode (g->curnode) == n;
|
||||
const int cur = g->curnode && get_anode (g->curnode) == n;
|
||||
|
||||
if (g->is_small_nodes)
|
||||
small_RANode_print(g, n, cur);
|
||||
@ -1676,7 +1677,8 @@ static void agraph_print_nodes(const RAGraph *g) {
|
||||
}
|
||||
|
||||
/* draw current node now to make it appear on top */
|
||||
agraph_print_node (g, get_anode (g->curnode));
|
||||
if (g->curnode)
|
||||
agraph_print_node (g, get_anode (g->curnode));
|
||||
}
|
||||
|
||||
/* print an edge between two nodes.
|
||||
@ -1927,6 +1929,8 @@ static void agraph_init(RAGraph *g) {
|
||||
|
||||
R_API void r_agraph_print (RAGraph *g) {
|
||||
agraph_print (g, R_FALSE, NULL, NULL);
|
||||
if (g->graph->n_nodes > 0)
|
||||
r_cons_newline ();
|
||||
}
|
||||
|
||||
R_API RANode *r_agraph_add_node (const RAGraph *g, const char *title,
|
||||
|
@ -124,6 +124,7 @@ typedef struct r_core_t {
|
||||
RFS *fs;
|
||||
REgg *egg;
|
||||
RCoreLog *log;
|
||||
RAGraph *graph;
|
||||
char *cmdqueue;
|
||||
char *lastcmd;
|
||||
int cmdrepeat;
|
||||
|
Loading…
Reference in New Issue
Block a user