mirror of
https://github.com/radareorg/radare2.git
synced 2025-03-01 18:57:20 +00:00
Fix tons of bugs of cursor for disassembly in panels
This commit is contained in:
parent
f7d61f3c1f
commit
30389573c1
@ -258,7 +258,8 @@ static void cursorLeft(RCore *core);
|
|||||||
static void cursorRight(RCore *core);
|
static void cursorRight(RCore *core);
|
||||||
static void cursorDown(RCore *core);
|
static void cursorDown(RCore *core);
|
||||||
static void cursorUp(RCore *core);
|
static void cursorUp(RCore *core);
|
||||||
static int cursorThreshold(RPanel* panel);
|
static void fix_cursor_up(RCore *core);
|
||||||
|
static void fix_cursor_down(RCore *core);
|
||||||
static void delPanel(RPanels *ps, int pi);
|
static void delPanel(RPanels *ps, int pi);
|
||||||
static void dismantleDelPanel(RPanels *ps, RPanel *p, int pi);
|
static void dismantleDelPanel(RPanels *ps, RPanel *p, int pi);
|
||||||
static void delInvalidPanels(RPanels *panels);
|
static void delInvalidPanels(RPanels *panels);
|
||||||
@ -532,13 +533,18 @@ static void defaultPanelPrint(RCore *core, RConsCanvas *can, RPanel *panel, int
|
|||||||
} else {
|
} else {
|
||||||
if (panel->model->cmd) {
|
if (panel->model->cmd) {
|
||||||
if (check_panel_type(panel, PANEL_CMD_DISASSEMBLY, strlen (PANEL_CMD_DISASSEMBLY))) {
|
if (check_panel_type(panel, PANEL_CMD_DISASSEMBLY, strlen (PANEL_CMD_DISASSEMBLY))) {
|
||||||
|
core->print->screen_bounds = 1LL;
|
||||||
if (!findCmdStrCache (core, panel, &cmdStr)) {
|
if (!findCmdStrCache (core, panel, &cmdStr)) {
|
||||||
|
char *ocmd = panel->model->cmd;
|
||||||
|
panel->model->cmd = r_str_newf ("%s %d", panel->model->cmd, panel->view->pos.h - 3);
|
||||||
ut64 o_offset = core->offset;
|
ut64 o_offset = core->offset;
|
||||||
core->offset = panel->model->addr;
|
core->offset = panel->model->addr;
|
||||||
r_core_seek (core, panel->model->addr, 1);
|
r_core_seek (core, panel->model->addr, 1);
|
||||||
r_core_block_read (core);
|
r_core_block_read (core);
|
||||||
cmdStr = handleCmdStrCache (core, panel);
|
cmdStr = handleCmdStrCache (core, panel);
|
||||||
core->offset = o_offset;
|
core->offset = o_offset;
|
||||||
|
free (panel->model->cmd);
|
||||||
|
panel->model->cmd = ocmd;
|
||||||
}
|
}
|
||||||
} else if (check_panel_type (panel, PANEL_CMD_STACK, strlen (PANEL_CMD_STACK))) {
|
} else if (check_panel_type (panel, PANEL_CMD_STACK, strlen (PANEL_CMD_STACK))) {
|
||||||
const int delta = r_config_get_i (core->config, "stack.delta");
|
const int delta = r_config_get_i (core->config, "stack.delta");
|
||||||
@ -867,37 +873,6 @@ static void setCursor(RCore *core, bool cur) {
|
|||||||
print->col = print->cur_enabled ? 1: 0;
|
print->col = print->cur_enabled ? 1: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cursorRight(RCore *core) {
|
|
||||||
RPanel *cur = getCurPanel (core->panels);
|
|
||||||
RPrint *print = core->print;
|
|
||||||
if (check_panel_type (cur, PANEL_CMD_STACK, strlen (PANEL_CMD_STACK)) && print->cur >= 15) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (check_panel_type (cur, PANEL_CMD_REGISTERS, strlen (PANEL_CMD_REGISTERS))
|
|
||||||
|| check_panel_type (cur, PANEL_CMD_STACK, strlen (PANEL_CMD_STACK))) {
|
|
||||||
print->cur++;
|
|
||||||
cur->model->addr++;
|
|
||||||
} else {
|
|
||||||
print->cur++;
|
|
||||||
int threshold = cursorThreshold (cur);
|
|
||||||
int row = r_print_row_at_off (print, print->cur);
|
|
||||||
if (row >= threshold) {
|
|
||||||
core->offset = cur->model->addr;
|
|
||||||
RAsmOp op;
|
|
||||||
ut32 next_roff = r_print_rowoff (print, row + 1);
|
|
||||||
int sz = r_asm_disassemble (core->assembler, &op,
|
|
||||||
core->block + next_roff, 32);
|
|
||||||
if (sz < 1) {
|
|
||||||
sz = 1;
|
|
||||||
}
|
|
||||||
r_core_seek_delta (core, sz);
|
|
||||||
cur->model->addr = core->offset;
|
|
||||||
r_core_block_read (core);
|
|
||||||
print->cur = R_MAX (print->cur - sz, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void activateCursor(RCore *core) {
|
static void activateCursor(RCore *core) {
|
||||||
RPanels *panels = core->panels;
|
RPanels *panels = core->panels;
|
||||||
RPanel *cur = getCurPanel (panels);
|
RPanel *cur = getCurPanel (panels);
|
||||||
@ -936,102 +911,89 @@ static void cursorLeft(RCore *core) {
|
|||||||
}
|
}
|
||||||
} else if (check_panel_type (cur, PANEL_CMD_DISASSEMBLY, strlen (PANEL_CMD_DISASSEMBLY))) {
|
} else if (check_panel_type (cur, PANEL_CMD_DISASSEMBLY, strlen (PANEL_CMD_DISASSEMBLY))) {
|
||||||
print->cur--;
|
print->cur--;
|
||||||
int row = r_print_row_at_off (print, print->cur);
|
fix_cursor_up (core);
|
||||||
if (row < 0) {
|
|
||||||
int cols = print->cols;
|
|
||||||
ut64 prevoff = core->offset;
|
|
||||||
core->offset = cur->model->addr;
|
|
||||||
r_core_visual_disasm_up (core, &cols);
|
|
||||||
r_core_seek_delta (core, -cols);
|
|
||||||
cur->model->addr = core->offset;
|
|
||||||
print->cur = prevoff - core->offset - 1;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
print->cur--;
|
print->cur--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void cursorRight(RCore *core) {
|
||||||
|
RPanel *cur = getCurPanel (core->panels);
|
||||||
|
RPrint *print = core->print;
|
||||||
|
if (check_panel_type (cur, PANEL_CMD_STACK, strlen (PANEL_CMD_STACK)) && print->cur >= 15) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (check_panel_type (cur, PANEL_CMD_REGISTERS, strlen (PANEL_CMD_REGISTERS))
|
||||||
|
|| check_panel_type (cur, PANEL_CMD_STACK, strlen (PANEL_CMD_STACK))) {
|
||||||
|
print->cur++;
|
||||||
|
cur->model->addr++;
|
||||||
|
} else {
|
||||||
|
print->cur++;
|
||||||
|
fix_cursor_down (core);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void cursorUp(RCore *core) {
|
static void cursorUp(RCore *core) {
|
||||||
RPrint *print = core->print;
|
RPrint *print = core->print;
|
||||||
ut32 roff;
|
ut64 addr, oaddr = core->offset + print->cur;
|
||||||
int row;
|
if (r_core_prevop_addr (core, oaddr, 1, &addr)) {
|
||||||
if (print->row_offsets) {
|
const int delta = oaddr - addr;
|
||||||
row = r_print_row_at_off (print, print->cur);
|
print->cur -= delta;
|
||||||
roff = r_print_rowoff (print, row);
|
|
||||||
if (roff == UT32_MAX) {
|
|
||||||
print->cur--;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (row > 0) {
|
|
||||||
ut32 prev_roff;
|
|
||||||
int delta, prev_sz;
|
|
||||||
prev_roff = r_print_rowoff (print, row - 1);
|
|
||||||
delta = print->cur - roff;
|
|
||||||
prev_sz = roff - prev_roff;
|
|
||||||
int res = R_MIN (delta, prev_sz - 1);
|
|
||||||
ut64 cur = prev_roff + res;
|
|
||||||
if (cur == print->cur) {
|
|
||||||
if (print->cur > 0) {
|
|
||||||
print->cur--;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
print->cur = prev_roff + delta;
|
print->cur -= 4;
|
||||||
}
|
|
||||||
} else {
|
|
||||||
RPanel *cur = getCurPanel (core->panels);
|
|
||||||
int cols = print->cols;
|
|
||||||
ut64 prevoff = core->offset;
|
|
||||||
r_core_visual_disasm_up (core, &cols);
|
|
||||||
r_core_seek_delta (core, -cols);
|
|
||||||
cur->model->addr = core->offset;
|
|
||||||
print->cur = R_MIN (prevoff - core->offset - 1, print->cur);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
print->cur -= print->cols;
|
|
||||||
}
|
}
|
||||||
|
fix_cursor_up (core);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cursorDown(RCore *core) {
|
static void cursorDown(RCore *core) {
|
||||||
RPanel *cur = getCurPanel (core->panels);
|
|
||||||
RPrint *print = core->print;
|
RPrint *print = core->print;
|
||||||
ut32 roff, next_roff;
|
RAnalOp *aop = r_core_anal_op (core, core->offset + print->cur, R_ANAL_OP_MASK_BASIC);
|
||||||
int row, sz, delta, threshold = cursorThreshold (cur);
|
if (aop) {
|
||||||
RAsmOp op;
|
print->cur += aop->size;
|
||||||
if (print->row_offsets) {
|
r_anal_op_free (aop);
|
||||||
row = r_print_row_at_off (print, print->cur);
|
} else {
|
||||||
roff = r_print_rowoff (print, row);
|
print->cur += 4;
|
||||||
if (roff == -1) {
|
}
|
||||||
print->cur++;
|
fix_cursor_down (core);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void fix_cursor_up(RCore *core) {
|
||||||
|
RPrint *print = core->print;
|
||||||
|
if (print->cur >= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
next_roff = r_print_rowoff (print, row + 1);
|
int sz = r_core_visual_prevopsz (core, core->offset + print->cur);
|
||||||
if (next_roff == -1) {
|
|
||||||
print->cur++;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
sz = r_asm_disassemble (core->assembler, &op,
|
|
||||||
core->block + next_roff, 32);
|
|
||||||
if (sz < 1) {
|
if (sz < 1) {
|
||||||
sz = 1;
|
sz = 1;
|
||||||
}
|
}
|
||||||
delta = print->cur - roff;
|
r_core_seek_delta (core, -sz);
|
||||||
print->cur = next_roff + R_MIN (delta, sz - 1);
|
print->cur += sz;
|
||||||
row = r_print_row_at_off (print, print->cur);
|
if (print->ocur != -1) {
|
||||||
if (row >= threshold) {
|
print->ocur += sz;
|
||||||
r_core_seek_delta (core, sz);
|
|
||||||
print->cur = R_MAX (print->cur - sz, 0);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
print->cur += R_MAX (1, print->cols);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cursorThreshold(RPanel* panel) {
|
static void fix_cursor_down(RCore *core) {
|
||||||
int threshold = (panel->view->pos.h - 4) / 2;
|
RPrint *print = core->print;
|
||||||
if (threshold < 10) {
|
bool cur_is_visible = core->offset + print->cur + 32 < print->screen_bounds;
|
||||||
threshold = 1;
|
if (!cur_is_visible) {
|
||||||
|
int i = 0;
|
||||||
|
//XXX: ugly hack
|
||||||
|
for (i = 0; i < 2; i++) {
|
||||||
|
RAsmOp op;
|
||||||
|
int sz = r_asm_disassemble (core->assembler,
|
||||||
|
&op, core->block, 32);
|
||||||
|
if (sz < 1) {
|
||||||
|
sz = 1;
|
||||||
|
}
|
||||||
|
r_core_seek_delta (core, sz);
|
||||||
|
print->cur = R_MAX (print->cur - sz, 0);
|
||||||
|
if (print->ocur != -1) {
|
||||||
|
print->ocur = R_MAX (print->ocur - sz, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return threshold;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool handleZoomMode(RCore *core, const int key) {
|
static bool handleZoomMode(RCore *core, const int key) {
|
||||||
@ -2456,6 +2418,8 @@ static void directionDisassemblyCb(void *user, int direction) {
|
|||||||
case LEFT:
|
case LEFT:
|
||||||
if (core->print->cur_enabled) {
|
if (core->print->cur_enabled) {
|
||||||
cursorLeft (core);
|
cursorLeft (core);
|
||||||
|
r_core_block_read (core);
|
||||||
|
cur->model->addr = core->offset;
|
||||||
} else if (cur->view->sx > 0) {
|
} else if (cur->view->sx > 0) {
|
||||||
cur->view->sx--;
|
cur->view->sx--;
|
||||||
cur->view->refresh = true;
|
cur->view->refresh = true;
|
||||||
@ -2464,6 +2428,8 @@ static void directionDisassemblyCb(void *user, int direction) {
|
|||||||
case RIGHT:
|
case RIGHT:
|
||||||
if (core->print->cur_enabled) {
|
if (core->print->cur_enabled) {
|
||||||
cursorRight (core);
|
cursorRight (core);
|
||||||
|
r_core_block_read (core);
|
||||||
|
cur->model->addr = core->offset;
|
||||||
} else {
|
} else {
|
||||||
cur->view->sx++;
|
cur->view->sx++;
|
||||||
cur->view->refresh = true;
|
cur->view->refresh = true;
|
||||||
@ -2473,6 +2439,7 @@ static void directionDisassemblyCb(void *user, int direction) {
|
|||||||
core->offset = cur->model->addr;
|
core->offset = cur->model->addr;
|
||||||
if (core->print->cur_enabled) {
|
if (core->print->cur_enabled) {
|
||||||
cursorUp (core);
|
cursorUp (core);
|
||||||
|
r_core_block_read (core);
|
||||||
cur->model->addr = core->offset;
|
cur->model->addr = core->offset;
|
||||||
} else {
|
} else {
|
||||||
r_core_visual_disasm_up (core, &cols);
|
r_core_visual_disasm_up (core, &cols);
|
||||||
@ -3335,7 +3302,7 @@ static void initSdb(RPanels *panels) {
|
|||||||
sdb_set (panels->db, "Stack" , "px 256@r:SP", 0);
|
sdb_set (panels->db, "Stack" , "px 256@r:SP", 0);
|
||||||
sdb_set (panels->db, "Locals", "afvd", 0);
|
sdb_set (panels->db, "Locals", "afvd", 0);
|
||||||
sdb_set (panels->db, "Registers", "dr", 0);
|
sdb_set (panels->db, "Registers", "dr", 0);
|
||||||
sdb_set (panels->db, "Disassembly", "pd $r", 0);
|
sdb_set (panels->db, "Disassembly", "pd", 0);
|
||||||
sdb_set (panels->db, "Decompiler", "pdc", 0);
|
sdb_set (panels->db, "Decompiler", "pdc", 0);
|
||||||
sdb_set (panels->db, "Graph", "agf", 0);
|
sdb_set (panels->db, "Graph", "agf", 0);
|
||||||
sdb_set (panels->db, "Info", "i", 0);
|
sdb_set (panels->db, "Info", "i", 0);
|
||||||
|
@ -1255,7 +1255,7 @@ R_API void r_core_visual_offset(RCore *core) {
|
|||||||
core->cons->line->prompt_type = R_LINE_PROMPT_DEFAULT;
|
core->cons->line->prompt_type = R_LINE_PROMPT_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int prevopsz(RCore *core, ut64 addr) {
|
R_API int r_core_visual_prevopsz(RCore *core, ut64 addr) {
|
||||||
ut64 prev_addr = prevop_addr (core, addr);
|
ut64 prev_addr = prevop_addr (core, addr);
|
||||||
return addr - prev_addr;
|
return addr - prev_addr;
|
||||||
}
|
}
|
||||||
@ -1878,7 +1878,7 @@ static bool fix_cursor(RCore *core) {
|
|||||||
if (p->cur < 0) {
|
if (p->cur < 0) {
|
||||||
int sz = p->cols;
|
int sz = p->cols;
|
||||||
if (isDisasmPrint (core->printidx)) {
|
if (isDisasmPrint (core->printidx)) {
|
||||||
sz = prevopsz (core, core->offset + p->cur);
|
sz = r_core_visual_prevopsz (core, core->offset + p->cur);
|
||||||
if (sz < 1) {
|
if (sz < 1) {
|
||||||
sz = 1;
|
sz = 1;
|
||||||
}
|
}
|
||||||
@ -4020,7 +4020,7 @@ R_API void r_core_visual_disasm_up(RCore *core, int *cols) {
|
|||||||
*cols = 4;
|
*cols = 4;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
*cols = prevopsz (core, core->offset);
|
*cols = r_core_visual_prevopsz (core, core->offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -716,6 +716,7 @@ R_API int r_core_rtr_http(RCore *core, int launch, int browse, const char *path)
|
|||||||
R_API int r_core_rtr_http_stop(RCore *u);
|
R_API int r_core_rtr_http_stop(RCore *u);
|
||||||
R_API int r_core_rtr_gdb(RCore *core, int launch, const char *path);
|
R_API int r_core_rtr_gdb(RCore *core, int launch, const char *path);
|
||||||
|
|
||||||
|
R_API int r_core_visual_prevopsz(RCore *core, ut64 addr);
|
||||||
R_API void r_core_visual_config(RCore *core);
|
R_API void r_core_visual_config(RCore *core);
|
||||||
R_API void r_core_visual_mounts(RCore *core);
|
R_API void r_core_visual_mounts(RCore *core);
|
||||||
R_API void r_core_visual_anal(RCore *core, const char *input);
|
R_API void r_core_visual_anal(RCore *core, const char *input);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user