* Huge build system refactoring

- Make proper use of the config-user.mk
  - Accelerate build by manually checking timestamps of bin/lib to objs/srcs
  - Use '-MD' by default
  - Lot of minor fixups done in multiple places
  - Fix PREFIX/LIBDIR installation/loading problems for plugins
  - Some segfaults has been fixed
  - Use R_API in r_core and r_lib
* Add 'vm' to be build by libr by default
* Add 'libs.c' in core/ to manage plugins from core
  - Added 'dir.plugins'
  - Make '-e' and '-L' radare2 flags work
  - Plugins are not loaded multiple times now
* Added r_lib_types string array containing plugin types strings
* Minor fixups in r_debug
  - Properly check 'contsc' delegate
  - Separate r_debug_wait()
* Rename dbg-ptrace into dbg_ptrace

--HG--
rename : libr/debug/p/dbg-ptrace.c => libr/debug/p/dbg_ptrace.c
This commit is contained in:
pancake 2009-04-01 00:28:13 +00:00
parent c4421c3c7f
commit d41e40ba05
24 changed files with 290 additions and 223 deletions

View file

@ -1,4 +1,4 @@
include config.mk
include config-user.mk
all:
cd libr && make

View file

@ -2,3 +2,14 @@
PREFIX=@PREFIX@
HAVE_LIB_EWF=@HAVE_LIB_EWF@
# TODO: add configure flag to choose compiler
COMPILER=gcc
STATIC_DEBUG=0
RUNTIME_DEBUG=1
# TODO: add flag to choose ostype
OSTYPE?=gnulinux
-include ../config.mk
-include ../../config.mk

View file

@ -1,15 +1,15 @@
VERSION=0.2b
RELEASE=0
DESTDIR=
OSTYPE=gnulinux
OSTYPE?=gnulinux
COMPILER=gcc
COMPILER?=gcc
#COMPILER=tcc
# verbose error messages everywhere
STATIC_DEBUG=0
# getenv("LIBR_RTDEBUG");
RUNTIME_DEBUG=1
RUNTIME_DEBUG?=1
ifeq (${RELEASE},1)
PREFIX=/usr/local
@ -18,4 +18,6 @@ PREFIX=${PWD}/prefix
VERSION=`date '+%Y%m%d'`
endif
LIBDIR=${PREFIX}/lib
-include config-user.mk

View file

@ -1,10 +1,12 @@
PREFIX=${PWD}/../prefix
include ../config-user.mk
PREFIX?=${PWD}/../prefix
DESTDIR?=../
PFX=${DESTDIR}${PREFIX}
#PREFIX=${PFX}
# Libraries
LIBLIST=io util lib meta lang flags bin bininfo macro hash line cons line print config syscall range socket cmd asm anal parse search diff debug reg core var sign trace
LIBLIST=io util lib meta lang flags bin bininfo macro hash line cons line print config syscall range socket cmd asm anal parse search diff debug reg core var sign trace vm
# Under development
#LIBLIST+=print
@ -16,6 +18,8 @@ LIBLIST=io util lib meta lang flags bin bininfo macro hash line cons line print
#LIBAR=libr.a
all:
echo PREFIX=${PREFIX}
#exit 1
for lib in ${LIBLIST}; do ( cd $${lib} && ${MAKE} all ); done
@echo Build done for: ${LIBLIST}

View file

@ -1,4 +1,4 @@
include ../../../config.mk
include ../../../config-user.mk
OBJ_ARM=asm_arm.o
OBJ_ARM+=../arch/arm/gnu/arm-dis.o

View file

@ -6,7 +6,7 @@ foo: pre libr_bin.so plugins
CFLAGS+=-DCORELIB -Iformat
#XXX
CFLAGS+=-D__UNIX__=1 -DLIL_ENDIAN=1
include ../config.mk
include ../config-user.mk
include ${STATIC_BIN_PLUGINS}
STATIC_OBJS=$(subst ..,p/..,$(subst bin_,p/bin_,$(STATIC_OBJ)))
OBJ=bin.o ${STATIC_OBJS}

View file

@ -6,7 +6,7 @@ foo: pre libr_bininfo.so plugins
CFLAGS+=-DCORELIB -Iformat
#XXX
CFLAGS+=-D__UNIX__=1 -DLIL_ENDIAN=1
include ../config.mk
include ../config-user.mk
include ${STATIC_BININFO_PLUGINS}
STATIC_OBJS=$(subst ..,p/..,$(subst bininfo_,p/bininfo_,$(STATIC_OBJ)))
OBJ=bininfo.o ${STATIC_OBJS}

