* Added r_cons_resize() and _interrupt() RConsEvent callbacks
- Use _resize() from visual mode, so redrawing is now cleaner * Minor bug fixes
This commit is contained in:
parent
730cfb9f49
commit
9cd07bd9d2
2
TODO
2
TODO
|
@ -8,6 +8,7 @@
|
|||
Things to improve in r2 (from radare.org/pad)
|
||||
=======================
|
||||
|
||||
- Implement print Zoom mode (copypasta from r1)
|
||||
- allow to hook r_asm_disassemble and assemble with custom callbacks
|
||||
- extend a disassembler with own instructions.
|
||||
- code analysis must resolve jump tables
|
||||
|
@ -17,7 +18,6 @@ Things to improve in r2 (from radare.org/pad)
|
|||
- focus in single arch (beat ida) mips, ppc64 or arm?
|
||||
- display filesize info instead of virtual space address limit
|
||||
- cursor can move outside screen (visual broken)
|
||||
- documentate 't' key in visual help (make navigation simpler)
|
||||
- fix instruction navigation (earada)
|
||||
- do not allow to disassemble unaligned addresses (toggle)
|
||||
- use 'jk' with bwdisasm to go up to previous opcode.
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include <r_io.h>
|
||||
|
||||
static struct r_io_t *io;
|
||||
static int fd = -1;
|
||||
static RIODesc *fd = NULL;
|
||||
static int rad = 0;
|
||||
struct r_search_t *rs;
|
||||
static ut64 from = 0LL, to = -1;
|
||||
|
@ -72,9 +72,9 @@ static int rafind_open(char *file) {
|
|||
int ret, last = 0;
|
||||
struct list_head *pos;
|
||||
|
||||
io = r_io_new();
|
||||
fd = r_io_open(io, file, R_IO_READ, 0);
|
||||
if (fd == -1) {
|
||||
io = r_io_new ();
|
||||
fd = r_io_open (io, file, R_IO_READ, 0);
|
||||
if (fd == NULL) {
|
||||
eprintf ("Cannot open file '%s'\n", file);
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* radare - LGPL - Copyright 2008-2010 pancake<nopcode.org> */
|
||||
/* radare - LGPL - Copyright 2008-2011 pancake<nopcode.org> */
|
||||
|
||||
#include <r_cons.h>
|
||||
#include <r_types.h>
|
||||
|
@ -16,8 +16,8 @@ static RCons r_cons_instance;
|
|||
|
||||
static void break_signal(int sig) {
|
||||
I.breaked = R_TRUE;
|
||||
if (I.break_cb)
|
||||
I.break_cb (I.break_user);
|
||||
if (I.event_interrupt)
|
||||
I.event_interrupt (I.data);
|
||||
}
|
||||
|
||||
static inline void r_cons_write (char *buf, int len) {
|
||||
|
@ -37,8 +37,8 @@ R_API RCons *r_cons_singleton () {
|
|||
|
||||
R_API void r_cons_break(void (*cb)(void *u), void *user) {
|
||||
I.breaked = R_FALSE;
|
||||
I.break_cb = cb;
|
||||
I.break_user = user;
|
||||
I.event_interrupt = cb;
|
||||
I.data = user;
|
||||
#if __UNIX__
|
||||
signal (SIGINT, break_signal);
|
||||
#endif
|
||||
|
@ -62,9 +62,18 @@ static BOOL __w32_control(DWORD type) {
|
|||
}
|
||||
#endif
|
||||
|
||||
#if __UNIX__
|
||||
static void resize (int sig) {
|
||||
if (I.event_resize)
|
||||
I.event_resize (I.data);
|
||||
}
|
||||
#endif
|
||||
|
||||
R_API RCons *r_cons_new () {
|
||||
I.event_interrupt = NULL;
|
||||
I.event_resize = NULL;
|
||||
I.data = NULL;
|
||||
I.is_interactive = R_TRUE;
|
||||
I.breaked = R_FALSE;
|
||||
I.noflush = R_FALSE;
|
||||
I.fdin = stdin;
|
||||
I.fdout = 1;
|
||||
|
@ -82,6 +91,7 @@ R_API RCons *r_cons_new () {
|
|||
I.term_raw.c_cflag &= ~(CSIZE|PARENB);
|
||||
I.term_raw.c_cflag |= CS8;
|
||||
I.term_raw.c_cc[VMIN] = 1; // Solaris stuff hehe
|
||||
signal (SIGWINCH, resize);
|
||||
#elif __WINDOWS__
|
||||
h = GetStdHandle (STD_INPUT_HANDLE);
|
||||
GetConsoleMode (h, (PDWORD) &I.term_buf);
|
||||
|
@ -267,23 +277,15 @@ R_API void r_cons_newline() {
|
|||
else r_cons_strcat ("\n");
|
||||
}
|
||||
|
||||
static void sig_winch(int i) {
|
||||
r_cons_get_size (NULL);
|
||||
}
|
||||
|
||||
R_API int r_cons_get_size(int *rows) {
|
||||
#if __UNIX__
|
||||
struct winsize win;
|
||||
struct sigaction sa;
|
||||
signal (SIGWINCH, sig_winch);
|
||||
sigaction (SIGWINCH, (struct sigaction *)0, &sa);
|
||||
sa.sa_flags &= ~ SA_RESTART;
|
||||
sigaction (SIGWINCH, &sa, (struct sigaction *)0);
|
||||
I.columns = 80;
|
||||
I.rows = 23;
|
||||
if (ioctl (1, TIOCGWINSZ, &win) == 0) {
|
||||
I.columns = win.ws_col;
|
||||
I.rows = win.ws_row;
|
||||
} else {
|
||||
I.columns = 80;
|
||||
I.rows = 23;
|
||||
}
|
||||
#else
|
||||
const char *str = r_sys_getenv ("COLUMNS");
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
/* radare - LGPL - Copyright 2009-2010 pancake<nopcode.org> */
|
||||
/* radare - LGPL - Copyright 2009-2011 pancake<nopcode.org> */
|
||||
|
||||
#include "r_core.h"
|
||||
|
||||
#define NPF 6
|
||||
static int printidx = 0;
|
||||
const char *printfmt[] = { "x", "pd", "f tmp&&sr sp&&x 64&&dr=&&s-&&s tmp&&f-tmp&&pd", "p8", "pc", "ps" };
|
||||
static const char *printfmt[] = { "x", "pd", "f tmp&&sr sp&&x 64&&dr=&&s-&&s tmp&&f-tmp&&pd", "p8", "pc", "ps" };
|
||||
|
||||
// XXX: use core->print->cur_enabled instead of curset/cursor/ocursor
|
||||
static int curset = 0, cursor = 0, ocursor=-1;
|
||||
|
@ -74,7 +74,7 @@ R_API int r_core_visual_trackflags(RCore *core) {
|
|||
fs2 = flag->name;
|
||||
hit = 1;
|
||||
}
|
||||
if ((i >=option-delta) && ((i<option+delta)||((option<delta)&&(i<(delta<<1))))) {
|
||||
if ((i>=option-delta) && ((i<option+delta)||((option<delta)&&(i<(delta<<1))))) {
|
||||
r_cons_printf (" %c %03d 0x%08"PFMT64x" %4"PFMT64d" %s\n",
|
||||
(option==i)?'>':' ',
|
||||
i, flag->offset, flag->size, flag->name);
|
||||
|
@ -529,6 +529,7 @@ static ut64 var_functions_show(RCore *core, int idx) {
|
|||
}
|
||||
return addr;
|
||||
}
|
||||
|
||||
/* Like emenu but for real */
|
||||
R_API void r_core_visual_anal(RCore *core) {
|
||||
int option = 0;
|
||||
|
@ -656,7 +657,6 @@ R_API void r_core_visual_anal(RCore *core) {
|
|||
}
|
||||
#endif
|
||||
|
||||
|
||||
R_API void r_core_visual_define (RCore *core) {
|
||||
int ch;
|
||||
ut64 off = core->offset;
|
||||
|
@ -704,7 +704,7 @@ R_API void r_core_visual_define (RCore *core) {
|
|||
|
||||
/* TODO: use r_cmd here in core->vcmd..optimize over 255 table */
|
||||
R_API int r_core_visual_cmd(RCore *core, int ch) {
|
||||
RAsmAop *aop;
|
||||
RAsmAop aop;
|
||||
char buf[1024];
|
||||
int cols = core->print->cols;
|
||||
ch = r_cons_arrow_to_hjkl (ch);
|
||||
|
@ -947,22 +947,23 @@ R_API int r_core_visual_cmd(RCore *core, int ch) {
|
|||
r_cons_clear00 ();
|
||||
r_cons_printf (
|
||||
"\nVisual mode help:\n\n"
|
||||
" >||< - seek aligned to block size\n"
|
||||
" hjkl - move around\n"
|
||||
" HJKL - move around faster\n"
|
||||
" pP - rotate print modes\n"
|
||||
" /*+- - change block size\n"
|
||||
" cC - toggle cursor and colors\n"
|
||||
" d[f?] - define function, data, code, ..\n"
|
||||
" x - find xrefs for current offset\n"
|
||||
" sS - step / step over\n"
|
||||
" uU - undo/redo seek\n"
|
||||
" yY - copy and paste selection\n"
|
||||
" mK/'K - mark/go to Key (any key)\n"
|
||||
" :cmd - run radare command\n"
|
||||
" ;[-]cmt - add/remove comment\n"
|
||||
" . - seek to program counter\n"
|
||||
" q - back to radare shell\n");
|
||||
" >||< - seek aligned to block size\n"
|
||||
" hjkl - move around\n"
|
||||
" HJKL - move around faster\n"
|
||||
" pP - rotate print modes\n"
|
||||
" /*+- - change block size\n"
|
||||
" cC - toggle cursor and colors\n"
|
||||
" d[f?] - define function, data, code, ..\n"
|
||||
" x - find xrefs for current offset\n"
|
||||
" sS - step / step over\n"
|
||||
" t - track flags (browse symbols, functions..\n"
|
||||
" uU - undo/redo seek\n"
|
||||
" yY - copy and paste selection\n"
|
||||
" mK/'K - mark/go to Key (any key)\n"
|
||||
" :cmd - run radare command\n"
|
||||
" ;[-]cmt - add/remove comment\n"
|
||||
" . - seek to program counter\n"
|
||||
" q - back to radare shell\n");
|
||||
r_cons_flush ();
|
||||
r_cons_any_key ();
|
||||
break;
|
||||
|
@ -983,12 +984,24 @@ R_API void r_core_visual_prompt(RCore *core, int color) {
|
|||
if (color) r_cons_strcat (Color_RESET);
|
||||
}
|
||||
|
||||
static void r_core_visual_refresh (RCore *core) {
|
||||
r_cons_get_size (NULL);
|
||||
r_cons_clear00 ();
|
||||
r_print_set_cursor (core->print, curset, ocursor, cursor);
|
||||
r_core_visual_prompt (core, color);
|
||||
r_core_cmd (core, printfmt[R_ABS (printidx%NPF)], 0);
|
||||
r_cons_visual_flush ();
|
||||
}
|
||||
|
||||
R_API int r_core_visual(RCore *core, const char *input) {
|
||||
const char *cmdprompt;
|
||||
const char *vi;
|
||||
ut64 scrseek;
|
||||
int ch;
|
||||
|
||||
r_cons_singleton ()->data = core;
|
||||
r_cons_singleton ()->event_resize = (RConsEvent)r_core_visual_refresh;
|
||||
|
||||
vi = r_config_get (core->config, "cmd.vprompt");
|
||||
if (vi) r_core_cmd (core, vi, 0);
|
||||
|
||||
|
@ -1000,7 +1013,7 @@ R_API int r_core_visual(RCore *core, const char *input) {
|
|||
r_cons_any_key ();
|
||||
return 0;
|
||||
}
|
||||
input = input + 1;
|
||||
input++;
|
||||
}
|
||||
|
||||
color = r_config_get_i (core->config, "scr.color");
|
||||
|
@ -1010,20 +1023,14 @@ R_API int r_core_visual(RCore *core, const char *input) {
|
|||
do {
|
||||
scrseek = r_num_math (core->num,
|
||||
r_config_get (core->config, "scr.seek"));
|
||||
if (scrseek != 0LL) {
|
||||
if (scrseek != 0LL)
|
||||
r_core_seek (core, scrseek, 1);
|
||||
// TODO: read?
|
||||
}
|
||||
if (debug)
|
||||
r_core_cmd (core, ".dr*", 0);
|
||||
cmdprompt = r_config_get (core->config, "cmd.vprompt");
|
||||
if (cmdprompt && *cmdprompt)
|
||||
r_core_cmd (core, cmdprompt, 0);
|
||||
r_cons_clear00 ();
|
||||
r_print_set_cursor (core->print, curset, ocursor, cursor);
|
||||
r_core_visual_prompt (core, color);
|
||||
r_core_cmd (core, printfmt[R_ABS (printidx%NPF)], 0);
|
||||
r_cons_visual_flush ();
|
||||
r_core_visual_refresh (core);
|
||||
ch = r_cons_readchar ();
|
||||
} while (r_core_visual_cmd (core, ch));
|
||||
|
||||
|
|
|
@ -39,6 +39,8 @@ typedef struct r_cons_grep_t {
|
|||
int neg;
|
||||
} RConsGrep;
|
||||
|
||||
typedef void (*RConsEvent)(void *);
|
||||
|
||||
typedef struct r_cons_t {
|
||||
RConsGrep grep;
|
||||
char *buffer;
|
||||
|
@ -56,21 +58,16 @@ typedef struct r_cons_t {
|
|||
FILE *fdin; // FILE? and then int ??
|
||||
int fdout; // only used in pipe.c :?? remove?
|
||||
char *teefile;
|
||||
void (*break_cb)(void *user); // TODO: use RConsBreakCallback here
|
||||
void *break_user;
|
||||
/* TODO: rewrite as in typedef */
|
||||
int (*user_fgets)(char *buf, int len);
|
||||
RConsEvent event_interrupt;
|
||||
RConsEvent event_resize;
|
||||
void *data;
|
||||
#if __UNIX__
|
||||
struct termios term_raw, term_buf;
|
||||
#elif __WINDOWS__
|
||||
LPDWORD term_raw, term_buf;
|
||||
#endif
|
||||
} RCons;
|
||||
//extern RCons r_cons_instance;
|
||||
|
||||
// TODO: pass instance ?
|
||||
typedef void (*RConsBreakCallback)(void *user);
|
||||
//--
|
||||
|
||||
// XXX THIS MUST BE A SINGLETON AND WRAPPED INTO RCons */
|
||||
/* XXX : global variables? or a struct with a singleton? */
|
||||
|
@ -143,7 +140,6 @@ enum {
|
|||
#endif
|
||||
|
||||
#ifdef R_API
|
||||
|
||||
R_API RCons *r_cons_new ();
|
||||
R_API RCons *r_cons_singleton ();
|
||||
R_API RCons *r_cons_free ();
|
||||
|
|
|
@ -212,7 +212,7 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba
|
|||
inc = 2 + (int)((p->width-14)/4);
|
||||
if (inc%2) inc++;
|
||||
inc = 16;
|
||||
inc = p->cols;
|
||||
inc = p->cols;
|
||||
|
||||
if (p->flags & R_PRINT_FLAGS_HEADER) {
|
||||
// only for color..too many options .. brbr
|
||||
|
|
Loading…
Reference in New Issue