* Implement static plugins for r_io

- Prefix all plugins with 'io_' (like in the rest of libs)
  - Statify io_dbg and io_ptrace IO plugins
* Added _free methods for r_io and r_debug. Oops
* Initial dummy version of r_debug.vapi
* More stuff in the debug/t/main.c (not yet working)
* Better hg-miss missing file detection checks

--HG--
rename : libr/io/p/dbg.c => libr/io/p/io_dbg.c
rename : libr/io/p/ewf.c => libr/io/p/io_ewf.c
rename : libr/io/p/malloc.c => libr/io/p/io_malloc.c
rename : libr/io/p/ptrace.c => libr/io/p/io_ptrace.c
rename : libr/io/p/shm.c => libr/io/p/io_shm.c
This commit is contained in:
pancake 2009-08-22 03:11:33 +00:00
parent 8bf75e93d6
commit 6c28274aa0
22 changed files with 192 additions and 53 deletions

View file

@ -7,7 +7,7 @@ foo: pre libr_asm.so plugins
include ../config.mk
include ${STATIC_ASM_PLUGINS}
STATIC_OBJS=$(subst ..,p/..,$(subst asm_,p/asm_,$(STATIC_OBJ)))
OBJ=asm.o ${STATIC_OBJS}
OBJ=${STATIC_OBJS} asm.o
pre:
@if [ ! -e libr_asm.so ]; then rm -f ${STATIC_OBJS} ; fi

View file

@ -43,4 +43,9 @@
&r_debug_plugin_ptrace, \
0
#define R_IO_STATIC_PLUGINS \
&r_io_plugin_dbg, \
&r_io_plugin_ptrace, \
0
#endif

View file

@ -13,6 +13,7 @@ STATIC_ASM_PLUGINS=p/x86olly.mk p/x86nasm.mk p/mips.mk p/java.mk
STATIC_PARSE_PLUGINS=p/dummy.mk p/x86_pseudo.mk p/mreplace.mk
STATIC_BIN_PLUGINS=p/elf.mk p/elf64.mk p/pe.mk p/pe64.mk p/java.mk p/dummy.mk
STATIC_BP_PLUGINS=p/x86.mk
STATIC_IO_PLUGINS=p/ptrace.mk p/dbg.mk
STATIC_BININFO_PLUGINS=p/addr2line.mk
STATIC_DEBUG_PLUGINS=p/ptrace.mk

View file

