Skip to content

Commit

Permalink
Implement soft scrolling over varlisting in visual disasm ##visual
Browse files Browse the repository at this point in the history
  • Loading branch information
radare authored and trufae committed Jun 19, 2024
1 parent 60c00d7 commit e99f3e6
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 7 deletions.
12 changes: 12 additions & 0 deletions libr/core/disasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ typedef struct r_disasm_state_t {
// ugly ones but at least not globals
ut64 emustack_min;
ut64 emustack_max;
int skiplines; // for smooth scrolling in visual disasm
} RDisasmState;

static void ds_setup_print_pre(RDisasmState *ds, bool tail, bool middle);
Expand Down Expand Up @@ -2101,10 +2102,21 @@ static void ds_show_functions(RDisasmState *ds) {
char spaces[32];
RAnalVar *var;
RListIter *iter;

int skipped = 0;
#if R2_USE_NEW_ABI
if (f->addr == core->offset) {
skipped = core->skiplines;
}
#endif
RList *all_vars = vars_cache.rvars;
r_list_join (all_vars, vars_cache.bvars);
r_list_join (all_vars, vars_cache.svars);
r_list_foreach (all_vars, iter, var) {
if (skipped > 0) {
skipped--;
continue;
}
ds_begin_line (ds);
int idx;
RAnal *anal = ds->core->anal;
Expand Down
72 changes: 65 additions & 7 deletions libr/core/visual.c
Original file line number Diff line number Diff line change
Expand Up @@ -2191,7 +2191,9 @@ static void cursor_prevrow(RCore *core, bool use_ocur) {
} else {
RAnalOp op;
prev_roff = 0;
r_asm_op_init (&op);
r_core_seek (core, prev_addr, true);
r_asm_set_pc (core->rasm, prev_addr);
prev_sz = r_asm_disassemble (core->rasm, &op,
core->block, 32);
r_asm_op_fini (&op);
Expand All @@ -2206,7 +2208,7 @@ static void cursor_prevrow(RCore *core, bool use_ocur) {
p->cur--;
}
} else {
p->cur = prev_roff + delta; //res;
p->cur = prev_roff + delta; // res;
}
} else {
p->cur -= p->cols;
Expand Down Expand Up @@ -3551,7 +3553,9 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) {
} else if (!strcmp (__core_visual_print_command (core), "prc")) {
cols = r_config_get_i (core->config, "hex.cols");
}
r_core_seek_delta (core, -cols);
if (cols != 0) {
r_core_seek_delta (core, -cols);
}
}
}
}
Expand Down Expand Up @@ -4618,29 +4622,69 @@ static void visual_refresh_oneshot(RCore *core) {
r_core_task_enqueue_oneshot (&core->tasks, (RCoreTaskOneShot) visual_refresh, core);
}

#if R2_USE_NEW_ABI
static int varcount(RCore *core, RAnalFunction *f) {
RAnalFcnVarsCache vars_cache;
if (!f) {
f = r_anal_get_function_at (core->anal, core->offset);
if (!f) {
return 0;
}
}
r_anal_function_vars_cache_init (core->anal, &vars_cache, f);
int len = r_list_length (vars_cache.rvars);
len += r_list_length (vars_cache.bvars);
len += r_list_length (vars_cache.svars);
return len;
}
#endif

R_API void r_core_visual_disasm_up(RCore *core, int *cols) {
RAnalFunction *f = r_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL);
if (f && f->folded) {
*cols = core->offset - f->addr; // + f->size;
*cols = core->offset - f->addr;
if (*cols < 1) {
*cols = 4;
}
} else {
#if R2_USE_NEW_ABI
if (f && core->offset == f->addr) {
if (core->skiplines > 0) {
core->skiplines--;
*cols = 0;
} else {
int delta = r_core_visual_prevopsz (core, core->offset);
*cols = delta;
}
return;
}
int delta = r_core_visual_prevopsz (core, core->offset);
if (f && core->offset - delta == f->addr) {
core->skiplines = varcount (core, f);
*cols = delta;
if (core->skiplines > 0) {
core->skiplines--;
}
} else {
*cols = delta;
// *cols = 0;
}
#else
*cols = r_core_visual_prevopsz (core, core->offset);
#endif
}
}

R_API void r_core_visual_disasm_down(RCore *core, RAnalOp *op, int *cols) {
int midflags = r_config_get_i (core->config, "asm.flags.middle");
const bool midbb = r_config_get_i (core->config, "asm.bbmiddle");
RAnalFunction *f = NULL;
f = r_anal_get_fcn_in (core->anal, core->offset, 0);
RAnalFunction *f = r_anal_get_fcn_in (core->anal, core->offset, 0);
ut64 orig = core->offset;
op->size = 1;
if (f && f->folded) {
*cols = core->offset - r_anal_function_max_addr (f);
} else {
r_asm_set_pc (core->rasm, core->offset);

int maxopsize = r_anal_archinfo (core->anal,
R_ARCH_INFO_MAXOP_SIZE);
size_t bufsize = maxopsize > -1? R_MAX (maxopsize, 32): 32;
Expand All @@ -4649,7 +4693,6 @@ R_API void r_core_visual_disasm_down(RCore *core, RAnalOp *op, int *cols) {
R_LOG_ERROR ("Cannot allocate %d byte(s)", (int)bufsize);
return;
};
ut64 orig = core->offset;
size_t bufpos = 0;
size_t cpysize = 0;
while (bufpos < bufsize) {
Expand Down Expand Up @@ -4681,9 +4724,24 @@ R_API void r_core_visual_disasm_down(RCore *core, RAnalOp *op, int *cols) {
}
}
}
#if R2_USE_NEW_ABI
if (f && f->addr == orig) {
// skip line by line here
if (varcount (core, f) <= core->skiplines) {
*cols = op->size > 1 ? op->size : 1;
core->skiplines = 0;
} else {
core->skiplines ++;
*cols = 0;
}
} else if (*cols < 1) {
*cols = op->size > 1 ? op->size : 1;
}
#else
if (*cols < 1) {
*cols = op->size > 1 ? op->size : 1;
}
#endif
}

#ifdef R2__WINDOWS__
Expand Down
4 changes: 4 additions & 0 deletions libr/include/r_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,10 @@ struct r_core_t {
int (*r_main_ragg2)(int argc, const char **argv);
int (*r_main_rasm2)(int argc, const char **argv);
int (*r_main_rax2)(int argc, const char **argv);
#if R2_USE_NEW_ABI
int skiplines; // used only for disasm
void *priv;
#endif
};

// maybe move into RAnal
Expand Down

0 comments on commit e99f3e6

Please sign in to comment.