Plugins are now loaded from API, not from Core constructor

This commit is contained in:
pancake 2014-04-03 12:42:53 +02:00
parent 94bcf930ee
commit 08d94e38e1
8 changed files with 43 additions and 30 deletions

View File

@ -15,6 +15,7 @@ static void _libwrap_init() {
printf ("libr2 initialized. send SIGUSR1 to %d in order to reach the r2 prompt\n", getpid ());
printf ("kill -USR1 %d\n", getpid());
core = r_core_new ();
r_core_loadlibs (core, R_CORE_LOADLIBS_ALL, NULL);
// TODO: maybe reopen every time a signal is spawned to reload memory regions information
// TODO: open io_self
}

View File

@ -221,6 +221,7 @@ int main(int argc, char **argv, char **envp) {
return 0;
}
r_core_init (&r);
r_core_loadlibs (&r, R_CORE_LOADLIBS_ALL, NULL);
while ((c = getopt (argc, argv, "ACwfhm:e:nk:Ndqs:p:b:B:a:Lui:l:P:c:D:vV:S"
#if USE_THREADS
"t"

View File

@ -58,6 +58,7 @@ static int cb(RDiff *d, void *user, RDiffOp *op) {
static RCore* opencore(const char *f) {
const ut64 baddr = 0;
RCore *c = r_core_new ();
r_core_loadlibs (c, R_CORE_LOADLIBS_ALL, NULL);
r_config_set_i (c->config, "io.va", useva);
r_config_set_i (c->config, "anal.split", R_TRUE);
if (r_core_file_open (c, f, 0, 0) == NULL) {

View File

@ -331,6 +331,7 @@ static int cmd_cmp(void *data, const char *input) {
eprintf ("Cannot init diff core\n");
return R_FALSE;
}
r_core_loadlibs (core2, R_CORE_LOADLIBS_ALL, NULL);
core2->io->va = core->io->va;
core2->anal->split = core->anal->split;
if (!r_core_file_open (core2, file2, 0, 0LL)) {

View File

@ -587,8 +587,8 @@ R_API int r_core_init(RCore *core) {
r_core_config_init (core);
/* load plugins */
r_core_loadlibs (core);
r_core_loadlibs_init (core);
//r_core_loadlibs (core);
// TODO: get arch from r_bin or from native arch
r_asm_use (core->assembler, R_SYS_ARCH);

View File

@ -27,33 +27,35 @@ CB (parse, parser)
CB (bin, bin)
CB (egg, egg)
R_API int r_core_loadlibs_init(RCore *core) {
R_API void r_core_loadlibs_init(RCore *core) {
#define DF(x,y,z) r_lib_add_handler(core->lib, R_LIB_TYPE_##x,y,&__lib_##z##_cb, &__lib_##z##_dt, core);
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);
return R_TRUE;
}
R_API int r_core_loadlibs(struct r_core_t *core) {
/* TODO: all those default plugin paths should be defined in r_lib */
char *homeplugindir = r_str_home (R2_HOMEDIR"/plugins");
core->lib = r_lib_new ("radare_plugin");
r_core_loadlibs_init (core);
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);
}
R_API int r_core_loadlibs(RCore *core, int where, const char *path) {
/* TODO: all those default plugin paths should be defined in r_lib */
if (!where) where = -1;
if (path) r_lib_opendir (core->lib, path);
if (where & R_CORE_LOADLIBS_CONFIG)
r_lib_opendir (core->lib, r_config_get (core->config, "dir.plugins"));
if (where & R_CORE_LOADLIBS_ENV)
r_lib_opendir (core->lib, getenv (R_LIB_ENV));
// !!!! // r_lib_opendir (core->lib, ".");
if (where & R_CORE_LOADLIBS_HOME) {
char *homeplugindir = r_str_home (R2_HOMEDIR"/plugins");
r_lib_opendir (core->lib, homeplugindir);
r_lib_opendir (core->lib, R2_LIBDIR"/radare2/"R2_VERSION);
free (homeplugindir);
}
if (where & R_CORE_LOADLIBS_SYSTEM)
r_lib_opendir (core->lib, R2_LIBDIR"/radare2/"R2_VERSION);
return R_TRUE;
}

View File

@ -73,7 +73,7 @@ static int perform_mapped_file_yank (RCore *core, ut64 offset, ut64 len, const c
if (len == -1) len = yank_file_sz;
IFDBG eprintf ("yankfd: %p, yank->fd = %d, fd=%d\n", yankfd,
(yankfd ? yankfd->fd : -1), fd);
(int)(yankfd ? yankfd->fd : -1), (int)fd);
// this wont happen if the file failed to open or the file failed to
// map into the IO layer
if (yankfd) {

View File

@ -238,7 +238,14 @@ R_API int r_core_yank_hud_path (RCore *core, const char *input, int dir);
R_API int r_core_yank_file_ex (RCore *core, const char *input);
R_API int r_core_yank_file_all (RCore *core, const char *input);
R_API int r_core_loadlibs(RCore *core);
#define R_CORE_LOADLIBS_ENV 1
#define R_CORE_LOADLIBS_HOME 2
#define R_CORE_LOADLIBS_SYSTEM 4
#define R_CORE_LOADLIBS_CONFIG 8
#define R_CORE_LOADLIBS_ALL -1
R_API void r_core_loadlibs_init(RCore *core);
R_API int r_core_loadlibs(RCore *core, int where, const char *path);
// FIXME: change (void *user) -> (RCore *core)
R_API int r_core_cmd_buffer(void *user, const char *buf);
R_API int r_core_cmdf(void *user, const char *fmt, ...);