@ -16,13 +16,10 @@ R_API int r_debug_init(struct r_debug_t *dbg)
return R_TRUE;
}
R_API void r_debug_set_io(struct r_debug_t *dbg,
int (*_read)(void *user, int pid, ut64 addr, ut8 *buf, int len),
int (*_write)(void *user, int pid, ut64 addr, const ut8 *buf, int len),
void *user)
R_API int r_debug_set_io(struct r_debug_t *dbg, CB_READ, CB_WRITE, void *user)
{
dbg->read = _read;
dbg->write = _write;
dbg->read = _cb_read;
dbg->write = _cb_write;
dbg->user = user;
}
@ -34,6 +31,13 @@ R_API struct r_debug_t *r_debug_new()
return dbg;
}
R_API struct r_debug_t *r_debug_free(struct r_debug_t *dbg)
{
// TODO: free it correctly
free(dbg);
return NULL;
}
R_API int r_debug_attach(struct r_debug_t *dbg, int pid)
{
int ret = R_FALSE;
@ -49,8 +53,6 @@ R_API int r_debug_attach(struct r_debug_t *dbg, int pid)
R_API int r_debug_startv(struct r_debug_t *dbg, int argc, char **argv)
{
if (dbg->h && dbg->h->startv)
return dbg->h->startv(pid);
return R_FALSE;
}

View file

@ -1,5 +1,6 @@
#include <r_util.h>
#include <r_debug.h>
#include <r_io.h>
int main(int argc, char **argv)
{
@ -7,8 +8,18 @@ int main(int argc, char **argv)
struct r_io_t *io = r_io_new();
struct r_dbg_t *dbg;
dbg = r_debug_new();
io = r_io_new();
printf("Supported IO pluggins:\n");
r_io_handle_list(io);
ret = r_io_open(io, "dbg:///bin/ls", 0, 0);
printf("r_io_open dbg:///bin/ls' = %s\n", r_str_bool(ret));
if (!ret) {
printf("Cannot open dbg:///bin/ls\n");
goto beach;
}
dbg = r_debug_new();
printf("Supported debugger backends:\n");
r_debug_handle_list (dbg);
@ -25,5 +36,7 @@ int main(int argc, char **argv)
r_debug_continue (dbg);
beach:
r_io_free(io);
r_debug_free(dbg);
return 0;
}

View file

@ -102,12 +102,13 @@ R_API int r_debug_handle_add(struct r_debug_t *dbg, struct r_debug_handle_t *foo
R_API int r_debug_handle_set(struct r_debug_t *dbg, const char *str);
R_API int r_debug_handle_init(struct r_debug_t *dbg);
R_API int r_debug_init(struct r_debug_t *dbg);
R_API struct r_debug_t *r_debug_new();
R_API struct r_debug_t *r_debug_free(struct r_debug_t *dbg);
// TODO:
R_API void r_debug_set_io(struct r_debug_t *dbg,
int (*read)(void *user, int pid, ut64 addr, ut8 *buf, int len),
int (*write)(void *user, int pid, ut64 addr, const ut8 *buf, int len),
void *user);
#define CB_READ int (*_cb_read)(void *user, int pid, ut64 addr, ut8 *buf, int len)
#define CB_WRITE int (*_cb_write)(void *user, int pid, ut64 addr, const ut8 *buf, int len)
R_API int r_debug_set_io(struct r_debug_t *dbg, CB_READ, CB_WRITE, void *user);
/* send signals */
R_API int r_debug_kill(struct r_debug_t *dbg, int pid, int sig);

View file

@ -80,6 +80,7 @@ struct r_io_list_t {
/* io/handle.c */
struct r_io_t *r_io_new();
R_API struct r_io_t *r_io_free(struct r_io_t *io);
int r_io_handle_init(struct r_io_t *io);
int r_io_handle_open(struct r_io_t *io, int fd, struct r_io_handle_t *plugin);
int r_io_handle_close(struct r_io_t *io, int fd, struct r_io_handle_t *plugin);
@ -140,4 +141,14 @@ void r_io_section_init(struct r_io_t *io);
int r_io_section_overlaps(struct r_io_t *io, struct r_io_section_t *s);
ut64 r_io_section_align(struct r_io_t *io, ut64 addr, ut64 vaddr, ut64 paddr);
#if 0
#define CB_READ int (*cb_read)(struct r_io_t *user, int pid, ut64 addr, ut8 *buf, int len)
#define CB_WRITE int (*cb_write)(struct r_io_t *user, int pid, ut64 addr, const ut8 *buf, int len)
#define CB_IO int (*cb_io)(void *user, CB_READ, CB_WRITE)
R_API int r_io_hook(struct r_io_t *io, CB_IO);
#endif
/* plugins */
struct r_io_handle_t r_io_plugin_dbg;
struct r_io_handle_t r_io_plugin_ptrace;
#endif

View file

@ -1,5 +1,23 @@
NAME=r_io
OBJ=io.o handle.o map.o section.o
CFLAGS+=-Wall
DEPS=r_lib
#DEPS=r_util
CFLAGS+=-Wall -DCORELIB
foo: pre libr_io.so tests plugins
include ../config.mk
include ${STATIC_DEBUG_PLUGINS}
STATIC_OBJS=$(subst ..,p/..,$(subst io_,p/io_,$(STATIC_OBJ)))
OBJ=${STATIC_OBJS} io.o handle.o map.o section.o
pre:
@echo STATICOBJS: ${STATIC_OBJS}
@if [ ! -e libr_io.so ]; then rm -f ${STATIC_OBJS} ; fi
tests:
cd t && ${MAKE} all
plugins:
cd p && ${MAKE} all
include ../rules.mk

View file

@ -3,28 +3,36 @@
/* TODO: write li->fds setter/getter helpers */
#include "r_io.h"
#include "../config.h"
#include "list.h"
#include <stdio.h>
static struct r_io_handle_t *io_static_plugins[] =
{ R_IO_STATIC_PLUGINS };
int r_io_handle_init(struct r_io_t *io)
{
int i;
INIT_LIST_HEAD(&io->io_list);
/* load default IO plugins here */
return 0;
for(i=0;io_static_plugins[i];i++)
r_io_handle_add (io, io_static_plugins[i]);
return R_TRUE;
}
int r_io_handle_add(struct r_io_t *io, struct r_io_handle_t *plugin)
{
int i;
struct r_io_list_t *li;
if (plugin == NULL)
return R_FALSE;
li = MALLOC_STRUCT(struct r_io_list_t);
if (li == NULL)
return -1;
return R_FALSE;
li->plugin = plugin;
for(i=0;i<R_IO_NFDS;i++)
li->plugin->fds[i] = -1;
list_add_tail(&(li->list), &(io->io_list));
return 0;
return R_TRUE;
}
struct r_io_handle_t *r_io_handle_resolve(struct r_io_t *io, const char *filename)

View file

@ -4,7 +4,7 @@
#include "r_util.h"
#include <stdio.h>
int r_io_init(struct r_io_t *io)
R_API int r_io_init(struct r_io_t *io)
{
io->write_mask_fd = -1;
io->last_align = 0;
@ -15,21 +15,27 @@ int r_io_init(struct r_io_t *io)
return 0;
}
struct r_io_t *r_io_new()
R_API struct r_io_t *r_io_new()
{
struct r_io_t *io = MALLOC_STRUCT(struct r_io_t);
r_io_init(io);
return io;
}
int r_io_redirect(struct r_io_t *io, const char *file)
R_API struct r_io_t *r_io_free(struct r_io_t *io)
{
free(io);
return NULL;
}
R_API int r_io_redirect(struct r_io_t *io, const char *file)
{
free(io->redirect);
io->redirect = file?strdup(file):NULL;
return 0;
}
int r_io_open(struct r_io_t *io, const char *file, int flags, int mode)
R_API int r_io_open(struct r_io_t *io, const char *file, int flags, int mode)
{
const char *uri = strdup(file);
struct r_io_handle_t *plugin;
@ -196,3 +202,19 @@ int r_io_close(struct r_io_t *io, int fd)
}
return close(fd);
}
#if 0
// define callback for other APIs to use with current io
static int _cb_read(struct r_io_t *io, int pid, ut64 addr, ut8 *buf, int len)
{
}
static int _cb_write(struct r_io_t *io, int pid, ut64 addr, const ut8 *buf, int len)
{
}
R_API int r_io_hook(struct r_io_t *io, CB_IO)
{
return cb_io(user, _cb_read, _cb_write
}
#endif

View file

@ -1,23 +1,20 @@
CFLAGS=-I../../include -Wall -DWORDSIZE=64
BINDEPS=
CFLAGS=-I../../include -Wall -DWORDSIZE=64 -fPIC -shared -Wl,-R..
all: io_ptrace.so io_dbg.so io_malloc.so io_shm.so
foo: all
ALL_TARGETS=
DEBUGS=ptrace.mk dbg.mk malloc.mk shm.mk
include ${DEBUGS}
#ALL_TARGETS+=io_ewf.so
all: ${ALL_TARGETS}
@true
io_malloc.so: malloc.o
${CC} ${CFLAGS} -fPIC -shared -o io_malloc.so malloc.c
BINDEPS=
io_ptrace.so: ptrace.o
${CC} ${CFLAGS} -fPIC -shared -o io_ptrace.so ptrace.c
io_dbg.so: dbg.o
${CC} ${CFLAGS} -fPIC -shared -o io_dbg.so dbg.c -lr_io -L../../io -Wl,-R..
io_shm.so: shm.o
${CC} ${CFLAGS} -fPIC -shared -o io_shm.so shm.c -lr_io -L../../io -Wl,-R..
io_ewf.so: ewf.o
${CC} ${CFLAGS} -fPIC -shared -o io_ewf.so ewf.c -lr_io -L../../io -Wl,-R..
io_ewf.so: io_ewf.o
${CC} ${CFLAGS} -fPIC -shared -o io_ewf.so ewf.c -lr_io -L../../io -Wl,-R.. -lewf
clean:
-rm -f *.so *.o

11
libr/io/p/dbg.mk Normal file
View file

@ -0,0 +1,11 @@
include ../../../config-user.mk
OBJ_DBG=io_dbg.o
STATIC_OBJ+=${OBJ_DBG}
TARGET_DBG=io_dbg.so
ALL_TARGETS+=${TARGET_DBG}
${TARGET_DBG}: ${OBJ_DBG}
${CC} ${CFLAGS} -o ${TARGET_DBG} ${OBJ_DBG}

View file

@ -4,6 +4,7 @@
#include <r_io.h>
#include <r_lib.h>
#include <r_util.h>
#include <signal.h>
#include <sys/ptrace.h>
#include <sys/types.h>
@ -129,16 +130,16 @@ static int __init(struct r_io_t *io)
return R_TRUE;
}
static struct r_io_handle_t r_io_plugin_dbg = {
struct r_io_handle_t r_io_plugin_dbg = {
//void *handle;
.name = "dbg",
.name = "io_dbg",
.desc = "Debug a program or pid. dbg:///bin/ls, dbg://1388",
.open = __open,
.handle_open = __handle_open,
.handle_fd = __handle_fd,
.lseek = NULL,
.system = NULL,
.debug = 1,
.debug = (void *)1,
.init = __init,
//void *widget;
/*
@ -148,9 +149,11 @@ static struct r_io_handle_t r_io_plugin_dbg = {
*/
};
#ifndef CORELIB
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_IO,
.data = &r_io_plugin_dbg
};
#endif
#endif

View file

@ -170,7 +170,7 @@ static int ewf__init(struct r_io_t *io)
return R_TRUE;
}
static struct r_io_handle_t r_io_plugin_ewf = {
struct r_io_handle_t r_io_plugin_ewf = {
//void *handle;
.name = "ewf",
.desc = "Forensic file formats (Encase, ..) (ewf://file, els://file)",
@ -185,8 +185,10 @@ static struct r_io_handle_t r_io_plugin_ewf = {
.write = ewf__write,
};
#ifndef CORELIB
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_IO,
.data = &r_io_plugin_ewf
};
#endif
#endif

View file

@ -107,9 +107,9 @@ static int __system(struct r_io_t *io, int fd, const char *cmd)
return 0;
}
static struct r_io_handle_t r_io_plugin_malloc = {
struct r_io_handle_t r_io_plugin_malloc = {
//void *handle;
.name = "malloc",
.name = "io_malloc",
.desc = "memory allocation ( malloc://size-in-bytes )",
.open = __open,
.close = __close,
@ -128,7 +128,9 @@ static struct r_io_handle_t r_io_plugin_malloc = {
*/
};
#ifndef CORELIB
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_IO,
.data = &r_io_plugin_malloc
};
#endif

View file

@ -236,7 +236,7 @@ static int __init(struct r_io_t *io)
// TODO: rename ptrace to io_ptrace .. err io.ptrace ??
struct r_io_handle_t r_io_plugin_ptrace = {
//void *handle;
.name = "ptrace",
.name = "io_ptrace",
.desc = "ptrace io",
.open = __open,
.close = __close,

View file

@ -92,9 +92,9 @@ static int shm__init(struct r_io_t *io)
return R_TRUE;
}
static struct r_io_handle_t r_io_plugin_shm = {
struct r_io_handle_t r_io_plugin_shm = {
//void *handle;
.name = "shm",
.name = "io_shm",
.desc = "shared memory resources (shm://key)",
.open = shm__open,
.close = shm__close,
@ -107,9 +107,11 @@ static struct r_io_handle_t r_io_plugin_shm = {
.write = shm__write,
};
#ifndef CORELIB
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_IO,
.data = &r_io_plugin_shm
};
#endif
#endif

10
libr/io/p/malloc.mk Normal file
View file

@ -0,0 +1,10 @@
include ../../../config-user.mk
OBJ_MALLOC=io_malloc.o
STATIC_OBJ+=${OBJ_MALLOC}
TARGET_MALLOC=io_malloc.so
ALL_TARGETS+=${TARGET_MALLOC}
${TARGET_MALLOC}: ${OBJ_MALLOC}
${CC} ${CFLAGS} -o ${TARGET_MALLOC} ${OBJ_MALLOC}

10
libr/io/p/ptrace.mk Normal file
View file

@ -0,0 +1,10 @@
include ../../../config-user.mk
OBJ_PTRACE=io_ptrace.o
STATIC_OBJ+=${OBJ_PTRACE}
TARGET_PTRACE=io_ptrace.so
ALL_TARGETS+=${TARGET_PTRACE}
${TARGET_PTRACE}: ${OBJ_PTRACE}
${CC} ${CFLAGS} -o ${TARGET_PTRACE} ${OBJ_PTRACE}

10
libr/io/p/shm.mk Normal file
View file

@ -0,0 +1,10 @@
include ../../../config-user.mk
OBJ_SHM=io_shm.o
STATIC_OBJ+=${OBJ_SHM}
TARGET_SHM=io_shm.so
ALL_TARGETS+=${TARGET_SHM}
${TARGET_SHM}: ${OBJ_SHM}
${CC} ${CFLAGS} -o ${TARGET_SHM} ${OBJ_SHM}

10
libr/vapi/r_debug.vapi Normal file
View file

@ -0,0 +1,10 @@
/* radare - LGPL - Copyright 2009 pancake<nopcode.org> */
[CCode (cheader_filename="r_debug.h", cprefix="r_debug", lower_case_cprefix="r_debug_")]
namespace Radare {
[Compact]
[CCode (cname="struct r_debug_t", free_function="r_debug_free", cprefix="r_debug_")]
public class Debug {
public Debug();
}
}

View file

@ -2,9 +2,10 @@
# Makefile helpers for mercurial
hg-miss:
@-hg st . | grep -e vala$$ -e mk$$ | grep ^? | grep -v config-user || true
@-hg st . | grep -e \\.c$$ | grep -v vapi | grep ^? || true
@-hg st . | grep -e \\.h$$ | grep -v vapi | grep ^? | grep -v r_userconf || true
@-hg st . | grep -e vala$$ -e mk$$ | grep ^? | grep -v config-user | cut -c 2- || true
@-hg st . | grep -e \\.c$$ -e \\.h$$ | grep -v vapi | grep ^? | grep -v r_userconf | cut -c 2- || true
@-hg st . | grep -e \\.vapi$$ | grep ^? | cut -c 2- || true
@-hg st . | grep -e \\.acr$$ | grep ^? | cut -c 2- || true
FILES?=
hg-locdiff: