radare2/libr/debug/plugin.c

115 lines
2.6 KiB
C
Raw Normal View History

/* radare - LGPL - Copyright 2009-2017 pancake */
#include <r_debug.h>
#include <config.h>
static RDebugPlugin *debug_static_plugins[] = {
R_DEBUG_STATIC_PLUGINS
};
2015-12-04 02:57:56 +01:00
R_API void r_debug_plugin_init(RDebug *dbg) {
int i;
dbg->plugins = r_list_newf (free);
for (i = 0; debug_static_plugins[i]; i++) {
r_debug_plugin_add (dbg, debug_static_plugins[i]);
}
}
2015-12-04 02:57:56 +01:00
R_API bool r_debug_use(RDebug *dbg, const char *str) {
2019-09-16 00:13:59 +03:00
if (dbg && str) {
RDebugPlugin *h;
RListIter *iter;
r_list_foreach (dbg->plugins, iter, h) {
2015-12-04 02:57:56 +01:00
if (h->name && !strcmp (str, h->name)) {
dbg->h = h;
if (dbg->anal && dbg->anal->cur) {
2015-12-04 02:57:56 +01:00
r_debug_set_arch (dbg, dbg->anal->cur->arch, dbg->bits);
}
2015-12-04 02:57:56 +01:00
dbg->bp->breakpoint = dbg->h->breakpoint;
dbg->bp->user = dbg;
}
}
}
if (dbg && dbg->h && dbg->h->reg_profile) {
2011-05-07 18:19:16 +02:00
char *p = dbg->h->reg_profile (dbg);
2015-12-04 02:57:56 +01:00
if (p) {
r_reg_set_profile_string (dbg->reg, p);
if (dbg->anal && dbg->reg != dbg->anal->reg) {
r_reg_free (dbg->anal->reg);
dbg->anal->reg = dbg->reg;
2016-04-13 17:24:23 +05:30
}
2017-08-18 23:02:53 +05:30
if (dbg->h->init) {
dbg->h->init (dbg);
2017-08-18 23:02:53 +05:30
}
r_reg_set_profile_string (dbg->reg, p);
2014-09-10 02:21:10 +02:00
free (p);
2015-12-04 02:57:56 +01:00
} else {
eprintf ("Cannot retrieve reg profile from debug plugin (%s)\n", dbg->h->name);
}
}
return (dbg && dbg->h);
}
2021-01-24 10:07:30 -05:00
R_API bool r_debug_plugin_list(RDebug *dbg, int mode) {
2015-06-12 03:04:09 +02:00
char spaces[16];
int count = 0;
2015-06-12 03:04:09 +02:00
memset (spaces, ' ', 15);
spaces[15] = 0;
RDebugPlugin *h;
RListIter *iter;
2021-01-24 10:07:30 -05:00
PJ *pj = NULL;
if (mode == 'j') {
2021-01-24 10:07:30 -05:00
pj = dbg->pj;
if (!pj) {
return false;
}
pj_a (pj);
}
r_list_foreach (dbg->plugins, iter, h) {
2015-06-12 03:04:09 +02:00
int sp = 8-strlen (h->name);
spaces[sp] = 0;
2016-10-04 14:34:06 +02:00
if (mode == 'q') {
dbg->cb_printf ("%s\n", h->name);
} else if (mode == 'j') {
2021-01-24 10:07:30 -05:00
pj_o (pj);
pj_ks (pj, "name", h->name);
pj_ks (pj, "license", h->license);
pj_end (pj);
2016-10-04 14:34:06 +02:00
} else {
dbg->cb_printf ("%d %s %s %s%s\n",
count, (h == dbg->h)? "dbg": "---",
h->name, spaces, h->license);
}
2015-06-12 03:04:09 +02:00
spaces[sp] = ' ';
count++;
}
if (mode == 'j') {
2021-01-24 10:07:30 -05:00
pj_end (pj);
dbg->cb_printf ("%s\n", pj_string (pj));
}
2021-01-24 10:07:30 -05:00
return true;
}
2015-12-04 02:57:56 +01:00
R_API bool r_debug_plugin_add(RDebug *dbg, RDebugPlugin *foo) {
if (!dbg || !foo || !foo->name) {
return false;
}
RDebugPlugin *dp = R_NEW (RDebugPlugin);
memcpy (dp, foo, sizeof (RDebugPlugin));
r_list_append (dbg->plugins, dp);
2015-12-04 02:57:56 +01:00
return true;
}
R_API bool r_debug_plugin_set_reg_profile(RDebug *dbg, const char *profile) {
char *str = r_file_slurp (profile, NULL);
if (!str) {
eprintf ("r_debug_plugin_set_reg_profile: Cannot find '%s'\n", profile);
return false;
}
if (dbg && dbg->h && dbg->h->set_reg_profile) {
return dbg->h->set_reg_profile (str);
}
free (str);
return false;
}