2017-05-23 09:24:04 +00:00
|
|
|
/* radare - LGPL - Copyright 2009-2017 - pancake */
|
2009-04-01 00:28:13 +00:00
|
|
|
|
|
|
|
#include "r_core.h"
|
2017-05-26 00:43:26 +00:00
|
|
|
#include "config.h"
|
2009-04-01 00:28:13 +00:00
|
|
|
|
2017-03-25 01:30:00 +00:00
|
|
|
#define CB(x, y)\
|
|
|
|
static int __lib_ ## x ## _cb (RLibPlugin * pl, void *user, void *data) {\
|
|
|
|
struct r_ ## x ## _plugin_t *hand = (struct r_ ## x ## _plugin_t *)data;\
|
|
|
|
RCore *core = (RCore *) user;\
|
2017-09-25 14:05:42 +00:00
|
|
|
pl->free = NULL; \
|
2017-03-25 01:30:00 +00:00
|
|
|
r_ ## x ## _add (core->y, hand);\
|
|
|
|
return true;\
|
|
|
|
}\
|
|
|
|
static int __lib_ ## x ## _dt (RLibPlugin * pl, void *p, void *u) { return true; }
|
2013-01-22 04:06:12 +00:00
|
|
|
|
2017-03-25 01:30:00 +00:00
|
|
|
#define CB_COPY(x, y)\
|
|
|
|
static int __lib_ ## x ## _cb (RLibPlugin * pl, void *user, void *data) {\
|
|
|
|
struct r_ ## x ## _plugin_t *hand = (struct r_ ## x ## _plugin_t *)data;\
|
|
|
|
struct r_ ## x ## _plugin_t *instance;\
|
|
|
|
RCore *core = (RCore *) user;\
|
|
|
|
instance = R_NEW (struct r_ ## x ## _plugin_t);\
|
|
|
|
memcpy (instance, hand, sizeof (struct r_ ## x ## _plugin_t));\
|
|
|
|
r_ ## x ## _add (core->y, instance);\
|
|
|
|
return true;\
|
|
|
|
}\
|
|
|
|
static int __lib_ ## x ## _dt (RLibPlugin * pl, void *p, void *u) { return true; }
|
2016-09-09 17:30:23 +00:00
|
|
|
|
2013-01-22 04:06:12 +00:00
|
|
|
// XXX api consistency issues
|
|
|
|
#define r_io_add r_io_plugin_add
|
2016-09-09 17:30:23 +00:00
|
|
|
CB_COPY (io, io)
|
2014-04-01 15:09:07 +00:00
|
|
|
#define r_core_add r_core_plugin_add
|
|
|
|
CB (core, rcmd)
|
2013-01-22 04:06:12 +00:00
|
|
|
#define r_debug_add r_debug_plugin_add
|
|
|
|
CB (debug, dbg)
|
|
|
|
#define r_bp_add r_bp_plugin_add
|
|
|
|
CB (bp, dbg->bp)
|
|
|
|
CB (lang, lang)
|
|
|
|
CB (anal, anal)
|
|
|
|
CB (asm, assembler)
|
|
|
|
CB (parse, parser)
|
|
|
|
CB (bin, bin)
|
|
|
|
CB (egg, egg)
|
2016-02-21 01:32:28 +00:00
|
|
|
CB (fs, fs)
|
2011-11-13 03:08:08 +00:00
|
|
|
|
2014-04-03 10:42:53 +00:00
|
|
|
R_API void r_core_loadlibs_init(RCore *core) {
|
2017-03-25 01:30:00 +00:00
|
|
|
ut64 prev = r_sys_now ();
|
|
|
|
#define DF(x, y, z) r_lib_add_handler (core->lib, R_LIB_TYPE_ ## x, y, &__lib_ ## z ## _cb, &__lib_ ## z ## _dt, core);
|
2014-04-03 10:42:53 +00:00
|
|
|
core->lib = r_lib_new ("radare_plugin");
|
|
|
|
DF (IO, "io plugins", io);
|
|
|
|
DF (CORE, "core plugins", core);
|
|
|
|
DF (DBG, "debugger plugins", debug);
|
|
|
|
DF (BP, "debugger breakpoint plugins", bp);
|
|
|
|
DF (LANG, "language plugins", lang);
|
|
|
|
DF (ANAL, "analysis plugins", anal);
|
|
|
|
DF (ASM, "(dis)assembler plugins", asm);
|
|
|
|
DF (PARSE, "parsing plugins", parse);
|
|
|
|
DF (BIN, "bin plugins", bin);
|
|
|
|
DF (EGG, "egg plugins", egg);
|
2016-02-21 01:32:28 +00:00
|
|
|
DF (FS, "fs plugins", fs);
|
2016-03-18 12:39:45 +00:00
|
|
|
core->times->loadlibs_init_time = r_sys_now () - prev;
|
2009-04-01 00:28:13 +00:00
|
|
|
}
|
|
|
|
|
2014-04-03 10:42:53 +00:00
|
|
|
R_API int r_core_loadlibs(RCore *core, int where, const char *path) {
|
2017-03-25 01:30:00 +00:00
|
|
|
ut64 prev = r_sys_now ();
|
2015-04-09 22:17:30 +00:00
|
|
|
#if R2_LOADLIBS
|
2018-12-18 17:24:09 +00:00
|
|
|
char *p = NULL;
|
2009-04-01 22:44:43 +00:00
|
|
|
/* TODO: all those default plugin paths should be defined in r_lib */
|
2015-03-11 01:59:33 +00:00
|
|
|
if (!r_config_get_i (core->config, "cfg.plugins")) {
|
2016-03-18 12:39:45 +00:00
|
|
|
core->times->loadlibs_time = 0;
|
2015-09-14 10:35:38 +00:00
|
|
|
return false;
|
2015-03-11 01:59:33 +00:00
|
|
|
}
|
2017-03-25 01:30:00 +00:00
|
|
|
if (!where) {
|
|
|
|
where = -1;
|
|
|
|
}
|
|
|
|
if (path) {
|
|
|
|
r_lib_opendir (core->lib, path);
|
|
|
|
}
|
2015-03-11 01:59:33 +00:00
|
|
|
if (where & R_CORE_LOADLIBS_CONFIG) {
|
2014-04-03 10:42:53 +00:00
|
|
|
r_lib_opendir (core->lib, r_config_get (core->config, "dir.plugins"));
|
2015-03-11 01:59:33 +00:00
|
|
|
}
|
|
|
|
if (where & R_CORE_LOADLIBS_ENV) {
|
2016-04-10 19:28:05 +00:00
|
|
|
p = r_sys_getenv (R_LIB_ENV);
|
2017-03-25 01:30:00 +00:00
|
|
|
if (p && *p) {
|
2016-04-10 19:28:05 +00:00
|
|
|
r_lib_opendir (core->lib, p);
|
2017-03-25 01:30:00 +00:00
|
|
|
}
|
2016-04-10 19:28:05 +00:00
|
|
|
free (p);
|
2015-03-11 01:59:33 +00:00
|
|
|
}
|
2014-04-03 10:42:53 +00:00
|
|
|
if (where & R_CORE_LOADLIBS_HOME) {
|
2018-04-28 08:02:55 +00:00
|
|
|
char *homeplugindir = r_str_home (R2_HOME_PLUGINS);
|
2015-02-11 01:05:22 +00:00
|
|
|
// eprintf ("OPENDIR (%s)\n", homeplugindir);
|
2014-04-03 10:42:53 +00:00
|
|
|
r_lib_opendir (core->lib, homeplugindir);
|
|
|
|
free (homeplugindir);
|
|
|
|
}
|
2015-01-02 23:41:48 +00:00
|
|
|
if (where & R_CORE_LOADLIBS_SYSTEM) {
|
2018-05-02 13:58:14 +00:00
|
|
|
char *plugindir = r_str_r2_prefix (R2_PLUGINS);
|
|
|
|
char *extrasdir = r_str_r2_prefix (R2_EXTRAS);
|
|
|
|
char *bindingsdir = r_str_r2_prefix (R2_BINDINGS);
|
|
|
|
r_lib_opendir (core->lib, plugindir);
|
|
|
|
r_lib_opendir (core->lib, extrasdir);
|
|
|
|
r_lib_opendir (core->lib, bindingsdir);
|
|
|
|
free (plugindir);
|
|
|
|
free (extrasdir);
|
|
|
|
free (bindingsdir);
|
2015-01-02 23:41:48 +00:00
|
|
|
}
|
2015-04-09 22:17:30 +00:00
|
|
|
#endif
|
2017-05-23 02:10:40 +00:00
|
|
|
// load script plugins
|
2018-04-28 08:02:55 +00:00
|
|
|
char *homeplugindir = r_str_home (R2_HOME_PLUGINS);
|
2017-05-23 02:10:40 +00:00
|
|
|
RList *files = r_sys_dir (homeplugindir);
|
|
|
|
RListIter *iter;
|
|
|
|
char *file;
|
|
|
|
r_list_foreach (files, iter, file) {
|
|
|
|
bool isScript = r_str_endswith (file, ".py") || r_str_endswith (file, ".js") || r_str_endswith (file, ".lua");
|
|
|
|
if (isScript) {
|
|
|
|
// eprintf ("-> %s\n", file);
|
|
|
|
r_core_cmdf (core, ". %s/%s", homeplugindir, file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free (homeplugindir);
|
2017-03-25 01:30:00 +00:00
|
|
|
core->times->loadlibs_time = r_sys_now () - prev;
|
2017-05-23 09:24:04 +00:00
|
|
|
r_list_free (files);
|
2015-09-14 10:35:38 +00:00
|
|
|
return true;
|
2009-04-01 00:28:13 +00:00
|
|
|
}
|