static void visual_help() { r_cons_clear00 (); r_cons_less_str ( "Visual mode help:\n" " ? show this help or manpage in cursor mode\n" " & rotate asm.bits between supported 8, 16, 32, 64\n" " % in cursor mode finds matching pair, otherwise toggle autoblocksz\n" " @ set cmd.vprompt to run commands before the visual prompt\n" " ! enter into the visual panels mode\n" " _ enter the hud\n" " = set cmd.vprompt (top row)\n" " | set cmd.cprompt (right column)\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" " a/A (a)ssemble code, visual (A)ssembler\n" " b toggle breakpoint\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 or browse flags. f- to unset, F to browse, ..\n" " gG go seek to begin and end of file (0-$s)\n" " hjkl move around (or HJKL) (left-down-up-right)\n" " i insert hex or string (in hexdump) use tab to toggle\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" " o go/seek to given offset\n" " O toggle asm.esil\n" " p/P rotate print modes (hex, disasm, debug, words, buf)\n" " q back to radare shell\n" " r browse anal info and comments\n" " R randomize color palette (ecr)\n" " sS step / step over\n" " T enter textlog chat console (TT)\n" " uU undo/redo seek\n" " v visual code analysis menu\n" " V (V)iew graph using cmd.graph (agv?)\n" " wW seek cursor to next/prev word\n" " xX show xrefs/refs of current function from/to data/code\n" " yY copy and paste selection\n" " z fold/unfold comments in disassembly\n" " Z toggle zoom mode\n" " Enter follow address of jump/call\n" "Function Keys: (See 'e key.'), defaults to:\n" " F2 toggle breakpoint\n" " F7 single step\n" " F8 step over\n" " F9 continue\n" ); r_cons_flush (); r_cons_clear00 (); }
static void visual_help() { r_cons_clear00 (); r_cons_less_str ( "Visual mode help:\n" " ? show this help or manpage in cursor mode\n" " & rotate asm.bits between supported 8, 16, 32, 64\n" " ! run r2048 game\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" " o go/seek to given offset\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" " xX show xrefs/refs of current function from/to data/code\n" " yY copy and paste selection\n" " z toggle zoom mode\n" " Enter follow address of jump/call\n" "Function Keys: (See 'e key.'), defaults to:\n" " F2 toggle breakpoint\n" " F7 single step\n" " F8 step over\n" " F9 continue\n" ); r_cons_flush (); r_cons_clear00 (); }
R_API int r_core_visual_xrefs_x (RCore *core) { int ret = 0; #if FCN_OLD char ch; int count = 0; RList *xrefs = NULL; RAnalRef *refi; RListIter *iter; RAnalFunction *fun; if ((xrefs = r_anal_xref_get (core->anal, core->offset))) { r_cons_gotoxy (1, 1); r_cons_printf ("[GOTO XREF]> \n"); if (r_list_empty (xrefs)) { r_cons_printf ("\tNo XREF found at 0x%"PFMT64x"\n", core->offset); r_cons_any_key (NULL); r_cons_clear00 (); } else { r_list_foreach (xrefs, iter, refi) { fun = r_anal_get_fcn_in (core->anal, refi->addr, R_ANAL_FCN_TYPE_NULL); r_cons_printf (" [%i] 0x%08"PFMT64x" %s XREF 0x%08"PFMT64x" (%s) \n", count, refi->at, refi->type==R_ANAL_REF_TYPE_CODE?"CODE (JMP)": refi->type==R_ANAL_REF_TYPE_CALL?"CODE (CALL)":"DATA", refi->addr, fun?fun->name:"unk"); if (++count > 9) break; } }
// TODO: integrate in '/' command with search.inblock ? static void visual_search (RCore *core) { const ut8 *p; int len, d = cursor; char str[128], buf[258]; r_line_set_prompt ("search byte/string in block: "); r_cons_fgets (str, sizeof (str), 0, NULL); len = r_hex_str2bin (str, (ut8*)buf); if (*str=='"') { char *e = strncpy (buf, str+1, sizeof (buf)-1); if (e) { --e; if (*e=='"') *e=0; } len = strlen (buf); } else if (len<1) { strncpy (buf, str, sizeof (buf)-1); len = strlen (str); } p = r_mem_mem (core->block+d, core->blocksize-d, (const ut8*)buf, len); if (p) { cursor = (int)(size_t)(p-core->block); if (len>1) { ocursor = cursor+len-1; } else ocursor = -1; showcursor (core, true); eprintf ("FOUND IN %d\n", cursor); r_cons_any_key (NULL); } else { eprintf ("Cannot find bytes\n"); r_cons_any_key (NULL); r_cons_clear00 (); } }
R_API int r_core_visual_prompt (RCore *core) { char buf[1024]; int ret; #if __UNIX__ r_line_set_prompt (Color_RESET":> "); #else r_line_set_prompt (":> "); #endif showcursor (core, true); r_cons_fgets (buf, sizeof (buf), 0, NULL); if (!strcmp (buf, "q")) { ret = false; } else if (*buf) { r_line_hist_add (buf); r_core_cmd (core, buf, 0); r_cons_flush (); ret = true; } else { ret = false; //r_cons_any_key (NULL); r_cons_clear00 (); showcursor (core, false); } return ret; }
R_API int r_core_visual_prompt (RCore *core) { char buf[1024]; int ret; ut64 oseek = core->offset; #if __UNIX__ r_line_set_prompt (Color_RESET":> "); #else r_line_set_prompt (":> "); #endif showcursor (core, R_TRUE); r_cons_fgets (buf, sizeof (buf), 0, NULL); if (*buf) { r_line_hist_add (buf); r_core_cmd (core, buf, 0); r_cons_flush (); ret = R_TRUE; } else { ret = R_FALSE; //r_cons_any_key (); r_cons_clear00 (); showcursor (core, R_FALSE); } if (curset) r_core_seek (core, oseek, 1); return ret; }
static int readline_callback(void *_a, const char *str) { RCoreVisualAsm *a = _a; int xlen; r_cons_clear00 (); r_cons_printf ("Write your favourite %s-%d opcode...\n\n", r_config_get (a->core->config, "asm.arch"), r_config_get_i (a->core->config, "asm.bits")); if (*str == '?') { r_cons_printf ("0> ?\n\n" "Visual assembler help:\n\n" " assemble input while typing using asm.arch, asm.bits and cfg.bigendian\n" " press enter to quit (prompt if there are bytes to be written)\n" " this assembler supports various directives like .hex ...\n" ); } else { r_asm_code_free (a->acode); a->acode = r_asm_massemble (a->core->assembler, str); r_cons_printf ("%d> %s\n", a->acode? a->acode->len: 0, str); if (a->acode && a->acode->len) r_cons_printf ("* %s\n\n", a->acode->buf_hex); else r_cons_printf ("\n\n"); if (a->acode) { xlen = strlen (a->acode->buf_hex); strcpy (a->codebuf, a->blockbuf); memcpy (a->codebuf, a->acode->buf_hex, xlen); } r_core_cmdf (a->core, "pd 7@b:%s @0x%"PFMT64x, a->codebuf, a->off); } r_cons_flush (); return 1; }
static void printpage (const char *line, int *index, int from, int to) { int i; r_cons_clear00 (); for (i=from; i<to; i++) { // TODO: chop column width, clear lines r_cons_printf ("%s\n", line+index[i]); } r_cons_flush (); }
R_API void r_cons_2048() { int ch; r_cons_set_raw (1); twok_init (); twok_add (); twok_add (); while (twok_fin()) { r_cons_clear00(); r_cons_printf ("[r2048] score: %d moves: %d\n", score, moves); r_cons_flush (); twok_print(); ch = r_cons_readchar (); ch = r_cons_arrow_to_hjkl (ch); switch(ch){ case 'h': twok_move(1,1); break; case 'j': twok_move(0,0); break; case 'k': twok_move(0,1); break; case 'l': twok_move(1,0); break; } if (ch<1||ch =='q') break; } r_cons_clear00(); r_cons_printf ("[r2048] score: %d\n", score ); r_cons_flush (); twok_print(); r_cons_printf ("\n [r2048.score] %d\n", score ); do { ch = r_cons_any_key ("Press 'q' to quit."); } while (ch != 'q' && ch >= 1); r_cons_set_raw (0); }
R_API void r_core_visual_prompt (RCore *core) { char buf[1024]; ut64 oseek = core->offset; #if __UNIX__ r_line_set_prompt (Color_RESET":> "); #else r_line_set_prompt (":> "); #endif r_cons_show_cursor (R_TRUE); r_cons_fgets (buf, sizeof (buf), 0, NULL); r_line_hist_add (buf); r_core_cmd (core, buf, 0); r_cons_any_key (); r_cons_clear00 (); r_cons_show_cursor (R_FALSE); if (curset) r_core_seek (core, oseek, 1); }
static void printpage (const char *line, int *index, RRegexMatch **ms, int from, int to, int w) { int i; RStrpool *p; r_cons_clear00 (); if (from <0 || to <0) { return; } p = r_strpool_new(0); for (i=from; i<to; i++) { color_line(line + index[i], p, ms[i]); r_strpool_ansi_chop(p, w); r_cons_reset_colors(); r_cons_printf ("%s\n", p->str); } r_strpool_free(p); r_cons_flush (); }
R_API int r_core_visual_cmd(RCore *core, int ch) { RAsmOp op; ut64 offset = core->offset; char buf[4096]; int i, ret, offscreen, cols = core->print->cols, delta = 0; ch = r_cons_arrow_to_hjkl (ch); ch = visual_nkey (core, ch); if (ch<2) return 1; // do we need hotkeys for data references? not only calls? if (ch>='0'&& ch<='9') { ut64 off = core->asmqjmps[ch-'0']; if (off != UT64_MAX) { int delta = R_ABS ((st64)off-(st64)offset); r_io_sundo_push (core->io, offset); if (curset && delta<100) { cursor = delta; } else { r_core_visual_seek_animation (core, off); //r_core_seek (core, off, 1); } r_core_block_read (core, 1); } } else switch (ch) { case 0x0d: { r_cons_enable_mouse (R_TRUE); RAnalOp *op = r_core_anal_op (core, core->offset+cursor); if (op) { if (op->type == R_ANAL_OP_TYPE_JMP || op->type == R_ANAL_OP_TYPE_CJMP || op->type == R_ANAL_OP_TYPE_CALL) { r_io_sundo_push (core->io, offset); r_core_visual_seek_animation(core, op->jump); } } r_anal_op_free (op); } break; case 90: // shift+tab if (!strcmp (printfmt[0], "x")) printfmt[0] = "pxa"; else printfmt[0] = "x"; break; case 9: // tab { // XXX: unify diff mode detection ut64 f = r_config_get_i (core->config, "diff.from"); ut64 t = r_config_get_i (core->config, "diff.to"); if (f == t && f == 0) { core->print->col = core->print->col==1? 2: 1; } else { ut64 delta = offset - f; r_core_seek (core, t+delta, 1); r_config_set_i (core->config, "diff.from", t); r_config_set_i (core->config, "diff.to", f); } } break; case 'a': if (core->file && !(core->file->rwx & 2)) { r_cons_printf ("\nFile has been opened in read-only mode. Use -w flag\n"); r_cons_any_key (); return R_TRUE; } r_cons_printf ("Enter assembler opcodes separated with ';':\n"); showcursor (core, R_TRUE); r_cons_flush (); r_cons_set_raw (R_FALSE); strcpy (buf, "wa "); r_line_set_prompt (":> "); if (r_cons_fgets (buf+3, 1000, 0, NULL) <0) buf[0]='\0'; if (*buf) { if (curset) r_core_seek (core, core->offset + cursor, 0); r_core_cmd (core, buf, R_TRUE); if (curset) r_core_seek (core, core->offset - cursor, 1); } showcursor (core, R_FALSE); r_cons_set_raw (R_TRUE); break; case '!': r_cons_2048(); break; case 'o': visual_offset (core); break; case 'A': { int oc = curset; ut64 off = curset? core->offset+cursor : core->offset; curset = 0; r_core_visual_asm (core, off); curset = oc; } break; case 'c': setcursor (core, curset?0:1); break; case 'C': color = color? 0: 1; r_config_set_i (core->config, "scr.color", color); break; case 'd': r_core_visual_define (core); break; case 'D': setdiff (core); break; case 'f': { int range, min, max; char name[256], *n; r_line_set_prompt ("flag name: "); showcursor (core, R_TRUE); if (r_cons_fgets (name, sizeof (name), 0, NULL) >=0 && *name) { n = r_str_chop (name); if (*name=='-') { if (*n) r_flag_unset (core->flags, n+1, NULL); } else { if (ocursor != -1) { min = R_MIN (cursor, ocursor); max = R_MAX (cursor, ocursor); } else { min = max = cursor; } range = max-min+1; if (range<1) range = 1; if (*n) r_flag_set (core->flags, n, core->offset + min, range, 1); } } } showcursor (core, R_FALSE); break; case 'F': r_flag_unset_i (core->flags, core->offset + cursor, NULL); break; case 'n': r_core_seek_next (core, r_config_get (core->config, "scr.nkey")); break; case 'N': r_core_seek_previous (core, r_config_get (core->config, "scr.nkey")); break; case 'i': case 'I': if (core->file && !(core->file->rwx & 2)) { r_cons_printf ("\nFile has been opened in read-only mode. Use -w flag\n"); r_cons_any_key (); return R_TRUE; } showcursor (core, R_TRUE); r_cons_flush (); r_cons_set_raw (0); if (ch=='I') { strcpy (buf, "wow "); r_line_set_prompt ("insert hexpair block: "); if (r_cons_fgets (buf+4, sizeof (buf)-5, 0, NULL) <0) buf[0]='\0'; char *p = strdup (buf); int cur = core->print->cur; if (cur>=core->blocksize) cur = core->print->cur-1; snprintf (buf, sizeof (buf), "%s @ $$0!%i", p, core->blocksize-cursor); r_core_cmd (core, buf, 0); free (p); break; } delta = (ocursor!=-1)? R_MIN (cursor, ocursor): cursor; if (core->print->col==2) { strcpy (buf, "\"w "); r_line_set_prompt ("insert string: "); if (r_cons_fgets (buf+3, sizeof (buf)-4, 0, NULL) <0) buf[0]='\0'; strcat (buf, "\""); } else { r_line_set_prompt ("insert hex: "); if (ocursor != -1) { int bs = R_ABS (cursor-ocursor)+1; core->blocksize = bs; strcpy (buf, "wow "); } else { strcpy (buf, "wx "); } if (r_cons_fgets (buf+strlen (buf), sizeof (buf)-strlen (buf), 0, NULL) <0) buf[0]='\0'; } if (curset) r_core_seek (core, core->offset + delta, 0); r_core_cmd (core, buf, 1); if (curset) r_core_seek (core, offset, 1); r_cons_set_raw (1); showcursor (core, R_FALSE); break; case 'R': r_core_cmd0 (core, "ecr"); break; case 'e': r_core_visual_config (core); break; case 'E': r_core_visual_colors (core); break; case 'M': r_core_visual_mounts (core); break; case 't': r_core_visual_trackflags (core); break; case 'x': { int count = 0; RList *xrefs = NULL; RAnalRef *refi; RListIter *iter; RAnalFunction *fun; if ((xrefs = r_anal_xref_get (core->anal, core->offset))) { r_cons_gotoxy (1, 1); r_cons_printf ("[GOTO XREF]> \n"); if (r_list_empty (xrefs)) { r_cons_printf ("\tNo XREF found at 0x%"PFMT64x"\n", core->offset); r_cons_any_key (); r_cons_clear00 (); } else { r_list_foreach (xrefs, iter, refi) { fun = r_anal_fcn_find (core->anal, refi->addr, R_ANAL_FCN_TYPE_NULL); r_cons_printf (" [%i] 0x%08"PFMT64x" %s XREF 0x%08"PFMT64x" (%s) \n", count, refi->at, refi->type==R_ANAL_REF_TYPE_CODE?"CODE (JMP)": refi->type==R_ANAL_REF_TYPE_CALL?"CODE (CALL)":"DATA", refi->addr, fun?fun->name:"unk"); if (++count > 9) break; } } } else xrefs = NULL;
R_API int r_core_visual_cmd(RCore *core, int ch) { RAsmOp op; char buf[4096]; int i, ret, offscreen, cols = core->print->cols; ch = r_cons_arrow_to_hjkl (ch); ch = visual_nkey (core, ch); if (ch<2) return 1; // do we need hotkeys for data references? not only calls? if (ch>='0'&& ch<='9') { r_io_sundo_push (core->io, core->offset); r_core_seek (core, core->asmqjmps[ch-'0'], 1); r_core_block_read (core, 1); } else switch (ch) { case 9: // tab { // XXX: unify diff mode detection ut64 f = r_config_get_i (core->config, "diff.from"); ut64 t = r_config_get_i (core->config, "diff.to"); if (f == t && f == 0) { core->print->col = core->print->col==1? 2: 1; } else { ut64 delta = core->offset - f; r_core_seek (core, t+delta, 1); r_config_set_i (core->config, "diff.from", t); r_config_set_i (core->config, "diff.to", f); } } break; case 'c': // XXX dupped flag imho setcursor (core, curset ^ 1); break; case 'd': r_core_visual_define (core); break; case 'D': setdiff (core); break; case 'C': color ^= 1; if (color) flags |= R_PRINT_FLAGS_COLOR; else flags &= ~(flags&R_PRINT_FLAGS_COLOR); r_config_set_i (core->config, "scr.color", color); r_print_set_flags (core->print, flags); break; case 'f': { int range; char name[256], *n; r_line_set_prompt ("flag name: "); if (r_cons_fgets (name, sizeof (name), 0, NULL) >=0 && *name) { n = r_str_chop (name); if (*name=='-') { if (*n) r_flag_unset (core->flags, n+1, NULL); } else { range = curset? (R_ABS (cursor-ocursor)+1): 1; if (range<1) range = 1; if (*n) r_flag_set (core->flags, n, core->offset + cursor, range, 1); } } } break; case 'F': r_flag_unset_i (core->flags, core->offset + cursor, NULL); break; case 'n': r_core_seek_next (core, r_config_get (core->config, "scr.nkey")); break; case 'N': r_core_seek_previous (core, r_config_get (core->config, "scr.nkey")); break; case 'A': { int oc = curset; ut64 off = curset? core->offset+cursor : core->offset; curset = 0; r_core_visual_asm (core, off); curset = oc; } break; case 'a': if (core->file && !(core->file->rwx & 2)) { r_cons_printf ("\nFile has been opened in read-only mode. Use -w flag\n"); r_cons_any_key (); return R_TRUE; } r_cons_printf ("Enter assembler opcodes separated with ';':\n"); r_cons_show_cursor (R_TRUE); r_cons_flush (); r_cons_set_raw (R_FALSE); strcpy (buf, "wa "); r_line_set_prompt (":> "); if (r_cons_fgets (buf+3, 1000, 0, NULL) <0) buf[0]='\0'; if (*buf) { if (curset) r_core_seek (core, core->offset + cursor, 0); r_core_cmd (core, buf, R_TRUE); if (curset) r_core_seek (core, core->offset - cursor, 1); } r_cons_show_cursor (R_FALSE); r_cons_set_raw (R_TRUE); break; case 'i': case 'I': if (core->file && !(core->file->rwx & 2)) { r_cons_printf ("\nFile has been opened in read-only mode. Use -w flag\n"); r_cons_any_key (); return R_TRUE; } r_cons_show_cursor (R_TRUE); r_cons_flush (); r_cons_set_raw (0); if (ch=='I') { strcpy (buf, "wow "); r_line_set_prompt ("insert hexpair block: "); if (r_cons_fgets (buf+4, sizeof (buf)-3, 0, NULL) <0) buf[0]='\0'; char *p = strdup (buf); int cur = core->print->cur; if (cur>=core->blocksize) cur = core->print->cur-1; snprintf (buf, sizeof (buf), "%s @ $$0!%i", p, core->blocksize-cursor); r_core_cmd (core, buf, 0); free (p); break; } if (core->print->col==2) { strcpy (buf, "w "); r_line_set_prompt ("insert string: "); if (r_cons_fgets (buf+2, sizeof (buf)-3, 0, NULL) <0) buf[0]='\0'; } else { strcpy (buf, "wx "); r_line_set_prompt ("insert hex: "); if (r_cons_fgets (buf+3, sizeof (buf)-4, 0, NULL) <0) buf[0]='\0'; } if (curset) r_core_seek (core, core->offset + cursor, 0); r_core_cmd (core, buf, 1); if (curset) r_core_seek (core, core->offset - cursor, 1); r_cons_set_raw (1); r_cons_show_cursor (R_FALSE); break; case 'e': r_core_visual_config (core); break; case 'M': r_core_visual_mounts (core); break; case 't': r_core_visual_trackflags (core); break; case 'x': { int count = 0; RList *xrefs = NULL; RAnalRef *refi; RListIter *iter; RAnalFunction *fun; if ((xrefs = r_anal_xref_get (core->anal, core->offset))) { r_cons_printf ("XREFS:\n"); if (r_list_empty (xrefs)) { r_cons_printf ("\tNo XREF found at 0x%"PFMT64x"\n", core->offset); r_cons_any_key (); r_cons_clear00 (); } else { r_list_foreach (xrefs, iter, refi) { fun = r_anal_fcn_find (core->anal, refi->addr, R_ANAL_FCN_TYPE_NULL); r_cons_printf ("\t[%i] %s XREF 0x%08"PFMT64x" (%s)\n", count, refi->type==R_ANAL_REF_TYPE_CODE?"CODE (JMP)": refi->type==R_ANAL_REF_TYPE_CALL?"CODE (CALL)":"DATA", refi->addr, fun?fun->name:"unk"); if (++count > 9) break; } } } else xrefs = NULL;
R_API int r_core_visual_panels(RCore *core) { #define OS_INIT() ostack.size = 0; ostack.panels[0] = 0; #define OS_PUSH(x) if (ostack.size<LIMIT) {ostack.panels[++ostack.size]=x;} #define OS_POP() ((ostack.size>0)? ostack.panels[--ostack.size]:0) int okey, key, wheel; int w, h; int asm_comments = 0; int asm_bytes = 0; n_panels = 0; panels = NULL; callgraph = 0; _core = core; OS_INIT(); w = r_cons_get_size (&h); can = r_cons_canvas_new (w, h); can->linemode = 1; can->color = r_config_get_i (core->config, "scr.color"); // disable colors in disasm because canvas doesnt supports ansi text yet r_config_set_i (core->config, "scr.color", 0); //can->color = 0; if (!can) { eprintf ("Cannot create RCons.canvas context\n"); return R_FALSE; } n_panels = bbPanels (core, &panels); if (!panels) { r_config_set_i (core->config, "scr.color", can->color); free (can); return R_FALSE; } reloadPanels (core); asm_comments = r_config_get_i (core->config, "asm.comments"); r_config_set_i (core->config, "asm.comments", 0); asm_bytes = r_config_get_i (core->config, "asm.bytes"); r_config_set_i (core->config, "asm.bytes", 0); repeat: core->cons->event_data = core; core->cons->event_resize = \ (RConsEvent)r_core_panels_refresh; w = r_cons_get_size (&h); Layout_run (panels); r_core_panels_refresh (core); wheel = r_config_get_i (core->config, "scr.wheel"); if (wheel) r_cons_enable_mouse (R_TRUE); // r_core_graph_inputhandle() okey = r_cons_readchar (); key = r_cons_arrow_to_hjkl (okey); switch (key) { case ' ': case '\n': if (menu_y) { const char *action = menus_sub[menu_x][menu_y-1]; eprintf ("ACTION %s\n", action); if (strstr (action, "New")) { int i; // add new panel for testing for (i=0; panels[i].text; i++) { // find last panel } panels[i].text = strdup ("Test"); panels[i].cmd = r_str_newf ("pxW $r-2"); panels[i].addr = core->offset; panels[i].type = PANEL_TYPE_FRAME; i++; n_panels++; panels[i].text = NULL; } if (strstr (action, "Quit")) { goto beach; } } break; case '?': r_cons_clear00 (); r_cons_printf ("Visual Ascii Art Panels:\n" " ! run r2048 game\n" " . - center graph to the current node\n" " : - run r2 command in prompt\n" " hl - toggle scr.color\n" " HL - move vertical column split\n" " JK - select prev/next panels\n" " jk - scroll/select menu\n" " q - quit, back to visual mode\n" ); r_cons_flush (); r_cons_any_key (NULL); break; case ':': core->vmode = R_FALSE; r_core_visual_prompt_input (core); core->vmode = R_TRUE; break; case 'C': can->color = !!!can->color; //WTF //r_config_swap (core->config, "scr.color"); // refresh graph // reloadPanels (core); break; case '!': r_cons_2048 (); break; case 'j': if (panels[curnode].type == PANEL_TYPE_FLOAT) { if (menus_sub[menu_x][menu_y]) menu_y ++; } break; case 'k': if (panels[curnode].type == PANEL_TYPE_FLOAT) { menu_y --; if (menu_y<0) menu_y = 0; } break; case 'J': curnode++; if (!panels[curnode].text) { curnode--; } break; case 'K': curnode--; if (curnode<0) curnode = 0; break; case 'H': COLW += 4; break; case 'L': COLW -= 4; if (COLW<0) COLW=0; break; case 'h': if (menu_x) { menu_x --; menu_y = menu_y?1:0; } break; case 'l': if (menus[menu_x + 1]) { menu_x ++; menu_y = menu_y?1:0; } break; case 'q': case -1: // EOF goto beach; case 27: // ESC if (r_cons_readchar () == 91) { if (r_cons_readchar () == 90) { } } break; default: //eprintf ("Key %d\n", key); //sleep (1); break; } goto repeat; beach: free (panels); r_config_set_i (core->config, "scr.color", can->color); free (can); r_config_set_i (core->config, "asm.comments", asm_comments); r_config_set_i (core->config, "asm.bytes", asm_bytes); return R_TRUE; }
// damn singletons.. there should be only one screen and therefor // only one visual instance of the graph view. refactoring this // into a struct makes the code to reference pointers unnecesarily // we can look for a non-global solution here in the future if // necessary static void r_core_panels_refresh (RCore *core) { char title[128]; int i, j, h, w = r_cons_get_size (&h); if (instep && core->io->debug) { r_core_cmd0 (core, "sr pc"); } r_cons_clear00 (); if (!can) { return; } r_cons_canvas_resize (can, w, h); r_cons_canvas_clear (can); if (panels) { if (menu_y>0) { panels[menu_pos].x = menu_x * 6; } else { panels[menu_pos].x = w; } panels[menu_pos].y = 1; free (panels[menu_pos].text); panels[menu_pos].text = malloc(1024); //r_str_newf ("%d", menu_y); panels[menu_pos].text[0] = 0; int maxsub = 0; for (i=0; menus_sub[i]; i++) { maxsub = i; } if (menu_x >= 0 && menu_x <maxsub && menus_sub[menu_x]) { for (j = 0; menus_sub[menu_x][j]; j++) { if (menu_y-1 == j) { strcat (panels[menu_pos].text, "> "); } else { strcat (panels[menu_pos].text, " "); } strcat (panels[menu_pos].text, menus_sub[menu_x][j]); strcat (panels[menu_pos].text, " \n"); } } for (i=0; panels[i].text; i++) { if (i != curnode) { Panel_print (can, &panels[i], i==curnode); } } } if (menu_y) { curnode = menu_pos; } // redraw current node to make it appear on top if (curnode >= 0) { Panel_print (can, &panels[curnode], 1); } Panel_print (can, &panels[menu_pos], menu_y); (void)G (-can->sx, -can->sy); char str[128]; title[0] = 0; for (i=0; menus[i]; i++) { if (menu_x == i) { snprintf (str, sizeof (title)-1, "[%s]", menus[i]); } else { snprintf (str, sizeof (title)-1, " %s ", menus[i]); } strcat (title, str); } W (title); snprintf (title, sizeof (title)-1, "[0x%08"PFMT64x"]", core->offset); (void)G (-can->sx + w-strlen (title), -can->sy); W (title); r_cons_canvas_print (can); r_cons_flush_nonewline (); }