Fix #1670 - r2 -d 'ls -l /' working again

This commit is contained in:
pancake 2014-11-18 11:19:04 +01:00
parent 6a61fdfbd3
commit b1da2b30e3
2 changed files with 28 additions and 10 deletions

View File

@ -508,22 +508,34 @@ R_API int r_bin_load_io_at_offset_as_sz(RBin *bin, RIODesc *desc, ut64 baseaddr,
buf_bytes = NULL;
file_sz = iob->desc_size (io, desc);
if ((file_sz == 0 || file_sz == UT64_MAX) && is_debugger) {
int fail = 1;
/* get file path from desc name */
/* - asume path+exec have no space in path */
char *filepath, *foo = strdup (desc->name);
filepath = strchr (foo, ' ');
if (filepath) *filepath = 0;
filepath = r_file_path (foo);
// attempt a local open and read
// This happens when a plugin like debugger does not have a fixed size.
// if there is no fixed size or its MAXED, there is no way to definitively
// load the bin-properly. Many of the plugins require all content and are not
// stream based loaders
// NOTE: For RBin we dont need to open the file in read-write. This can be problematic
RIODesc *tdesc = iob->desc_open (io, desc->name, R_IO_READ, 0); //desc->flags, R_IO_READ);
if (!tdesc) return R_FALSE;
file_sz = iob->desc_size (io, tdesc);
if (file_sz == UT64_MAX) {
RIODesc *tdesc = iob->desc_open (io, filepath, R_IO_READ, 0); //desc->flags, R_IO_READ);
if (tdesc) {
file_sz = iob->desc_size (io, tdesc);
if (file_sz != UT64_MAX) {
sz = R_MIN (file_sz, sz);
buf_bytes = iob->desc_read (io, tdesc, &sz);
fail = 0;
}
iob->desc_close (io, tdesc);
return R_FALSE;
}
sz = R_MIN (file_sz, sz);
buf_bytes = iob->desc_read (io, tdesc, &sz);
iob->desc_close (io, tdesc);
free (foo);
free (filepath);
if (fail)
return R_FALSE;
} else if (sz != UT64_MAX) {
sz = R_MIN (file_sz, sz);
buf_bytes = iob->desc_read (io, desc, &sz);

View File

@ -558,8 +558,14 @@ R_API int r_run_start(RRunProfile *p) {
}
if (p->_program) {
if (!r_file_exists (p->_program)) {
eprintf ("rarun2: %s: file not found\n", p->_program);
return 1;
char *progpath = r_file_path (p->_program);
if (progpath && *progpath) {
free (p->_program);
p->_program = progpath;
} else {
eprintf ("rarun2: %s: file not found\n", p->_program);
return 1;
}
}
// XXX HACK close all non-tty fds
{ int i; for (i=3; i<10; i++) close (i); }