get [1][2] jumps for panels and fixed some unstable behaviors (#10836)

* fixed unstable behaviours and [1][2][3]jump now works.
* added the help messages
* restyling for the help message
This commit is contained in:
Vanellope 2018-07-29 13:56:15 +09:00 committed by Anton Kochkov
parent f3b33640d1
commit 5e56c90483
3 changed files with 131 additions and 82 deletions

View File

@ -165,7 +165,8 @@ static void panelSingleStepOver(RCore *core);
static void setRefreshAll(RPanels *panels);
static void setCursor(RCore *core, bool cur);
static void replaceCmd(RPanels* panels, char *title, char *cmd);
static bool handleMenu(RCore *core, const char *menu);
static void handleMenu(RCore *core, const int key, int *exit);
static void onMenu(RCore *core, const char *menu, int *exit);
static void changeMenu(RPanels *panels, const char **dstMenu);
static RConsCanvas *createNewCanvas(RCore *core, int w, int h);
@ -585,7 +586,8 @@ static void handleDownKey(RCore *core) {
r_cons_switchbuf (false);
if (panels->curnode == panels->menu_pos) {
if (!panels->menuStackDepth) {
handleMenu (core, panels->currentMenu[panels->currentMenuIndex]);
int exit = 0;
onMenu (core, panels->currentMenu[panels->currentMenuIndex], &exit);
} else {
if (panels->currentMenu[panels->currentMenuIndex + 1]) {
panels->currentMenuIndex++;
@ -1219,7 +1221,46 @@ R_API int file_history_down(RLine *line) {
return true;
}
static bool handleMenu(RCore *core, const char *menu) {
static void handleMenu(RCore *core, const int key, int *exit) {
RPanels *panels = core->panels;
switch (key) {
case 'h':
handleLeftKey (core);
break;
case 'j':
handleDownKey (core);
break;
case 'k':
handleUpKey (core);
break;
case 'l':
handleRightKey (core);
break;
case 'q':
case -1:
if (panels->menuStackDepth == 0) {
*exit = 1;
return;
}
panels->menuStackDepth--;
panels->currentMenu = panels->menuStack[panels->menuStackDepth];
panels->currentMenuIndex = panels->menuIndexStack[panels->menuStackDepth];
setRefreshAll (core->panels);
break;
case ' ':
case '\r':
case '\n':
onMenu (core, panels->currentMenu[panels->currentMenuIndex], exit);
break;
case 9:
handleTabKey (core, false);
break;
case 'Z':
handleTabKey (core, true);
}
}
static void onMenu(RCore *core, const char *menu, int *exit) {
RPanels *panels = core->panels;
if (!strcmp (menu, "File")) {
changeMenu (panels, menus_File);
@ -1455,10 +1496,10 @@ static bool handleMenu(RCore *core, const char *menu) {
} else if (!strcmp (menu, "Colors")) {
r_core_cmd0 (core, "e!scr.color");
} else if (!strcmp (menu, "Quit")) {
return false;
*exit = 1;
return;
}
doPanelsRefresh (core);
return true;
}
static void changeMenu(RPanels *panels, const char **dstMenu) {
@ -1546,6 +1587,8 @@ R_API int r_core_visual_panels(RCore *core, RPanels *panels) {
core->print->cur = 0;
core->print->cur_enabled = false;
core->print->col = 0;
bool originVmode = core->vmode;
core->vmode = true;
r_core_panels_layout (panels);
repeat:
@ -1562,10 +1605,28 @@ repeat:
key = r_cons_arrow_to_hjkl (okey);
r_cons_switchbuf (true);
if (panels->curnode == panels->menu_pos) {
int exit = 0;
handleMenu (core, key, &exit);
if (exit) {
goto exit;
}
goto repeat;
}
if (handleCursorMode (core, key)) {
goto repeat;
}
if (!strcmp (panels->panel[panels->curnode].cmd, PANEL_CMD_DISASSEMBLY)
&& '0' < key && key <= '9') {
ut8 ch = key;
r_core_visual_jump (core, ch);
panels->panel[panels->curnode].addr = core->offset;
panels->panel[panels->curnode].refresh = true;
goto repeat;
}
const char *cmd;
RConsCanvas *can = panels->can;
switch (key) {
@ -1609,7 +1670,7 @@ repeat:
r_core_cmd0 (core, "sn");
break;
case '.':
if (panels->curnode != panels->menu_pos && !strcmp (panels->panel[panels->curnode].cmd, PANEL_CMD_DISASSEMBLY)) {
if (!strcmp (panels->panel[panels->curnode].cmd, PANEL_CMD_DISASSEMBLY)) {
if (r_config_get_i (core->config, "cfg.debug")) {
r_core_cmd0 (core, "sr PC");
} else {
@ -1619,48 +1680,41 @@ repeat:
panels->panel[panels->curnode].refresh = true;
}
break;
case ' ':
case '\r':
case '\n':
if (panels->curnode == panels->menu_pos && !handleMenu (core, panels->currentMenu[panels->currentMenuIndex])) {
goto exit;
}
break;
case '?':
r_cons_clear00 ();
r_cons_printf ("Visual Ascii Art Panels:\n"
" ! - run r2048 game\n"
" . - seek to PC or entrypoint\n"
" : - run r2 command in prompt\n"
" _ - start the hud input mode\n"
" | - split the current panel vertically\n"
" - - split the current panel horizontally\n"
" w - change the current layout of the panels\n"
" ? - show this help\n"
" X - close current panel\n"
" m - move to the menu\n"
" V - go to the graph mode\n"
" b - browse symbols, flags, configurations, classes, ...\n"
" c - toggle cursor\n"
" C - toggle color\n"
" d - define in the current address. Same as Vd\n"
" e - change title and command of current panel\n"
" D - show disassembly in the current panel\n"
" g - show graph in the current panel\n"
" * - show pseudo code/r2dec in the current panel\n"
" i - insert hex\n"
" M - open new custom frame\n"
" hl - scroll panels horizontally\n"
" HL - resize panels horizontally\n"
" jk - scroll panels vertically\n"
" JK - scroll panels vertically by page\n"
" sS - step in / step over\n"
" uU - undo / redo seek\n"
" pP - seek to next or previous scr.nkey\n"
" o - go/seek to given offset\n"
" nN - create new panel with given command\n"
" q - quit, back to visual mode\n"
" 0-9 - jump to the nth panel. n is the number you hit\n"
" ? - show this help\n"
" ! - run r2048 game\n"
" . - seek to PC or entrypoint\n"
" : - run r2 command in prompt\n"
" _ - start the hud input mode\n"
" | - split the current panel vertically\n"
" - - split the current panel horizontally\n"
" * - show pseudo code/r2dec in the current panel\n"
" [1-9] - follow jmp/call identified by shortcut (like ;[1])\n"
" b - browse symbols, flags, configurations, classes, ...\n"
" c - toggle cursor\n"
" C - toggle color\n"
" d - define in the current address. Same as Vd\n"
" D - show disassembly in the current panel\n"
" e - change title and command of current panel\n"
" g - show graph in the current panel\n"
" hjkl - move around (left-down-up-right)\n"
" HL - resize panels horizontally\n"
" JK - scroll panels vertically by page\n"
" i - insert hex\n"
" m - move to the menu\n"
" M - open new custom frame\n"
" nN - create new panel with given command\n"
" r - toggle jmphints/leahints\n"
" o - go/seek to given offset\n"
" pP - seek to next or previous scr.nkey\n"
" q - quit, back to visual mode\n"
" sS - step in / step over\n"
" uU - undo / redo seek\n"
" V - go to the graph mode\n"
" w - change the current layout of the panels\n"
" X - close current panel\n"
);
r_cons_flush ();
r_cons_any_key (NULL);
@ -1669,7 +1723,7 @@ repeat:
r_core_visual_browse (core);
break;
case 'o':
if (panels->curnode != panels->menu_pos && !strcmp (panels->panel[panels->curnode].cmd, PANEL_CMD_DISASSEMBLY)) {
if (!strcmp (panels->panel[panels->curnode].cmd, PANEL_CMD_DISASSEMBLY)) {
r_core_visual_showcursor (core, true);
r_core_visual_offset (core);
r_core_visual_showcursor (core, false);
@ -1696,7 +1750,7 @@ repeat:
setRefreshAll (panels);
break;
case 'c':
if (panels->curnode != panels->menu_pos && (!strcmp (panels->panel[panels->curnode].cmd, PANEL_CMD_STACK)
if ((!strcmp (panels->panel[panels->curnode].cmd, PANEL_CMD_STACK)
|| !strcmp (panels->panel[panels->curnode].cmd, PANEL_CMD_REGISTERS))) {
setCursor (core, !core->print->cur_enabled);
panels->panel[panels->curnode].refresh = true;
@ -1708,6 +1762,11 @@ repeat:
// refresh graph
setRefreshAll (panels);
break;
case 'r':
r_core_cmd0 (core, "e!asm.jmphints");
r_core_cmd0 (core, "e!asm.leahints");
setRefreshAll (panels);
break;
case 'R':
if (r_config_get_i (core->config, "scr.randpal")) {
r_core_cmd0 (core, "ecr");
@ -1746,10 +1805,8 @@ repeat:
r_core_visual_hud (core);
break;
case 'X':
if (panels->curnode != panels->menu_pos) {
delCurPanel (panels);
setRefreshAll (panels);
}
delCurPanel (panels);
setRefreshAll (panels);
break;
case 9: // TAB
handleTabKey (core, false);
@ -1941,14 +1998,7 @@ repeat:
break;
case 'q':
case -1: // EOF
if (panels->menuStackDepth == 0) {
goto exit;
}
panels->menuStackDepth--;
panels->currentMenu = panels->menuStack[panels->menuStackDepth];
panels->currentMenuIndex = panels->menuIndexStack[panels->menuStackDepth];
setRefreshAll (core->panels);
break;
goto exit;
#if 0
case 27: // ESC
if (r_cons_readchar () == 91) {
@ -1961,12 +2011,6 @@ repeat:
// sleep (1);
break;
}
const int keyNum = key - 48;
if (0 <= keyNum && keyNum < panels->n_panels) {
panels->panel[panels->curnode].refresh = true;
panels->panel[keyNum].refresh = true;
panels->curnode = keyNum;
}
goto repeat;
exit:
core->cons->event_resize = NULL;
@ -1974,6 +2018,7 @@ exit:
core->print->cur = originCursor;
core->print->cur_enabled = false;
core->print->col = 0;
core->vmode = originVmode;
r_core_panels_free (panels);
core->panels = NULL;

View File

@ -304,6 +304,25 @@ R_API int r_core_visual_hud(RCore *core) {
return (int) (size_t) p;
}
R_API void r_core_visual_jump(RCore *core, ut8 ch) {
char chbuf[2];
ut64 off;
chbuf[0] = ch;
chbuf[1] = '\0';
off = r_core_get_asmqjmps (core, chbuf);
if (off != UT64_MAX) {
int delta = R_ABS ((st64) off - (st64) core->offset);
r_io_sundo_push (core->io, core->offset, r_print_get_cursor (core->print));
if (core->print->cur_enabled && delta < 100) {
core->print->cur = delta;
} else {
r_core_visual_seek_animation (core, off);
core->print->cur = 0;
}
r_core_block_read (core);
}
}
static void append_help(RStrBuf *p, const char *title, const char **help) {
int i, max_length = 0, padding = 0;
RCons *cons = r_cons_singleton ();
@ -1734,23 +1753,7 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) {
// do we need hotkeys for data references? not only calls?
// '0' is handled to seek at the beginning of the function
if (ch > '0' && ch <= '9') {
char chbuf[2];
ut64 off;
chbuf[0] = ch;
chbuf[1] = '\0';
off = r_core_get_asmqjmps (core, chbuf);
if (off != UT64_MAX) {
int delta = R_ABS ((st64) off - (st64) offset);
r_io_sundo_push (core->io, offset, r_print_get_cursor (core->print));
if (core->print->cur_enabled && delta < 100) {
core->print->cur = delta;
} else {
r_core_visual_seek_animation (core, off);
core->print->cur = 0;
}
r_core_block_read (core);
}
r_core_visual_jump (core, ch);
} else {
switch (ch) {
#if __WINDOWS__ && !__CYGWIN__

View File

@ -346,6 +346,7 @@ R_API int r_core_visual_xrefs_X(RCore *core);
R_API void r_core_visual_showcursor(RCore *core, int x);
R_API void r_core_visual_offset(RCore *core);
R_API int r_core_visual_hud(RCore *core);
R_API void r_core_visual_jump(RCore *core, ut8 ch);
R_API ut64 r_core_get_asmqjmps(RCore *core, const char *str);
R_API void r_core_set_asmqjmps(RCore *core, char *str, size_t len, int i);
R_API char* r_core_add_asmqjmp(RCore *core, ut64 addr);