From c7e1fad6bc66debc104497667d73b970c1f99c05 Mon Sep 17 00:00:00 2001 From: pancake Date: Fri, 9 Jan 2015 11:38:00 +0100 Subject: [PATCH] Add Vn (mini-ascii-art graph visual mode) --- libr/cons/canvas.c | 226 +++++++++++++++++++++++--------------------- libr/core/cmd_cmp.c | 2 +- libr/core/graph.c | 52 ++++++++-- 3 files changed, 163 insertions(+), 117 deletions(-) diff --git a/libr/cons/canvas.c b/libr/cons/canvas.c index 4518e4ac82..6e68848ff9 100644 --- a/libr/cons/canvas.c +++ b/libr/cons/canvas.c @@ -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 (y+1)) { - for (i=0;ix2) { - 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;ix2) { - 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 (y+1)) { + for (i=0;ix2) { + 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;ix2) { + 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); + } + } } diff --git a/libr/core/cmd_cmp.c b/libr/core/cmd_cmp.c index 6e7bb9c782..ef21624931 100644 --- a/libr/core/cmd_cmp.c +++ b/libr/core/cmd_cmp.c @@ -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); diff --git a/libr/core/graph.c b/libr/core/graph.c index 6336fac712..9e605009ed 100644 --- a/libr/core/graph.c +++ b/libr/core/graph.c @@ -1,13 +1,14 @@ /* Copyright radare2 2014 - Author: pancake */ #include +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);