mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-23 21:29:49 +00:00
Add support for highlighted edges in graphviz ##graph
* Add tests
This commit is contained in:
parent
c002a80328
commit
608f667688
@ -2951,8 +2951,7 @@ static void agraph_print_edges(RAGraph *g) {
|
||||
}
|
||||
}
|
||||
if (sdb_const_get (g->db, sdb_fmt ("agraph.edge.%s_%s.highlight", a->title, b->title), 0)) {
|
||||
|
||||
style.ansicolor = Color_BYELLOW;
|
||||
style.ansicolor = Color_BYELLOW; // it's CYAN for graphviz
|
||||
} else {
|
||||
style.ansicolor = NULL;
|
||||
}
|
||||
|
@ -8348,27 +8348,26 @@ static void agraph_print_edge_gml(RANode *from, RANode *to, void *user) {
|
||||
}
|
||||
|
||||
static void agraph_print_node_dot(RANode *n, void *user) {
|
||||
char *label = strdup (n->body);
|
||||
//label = r_str_replace (label, "\n", "\\l", 1);
|
||||
if (!label || !*label) {
|
||||
if (R_STR_ISEMPTY (n->body)) {
|
||||
r_cons_printf ("\"%s\" [URL=\"%s\", color=\"lightgray\", label=\"%s\"]\n",
|
||||
n->title, n->title, n->title);
|
||||
} else {
|
||||
char *label = strdup (n->body);
|
||||
//label = r_str_replace (label, "\n", "\\l", 1);
|
||||
r_cons_printf ("\"%s\" [URL=\"%s\", color=\"lightgray\", label=\"%s\\n%s\"]\n",
|
||||
n->title, n->title, n->title, label);
|
||||
free (label);
|
||||
}
|
||||
free (label);
|
||||
}
|
||||
|
||||
static void agraph_print_node(RANode *n, void *user) {
|
||||
char *encbody, *cmd;
|
||||
int len = strlen (n->body);
|
||||
size_t len = strlen (n->body);
|
||||
|
||||
if (len > 0 && n->body[len - 1] == '\n') {
|
||||
len--;
|
||||
}
|
||||
encbody = r_base64_encode_dyn (n->body, len);
|
||||
cmd = r_str_newf ("agn \"%s\" base64:%s\n", n->title, encbody);
|
||||
char *encbody = r_base64_encode_dyn (n->body, len);
|
||||
char *cmd = r_str_newf ("agn \"%s\" base64:%s\n", n->title, encbody);
|
||||
r_cons_print (cmd);
|
||||
free (cmd);
|
||||
free (encbody);
|
||||
@ -8465,7 +8464,15 @@ static bool convert_dot_str_to_image(RCore *core, char *str, const char *save_pa
|
||||
}
|
||||
|
||||
static void agraph_print_edge_dot(RANode *from, RANode *to, void *user) {
|
||||
r_cons_printf ("\"%s\" -> \"%s\"\n", from->title, to->title);
|
||||
RCore *core = (RCore *)user;
|
||||
ut64 a = r_num_math (NULL, from->title);
|
||||
ut64 b = r_num_math (NULL, to->title);
|
||||
const char *k = sdb_fmt ("agraph.edge.0x%08"PFMT64x"_0x%08"PFMT64x".highlight", a, b);
|
||||
if (sdb_exists (core->sdb, k)) {
|
||||
r_cons_printf ("\"%s\" -> \"%s\" [color=cyan]\n", from->title, to->title);
|
||||
} else {
|
||||
r_cons_printf ("\"%s\" -> \"%s\"\n", from->title, to->title);
|
||||
}
|
||||
}
|
||||
|
||||
static void agraph_print_edge(RANode *from, RANode *to, void *user) {
|
||||
@ -8667,14 +8674,14 @@ R_API void r_core_agraph_print(RCore *core, int use_utf, const char *input) {
|
||||
"node [fillcolor=white, style=filled shape=box "
|
||||
"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_agraph_foreach (core->graph, agraph_print_node_dot, core);
|
||||
r_agraph_foreach_edge (core->graph, agraph_print_edge_dot, core);
|
||||
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);
|
||||
r_agraph_foreach (core->graph, agraph_print_node, core);
|
||||
r_agraph_foreach_edge (core->graph, agraph_print_edge, core);
|
||||
break;
|
||||
case 'J':
|
||||
case 'j': {
|
||||
|
@ -354,3 +354,53 @@ EOF
|
||||
EXPECT=<<EOF
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=highlight edge
|
||||
FILE=-
|
||||
CMDS=<<EOF
|
||||
agn "0x123" body1
|
||||
agn "0x456" body2
|
||||
age 0x123 0x456
|
||||
ageh 0x123 0x456
|
||||
aggd
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
digraph code {
|
||||
rankdir=LR;
|
||||
outputorder=edgesfirst
|
||||
graph [bgcolor=azure];
|
||||
edge [arrowhead=normal, color="#3030c0" style=bold weight=2];
|
||||
node [fillcolor=white, style=filled shape=box fontname="Courier" fontsize="8"];
|
||||
"0x123" [URL="0x123", color="lightgray", label="0x123\nbody1
|
||||
"]
|
||||
"0x456" [URL="0x456", color="lightgray", label="0x456\nbody2
|
||||
"]
|
||||
"0x123" -> "0x456" [color=cyan]
|
||||
}
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=highlight edge management
|
||||
FILE=-
|
||||
CMDS=<<EOF
|
||||
ageh 0x123 0x456
|
||||
ageh
|
||||
ageh-0x123 0x456
|
||||
?e --
|
||||
ageh
|
||||
ageh 0x456 0x123
|
||||
ageh 0x123 0x456
|
||||
ageh 0x123 0x123
|
||||
?e --
|
||||
ageh
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
agraph.edge.0x00000123_0x00000456.highlight=true
|
||||
--
|
||||
agraph.edge.0x00000123_0x00000456.highlight=true
|
||||
--
|
||||
agraph.edge.0x00000456_0x00000123.highlight=true
|
||||
agraph.edge.0x00000123_0x00000123.highlight=true
|
||||
agraph.edge.0x00000123_0x00000456.highlight=true
|
||||
EOF
|
||||
RUN
|
||||
|
Loading…
Reference in New Issue
Block a user