2018-05-26 18:25:05 +02:00
|
|
|
/* radare - LGPL - Copyright 2010-2018 - pancake */
|
2010-02-26 00:37:49 +01:00
|
|
|
|
|
|
|
/* covardly copied from r_cmd */
|
|
|
|
|
2017-05-26 02:43:26 +02:00
|
|
|
#include <config.h>
|
2014-03-18 00:05:44 +01:00
|
|
|
#include <r_core.h>
|
2010-02-26 00:37:49 +01:00
|
|
|
#include <r_cmd.h>
|
|
|
|
#include <r_list.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2017-03-25 02:30:00 +01:00
|
|
|
static RCorePlugin *cmd_static_plugins[] = {
|
|
|
|
R_CORE_STATIC_PLUGINS
|
|
|
|
};
|
2010-02-26 00:37:49 +01:00
|
|
|
|
2018-05-26 18:25:05 +02:00
|
|
|
R_API int r_core_plugin_fini(RCmd *cmd) {
|
2014-04-28 10:40:09 -05:00
|
|
|
RListIter *iter;
|
|
|
|
RCorePlugin *plugin;
|
2016-06-17 14:26:24 +02:00
|
|
|
if (!cmd->plist) {
|
2015-09-14 12:35:38 +02:00
|
|
|
return false;
|
2016-06-17 14:26:24 +02:00
|
|
|
}
|
2014-04-28 10:40:09 -05:00
|
|
|
r_list_foreach (cmd->plist, iter, plugin) {
|
2018-05-26 18:25:05 +02:00
|
|
|
if (plugin && plugin->fini) {
|
|
|
|
plugin->fini (cmd, NULL);
|
2014-04-28 10:40:09 -05:00
|
|
|
}
|
|
|
|
}
|
2014-11-18 16:35:12 +01:00
|
|
|
/* empty the list */
|
|
|
|
r_list_free (cmd->plist);
|
|
|
|
cmd->plist = NULL;
|
2015-09-14 12:35:38 +02:00
|
|
|
return true;
|
2014-04-28 10:40:09 -05:00
|
|
|
}
|
|
|
|
|
2014-04-01 17:09:07 +02:00
|
|
|
R_API int r_core_plugin_add(RCmd *cmd, RCorePlugin *plugin) {
|
2018-01-16 11:13:21 +01:00
|
|
|
if (!cmd || (plugin && plugin->init && !plugin->init (cmd, NULL))) {
|
2015-09-14 12:35:38 +02:00
|
|
|
return false;
|
2016-06-17 14:26:24 +02:00
|
|
|
}
|
2010-02-26 00:37:49 +01:00
|
|
|
r_list_append (cmd->plist, plugin);
|
2015-09-14 12:35:38 +02:00
|
|
|
return true;
|
2010-02-26 00:37:49 +01:00
|
|
|
}
|
|
|
|
|
2014-04-01 17:09:07 +02:00
|
|
|
R_API int r_core_plugin_init(RCmd *cmd) {
|
2010-02-26 00:37:49 +01:00
|
|
|
int i;
|
2014-11-18 16:35:12 +01:00
|
|
|
cmd->plist = r_list_newf (NULL); // memleak or dblfree
|
2017-03-25 02:30:00 +01:00
|
|
|
for (i = 0; cmd_static_plugins[i]; i++) {
|
2014-04-01 17:09:07 +02:00
|
|
|
if (!r_core_plugin_add (cmd, cmd_static_plugins[i])) {
|
2010-02-26 00:37:49 +01:00
|
|
|
eprintf ("Error loading cmd plugin\n");
|
2015-09-14 12:35:38 +02:00
|
|
|
return false;
|
2010-02-26 00:37:49 +01:00
|
|
|
}
|
2010-05-28 02:44:51 +02:00
|
|
|
}
|
2015-09-14 12:35:38 +02:00
|
|
|
return true;
|
2010-02-26 00:37:49 +01:00
|
|
|
}
|
|
|
|
|
2014-04-01 17:09:07 +02:00
|
|
|
R_API int r_core_plugin_check(RCmd *cmd, const char *a0) {
|
2010-02-26 00:37:49 +01:00
|
|
|
RListIter *iter;
|
2014-04-01 17:09:07 +02:00
|
|
|
RCorePlugin *cp;
|
2012-02-14 18:19:16 +01:00
|
|
|
r_list_foreach (cmd->plist, iter, cp) {
|
2016-06-17 14:26:24 +02:00
|
|
|
if (cp->call (NULL, a0)) {
|
2015-09-14 12:35:38 +02:00
|
|
|
return true;
|
2016-06-17 14:26:24 +02:00
|
|
|
}
|
2010-02-26 00:37:49 +01:00
|
|
|
}
|
2015-09-14 12:35:38 +02:00
|
|
|
return false;
|
2010-02-26 00:37:49 +01:00
|
|
|
}
|