Honor colors in graphviz output ##graph

This commit is contained in:
pancake 2023-09-20 12:21:53 +02:00 committed by pancake
parent 579d45fb97
commit ac752dd4f0
3 changed files with 39 additions and 25 deletions

View File

@ -1834,15 +1834,15 @@ static int core_anal_graph_construct_nodes(RCore *core, RAnalFunction *fcn, int
}
} else {
if (is_html) {
nodes++;
r_cons_printf ("<p class=\"block draggable\" style=\""
"top: %dpx; left: %dpx; width: 400px;\" id=\""
"_0x%08"PFMT64x"\">\n%s</p>\n",
top, left, bbi->addr, str);
left = left? 0: 600;
if (!left) {
top += 250;
}
nodes++;
r_cons_printf ("<p class=\"block draggable\" style=\""
"top: %dpx; left: %dpx; width: 400px;\" id=\""
"_0x%08"PFMT64x"\">\n%s</p>\n",
top, left, bbi->addr, str);
left = left? 0: 600;
if (!left) {
top += 250;
}
} else if (!is_json && !is_keva) {
bool current = r_anal_block_contains (bbi, core->offset);
const char *label_color = bbi->traced
@ -1854,14 +1854,14 @@ static int core_anal_graph_construct_nodes(RCore *core, RAnalFunction *fcn, int
if ((current && color_current) || label_color == pal_traced) {
fill_color = r_str_newf ("fillcolor=\"%s\", ", pal_traced);
} else {
fill_color = r_str_newf ("fontcolor=\"%s\"", label_color);
fill_color = r_str_newf ("fontcolor=\"%s\", ", label_color);
}
nodes++;
if (is_star) {
char *title = get_title (bbi->addr);
char *body_b64 = r_base64_encode_dyn (str, -1);
int color = (bbi && bbi->diff) ? bbi->diff->type : 0;
if (!title || !body_b64) {
if (!title || !body_b64) {
free (body_b64);
free (title);
return false;
@ -1871,12 +1871,20 @@ static int core_anal_graph_construct_nodes(RCore *core, RAnalFunction *fcn, int
free (body_b64);
free (title);
} else {
if (R_STR_ISEMPTY (str)) {
r_cons_printf ("\t\"0x%08"PFMT64x"\" ["
"URL=\"%s/0x%08"PFMT64x"\", "
"%sfontname=\"%s\","
"%sfontname=\"%s\"]\n",
bbi->addr, fcn->name, bbi->addr,
fill_color, font);
} else {
r_cons_printf ("\t\"0x%08"PFMT64x"\" ["
"URL=\"%s/0x%08"PFMT64x"\", "
"%sfontname=\"%s\", "
"label=\"%s\"]\n",
bbi->addr, fcn->name, bbi->addr,
fill_color, font, str);
}
}
free (fill_color);
}
@ -1888,8 +1896,8 @@ static int core_anal_graph_construct_nodes(RCore *core, RAnalFunction *fcn, int
}
static int core_anal_graph_nodes(RCore *core, RAnalFunction *fcn, int opts, PJ *pj) {
int is_json = opts & R_CORE_ANAL_JSON;
int is_keva = opts & R_CORE_ANAL_KEYVALUE;
const bool is_json = opts & R_CORE_ANAL_JSON;
const bool is_keva = opts & R_CORE_ANAL_KEYVALUE;
int nodes = 0;
Sdb *DB = NULL;
char *pal_jump = palColorFor ("graph.true");
@ -1899,13 +1907,8 @@ static int core_anal_graph_nodes(RCore *core, RAnalFunction *fcn, int opts, PJ *
char *pal_traced = palColorFor ("graph.traced");
char *pal_box4 = palColorFor ("graph.box4");
if (!fcn || !fcn->bbs) {
free (pal_jump);
free (pal_fail);
free (pal_trfa);
free (pal_curr);
free (pal_traced);
free (pal_box4);
return -1;
nodes = -1;
goto fin;
}
if (is_keva) {
@ -1948,6 +1951,7 @@ static int core_anal_graph_nodes(RCore *core, RAnalFunction *fcn, int opts, PJ *
pj_end (pj);
pj_end (pj);
}
fin:
free (pal_jump);
free (pal_fail);
free (pal_trfa);

View File

@ -43,6 +43,16 @@ digraph code {
graph [fontsize=8 fontname="Courier" bgcolor=azure splines="ortho"];
node [fillcolor=white style=filled shape=box];
edge [arrowhead="normal"];
"0x00000010" [URL="fcn.00000010/0x00000010", fontcolor="#767676", fontname="Courier"]
"0x0000008a" [URL="fcn.00000010/0x0000008a", fontcolor="#767676", fontname="Courier"]
"0x00000034" [URL="fcn.00000010/0x00000034", fontcolor="#767676", fontname="Courier"]
"0x00000042" [URL="fcn.00000010/0x00000042", fontcolor="#767676", fontname="Courier"]
"0x00000091" [URL="fcn.00000010/0x00000091", fontcolor="#767676", fontname="Courier"]
"0x0000004e" [URL="fcn.00000010/0x0000004e", fontcolor="#767676", fontname="Courier"]
"0x0000005a" [URL="fcn.00000010/0x0000005a", fontcolor="#767676", fontname="Courier"]
"0x00000066" [URL="fcn.00000010/0x00000066", fontcolor="#767676", fontname="Courier"]
"0x00000072" [URL="fcn.00000010/0x00000072", fontcolor="#767676", fontname="Courier"]
"0x0000007e" [URL="fcn.00000010/0x0000007e", fontcolor="#767676", fontname="Courier"]
"0x00000010" -> "0x0000008a" [color="#13a10e"];
"0x00000010" -> "0x00000034" [color="#c50f1f"];
"0x0000008a" -> "0x00000091" [color="#3a96dd"];

View File

@ -423,10 +423,10 @@ digraph code {
graph [fontsize=8 fontname="Courier" bgcolor=azure splines="ortho"];
node [fillcolor=white style=filled shape=box];
edge [arrowhead="normal"];
"0x0000044b" [URL="fcn.0000044b/0x0000044b", fontcolor="#767676"fontname="Courier",label="54: fcn.0000044b (int64_t arg1, int64_t arg2, int64_t arg_4h, int64_t arg_8h, int64_t arg_34h, int64_t arg_38h);\l; arg int64_t arg1 @ rdi\l; arg int64_t arg2 @ rsi\l; arg int64_t arg_4h @ rsp+0x4\l; arg int64_t arg_8h @ rsp+0x8\l; arg int64_t arg_34h @ rsp+0x34\l; arg int64_t arg_38h @ rsp+0x38\l0x0000044b sar esi, 2 ; arg2\l0x0000044e test esi, esi ; arg2\l0x00000450 je 0x479\l"]
"0x00000479" [URL="fcn.0000044b/0x00000479", fontcolor="#767676"fontname="Courier",label="0x00000479 add esp, 0x1c\l0x0000047c pop rbx\l0x0000047d pop rsi\l0x0000047e pop rdi\l0x0000047f pop rbp\l0x00000480 ret\l"]
"0x00000452" [URL="fcn.0000044b/0x00000452", fontcolor="#767676"fontname="Courier",label="0x00000452 lea esi, [rsi] ; arg2\l"]
"0x00000458" [URL="fcn.0000044b/0x00000458", fontcolor="#767676"fontname="Courier",label="0x00000458 mov eax, dword [arg_38h]\l0x0000045c mov dword [rsp], ebp\l0x0000045f mov dword [arg_8h], eax\l0x00000463 mov eax, dword [arg_34h]\l0x00000467 mov dword [arg_4h], eax\l0x0000046b call qword [rbx + rdi*4 - 0xf8]\l0x00000472 add edi, 1 ; arg1\l0x00000475 cmp edi, esi ; arg2\l0x00000477 jne 0x458\l"]
"0x0000044b" [URL="fcn.0000044b/0x0000044b", fontcolor="#767676", fontname="Courier", label="54: fcn.0000044b (int64_t arg1, int64_t arg2, int64_t arg_4h, int64_t arg_8h, int64_t arg_34h, int64_t arg_38h);\l; arg int64_t arg1 @ rdi\l; arg int64_t arg2 @ rsi\l; arg int64_t arg_4h @ rsp+0x4\l; arg int64_t arg_8h @ rsp+0x8\l; arg int64_t arg_34h @ rsp+0x34\l; arg int64_t arg_38h @ rsp+0x38\l0x0000044b sar esi, 2 ; arg2\l0x0000044e test esi, esi ; arg2\l0x00000450 je 0x479\l"]
"0x00000479" [URL="fcn.0000044b/0x00000479", fontcolor="#767676", fontname="Courier", label="0x00000479 add esp, 0x1c\l0x0000047c pop rbx\l0x0000047d pop rsi\l0x0000047e pop rdi\l0x0000047f pop rbp\l0x00000480 ret\l"]
"0x00000452" [URL="fcn.0000044b/0x00000452", fontcolor="#767676", fontname="Courier", label="0x00000452 lea esi, [rsi] ; arg2\l"]
"0x00000458" [URL="fcn.0000044b/0x00000458", fontcolor="#767676", fontname="Courier", label="0x00000458 mov eax, dword [arg_38h]\l0x0000045c mov dword [rsp], ebp\l0x0000045f mov dword [arg_8h], eax\l0x00000463 mov eax, dword [arg_34h]\l0x00000467 mov dword [arg_4h], eax\l0x0000046b call qword [rbx + rdi*4 - 0xf8]\l0x00000472 add edi, 1 ; arg1\l0x00000475 cmp edi, esi ; arg2\l0x00000477 jne 0x458\l"]
"0x0000044b" -> "0x00000479" [color="#13a10e"];
"0x0000044b" -> "0x00000452" [color="#c50f1f"];
"0x00000452" -> "0x00000458" [color="cyan"];