Ejemplo n.º 1
0
Archivo: pp.c Proyecto: 0xroot/radare2
void cparsepp_file (const char *infile, const char *outfile) {
	FILE *in = r_sandbox_fopen (infile, "r");
	FILE *out = r_sandbox_fopen (outfile, "w");
	if (in && out)
		cparsepp_file_fd (in, out);
	fclose (in);
	fclose (out);
}
Ejemplo n.º 2
0
R_API int r_core_dump(RCore *core, const char *file, ut64 addr, ut64 size) {
	ut64 i;
	ut8 *buf;
	int bs = core->blocksize;
	FILE *fd;
	r_sys_truncate (file, 0);
	fd = r_sandbox_fopen (file, "wb");
	if (!fd) {
		eprintf ("Cannot open '%s' for writing\n", file);
		return R_FALSE;
	}
	buf = malloc (bs);
	r_cons_break (NULL, NULL);
	for (i=0; i<size; i+=bs) {
		if (r_cons_singleton ()->breaked)
			break;
		if ((i+bs)>size)
			bs = size-i;
		r_io_read_at (core->io, addr+i, buf, bs);
		if (fwrite (buf, bs, 1, fd) <1) {
			eprintf ("write error\n");
			break;
		}
	}
	eprintf ("dumped 0x%"PFMT64x" bytes\n", i);
	r_cons_break_end ();
	fclose (fd);
	free (buf);
	return R_TRUE;
}
Ejemplo n.º 3
0
R_API char *r_core_project_info(RCore *core, const char *prjfile) {
	char buf[256], *file = NULL, *prj = r_core_project_file (core, prjfile);
	FILE *fd = prj? r_sandbox_fopen (prj, "r"): NULL;
	for (;fd;) {
		fgets (buf, sizeof (buf), fd);
		if (feof (fd))
			break;
		if (!memcmp (buf, "\"e file.path = ", 15)) {
			buf[strlen(buf)-2]=0;
			file = r_str_new (buf+15);
			break;
		}
		// TODO: deprecate before 1.0
		if (!memcmp (buf, "e file.path = ", 14)) {
			buf[strlen(buf)-1]=0;
			file = r_str_new (buf+14);
			break;
		}
	}
	if (fd) fclose (fd);
	r_cons_printf ("%s\n", prj);
	if (file) r_cons_printf ("FilePath: %s\n", file);
	free (prj);
	return file;
}
Ejemplo n.º 4
0
R_API void r_cons_flush() {
	const char *tee = I.teefile;
	if (I.noflush)
		return;
	r_cons_filter ();
	if (I.is_interactive) {
		/* Use a pager if the output doesn't fit on the terminal window. */
		if (I.pager && *(I.pager)
				&& I.buffer_len > 0
				&& r_str_char_count (I.buffer, '\n') >= I.rows) {
			I.buffer[I.buffer_len-1] = 0;
			r_sys_cmd_str_full(I.pager, I.buffer, NULL, NULL, NULL);
			r_cons_reset ();

		} else if (I.buffer_len > CONS_MAX_USER) {
			if (!r_cons_yesno ('n',"Do you want to print %d bytes? (y/N)",
					I.buffer_len)) {
				r_cons_reset ();
				return;
			}
		}
	}
	if (tee&&*tee) {
		FILE *d = r_sandbox_fopen (tee, "a+");
		if (d != NULL) {
			if (I.buffer_len != fwrite (I.buffer, 1, I.buffer_len, d))
				eprintf ("r_cons_flush: fwrite: error (%s)\n", tee);
			fclose (d);
		} else eprintf ("Cannot write on '%s'\n", tee);
	}
	// is_html must be a filter, not a write endpoint
	if (I.is_html) r_cons_html_print (I.buffer);
	else r_cons_write (I.buffer, I.buffer_len);
	r_cons_reset ();
}
Ejemplo n.º 5
0
R_API void r_log_file(const char *str) {
	FILE *fd = r_sandbox_fopen (logfile, "a+");
	if (fd) {
		fputs (str, fd);
		fclose (fd);
	} else eprintf ("ERR: Cannot open %s\n", logfile);
}
Ejemplo n.º 6
0
R_API void r_cons_flush() {
	const char *tee = I.teefile;
	if (I.noflush)
		return;
	if (I.null) {
		r_cons_reset ();
		return;
	}
	r_cons_filter ();
	if (I.is_interactive) {
		/* Use a pager if the output doesn't fit on the terminal window. */
		if (I.pager && *I.pager && I.buffer_len > 0
				&& r_str_char_count (I.buffer, '\n') >= I.rows) {
			I.buffer[I.buffer_len-1] = 0;
			r_sys_cmd_str_full (I.pager, I.buffer, NULL, NULL, NULL);
			r_cons_reset ();

		} else if (I.buffer_len > CONS_MAX_USER) {
#define COUNT_LINES 1
#if COUNT_LINES
			int i, lines = 0;
			for (i=0; I.buffer[i]; i++) {
				if (I.buffer[i]=='\n')
					lines ++;
			}
			if (lines>0 && !r_cons_yesno ('n',"Do you want to print %d lines? (y/N)", lines)) {
				r_cons_reset ();
				return;
			}
#else
			char buf[64];
			char *buflen = r_num_units (buf, I.buffer_len);
			if (buflen && !r_cons_yesno ('n',"Do you want to print %s chars? (y/N)", buflen)) {
				r_cons_reset ();
				return;
			}
#endif
			// fix | more | less problem
			r_cons_set_raw (1);
		}
	}
	if (tee && *tee) {
		FILE *d = r_sandbox_fopen (tee, "a+");
		if (d != NULL) {
			if (I.buffer_len != fwrite (I.buffer, 1, I.buffer_len, d))
				eprintf ("r_cons_flush: fwrite: error (%s)\n", tee);
			fclose (d);
		} else eprintf ("Cannot write on '%s'\n", tee);
	}
	r_cons_highlight (I.highlight);
	// is_html must be a filter, not a write endpoint
	if (I.is_html) r_cons_html_print (I.buffer);
	else r_cons_write (I.buffer, I.buffer_len);

	r_cons_reset ();
	if (I.newline) {
		eprintf ("\n");
		I.newline = false;
	}
}
Ejemplo n.º 7
0
R_API int r_syscall_setup_file(RSyscall *ctx, const char *path) {
	if (ctx->fd)
		fclose (ctx->fd);
	ctx->fd = r_sandbox_fopen (path, "r");
	if (ctx->fd == NULL)
		return 1;
	/* TODO: load info from file */
	return 0;
}
Ejemplo n.º 8
0
Archivo: cio.c Proyecto: f0829/radare2
R_API bool r_core_dump(RCore *core, const char *file, ut64 addr, ut64 size, int append) {
	ut64 i;
	ut8 *buf;
	int bs = core->blocksize;
	FILE *fd;
	if (append) {
		fd = r_sandbox_fopen (file, "ab");
	} else {
		r_sys_truncate (file, 0);
		fd = r_sandbox_fopen (file, "wb");
	}
	if (!fd) {
		eprintf ("Cannot open '%s' for writing\n", file);
		return false;
	}
	/* some io backends seems to be buggy in those cases */
	if (bs > 4096) {
		bs = 4096;
	}
	buf = malloc (bs);
	if (!buf) {
		eprintf ("Cannot alloc %d byte(s)\n", bs);
		fclose (fd);
		return false;
	}
	r_cons_break_push (NULL, NULL);
	for (i = 0; i < size; i += bs) {
		if (r_cons_is_breaked ()) {
			break;
		}
		if ((i + bs) > size) {
			bs = size - i;
		}
		r_io_read_at (core->io, addr + i, buf, bs);
		if (fwrite (buf, bs, 1, fd) < 1) {
			eprintf ("write error\n");
			break;
		}
	}
	r_cons_break_pop ();
	fclose (fd);
	free (buf);
	return true;
}
Ejemplo n.º 9
0
/// XXX wtf is this function for?
R_API int r_syscall_setup_file(RSyscall *s, const char *path) {
	if (s->fd) {
		fclose (s->fd);
	}
	s->fd = r_sandbox_fopen (path, "r");
	if (!s->fd) {
		return false;
	}
	/* TODO: load info from file */
	return true;
}
Ejemplo n.º 10
0
static int r_io_zip_check_file(const char *file) {
	int res = R_FALSE;
	ut8 buf[10];
	FILE * fp = r_sandbox_fopen (file, "rb");
	if (file && fp) {
		fread (buf, 1, 10, fp);
		if (!memcmp (buf, "\x50\x4b\x03\x04", 4))
			res = R_TRUE;
		fclose (fp);
	}
	return res;
}
Ejemplo n.º 11
0
static RFSFile* fs_posix_open(RFSRoot *root, const char *path) {
	FILE *fd;
	RFSFile *file = r_fs_file_new (root, path);
	file->ptr = NULL;
	file->p = root->p;
	fd = r_sandbox_fopen (path, "r");
	if (fd) {
		fseek (fd, 0, SEEK_END);
		file->size = ftell (fd);
		fclose (fd);
	} else {
		r_fs_file_free (file);
		file = NULL;
	}
	return file;
}
Ejemplo n.º 12
0
R_API char *r_core_project_info(RCore *core, const char *prjfile) {
	char buf[256], *file = NULL;
	char *prj = r_core_project_file (prjfile);
	FILE *fd;
	if (prj && (fd = r_sandbox_fopen (prj, "r"))) {
		for (;;) {
			fgets (buf, sizeof (buf), fd);
			if (feof (fd))
				break;
			if (!memcmp (buf, "e file.path = ", 14)) {
				buf[strlen(buf)-1]=0;
				file = r_str_new (buf+14);
				break;
			}
		}
		fclose (fd);
	}
	r_cons_printf ("Project : %s\n", prj);
	if (file)
		r_cons_printf ("FilePath: %s\n", file);
	free (prj);
	return file;
}
Ejemplo n.º 13
0
/*
 * Load and parse one file.
 */
