Exemplo n.º 1
0
static RIODesc *haret__open(struct r_io_t *io, const char *pathname, int rw, int mode) {
	char *port, *ptr, buf[1024];
	RSocket *s;

	strncpy (buf, pathname, sizeof (buf)-1);
	if (haret__plugin_open (io, pathname, 0)) {
		ptr = buf + 8;
		if (!(port = strchr (ptr, ':'))) {
			eprintf ("haret: wrong url\n");
			return NULL;
		}
		if (!r_sandbox_enable (0)) {
			eprintf ("sandbox: cannot use network\n");
			return NULL;
		}
		*port++ = 0;
		if ((s = r_socket_new (R_FALSE)) == NULL) {
			eprintf ("Cannot create new socket\n");
			return NULL;
		}
		if (!r_socket_connect_tcp (s, ptr, port, 30)) {
			eprintf ("Cannot connect to '%s' (%s)\n", ptr, port);
			return NULL;
		} else eprintf ("Connected to: %s at port %s\n", ptr, port);
		haret_wait_until_prompt (s);
		//return r_io_desc_new (&r_io_plugin_haret, s->fd, pathname, rw, mode, (void*)s);
		RETURN_IO_DESC_NEW (&r_io_plugin_haret, s->fd, pathname, rw, mode, (void*)s);
	}
	return NULL;
}
Exemplo n.º 2
0
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 = -2; /* causes r_io_desc_new() to set the correct fd */
		if (!memcmp (pathname, "hex://", 6)) {
			mal->size = strlen (pathname);
			mal->buf = malloc (mal->size);
			memset (mal->buf, 0, mal->size);
			mal->size = r_hex_str2bin (pathname+6, mal->buf);
		} else {
			mal->size = r_num_math (NULL, pathname+9);
			if ((mal->size)>0) {
				mal->buf = malloc (mal->size);
				memset (mal->buf, '\0', mal->size);
			} else {
				eprintf ("Cannot allocate (%s) 0 bytes\n", pathname+9);
				return NULL;
			}
		}
		if (mal->buf != NULL) {
			RETURN_IO_DESC_NEW(&r_io_plugin_malloc, mal->fd, pathname, rw, mode,mal);
			//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);
	}
	return NULL;
}
Exemplo n.º 3
0
static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) {
	if (__plugin_open (io, pathname, 0)) {
		const char *hostport = pathname + 6;
		RIOKdp *mal = R_NEW (RIOKdp);
		mal->fd = -2; /* causes r_io_desc_new() to set the correct fd */
		eprintf ("HOST:PORT = %s", hostport);
		//mal->sock = r_socket_new();
		mal->size = strlen (pathname);
		mal->buf = malloc (mal->size+1);
		mal->offset = 0;
		memset (mal->buf, 0, mal->size);
		mal->size = r_hex_str2bin (hostport, mal->buf);
		if ((int)mal->size<1) {
			free (mal->buf);
			mal->buf = NULL;
		}
		if (mal->buf != NULL) {
			RETURN_IO_DESC_NEW (&r_io_plugin_kdp,
				mal->fd, pathname, rw, mode,mal);
		}
		eprintf ("Cannot connect to %s\n", hostport);
		free (mal);
	}
	return NULL;
}
Exemplo n.º 4
0
static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) {
	if (__plugin_open (io, pathname,0)) {
		RIOSparse *mal = R_NEW0 (RIOSparse);
		mal->fd = -2; /* causes r_io_desc_new() to set the correct fd */
		int size = (int)r_num_math (NULL, pathname+9);
		mal->buf = r_buf_new_sparse ();
		if (size>0) {
			ut8 *data = malloc (size);
			if (!data) {
				eprintf ("Cannot allocate (%s) %d bytes\n",
					pathname+9, size);
				mal->offset = 0;
			} else {
				memset (data, 0x00, size);
				r_buf_write_at (mal->buf, 0, data, size);
				free (data);
			}
		}
		if (mal->buf) {
			RETURN_IO_DESC_NEW (&r_io_plugin_sparse,
				mal->fd, pathname, rw, mode, mal);
		}
		r_buf_free (mal->buf);
		free (mal);
	}
	return NULL;
}
Exemplo n.º 5
0
static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) {
	if (__plugin_open (io, pathname,0)) {
		RIOMalloc *mal = R_NEW (RIOMalloc);
		mal->fd = -2; /* causes r_io_desc_new() to set the correct fd */
		if (!strncmp (pathname, "hex://", 6)) {
			mal->size = strlen (pathname);
			mal->buf = malloc (mal->size+1);
			mal->offset = 0;
			memset (mal->buf, 0, mal->size);
			mal->size = r_hex_str2bin (pathname+6, mal->buf);
			if ((int)mal->size<1) {
				free (mal->buf);
				mal->buf = NULL;
			}
		} else {
			mal->size = r_num_math (NULL, pathname+9);
			if (((int)mal->size) <= 0) {
				free (mal);
				eprintf ("Cannot allocate (%s) 0 bytes\n", pathname+9);
				return NULL;
			}
			mal->offset = 0;
			mal->buf = calloc (1, mal->size+1);
		}
		if (mal->buf != NULL) {
			RETURN_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);
	}
	return NULL;
}
Exemplo n.º 6
0
static RIODesc *__open(struct r_io_t *io, const char *file, int rw, int mode) {
	if (__plugin_open (io, file, 0)) {
		char *pidpath;
		RIOW32Dbg *dbg = R_NEW (RIOW32Dbg);
		if (dbg == NULL)
			return NULL;
		dbg->pid = atoi (file+9);
		if (__attach (dbg) == -1) {
			free (dbg);
			return NULL;
		}
		pidpath = r_sys_pid_to_path (dbg->pid);
		RETURN_IO_DESC_NEW (&r_io_plugin_w32dbg, -1,
			pidpath, rw | R_IO_EXEC, mode, dbg);
	}
	return NULL;
}
Exemplo n.º 7
0
static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) {
	if (__plugin_open (io, pathname, 0)) {
		RIOGzip *mal = R_NEW0 (RIOGzip);
		if (!mal) return NULL;
		int len;
		ut8 *data = (ut8*)r_file_slurp (pathname+7, &len);
		mal->buf = r_inflate (data, len, NULL, &mal->size);
		if (mal->buf) {
			RETURN_IO_DESC_NEW (&r_io_plugin_malloc,
				mal->fd, pathname, rw, mode, mal);
		}
		free (data);
		eprintf ("Cannot allocate (%s) %d bytes\n", pathname+9,
			mal->size);
		free (mal);
	}
	return NULL;
}
Exemplo n.º 8
0
static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
	char host[128], *port, *p;
	RSocket *_fd;
	RIOGdb *riog;
	if (!__plugin_open (io, file, 0))
		return NULL;
	strncpy (host, file+6, sizeof (host)-1);
	port = strchr (host , ':');
	if (!port) {
		eprintf ("Port not specified. Please use gdb://[host]:[port]\n");
		return NULL;
	}
	*port = '\0';
	port++;
	p = strchr (port, '/');
	if (p) *p=0;

	if (r_sandbox_enable (0)) {
		eprintf ("sandbox: Cannot use network\n");
		return NULL;
	}
	_fd = r_socket_new (R_FALSE);
	if (_fd && r_socket_connect_tcp (_fd, host, port, 3)) {
		riog = R_NEW (RIOGdb);
		riog->fd = _fd;
		riog->desc = gdbwrap_init (_fd->fd, NUM_REGS, 4);
		if (!riog->desc) {
			r_socket_free (_fd);
			free (riog);
			return NULL;
		}
#if __WINDOWS__
		// XXX: bypass lazylinking
		RETURN_IO_DESC_NEW (&r_io_plugin_gdb, _fd->fd, file, rw, mode, riog);
#else
		return r_io_desc_new (&r_io_plugin_gdb, _fd->fd, file, rw, mode, riog);
#endif
	}
	eprintf ("gdb.io.open: Cannot connect to host.\n");
	return NULL;
}
Exemplo n.º 9
0
R_API RIODesc *r_io_desc_new(RIOPlugin *plugin, int fd, const char *name, int flags, int mode, void *data) {
	RETURN_IO_DESC_NEW (plugin, fd, name, flags, mode, data);
}