2014-03-27 15:34:17 +00:00
|
|
|
#ifndef R2_LIB_H
|
|
|
|
#define R2_LIB_H
|
2009-02-05 21:08:46 +00:00
|
|
|
|
|
|
|
#include "r_types.h"
|
2011-05-13 08:22:28 +00:00
|
|
|
#include "r_list.h"
|
2009-02-05 21:08:46 +00:00
|
|
|
|
2021-06-10 11:52:29 +00:00
|
|
|
#if __UNIX__ && WANT_DYLINK
|
2019-08-09 21:49:15 +00:00
|
|
|
#include <dlfcn.h>
|
|
|
|
#endif
|
|
|
|
|
2013-06-18 10:09:23 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2013-06-14 00:51:33 +00:00
|
|
|
R_LIB_VERSION_HEADER (r_lib);
|
2019-09-30 09:21:56 +00:00
|
|
|
|
2009-09-09 00:35:00 +00:00
|
|
|
// rename to '.' ??
|
2009-09-17 09:48:36 +00:00
|
|
|
#define R_LIB_SEPARATOR "."
|
2019-09-30 09:21:56 +00:00
|
|
|
#define R_LIB_SYMNAME "radare_plugin"
|
|
|
|
#define R_LIB_SYMFUNC "radare_plugin_function"
|
2009-09-09 00:35:00 +00:00
|
|
|
|
2018-08-07 20:14:54 +00:00
|
|
|
#define R_LIB_ENV "R2_LIBR_PLUGINS"
|
2009-09-19 23:03:57 +00:00
|
|
|
|
2019-08-09 21:49:15 +00:00
|
|
|
/* TODO: This must depend on HOST_OS, and maybe move into r_types */
|
2010-01-15 12:02:54 +00:00
|
|
|
#if __WINDOWS__
|
2019-08-09 21:49:15 +00:00
|
|
|
#include <windows.h>
|
2010-01-15 12:02:54 +00:00
|
|
|
#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
|
2017-02-28 01:06:46 +00:00
|
|
|
char *author;
|
|
|
|
char *version;
|
2017-07-23 21:35:45 +00:00
|
|
|
void (*free)(void *data);
|
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;
|
2019-08-09 21:49:15 +00:00
|
|
|
char desc[128]; // TODO: use char *
|
2009-02-05 21:08:46 +00:00
|
|
|
void *user; /* user pointer */
|
2012-07-21 10:11:21 +00:00
|
|
|
int (*constructor)(RLibPlugin *, void *user, void *data);
|
|
|
|
int (*destructor)(RLibPlugin *, void *user, void *data);
|
2010-04-12 00:22:52 +00:00
|
|
|
} RLibHandler;
|
2009-02-05 21:08:46 +00:00
|
|
|
|
2012-07-21 10:11:21 +00:00
|
|
|
/* this structure should be pointed by the 'radare_plugin' symbol
|
2009-02-05 21:08:46 +00:00
|
|
|
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 */
|
2015-06-21 08:09:12 +00:00
|
|
|
const char *version; /* r2 version */
|
2017-07-23 21:35:45 +00:00
|
|
|
void (*free)(void *data);
|
2020-01-15 08:49:41 +00:00
|
|
|
const char *pkgname; /* pkgname associated to this plugin */
|
2010-04-12 00:22:52 +00:00
|
|
|
} RLibStruct;
|
2009-02-05 21:08:46 +00:00
|
|
|
|
2020-01-10 14:19:56 +00:00
|
|
|
typedef RLibStruct* (*RLibStructFunc) (void);
|
2019-09-30 09:21:56 +00:00
|
|
|
|
2014-07-30 09:12:58 +00:00
|
|
|
// order matters because of libr/util/lib.c
|
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 */
|
2018-01-07 20:54:41 +00:00
|
|
|
R_LIB_TYPE_BIN, /* bin headers */
|
2010-09-24 19:23:13 +00:00
|
|
|
R_LIB_TYPE_BIN_XTR, /* bin extractors */
|
2018-01-07 20:54:41 +00:00
|
|
|
R_LIB_TYPE_BIN_LDR, /* bin loaders */
|
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 */
|
2014-04-01 15:09:07 +00:00
|
|
|
R_LIB_TYPE_CORE, /* RCore commands */
|
2011-11-13 03:08:08 +00:00
|
|
|
R_LIB_TYPE_EGG, /* r_egg plugin */
|
2016-02-21 01:32:28 +00:00
|
|
|
R_LIB_TYPE_FS, /* r_fs plugin */
|
2021-01-24 15:39:45 +00:00
|
|
|
R_LIB_TYPE_ESIL, /* r_anal.esil plugin */
|
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 */
|
2019-08-09 21:49:15 +00:00
|
|
|
char *symname;
|
2019-09-30 09:21:56 +00:00
|
|
|
char *symnamefunc;
|
2011-05-13 08:22:28 +00:00
|
|
|
RList /*RLibPlugin*/ *plugins;
|
|
|
|
RList /*RLibHandler*/ *handlers;
|
2021-03-03 17:03:58 +00:00
|
|
|
bool ignore_version;
|
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);
|
2019-09-30 09:21:56 +00:00
|
|
|
|
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-02-05 21:08:46 +00:00
|
|
|
|
|
|
|
/* high level api */
|
2019-08-09 21:49:15 +00:00
|
|
|
typedef int (*RLibCallback)(RLibPlugin *, void *, void *);
|
2019-09-30 09:21:56 +00:00
|
|
|
R_API RLib *r_lib_new(const char *symname, const char *symnamefunc);
|
2019-08-09 21:49:15 +00:00
|
|
|
R_API void r_lib_free(RLib *lib);
|
2012-07-21 10:11:21 +00:00
|
|
|
R_API int r_lib_run_handler(RLib *lib, RLibPlugin *plugin, RLibStruct *symbol);
|
2012-06-06 09:48:40 +00:00
|
|
|
R_API RLibHandler *r_lib_get_handler(RLib *lib, int type);
|
|
|
|
R_API int r_lib_open(RLib *lib, const char *file);
|
2019-08-09 21:49:15 +00:00
|
|
|
R_API bool r_lib_opendir(RLib *lib, const char *path);
|
2021-12-21 18:52:17 +00:00
|
|
|
R_API int r_lib_open_ptr(RLib *lib, const char *file, void *handler, RLibStruct *stru);
|
2011-08-27 18:25:37 +00:00
|
|
|
R_API char *r_lib_path(const char *libname);
|
2012-06-06 09:48:40 +00:00
|
|
|
R_API void r_lib_list(RLib *lib);
|
2019-08-09 21:49:15 +00:00
|
|
|
R_API bool r_lib_add_handler(RLib *lib, int type, const char *desc, RLibCallback ct, RLibCallback dt, void *user);
|
2018-01-07 20:54:41 +00:00
|
|
|
R_API bool r_lib_del_handler(RLib *lib, int type);
|
2012-06-06 09:48:40 +00:00
|
|
|
R_API int r_lib_close(RLib *lib, const char *file);
|
2014-07-30 09:12:58 +00:00
|
|
|
|
|
|
|
R_API const char *r_lib_types_get(int idx);
|
|
|
|
R_API int r_lib_types_get_i(const char *str);
|
2009-12-24 02:17:53 +00:00
|
|
|
#endif
|
2009-02-05 21:08:46 +00:00
|
|
|
|
2013-06-18 10:09:23 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-02-05 21:08:46 +00:00
|
|
|
#endif
|