View file

@ -14,9 +14,11 @@ STATIC_BIN_PLUGINS=p/elf.mk
STATIC_BININFO_PLUGINS=p/addr2line.mk
ifneq (${BINDEPS},)
include ../../../config-user.mk
include ../../../config.mk
include ../../../mk/${COMPILER}.mk
else
include ../../config-user.mk
include ../../config.mk
include ../../mk/${COMPILER}.mk
endif

View file

@ -245,13 +245,8 @@ void r_cons_grep(const char *str)
}
}
/* TODO: refactorize and move grep stuff outside here */
void r_cons_flush()
{
FILE *fd;
char buf[1024];
int i,j;
int lines_counter = 0;
char *tee = r_cons_teefile;
if (r_cons_noflush)
@ -272,60 +267,11 @@ void r_cons_flush()
fwrite(r_cons_buffer, strlen(r_cons_buffer), 1, d);
fclose(d);
}
// TODO: make this 'write' portable
} else write(1, r_cons_buffer, r_cons_buffer_len);
// TODO: make 'write' portable
r_cons_reset();
return;
#if 0
char *file = r_cons_filterline;
if (!STR_IS_NULL(file)) {
fd = fopen(file, "r");
if (fd) {
while(!feof(fd)) {
buf[0]='\0';
fgets(buf, 1020, fd);
if (buf[0]) {
buf[strlen(buf)-1]='\0';
char *ptr = strchr(buf, '\t');;
if (ptr) {
ptr[0]='\0'; ptr = ptr +1;
r_cons_buffer = (char *)r_str_sub(r_cons_buffer, buf, ptr, 1);
r_cons_buffer_len = strlen(r_cons_buffer);
}
}
}
fclose(fd);
}
}
#endif
}
#if 0
// UNUSED
/* stream is ignored */
void r_cons_fprintf(FILE *stream, const char *format, ...)
{
/* dupped */
int len;
char buf[CONS_BUFSZ];
va_list ap;
va_start(ap, format);
len = vsnprintf(buf, CONS_BUFSZ-1, format, ap);
if (len>0) {
len = strlen(buf);
palloc(len);
memcpy(r_cons_buffer+r_cons_buffer_len, buf, len+1);
r_cons_buffer_len += len;
}
va_end(ap);
}
#endif
void r_cons_printf(const char *format, ...)
{
int len;

View file

@ -1,6 +1,8 @@
NAME=r_core
DEPS=r_config r_cons r_line r_io r_cmd r_util r_print r_flags r_asm r_lib r_macro r_debug r_hash r_bin r_lang r_io r_asm r_anal r_parse r_config r_macro r_print r_bininfo
OBJ=core.o cmd.o file.o config.o visual.o io.o yank.o
OBJ=core.o cmd.o file.o config.o visual.o io.o yank.o libs.o
CFLAGS+=-DLIBDIR=\"${PREFIX}/lib\"
include ../rules.mk

View file

@ -52,6 +52,7 @@ int r_core_config_init(struct r_core_t *core)
r_config_set_cb(cfg, "asm.parser", "x86_pseudo",
&config_asm_parser_callback);
r_config_set(cfg, "dir.plugins", LIBDIR"/radare/");
r_config_set(cfg, "asm.syntax", "intel");
r_config_set_i(cfg, "asm.bits", 32);
r_config_set(cfg, "asm.pseudo", "false"); // DEPRECATED ???
@ -287,7 +288,6 @@ int r_core_config_init(struct r_core_t *core)
}
config_set("dir.spcc", ptr);
config_set("dir.plugins", LIBDIR"/radare/");
snprintf(buf, 1023, "%s/.radare/rdb/", getenv("HOME"));
config_set("dir.project", buf); // ~/.radare/rdb/
config_set("dir.tmp", get_tmp_dir());

View file

