Add Vn (mini-ascii-art graph visual mode)

This commit is contained in:
pancake 2015-01-09 11:38:00 +01:00
parent d1489f9b6a
commit c7e1fad6bc
3 changed files with 163 additions and 117 deletions

View File

@ -221,117 +221,129 @@ R_API void r_cons_canvas_fill(RConsCanvas *c, int x, int y, int w, int h, char c
R_API void r_cons_canvas_line (RConsCanvas *c, int x, int y, int x2, int y2, int style) {
int i, onscreen;
switch (style) {
// vertical arrow line
case 0: //
case 0:
if (G (x, y))
W ("v");
if (G (x2, y2))
W ("V");
if (x==x2) {
int min = R_MIN (y,y2)+1;
int max = R_MAX (y,y2);
for (i=min; i<max; i++) {
if (G (x,i))
W ("|");
}
} else {
// --
// TODO: find if there's any collision in this line
int hl = R_ABS (y-y2) / 2;
int hl2 = R_ABS (y-y2)-hl;
hl--;
if (y2 > (y+1)) {
for (i=0;i<hl;i++) {
if (G (x,y+i+1))
W ("|");
}
for (i=0;i<hl2;i++) {
if (G (x2, y+hl+i+1))
W ("|");
}
int w = R_ABS (x-x2);
char *row = malloc (w+2);
if (x>x2) {
w++;
row[0] = '.';
if (w>2)
memset (row+1, '-', w-2);
row[w-1] = '\'';
row[w] = 0;
onscreen = G (x2+w,y+hl+1);
i = G (x2, y+hl+1);
if (!onscreen)
onscreen = i;
} else {
row[0] = '`';
if (w>1)
memset (row+1, '-', w-1);
row[w] = '.';
row[w+1] = 0;
onscreen = G (x+w,y+1+hl);
i = G (x,y+1+hl);
if (!onscreen)
onscreen = i;
}
if (onscreen)
W (row);
free (row);
} else {
int minx = R_MIN (x, x2);
//if (y >= y2) {
int rl = R_ABS (x-x2)/2;
int rl2 = R_ABS (x-x2)-rl+1;
int vl = (R_ABS(y-y2))+1;
if (y+1==y2)
vl--;
for (i=0;i<vl; i++) {
if (G (minx+rl,y2+i))
W ("|");
}
int w = rl;
char *row = malloc (w+1);
if (x>x2) {
row[0] = '.';
if (w>2)
memset (row+1, '-', w-2);
if (w>0)
row[w-1] = '.';
row[w] = 0;
onscreen = G (x2,y2-1);
} else {
row[0] = '`';
if (w>2)
memset (row+1, '-', w-2);
if (w>0)
row[w-1] = '\'';
row[w] = 0;
onscreen = G (x+1,y+1);
}
if (onscreen)
W (row);
w = rl2;
free (row);
row = malloc (rl2+1);
if (x>x2) {
row[0] = '`';
memset (row+1, '-', w-2);
row[w-1] = '\'';
row[w] = 0;
onscreen = G (x2+rl, y+1);
} else {
row[0] = '.';
memset (row+1, '-', w-2);
row[w-1] = '.';
row[w] = 0;
onscreen = G (x+rl, y2-1);
}
if (onscreen)
W (row);
free (row);
}
}
break;
case 1:
if (G (x, y))
W ("t"); //\\");
if (G (x2, y2))
W ("\\");
break;
case 2:
if (G (x, y))
W ("f");
if (G (x2, y2))
W ("/");
break;
}
if (x==x2) {
int min = R_MIN (y,y2)+1;
int max = R_MAX (y,y2);
for (i=min; i<max; i++) {
if (G (x,i))
W ("|");
}
} else {
// --
// TODO: find if there's any collision in this line
int hl = R_ABS (y-y2) / 2;
int hl2 = R_ABS (y-y2)-hl;
hl--;
if (y2 > (y+1)) {
for (i=0;i<hl;i++) {
if (G (x,y+i+1))
W ("|");
}
for (i=0;i<hl2;i++) {
if (G (x2, y+hl+i+1))
W ("|");
}
int w = R_ABS (x-x2);
char *row = malloc (w+2);
if (x>x2) {
w++;
row[0] = '.';
if (w>2)
memset (row+1, '-', w-2);
row[w-1] = '\'';
row[w] = 0;
onscreen = G (x2+w,y+hl+1);
i = G (x2, y+hl+1);
if (!onscreen)
onscreen = i;
} else {
row[0] = '`';
row[0] = '\'';
if (w>1)
memset (row+1, '-', w-1);
row[w] = '.';
row[w+1] = 0;
onscreen = G (x+w,y+1+hl);
i = G (x,y+1+hl);
if (!onscreen)
onscreen = i;
}
if (onscreen)
W (row);
free (row);
} else {
int minx = R_MIN (x, x2);
//if (y >= y2)
int rl = R_ABS (x-x2)/2;
int rl2 = R_ABS (x-x2)-rl+1;
int vl = (R_ABS(y-y2))+1;
if (y+1==y2)
vl--;
for (i=0;i<vl; i++) {
if (G (minx+rl,y2+i))
W ("|");
}
int w = rl;
char *row = malloc (w+1);
if (x>x2) {
row[0] = '.';
if (w>2)
memset (row+1, '-', w-2);
if (w>0)
row[w-1] = '.';
row[w] = 0;
onscreen = G (x2,y2-1);
} else {
row[0] = '`';
if (w>2)
memset (row+1, '-', w-2);
if (w>0)
row[w-1] = '\'';
row[w] = 0;
onscreen = G (x+1,y+1);
}
if (onscreen)
W (row);
w = rl2;
free (row);
row = malloc (rl2+1);
if (x>x2) {
row[0] = '`';
memset (row+1, '-', w-2);
row[w-1] = '\'';
row[w] = 0;
onscreen = G (x2+rl, y+1);
} else {
row[0] = '.';
memset (row+1, '-', w-2);
row[w-1] = '.';
row[w] = 0;
onscreen = G (x+rl, y2-1);
}
if (onscreen)
W (row);
free (row);
}
}
}

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2014 - pancake */
/* radare - LGPL - Copyright 2009-2015 - pancake */
R_API void r_core_cmpwatch_free (RCoreCmpWatcher *w) {
free (w->ndata);

View File

@ -1,13 +1,14 @@
/* Copyright radare2 2014 - Author: pancake */
#include <r_core.h>
int small_nodes = 0;
int simple_mode = 1;
static void reloadNodes(RCore *core) ;
#define OS_SIZE 128
struct {
int nodes[OS_SIZE];
int size;
} ostack;
struct {
int nodes[OS_SIZE];
int size;
} ostack;
// TODO: handle mouse wheel
@ -48,11 +49,30 @@ static Edge edges[] = {
#define W(x) r_cons_canvas_write (can, x)
#define B(x,y,w,h) r_cons_canvas_box(can, x,y,w,h)
#define L(x,y,x2,y2) r_cons_canvas_line(can, x,y,x2,y2,0)
#define L1(x,y,x2,y2) r_cons_canvas_line(can, x,y,x2,y2,1)
#define L2(x,y,x2,y2) r_cons_canvas_line(can, x,y,x2,y2,2)
#define F(x,y,x2,y2,c) r_cons_canvas_fill(can, x,y,x2,y2,c,0)
static void Node_print(RConsCanvas *can, Node *n, int cur) {
char title[128];
if (small_nodes) {
if (!G (n->x+2, n->y-1))
return;
if (cur) {
W("[_@@_]");
G (-can->sx, -can->sy+2);
snprintf (title, sizeof (title)-1,
"0x%08"PFMT64x":", n->addr);
W (title);
G (-can->sx, -can->sy+3);
W (n->text);
} else {
W("[____]");
}
return;
}
if (!can)
return;
n->w = r_str_bounds (n->text, &n->h);
@ -94,7 +114,15 @@ static void Edge_print(RConsCanvas *can, Node *a, Node *b, int nth) {
y = a->y + a->h;
x2 = b->x + xinc;
y2 = b->y;
L (x, y, x2, y2);
if (small_nodes) {
if (nth) {
L2 (x, y, x2, y2);
} else {
L1 (x, y, x2, y2);
}
} else {
L (x, y, x2, y2);
}
}
static int Edge_node(Edge *edges, int cur, int nth) {
@ -495,9 +523,9 @@ repeat:
}
break;
case 'O':
// free nodes or leak
simple_mode = !!!simple_mode;
reloadNodes(core);
// free nodes or leak
simple_mode = !!!simple_mode;
reloadNodes(core);
break;
case 'V':
callgraph = !!!callgraph;
@ -555,12 +583,13 @@ reloadNodes(core);
r_cons_clear00 ();
r_cons_printf ("Visual Ascii Art graph keybindings:\n"
" . - center graph to the current node\n"
" C - toggle scr.color\n"
" hjkl - move node\n"
" asdw - scroll canvas\n"
" tab - select next node\n"
" TAB - select previous node\n"
" t/f - follow true/false edges\n"
" C - toggle scr.color\n"
" n - toggle mini-graph\n"
" O - toggle disasm mode\n"
" u - select previous node\n"
" V - toggle basicblock / call graphs\n"
@ -591,6 +620,11 @@ reloadNodes(core);
case 'A': can->sx -= 5; break;
case 'D': can->sx += 5; break;
break;
case 'n':
small_nodes = small_nodes ? 0: 1;
reloadNodes (core);
//Layout_depth (nodes, edges);
break;
case 'u':
curnode = OS_POP(); // wtf double push ?
updateSeek (can, &N, w, h, 0);