cleanup rbufplug and make it a usual plugin

This commit is contained in:
condret 2017-08-19 22:42:04 +00:00
parent 64f7e2a93a
commit 45fb32a213
9 changed files with 48 additions and 42 deletions

View File

@ -638,13 +638,6 @@ int main(int argc, char **argv, char **envp) {
help++;
}
}
#if 0
{
RBuffer *buf = r_buf_new_with_string("Hello World");
r_core_file_open_desc (&r, buf, 7, 0);
r_core_block_read (&r);
}
#endif
if (noStderr) {
close (2);
}

View File

@ -761,23 +761,6 @@ R_API RCoreFile *r_core_file_open_many(RCore *r, const char *file, int flags, ut
return top_file;
}
R_API RCoreFile *r_core_file_open_desc(RCore *r, RBuffer *b, int flags, ut64 loadaddr) {
RIODesc *d = r_io_open_buffer (r->io, b);
if (d) {
RCoreFile *fh = R_NEW0 (RCoreFile);
if (fh) {
fh->alive = 1;
fh->core = r;
fh->desc = d;
r->file = fh;
r->io->plugin = d->plugin;
r_list_append (r->files, fh);
return fh;
}
}
return NULL;
}
/* loadaddr is r2 -m (mapaddr) */
R_API RCoreFile *r_core_file_open(RCore *r, const char *file, int flags, ut64 loadaddr) {
ut64 prev = r_sys_now ();

View File

@ -296,7 +296,6 @@ R_API int r_core_setup_debugger (RCore *r, const char *debugbackend, bool attach
R_API int r_core_files_free(const RCore *core, RCoreFile *cf);
R_API void r_core_file_free(RCoreFile *cf);
R_API RCoreFile *r_core_file_open(RCore *core, const char *file, int flags, ut64 loadaddr);
R_API RCoreFile *r_core_file_open_desc(RCore *r, RBuffer *b, int flags, ut64 loadaddr);
R_API RCoreFile *r_core_file_open_many(RCore *r, const char *file, int flags, ut64 loadaddr);
R_API RCoreFile *r_core_file_get_by_fd(RCore *core, int fd);
R_API int r_core_file_close(RCore *core, RCoreFile *fh);

View File

@ -276,7 +276,6 @@ R_API RIOPlugin *r_io_plugin_get_default(RIO *io, const char *filename, bool man
R_API int r_io_set_write_mask(RIO *io, const ut8 *buf, int len);
R_API RIODesc *r_io_open(RIO *io, const char *file, int flags, int mode); //opens a file with map at 0x0
R_API RIODesc *r_io_open_at (RIO *io, const char *file, int flags, int mode, ut64 maddr); //opens a file with map at maddr
R_API RIODesc *r_io_open_buffer(RIO *io, RBuffer *buf);
R_API RIODesc *r_io_open_nomap (RIO *io, const char *file, int flags, int mode); //opens a file without map -> only pread and pwrite can be used for access
R_API RList *r_io_open_many(RIO *io, const char *file, int flags, int mode);
R_API RIODesc *r_io_open_as(RIO *io, const char *urihandler, const char *file, int flags, int mode);
@ -498,6 +497,7 @@ extern RIOPlugin r_io_plugin_r2k;
extern RIOPlugin r_io_plugin_tcp;
extern RIOPlugin r_io_plugin_null;
extern RIOPlugin r_io_plugin_ar;
extern RIOPlugin r_io_plugin_rbuf;
#endif

View File

@ -5,7 +5,7 @@ DEPS+=r_util
DEPS+=r_socket
STATIC_OBJS=$(subst ..,p/..,$(subst io_,p/io_,$(STATIC_OBJ)))
OBJS=${STATIC_OBJS}
OBJS+=io.o plugin.o map.o section.o desc.o cache.o p_cache.o undo.o iobuf.o fd.o rbufplug.o
OBJS+=io.o plugin.o map.o section.o desc.o cache.o p_cache.o undo.o iobuf.o fd.o
CFLAGS+=-Wall -DCORELIB

View File

@ -15,7 +15,7 @@ endif
foo: all
ALL_TARGETS=
PLUGINS=ptrace.mk debug.mk gdb.mk malloc.mk shm.mk mach.mk w32dbg.mk procpid.mk windbg.mk bochs.mk qnx.mk r2k.mk ar.mk
PLUGINS=ptrace.mk debug.mk gdb.mk malloc.mk shm.mk mach.mk w32dbg.mk procpid.mk windbg.mk bochs.mk qnx.mk r2k.mk ar.mk rbuf.mk
#zip.mk
#PLUGINS=ptrace.mk debug.mk gdb.mk malloc.mk mach.mk w32dbg.mk procpid.mk
include ${PLUGINS}

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2017 - pancake */
/* radare2 - LGPL - Copyright 2017 - pancake, condret */
#include "r_io.h"
#include "r_lib.h"
@ -31,23 +31,36 @@ static ut64 __lseek(RIO* io, RIODesc *fd, ut64 offset, int whence) {
return r_buf_seek (buf, offset, whence);
}
static bool __check(RIO *io, const char *pathname, bool many) {
return (!strncmp (pathname, "rbuf://", 7));
}
static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) {
RIODesc *desc;
RBuffer *buf = r_buf_new ();
if (buf && (desc = r_io_desc_new (io, &r_io_plugin_rbuf, pathname, 7, 0, buf))) {
return desc;
}
r_buf_free (buf);
return NULL;
}
RIOPlugin r_io_plugin_rbuf = {
.name = "rbuf",
.desc = "Internal RBuffer IO plugin",
.license = "MIT",
.desc = "RBuffer IO plugin: rbuf://",
.license = "LGPL",
.open = __open,
.close = __close,
.read = __read,
.lseek = __lseek,
.write = __write
.write = __write,
.check = __check
};
R_API RIODesc *r_io_open_buffer(RIO *io, RBuffer *buf) {
RIODesc *desc = r_io_desc_new (io, &r_io_plugin_rbuf, "rbuf", 7, 0, buf);
if (desc) {
r_io_map_new (io, desc->fd, 7, 0, 0, r_buf_size (buf));
r_io_desc_add (io, desc);
r_io_use_desc (io, desc);
}
return desc;
}
#ifndef CORELIB
RLibStruct radare_plugin = {
.type = R_LIB_TYPE_IO,
.data = &r_io_plugin_rbuf,
.version = R2_VERSION
};
#endif

17
libr/io/p/rbuf.mk Normal file
View File

@ -0,0 +1,17 @@
OBJ_RBUF=io_rbuf.o
STATIC_OBJ+=${OBJ_RBUF}
TARGET_RBUF=io_rbuf.${EXT_SO}
ALL_TARGETS+=${TARGET_RBUF}
ifeq (${WITHPIC},0)
LINKFLAGS+=../../util/libr_util.a
LINKFLAGS+=../../io/libr_io.a
else
LINKFLAGS+=-L../../util -lr_util
LINKFLAGS+=-L.. -lr_io
endif
${TARGET_RBUF}: ${OBJ_RBUF}
${CC_LIB} $(call libname,io_rbuf) ${CFLAGS} -o ${TARGET_RBUF} \
${LDFLAGS} ${OBJ_RBUF} ${LINKFLAGS}

View File

@ -223,6 +223,7 @@ io.windbg
io.zip
io.r2k
io.ar
io.rbuf
lang.vala
parse.m68k_pseudo
parse.6502_pseudo