2009-02-05 21:08:46 +00:00
|
|
|
#ifndef _LIB_R_LIB_H_
|
|
|
|
#define _LIB_R_LIB_H_
|
|
|
|
|
|
|
|
// TODO: rename type from int to 4 byte string
|
|
|
|
// TODO: use 4 chars to idnetify plugin type
|
|
|
|
|
|
|
|
#include "r_types.h"
|
|
|
|
#include "list.h"
|
|
|
|
|
2009-09-09 00:35:00 +00:00
|
|
|
// rename to '.' ??
|
2009-09-17 09:48:36 +00:00
|
|
|
#define R_LIB_SEPARATOR "."
|
2009-09-09 00:35:00 +00:00
|
|
|
|
2009-09-19 23:03:57 +00:00
|
|
|
#define R_LIB_ENV "LIBR_PLUGINS"
|
|
|
|
|
2010-01-15 12:02:54 +00:00
|
|
|
/* XXX : This must depend on HOST_OS */
|
|
|
|
#if __WINDOWS__
|
|
|
|
#define R_LIB_EXT "dll"
|
|
|
|
#elif __APPLE__
|
|
|
|
#define R_LIB_EXT "dylib"
|
|
|
|
#else
|
|
|
|
#define R_LIB_EXT "so"
|
|
|
|
#endif
|
|
|
|
|
2009-02-05 21:08:46 +00:00
|
|
|
/* store list of loaded plugins */
|
2009-12-24 02:17:53 +00:00
|
|
|
typedef struct r_lib_plugin_t {
|
2009-02-05 21:08:46 +00:00
|
|
|
int type;
|
|
|
|
char *file;
|
|
|
|
void *data; /* user pointer */
|
|
|
|
struct r_lib_handler_t *handler;
|
|
|
|
void *dl_handler; // DL HANDLER
|
|
|
|
struct list_head list;
|
2010-04-12 00:22:52 +00:00
|
|
|
} RLibPlugin;
|
2009-02-05 21:08:46 +00:00
|
|
|
|
|
|
|
/* store list of initialized plugin handlers */
|
2009-12-24 02:17:53 +00:00
|
|
|
typedef struct r_lib_handler_t {
|
2009-02-05 21:08:46 +00:00
|
|
|
int type;
|
|
|
|
char desc[128];
|
|
|
|
void *user; /* user pointer */
|
|
|
|
int (*constructor)(struct r_lib_plugin_t *, void *user, void *data);
|
|
|
|
int (*destructor)(struct r_lib_plugin_t *, void *user, void *data);
|
|
|
|
struct list_head list;
|
2010-04-12 00:22:52 +00:00
|
|
|
} RLibHandler;
|
2009-02-05 21:08:46 +00:00
|
|
|
|
|
|
|
/* this structure should be pointed by the 'radare_plugin' symbol
|
|
|
|
found in the loaded .so */
|
2009-12-24 02:17:53 +00:00
|
|
|
typedef struct r_lib_struct_t {
|
2009-02-05 21:08:46 +00:00
|
|
|
int type;
|
|
|
|
void *data; /* pointer to data handled by plugin handler */
|
2010-04-12 00:22:52 +00:00
|
|
|
} RLibStruct;
|
2009-02-05 21:08:46 +00:00
|
|
|
|
|
|
|
enum {
|
2009-03-19 22:58:57 +00:00
|
|
|
R_LIB_TYPE_IO, /* io layer */
|
|
|
|
R_LIB_TYPE_DBG, /* debugger */
|
|
|
|
R_LIB_TYPE_LANG, /* language */
|
|
|
|
R_LIB_TYPE_ASM, /* assembler */
|
|
|
|
R_LIB_TYPE_ANAL, /* analysis */
|
|
|
|
R_LIB_TYPE_PARSE, /* parsers */
|
|
|
|
R_LIB_TYPE_BIN, /* bins */
|
2010-09-24 19:23:13 +00:00
|
|
|
R_LIB_TYPE_BIN_XTR, /* bin extractors */
|
2010-02-22 03:02:13 +00:00
|
|
|
R_LIB_TYPE_BP, /* breakpoint */
|
|
|
|
R_LIB_TYPE_SYSCALL, /* syscall */
|
|
|
|
R_LIB_TYPE_FASTCALL,/* fastcall */
|
|
|
|
R_LIB_TYPE_CRYPTO, /* cryptography */
|
|
|
|
R_LIB_TYPE_CMD, /* commands */
|
2009-04-01 01:40:04 +00:00
|
|
|
R_LIB_TYPE_LAST
|
2009-02-05 21:08:46 +00:00
|
|
|
};
|
|
|
|
|
2009-12-24 02:17:53 +00:00
|
|
|
typedef struct r_lib_t {
|
2009-02-05 21:08:46 +00:00
|
|
|
/* linked list with all the plugin handler */
|
|
|
|
/* only one handler per handler-id allowed */
|
|
|
|
/* this is checked in add_handler function */
|
|
|
|
char symname[32];
|
|
|
|
struct list_head plugins;
|
|
|
|
struct list_head handlers;
|
2010-04-12 00:22:52 +00:00
|
|
|
} RLib;
|
2009-02-05 21:08:46 +00:00
|
|
|
|
2009-12-24 02:17:53 +00:00
|
|
|
#ifdef R_API
|
2009-02-05 21:08:46 +00:00
|
|
|
/* low level api */
|
2009-09-17 09:48:36 +00:00
|
|
|
R_API void *r_lib_dl_open(const char *libname);
|
2010-05-26 16:25:35 +00:00
|
|
|
R_API void *r_lib_dl_sym(void *handler, const char *name);
|
|
|
|
R_API int r_lib_dl_close(void *handler);
|
2009-09-17 09:48:36 +00:00
|
|
|
R_API int r_lib_dl_check_filename(const char *file);
|
2009-02-05 21:08:46 +00:00
|
|
|
|
|
|
|
/* high level api */
|
2009-09-17 09:48:36 +00:00
|
|
|
R_API struct r_lib_t *r_lib_new(const char *symname);
|
2009-09-20 00:16:14 +00:00
|
|
|
R_API struct r_lib_t *r_lib_free(struct r_lib_t *lib);
|
2009-09-17 09:48:36 +00:00
|
|
|
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 );
|
2009-09-20 00:16:14 +00:00
|
|
|
R_API int r_lib_del_handler(struct r_lib_t *lib, int type);
|
2009-09-17 09:48:36 +00:00
|
|
|
R_API int r_lib_close(struct r_lib_t *lib, const char *file);
|
2009-12-24 02:17:53 +00:00
|
|
|
#endif
|
2009-02-05 21:08:46 +00:00
|
|
|
|
|
|
|
#endif
|