* Much more fixes for the new r_io

- r_io_malloc plugin is now working
  - r_io_size now accepts only one argument
* Fix nullptr bug in r_fs
This commit is contained in:
pancake 2011-01-21 00:21:32 +01:00
parent ed8d076cbe
commit bbda7ed61e
8 changed files with 38 additions and 25 deletions

2
TODO
View File

@ -5,7 +5,9 @@
<{include libr/TODO}>
* mount /mnt/ must chop last '/'
* jk in visual mode for disassembly print format must scroll by opcodes, not bytes
* "wx jeje" does not says "invalid hexpair string" (must report error)
* Add support for aout binaries?
* eprintf should be modified to log into a file

View File

@ -243,6 +243,8 @@ int main(int argc, char **argv) {
r_core_cmd (&r, "fo", 0);
r_cons_flush ();
}
// read current block
r_core_seek (&r, r.offset, 1);
/* XXX: find better solution.. files > 10MB does not hash */
#define SLURP_LIMIT (10*1024*1024)

View File

@ -3125,7 +3125,7 @@ static int cmd_open(void *data, const char *input) {
if (file) {
if (ptr) {
addr = r_num_math (core->num, ptr+1);
size = r_io_size (core->io, file->fd->fd);
size = r_io_size (core->io);
r_io_map_add (core->io, file->fd->fd, R_IO_READ, 0, addr, size);
eprintf ("Map '%s' in 0x%08"PFMT64x" with size 0x%"PFMT64x"\n",
input+1, addr, size);

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2010 pancake<nopcode.org> */
/* radare - LGPL - Copyright 2009-2011 pancake<nopcode.org> */
#include <r_core.h>
@ -198,7 +198,8 @@ R_API RCoreFile *r_core_file_open(RCore *r, const char *file, int mode) {
fh->filename = p+3;
fh->rwx = mode;
r->file = fh;
fh->size = r_io_size (r->io, fd->fd);
r->io->plugin = fd->plugin;
fh->size = r_io_size (r->io);
list_add (&(fh->list), &r->files);
// r_core_bin_load (r, fh->filename);

View File

@ -138,10 +138,12 @@ R_API int r_fs_read (RFS* fs, RFSFile *file, ut64 addr, int len) {
R_API RList *r_fs_dir(RFS* fs, const char *path) {
if (fs) {
RFSRoot *root = r_fs_root (fs, path);
const char *dir = path + strlen (root->path);
if (!*dir) dir = "/";
if (root)
return root->p->dir (root, dir);
if (root) {
const char *dir = path + strlen (root->path);
if (!*dir) dir = "/";
if (root)
return root->p->dir (root, dir);
}
eprintf ("r_fs_dir: error, path %s is not mounted\n", path);
}
return NULL;

View File

@ -197,7 +197,7 @@ R_API int r_io_write_at(RIO *io, ut64 addr, const ut8 *buf, int len);
R_API ut64 r_io_seek(RIO *io, ut64 offset, int whence);
R_API int r_io_system(RIO *io, const char *cmd);
R_API int r_io_close(RIO *io, RIODesc *fd);
R_API ut64 r_io_size(RIO *io, int fd);
R_API ut64 r_io_size(RIO *io); //, int fd);
R_API int r_io_resize(struct r_io_t *io, ut64 newsize);
/* io/cache.c */

View File

@ -116,7 +116,8 @@ R_API RIODesc *r_io_open(struct r_io_t *io, const char *file, int flags, int mod
#endif
}
if (fd >= 0) {
desc = r_io_desc_new (io->plugin, fd, file, flags, mode, io->plugin);
if (desc == NULL)
desc = r_io_desc_new (io->plugin, fd, file, flags, mode, NULL);
r_io_desc_add (io, desc);
r_io_set_fd (io, desc);
}
@ -283,16 +284,16 @@ R_API ut64 r_io_seek(struct r_io_t *io, ut64 offset, int whence) {
switch(whence) {
case R_IO_SEEK_SET:
posix_whence = SEEK_SET;
ret=offset;
ret=offset;
break;
case R_IO_SEEK_CUR:
// offset += io->off;
posix_whence = SEEK_CUR;
ret=offset+io->off;
ret=offset+io->off;
break;
case R_IO_SEEK_END:
//offset = UT64_MAX; // XXX: depending on io bits?
ret = UT64_MAX;
ret = UT64_MAX;
posix_whence = SEEK_END;
break;
}
@ -314,13 +315,13 @@ ret = UT64_MAX;
ret = (!io->debug && io->va && !list_empty (&io->sections))?
r_io_section_offset_to_vaddr (io, io->off) : io->off;
} else eprintf ("r_io_seek: cannot seek to %"PFMT64x"\n", offset);
} else eprintf ("r_io_seek: null fd\n");
} else { eprintf ("r_io_seek: null fd\n"); asm("int3"); }
return ret;
}
R_API ut64 r_io_size(RIO *io, int fd) {
R_API ut64 r_io_size(RIO *io) {
ut64 size, here;
r_io_set_fdn (io, fd);
//r_io_set_fdn (io, fd);
here = r_io_seek (io, 0, R_IO_SEEK_CUR);
size = r_io_seek (io, 0, R_IO_SEEK_END);
r_io_seek (io, here, R_IO_SEEK_SET);

View File

@ -12,9 +12,9 @@ typedef struct {
ut32 size;
} RIOMalloc;
#define RIOMALLOC_FD(x) (((RIOMalloc*)x)->fd)
#define RIOMALLOC_SZ(x) (((RIOMalloc*)x)->size)
#define RIOMALLOC_BUF(x) (((RIOMalloc*)x)->buf)
#define RIOMALLOC_FD(x) (((RIOMalloc*)x->data)->fd)
#define RIOMALLOC_SZ(x) (((RIOMalloc*)x->data)->size)
#define RIOMALLOC_BUF(x) (((RIOMalloc*)x->data)->buf)
static int __write(struct r_io_t *io, RIODesc *fd, const ut8 *buf, int count) {
if (fd == NULL || fd->data == NULL)
@ -35,9 +35,12 @@ static int __read(struct r_io_t *io, RIODesc *fd, ut8 *buf, int count) {
}
static int __close(RIODesc *fd) {
RIOMalloc *riom;
if (fd == NULL || fd->data == NULL)
return -1;
free (RIOMALLOC_BUF (fd));
riom = fd->data;
free (riom->buf);
riom->buf = NULL;
free (fd->data);
fd->data = NULL;
fd->state = R_IO_DESC_TYPE_CLOSED;
@ -58,18 +61,20 @@ static int __plugin_open(struct r_io_t *io, const char *pathname) {
}
static inline int getmalfd (RIOMalloc *mal) {
return (int)(size_t)mal->buf;
return 0xfffffff & (int)(size_t)mal->buf;
}
static RIODesc *__open(struct r_io_t *io, const char *pathname, int rw, int mode) {
if (__plugin_open (io, pathname)) {
RIOMalloc *mal = R_NEW (RIOMalloc);
mal->fd = getmalfd (mal);
mal->size = atoi (pathname+9) +1;
mal->buf = malloc (mal->size);
if (mal->buf != NULL) {
memset (mal->buf, '\0', mal->size);
return r_io_desc_new (&r_io_plugin_malloc, mal->fd, pathname, rw, mode, mal);
mal->size = atoi (pathname+9);
if ((mal->size)>0) {
mal->buf = malloc (mal->size);
if (mal->buf != NULL) {
memset (mal->buf, '\0', mal->size);
return r_io_desc_new (&r_io_plugin_malloc, mal->fd, pathname, rw, mode, mal);
}
}
eprintf ("Cannot allocate (%s) %d bytes\n", pathname+9, mal->size);
free (mal);