Add scr.flush and handle ^C in px/pxr/pd/..

This commit is contained in:
pancake 2016-09-20 00:11:59 +02:00
parent 2c2e3078e0
commit 6d6a23c456
7 changed files with 44 additions and 10 deletions

View File

@ -355,12 +355,20 @@ R_API char* r_anal_reflines_str(void *_core, ut64 addr, int opts) {
int middle = opts & R_ANAL_REFLINE_TYPE_MIDDLE;
char *str = NULL;
if (!anal || !anal->reflines) return NULL;
if (!anal || !anal->reflines) {
return NULL;
}
RList *lvls = r_list_new ();
if (!lvls) return NULL;
if (!lvls) {
return NULL;
}
r_list_foreach (anal->reflines, iter, ref) {
if (core && core->cons && core->cons->breaked) {
r_list_free (lvls);
return NULL;
}
if (in_refline (addr, ref)) {
r_list_add_sorted (lvls, (void *)ref, (RListComparator)cmp_by_ref_lvl);
}
@ -370,6 +378,10 @@ R_API char* r_anal_reflines_str(void *_core, ut64 addr, int opts) {
b = r_buf_new ();
r_buf_append_string (b, " ");
r_list_foreach (lvls, iter, ref) {
if (core && core->cons && core->cons->breaked) {
r_list_free (lvls);
return NULL;
}
if (ref->from == addr || ref->to == addr) {
const char *corner = get_corner_char (ref, addr, middle);
const char ch = ref->from == addr ? '=' : '-';

View File

@ -664,6 +664,9 @@ R_API void r_cons_memcat(const char *str, int len) {
I.buffer_len += len;
I.buffer[I.buffer_len] = 0;
}
if (I.flush) {
r_cons_flush ();
}
}
R_API void r_cons_memset(char ch, int len) {

View File

@ -2515,16 +2515,20 @@ static int cmd_print(void *data, const char *input) {
// get to the space
if (input[0]) {
for (pos = 1; pos < R_BIN_SIZEOF_STRINGS && input[pos]; pos++)
if (input[pos] == ' ') break;
for (pos = 1; pos < R_BIN_SIZEOF_STRINGS && input[pos]; pos++) {
if (input[pos] == ' ') {
break;
}
}
}
if (!process_input (core, input+pos, &use_blocksize, &new_arch, &new_bits)) {
// XXX - print help message
//return false;
}
if (!use_blocksize)
if (!use_blocksize) {
use_blocksize = core->blocksize;
}
if (core->blocksize_max < use_blocksize && (int)use_blocksize < -core->blocksize_max) {
eprintf ("This block size is too big (%"PFMT64d"<%"PFMT64d"). Did you mean 'p%c @ 0x%08"PFMT64x"' instead?\n",
@ -2548,7 +2552,7 @@ static int cmd_print(void *data, const char *input) {
switch (input[1]) {
case 'c': // "pdc" // "pDc"
r_core_pseudo_code (core, input+2);
r_core_pseudo_code (core, input + 2);
pd_result = 0;
processed_cmd = true;
break;
@ -2827,7 +2831,7 @@ static int cmd_print(void *data, const char *input) {
case 0:
/* "pd" -> will disassemble blocksize/4 instructions */
if (*input=='d') {
l/=4;
l /= 4;
}
break;
case '?': // "pd?"
@ -2887,7 +2891,7 @@ static int cmd_print(void *data, const char *input) {
r_core_read_at (core, addr+bs, block+bs, instr_len-bs); //core->blocksize);
core->num->value = r_core_print_disasm (core->print,
core, addr, block, instr_len, l, 0, 1);
r_core_seek(core, prevaddr, true);
r_core_seek (core, prevaddr, true);
}
}
} else {
@ -3256,6 +3260,7 @@ static int cmd_print(void *data, const char *input) {
core->print->flags &= ~R_PRINT_FLAGS_HEADER;
}
}
r_cons_break (NULL, NULL);
switch (input[1]) {
case '/':
r_core_print_examine (core, input+2);
@ -3473,9 +3478,11 @@ static int cmd_print(void *data, const char *input) {
if (bitsize == 16) bitsize = 32;
core->print->cols = 1;
core->print->flags |= R_PRINT_FLAGS_REFS;
r_cons_break (NULL, NULL);
r_print_hexdump (core->print, core->offset,
core->block, len,
bitsize, bitsize / 8);
r_cons_break_end ();
core->print->flags &= ~R_PRINT_FLAGS_REFS;
core->print->cols = ocols;
}
@ -3678,6 +3685,7 @@ static int cmd_print(void *data, const char *input) {
}
break;
}
r_cons_break_end ();
break;
case '2': // "p2"
if (l != 0) {

View File

@ -1088,6 +1088,12 @@ static int cb_screcho(void *user, void *data) {
return true;
}
static int cb_scrflush(void *user, void *data) {
RConfigNode *node = (RConfigNode *) data;
r_cons_singleton()->flush = node->i_value;
return true;
}
static int cb_exectrap(void *user, void *data) {
RConfigNode *node = (RConfigNode *) data;
RCore *core = (RCore*) user;
@ -1890,6 +1896,7 @@ R_API int r_core_config_init(RCore *core) {
#endif
r_config_desc (cfg, "scr.fgets", "Use fgets() instead of dietline for prompt input");
SETCB("scr.echo", "false", &cb_screcho, "Show rcons output in realtime to stderr and buffer");
SETCB("scr.flush", "false", &cb_scrflush, "Force flush to console in realtime (breaks scripting)");
/* TODO: rename to asm.color.ops ? */
SETPREF("scr.color.ops", "true", "Colorize numbers and registers in opcodes");
SETPREF("scr.color.bytes", "true", "Colorize bytes that represent the opcodes of the instruction");

View File

@ -3074,9 +3074,9 @@ toro:
for (i = idx = ret = 0; idx < len && ds->lines < ds->l;
idx += inc, i++, ds->index += inc, ds->lines++) {
ds->at = ds->addr + idx;
if (r_cons_singleton ()->breaked) {
if (core->cons && core->cons->breaked) {
dorepeat = 0;
break;
return 0; //break;
}
r_core_seek_archbits (core, ds->at); // slow but safe
ds->has_description = false;

View File

@ -219,6 +219,7 @@ typedef struct r_cons_t {
#if __WINDOWS__ && !__CYGWIN__
bool ansicon;
#endif
bool flush;
} RCons;
// XXX THIS MUST BE A SINGLETON AND WRAPPED INTO RCons */

View File

@ -719,6 +719,9 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba
//for (i=j=0; (p&&!p->interrupt) && i<len; i+=(stride?stride:inc), j+=(stride?stride:0)) {
for (i=j=0; i<len; i+=(stride?stride:inc), j+=(stride?stride:0)) {
r_print_set_screenbounds (p, addr + i);
if (p && p->cons && p->cons->breaked) {
break;
}
if (use_sparse) {
if (check_sparse (buf+i, inc, sparse_char)) {
if (i+inc>=len || check_sparse (buf+i+inc, inc, sparse_char)) {