Esempio n. 1
0
static bool run_commands(RList *cmds, RList *files, bool quiet) {
	RListIter *iter;
	const char *cmdn;
	const char *file;
	int ret;
	/* -i */
	r_list_foreach (files, iter, file) {
		if (!r_file_exists (file)) {
			eprintf ("Script '%s' not found.\n", file);
			return false;
		}
		ret = r_core_run_script (&r, file);
		if (ret == -2) {
			eprintf ("Cannot open '%s'\n", file);
		}
		if (ret < 0 || (ret == 0 && quiet)) {
			r_cons_flush ();
			return false;
		}
	}
	/* -c */
	r_list_foreach (cmds, iter, cmdn) {
		r_core_cmd0 (&r, cmdn);
		r_cons_flush ();
	}
Esempio n. 2
0
R_API void r_core_visual_seek_animation (RCore *core, ut64 addr) {
	if (r_config_get_i (core->config, "scr.feedback")<1)
		return;
#if 0
	int i, ns = 90000;
	const char *scmd = (addr > core->offset)? "so": "s-4";
	for (i=0;i<5;i++) {
		r_core_cmd0 (core, scmd);
		r_core_visual_refresh (core);
		r_cons_flush();
		r_sys_usleep (ns);
		ns -= 1000;
	}
	r_core_seek (core, addr, 1);
#else
	if (core->offset == addr)
		return;
	r_cons_gotoxy (1, 2);
	if (addr>core->offset) {
		r_cons_printf (".----.\n");
		r_cons_printf ("| \\/ |\n");
		r_cons_printf ("'----'\n");
	} else {
		r_cons_printf (".----.\n");
		r_cons_printf ("| /\\ |\n");
		r_cons_printf ("'----'\n");
	}
	r_cons_flush();
	r_sys_usleep (90000);
#endif
	r_core_seek (core, addr, 1);
}
Esempio n. 3
0
static int r_core_visual_hud(RCore *core) {
    const char *f = R2_LIBDIR"/radare2/"R2_VERSION"/hud/main";
    char *homehud = r_str_home (R2_HOMEDIR"/hud");
    char *res = NULL;
    char *p = 0;

    showcursor (core, R_TRUE);
    if (homehud)
        res = r_cons_hud_file (homehud);
    if (!res) {
        if (r_file_exists (f))
            res = r_cons_hud_file (f);
        else r_cons_message ("Cannot find hud file");
    }
    r_cons_clear ();
    if (res) {
        p = strchr (res, '\t');
        core->printidx = 1;
        r_cons_printf ("%s\n", res);
        r_cons_flush ();
        if (p) r_core_cmd0 (core, p+1);
        free (res);
    }
    showcursor (core, R_FALSE);
    r_cons_flush ();
    free (homehud);
    return (int)(size_t)p;
}
Esempio n. 4
0
R_API int r_core_visual_hud(RCore *core) {
	const char *c = r_config_get (core->config, "hud.path");
	const char *f = R2_LIBDIR"/radare2/"R2_VERSION"/hud/main";
	char *homehud = r_str_home (R2_HOMEDIR"/hud");
	char *res = NULL;
	char *p = 0;

	showcursor (core, true);
	if (c && *c && r_file_exists (c))
		res = r_cons_hud_file (c);
	if (!res && homehud)
		res = r_cons_hud_file (homehud);
	if (!res && r_file_exists (f))
		res = r_cons_hud_file (f);
	if (!res)
		r_cons_message ("Cannot find hud file");

	r_cons_clear ();
	if (res) {
		p = strchr (res, '\t');
		r_cons_printf ("%s\n", res);
		r_cons_flush ();
		if (p) r_core_cmd0 (core, p+1);
		free (res);
	}
	showcursor (core, false);
	r_cons_flush ();
	free (homehud);
	return (int)(size_t)p;
}
Esempio n. 5
0
R_API int r_core_visual_prompt (RCore *core) {
	char buf[1024];
	int ret;
#if __UNIX__
	r_line_set_prompt (Color_RESET":> ");
#else
	r_line_set_prompt (":> ");
#endif
	showcursor (core, true);
	r_cons_fgets (buf, sizeof (buf), 0, NULL);
	if (!strcmp (buf, "q")) {
		ret = false;
	} else if (*buf) {
		r_line_hist_add (buf);
		r_core_cmd (core, buf, 0);
		r_cons_flush ();
		ret = true;
	} else {
		ret = false;
		//r_cons_any_key (NULL);
		r_cons_clear00 ();
		showcursor (core, false);
	}
	return ret;
}
Esempio n. 6
0
static int visual_repeat_thread(RThread *th) {
	RCore *core = th->user;
	int i = 0;
	for (;;) {
		if (core->cons->breaked)
			break;
		r_core_visual_refresh (core);
		r_cons_flush ();
		r_cons_gotoxy (0, 0);
		r_cons_printf ("[@%d] ", i++);
		r_cons_flush ();
		r_sys_sleep (1);
	}
	r_th_kill (th, 1);
	return 0;
}
Esempio n. 7
0
R_API int r_core_visual_prompt (RCore *core) {
    char buf[1024];
    int ret;
    ut64 oseek = core->offset;
#if __UNIX__
    r_line_set_prompt (Color_RESET":> ");
#else
    r_line_set_prompt (":> ");
#endif
    showcursor (core, R_TRUE);
    r_cons_fgets (buf, sizeof (buf), 0, NULL);
    if (*buf) {
        r_line_hist_add (buf);
        r_core_cmd (core, buf, 0);
        r_cons_flush ();
        ret = R_TRUE;
    } else {
        ret = R_FALSE;
        //r_cons_any_key ();
        r_cons_clear00 ();
        showcursor (core, R_FALSE);
    }
    if (curset) r_core_seek (core, oseek, 1);
    return ret;
}
Esempio n. 8
0
int main() {
	int i,j ,k;
	//char *str = "\x1b[38;5;231mpop\x1b[0m";
         //char *str ="\x1b]4;%d;rgb:30/20/24pop\x1b[0m";
         char *str ="\x1b\\pop\x1b[0m";
i=j=k =0;

	r_cons_new ();
//	r_cons_rgb_init ();
	printf ("3 == %d\n", r_str_ansi_len (str));
	for (i=0;i<255;i+=40) {
	for (j=0;j<255;j+=40) { for (k=0;k<255;k+=40) {
		r_cons_rgb (i, j, k, 0);
		r_cons_rgb (i, j, k, 1);
		r_cons_print ("__");
		r_cons_reset_colors ();

		r_cons_rgb (i, j, k, 0);
//		r_cons_rgb (155, 200, 200, 1);
		r_cons_printf (" RGB %d %d %d", i, j, k);
		r_cons_reset_colors ();
		r_cons_newline ();
	}
}}
	r_cons_flush ();

	return 0;
}
Esempio n. 9
0
static void showcursor(RCore *core, int x) {
    if (core && core->vmode) {
        r_cons_show_cursor (x);
        r_cons_enable_mouse (!!!x);
    } else r_cons_enable_mouse (R_FALSE);
    r_cons_flush ();
}
Esempio n. 10
0
File: rtr.c Progetto: moon2l/radare2
R_API void r_core_rtr_session(RCore *core, const char *input) {
	char prompt[32], buf[4096];
	int fd;

	if (input[0] >= '0' && input[0] <= '9') {
		fd = r_num_math (core->num, input);
		//for (rtr_n = 0; rtr_host[rtr_n].fd->fd != fd && rtr_n < RTR_MAX_HOSTS; rtr_n++);
	}

	for (;;) {
		if (rtr_host[rtr_n].fd)
			snprintf (prompt, sizeof (prompt),
				"fd:%d> ", rtr_host[rtr_n].fd->fd);
		free (r_line_singleton ()->prompt);
		r_line_singleton ()->prompt = strdup (prompt);
		if ((r_cons_fgets (buf, sizeof (buf), 0, NULL))) {
			if (*buf == 'q')
				break;
			else if (*buf == 'V') {
				eprintf ("Visual mode not supported\n");
				continue;
			}
			r_core_rtr_cmd (core, buf);
			r_cons_flush ();
		}
	}
}
Esempio n. 11
0
static int readline_callback(void *_a, const char *str) {
	RCoreVisualAsm *a = _a;
	int xlen;
	r_cons_clear00 ();
	r_cons_printf ("Write your favourite %s-%d opcode...\n\n",
		r_config_get (a->core->config, "asm.arch"),
		r_config_get_i (a->core->config, "asm.bits"));
	if (*str == '?') {
		r_cons_printf ("0> ?\n\n"
			"Visual assembler help:\n\n"
			"  assemble input while typing using asm.arch, asm.bits and cfg.bigendian\n"
			"  press enter to quit (prompt if there are bytes to be written)\n"
			"  this assembler supports various directives like .hex ...\n"
			);
	} else {
		r_asm_code_free (a->acode);
		a->acode = r_asm_massemble (a->core->assembler, str);
		r_cons_printf ("%d> %s\n", a->acode? a->acode->len: 0, str);
		if (a->acode && a->acode->len)
			r_cons_printf ("* %s\n\n", a->acode->buf_hex);
		else r_cons_printf ("\n\n");
		if (a->acode) {
			xlen = strlen (a->acode->buf_hex);
			strcpy (a->codebuf, a->blockbuf);
			memcpy (a->codebuf, a->acode->buf_hex, xlen);
		}
		r_core_cmdf (a->core, "pd 7@b:%s @0x%"PFMT64x, a->codebuf, a->off);
	}
	r_cons_flush ();
	return 1;
}
Esempio n. 12
0
// Below this line are the r_io_zip plugin APIs
static RIODesc *r_io_zip_open(RIO *io, const char *file, int rw, int mode) {
	RIODesc *result = NULL;
	RIOZipFileObj *zipFileObj = NULL;

	char *zip_uri = NULL, *zip_filename = NULL, *filename_in_zipfile = NULL;
	if (!r_io_zip_plugin_open (io, file)) {
		return result;
	}

	zip_uri = strdup(file);
	// 1) Tokenize to the '//' and find the base file directory ('/')
	zip_filename = strstr(zip_uri, "//");
	if (zip_filename && zip_filename[2]) {
		if (zip_filename[0] && zip_filename[0] == '/' &&
			zip_filename[1] && zip_filename[1] == '/' ) {
			*zip_filename++ = 0;	
		}
		*zip_filename++ = 0;

		filename_in_zipfile = strstr(zip_filename, "//");
		if (filename_in_zipfile && filename_in_zipfile[2]) {
			// null terminating uri to filename here.
			*filename_in_zipfile++ = 0;
			*filename_in_zipfile++ = 0;
		}
	}

	if (!zip_filename) {// && !filename_in_zipfile) {
		if (zip_uri)
			free(zip_uri);
		eprintf("usage: zip:///path/to/archive//filepath\n");
		eprintf("Archive was not found.\n");

		return result;
	}

	// Failed to find the file name the archive.
	if (!filename_in_zipfile) {
		RList *files = NULL;
		RListIter *iter, *iter_tmp;
		char *name;
		//eprintf("usage: zip:///path/to/archive//filepath\n");
		eprintf("\nFiles in archive\n\n");
		files = r_io_zip_get_files(zip_filename, 0, mode, rw );

		if (files) {
			int i = 0;
			r_list_foreach_safe(files, iter, iter_tmp, name) {
				// XXX - io->printf does not flush
				// io->printf("%s\n", name);
				r_cons_printf("%s\n", name);
				r_cons_flush ();
				free (name);
				r_list_delete (files, iter);
			}
			r_list_free (files);
		}
Esempio n. 13
0
static void visual_help() {
	r_cons_clear00 ();
	r_cons_less_str (
	"Visual mode help:\n"
	" ?        show this help or manpage in cursor mode\n"
	" &        rotate asm.bits between supported 8, 16, 32, 64\n"
	" %        in cursor mode finds matching pair, otherwise toggle autoblocksz\n"
	" @        set cmd.vprompt to run commands before the visual prompt\n"
	" !        enter into the visual panels mode\n"
	" _        enter the hud\n"
	" =        set cmd.vprompt (top row)\n"
	" |        set cmd.cprompt (right column)\n"
	" .        seek to program counter\n"
	" /        in cursor mode search in current block\n"
	" :cmd     run radare command\n"
	" ;[-]cmt  add/remove comment\n"
	" /*+-[]   change block size, [] = resize hex.cols\n"
	" >||<     seek aligned to block size\n"
	" a/A      (a)ssemble code, visual (A)ssembler\n"
	" b        toggle breakpoint\n"
	" c/C      toggle (c)ursor and (C)olors\n"
	" d[f?]    define function, data, code, ..\n"
	" D        enter visual diff mode (set diff.from/to)\n"
	" e        edit eval configuration variables\n"
	" f/F      set/unset or browse flags. f- to unset, F to browse, ..\n"
	" gG       go seek to begin and end of file (0-$s)\n"
	" hjkl     move around (or HJKL) (left-down-up-right)\n"
	" i        insert hex or string (in hexdump) use tab to toggle\n"
	" mK/'K    mark/go to Key (any key)\n"
	" M        walk the mounted filesystems\n"
	" n/N      seek next/prev function/flag/hit (scr.nkey)\n"
	" o        go/seek to given offset\n"
	" O        toggle asm.esil\n"
	" p/P      rotate print modes (hex, disasm, debug, words, buf)\n"
	" q        back to radare shell\n"
	" r        browse anal info and comments\n"
	" R        randomize color palette (ecr)\n"
	" sS       step / step over\n"
	" T        enter textlog chat console (TT)\n"
	" uU       undo/redo seek\n"
	" v        visual code analysis menu\n"
	" V        (V)iew graph using cmd.graph (agv?)\n"
	" wW       seek cursor to next/prev word\n"
	" xX       show xrefs/refs of current function from/to data/code\n"
	" yY       copy and paste selection\n"
	" z        fold/unfold comments in disassembly\n"
	" Z        toggle zoom mode\n"
	" Enter    follow address of jump/call\n"
	"Function Keys: (See 'e key.'), defaults to:\n"
	"  F2      toggle breakpoint\n"
	"  F7      single step\n"
	"  F8      step over\n"
	"  F9      continue\n"
	);
	r_cons_flush ();
	r_cons_clear00 ();
}
Esempio n. 14
0
static void printpage (const char *line, int *index, int from, int to) {
	int i;
	r_cons_clear00 ();
	for (i=from; i<to; i++) {
// TODO: chop column width, clear lines
		r_cons_printf ("%s\n", line+index[i]);
	}
	r_cons_flush ();
}
Esempio n. 15
0
R_API int r_cons_any_key(const char *msg) {
	if (msg && *msg) {
		r_cons_printf ("\n-- %s --\n", msg);
	} else {
		r_cons_print ("\n--press any key--\n");
	}
	r_cons_flush ();
	return r_cons_readchar ();
	//r_cons_strcat ("\x1b[2J\x1b[0;0H"); // wtf?
}
Esempio n. 16
0
R_API int r_core_project_save(RCore *core, const char *file) {
	int fd, tmp, ret = R_TRUE;
	char *prj;

	if (file == NULL || *file == '\0')
		return R_FALSE;

	prj = r_core_project_file (file);
	r_core_project_init ();
	fd = r_sandbox_open (prj, O_BINARY|O_RDWR|O_CREAT, 0644);
	if (fd != -1) {
		int fdold = r_cons_singleton ()->fdout;
		r_cons_singleton ()->fdout = fd;
		r_cons_singleton ()->is_interactive = R_FALSE;
		r_str_write (fd, "# r2 rdb project file\n");
		//--
		r_str_write (fd, "# flags\n");
		tmp = core->flags->space_idx;
		core->flags->space_idx = -1;
		r_flag_list (core->flags, R_TRUE);
		core->flags->space_idx = tmp;
		r_cons_flush ();
		//--
		r_str_write (fd, "# eval\n");
		// TODO: r_str_writef (fd, "e asm.arch=%s", r_config_get ("asm.arch"));
		r_config_list (core->config, NULL, R_TRUE);
		r_cons_flush ();
		r_str_write (fd, "# sections\n");
		r_io_section_list (core->io, core->offset, 1);
		r_cons_flush ();
		r_str_write (fd, "# meta\n");
		r_meta_list (core->anal->meta, R_META_TYPE_ANY, 1);
		r_cons_flush ();
		r_core_cmd (core, "ar*", 0);
		r_cons_flush ();
		r_core_cmd (core, "af*", 0);
		r_cons_flush ();
		r_core_cmd (core, "ah*", 0);
		r_cons_flush ();
		r_str_write (fd, "# seek\n");
		r_str_writef (fd, "s 0x%08"PFMT64x, core->offset);
		r_cons_flush ();
		close (fd);
		r_cons_singleton ()->fdout = fdold;
		r_cons_singleton ()->is_interactive = R_TRUE;
	} else {
		eprintf ("Cannot open '%s' for writing\n", prj);
		ret = R_FALSE;
	}
	free (prj);
	return ret;
}
Esempio n. 17
0
R_API void r_core_visual_show_char (RCore *core, char ch) {
	if (r_config_get_i (core->config, "scr.feedback")<2)
		return;
	if (!IS_PRINTABLE (ch))
		return;
	r_cons_gotoxy (1, 2);
	r_cons_printf (".---.\n");
	r_cons_printf ("| %c |\n", ch);
	r_cons_printf ("'---'\n");
	r_cons_flush ();
	r_sys_sleep (1);
}
Esempio n. 18
0
R_API void r_cons_2048() {
	int ch;
	r_cons_set_raw (1);
	twok_init ();
	twok_add ();
	twok_add ();
	while (twok_fin()) {
		r_cons_clear00();
		r_cons_printf ("[r2048] score: %d   moves: %d\n",
			score, moves);
		r_cons_flush ();
		twok_print();
		ch = r_cons_readchar ();
		ch = r_cons_arrow_to_hjkl (ch);
		switch(ch){
		case 'h':
			twok_move(1,1);
			break;
		case 'j':
			twok_move(0,0);
			break;
		case 'k':
			twok_move(0,1);
			break;
		case 'l':
			twok_move(1,0);
			break;
		}
		if (ch<1||ch =='q') break;
	}
	r_cons_clear00();
	r_cons_printf ("[r2048] score: %d\n", score );
	r_cons_flush ();
	twok_print();
	r_cons_printf ("\n  [r2048.score] %d\n", score );
	do {
		ch = r_cons_any_key ("Press 'q' to quit.");
	} while (ch != 'q' && ch >= 1);
	r_cons_set_raw (0);
}
Esempio n. 19
0
// XXX no control for max length here?!?!
R_API int r_cons_fgets(char *buf, int len, int argc, const char **argv) {
#define RETURN(x) { ret=x; goto beach; }
	RCons *cons = r_cons_singleton ();
	int ret = 0, color = cons->pal.input && *cons->pal.input;
	if (cons->echo) {
		r_cons_set_raw (0);
		r_cons_show_cursor (1);
	}
#if 0
	int mouse = r_cons_enable_mouse (false);
	r_cons_enable_mouse (false);
	r_cons_flush ();
#endif
	if (cons->user_fgets) {
		RETURN (cons->user_fgets (buf, len));
	}
	printf ("%s", cons->line->prompt);
	fflush (stdout);
	*buf = '\0';
	fflush (cons->fdin);
	if (color) {
		const char *p = cons->pal.input;
		int len = p? strlen (p): 0;
		if (len>0)
			fwrite (p, len, 1, stdout);
		fflush (stdout);
	}
	if (!fgets (buf, len, cons->fdin)) {
		if (color) {
			printf (Color_RESET);
			fflush (stdout);
		}
		RETURN (-1);
	}
	if (feof (cons->fdin)) {
		if (color) {
			printf (Color_RESET);
		}
		RETURN (-2);
	}
	buf[strlen (buf)-1] = '\0';
	if (color) printf (Color_RESET);
	ret = strlen (buf);
beach:
#if __UNIX__
	if (errno == EINTR) {
		ret = 0;
	}
#endif
	//r_cons_enable_mouse (mouse);
	return ret;
}
Esempio n. 20
0
static void showcursor(RCore *core, int x) {
	if (core && core->vmode) {
		r_cons_show_cursor (x);
		if (x) {
			// TODO: cache this
			int wheel = r_config_get_i (core->config, "scr.wheel");
			if (wheel) r_cons_enable_mouse (true);
			else r_cons_enable_mouse (false);
		} else {
			r_cons_enable_mouse (false);
		}
	} else r_cons_enable_mouse (false);
	r_cons_flush ();
}
Esempio n. 21
0
// TODO: Add fmt support
R_API char *r_cons_message(const char *msg) {
	int cols, rows;
	int len = strlen (msg);
	cols = r_cons_get_size (&rows);

	r_cons_clear ();
	r_cons_gotoxy ((cols-len)/2, rows/2); // XXX
	/// TODO: add square, or talking clip here
	r_cons_printf ("%s\n", msg);
	r_cons_flush ();
	r_cons_gotoxy (0, rows-2); // XXX
	r_cons_any_key ();
	return NULL;
}
Esempio n. 22
0
static void visual_help() {
	r_cons_clear00 ();
	r_cons_less_str (
	"Visual mode help:\n"
	" ?        show this help or manpage in cursor mode\n"
	" &        rotate asm.bits between supported 8, 16, 32, 64\n"
	" !        run r2048 game\n"
	" _        enter the hud\n"
	" .        seek to program counter\n"
	" /        in cursor mode search in current block\n"
	" :cmd     run radare command\n"
	" ;[-]cmt  add/remove comment\n"
	" /*+-[]   change block size, [] = resize hex.cols\n"
	" >||<     seek aligned to block size\n"
	" i/a/A    (i)nsert hex, (a)ssemble code, visual (A)ssembler\n"
	" b/B      toggle breakpoint / automatic block size\n"
	" c/C      toggle (c)ursor and (C)olors\n"
	" d[f?]    define function, data, code, ..\n"
	" D        enter visual diff mode (set diff.from/to)\n"
	" e        edit eval configuration variables\n"
	" f/F      set/unset flag\n"
	" gG       go seek to begin and end of file (0-$s)\n"
	" hjkl     move around (or HJKL) (left-down-up-right)\n"
	" mK/'K    mark/go to Key (any key)\n"
	" M        walk the mounted filesystems\n"
	" n/N      seek next/prev function/flag/hit (scr.nkey)\n"
	" o        go/seek to given offset\n"
	" p/P      rotate print modes (hex, disasm, debug, words, buf)\n"
	" q        back to radare shell\n"
	" R        randomize color palette (ecr)\n"
	" sS       step / step over\n"
	" t        track flags (browse symbols, functions..)\n"
	" T        browse anal info and comments\n"
	" v        visual code analysis menu\n"
	" V/W      (V)iew graph using cmd.graph (agv?), open (W)ebUI\n"
	" uU       undo/redo seek\n"
	" xX       show xrefs/refs of current function from/to data/code\n"
	" yY       copy and paste selection\n"
	" z        toggle zoom mode\n"
	" Enter    follow address of jump/call\n"
	"Function Keys: (See 'e key.'), defaults to:\n"
	"  F2      toggle breakpoint\n"
	"  F7      single step\n"
	"  F8      step over\n"
	"  F9      continue\n"
	);
	r_cons_flush ();
	r_cons_clear00 ();
}
Esempio n. 23
0
static int hit(RSearchKeyword *kw, void *user, ut64 addr) {
	int delta = addr - cur;
	if (cur > addr && (cur - addr == kw->keyword_length - 1)) {
		// This case occurs when there is hit in search left over
		delta = cur - addr;
	}
	if (delta < 0 || delta >= bsize) {
		eprintf ("Invalid delta\n");
		return 0;
	}
	if (rad) {
		printf ("f hit%d_%d 0x%08"PFMT64x" ; %s\n", 0, kw->count, addr, curfile);
	} else {
		if (showstr) {
			if (widestr) {
				char *str = calloc (1, bsize);
				int i, j = 0;
				for (i = delta; buf[i] && i < bsize; i++) {
					if (!IS_PRINTABLE (buf[i])) {
						break;
					}
					str[j++] = buf[i++];
					if (j > 80) {
						strcpy (str + j, "...");
						j += 3;
						break;
					}
					if (buf[i]) {
						break;
					}
				}
				str[j] = 0;
				printf ("0x%"PFMT64x" %s\n", addr, str);
				free (str);
			} else {
				printf ("0x%"PFMT64x" %s\n", addr, buf + delta);
			}
		} else {
			printf ("0x%"PFMT64x"\n", addr);
			if (pr) {
				r_print_hexdump (pr, addr, (ut8*)buf + delta, 78, 16, 1, 1);
				r_cons_flush ();
			}
		}
	}
	return 1;
}
Esempio n. 24
0
/* final entrypoint for adding stuff in the buffer screen */
R_API void r_cons_memcat(const char *str, int len) {
	if (len < 0 || (I.buffer_len + len) < 0) {
		return;
	}
	if (I.echo) {
		write (2, str, len);
	}
	if (str && len > 0 && !I.null) {
		palloc (len+1);
		memcpy (I.buffer + I.buffer_len, str, len);
		I.buffer_len += len;
		I.buffer[I.buffer_len] = 0;
	}
	if (I.flush) {
		r_cons_flush ();
	}
}
Esempio n. 25
0
main() {
	char *res;
	RFList fl = r_flist_new (3);
	r_flist_set (fl, 0, "foo is pure cow");
	r_flist_set (fl, 1, "bla is kinda crazy");
	r_flist_set (fl, 2, "funny to see you here");
	
	r_cons_new ();
	res = r_cons_hud (fl, NULL);
	r_cons_clear ();
	if (res) {
		r_cons_printf ("%s\n", res);
		free (res);
	}
	r_cons_flush ();
	r_cons_free ();
}
Esempio n. 26
0
static void printpage (const char *line, int *index, RRegexMatch **ms,
		       int from, int to, int w) {
	int i;
	RStrpool *p;

	r_cons_clear00 ();
	if (from <0 || to <0) {
		return;
	}
	p = r_strpool_new(0);
	for (i=from; i<to; i++) {
		color_line(line + index[i], p, ms[i]);
		r_strpool_ansi_chop(p, w);
		r_cons_reset_colors();
		r_cons_printf ("%s\n", p->str);
	}
	r_strpool_free(p);
	r_cons_flush ();
}
Esempio n. 27
0
static int parseMouseEvent() {
	int ch = r_cons_readchar ();
	/* Skip the x/y coordinates */
#if USE_CLICK
	int x = r_cons_readchar() - 33;
	int y = r_cons_readchar() - 33;
#else
	(void) r_cons_readchar ();
	(void) r_cons_readchar ();
#endif
#if USE_CLICK
	if (ch == 35) {
		/* handle click  */
#define CLICK_DEBUG 1
#if CLICK_DEBUG
		r_cons_gotoxy (0, 0);
		r_cons_printf ("Click at %d %d\n", x, y);
		r_cons_flush ();
#endif
		RCons *cons = r_cons_singleton ();
		if (cons->onclick) {
			cons->onclick (cons->data, x, y);
		}
		r_cons_enable_mouse (false);
		(void)r_cons_readchar ();
		return 0;
	}
#endif
	if (ch != 0x20 && ch >= 64 + 32) {
		/* Grab wheel events only */
		I->mouse_event = 1;
		return "kj"[(ch - (64 + 32))&1];
	}

	// temporary disable the mouse wheel to allow select
	r_cons_enable_mouse (false);
	(void)r_cons_readchar ();
	return 0;
}
Esempio n. 28
0
// XXX no control for max length here?!?!
R_API int r_cons_fgets(char *buf, int len, int argc, const char **argv) {
#define RETURN(x) { ret=x; goto beach; }
    RCons *cons = r_cons_singleton ();
    int ret = 0, color = cons->pal.input && *cons->pal.input;
#if 0
    int mouse = r_cons_enable_mouse (R_FALSE);
    r_cons_enable_mouse (R_FALSE);
    r_cons_flush ();
#endif
    if (cons->user_fgets) {
        RETURN (cons->user_fgets (buf, len));
    }
    *buf = '\0';
    fflush (cons->fdin);
    if (color) {
        const char *p = cons->pal.input;
        int len = p? strlen (p): 0;
        if (len>0)
            fwrite (p, len, 1, stdout);
        fflush (stdout);
    }
    if (fgets (buf, len, cons->fdin) == NULL) {
        if (color) {
            printf (Color_RESET);
            fflush (stdout);
        }
        RETURN (-1);
    }
    if (feof (cons->fdin)) {
        if (color) printf (Color_RESET);
        RETURN (-2);
    }
    buf[strlen (buf)-1] = '\0';
    if (color) printf (Color_RESET);
    ret = strlen (buf);
beach:
    //r_cons_enable_mouse (mouse);
    return ret;
}
Esempio n. 29
0
/* final entrypoint for adding stuff in the buffer screen */
R_API int r_cons_memcat(const char *str, int len) {
	if (len < 0 || (I.buffer_len + len) < 0) {
		return -1;
	}
	if (I.echo) {
		write (2, str, len);
	}
	if (str && len > 0 && !I.null) {
		if (palloc (len + 1)) {
			memcpy (I.buffer + I.buffer_len, str, len);
			I.buffer_len += len;
			I.buffer[I.buffer_len] = 0;
		}
	}
	if (I.flush) {
		r_cons_flush ();
	}
	if (I.break_word && str) {
		if (r_mem_mem ((const ut8*)str, len, (const ut8*)I.break_word, I.break_word_len)) {
			I.breaked = true;
		}
	}
	return len;
}
Esempio n. 30
0
File: core.c Progetto: 0x2F/radare2
R_API void r_core_cmd_flush (RCore *core) {
	// alias
	r_cons_flush ();
}