mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-23 21:29:49 +00:00
Fix issue when highlighting edges on low addresses + test
This commit is contained in:
parent
107420e49d
commit
c12ad43b38
@ -333,8 +333,8 @@ static char *get_node_color(int color, int cur) {
|
||||
return cur ? cons->context->pal.graph_box2 : cons->context->pal.graph_box;
|
||||
}
|
||||
return color ? (\
|
||||
color==R_ANAL_DIFF_TYPE_MATCH ? cons->context->pal.graph_diff_match:
|
||||
color==R_ANAL_DIFF_TYPE_UNMATCH? cons->context->pal.graph_diff_unmatch : cons->context->pal.graph_diff_new): cons->context->pal.graph_diff_unknown;
|
||||
color == R_ANAL_DIFF_TYPE_MATCH ? cons->context->pal.graph_diff_match:
|
||||
color == R_ANAL_DIFF_TYPE_UNMATCH? cons->context->pal.graph_diff_unmatch : cons->context->pal.graph_diff_new): cons->context->pal.graph_diff_unknown;
|
||||
}
|
||||
|
||||
static void normal_RANode_print(const RAGraph *g, const RANode *n, int cur) {
|
||||
@ -2326,7 +2326,10 @@ static void add_child(RCore *core, RAGraph *g, RANode *u, ut64 jump) {
|
||||
char *title = get_title (jump);
|
||||
RANode *v = r_agraph_get_node (g, title);
|
||||
free (title);
|
||||
bool hl = sdb_const_get (core->sdb, sdb_fmt ("agraph.edge.%s_%s.highlight", u->title, title), 0) != NULL;
|
||||
ut64 a = r_num_get (NULL, u->title);
|
||||
ut64 b = r_num_get (NULL, title);
|
||||
const char *k = sdb_fmt ("agraph.edge.0x%"PFMT64x"_0x%"PFMT64x".highlight", a, b);
|
||||
bool hl = sdb_exists (core->sdb, k);
|
||||
r_agraph_add_edge (g, u, v, hl);
|
||||
}
|
||||
|
||||
@ -2950,10 +2953,19 @@ static void agraph_print_edges(RAGraph *g) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (sdb_const_get (g->db, sdb_fmt ("agraph.edge.%s_%s.highlight", a->title, b->title), 0)) {
|
||||
style.ansicolor = Color_BYELLOW; // it's CYAN for graphviz
|
||||
} else {
|
||||
style.ansicolor = NULL;
|
||||
if (!*b->title) {
|
||||
/// XXX non-colorized edges happen because of those ghost nodes
|
||||
// eprintf ("%s|%s%c", a->title, b->title, 10);
|
||||
}
|
||||
if (!R_STR_ISEMPTY (a->title) && !R_STR_ISEMPTY (b->title)) {
|
||||
ut64 aa = r_num_get (NULL, a->title);
|
||||
ut64 bb = r_num_get (NULL, b->title);
|
||||
const char *k = sdb_fmt ("agraph.edge.0x%"PFMT64x"_0x%"PFMT64x".highlight", aa, bb);
|
||||
if (sdb_exists (g->db, k)) {
|
||||
style.ansicolor = Color_BYELLOW; // it's CYAN for graphviz
|
||||
} else {
|
||||
style.ansicolor = NULL;
|
||||
}
|
||||
}
|
||||
switch (g->layout) {
|
||||
case 0:
|
||||
@ -3855,7 +3867,9 @@ R_API void r_agraph_add_edge(const RAGraph *g, RANode *a, RANode *b, bool highli
|
||||
r_return_if_fail (g && a && b);
|
||||
r_graph_add_edge (g->graph, a->gnode, b->gnode);
|
||||
if (highlight) {
|
||||
const char *k = sdb_fmt ("agraph.edge.%s_%s.highlight", a->title, b->title);
|
||||
ut64 aa = r_num_get (NULL, a->title);
|
||||
ut64 bb = r_num_get (NULL, b->title);
|
||||
const char *k = sdb_fmt ("agraph.edge.0x%"PFMT64x"_0x%"PFMT64x".highlight", aa, bb);
|
||||
sdb_set (g->db, k, "true", 0);
|
||||
}
|
||||
if (a->title && b->title) {
|
||||
@ -4848,13 +4862,8 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int
|
||||
{
|
||||
RIOUndos *undo = r_io_sundo (core->io, core->offset);
|
||||
r_io_sundo_redo (core->io);
|
||||
|
||||
char *a = r_str_newf ("0x%08"PFMT64x, undo->off);
|
||||
char *b = r_str_newf ("0x%08"PFMT64x, core->offset);
|
||||
char *c = r_str_newf ("agraph.edge.%s_%s.highlight", a, b);
|
||||
char *c = r_str_newf ("agraph.edge.0x%"PFMT64x"_0x%"PFMT64x".highlight", undo->off, core->offset);
|
||||
sdb_set (g->db, c, "true", 0);
|
||||
free (a);
|
||||
free (b);
|
||||
free (c);
|
||||
}
|
||||
break;
|
||||
|
@ -1488,12 +1488,15 @@ static int core_anal_graph_construct_edges(RCore *core, RAnalFunction *fcn, int
|
||||
char *from = get_title (bbi->addr);
|
||||
char *to = get_title (bbi->jump);
|
||||
r_cons_printf ("age %s %s\n", from, to);
|
||||
free(from);
|
||||
free(to);
|
||||
free (from);
|
||||
free (to);
|
||||
} else {
|
||||
const char* edge_color = bbi->fail != -1 ? pal_jump : pal_trfa;
|
||||
if (sdb_const_get (core->sdb, sdb_fmt ("agraph.edge.0x%"PFMT64x"_0x%"PFMT64x".highlight", bbi->addr, bbi->jump), 0)) {
|
||||
edge_color = "cyan";
|
||||
}
|
||||
r_cons_printf (" \"0x%08"PFMT64x"\" -> \"0x%08"PFMT64x"\" "
|
||||
"[color=\"%s\"];\n", bbi->addr, bbi->jump,
|
||||
bbi->fail != -1 ? pal_jump : pal_trfa);
|
||||
"[color=\"%s\"];\n", bbi->addr, bbi->jump, edge_color);
|
||||
core_anal_color_curr_node (core, bbi);
|
||||
}
|
||||
}
|
||||
|
@ -8467,7 +8467,7 @@ static void agraph_print_edge_dot(RANode *from, RANode *to, void *user) {
|
||||
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);
|
||||
const char *k = sdb_fmt ("agraph.edge.0x%"PFMT64x"_0x%"PFMT64x".highlight", a, b);
|
||||
if (sdb_exists (core->sdb, k)) {
|
||||
r_cons_printf ("\"%s\" -> \"%s\" [color=cyan]\n", from->title, to->title);
|
||||
} else {
|
||||
@ -8564,7 +8564,7 @@ static bool cmd_ageh(RCore *core, const char *input) {
|
||||
ut64 a = r_num_math (core->num, arg);
|
||||
ut64 b = r_num_math (core->num, sp);
|
||||
|
||||
const char *k = sdb_fmt ("agraph.edge.0x%08"PFMT64x"_0x%08"PFMT64x".highlight", a, b);
|
||||
const char *k = sdb_fmt ("agraph.edge.0x%"PFMT64x"_0x%"PFMT64x".highlight", a, b);
|
||||
sdb_set (core->sdb, k, add? "true": "", 0);
|
||||
return true;
|
||||
}
|
||||
|
@ -395,12 +395,41 @@ ageh 0x123 0x123
|
||||
ageh
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
agraph.edge.0x00000123_0x00000456.highlight=true
|
||||
agraph.edge.0x123_0x456.highlight=true
|
||||
--
|
||||
agraph.edge.0x00000123_0x00000456.highlight=true
|
||||
agraph.edge.0x123_0x456.highlight=true
|
||||
--
|
||||
agraph.edge.0x00000456_0x00000123.highlight=true
|
||||
agraph.edge.0x00000123_0x00000123.highlight=true
|
||||
agraph.edge.0x00000123_0x00000456.highlight=true
|
||||
agraph.edge.0x123_0x123.highlight=true
|
||||
agraph.edge.0x123_0x456.highlight=true
|
||||
agraph.edge.0x456_0x123.highlight=true
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=lowaddr lights
|
||||
FILE=bins/elf/elf_one_symbol_shdr
|
||||
ARGS=-n
|
||||
CMDS=<<EOF
|
||||
s 0x44b
|
||||
af
|
||||
ageh 0x452 0x458
|
||||
ageh
|
||||
agfd
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
agraph.edge.0x452_0x458.highlight=true
|
||||
digraph code {
|
||||
graph [bgcolor=azure fontsize=8 fontname="Courier" splines="ortho"];
|
||||
node [fillcolor=gray style=filled shape=box];
|
||||
edge [arrowhead="normal"];
|
||||
"0x0000044b" [URL="fcn.0000044b/0x0000044b", fillcolor="white",color="#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 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\l; arg int64_t arg1 @ rdi\l; arg int64_t arg2 @ rsi\l0x0000044b sar esi, 2 ; arg2\l0x0000044e test esi, esi ; arg2\l0x00000450 je 0x479\l"]
|
||||
"0x00000479" [URL="fcn.0000044b/0x00000479", fillcolor="white",color="#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", fillcolor="white",color="#767676", fontname="Courier",label="0x00000452 lea esi, [rsi] ; arg2\l"]
|
||||
"0x00000458" [URL="fcn.0000044b/0x00000458", fillcolor="white",color="#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"];
|
||||
"0x00000458" -> "0x00000458" [color="#13a10e"];
|
||||
"0x00000458" -> "0x00000479" [color="#c50f1f"];
|
||||
}
|
||||
EOF
|
||||
RUN
|
||||
|
Loading…
Reference in New Issue
Block a user