@ -24,99 +24,14 @@ static u64 num_callback(void *userptr, const char *str, int *ok)
return 0LL;
}
struct r_core_t *r_core_new()
R_API struct r_core_t *r_core_new()
{
struct r_core_t *c = MALLOC_STRUCT(struct r_core_t);
r_core_init(c);
return c;
}
/* TODO: move to a separated file */
/* io callback */
static int __lib_io_cb(struct r_lib_plugin_t *pl, void *user, void *data)
{
struct r_io_handle_t *hand = (struct r_io_handle_t *)data;
struct r_core_t *core = (struct r_core_t *)user;
//printf(" * Added IO handler\n");
r_io_handle_add(&core->io, hand);
return R_TRUE;
}
static int __lib_io_dt(struct r_lib_plugin_t *pl, void *p, void *u) { return R_TRUE; }
/* debug callback */
static int __lib_dbg_cb(struct r_lib_plugin_t *pl, void *user, void *data)
{
struct r_debug_handle_t *hand = (struct r_debug_handle_t *)data;
struct r_core_t *core = (struct r_core_t *)user;
//printf(" * Added debugger handler\n");
r_debug_handle_add(&core->dbg, hand);
return R_TRUE;
}
static int __lib_dbg_dt(struct r_lib_plugin_t *pl, void *p, void *u) { return R_TRUE; }
/* lang callback */
static int __lib_lng_cb(struct r_lib_plugin_t *pl, void *user, void *data)
{
struct r_lang_handle_t *hand = (struct r_lang_handle_t *)data;
struct r_core_t *core = (struct r_core_t *)user;
//printf(" * Added language handler\n");
r_lang_add(&core->lang, hand);
return R_TRUE;
}
static int __lib_lng_dt(struct r_lib_plugin_t *pl, void *p, void *u) { return R_TRUE; }
/* anal callback */
static int __lib_anl_cb(struct r_lib_plugin_t *pl, void *user, void *data)
{
struct r_anal_handle_t *hand = (struct r_anal_handle_t *)data;
struct r_core_t *core = (struct r_core_t *)user;
//printf(" * Added analysis handler\n");
r_anal_add(&core->anal, hand);
return R_TRUE;
}
static int __lib_anl_dt(struct r_lib_plugin_t *pl, void *p, void *u) { return R_TRUE; }
/* asm callback */
static int __lib_asm_cb(struct r_lib_plugin_t *pl, void *user, void *data)
{
struct r_asm_handle_t *hand = (struct r_asm_handle_t *)data;
struct r_core_t *core = (struct r_core_t *)user;
//printf(" * Added (dis)assembly handler\n");
r_asm_add(&core->assembler, hand);
return R_TRUE;
}
static int __lib_asm_dt(struct r_lib_plugin_t *pl, void *p, void *u) { return R_TRUE; }
/* parse callback */
static int __lib_parse_cb(struct r_lib_plugin_t *pl, void *user, void *data)
{
struct r_parse_handle_t *hand = (struct r_parse_handle_t *)data;
struct r_core_t *core = (struct r_core_t *)user;
//printf(" * Added (dis)assembly handler\n");
r_parse_add(&core->parser, hand);
return R_TRUE;
}
static int __lib_parse_dt(struct r_lib_plugin_t *pl, void *p, void *u) { return R_TRUE; }
/* bin callback */
static int __lib_bin_cb(struct r_lib_plugin_t *pl, void *user, void *data)
{
struct r_bin_handle_t *hand = (struct r_bin_handle_t *)data;
struct r_core_t *core = (struct r_core_t *)user;
//printf(" * Added (dis)assembly handler\n");
r_bin_add(&core->bin, hand);
return R_TRUE;
}
static int __lib_bin_dt(struct r_lib_plugin_t *pl, void *p, void *u) { return R_TRUE; }
int r_core_init(struct r_core_t *core)
R_API int r_core_init(struct r_core_t *core)
{
core->oobi = NULL;
core->oobi_len = 0;
@ -125,6 +40,8 @@ int r_core_init(struct r_core_t *core)
core->yank_off = 0LL;
core->num.callback = &num_callback;
core->num.userptr = core;
/* initialize libraries */
r_print_init(&core->print);
core->print.printf = r_cons_printf;
r_lang_init(&core->lang);
@ -141,6 +58,7 @@ int r_core_init(struct r_core_t *core)
r_bin_set_user_ptr(&core->bin, core);
r_meta_init(&core->meta);
r_cons_init();
core->search = r_search_new(R_SEARCH_KEYWORD);
r_io_init(&core->io);
r_macro_init(&core->macro);
@ -155,33 +73,16 @@ int r_core_init(struct r_core_t *core)
r_core_cmd_init(core);
r_flag_init(&core->flags);
r_debug_init(&core->dbg);
r_lib_init(&core->lib, "radare_plugin");
r_lib_add_handler(&core->lib, R_LIB_TYPE_IO, "io plugins",
&__lib_io_cb, &__lib_io_dt, core);
r_lib_add_handler(&core->lib, R_LIB_TYPE_DBG, "debug plugins",
&__lib_dbg_cb, &__lib_dbg_dt, core);
r_lib_add_handler(&core->lib, R_LIB_TYPE_LANG, "language plugins",
&__lib_lng_cb, &__lib_lng_dt, core);
r_lib_add_handler(&core->lib, R_LIB_TYPE_ANAL, "analysis plugins",
&__lib_anl_cb, &__lib_anl_dt, core);
r_lib_add_handler(&core->lib, R_LIB_TYPE_ASM, "(dis)assembly plugins",
&__lib_asm_cb, &__lib_asm_dt, core);
r_lib_add_handler(&core->lib, R_LIB_TYPE_PARSE, "parsing plugins",
&__lib_parse_cb, &__lib_parse_dt, core);
r_lib_add_handler(&core->lib, R_LIB_TYPE_BIN, "bin plugins",
&__lib_bin_cb, &__lib_bin_dt, core);
r_lib_opendir(&core->lib, getenv("LIBR_PLUGINS"));
{
char *homeplugindir = r_str_home(".radare/plugins");
r_lib_opendir(&core->lib, homeplugindir);
free(homeplugindir);
}
r_core_config_init(core);
// XXX fix path here
/* load plugins */
r_core_loadlibs(core);
return 0;
}
struct r_core_t *r_core_free(struct r_core_t *c)
R_API struct r_core_t *r_core_free(struct r_core_t *c)
{
free(c);
return NULL;

124
libr/core/libs.c Normal file
View file

@ -0,0 +1,124 @@
/* radare - LGPL - Copyright 2009 pancake<nopcode.org> */
#include "r_core.h"
/* io callback */
static int __lib_io_cb(struct r_lib_plugin_t *pl, void *user, void *data)
{
struct r_io_handle_t *hand = (struct r_io_handle_t *)data;
struct r_core_t *core = (struct r_core_t *)user;
//printf(" * Added IO handler\n");
r_io_handle_add(&core->io, hand);
return R_TRUE;
}
static int __lib_io_dt(struct r_lib_plugin_t *pl, void *p, void *u) { return R_TRUE; }
/* debug callback */
static int __lib_dbg_cb(struct r_lib_plugin_t *pl, void *user, void *data)
{
struct r_debug_handle_t *hand = (struct r_debug_handle_t *)data;
struct r_core_t *core = (struct r_core_t *)user;
//printf(" * Added debugger handler\n");
r_debug_handle_add(&core->dbg, hand);
return R_TRUE;
}
static int __lib_dbg_dt(struct r_lib_plugin_t *pl, void *p, void *u) { return R_TRUE; }
/* lang callback */
static int __lib_lng_cb(struct r_lib_plugin_t *pl, void *user, void *data)
{
struct r_lang_handle_t *hand = (struct r_lang_handle_t *)data;
struct r_core_t *core = (struct r_core_t *)user;
//printf(" * Added language handler\n");
r_lang_add(&core->lang, hand);
return R_TRUE;
}
static int __lib_lng_dt(struct r_lib_plugin_t *pl, void *p, void *u) { return R_TRUE; }
/* anal callback */
static int __lib_anl_cb(struct r_lib_plugin_t *pl, void *user, void *data)
{
struct r_anal_handle_t *hand = (struct r_anal_handle_t *)data;
struct r_core_t *core = (struct r_core_t *)user;
//printf(" * Added analysis handler\n");
r_anal_add(&core->anal, hand);
return R_TRUE;
}
static int __lib_anl_dt(struct r_lib_plugin_t *pl, void *p, void *u) { return R_TRUE; }
/* asm callback */
static int __lib_asm_cb(struct r_lib_plugin_t *pl, void *user, void *data)
{
struct r_asm_handle_t *hand = (struct r_asm_handle_t *)data;
struct r_core_t *core = (struct r_core_t *)user;
//printf(" * Added (dis)assembly handler\n");
r_asm_add(&core->assembler, hand);
return R_TRUE;
}
static int __lib_asm_dt(struct r_lib_plugin_t *pl, void *p, void *u) { return R_TRUE; }
/* parse callback */
static int __lib_parse_cb(struct r_lib_plugin_t *pl, void *user, void *data)
{
struct r_parse_handle_t *hand = (struct r_parse_handle_t *)data;
struct r_core_t *core = (struct r_core_t *)user;
//printf(" * Added (dis)assembly handler\n");
r_parse_add(&core->parser, hand);
return R_TRUE;
}
static int __lib_parse_dt(struct r_lib_plugin_t *pl, void *p, void *u) { return R_TRUE; }
/* bin callback */
static int __lib_bin_cb(struct r_lib_plugin_t *pl, void *user, void *data)
{
struct r_bin_handle_t *hand = (struct r_bin_handle_t *)data;
struct r_core_t *core = (struct r_core_t *)user;
//printf(" * Added (dis)assembly handler\n");
r_bin_add(&core->bin, hand);
return R_TRUE;
}
static int __lib_bin_dt(struct r_lib_plugin_t *pl, void *p, void *u) { return R_TRUE; }
R_API int r_core_loadlibs_init(struct r_core_t *core)
{
/* initialize handlers */
r_lib_init(&core->lib, "radare_plugin");
r_lib_add_handler(&core->lib, R_LIB_TYPE_IO, "io plugins",
&__lib_io_cb, &__lib_io_dt, core);
r_lib_add_handler(&core->lib, R_LIB_TYPE_DBG, "debug plugins",
&__lib_dbg_cb, &__lib_dbg_dt, core);
r_lib_add_handler(&core->lib, R_LIB_TYPE_LANG, "language plugins",
&__lib_lng_cb, &__lib_lng_dt, core);
r_lib_add_handler(&core->lib, R_LIB_TYPE_ANAL, "analysis plugins",
&__lib_anl_cb, &__lib_anl_dt, core);
r_lib_add_handler(&core->lib, R_LIB_TYPE_ASM, "(dis)assembly plugins",
&__lib_asm_cb, &__lib_asm_dt, core);
r_lib_add_handler(&core->lib, R_LIB_TYPE_PARSE, "parsing plugins",
&__lib_parse_cb, &__lib_parse_dt, core);
r_lib_add_handler(&core->lib, R_LIB_TYPE_BIN, "bin plugins",
&__lib_bin_cb, &__lib_bin_dt, core);
return R_TRUE;
}
R_API int r_core_loadlibs(struct r_core_t *core)
{
char *homeplugindir = r_str_home(".radare/plugins");
static int singleton = R_TRUE;
if (singleton) {
r_core_loadlibs_init(core);
singleton = R_FALSE;
}
r_lib_opendir(&core->lib, r_config_get(&core->config, "dir.plugins"));
r_lib_opendir(&core->lib, getenv("LIBR_PLUGINS"));
r_lib_opendir(&core->lib, homeplugindir);
r_lib_opendir(&core->lib, LIBDIR"/radare2/");
free(homeplugindir);
return R_TRUE;
}

View file

@ -1,6 +1,7 @@
OBJ=radare2.o
BIN=radare2
BINDEPS=r_core r_cons r_macro r_util r_flags r_lib r_io r_hash r_cmd r_config r_asm r_anal r_parse r_lang r_debug r_print r_line r_bin r_search r_meta r_bininfo
BINDEPS=r_core r_cons r_macro r_util r_flags r_lib r_io r_hash r_cmd r_config r_asm
BINDEPS+=r_anal r_parse r_lang r_debug r_print r_line r_bin r_search r_meta r_bininfo
#LIBS=-lr_core -L..
### shared
@ -57,6 +58,5 @@ LIBS+=-ldl
../../macro/*.a \
../../debug/*.a \
../../hash/*.a
LIBS+=-ldl
include ../../rules.mk

View file

@ -47,7 +47,7 @@ int main(int argc, char **argv)
r_core_init (&r);
while ((c = getopt (argc, argv, "wfhendVs:b:Lu"))!=-1) {
while ((c = getopt (argc, argv, "wfhe:ndVs:b:Lu"))!=-1) {
switch (c) {
case 'd':
debug = 1;
@ -76,7 +76,10 @@ int main(int argc, char **argv)
seek = atoi (optarg); // XXX use r_num
break;
case 'L':
r_io_handle_list (&r.io);
r_lib_opendir(&r.lib, r_config_get(&r.config, "dir.plugins"));
r_core_loadlibs(&r);
r_lib_list (&r.lib);
//r_io_handle_list (&r.io);
break;
case 'u':
fprintf(stderr, "TODO\n");
@ -103,15 +106,18 @@ int main(int argc, char **argv)
if (++optind != argc)
strcat(file, " ");
}
r_core_loadlibs(&r);
fh = r_core_file_open (&r, file, perms);
if (fh == NULL) {
fprintf (stderr,
"Cannot open file '%s'\n", file);
fprintf (stderr, "Cannot open file '%s'\n", file);
return 1;
}
} else
while (optind < argc) {
const char *file = argv[optind++];
// XXX dupped
r_core_loadlibs(&r);
fh = r_core_file_open (&r, file, perms);
if (fh == NULL) {
fprintf (stderr, "Cannot open file '%s'\n", file);
@ -131,6 +137,7 @@ int main(int argc, char **argv)
free (homerc);
}
}
if (debug) {
r_core_cmd (&r, "dh ptrace", 0);
r_core_cmdf (&r, "dp %d", r.file->fd);

View file

@ -83,6 +83,14 @@ int r_debug_stop_reason(struct r_debug_t *dbg)
return R_TRUE;
}
int r_debug_wait(struct r_debug_t *dbg)
{
int ret = R_FALSE;
if (dbg->h->wait)
ret = dbg->h->wait(dbg->pid);
return ret;
}
// TODO: count number of steps done to check if no error??
int r_debug_step(struct r_debug_t *dbg, int steps)
{
@ -92,9 +100,8 @@ int r_debug_step(struct r_debug_t *dbg, int steps)
ret = dbg->h->step(dbg->pid);
if (ret == R_FALSE)
break;
r_debug_wait(dbg);
// TODO: create wrapper for dbg_wait
if (dbg->h->wait)
ret = dbg->h->wait(dbg->pid);
// TODO: check return value of wait and show error
dbg->steps++;
}
@ -136,7 +143,7 @@ int r_debug_continue_until(struct r_debug_t *dbg, u64 addr)
int r_debug_continue_syscall(struct r_debug_t *dbg, int sc)
{
int ret = R_FALSE;
if (dbg->h && dbg->h->cont)
if (dbg->h && dbg->h->contsc)
ret = dbg->h->contsc(dbg->pid, sc);
return ret;
}

View file

@ -1,11 +1,11 @@
CFLAGS=-I../../include -Wall
BINDEPS=
all: dbg-ptrace.so
all: dbg_ptrace.so
@true
dbg-ptrace.so: dbg-ptrace.o
${CC} ${CFLAGS} -fPIC -shared -o dbg-ptrace.so dbg-ptrace.c
dbg_ptrace.so: dbg_ptrace.o
${CC} ${CFLAGS} -fPIC -shared -o dbg_ptrace.so dbg_ptrace.c
#strip -s ptrace.so
clean:

View file

@ -67,33 +67,34 @@ struct r_core_t {
struct r_search_t *search;
};
int r_core_init(struct r_core_t *core);
struct r_core_t *r_core_new();
int r_core_config_init(struct r_core_t *core);
int r_core_prompt(struct r_core_t *r);
int r_core_cmd(struct r_core_t *r, const char *cmd, int log);
int r_core_cmdf(void *user, const char *fmt, ...);
int r_core_cmd0(void *user, const char *cmd);
int r_core_cmd_init(struct r_core_t *core);
char *r_core_cmd_str(struct r_core_t *core, const char *cmd);
int r_core_cmd_file(struct r_core_t *core, const char *file);
int r_core_seek(struct r_core_t *core, u64 addr);
int r_core_seek_align(struct r_core_t *core, u64 align, int times);
int r_core_block_read(struct r_core_t *core, int next);
int r_core_block_size(struct r_core_t *core, u32 bsize);
int r_core_read_at(struct r_core_t *core, u64 addr, u8 *buf, int size);
int r_core_cmd_init(struct r_core_t *core);
int r_core_visual(struct r_core_t *core, const char *input);
int r_core_visual_cmd(struct r_core_t *core, int ch);
R_API int r_core_init(struct r_core_t *core);
R_API struct r_core_t *r_core_new();
R_API int r_core_config_init(struct r_core_t *core);
R_API int r_core_prompt(struct r_core_t *r);
R_API int r_core_cmd(struct r_core_t *r, const char *cmd, int log);
R_API int r_core_cmdf(void *user, const char *fmt, ...);
R_API int r_core_cmd0(void *user, const char *cmd);
R_API int r_core_cmd_init(struct r_core_t *core);
R_API char *r_core_cmd_str(struct r_core_t *core, const char *cmd);
R_API int r_core_cmd_file(struct r_core_t *core, const char *file);
R_API int r_core_seek(struct r_core_t *core, u64 addr);
R_API int r_core_seek_align(struct r_core_t *core, u64 align, int times);
R_API int r_core_block_read(struct r_core_t *core, int next);
R_API int r_core_block_size(struct r_core_t *core, u32 bsize);
R_API int r_core_read_at(struct r_core_t *core, u64 addr, u8 *buf, int size);
R_API int r_core_cmd_init(struct r_core_t *core);
R_API int r_core_visual(struct r_core_t *core, const char *input);
R_API int r_core_visual_cmd(struct r_core_t *core, int ch);
struct r_core_file_t *r_core_file_open(struct r_core_t *r, const char *file, int mode);
int r_core_file_close(struct r_core_t *r, struct r_core_file_t *fh);
int r_core_seek_delta(struct r_core_t *core, s64 addr);
int r_core_write_at(struct r_core_t *core, u64 addr, const u8 *buf, int size);
R_API struct r_core_file_t *r_core_file_open(struct r_core_t *r, const char *file, int mode);
R_API int r_core_file_close(struct r_core_t *r, struct r_core_file_t *fh);
R_API int r_core_seek_delta(struct r_core_t *core, s64 addr);
R_API int r_core_write_at(struct r_core_t *core, u64 addr, const u8 *buf, int size);
/* yank */
int r_core_yank(struct r_core_t *core, u64 addr, int len);
int r_core_yank_paste(struct r_core_t *core, u64 addr, int len);
R_API int r_core_yank(struct r_core_t *core, u64 addr, int len);
R_API int r_core_yank_paste(struct r_core_t *core, u64 addr, int len);
R_API int r_core_loadlibs(struct r_core_t *core);
#endif

View file

@ -35,6 +35,8 @@ struct r_lib_struct_t {
void *data; /* pointer to data handled by plugin handler */
};
extern const char *r_lib_types[];
enum {
R_LIB_TYPE_IO, /* io layer */
R_LIB_TYPE_DBG, /* debugger */

View file

@ -13,6 +13,7 @@
#else
#define IFRTDBG if (0)
#endif
/* ------------------------------------------- */
#if R_INLINE
#define R_API inline

View file

@ -23,6 +23,10 @@
#define DLCLOSE(x) NULL
#endif
const char *r_lib_types[] = {
"io", "dbg", "lang", "asm", "anal", "parse", "bin", "bininfo", NULL
};
void *r_lib_dl_open(const char *libname)
{
void *ret;
@ -108,7 +112,7 @@ struct r_lib_handler_t *r_lib_get_handler(struct r_lib_t *lib, int type)
return 0;
}
int r_lib_close(struct r_lib_t *lib, const char *file)
R_API int r_lib_close(struct r_lib_t *lib, const char *file)
{
struct list_head *pos;
list_for_each_prev(pos, &lib->plugins) {
@ -124,12 +128,37 @@ int r_lib_close(struct r_lib_t *lib, const char *file)
return -1;
}
int r_lib_open(struct r_lib_t *lib, const char *file)
// XXX ugly hack ?
static int samefile(const char *a, const char *b)
{
char *sa = strdup(a);
char *sb = strdup(b);
char *ptr;
int ret;
do {
ptr = strstr(sa, "//");
if (ptr) strcpy(ptr, ptr+1);
} while(ptr);
do {
ptr = strstr(sb, "//");
if (ptr) strcpy(ptr, ptr+1);
} while(ptr);
ret = strcmp(sa,sb)?R_FALSE:R_TRUE;
free(sa);
free(sb);
return ret;
}
R_API int r_lib_open(struct r_lib_t *lib, const char *file)
{
struct r_lib_struct_t *stru;
void * handler;
int ret;
//printf("OPENLIB(%s)\n", file);
/* ignored by filename */
if (!r_lib_dl_check_filename(file)) {
IFDBG fprintf(stderr, "Invalid library extension: %s\n", file);
@ -141,11 +170,23 @@ int r_lib_open(struct r_lib_t *lib, const char *file)
IFDBG fprintf(stderr, "Cannot open library: '%s'\n", file);
return -1;
}
stru = (struct r_lib_struct_t *) r_lib_dl_sym(handler, lib->symname);
if (stru == NULL) {
IFDBG fprintf(stderr, "No root symbol '%s' found in library '%s'\n", lib->symname, file);
return -1;
}
{
struct list_head *pos;
list_for_each_prev(pos, &lib->plugins) {
struct r_lib_plugin_t *p = list_entry(pos, struct r_lib_plugin_t, list);
if (samefile(file, p->file)) {
//printf("SKIP---------------(%s)\n", file);
r_lib_dl_close(handler);
return 0;
}
}
}
struct r_lib_plugin_t *p = MALLOC_STRUCT(struct r_lib_plugin_t);
p->type = stru->type;
p->data = stru->data;
@ -153,6 +194,7 @@ int r_lib_open(struct r_lib_t *lib, const char *file)
p->dl_handler = handler;
p->handler = r_lib_get_handler(lib, p->type);
//printf("ADD---------------(%s)\n", file);
ret = r_lib_run_handler(lib, p, stru);
if (ret == -1) {
IFDBG fprintf(stderr, "Library handler returned -1 for '%s'\n", file);
@ -178,6 +220,8 @@ int r_lib_opendir(struct r_lib_t *lib, const char *path)
#endif
if (path == NULL)
return R_FALSE;
//printf("OPENPATH(%s)\n", path);
dh = opendir(path);
if (dh == NULL) {
IFDBG fprintf(stderr, "Cannot open directory '%s'\n", path);
@ -194,15 +238,17 @@ int r_lib_opendir(struct r_lib_t *lib, const char *path)
int r_lib_list(struct r_lib_t *lib)
{
struct list_head *pos;
#if 0
printf("Plugin Handlers:\n");
list_for_each_prev(pos, &lib->handlers) {
struct r_lib_handler_t *h = list_entry(pos, struct r_lib_handler_t, list);
printf(" - %d: %s\n", h->type, h->desc);
}
printf("Loaded plugins:\n");
#endif
//printf("Loaded plugins:\n");
list_for_each_prev(pos, &lib->plugins) {
struct r_lib_plugin_t *p = list_entry(pos, struct r_lib_plugin_t, list);
printf(" - %d : %s (%p)\n", p->type, p->file, p->handler->destructor);
printf(" %5s : %s (%p)\n", r_lib_types[p->type], p->file, p->handler->destructor);
}
return 0;
}

View file

@ -39,10 +39,10 @@ LIBAR=${LIB}.${EXT_AR}
LIBSO=${LIB}.${EXT_SO}
#-------------------------------------#
# Rules
# Rules for libraries
ifeq (${BINDEPS},)
ifneq ($(NAME),)
include ../../config.mk
include ../../config-user.mk
include ../../mk/${COMPILER}.mk
CFLAGS+=-I../include
@ -51,9 +51,17 @@ real_all all: ${LIBSO} ${EXTRA_TARGETS}
@-if [ -e p/Makefile ]; then (cd p && ${MAKE} all) ; fi
@true
SRC=$(subst .o,.c,$(OBJ))
${LIBSO}: ${OBJ}
${CC_LIB} ${LDFLAGS} ${LINK} ${OBJ}
@if [ -f "../stripsyms.sh" ]; then sh ../stripsyms.sh ${LIBSO} ${NAME} ; fi
@for a in ${OBJ} ${SRC}; do \
test $$a -nt ${LIBSO} ; \
if [ $$? = 0 ]; then \
echo "${CC_LIB} ${LDFLAGS} ${LINK} ${OBJ}" ; \
${CC_LIB} ${LDFLAGS} ${LINK} ${OBJ} ; \
if [ -f "../stripsyms.sh" ]; then sh ../stripsyms.sh ${LIBSO} ${NAME} ; fi ; \
break ; \
fi ; done
${LIBAR}: ${OBJ}
${CC_AR} ${OBJ}
@ -70,14 +78,18 @@ clean: ${EXTRA_CLEAN}
endif
else
#-------------------------------------#
# Rules for test programs
include ../../config.mk
include ../../../mk/${COMPILER}.mk
CFLAGS+=-I../../include
all: ${BIN}
@true
${BIN}: ${OBJ}
# XXX Shouldnt run always
${CC} ${LDFLAGS} ${OBJ} -o ${BIN} ${LIBS}
#Dummy myclean rule that can be overriden by the t/ Makefile
@ -95,7 +107,6 @@ endif
CFLAGS+=-DR_RTDEBUG
#endif
// TODO: Not working
#if STATIC_DEBUG
#CFLAGS+=-DR_DEBUG

View file

@ -1,7 +1,7 @@
CC?=gcc
LINK=
CC_AR=ar -r ${LIBAR}
CFLAGS+=-fPIC
CFLAGS+=-fPIC -MD
CC_LIB=${CC} -shared -o ${LIBSO}
CFLAGS_INCLUDE=-I
LDFLAGS_LINK=-l