mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-23 21:29:49 +00:00
* Added 'mk/stat' tools
- Perform statistics about XXX and TODOs * Change signature of r_debug_mmu_ * Added io->cached_reads * RAPIfy the r_lang * Reviewing of the r_lib API - Write the vapi file - Check for null mallocs * Fix build of r_reg
This commit is contained in:
parent
df967c868b
commit
b37ec4f0b1
@ -5,7 +5,7 @@ PREFIX=@PREFIX@
|
||||
HAVE_LIB_EWF=@HAVE_LIB_EWF@
|
||||
LIL_ENDIAN=@LIL_ENDIAN@
|
||||
|
||||
MKPLUGINS=mk/hg-utils.mk
|
||||
MKPLUGINS=mk/hg-utils.mk mk/stat.mk
|
||||
|
||||
COMPILER=@USERCC@
|
||||
STATIC_DEBUG=0
|
||||
|
@ -9,7 +9,7 @@ R_API int r_debug_init(struct r_debug_t *dbg, int hard)
|
||||
dbg->swstep = 0; // software step
|
||||
dbg->newstate = 0;
|
||||
dbg->regs = dbg->oregs = NULL;
|
||||
dbg->printf = printf;
|
||||
dbg->printf = (void *)printf;
|
||||
dbg->h = NULL;
|
||||
if (hard) {
|
||||
dbg->bp = r_bp_new();
|
||||
@ -23,7 +23,7 @@ R_API struct r_debug_t *r_debug_new()
|
||||
{
|
||||
struct r_debug_t *dbg = MALLOC_STRUCT(struct r_debug_t);
|
||||
if (dbg != NULL)
|
||||
r_debug_init(dbg);
|
||||
r_debug_init(dbg, R_TRUE);
|
||||
return dbg;
|
||||
}
|
||||
|
||||
@ -178,7 +178,7 @@ R_API int r_debug_kill(struct r_debug_t *dbg, int pid, int sig)
|
||||
|
||||
// TODO move to mem.c
|
||||
/* mmu */
|
||||
R_API ut64 r_debug_mmu_alloc(struct r_debug_t *dbg, ut64 size, ut64 *addr)
|
||||
R_API ut64 r_debug_mmu_alloc(struct r_debug_t *dbg, ut64 size, ut64 addr)
|
||||
{
|
||||
ut64 ret = 0LL;
|
||||
if (dbg->h && dbg->h->mmu_alloc)
|
||||
@ -193,3 +193,4 @@ R_API int r_debug_mmu_free(struct r_debug_t *dbg, ut64 addr)
|
||||
ret = dbg->h->mmu_free(dbg, addr);
|
||||
return ret;
|
||||
}
|
||||
// TODO: add support to iterate over all allocated memory chunks?
|
||||
|
@ -102,12 +102,9 @@ R_API int r_debug_handle_set(struct r_debug_t *dbg, const char *str);
|
||||
R_API int r_debug_handle_list(struct r_debug_t *dbg);
|
||||
R_API int r_debug_handle_add(struct r_debug_t *dbg, struct r_debug_handle_t *foo);
|
||||
|
||||
/* breakpoints */
|
||||
R_API int r_debug_bp_add(struct r_debug_t *dbg, ut64 addr, int size, int hw, int rwx);
|
||||
R_API int r_debug_bp_del(struct r_debug_t *dbg, ut64 addr);
|
||||
R_API int r_debug_bp_enable(struct r_debug_t *dbg, ut64 addr, int set);
|
||||
R_API int r_debug_bp_disable(struct r_debug_t *dbg);
|
||||
R_API int r_debug_bp_list(struct r_debug_t *dbg, int rad);
|
||||
/* memory */
|
||||
R_API ut64 r_debug_mmu_alloc(struct r_debug_t *dbg, ut64 size, ut64 addr);
|
||||
R_API int r_debug_mmu_free(struct r_debug_t *dbg, ut64 addr);
|
||||
|
||||
/* registers */
|
||||
R_API int r_debug_reg_sync(struct r_debug_t *dbg, int write);
|
||||
|
@ -53,6 +53,7 @@ struct r_io_t {
|
||||
int enforce_rwx;
|
||||
int enforce_seek;
|
||||
int cached;
|
||||
int cached_read;
|
||||
ut64 seek;
|
||||
char *redirect;
|
||||
/* write mask */
|
||||
@ -144,7 +145,7 @@ R_API int r_io_close(struct r_io_t *io, int fd);
|
||||
R_API ut64 r_io_size(struct r_io_t *io, int fd);
|
||||
|
||||
/* io/cache.c */
|
||||
R_API void r_io_cache_enable(struct r_io_t *io, int set);
|
||||
R_API void r_io_cache_enable(struct r_io_t *io, int read, int write);
|
||||
R_API void r_io_cache_init(struct r_io_t *io);
|
||||
R_API int r_io_cache_write(struct r_io_t *io, ut64 addr, const ut8 *buf, int len);
|
||||
R_API int r_io_cache_read(struct r_io_t *io, ut64 addr, ut8 *buf, int len);
|
||||
|
@ -23,15 +23,15 @@ struct r_lang_t {
|
||||
struct list_head langs;
|
||||
};
|
||||
|
||||
int r_lang_init(struct r_lang_t *lang);
|
||||
int r_lang_add(struct r_lang_t *lang, struct r_lang_handle_t *foo);
|
||||
int r_lang_list(struct r_lang_t *lang);
|
||||
int r_lang_set(struct r_lang_t *lang, const char *name);
|
||||
int r_lang_run(struct r_lang_t *lang, const char *code, int len);
|
||||
void r_lang_set_user_ptr(struct r_lang_t *lang, void *user);
|
||||
int r_lang_set_argv(struct r_lang_t *lang, int argc, char **argv);
|
||||
int r_lang_run(struct r_lang_t *lang, const char *code, int len);
|
||||
int r_lang_run_file(struct r_lang_t *lang, const char *file);
|
||||
int r_lang_prompt(struct r_lang_t *lang);
|
||||
R_API int r_lang_init(struct r_lang_t *lang);
|
||||
R_API int r_lang_add(struct r_lang_t *lang, struct r_lang_handle_t *foo);
|
||||
R_API int r_lang_list(struct r_lang_t *lang);
|
||||
R_API int r_lang_set(struct r_lang_t *lang, const char *name);
|
||||
R_API int r_lang_run(struct r_lang_t *lang, const char *code, int len);
|
||||
R_API void r_lang_set_user_ptr(struct r_lang_t *lang, void *user);
|
||||
R_API int r_lang_set_argv(struct r_lang_t *lang, int argc, char **argv);
|
||||
R_API int r_lang_run(struct r_lang_t *lang, const char *code, int len);
|
||||
R_API int r_lang_run_file(struct r_lang_t *lang, const char *file);
|
||||
R_API int r_lang_prompt(struct r_lang_t *lang);
|
||||
|
||||
#endif
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include "list.h"
|
||||
|
||||
// rename to '.' ??
|
||||
#define R_LIB_SEPARATOR "_"
|
||||
#define R_LIB_SEPARATOR "."
|
||||
|
||||
/* store list of loaded plugins */
|
||||
struct r_lib_plugin_t {
|
||||
@ -30,7 +30,6 @@ struct r_lib_handler_t {
|
||||
struct list_head list;
|
||||
};
|
||||
|
||||
|
||||
/* this structure should be pointed by the 'radare_plugin' symbol
|
||||
found in the loaded .so */
|
||||
struct r_lib_struct_t {
|
||||
@ -65,22 +64,24 @@ struct r_lib_t {
|
||||
struct list_head handlers;
|
||||
};
|
||||
|
||||
int r_lib_init(struct r_lib_t *lib, const char *symname);
|
||||
R_API int r_lib_init(struct r_lib_t *lib, const char *symname);
|
||||
|
||||
/* low level api */
|
||||
void *r_lib_dl_open(const char *libname);
|
||||
void *r_lib_dl_sym(void *handle, const char *name);
|
||||
int r_lib_dl_close(void *handle);
|
||||
int r_lib_dl_check_filename(const char *file);
|
||||
R_API void *r_lib_dl_open(const char *libname);
|
||||
R_API void *r_lib_dl_sym(void *handle, const char *name);
|
||||
R_API int r_lib_dl_close(void *handle);
|
||||
R_API int r_lib_dl_check_filename(const char *file);
|
||||
|
||||
/* high level api */
|
||||
struct r_lib_t *r_lib_new(const char *symname);
|
||||
int r_lib_free(struct r_lib_t *lib);
|
||||
int r_lib_run_handler(struct r_lib_t *lib, struct r_lib_plugin_t *plugin, struct r_lib_struct_t *symbol);
|
||||
int r_lib_open(struct r_lib_t *lib, const char *file);
|
||||
int r_lib_opendir(struct r_lib_t *lib, const char *path);
|
||||
int r_lib_list(struct r_lib_t *lib);
|
||||
int r_lib_add_handler(struct r_lib_t *lib, int type, const char *desc, int (*cb)(struct r_lib_plugin_t *,void *, void *), int (*dt)(struct r_lib_plugin_t *, void *, void *), void *user );
|
||||
int r_lib_close(struct r_lib_t *lib, const char *file);
|
||||
R_API struct r_lib_t *r_lib_new(const char *symname);
|
||||
R_API int r_lib_free(struct r_lib_t *lib);
|
||||
R_API int r_lib_run_handler(struct r_lib_t *lib, struct r_lib_plugin_t *plugin, struct r_lib_struct_t *symbol);
|
||||
R_API struct r_lib_handler_t *r_lib_get_handler(struct r_lib_t *lib, int type);
|
||||
R_API int r_lib_open(struct r_lib_t *lib, const char *file);
|
||||
R_API int r_lib_opendir(struct r_lib_t *lib, const char *path);
|
||||
R_API void r_lib_list(struct r_lib_t *lib);
|
||||
R_API int r_lib_add_handler(struct r_lib_t *lib, int type, const char *desc, int (*cb)(struct r_lib_plugin_t *,void *, void *), int (*dt)(struct r_lib_plugin_t *, void *, void *), void *user );
|
||||
R_API int r_lib_del_handler(struct r_lib_t *lib, struct r_lib_handler_t *hand);
|
||||
R_API int r_lib_close(struct r_lib_t *lib, const char *file);
|
||||
|
||||
#endif
|
||||
|
@ -19,6 +19,7 @@ enum {
|
||||
};
|
||||
|
||||
struct r_reg_handle_t {
|
||||
char *name;
|
||||
int (*is_arch)(int arch, int bits);
|
||||
struct list_head list;
|
||||
};
|
||||
@ -47,6 +48,9 @@ struct r_regset_t {
|
||||
struct r_reg_item_t *regs;
|
||||
};
|
||||
|
||||
int r_reg_set_arch(struct r_reg_t *reg, int arch, int bits);
|
||||
R_API int r_reg_set_arch(struct r_reg_t *reg, int arch, int bits);
|
||||
R_API int r_reg_handle_set(struct r_reg_t *reg, const char *str);
|
||||
R_API int r_reg_handle_init(struct r_reg_t *reg);
|
||||
R_API int r_reg_handle_add(struct r_reg_t *reg, struct r_reg_handle_t *foo);
|
||||
|
||||
#endif
|
||||
|
@ -113,6 +113,7 @@ static inline int ERR(char *str, ...)
|
||||
#define R_MIN(x,y) (x>y)?y:x
|
||||
#define R_ABS(x) ((x<0)?-x:x)
|
||||
|
||||
#define R_FAIL -1
|
||||
#define R_FALSE 0
|
||||
#define R_TRUE 1
|
||||
#define R_TRUFAE 2
|
||||
|
@ -3,18 +3,22 @@
|
||||
// XXX This has been stolen from r_vm !!! we must adapt this
|
||||
// XXX to work with r_io correctly
|
||||
// r_io_cache_t has not been defined
|
||||
// TODO: implement a more inteligent way to store cached memory
|
||||
// TODO: define limit of max mem to cache
|
||||
|
||||
#include "r_io.h"
|
||||
|
||||
R_API void r_io_cache_init(struct r_io_t *io)
|
||||
{
|
||||
io->cached = 0; // IO cached
|
||||
io->cached = R_FALSE; // cache write ops
|
||||
io->cached_read = R_FALSE; // cached read ops
|
||||
INIT_LIST_HEAD(&io->cache);
|
||||
}
|
||||
|
||||
R_API void r_io_cache_enable(struct r_io_t *io, int set)
|
||||
R_API void r_io_cache_enable(struct r_io_t *io, int read, int write)
|
||||
{
|
||||
io->cached = set;
|
||||
io->cached = read|write;
|
||||
io->cached_read = read;
|
||||
}
|
||||
|
||||
R_API void r_io_cache_free(struct r_io_t *io, int set)
|
||||
@ -32,6 +36,13 @@ R_API void r_io_cache_free(struct r_io_t *io, int set)
|
||||
INIT_LIST_HEAD(&io->cache);
|
||||
}
|
||||
|
||||
R_API int r_io_cache_invalidate(struct r_io_t *io, ut64 from, ut64 to)
|
||||
{
|
||||
int ret = R_FALSE;
|
||||
/* TODO: Implement: invalidate ranged cached read ops between from/to */
|
||||
return ret;
|
||||
}
|
||||
|
||||
R_API int r_io_cache_write(struct r_io_t *io, ut64 addr, const ut8 *buf, int len)
|
||||
{
|
||||
struct r_io_cache_t *ch = MALLOC_STRUCT(struct r_io_cache_t);
|
||||
@ -59,22 +70,3 @@ R_API int r_io_cache_read(struct r_io_t *io, ut64 addr, ut8 *buf, int len)
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
/*
|
||||
R_API int r_io_cache_read(struct r_io_t *io, ut64 off, ut8 *data, int len)
|
||||
{
|
||||
if (io->cached && r_io_cache_cache_read(io, off, data, len))
|
||||
return len;
|
||||
return r_io_read_at(io, off, data, len);
|
||||
}
|
||||
*/
|
||||
|
||||
#if 0
|
||||
R_API int r_io_cache_write(struct r_io_t *io, ut64 off, ut8 *data, int len)
|
||||
{
|
||||
if (io->cached)
|
||||
return r_io_cache_write(io, off, data, len);
|
||||
// XXX: callback for write-at should be userdefined
|
||||
return r_io_write_at(io, off, data, len);
|
||||
}
|
||||
#endif
|
||||
|
17
libr/io/io.c
17
libr/io/io.c
@ -132,21 +132,30 @@ R_API int r_io_read(struct r_io_t *io, ut8 *buf, int len)
|
||||
len -= ret;
|
||||
buf += ret;
|
||||
}
|
||||
}
|
||||
ret = r_io_map_read_at(io, io->seek, buf, len);
|
||||
// partial reads
|
||||
if (ret == len)
|
||||
return len;
|
||||
}
|
||||
ret = r_io_map_read_at(io, io->seek, buf, len);
|
||||
|
||||
// partial reads
|
||||
if (ret != len) {
|
||||
if (ret != -1) {
|
||||
len -= ret;
|
||||
buf += len;
|
||||
}
|
||||
if (io->plugin && io->plugin->read) {
|
||||
if (io->plugin->read != NULL)
|
||||
return io->plugin->read(io, io->fd, buf, len);
|
||||
ret = io->plugin->read(io, io->fd, buf, len);
|
||||
else fprintf(stderr, "IO handler for fd=%d has no read()\n", io->fd);
|
||||
} else ret = read(io->fd, buf, len);
|
||||
}
|
||||
return read(io->fd, buf, len);
|
||||
|
||||
if (ret == len && io->cached_read) {
|
||||
/* if read is cached. cache it :) */
|
||||
r_io_cache_write(io, io->seek, buf, len);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
R_API int r_io_read_at(struct r_io_t *io, ut64 addr, ut8 *buf, int len)
|
||||
|
15
libr/lang/README
Normal file
15
libr/lang/README
Normal file
@ -0,0 +1,15 @@
|
||||
Language bindings
|
||||
=================
|
||||
|
||||
Bindings should be generated automatically from vala or C.
|
||||
|
||||
The programs running in r_lang should need a better integration with the rest of libs.
|
||||
This is: We need an api in r_lang to export a C symbol into the language namespace.
|
||||
|
||||
For example:
|
||||
|
||||
r_lang_define(lang, "Core", "core", core);
|
||||
r_lang_define(lang, "Asm", "asm", asm)
|
||||
|
||||
This way the module instances can be shared between the core C application and many
|
||||
r_lang supported language bindings (perk, python, ..)
|
@ -3,19 +3,27 @@
|
||||
#include <r_lang.h>
|
||||
#include <r_util.h>
|
||||
|
||||
int r_lang_init(struct r_lang_t *lang)
|
||||
R_API int r_lang_init(struct r_lang_t *lang)
|
||||
{
|
||||
lang->user = NULL;
|
||||
INIT_LIST_HEAD(&lang->langs);
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
void r_lang_set_user_ptr(struct r_lang_t *lang, void *user)
|
||||
// XXX: This is only used actually to pass 'core' structure
|
||||
// TODO: when language bindings are done we will need an api to
|
||||
// define symbols from C to the language namespace
|
||||
R_API void r_lang_set_user_ptr(struct r_lang_t *lang, void *user)
|
||||
{
|
||||
lang->user = user;
|
||||
}
|
||||
|
||||
int r_lang_add(struct r_lang_t *lang, struct r_lang_handle_t *foo)
|
||||
R_API int r_lang_define(struct r_lang_t *lang, const char *type, const char *name, void *value)
|
||||
{
|
||||
// if (lang->cur && lang->cur->define)
|
||||
}
|
||||
|
||||
R_API int r_lang_add(struct r_lang_t *lang, struct r_lang_handle_t *foo)
|
||||
{
|
||||
if (foo->init)
|
||||
foo->init(lang->user);
|
||||
@ -23,7 +31,7 @@ int r_lang_add(struct r_lang_t *lang, struct r_lang_handle_t *foo)
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
int r_lang_list(struct r_lang_t *lang)
|
||||
R_API int r_lang_list(struct r_lang_t *lang)
|
||||
{
|
||||
struct list_head *pos;
|
||||
list_for_each_prev(pos, &lang->langs) {
|
||||
@ -33,7 +41,7 @@ int r_lang_list(struct r_lang_t *lang)
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
int r_lang_set(struct r_lang_t *lang, const char *name)
|
||||
R_API int r_lang_set(struct r_lang_t *lang, const char *name)
|
||||
{
|
||||
struct list_head *pos;
|
||||
list_for_each_prev(pos, &lang->langs) {
|
||||
@ -46,21 +54,21 @@ int r_lang_set(struct r_lang_t *lang, const char *name)
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
int r_lang_set_argv(struct r_lang_t *lang, int argc, char **argv)
|
||||
R_API int r_lang_set_argv(struct r_lang_t *lang, int argc, char **argv)
|
||||
{
|
||||
if (lang->cur && lang->cur->set_argv)
|
||||
return lang->cur->set_argv(lang->user, argc, argv);
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
int r_lang_run(struct r_lang_t *lang, const char *code, int len)
|
||||
R_API int r_lang_run(struct r_lang_t *lang, const char *code, int len)
|
||||
{
|
||||
if (lang->cur && lang->cur->run)
|
||||
return lang->cur->run(lang->user, code, len);
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
int r_lang_run_file(struct r_lang_t *lang, const char *file)
|
||||
R_API int r_lang_run_file(struct r_lang_t *lang, const char *file)
|
||||
{
|
||||
int len, ret = R_FALSE;
|
||||
if (lang->cur) {
|
||||
@ -75,7 +83,7 @@ int r_lang_run_file(struct r_lang_t *lang, const char *file)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int r_lang_prompt(struct r_lang_t *lang)
|
||||
R_API int r_lang_prompt(struct r_lang_t *lang)
|
||||
{
|
||||
char buf[1024];
|
||||
|
||||
|
141
libr/lib/lib.c
141
libr/lib/lib.c
@ -23,19 +23,21 @@
|
||||
#define DLCLOSE(x) NULL
|
||||
#endif
|
||||
|
||||
const char *r_lib_types[] = {
|
||||
/* XXX : this must be registered in runtime */
|
||||
static const char *r_lib_types[] = {
|
||||
"io", "dbg", "lang", "asm", "anal", "parse", "bin", "bininfo",
|
||||
"bp", "syscall", "fastcall", NULL
|
||||
};
|
||||
|
||||
const char *r_lib_types_get(int idx)
|
||||
/* XXX: Rename this helper function */
|
||||
R_API const char *r_lib_types_get(int idx)
|
||||
{
|
||||
if (idx<0||idx>R_LIB_TYPE_LAST)
|
||||
return "unk";
|
||||
return r_lib_types[idx];
|
||||
}
|
||||
|
||||
void *r_lib_dl_open(const char *libname)
|
||||
R_API void *r_lib_dl_open(const char *libname)
|
||||
{
|
||||
void *ret;
|
||||
IFRTDBG fprintf(stderr, "Opening '%s'\n", libname);
|
||||
@ -45,44 +47,45 @@ void *r_lib_dl_open(const char *libname)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *r_lib_dl_sym(void *handle, const char *name)
|
||||
R_API void *r_lib_dl_sym(void *handle, const char *name)
|
||||
{
|
||||
return DLSYM(handle, name);
|
||||
}
|
||||
|
||||
int r_lib_dl_close(void *handle)
|
||||
R_API int r_lib_dl_close(void *handle)
|
||||
{
|
||||
return DLCLOSE(handle);
|
||||
}
|
||||
|
||||
/* ---- */
|
||||
|
||||
int r_lib_init(struct r_lib_t *lib, const char *symname)
|
||||
R_API struct r_lib_t *r_lib_init(struct r_lib_t *lib, const char *symname)
|
||||
{
|
||||
if (lib) {
|
||||
INIT_LIST_HEAD(&lib->handlers);
|
||||
INIT_LIST_HEAD(&lib->plugins);
|
||||
strncpy(lib->symname, symname, sizeof(lib->symname)-1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct r_lib_t *r_lib_new(const char *symname)
|
||||
{
|
||||
struct r_lib_t *lib = MALLOC_STRUCT(struct r_lib_t);
|
||||
r_lib_init(lib, symname);
|
||||
}
|
||||
return lib;
|
||||
}
|
||||
|
||||
int r_lib_free(struct r_lib_t *lib)
|
||||
R_API struct r_lib_t *r_lib_new(const char *symname)
|
||||
{
|
||||
struct r_lib_t *lib = MALLOC_STRUCT(struct r_lib_t);
|
||||
return r_lib_init(lib, symname);
|
||||
}
|
||||
|
||||
R_API struct r_lib_t *r_lib_free(struct r_lib_t *lib)
|
||||
{
|
||||
/* TODO: iterate over libraries and free them all */
|
||||
/* TODO: iterate over handlers and free them all */
|
||||
r_lib_close(lib, NULL);
|
||||
free (lib);
|
||||
return 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* THIS IS WRONG */
|
||||
int r_lib_dl_check_filename(const char *file)
|
||||
R_API int r_lib_dl_check_filename(const char *file)
|
||||
{
|
||||
/* skip hidden files */
|
||||
if (file[0]=='.')
|
||||
@ -100,27 +103,26 @@ int r_lib_dl_check_filename(const char *file)
|
||||
|
||||
/* high level api */
|
||||
|
||||
int r_lib_run_handler(struct r_lib_t *lib, struct r_lib_plugin_t *plugin, struct r_lib_struct_t *symbol)
|
||||
R_API int r_lib_run_handler(struct r_lib_t *lib, struct r_lib_plugin_t *plugin, struct r_lib_struct_t *symbol)
|
||||
{
|
||||
struct r_lib_handler_t *h = plugin->handler;
|
||||
if (h && h->constructor != NULL)
|
||||
return h->constructor(plugin, h->user, symbol->data);
|
||||
return -1;
|
||||
return R_FAIL;
|
||||
}
|
||||
|
||||
struct r_lib_handler_t *r_lib_get_handler(struct r_lib_t *lib, int type)
|
||||
R_API struct r_lib_handler_t *r_lib_get_handler(struct r_lib_t *lib, int type)
|
||||
{
|
||||
struct list_head *pos;
|
||||
list_for_each_prev(pos, &lib->handlers) {
|
||||
struct r_lib_handler_t *h = list_entry(pos, struct r_lib_handler_t, list);
|
||||
if (h->type == type) {
|
||||
if (h->type == type)
|
||||
return h;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
R_API int r_lib_close(struct r_lib_t *lib, const char *file)
|
||||
R_API 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) {
|
||||
@ -164,61 +166,57 @@ static int samefile(const char *a, const char *b)
|
||||
|
||||
R_API int r_lib_open(struct r_lib_t *lib, const char *file)
|
||||
{
|
||||
struct r_lib_plugin_t *p;
|
||||
struct list_head *pos;
|
||||
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);
|
||||
return -1;
|
||||
return R_FAIL;
|
||||
}
|
||||
|
||||
handler = r_lib_dl_open(file);
|
||||
if (handler == NULL) {
|
||||
IFDBG fprintf(stderr, "Cannot open library: '%s'\n", file);
|
||||
return -1;
|
||||
return R_FAIL;
|
||||
}
|
||||
|
||||
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;
|
||||
return R_FAIL;
|
||||
}
|
||||
{
|
||||
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;
|
||||
return R_FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
struct r_lib_plugin_t *p = MALLOC_STRUCT(struct r_lib_plugin_t);
|
||||
|
||||
p = MALLOC_STRUCT(struct r_lib_plugin_t);
|
||||
p->type = stru->type;
|
||||
p->data = stru->data;
|
||||
p->file = strdup(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);
|
||||
if (ret == R_FAIL) {
|
||||
IFDBG fprintf(stderr, "Library handler has failed for '%s'\n", file);
|
||||
free(p->file);
|
||||
free(p);
|
||||
r_lib_dl_close(handler);
|
||||
} else {
|
||||
/* append plugin */
|
||||
list_add(&p->list, &lib->plugins);
|
||||
}
|
||||
} else list_add(&p->list, &lib->plugins);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int r_lib_opendir(struct r_lib_t *lib, const char *path)
|
||||
R_API int r_lib_opendir(struct r_lib_t *lib, const char *path)
|
||||
{
|
||||
char file[1024];
|
||||
struct dirent *de;
|
||||
@ -231,7 +229,6 @@ int r_lib_opendir(struct r_lib_t *lib, const char *path)
|
||||
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);
|
||||
@ -245,25 +242,7 @@ int r_lib_opendir(struct r_lib_t *lib, const char *path)
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
#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(" %5s %p %s \n", r_lib_types_get(p->type), p->handler->destructor, p->file);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int r_lib_add_handler(struct r_lib_t *lib,
|
||||
R_API int r_lib_add_handler(struct r_lib_t *lib,
|
||||
int type, const char *desc,
|
||||
int (*cb)(struct r_lib_plugin_t *, void *, void *), /* constructor */
|
||||
int (*dt)(struct r_lib_plugin_t *, void *, void *), /* destructor */
|
||||
@ -282,6 +261,8 @@ int r_lib_add_handler(struct r_lib_t *lib,
|
||||
}
|
||||
if (handler == NULL) {
|
||||
handler = MALLOC_STRUCT(struct r_lib_handler_t);
|
||||
if (handler == NULL)
|
||||
return R_FALSE;
|
||||
handler->type = type;
|
||||
list_add(&handler->list, &lib->handlers);
|
||||
}
|
||||
@ -290,18 +271,38 @@ int r_lib_add_handler(struct r_lib_t *lib,
|
||||
handler->constructor = cb;
|
||||
handler->destructor = dt;
|
||||
|
||||
//printf("constructor: %p\n", dt);
|
||||
//printf("destructor : %p\n", dt);
|
||||
return 0;
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
#if 0
|
||||
// TODO
|
||||
|
||||
int r_lib_del_handler(struct r_lib_t *lib)
|
||||
R_API int r_lib_del_handler(struct r_lib_t *lib, int type)
|
||||
{
|
||||
return 0;
|
||||
struct list_head *pos;
|
||||
// TODO: remove all handlers for that type? or only one?
|
||||
list_for_each_prev(pos, &lib->handlers) {
|
||||
struct r_lib_handler_t *h = list_entry(pos, struct r_lib_handler_t, list);
|
||||
if (type == h->type) {
|
||||
list_del(&(h->list));
|
||||
return R_TRUE;
|
||||
}
|
||||
}
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
|
||||
/* XXX _list methods must be deprecated before r2-1.0 */
|
||||
R_API void 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);
|
||||
}
|
||||
#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(" %5s %p %s \n", r_lib_types_get(p->type), p->handler->destructor, p->file);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
NAME=r_reg
|
||||
OBJ=reg.o regset.o
|
||||
OBJ=reg.o regset.o handle.o
|
||||
|
||||
include ../rules.mk
|
||||
|
@ -21,7 +21,7 @@ int r_file_mkdir(const char *path)
|
||||
R_API int r_file_exist(const char *str)
|
||||
{
|
||||
struct stat buf;
|
||||
return (stat(str, &buf)!=-1)?R_TRUE:R_FALSE;
|
||||
return (stat(str, &buf)==-1)?R_FALSE:R_TRUE;
|
||||
}
|
||||
|
||||
R_API char *r_file_path(const char *bin)
|
||||
|
35
libr/vapi/r_lib.vapi
Normal file
35
libr/vapi/r_lib.vapi
Normal file
@ -0,0 +1,35 @@
|
||||
/* radare - LGPL - Copyright 2009 pancake<nopcode.org> */
|
||||
|
||||
[CCode (cheader_filename="r_lib.h", cprefix="r_", lower_case_cprefix="r_")]
|
||||
namespace Radare {
|
||||
|
||||
[Compact]
|
||||
[CCode (cname="struct r_lib_t", free_function="r_lib_free")]
|
||||
public class Library {
|
||||
public Library(string symname);
|
||||
public Library init(string symname);
|
||||
public bool close(void *ptr);
|
||||
public void* opendir(string path);
|
||||
public string types_get(int idx);
|
||||
|
||||
/* lowlevel api */
|
||||
public void* dl_open(string libname);
|
||||
public void* dl_sym(string symname);
|
||||
public bool dl_close(void *lh);
|
||||
public bool dl_check_filename(string file);
|
||||
/* handlers */
|
||||
// we need delegates here (function pointerz)
|
||||
// public bool add_handler(int type, string desc, /* */, void* user);
|
||||
public bool del_handler(int type);
|
||||
public Library.Handler get_handler(int type);
|
||||
//public struct Struct { }
|
||||
[Compact]
|
||||
public struct Handler {
|
||||
int type;
|
||||
string desc;
|
||||
void* user;
|
||||
// constructor
|
||||
// destructor
|
||||
}
|
||||
}
|
||||
}
|
@ -1,2 +1,12 @@
|
||||
|
||||
API for accessing and analyzing variables
|
||||
=========================================
|
||||
|
||||
Describes variable types:
|
||||
|
||||
int, float, byte, char, ...
|
||||
size of array of elements (optional)
|
||||
local/global
|
||||
...
|
||||
|
||||
This API has been stolen from the r1 API.
|
||||
|
27
mk/stat-make.pl
Normal file
27
mk/stat-make.pl
Normal file
@ -0,0 +1,27 @@
|
||||
#!/usr/bin/perl #
|
||||
# ------------- #
|
||||
my $level = 0;
|
||||
my $path = "";
|
||||
my $ofile = "";
|
||||
while(<STDIN>) {
|
||||
if (/Entering directory `(.*)'/) {
|
||||
$path = $1;
|
||||
if ($level>0) {
|
||||
print " |"x$level;
|
||||
@str=split('/', $1);
|
||||
print "- ".$str[$#str]."\n";
|
||||
}
|
||||
$level++;
|
||||
}
|
||||
--$level if (/Leaving directory `(.*)'/);
|
||||
s/warning:/\x1b[32mwarning\x1b[0m:/;
|
||||
s/error:/\x1b[31merror\x1b[0m:/;
|
||||
if (/\..:/) {
|
||||
s/:/\n\t/;
|
||||
/(.*):/;
|
||||
$file = $1;
|
||||
print "$path/$_" if ($file ne $ofile)
|
||||
$ofile = $file;
|
||||
}
|
||||
#{ print "$path/".$line; }
|
||||
}
|
12
mk/stat.mk
Normal file
12
mk/stat.mk
Normal file
@ -0,0 +1,12 @@
|
||||
stat-todo:
|
||||
@printf "XXX\tTODO\tName\n"
|
||||
@for a in libr/* ; do \
|
||||
if [ -d "$$a" ]; then \
|
||||
xxx=`grep -e XXX $$a/*.c $$a/p/*.c $$a/t/*.c 2>/dev/null | wc -l` ; \
|
||||
todo=`grep -e TODO $$a/*.c $$a/p/*.c $$a/t/*.c 2>/dev/null | wc -l` ; \
|
||||
printf "$$xxx\t$$todo\t$$a\n" ; \
|
||||
fi ; \
|
||||
done
|
||||
|
||||
stat-make:
|
||||
make 2>&1 | perl mk/stat-make.pl
|
Loading…
Reference in New Issue
Block a user