static void load_1(RMagic *ms, int action, const char *file, int *errs, struct r_magic_entry **marray, ut32 *marraycount) {
	char line[BUFSIZ];
	size_t lineno = 0;
	FILE *f = r_sandbox_fopen (ms->file = file, "r");
	if (!f) {
		if (errno != ENOENT)
			file_error (ms, errno, "cannot read magic file `%s'", file);
		(*errs)++;
	} else {
		/* read and parse this file */
		for (ms->line = 1; fgets (line, sizeof (line), f) != NULL; ms->line++) {
			size_t len = strlen (line);
			if (len == 0) /* null line, garbage, etc */
				continue;
			if (line[len - 1] == '\n') {
				lineno++;
				line[len - 1] = '\0'; /* delete newline */
			}
			if (line[0] == '\0')	/* empty, do not parse */
				continue;
			if (line[0] == '#')	/* comment, do not parse */
				continue;
			if (len > mime_marker_len &&
			    memcmp (line, mime_marker, mime_marker_len) == 0) {
				/* MIME type */
				if (parse_mime (ms, marray, marraycount,
					       line + mime_marker_len) != 0)
					(*errs)++;
				continue;
			}
			if (parse (ms, marray, marraycount, line, lineno, action) != 0)
				(*errs)++;
		}
		fclose (f);
	}
}
Ejemplo n.º 14
0
R_API int r_core_patch (RCore *core, const char *patch) {
	char *p, *p2, *q, str[200], tmp[64];
	ut64 noff = 0LL;
	FILE *fd = r_sandbox_fopen (patch, "r");
	if (fd==NULL) {
		eprintf ("Cannot open patch file\n");
		return 1;
	}

	while (!feof (fd)) {
		fgets (str, sizeof (str), fd);
		if (*str=='#' || *str=='\n' || *str=='\r')
			continue;
		if (*str==':') {
			r_core_cmd0 (core, str+1);
			continue;
		}
		if (*str=='.' || *str=='!') {
			r_core_cmd0 (core, str);
			continue;
		}
		p = strchr (str+1, ' ');
		if (p) {
			*p = 0;
			for (++p; *p==' '; p++); // XXX: skipsspaces here
			switch (*p) {
			case '{': {
				char *s, *off = strdup (str);
				RBuffer *b = r_buf_new ();
				
				while (!feof (fd)) {
					fgets (str, sizeof (str), fd);
					if (*str=='}')
						break;
					if ((q=strstr (str, "${"))) {
						char *end = strchr (q+2,'}');
						if (end) {
							*q = *end = 0;
							noff = r_num_math (core->num, q+2);
							r_buf_append_bytes (b, (const ut8*)str, strlen (str));
							snprintf (tmp, sizeof (tmp), "0x%08"PFMT64x, noff);
							r_buf_append_bytes (b, (const ut8*)tmp, strlen (tmp));
							r_buf_append_bytes (b, (const ut8*)end+1, strlen (end+1));
						}
					} else r_buf_append_bytes (b, (const ut8*)str, strlen (str));
				}

				s = r_buf_to_string (b);
				r_egg_load (core->egg, s, 0);
				free (s);
			
				r_egg_compile (core->egg);
				r_egg_assemble (core->egg);

				r_buf_free (b);
				b = r_egg_get_bin (core->egg);

				if (strcmp (off, "+"))
					noff = r_num_math (core->num, off);
				r_core_write_at (core, noff, b->buf, b->length);
				noff += b->length;
				r_buf_free (b);
				free (off);
				}
				break;
			case '"':
				p2 = strchr (p+1,'"');
				if (p2) *p2=0;
				r_core_cmdf (core, "s %s", str);
				r_core_cmdf (core, "\"w %s\"", p+1);
				break;
			case ':':
				r_core_cmdf (core, "s %s", str);
				r_core_cmdf (core, "wa %s", p);
				break;
			default:
				r_core_cmdf (core, "s %s", str);
				r_core_cmdf (core, "wx %s", p);
				break;
			}
		}
	}
	fclose (fd);
	return 0;
}
Ejemplo n.º 15
0
static int cmd_project(void *data, const char *input) {
	RCore *core = (RCore *) data;
	const char *file, *arg = (input && *input)? input + 1: NULL;
	const char *fileproject = r_config_get (core->config, "prj.name");
	char *str = NULL;

	if (!input) {
		return false;
	}
	str = strdup (fileproject);
	arg = strchr (input, ' ');
	if (arg) {
		arg++;
	} else {
		if (*input) {
			arg = input + 1;
			if (*arg == '&') {
				arg++;
			}
		}
	}
	file = arg;
	switch (input[0]) {
	case 'c':
		if (input[1] == ' ') {
			r_core_project_cat (core, input + 2);
		} else {
			eprintf ("Usage: Pc [prjname]\n");
		}
		break;
	case 'o':
		//	if (r_file_is_regular (file))
		if (input[1] == '&') {
			r_core_project_open (core, file, true);
		} else if (input[1]) {
			r_core_project_open (core, file, false);
		} else {
			if (file && *file) {
				r_cons_println (file);
			}
		}
		break;
	case 'l':
		r_core_project_list (core, input[1]);
		break;
	case 'd':
	case '-':
		r_core_project_delete (core, file);
		break;
	case 's':
		if (!file || !file[0]) { /* if no argument specified use current project */
			file = str;
		}
		if (r_core_project_save (core, file)) {
			r_config_set (core->config, "prj.name", file);
			r_cons_println (file);
		}
		break;
	case 'S':
		if (input[1] == ' ') {
			r_core_project_save_rdb (core, input + 2, R_CORE_PRJ_ALL);
		} else {
			eprintf ("Usage: PS [file]\n");
		}
		break;
	case 'n':
		if (!fileproject || !*fileproject) {
			eprintf ("No project\n");
		} else {
			switch (input[1]) {
			case '-':
				/* remove lines containing specific words */
			{
				FILE *fd = r_sandbox_fopen (str, "w");
				if (!fd) {
					eprintf ("Cannot open %s\n", str);
				} else {
					char *str = r_core_project_notes_file (core, fileproject);
					char *data = r_file_slurp (str, NULL);
					int del = 0;
					if (data) {
						char *ptr, *nl;
						for (ptr = data; ptr; ptr = nl)  {
							nl = strchr (ptr, '\n');
							if (nl) {
								*nl++ = 0;
								if (strstr (ptr, input + 2)) {
									del++;
								} else {
									fprintf (fd, "%s\n", ptr);
								}
							}
						}
						free (data);
					}
					if (del > 0) {
						eprintf ("Deleted %d lines\n", del);
					}
					free (str);
					fclose (fd);
				}
			}
			break;
			case ' ':
				if (input[2] == '-') {
					char *str = r_core_project_notes_file (core, fileproject);
					// edit with cfg.editor
					const char *editor = r_config_get (core->config, "cfg.editor");
					if (str && *str && editor && *editor) {
						r_sys_cmdf ("%s %s", editor, str);
					} else {
						eprintf ("No cfg.editor configured\n");
					}
					free (str);
				} else {
					//char *str = r_core_project_notes_file (core, fileproject);
					// append line to project notes
					char *str = r_core_project_notes_file (core, fileproject);
					char *data = r_file_slurp (str, NULL);
					FILE *fd = r_sandbox_fopen (str, "a");
					if (fd) {
						fprintf (fd, "%s\n", input + 2);
						fclose (fd);
					}
					free (str);
					free (data);
				}
				break;
			case 'j':
				if (!input[2]) {
					int len = 0;
					/* get base64 string */
					char *str = r_core_project_notes_file (core, fileproject);
					if (str) {
						char *data = r_file_slurp (str, &len);
						char *res = r_base64_encode_dyn (data, len);
						if (res) {
							r_cons_println (res);
							free (res);
						}
						free (data);
						free (str);
					}
				} else if (input[2] == ' ') {
					/* set base64 string */
					ut8 *data = r_base64_decode_dyn (input + 3, -1);
					if (data) {
						char *str = r_core_project_notes_file (core, fileproject);
						if (str) {
							r_file_dump (str, data, strlen ((const char *) data), 0);
							free (str);
						}
						free (data);
					}
				} else {
					eprintf ("Usage: `Pnj` or `Pnj ...`\n");
				}
				break;
			case 'x':
				r_core_project_execute_cmds (core, fileproject);
				break;
			case 0:
			{
				char *str = r_core_project_notes_file (core, fileproject);
				char *data = r_file_slurp (str, NULL);
				if (data) {
					r_cons_println (data);
					free (data);
				}
				free (str);
			}
			break;
			case '?':
			{
				const char *help_msg[] = {
					"Usage:", "Pn[j-?] [...]", "Project Notes",
					"Pn", "", "show project notes",
					"Pn", " -", "edit notes with cfg.editor",
					"Pn-", "", "delete notes",
					"Pn-", "str", "delete lines matching /str/ in notes",
					"Pnx", "", "run project note commands",
					"Pnj", "", "show notes in base64",
					"Pnj", " [base64]", "set notes in base64",
					NULL
				};
				r_core_cmd_help (core, help_msg);
			}
			break;
			}
		}
		break;
	case 'i':
		if (file && *file) {
			char *prjName = r_core_project_info (core, file);
			r_cons_println (prjName);
			free (prjName);
		}
		break;
	default: {
		const char *help_msg[] = {
			"Usage:", "P[?osi] [file]", "Project management",
			"Pc", " [file]", "show project script to console",
			"Pd", " [file]", "delete project",
			"Pi", " [file]", "show project information",
			"Pl", "", "list all projects",
			"Pn", "[j]", "show project notes (Pnj for json)",
			"Pn", " [base64]", "set notes text",
			"Pn", " -", "edit notes with cfg.editor",
			"Po", " [file]", "open project",
			"Ps", " [file]", "save project",
			"PS", " [file]", "save script file",
			"P-", " [file]", "delete project (alias for Pd)",
			"NOTE:", "", "See 'e??prj.'",
			"NOTE:", "", "project are stored in ~/.config/radare2/projects",
			NULL
		};
		r_core_cmd_help (core, help_msg);
	}
		break;
	}
	free (str);
	return true;
}
Ejemplo n.º 16
0
static int cmd_project(void *data, const char *input) {
	RCore *core = (RCore *)data;
	const char *file, *arg = input+1;
	const char *fileproject = r_config_get (core->config, "file.project");
	char *str = strdup (fileproject);
	if (*arg==' ') arg++;
	file = input[1]?arg:str;
	switch (input[0]) {
	case 'c':
		if (!input[1]) {
			eprintf ("TODO: Show project saving script to console\n");
		} else if (input[1]==' ') {
			r_core_project_cat (core, input+2);
		} else eprintf ("Usage: Pc [prjname]\n");
		break;
	case 'o':
	//	if (r_file_is_regular (file))
		if (input[1]) {
			r_core_project_open (core, file);
		} else {
			if (file && *file)
				r_cons_printf ("%s\n", file);
		}
		break;
	case 'l':
		r_core_project_list (core, input[1]);
		break;
	case 'd':
		r_core_project_delete (core, file);
		break;
	case 's':
		if (r_core_project_save (core, file)) {
			r_config_set (core->config, "file.project", file);
			r_cons_printf ("%s\n", file);
		}
		break;
	case 'n':
		if (!fileproject || !*fileproject) {
			eprintf ("No project\n");
		} else
		switch (input[1]) {
		case '-':
			/* remove lines containing specific words */
			{
			char *str = r_core_project_notes_file (core, fileproject);
			char *data = r_file_slurp (str, NULL);
			FILE *fd = r_sandbox_fopen (str, "w");
			if (!fd) {
				eprintf ("Cannot open %s\n", str);
			} else {
				int del = 0;
				if (data) {
					char *ptr, *nl;
					for (ptr = data; ptr; ptr = nl)  {
						nl = strchr (ptr, '\n');
						if (nl) {
							*nl++ = 0;
							if (strstr (ptr, input+2)) {
								del ++;
							} else {
								fprintf (fd, "%s\n", ptr);
							}
						}
					}
					free (data);
				}
				fclose (fd);
				free (str);
				if (del>0) {
					eprintf ("Deleted %d lines\n", del);
				}
			}
			}
			break;
		case ' ':
			if (input[2]=='-') {
				char *str = r_core_project_notes_file (core, fileproject);
				// edit with cfg.editor
				const char *editor = r_config_get (core->config, "cfg.editor");
				if (str && *str && editor && *editor)
					r_sys_cmdf ("%s %s", editor, str);
				else eprintf ("No cfg.editor configured\n");
				free (str);
			} else {
				//char *str = r_core_project_notes_file (core, fileproject);
				// append line to project notes
				char *str = r_core_project_notes_file (core, fileproject);
				char *data = r_file_slurp (str, NULL);
				FILE *fd = r_sandbox_fopen (str, "a");
				if (fd) {
					fprintf (fd, "%s\n", input+2);
					fclose (fd);
				}
				free (str);
				free (data);
			}
			break;
		case 'j':
			if (!input[2]) {
				int len = 0;
				/* get base64 string */
				char *str = r_core_project_notes_file (core, fileproject);
				if (str) {
					char *data = r_file_slurp (str, &len);
					char *res = r_base64_encode_dyn (data, len);
					if (res) {
						r_cons_printf ("%s\n", res);
						free (res);
					}
					free (data);
					free (str);
				}
			} else if (input[2] == ' ') {
				/* set base64 string */
				ut8 *data = r_base64_decode_dyn (input+3, 0);
				if (data) {
					char *str = r_core_project_notes_file (core, fileproject);
					if (str) {
						r_file_dump (str, data, strlen ((const char*)data));
						free (str);
					}
					free (data);
				}
			} else {
				eprintf ("Usage: `Pnj` or `Pnj ...`\n");
			}
			break;
		case 0:
			{
			char *str = r_core_project_notes_file (core, fileproject);
			char *data = r_file_slurp (str, NULL);
			if (data) {
				r_cons_printf ("%s\n", data);
				free (data);
			}
			free (str);
			}
			break;
		case '?':
			{
				const char* help_msg[] = {
					"Usage:", "Pn[j-?] [...]", "Project Notes",
					"Pn", "", "show project notes",
					"Pn", " -", "edit notes with cfg.editor",
					"Pn-", "", "delete notes",
					"Pn-", "str", "delete lines matching /str/ in notes",
					"Pnj", "", "show notes in base64",
					"Pnj", " [base64]", "set notes in base64",
					NULL};
				r_core_cmd_help (core, help_msg);
			}
			break;
		}
		break;
	case 'i':
//		if (r_file_is_regular (file))
		free (r_core_project_info (core, file));
		break;
	default: {
		const char* help_msg[] = {
		"Usage:", "P[?osi] [file]", "Project management",
		"Pc", "", "show what will be saved in the project script",
		"Pc", " [file]", "show project script to console",
		"Pd", " [file]", "delete project",
		"Pi", " [file]", "show project information",
		"Pl", "", "list all projects",
		"Pn", "[j]", "show project notes (Pnj for json)",
		"Pn", " [base64]", "set notes text",
		"Pn", " -", "edit notes with cfg.editor",
		"Po", " [file]", "open project",
		"Ps", " [file]", "save project",
		"NOTE:", "", "See 'e file.project'",
		"NOTE:", "", "project files are stored in ~/.config/radare2/projects",
		NULL};
		r_core_cmd_help (core, help_msg);
		}
		break;
	}
	free (str);
	return R_TRUE;
}
Ejemplo n.º 17
0
static RIODesc *ewf__open(RIO *io, const char *pathname, int rw, int mode) {
	RIOEwf *rewf;
	libewf_handle_t *ewf_h;
	// XXX filename list should be dynamic. 1024 limit is ugly
	const char *filenames[1024];
	char *ptr,*optr;
	ut8 hash[1024];
	size64_t media_size;
	uint32_t bytes_per_sector;
	//uint64_t amount_of_sectors;
	uint32_t error_granularity;
	//uint32_t amount_of_acquiry_errors;
	int8_t compression_level;
	uint8_t media_type;
	uint8_t media_flags;
	uint8_t compress_empty_block;
	uint8_t format;
	int i;

	if (!memcmp (pathname, "els://", 6)) {
		FILE *fd = r_sandbox_fopen (pathname+6, "r");
		ut64 len;
		char *buf;

		if (fd == NULL)
			return NULL;
		fseek (fd, 0, SEEK_END);
		len = ftell (fd);
		fseek(fd, 0, SEEK_SET);
		buf = (char *)malloc (len);
		fread (buf, len, 1, fd);
		
		ptr = strchr (buf, '\n');
		for (i=0, optr = buf; ptr&&(ptr=strchr(ptr, '\n')); optr=ptr) {
			*ptr = '\0';
			ptr++;
			filenames[i++] = optr;
		}
		filenames[i] = NULL;

		free (buf);
		fclose (fd);

		for (i=0; filenames[i]; i++)
			eprintf ("%02x: %s)\n", i, filenames[i]);
	} else {
		filenames[0] = pathname + 6;
		filenames[1] = NULL;
	}
	libewf_handle_initialize (&ewf_h, NULL);
	if (libewf_handle_open (ewf_h, (char * const *)filenames, (int)1, rw?
			LIBEWF_OPEN_READ_WRITE: LIBEWF_OPEN_READ, NULL) != 1)
		return NULL;
#if 0
		if( ((libewf_internal_plugin_t*)ewf_h)->header_values == NULL ) {
			fprintf( stream, "\tNo information found in file.\n" );
		} else {
			libewf_get_header_value_examiner_name(ewf_h, hash, 128);
			eprintf("ExaminerName:     %s\n", hash);
			libewf_get_header_value_case_number(ewf_h, hash, 128);
			eprintf("CaseNumber:       %s\n", hash);
		}
#endif
	libewf_handle_get_format (ewf_h, &format, NULL);
	eprintf ("FormatVersion:    %d\n", format);
	libewf_handle_get_compression_values (ewf_h,
		&compression_level, &compress_empty_block, NULL);
	eprintf ("CompressionLevel: %d\n", compression_level);
	libewf_handle_get_error_granularity (ewf_h, &error_granularity, NULL);
	eprintf ("ErrorGranurality: %d\n", error_granularity);
	//libewf_handle_get_number_of_sectors (ewf_h, &amount_of_sectors, NULL);
	//eprintf ("AmountOfSectors:  %"PFMT64d"\n", amount_of_sectors);
	libewf_handle_get_bytes_per_sector (ewf_h, &bytes_per_sector, NULL);
	eprintf ("BytesPerSector:   %d\n", bytes_per_sector);
	libewf_handle_get_media_size (ewf_h, &media_size, NULL);
	eprintf ("MediaSize:        %"PFMT64d"\n", media_size);
	libewf_handle_get_media_type (ewf_h, &media_type, NULL);
	eprintf ("MediaType:        %d\n", media_type);
	libewf_handle_get_media_flags (ewf_h, &media_flags, NULL);
	eprintf ("MediaFlags:       %d\n", media_flags);
	libewf_handle_get_md5_hash (ewf_h, hash, 128, NULL);
	eprintf ("CalculatedHash:   %s\n", hash);

	rewf = R_NEW (RIOEwf);
	rewf->handle = ewf_h;
	rewf->fd = RIOEWF_TO_FD (rewf);
	return r_io_desc_new (&r_io_plugin_shm, rewf->fd, pathname, rw, mode, rewf);
}
Ejemplo n.º 18
0
R_API void r_cons_flush() {
	const char *tee = I.teefile;
	if (I.noflush) {
		return;
	}
	if (I.null) {
		r_cons_reset ();
		return;
	}
	r_cons_filter ();
	if (I.is_interactive && I.fdout == 1) {
		/* Use a pager if the output doesn't fit on the terminal window. */
		if (I.pager && *I.pager && I.buffer_len > 0
				&& r_str_char_count (I.buffer, '\n') >= I.rows) {
			I.buffer[I.buffer_len-1] = 0;
			r_sys_cmd_str_full (I.pager, I.buffer, NULL, NULL, NULL);
			r_cons_reset ();

		} else if (I.buffer_len > CONS_MAX_USER) {
#if COUNT_LINES
			int i, lines = 0;
			for (i = 0; I.buffer[i]; i++) {
				if (I.buffer[i] == '\n') {
					lines ++;
				}
			}
			if (lines > 0 && !r_cons_yesno ('n',"Do you want to print %d lines? (y/N)", lines)) {
				r_cons_reset ();
				return;
			}
#else
			char buf[64];
			char *buflen = r_num_units (buf, I.buffer_len);
			if (buflen && !r_cons_yesno ('n',"Do you want to print %s chars? (y/N)", buflen)) {
				r_cons_reset ();
				return;
			}
#endif
			// fix | more | less problem
			r_cons_set_raw (1);
		}
	}
	if (tee && *tee) {
		FILE *d = r_sandbox_fopen (tee, "a+");
		if (d) {
			if (I.buffer_len != fwrite (I.buffer, 1, I.buffer_len, d)) {
				eprintf ("r_cons_flush: fwrite: error (%s)\n", tee);
			}
			fclose (d);
		} else {
			eprintf ("Cannot write on '%s'\n", tee);
		}
	}
	r_cons_highlight (I.highlight);
	// is_html must be a filter, not a write endpoint
	if (I.is_html) {
		r_cons_html_print (I.buffer);
	} else {
		if (I.is_interactive && !r_sandbox_enable (false)) {
			if (I.linesleep > 0 && I.linesleep < 1000) {
				int i = 0;
				int pagesize = R_MAX (1, I.pagesize);
				char *ptr = I.buffer;
				char *nl = strchr (ptr, '\n');
				int len = I.buffer_len;
				I.buffer[I.buffer_len] = 0;
				r_cons_break_push (NULL, NULL);
				while (nl && !r_cons_is_breaked ()) {
					r_cons_write (ptr, nl - ptr + 1);
					if (!(i % pagesize)) {
						r_sys_usleep (I.linesleep * 1000);
					}
					ptr = nl + 1;
					nl = strchr (ptr, '\n');
					i++;
				}
				r_cons_write (ptr, I.buffer + len - ptr);
				r_cons_break_pop ();
			} else {
				r_cons_write (I.buffer, I.buffer_len);
			}
		} else {
			r_cons_write (I.buffer, I.buffer_len);
		}
	}

	r_cons_reset ();
	if (I.newline) {
		eprintf ("\n");
		I.newline = false;
	}
}