Skip to content

Commit

Permalink
Close radareorg#18305 ##IO
Browse files Browse the repository at this point in the history
  • Loading branch information
condret committed Jan 31, 2021
1 parent f80c847 commit 4b7e35d
Show file tree
Hide file tree
Showing 36 changed files with 104 additions and 104 deletions.
6 changes: 3 additions & 3 deletions libr/include/r_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ typedef struct r_io_plugin_t {
bool isdbg;
// int (*is_file_opened)(RIO *io, RIODesc *fd, const char *);
char *(*system)(RIO *io, RIODesc *fd, const char *);
RIODesc* (*open)(RIO *io, const char *, int perm, int mode);
RList* /*RIODesc* */ (*open_many)(RIO *io, const char *, int perm, int mode);
RIODesc* (*open)(RIO *io, struct r_io_plugin_t *plugin, const char *, int perm, int mode);
RList* /*RIODesc* */ (*open_many)(RIO *io, struct r_io_plugin_t *plugin, const char *, int perm, int mode);
int (*read)(RIO *io, RIODesc *fd, ut8 *buf, int count);
ut64 (*lseek)(RIO *io, RIODesc *fd, ut64 offset, int whence);
int (*write)(RIO *io, RIODesc *fd, const ut8 *buf, int count);
Expand All @@ -183,7 +183,7 @@ typedef struct r_io_plugin_t {
int (*extend)(RIO *io, RIODesc *fd, ut64 size);
bool (*accept)(RIO *io, RIODesc *desc, int fd);
int (*create)(RIO *io, const char *file, int mode, int type);
bool (*check)(RIO *io, const char *, bool many);
bool (*check)(RIO *io, struct r_io_plugin_t *plugin, const char *, bool many);
} RIOPlugin;

typedef struct r_io_map_t {
Expand Down
2 changes: 1 addition & 1 deletion libr/io/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ R_API RList* r_io_open_many(RIO* io, const char* uri, int perm, int mode) {
if (!plugin || !plugin->open_many || !plugin->close) {
return NULL;
}
if (!(desc_list = plugin->open_many (io, uri, perm, mode))) {
if (!(desc_list = plugin->open_many (io, plugin, uri, perm, mode))) {
return NULL;
}
r_list_foreach (desc_list, iter, desc) {
Expand Down
6 changes: 3 additions & 3 deletions libr/io/io_desc.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ R_API RIODesc *r_io_desc_open(RIO *io, const char *uri, int perm, int mode) {
if (!plugin || !plugin->open) {
return NULL;
}
RIODesc *desc = plugin->open (io, uri, perm, mode);
RIODesc *desc = plugin->open (io, plugin, uri, perm, mode);
if (!desc) {
return NULL;
}
Expand All @@ -135,10 +135,10 @@ R_API RIODesc *r_io_desc_open(RIO *io, const char *uri, int perm, int mode) {

R_API RIODesc *r_io_desc_open_plugin(RIO *io, RIOPlugin *plugin, const char *uri, int perm, int mode) {
r_return_val_if_fail (io && io->files && uri, NULL);
if (!plugin || !plugin->open || !plugin->check || !plugin->check (io, uri, false)) {
if (!plugin || !plugin->open || !plugin->check || !plugin->check (io, plugin, uri, false)) {
return NULL;
}
RIODesc *desc = plugin->open (io, uri, perm, mode);
RIODesc *desc = plugin->open (io, plugin, uri, perm, mode);
if (!desc) {
return NULL;
}
Expand Down
4 changes: 2 additions & 2 deletions libr/io/io_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ R_API bool r_io_plugin_init(RIO *io) {
}

R_API RIOPlugin *r_io_plugin_get_default(RIO *io, const char *filename, bool many) {
if (!default_plugin || !default_plugin->check || !default_plugin->check (io, filename, many) ) {
if (!default_plugin || !default_plugin->check || !default_plugin->check (io, default_plugin, filename, many) ) {
return NULL;
}
return (RIOPlugin*) default_plugin;
Expand All @@ -53,7 +53,7 @@ R_API RIOPlugin *r_io_plugin_resolve(RIO *io, const char *filename, bool many) {
if (!ret || !ret->check) {
continue;
}
if (ret->check (io, filename, many)) {
if (ret->check (io, ret, filename, many)) {
return ret;
}
}
Expand Down
8 changes: 4 additions & 4 deletions libr/io/p/io_ar.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static const char *r_io_get_individual_schema(const char *file) {
return NULL;
}

static bool r_io_ar_plugin_open(RIO *io, const char *file, bool many) {
static bool r_io_ar_plugin_open(RIO *io, RIOPlugin *plugin, const char *file, bool many) {
r_return_val_if_fail (io && file, NULL);
if (many) {
return (r_io_get_individual_schema (file) != NULL);
Expand All @@ -31,8 +31,8 @@ static int r_io_ar_close(RIODesc *fd) {
return ar_close ((RArFp *)fd->data);
}

static RIODesc *r_io_ar_open(RIO *io, const char *file, int rw, int mode) {
r_return_val_if_fail (r_io_ar_plugin_open (io, file, false), NULL);
static RIODesc *r_io_ar_open(RIO *io, RIOPlugin *plugin, const char *file, int rw, int mode) {
r_return_val_if_fail (r_io_ar_plugin_open (io, plugin, file, false), NULL);
const char *arname = strstr (file, "://") + 3;
char *filename = strstr (arname, "//");
if (filename) {
Expand Down Expand Up @@ -79,7 +79,7 @@ static int __io_ar_list(RArFp *arf, void *user) {
return 0; // continue
}

static RList *r_io_ar_open_many(RIO *io, const char *file, int rw, int mode) {
static RList *r_io_ar_open_many(RIO *io, RIOPlugin *plugin, const char *file, int rw, int mode) {
r_return_val_if_fail (io && file, NULL);
ar_many_data data;
if ((data.schema = r_io_get_individual_schema (file)) == NULL) {
Expand Down
6 changes: 3 additions & 3 deletions libr/io/p/io_bfdbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,17 @@ static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) {
return offset;
}

static bool __plugin_open(RIO *io, const char *pathname, bool many) {
static bool __plugin_open(RIO *io, RIOPlugin *plugin, const char *pathname, bool many) {
return (!strncmp (pathname, "bfdbg://", 8));
}

static inline int getmalfd (RIOBfdbg *mal) {
return 0xffff & (int)(size_t)mal->buf;
}

static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) {
static RIODesc *__open(RIO *io, RIOPlugin *plugin, const char *pathname, int rw, int mode) {
char *out;
if (__plugin_open (io, pathname, 0)) {
if (__plugin_open (io, plugin, pathname, 0)) {
RIOBind iob;
RIOBfdbg *mal = R_NEW0 (RIOBfdbg);
if (!mal) {
Expand Down
6 changes: 3 additions & 3 deletions libr/io/p/io_bochs.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ static libbochs_t *desc = NULL;
static RIODesc *riobochs = NULL;
extern RIOPlugin r_io_plugin_bochs; // forward declaration

static bool __plugin_open(RIO *io, const char *file, bool many) {
static bool __plugin_open(RIO *io, RIOPlugin *plugin, const char *file, bool many) {
return !strncmp (file, "bochs://", strlen ("bochs://"));
}

static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
static RIODesc *__open(RIO *io, RIOPlugin *plugin, const char *file, int rw, int mode) {
RIOBochs *riob;
lprintf("io_open\n");
const char *i;
char * fileBochs = NULL;
char * fileCfg = NULL;
int l;
if (!__plugin_open (io, file, 0)) {
if (!__plugin_open (io, plugin, file, 0)) {
return NULL;
}
if (r_sandbox_enable (false)) {
Expand Down
14 changes: 7 additions & 7 deletions libr/io/p/io_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ static int fork_and_ptraceme(RIO *io, int bits, const char *cmd) {
}
#endif

static bool __plugin_open(RIO *io, const char *file, bool many) {
static bool __plugin_open(RIO *io, RIOPlugin *plugin, const char *file, bool many) {
if (!strncmp (file, "waitfor://", 10)) {
return true;
}
Expand Down Expand Up @@ -477,7 +477,7 @@ static int get_pid_of(RIO *io, const char *procname) {
return -1;
}

static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
static RIODesc *__open(RIO *io, RIOPlugin *plugin, const char *file, int rw, int mode) {
RIOPlugin *_plugin;
RIODesc *ret = NULL;
char uri[128];
Expand All @@ -503,7 +503,7 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
snprintf (uri, sizeof (uri), "dbg://%d", target_pid);
file = uri;
}
if (__plugin_open (io, file, 0)) {
if (__plugin_open (io, plugin, file, 0)) {
const char *pidfile = file + 6;
char *endptr;
int pid = (int)strtol (pidfile, &endptr, 10);
Expand All @@ -521,7 +521,7 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
if (!_plugin || !_plugin->open) {
return NULL;
}
if ((ret = _plugin->open (io, uri, rw, mode))) {
if ((ret = _plugin->open (io, _plugin, uri, rw, mode))) {
RCore *c = io->corebind.core;
W32DbgWInst *wrap = (W32DbgWInst *)ret->data;
c->dbg->user = wrap;
Expand All @@ -532,23 +532,23 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
if (!_plugin || !_plugin->open || !_plugin->close) {
return NULL;
}
ret = _plugin->open (io, uri, rw, mode);
ret = _plugin->open (io, _plugin, uri, rw, mode);
#else
// TODO: use io_procpid here? faster or what?
sprintf (uri, "ptrace://%d", pid);
_plugin = r_io_plugin_resolve (io, (const char *)uri, false);
if (!_plugin || !_plugin->open) {
return NULL;
}
ret = _plugin->open (io, uri, rw, mode);
ret = _plugin->open (io, _plugin, uri, rw, mode);
#endif
} else {
sprintf (uri, "attach://%d", pid);
_plugin = r_io_plugin_resolve (io, (const char *)uri, false);
if (!_plugin || !_plugin->open) {
return NULL;
}
ret = _plugin->open (io, uri, rw, mode);
ret = _plugin->open (io, _plugin, uri, rw, mode);
#if __WINDOWS__
if (ret) {
RCore *c = io->corebind.core;
Expand Down
4 changes: 2 additions & 2 deletions libr/io/p/io_default.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,12 @@ static int r_io_def_mmap_truncate(RIOMMapFileObj *mmo, ut64 size) {
return res;
}

static bool __plugin_open_default(RIO *io, const char *file, bool many) {
static bool __plugin_open_default(RIO *io, RIOPlugin *plugin, const char *file, bool many) {
return r_io_def_mmap_check_default (file);
}

// default open should permit opening
static RIODesc *__open_default(RIO *io, const char *file, int perm, int mode) {
static RIODesc *__open_default(RIO *io, RIOPlugin *plugin, const char *file, int perm, int mode) {
if (r_io_def_mmap_check_default (file)) {
return r_io_def_mmap_open (io, file, perm, mode);
}
Expand Down
6 changes: 3 additions & 3 deletions libr/io/p/io_fd.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ static ut64 __lseek(RIO* io, RIODesc *desc, ut64 offset, int whence) {
return 0;
}

static bool __check(RIO *io, const char *pathname, bool many) {
static bool __check(RIO *io, RIOPlugin *plugin, const char *pathname, bool many) {
return !strncmp (pathname, FDURI, strlen (FDURI));
}

static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) {
static RIODesc *__open(RIO *io, RIOPlugin *plugin, const char *pathname, int rw, int mode) {
if (r_sandbox_enable (false)) {
eprintf ("Do not permit " FDURI " in sandbox mode.\n");
return NULL;
}
if (!__check (io, pathname, 0)) {
if (!__check (io, plugin, pathname, 0)) {
return NULL;
}
RIOFdata *fdd = R_NEW0 (RIOFdata);
Expand Down
6 changes: 3 additions & 3 deletions libr/io/p/io_gdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ typedef struct {
static int __close(RIODesc *fd);
static libgdbr_t *desc = NULL;

static bool __plugin_open(RIO *io, const char *file, bool many) {
static bool __plugin_open(RIO *io, RIOPlugin *plugin, const char *file, bool many) {
return (!strncmp (file, "gdb://", 6));
}

Expand Down Expand Up @@ -50,14 +50,14 @@ static int debug_gdb_write_at(const ut8 *buf, int sz, ut64 addr) {
return sz;
}

static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
static RIODesc *__open(RIO *io, RIOPlugin *plugin, const char *file, int rw, int mode) {
RIODesc *riogdb = NULL;
RIOGdb *riog;
char host[128], *port, *pid;
int i_port = -1;
bool isdev = false;

if (!__plugin_open (io, file, 0)) {
if (!__plugin_open (io, plugin, file, 0)) {
return NULL;
}
strncpy (host, file + 6, sizeof (host) - 1);
Expand Down
6 changes: 3 additions & 3 deletions libr/io/p/io_gprobe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1114,12 +1114,12 @@ static ut64 __lseek (RIO *io, RIODesc *fd, ut64 offset, int whence) {
return offset;
}

static bool __plugin_open (RIO *io, const char *pathname, bool many) {
static bool __plugin_open (RIO *io, RIOPlugin *plugin, const char *pathname, bool many) {
return pathname && r_str_startswith (pathname, "gprobe://") && strlen (pathname + strlen ("gprobe://"));
}

static RIODesc *__open (RIO *io, const char *pathname, int rw, int mode) {
if (__plugin_open (io, pathname, 0)) {
static RIODesc *__open (RIO *io, RIOPlugin *plugin, const char *pathname, int rw, int mode) {
if (__plugin_open (io, plugin, pathname, 0)) {
RIOGprobe *gprobe = R_NEW0 (RIOGprobe);

gprobe->offset = 0LL;
Expand Down
6 changes: 3 additions & 3 deletions libr/io/p/io_gzip.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ static ut64 __lseek(RIO* io, RIODesc *fd, ut64 offset, int whence) {
return r_offset;
}

static bool __plugin_open(RIO *io, const char *pathname, bool many) {
static bool __plugin_open(RIO *io, RIOPlugin *plugin, const char *pathname, bool many) {
return (!strncmp (pathname, "gzip://", 7));
}

static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) {
if (__plugin_open (io, pathname, 0)) {
static RIODesc *__open(RIO *io, RIOPlugin *plugin, const char *pathname, int rw, int mode) {
if (__plugin_open (io, plugin, pathname, 0)) {
RIOGzip *mal = R_NEW0 (RIOGzip);
if (!mal) {
return NULL;
Expand Down
6 changes: 3 additions & 3 deletions libr/io/p/io_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
#include <stdlib.h>
#include "../io_memory.h"

static bool __check(RIO *io, const char *pathname, bool many) {
static bool __check(RIO *io, RIOPlugin *plugin, const char *pathname, bool many) {
return (!strncmp (pathname, "http://", 7));
}

static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) {
if (__check (io, pathname, 0)) {
static RIODesc *__open(RIO *io, RIOPlugin *plugin, const char *pathname, int rw, int mode) {
if (__check (io, plugin, pathname, 0)) {
int rlen, code;
RIOMalloc *mal = R_NEW0 (RIOMalloc);
if (!mal) {
Expand Down
6 changes: 3 additions & 3 deletions libr/io/p/io_ihex.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ static ut64 __lseek(struct r_io_t *io, RIODesc *fd, ut64 offset, int whence) {
return io->off;
}

static bool __plugin_open(RIO *io, const char *pathname, bool many) {
static bool __plugin_open(RIO *io, RIOPlugin *plugin, const char *pathname, bool many) {
return (!strncmp (pathname, "ihex://", 7));
}

Expand Down Expand Up @@ -388,10 +388,10 @@ static bool ihex_parse(RBuffer *rbuf, char *str) {
return false;
}

static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) {
static RIODesc *__open(RIO *io, RIOPlugin *plugin, const char *pathname, int rw, int mode) {
Rihex *mal = NULL;
char *str = NULL;
if (__plugin_open (io, pathname, 0)) {
if (__plugin_open (io, plugin, pathname, 0)) {
str = r_file_slurp (pathname + 7, NULL);
if (!str) {
return NULL;
Expand Down
4 changes: 2 additions & 2 deletions libr/io/p/io_mach.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,11 @@ static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int len) {
return mach_write_at (io, fd, buf, len, io->off);
}

static bool __plugin_open(RIO *io, const char *file, bool many) {
static bool __plugin_open(RIO *io, RIOPlugin *plugin, const char *file, bool many) {
return (!strncmp (file, "attach://", 9) || !strncmp (file, "mach://", 7));
}

static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
static RIODesc *__open(RIO *io, RIOPlugin *plugin, const char *file, int rw, int mode) {
RIODesc *ret = NULL;
RIOMach *riom = NULL;
const char *pidfile;
Expand Down
6 changes: 3 additions & 3 deletions libr/io/p/io_malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
#include <stdlib.h>
#include "../io_memory.h"

static bool __check(RIO *io, const char *pathname, bool many) {
static bool __check(RIO *io, RIOPlugin *plugin, const char *pathname, bool many) {
return (!strncmp (pathname, "malloc://", 9)) || (!strncmp (pathname, "hex://", 6));
}

static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) {
if (__check (io, pathname, 0)) {
static RIODesc *__open(RIO *io, RIOPlugin *plugin, const char *pathname, int rw, int mode) {
if (__check (io, plugin, pathname, 0)) {
RIOMalloc *mal = R_NEW0 (RIOMalloc);
if (!mal) {
return NULL;
Expand Down
4 changes: 2 additions & 2 deletions libr/io/p/io_mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ static bool r_io_mmap_truncate(RIOMMapFileObj *mmo, ut64 size) {
}


static bool __plugin_open(RIO *io, const char *file, bool many) {
static bool __plugin_open(RIO *io, RIOPlugin *plugin, const char *file, bool many) {
return r_io_mmap_check (file);
}

static RIODesc *__open(RIO *io, const char *file, int flags, int mode) {
static RIODesc *__open(RIO *io, RIOPlugin *plugin, const char *file, int flags, int mode) {
if (!r_io_mmap_check (file)) {
return NULL;
}
Expand Down
6 changes: 3 additions & 3 deletions libr/io/p/io_null.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ static ut64 __lseek(RIO* io, RIODesc* fd, ut64 offset, int whence) {
return offset;
}

static bool __plugin_open(RIO* io, const char* pathname, bool many) {
static bool __plugin_open(RIO* io, RIOPlugin *plugin, const char* pathname, bool many) {
return (!strncmp (pathname, "null://", 7));
}

static RIODesc* __open(RIO* io, const char* pathname, int rw, int mode) {
static RIODesc* __open(RIO* io, RIOPlugin *plugin, const char* pathname, int rw, int mode) {
RIONull* null;
if (__plugin_open (io, pathname,0)) {
if (__plugin_open (io, plugin, pathname,0)) {
if (!strncmp (pathname, "null://", 7) && strlen (pathname + 7)) {
null = R_NEW0 (RIONull);
null->size = r_num_math (NULL, pathname + 7) + 1; //???
Expand Down
Loading

0 comments on commit 4b7e35d

Please sign in to comment.