diff --git a/binr/radare2/radare2.c b/binr/radare2/radare2.c index da8725a0d7..ce18b51bea 100644 --- a/binr/radare2/radare2.c +++ b/binr/radare2/radare2.c @@ -101,7 +101,7 @@ static int main_help(int line) { printf ( "Scripts:\n" " system "R2_PREFIX"/share/radare2/radare2rc\n" - " user ~/.radare2rc\n" + " user ~/.radare2rc ${RHOMEDIR}/radare2/radare2rc\n" " file ${filename}.r2\n" "Environment:\n" " RHOMEDIR ~/.config/radare2\n" @@ -437,6 +437,11 @@ int main(int argc, char **argv) { r_core_cmd_file (&r, homerc); free (homerc); } + homerc = r_str_home ("/.config/radare2/radare2rc"); + if (homerc) { + r_core_cmd_file (&r, homerc); + free (homerc); + } } if (asmarch) r_config_set (r.config, "asm.arch", asmarch); if (asmbits) r_config_set (r.config, "asm.bits", asmbits); diff --git a/libr/anal/reflines.c b/libr/anal/reflines.c index 1572810c22..5d0fb1055a 100644 --- a/libr/anal/reflines.c +++ b/libr/anal/reflines.c @@ -95,7 +95,7 @@ R_API char* r_anal_reflines_str(void *core, ut64 addr, int opts) { str = r_str_concat (str, (ref->from>ref->to)? "." : "`"); ch = '-'; } else if (addr == ref->from) { - str = r_str_concat (str, (ref->from>ref->to)? "`" : "," ); + str = r_str_concat (str, (ref->from>ref->to)? "`" : ","); ch = '='; } else if (ref->from < ref->to) { if (addr > ref->from && addr < ref->to) { @@ -118,32 +118,33 @@ R_API char* r_anal_reflines_str(void *core, ut64 addr, int opts) { //str = r_str_concat (str, (dir==1)?"-> ":(dir==2)?"=< ":" "); str = r_str_concat (str, (dir==1)? "-> " :(dir==2)? "=< " : " "); if (((RCore*)core)->anal->lineswidth>0) { - l = r_str_len_utf8 (str); - if (l > ((RCore*)core)->anal->lineswidth) - r_str_cpy (str, str + l - ((RCore*)core)->anal->lineswidth); + int lw = ((RCore*)core)->anal->lineswidth; + l = strlen (str); + if (l > lw) { + r_str_cpy (str, str + l - lw); + } else { + char pfx[128]; + if (l >= lw) lw = 0; else lw -= l; + memset (pfx, ' ', sizeof (pfx)); + if (lw>=sizeof (pfx)) lw = sizeof (pfx); + pfx[lw] = 0; + if (lw>0) str = r_str_prefix (str, pfx); + } } /* HACK */ if (((RCore*)core)->utf8 && ((RCore*)core)->cons->vline) { - RCons *cons = ((RCore*)core)->cons; + RCons *c = ((RCore*)core)->cons; //str = r_str_replace (str, "=", "-", 1); - str = r_str_replace (str, "<", cons->vline[ARROW_LEFT], 1); - str = r_str_replace (str, ">", cons->vline[ARROW_RIGHT], 1); - str = r_str_replace (str, "|", cons->vline[LINE_VERT], 1); - str = r_str_replace (str, "=", cons->vline[LINE_HORIZ], 1); - str = r_str_replace (str, "-", cons->vline[LINE_HORIZ], 1); + str = r_str_replace (str, "<", c->vline[ARROW_LEFT], 1); + str = r_str_replace (str, ">", c->vline[ARROW_RIGHT], 1); + str = r_str_replace (str, "|", c->vline[LINE_VERT], 1); + str = r_str_replace (str, "=", c->vline[LINE_HORIZ], 1); + str = r_str_replace (str, "-", c->vline[LINE_HORIZ], 1); //str = r_str_replace (str, ".", "\xe2\x94\x8c", 1); - str = r_str_replace (str, ",", cons->vline[LUP_CORNER], 1); - str = r_str_replace (str, ".", cons->vline[LUP_CORNER], 1); - str = r_str_replace (str, "`", cons->vline[LDWN_CORNER], 1); - } - if (((RCore*)core)->anal->lineswidth>0) { - char pfx[128]; - int l = ((RCore*)core)->anal->lineswidth-r_str_len_utf8 (str); - memset (pfx, ' ', sizeof (pfx)); - if (l>=sizeof(pfx)) l = sizeof (pfx)-1; - pfx[l] = 0; - str = r_str_prefix (str, pfx); + str = r_str_replace (str, ",", c->vline[LUP_CORNER], 1); + str = r_str_replace (str, ".", c->vline[LUP_CORNER], 1); + str = r_str_replace (str, "`", c->vline[LDWN_CORNER], 1); } return str; } diff --git a/libr/core/cmd_cmp.c b/libr/core/cmd_cmp.c index 6a9afb5289..3443d56374 100644 --- a/libr/core/cmd_cmp.c +++ b/libr/core/cmd_cmp.c @@ -336,7 +336,12 @@ static int cmd_cmp(void *data, const char *input) { " cf [file] Compare contents of file at current seek\n" " cg[o] [file] Graphdiff current file and [file]\n" " cw[us?] [...] Compare memory watchers\n" - " cat [file] Show contents of file (see pwd, ls)\n"); + " cat [file] Show contents of file (see pwd, ls)\n" + " cl|cls|clear Clear screen\n"); + break; + case 'l': + r_cons_clear (); + r_cons_gotoxy (0, 0); break; default: eprintf ("Usage: c[?48cdDxfw] [argument]\n"); diff --git a/libr/core/core.c b/libr/core/core.c index 63ff3abc88..11cd945820 100644 --- a/libr/core/core.c +++ b/libr/core/core.c @@ -594,7 +594,8 @@ R_API RCore *r_core_fini(RCore *c) { r_core_file_free (c->file); c->file = NULL; r_list_free (c->files); - r_list_free (c->watchers); + if (c->watchers != UT64_MAX) + r_list_free (c->watchers); free (c->num); r_cmd_free (c->rcmd); r_anal_free (c->anal); diff --git a/libr/core/disasm.c b/libr/core/disasm.c index fdd387afc2..f05eb22888 100644 --- a/libr/core/disasm.c +++ b/libr/core/disasm.c @@ -65,10 +65,8 @@ R_API RAnalHint *r_core_hint_begin (RCore *core, RAnalHint* hint, ut64 at) { // this is another random hack for reflines.. crappy stuff static char *filter_refline2(RCore *core, const char *str) { - char *p = r_str_replace (strdup (str), "|", core->cons->vline[LINE_VERT], 1); - p = r_str_replace (strdup (p), "`", core->cons->vline[LINE_VERT], 1); + char *p, *s = strdup (str); char n = '|'; - char *s = strdup (str); for (p=s; *p; p++) { switch (*p) { case '`': @@ -82,18 +80,13 @@ static char *filter_refline2(RCore *core, const char *str) { break; } } + s = r_str_replace (s, "|", core->cons->vline[LINE_VERT], 1); + s = r_str_replace (s, "`", core->cons->vline[LINE_VERT], 1); return s; } static char *filter_refline(RCore *core, const char *str) { char *p, *s = strdup (str); - p = strstr (s, core->cons->vline[ARROW_RIGHT]); - if (p) - p = r_str_replace (strdup (p), core->cons->vline[ARROW_RIGHT], " ", 0); - - p = strstr (s, core->cons->vline[ARROW_LEFT]); - if (p) - p = r_str_replace (strdup (p), core->cons->vline[ARROW_LEFT], " ", 0); p = s; p = r_str_replace (strdup (p), "`", @@ -103,6 +96,13 @@ static char *filter_refline(RCore *core, const char *str) { p = r_str_replace (strdup (p), core->cons->vline[LINE_HORIZ], core->cons->vline[LINE_VERT], 1); // "=" -> "|" + p = strstr (s, core->cons->vline[ARROW_RIGHT]); + if (p) + p = r_str_replace (strdup (p), core->cons->vline[ARROW_RIGHT], " ", 0); + + p = strstr (s, core->cons->vline[ARROW_LEFT]); + if (p) + p = r_str_replace (strdup (p), core->cons->vline[ARROW_LEFT], " ", 0); return s; } @@ -769,12 +769,12 @@ toro: if (show_color) { r_cons_printf (Color_RESET"%s%s"Color_RESET, color_fline, f ? pre : " "); - } else - r_cons_printf (f ? pre : " "); + } else r_cons_printf (f ? pre : " "); } } if (!linesright && show_lines && line) { if (show_color) { +// XXX line is too long wtf r_cons_printf ("%s%s"Color_RESET, color_flow, line); } else r_cons_printf (line); } diff --git a/libr/core/visual.c b/libr/core/visual.c index e4d05c8296..f7444957d7 100644 --- a/libr/core/visual.c +++ b/libr/core/visual.c @@ -66,6 +66,48 @@ static void r_core_visual_mark_seek(RCore *core, ut8 ch) { r_core_seek (core, marks[ch], 1); } +static void visual_help() { + r_cons_clear00 (); + r_cons_printf ( + "Visual mode help:\n" + " ? show this help or manpage in cursor mode\n" + " _ enter the hud\n" + " . seek to program counter\n" + " / in cursor mode search in current block\n" + " :cmd run radare command\n" + " ;[-]cmt add/remove comment\n" + " /*+-[] change block size, [] = resize hex.cols\n" + " >||< seek aligned to block size\n" + " i/a/A (i)nsert hex, (a)ssemble code, visual (A)ssembler\n" + " b/B toggle breakpoint / automatic block size\n" + " c/C toggle (c)ursor and (C)olors\n" + " d[f?] define function, data, code, ..\n" + " D enter visual diff mode (set diff.from/to)\n" + " e edit eval configuration variables\n" + " f/F set/unset flag\n" + " gG go seek to begin and end of file (0-$s)\n" + " hjkl move around (or HJKL) (left-down-up-right)\n" + " mK/'K mark/go to Key (any key)\n" + " M walk the mounted filesystems\n" + " n/N seek next/prev function/flag/hit (scr.nkey)\n" + " p/P rotate print modes (hex, disasm, debug, words, buf)\n" + " q back to radare shell\n" + " R randomize color palette (ecr)\n" + " sS step / step over\n" + " t track flags (browse symbols, functions..)\n" + " T browse anal info and comments\n" + " v visual code analysis menu\n" + " V/W (V)iew graph using cmd.graph (agv?), open (W)ebUI\n" + " uU undo/redo seek\n" + " x show xrefs to seek between them\n" + " yY copy and paste selection\n" + " z toggle zoom mode\n" + ); + r_cons_flush (); + r_cons_any_key (); + r_cons_clear00 (); +} + static void r_core_visual_mark(RCore *core, ut8 ch) { if (!marks_init) { int i; @@ -249,6 +291,29 @@ R_API void r_core_visual_seek_animation (RCore *core, ut64 addr) { r_core_seek (core, addr, 1); } +static int prevopsz (RCore *core, ut64 addr) { + const int delta = 32; + ut64 target = addr; + ut64 base = target-delta; + int len, ret, i; + ut8 buf[delta*2]; + RAnalOp op; + + r_core_read_at (core, base, buf, sizeof (buf)); + for (i=0; ianal, &op, addr+i, + buf+i, sizeof (buf)-i); + if (!ret) continue; + len = op.length; + r_anal_op_fini (&op); + if (len<1) continue; + i += len-1; + if (target == base+i+1) + return len; + } + return 4; +} + R_API int r_core_visual_cmd(RCore *core, int ch) { RAsmOp op; char buf[4096]; @@ -551,6 +616,7 @@ R_API int r_core_visual_cmd(RCore *core, int ch) { if (core->printidx == 1 || core->printidx == 2) cols = r_asm_disassemble (core->assembler, &op, core->block+cursor, 32); + if (cols<1) cols = 1; cursor += cols; ocursor = -1; offscreen = (core->cons->rows-3)*cols; @@ -572,6 +638,11 @@ R_API int r_core_visual_cmd(RCore *core, int ch) { break; case 'J': if (curset) { + if (core->printidx == 1 || core->printidx == 2) { + cols = r_asm_disassemble (core->assembler, + &op, core->block+cursor, 32); + if (cols<1) cols = 1; + } if (ocursor==-1) ocursor = cursor; cursor += cols; offscreen = (core->cons->rows-3)*cols; @@ -585,20 +656,18 @@ R_API int r_core_visual_cmd(RCore *core, int ch) { case 'k': if (curset) { if (core->printidx == 1 || core->printidx == 2) - cols = 4; + cols = prevopsz (core, core->offset+cursor); cursor -= cols; ocursor = -1; if (cursor<0) { - if (core->offset>=cols) + if (core->offset>=cols) { r_core_seek (core, core->offset-cols, 1); - cursor += cols; + cursor += cols; + } } } else { if (core->printidx == 1 || core->printidx == 2) { - cols = core->inc; - for (i = 0; i < R_CORE_ASMSTEPS; i++) - if (core->offset == core->asmsteps[i].offset) - cols = core->asmsteps[i].cols; + cols = prevopsz (core, core->offset); } if (core->offset >= cols) r_core_seek (core, core->offset-cols, 1); @@ -608,28 +677,8 @@ R_API int r_core_visual_cmd(RCore *core, int ch) { case 'K': if (curset) { if (ocursor==-1) ocursor=cursor; - { - char *man = NULL; - /* check for manpage */ - RAnalOp *op = r_core_anal_op (core, core->offset+cursor); - if (op) { - if (op->jump != UT64_MAX) { - RFlagItem *item = r_flag_get_i (core->flags, op->jump); - if (item) { - const char *ptr = r_str_lchr (item->name, '.'); - if (ptr) - man = strdup (ptr+1); - } - } - r_anal_op_free (op); - } - if (man) { - r_cons_clear(); - r_cons_flush(); - r_sys_cmdf ("man %s", man); - break; - } - } + if (core->printidx == 1 || core->printidx == 2) + cols = prevopsz (core, core->offset+cursor); cursor -= cols; if (cursor<0) { if (core->offset>=cols) { @@ -870,44 +919,33 @@ R_API int r_core_visual_cmd(RCore *core, int ch) { zoom = !zoom; break; case '?': - r_cons_clear00 (); - r_cons_printf ( - "Visual mode help:\n" - " _ enter the hud\n" - " . seek to program counter\n" - " / in cursor mode search in current block\n" - " :cmd run radare command\n" - " ;[-]cmt add/remove comment\n" - " /*+-[] change block size, [] = resize hex.cols\n" - " >||< seek aligned to block size\n" - " i/a/A (i)nsert hex, (a)ssemble code, visual (A)ssembler\n" - " b/B toggle breakpoint / automatic block size\n" - " c/C toggle (c)ursor and (C)olors\n" - " d[f?] define function, data, code, ..\n" - " D enter visual diff mode (set diff.from/to)\n" - " e edit eval configuration variables\n" - " f/F set/unset flag\n" - " gG go seek to begin and end of file (0-$s)\n" - " hjkl move around (or HJKL) (left-down-up-right)\n" - " mK/'K mark/go to Key (any key)\n" - " M walk the mounted filesystems\n" - " n/N seek next/prev function/flag/hit (scr.nkey)\n" - " p/P rotate print modes (hex, disasm, debug, words, buf)\n" - " q back to radare shell\n" - " R randomize color palette (ecr)\n" - " sS step / step over\n" - " t track flags (browse symbols, functions..)\n" - " T browse anal info and comments\n" - " v visual code analysis menu\n" - " V/W (V)iew graph using cmd.graph (agv?), open (W)ebUI\n" - " uU undo/redo seek\n" - " x show xrefs to seek between them\n" - " yY copy and paste selection\n" - " z toggle zoom mode\n" - ); - r_cons_flush (); - r_cons_any_key (); - r_cons_clear00 (); + if (curset) { + char *man = NULL; + /* check for manpage */ + RAnalOp *op = r_core_anal_op (core, core->offset+cursor); + if (op) { + if (op->jump != UT64_MAX) { + RFlagItem *item = r_flag_get_i (core->flags, op->jump); + if (item) { + const char *ptr = r_str_lchr (item->name, '.'); + if (ptr) + man = strdup (ptr+1); + } + } + r_anal_op_free (op); + } + if (man) { + char *p = strstr (man, "INODE"); + if (p) *p = 0; + r_cons_clear(); + r_cons_flush(); + r_sys_cmdf ("man %s", man); + free (man); + break; + } + } else { + visual_help(); +} break; case 0x1b: case 'q':