mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-21 06:40:33 +00:00
Refactor RDebugPlugin access solving a null deref in plugin-less builds
This commit is contained in:
parent
c095845c3e
commit
a62d03c2e1
@ -963,7 +963,8 @@ static bool cb_asmbits(void *user, void *data) {
|
||||
r_debug_set_arch (core->dbg, core->anal->config->arch, bits);
|
||||
const bool load_from_debug = r_config_get_b (core->config, "cfg.debug");
|
||||
if (load_from_debug) {
|
||||
if (core->dbg->current && core->dbg->current->plugin.reg_profile) {
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (core->dbg, current, plugin);
|
||||
if (plugin && plugin->reg_profile) {
|
||||
// XXX. that should depend on the plugin, not the host os
|
||||
#if R2__WINDOWS__
|
||||
#if !defined(_WIN64)
|
||||
@ -972,7 +973,7 @@ static bool cb_asmbits(void *user, void *data) {
|
||||
core->dbg->bits = R_SYS_BITS_64;
|
||||
#endif
|
||||
#endif
|
||||
char *rp = core->dbg->current->plugin.reg_profile (core->dbg);
|
||||
char *rp = plugin->reg_profile (core->dbg);
|
||||
if (rp) {
|
||||
r_reg_set_profile_string (core->dbg->reg, rp);
|
||||
r_reg_set_profile_string (core->anal->reg, rp);
|
||||
|
@ -938,10 +938,8 @@ R_API RIODesc *r_core_file_open(RCore *r, const char *file, int flags, ut64 load
|
||||
|
||||
r_esil_setup (r->anal->esil, r->anal, 0, 0, false);
|
||||
if (r_config_get_b (r->config, "cfg.debug")) {
|
||||
bool swstep = true;
|
||||
if (r->dbg->current && r->dbg->current->plugin.canstep) {
|
||||
swstep = false;
|
||||
}
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (r->dbg, current, plugin);
|
||||
const bool swstep = (plugin && plugin->canstep)? false: true;
|
||||
r_config_set_b (r->config, "dbg.swstep", swstep);
|
||||
// Set the correct debug handle
|
||||
if (fd->plugin && fd->plugin->isdbg) {
|
||||
|
@ -5192,14 +5192,17 @@ static RList *foreach3list(RCore *core, char type, const char *glob) {
|
||||
}
|
||||
break;
|
||||
case 't': // @@@t
|
||||
// iterate over all threads
|
||||
if (core->dbg && core->dbg->current && core->dbg->current->plugin.threads) {
|
||||
RDebugPid *p;
|
||||
RList *thlist = core->dbg->current->plugin.threads (core->dbg, core->dbg->pid);
|
||||
r_list_foreach (thlist, iter, p) {
|
||||
append_item (list, NULL, (ut64)p->pid, UT64_MAX);
|
||||
{
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (core->dbg, current, plugin);
|
||||
// iterate over all threads
|
||||
if (plugin && plugin->threads) {
|
||||
RDebugPid *p;
|
||||
RList *thlist = plugin->threads (core->dbg, core->dbg->pid);
|
||||
r_list_foreach (thlist, iter, p) {
|
||||
append_item (list, NULL, (ut64)p->pid, UT64_MAX);
|
||||
}
|
||||
r_list_free (thlist);
|
||||
}
|
||||
r_list_free (thlist);
|
||||
}
|
||||
break;
|
||||
case 'i': // @@@i
|
||||
@ -5423,7 +5426,7 @@ R_API int r_core_cmd_foreach3(RCore *core, const char *cmd, char *each) { // "@@
|
||||
break;
|
||||
case 't':
|
||||
// TODO: generalize like the rest, just call dp before and after
|
||||
if (core->dbg && core->dbg->current && core->dbg->current->plugin.threads) {
|
||||
{
|
||||
int origpid = core->dbg->pid;
|
||||
r_list_foreach (list, iter, item) {
|
||||
int curpid = (int) item->addr;
|
||||
@ -5727,8 +5730,9 @@ R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each) {
|
||||
{
|
||||
RDebugPid *p;
|
||||
int pid = core->dbg->pid;
|
||||
if (core->dbg->current && core->dbg->current->plugin.pids) {
|
||||
RList *list = core->dbg->current->plugin.pids (core->dbg, R_MAX (0, pid));
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (core->dbg, current, plugin);
|
||||
if (plugin && plugin->pids) {
|
||||
RList *list = plugin->pids (core->dbg, R_MAX (0, pid));
|
||||
r_list_foreach (list, iter, p) {
|
||||
r_cons_printf ("# PID %d\n", p->pid);
|
||||
r_debug_select (core->dbg, p->pid, p->pid);
|
||||
|
@ -13267,8 +13267,8 @@ static int cmd_anal_all(RCore *core, const char *input) {
|
||||
|
||||
// Run pending analysis immediately after analysis
|
||||
// Usefull when running commands with ";" or via r2 -c,-i
|
||||
dh_orig = core->dbg->current
|
||||
? strdup (core->dbg->current->plugin.meta.name)
|
||||
dh_orig = (core->dbg->current && core->dbg->current->plugin)
|
||||
? strdup (core->dbg->current->plugin->meta.name)
|
||||
: strdup ("esil");
|
||||
if (core->io->desc && core->io->desc->plugin && !core->io->desc->plugin->isdbg) {
|
||||
//use dh_origin if we are debugging
|
||||
|
@ -1136,8 +1136,11 @@ static void cmd_debug_pid(RCore *core, const char *input) {
|
||||
}
|
||||
}
|
||||
r_debug_select (core->dbg, core->dbg->pid, core->dbg->tid);
|
||||
r_config_set_i (core->config, "dbg.swstep",
|
||||
(core->dbg->current && !core->dbg->current->plugin.canstep));
|
||||
{
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (core->dbg, current, plugin);
|
||||
const bool canstep = (plugin && plugin->canstep);
|
||||
r_config_set_i (core->config, "dbg.swstep", canstep);
|
||||
}
|
||||
r_core_cmdf (core, ":pid %d", core->dbg->pid);
|
||||
break;
|
||||
case 'f': // "dpf"
|
||||
@ -2193,9 +2196,9 @@ static void cmd_reg_profile(RCore *core, char from, const char *str) { // "arp"
|
||||
const bool cfg_debug = r_config_get_b (core->config, "cfg.debug");
|
||||
if (cfg_debug) {
|
||||
// XXX bas practice
|
||||
char* (*reg_profile)(RDebug *dbg) = R_UNWRAP2 (core->dbg->current, plugin.reg_profile);
|
||||
if (reg_profile) {
|
||||
char *rp = reg_profile (core->dbg);
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (core->dbg, current, plugin);
|
||||
if (plugin && plugin->reg_profile) {
|
||||
char *rp = plugin->reg_profile (core->dbg);
|
||||
r_reg_set_profile_string (core->dbg->reg, rp);
|
||||
free (rp);
|
||||
}
|
||||
@ -5866,7 +5869,7 @@ static int cmd_debug(void *data, const char *input) {
|
||||
r_core_debug_esil (core, input + 1);
|
||||
break;
|
||||
case 'g': // "dg"
|
||||
if (core->dbg->current && core->dbg->current->plugin.gcore) {
|
||||
if (core->dbg->current && core->dbg->current->plugin && core->dbg->current->plugin->gcore) {
|
||||
if (core->dbg->pid == -1) {
|
||||
R_LOG_ERROR ("Not debugging, can't write core");
|
||||
break;
|
||||
@ -5876,7 +5879,7 @@ static int cmd_debug(void *data, const char *input) {
|
||||
r_file_rm (corefile);
|
||||
RBuffer *dst = r_buf_new_file (corefile, O_RDWR | O_CREAT, 0644);
|
||||
if (dst) {
|
||||
if (!core->dbg->current->plugin.gcore (core->dbg, dst)) {
|
||||
if (!core->dbg->current->plugin->gcore (core->dbg, dst)) {
|
||||
R_LOG_ERROR ("dg: coredump failed");
|
||||
}
|
||||
r_buf_free (dst);
|
||||
@ -5941,8 +5944,9 @@ static int cmd_debug(void *data, const char *input) {
|
||||
core->dbg->session = NULL;
|
||||
}
|
||||
// Kill debugee and all child processes
|
||||
if (core->dbg && core->dbg->current && core->dbg->current->plugin.pids && core->dbg->pid != -1) {
|
||||
list = core->dbg->current->plugin.pids (core->dbg, core->dbg->pid);
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (core->dbg, current, plugin);
|
||||
if (plugin && plugin->pids && core->dbg->pid != -1) {
|
||||
list = plugin->pids (core->dbg, core->dbg->pid);
|
||||
if (list) {
|
||||
r_list_foreach (list, iter, p) {
|
||||
r_debug_kill (core->dbg, p->pid, p->pid, SIGKILL);
|
||||
|
@ -8078,22 +8078,24 @@ static int cmd_print(void *data, const char *input) {
|
||||
case 'k': // "pk"
|
||||
if (input[1] == '?') {
|
||||
r_core_cmd_help_contains (core, help_msg_p, "pk");
|
||||
} else if (!strncmp (input, "kill", 4)) {
|
||||
} else if (r_str_startswith (input, "kill")) {
|
||||
RListIter *iter;
|
||||
RDebugPid *pid;
|
||||
const char *arg = strchr (input, ' ');
|
||||
RList *pids = (core->dbg->current && core->dbg->current->plugin.pids)
|
||||
? core->dbg->current->plugin.pids (core->dbg, 0): NULL;
|
||||
if (R_STR_ISNOTEMPTY (arg)) {
|
||||
arg++;
|
||||
r_list_foreach (pids, iter, pid) {
|
||||
if (strstr (pid->path, arg)) {
|
||||
r_cons_printf ("dk 9 %d\n", pid->pid);
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (core->dbg, current, plugin);
|
||||
if (plugin && plugin->pids) {
|
||||
RList *pids = plugin->pids (core->dbg, 0);
|
||||
if (pids && R_STR_ISNOTEMPTY (arg)) {
|
||||
arg++;
|
||||
r_list_foreach (pids, iter, pid) {
|
||||
if (strstr (pid->path, arg)) {
|
||||
r_cons_printf ("dk 9 %d\n", pid->pid);
|
||||
}
|
||||
// r_debug_kill (core->dbg, pid->pid, pid->pid, 9); // kill -9
|
||||
}
|
||||
// r_debug_kill (core->dbg, pid->pid, pid->pid, 9); // kill -9
|
||||
}
|
||||
r_list_free (pids);
|
||||
}
|
||||
r_list_free (pids);
|
||||
} else if (l > 0) {
|
||||
len = len > core->blocksize? core->blocksize: len;
|
||||
char *s = r_print_randomart (block, len, core->offset);
|
||||
|
@ -389,26 +389,29 @@ static int r_core_rtr_gdb_cb(libgdbr_t *g, void *core_ptr, const char *cmd,
|
||||
case 't':
|
||||
switch (cmd[3]) {
|
||||
case '\0': // dpt
|
||||
if (!core->dbg->current->plugin.threads) {
|
||||
return -1;
|
||||
}
|
||||
if (!(list = core->dbg->current->plugin.threads(core->dbg, core->dbg->pid))) {
|
||||
return -1;
|
||||
}
|
||||
memset (out_buf, 0, max_len);
|
||||
out_buf[0] = 'm';
|
||||
ret = 1;
|
||||
r_list_foreach (list, iter, dbgpid) {
|
||||
// Max length of a hex pid = 8?
|
||||
if (ret >= max_len - 9) {
|
||||
break;
|
||||
{
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (core->dbg, current, plugin);
|
||||
if (!plugin || !plugin->threads) {
|
||||
return -1;
|
||||
}
|
||||
if (!(list = plugin->threads (core->dbg, core->dbg->pid))) {
|
||||
return -1;
|
||||
}
|
||||
memset (out_buf, 0, max_len);
|
||||
out_buf[0] = 'm';
|
||||
ret = 1;
|
||||
r_list_foreach (list, iter, dbgpid) {
|
||||
// Max length of a hex pid = 8?
|
||||
if (ret >= max_len - 9) {
|
||||
break;
|
||||
}
|
||||
snprintf (out_buf + ret, max_len - ret - 1, "%x,", dbgpid->pid);
|
||||
ret = strlen (out_buf);
|
||||
}
|
||||
if (ret > 1) {
|
||||
ret--;
|
||||
out_buf[ret] = '\0';
|
||||
}
|
||||
snprintf (out_buf + ret, max_len - ret - 1, "%x,", dbgpid->pid);
|
||||
ret = strlen (out_buf);
|
||||
}
|
||||
if (ret > 1) {
|
||||
ret--;
|
||||
out_buf[ret] = '\0';
|
||||
}
|
||||
return 0;
|
||||
case 'r': // dptr -> return current tid as int
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2010-2021 - pancake */
|
||||
/* radare - LGPL - Copyright 2010-2023 - pancake */
|
||||
|
||||
#include <r_debug.h>
|
||||
|
||||
@ -21,56 +21,62 @@ R_API void r_debug_desc_free(RDebugDesc *p) {
|
||||
}
|
||||
}
|
||||
|
||||
#define BOILERPLATE \
|
||||
r_return_val_if_fail (dbg, -1); \
|
||||
RDebugPlugin *plugin = R_UNWRAP2 (dbg->current, plugin); \
|
||||
if (plugin) if
|
||||
|
||||
R_API int r_debug_desc_open(RDebug *dbg, const char *path) {
|
||||
r_return_val_if_fail (dbg && dbg->current, -1);
|
||||
if (dbg && dbg->current && dbg->current->plugin.desc.open) {
|
||||
return dbg->current->plugin.desc.open (path);
|
||||
BOILERPLATE (plugin->desc.open) {
|
||||
return plugin->desc.open (path);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
R_API int r_debug_desc_close(RDebug *dbg, int fd) {
|
||||
if (dbg && dbg->current && dbg->current->plugin.desc.close) {
|
||||
return dbg->current->plugin.desc.close (fd);
|
||||
BOILERPLATE (plugin->desc.close) {
|
||||
return plugin->desc.close (fd);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
R_API int r_debug_desc_dup(RDebug *dbg, int fd, int newfd) {
|
||||
if (dbg && dbg->current && dbg->current->plugin.desc.dup) {
|
||||
return dbg->current->plugin.desc.dup (fd, newfd);
|
||||
BOILERPLATE (plugin->desc.dup) {
|
||||
return plugin->desc.dup (fd, newfd);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
R_API int r_debug_desc_read(RDebug *dbg, int fd, ut64 addr, int len) {
|
||||
if (dbg && dbg->current && dbg->current->plugin.desc.read) {
|
||||
return dbg->current->plugin.desc.read (fd, addr, len);
|
||||
BOILERPLATE (plugin->desc.read) {
|
||||
return plugin->desc.read (fd, addr, len);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
R_API int r_debug_desc_seek(RDebug *dbg, int fd, ut64 addr) {
|
||||
if (dbg && dbg->current && dbg->current->plugin.desc.seek) {
|
||||
return dbg->current->plugin.desc.seek (fd, addr);
|
||||
BOILERPLATE (plugin->desc.seek) {
|
||||
return plugin->desc.seek (fd, addr);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
R_API int r_debug_desc_write(RDebug *dbg, int fd, ut64 addr, int len) {
|
||||
if (dbg && dbg->current && dbg->current->plugin.desc.write) {
|
||||
return dbg->current->plugin.desc.write (fd, addr, len);
|
||||
BOILERPLATE (plugin->desc.write) {
|
||||
return plugin->desc.write (fd, addr, len);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
R_API int r_debug_desc_list(RDebug *dbg, bool show_commands) {
|
||||
r_return_val_if_fail (dbg, 0);
|
||||
RListIter *iter;
|
||||
RDebugDesc *p;
|
||||
int count = 0;
|
||||
|
||||
if (dbg && dbg->current && dbg->current->plugin.desc.list) {
|
||||
RList *list = dbg->current->plugin.desc.list (dbg->pid);
|
||||
RDebugPlugin *plugin = R_UNWRAP2 (dbg->current, plugin);
|
||||
if (plugin && plugin->desc.list) {
|
||||
RList *list = plugin->desc.list (dbg->pid);
|
||||
r_list_foreach (list, iter, p) {
|
||||
if (show_commands) {
|
||||
// Skip over std streams
|
||||
|
@ -11,11 +11,12 @@ R_LIB_VERSION(r_debug);
|
||||
#define DBG_BUF_SIZE 512
|
||||
|
||||
R_API RDebugInfo *r_debug_info(RDebug *dbg, const char *arg) {
|
||||
r_return_val_if_fail (dbg && dbg->current, NULL);
|
||||
r_return_val_if_fail (dbg, NULL);
|
||||
if (dbg->pid < 0) {
|
||||
return NULL;
|
||||
}
|
||||
return dbg->current->plugin.info? dbg->current->plugin.info (dbg, arg): NULL;
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (dbg, current, plugin);
|
||||
return plugin->info? plugin->info (dbg, arg): NULL;
|
||||
}
|
||||
|
||||
R_API void r_debug_info_free(RDebugInfo *rdi) {
|
||||
@ -40,14 +41,13 @@ R_API void r_debug_bp_update(RDebug *dbg) {
|
||||
}
|
||||
}
|
||||
|
||||
#if __i386__ || __x86_64__
|
||||
static int r_debug_drx_at(RDebug *dbg, ut64 addr) {
|
||||
if (dbg && dbg->current && dbg->current->plugin.drx) {
|
||||
return dbg->current->plugin.drx (dbg, 0, addr, 0, 0, 0, DRX_API_GET_BP);
|
||||
R_API int r_debug_drx_get(RDebug *dbg, ut64 addr) {
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (dbg, current, plugin);
|
||||
if (plugin && plugin->drx) {
|
||||
return plugin->drx (dbg, 0, addr, 0, 0, 0, DRX_API_GET_BP);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Recoiling after a breakpoint has two stages:
|
||||
@ -104,7 +104,7 @@ static bool r_debug_bp_hit(RDebug *dbg, RRegItem *pc_ri, ut64 pc, RBreakpointIte
|
||||
#if __i386__ || __x86_64__
|
||||
if (!b) {
|
||||
/* handle the case of hw breakpoints - notify the user */
|
||||
int drx_reg_idx = r_debug_drx_at (dbg, pc);
|
||||
int drx_reg_idx = r_debug_drx_get (dbg, pc);
|
||||
if (drx_reg_idx != -1) {
|
||||
R_LOG_INFO ("hit hardware breakpoint %d at: %" PFMT64x,
|
||||
drx_reg_idx, pc);
|
||||
@ -452,8 +452,9 @@ R_API bool r_debug_attach(RDebug *dbg, int pid) {
|
||||
return false;
|
||||
}
|
||||
bool ret = false;
|
||||
if (dbg->current && dbg->current->plugin.attach) {
|
||||
ret = dbg->current->plugin.attach (dbg, pid);
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (dbg, current, plugin);
|
||||
if (plugin && plugin->attach) {
|
||||
ret = plugin->attach (dbg, pid);
|
||||
if (ret) {
|
||||
dbg->tid = pid;
|
||||
// dbg->pid = pid;
|
||||
@ -466,51 +467,54 @@ R_API bool r_debug_attach(RDebug *dbg, int pid) {
|
||||
}
|
||||
|
||||
/* stop execution of child process */
|
||||
R_API int r_debug_stop(RDebug *dbg) {
|
||||
if (dbg && dbg->current && dbg->current->plugin.stop) {
|
||||
return dbg->current->plugin.stop (dbg);
|
||||
R_API bool r_debug_stop(RDebug *dbg) {
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (dbg, current, plugin);
|
||||
if (plugin->stop) {
|
||||
return plugin->stop (dbg);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
R_API bool r_debug_set_arch(RDebug *dbg, const char *arch, int bits) {
|
||||
if (arch && dbg && dbg->current) {
|
||||
switch (bits) {
|
||||
case 16:
|
||||
if (dbg->current->plugin.bits == 16) {
|
||||
dbg->bits = R_SYS_BITS_16;
|
||||
}
|
||||
break;
|
||||
case 27:
|
||||
if (dbg->current->plugin.bits == 27) {
|
||||
dbg->bits = R_SYS_BITS_27;
|
||||
}
|
||||
break;
|
||||
case 32:
|
||||
if (dbg->current->plugin.bits & R_SYS_BITS_32) {
|
||||
dbg->bits = R_SYS_BITS_32;
|
||||
}
|
||||
break;
|
||||
case 64:
|
||||
dbg->bits = R_SYS_BITS_64;
|
||||
break;
|
||||
}
|
||||
if (!dbg->current->plugin.bits) {
|
||||
dbg->bits = dbg->current->plugin.bits;
|
||||
} else if (!(dbg->current->plugin.bits & dbg->bits)) {
|
||||
dbg->bits = dbg->current->plugin.bits & R_SYS_BITS_64;
|
||||
if (!dbg->bits) {
|
||||
dbg->bits = dbg->current->plugin.bits & R_SYS_BITS_32;
|
||||
}
|
||||
if (!dbg->bits) {
|
||||
dbg->bits = R_SYS_BITS_32;
|
||||
}
|
||||
}
|
||||
free (dbg->arch);
|
||||
dbg->arch = strdup (arch);
|
||||
return true;
|
||||
r_return_val_if_fail (dbg && arch, false);
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (dbg, current, plugin);
|
||||
if (!plugin) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
switch (bits) {
|
||||
case 16:
|
||||
if (plugin->bits == 16) {
|
||||
dbg->bits = R_SYS_BITS_16;
|
||||
}
|
||||
break;
|
||||
case 27:
|
||||
if (plugin->bits == 27) {
|
||||
dbg->bits = R_SYS_BITS_27;
|
||||
}
|
||||
break;
|
||||
case 32:
|
||||
if (plugin->bits & R_SYS_BITS_32) {
|
||||
dbg->bits = R_SYS_BITS_32;
|
||||
}
|
||||
break;
|
||||
case 64:
|
||||
dbg->bits = R_SYS_BITS_64;
|
||||
break;
|
||||
}
|
||||
if (!plugin->bits) {
|
||||
dbg->bits = plugin->bits;
|
||||
} else if (!(plugin->bits & dbg->bits)) {
|
||||
dbg->bits = plugin->bits & R_SYS_BITS_64;
|
||||
if (!dbg->bits) {
|
||||
dbg->bits = plugin->bits & R_SYS_BITS_32;
|
||||
}
|
||||
if (!dbg->bits) {
|
||||
dbg->bits = R_SYS_BITS_32;
|
||||
}
|
||||
}
|
||||
free (dbg->arch);
|
||||
dbg->arch = strdup (arch);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Inject and execute shellcode
|
||||
@ -619,8 +623,9 @@ R_API bool r_debug_start(RDebug *dbg, const char *cmd) {
|
||||
R_API bool r_debug_detach(RDebug *dbg, int pid) {
|
||||
r_return_val_if_fail (dbg, false);
|
||||
bool ret = false;
|
||||
if (dbg->current && dbg->current->plugin.detach) {
|
||||
ret = dbg->current->plugin.detach (dbg, pid);
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (dbg, current, plugin);
|
||||
if (plugin && plugin->detach) {
|
||||
ret = -plugin->detach (dbg, pid);
|
||||
if (dbg->pid == pid) {
|
||||
dbg->pid = -1;
|
||||
dbg->tid = -1;
|
||||
@ -649,8 +654,9 @@ R_API bool r_debug_select(RDebug *dbg, int pid, int tid) {
|
||||
if (pid < 0 || tid < 0) {
|
||||
return false;
|
||||
}
|
||||
if (dbg->current && dbg->current->plugin.select) {
|
||||
if (!dbg->current->plugin.select (dbg, pid, tid)) {
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (dbg, current, plugin);
|
||||
if (plugin && plugin->select) {
|
||||
if (!plugin->select (dbg, pid, tid)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -744,8 +750,9 @@ R_API RDebugReasonType r_debug_wait(RDebug *dbg, RBreakpointItem **bp) {
|
||||
}
|
||||
|
||||
/* if our debugger plugin has wait */
|
||||
if (dbg->current && dbg->current->plugin.wait) {
|
||||
reason = dbg->current->plugin.wait (dbg, dbg->pid);
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (dbg, current, plugin);
|
||||
if (plugin && plugin->wait) {
|
||||
reason = plugin->wait (dbg, dbg->pid);
|
||||
if (reason == R_DEBUG_REASON_DEAD) {
|
||||
R_LOG_INFO ("==> Process finished");
|
||||
REventDebugProcessFinished event = {
|
||||
@ -958,8 +965,8 @@ R_API int r_debug_step_hard(RDebug *dbg, RBreakpointItem **pb) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!dbg->current->plugin.step (dbg)) {
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (dbg, current, plugin);
|
||||
if (plugin && !plugin->step (dbg)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -991,6 +998,7 @@ R_API int r_debug_step_hard(RDebug *dbg, RBreakpointItem **pb) {
|
||||
}
|
||||
|
||||
R_API int r_debug_step(RDebug *dbg, int steps) {
|
||||
r_return_val_if_fail (dbg, 0);
|
||||
RBreakpointItem *bp = NULL;
|
||||
int ret, steps_taken = 0;
|
||||
|
||||
@ -999,10 +1007,6 @@ R_API int r_debug_step(RDebug *dbg, int steps) {
|
||||
steps = 1;
|
||||
}
|
||||
|
||||
if (!dbg || !dbg->current) {
|
||||
return steps_taken;
|
||||
}
|
||||
|
||||
if (r_debug_is_dead (dbg)) {
|
||||
return steps_taken;
|
||||
}
|
||||
@ -1080,14 +1084,15 @@ R_API int r_debug_step_over(RDebug *dbg, int steps) {
|
||||
steps = 1;
|
||||
}
|
||||
|
||||
if (dbg->current && dbg->current->plugin.step_over) {
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (dbg, current, plugin);
|
||||
if (plugin && plugin->step_over) {
|
||||
for (; steps_taken < steps; steps_taken++) {
|
||||
if (dbg->session && dbg->recoil_mode == R_DBG_RECOIL_NONE) {
|
||||
dbg->session->cnum++;
|
||||
dbg->session->maxcnum++;
|
||||
r_debug_trace_ins_before (dbg);
|
||||
}
|
||||
if (!dbg->current->plugin.step_over (dbg)) {
|
||||
if (!plugin->step_over (dbg)) {
|
||||
return steps_taken;
|
||||
}
|
||||
if (dbg->session && dbg->recoil_mode == R_DBG_RECOIL_NONE) {
|
||||
@ -1210,6 +1215,7 @@ repeat:
|
||||
if (r_debug_is_dead (dbg)) {
|
||||
return 0;
|
||||
}
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (dbg, current, plugin);
|
||||
if (dbg->session && dbg->trace_continue) {
|
||||
while (!r_cons_is_breaked ()) {
|
||||
if (r_debug_step (dbg, 1) != 1) {
|
||||
@ -1221,13 +1227,13 @@ repeat:
|
||||
}
|
||||
reason = dbg->session->reasontype;
|
||||
bp = dbg->session->bp;
|
||||
} else if (dbg->current && dbg->current->plugin.cont) {
|
||||
} else if (plugin && plugin->cont) {
|
||||
/* handle the stage-2 of breakpoints */
|
||||
if (!r_debug_recoil (dbg, R_DBG_RECOIL_CONTINUE)) {
|
||||
return 0;
|
||||
}
|
||||
/* tell the inferior to go! */
|
||||
ret = dbg->current->plugin.cont (dbg, dbg->pid, dbg->tid, sig);
|
||||
ret = plugin->cont (dbg, dbg->pid, dbg->tid, sig);
|
||||
//XXX(jjd): why? //dbg->reason.signum = 0;
|
||||
reason = r_debug_wait (dbg, &bp);
|
||||
} else {
|
||||
@ -1556,7 +1562,8 @@ R_API int r_debug_continue_syscalls(RDebug *dbg, int *sc, int n_sc) {
|
||||
if (!dbg->current || r_debug_is_dead (dbg)) {
|
||||
return -1;
|
||||
}
|
||||
if (!dbg->current->plugin.contsc) {
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (dbg, current, plugin);
|
||||
if (plugin && !plugin->contsc) {
|
||||
/* user-level syscall tracing */
|
||||
r_debug_continue_until_optype (dbg, R_ANAL_OP_TYPE_SWI, 0);
|
||||
return show_syscall (dbg, "A0");
|
||||
@ -1584,7 +1591,7 @@ R_API int r_debug_continue_syscalls(RDebug *dbg, int *sc, int n_sc) {
|
||||
* return value after... */
|
||||
r_debug_step (dbg, 1);
|
||||
#endif
|
||||
dbg->current->plugin.contsc (dbg, dbg->pid, 0); // TODO handle return value
|
||||
r_debug_contsc (dbg, 0); // TODO handle return value
|
||||
// wait until continuation
|
||||
reason = r_debug_wait (dbg, NULL);
|
||||
if (reason == R_DEBUG_REASON_DEAD || r_debug_is_dead (dbg)) {
|
||||
@ -1626,24 +1633,26 @@ R_API int r_debug_continue_syscall(RDebug *dbg, int sc) {
|
||||
return r_debug_continue_syscalls (dbg, &sc, 1);
|
||||
}
|
||||
|
||||
// TODO: remove from here? this is code injection!
|
||||
R_API int r_debug_syscall(RDebug *dbg, int num) {
|
||||
bool ret = true;
|
||||
if (dbg->current->plugin.contsc) {
|
||||
ret = dbg->current->plugin.contsc (dbg, dbg->pid, num);
|
||||
// TODO: bad name, contsc wtf
|
||||
R_API bool r_debug_contsc(RDebug *dbg, int num) {
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (dbg, current, plugin);
|
||||
bool ret = true; // false?
|
||||
if (plugin && plugin->contsc) {
|
||||
ret = plugin->contsc (dbg, dbg->pid, num);
|
||||
}
|
||||
R_LOG_TODO ("show syscall information");
|
||||
/* r2rc task? ala inject? */
|
||||
return (int)ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
R_API int r_debug_kill(RDebug *dbg, int pid, int tid, int sig) {
|
||||
R_API bool r_debug_kill(RDebug *dbg, int pid, int tid, int sig) {
|
||||
if (r_debug_is_dead (dbg)) {
|
||||
return false;
|
||||
}
|
||||
if (dbg->current && dbg->current->plugin.kill) {
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (dbg, current, plugin);
|
||||
if (plugin && plugin->kill) {
|
||||
if (pid > 0) {
|
||||
return dbg->current->plugin.kill (dbg, pid, tid, sig);
|
||||
return plugin->kill (dbg, pid, tid, sig);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@ -1652,8 +1661,9 @@ R_API int r_debug_kill(RDebug *dbg, int pid, int tid, int sig) {
|
||||
}
|
||||
|
||||
R_API RList *r_debug_frames(RDebug *dbg, ut64 at) {
|
||||
if (dbg && dbg->current && dbg->current->plugin.frames) {
|
||||
return dbg->current->plugin.frames (dbg, at);
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (dbg, current, plugin);
|
||||
if (plugin && plugin->frames) {
|
||||
return plugin->frames (dbg, at);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@ -1672,16 +1682,17 @@ R_API int r_debug_child_clone(RDebug *dbg) {
|
||||
}
|
||||
|
||||
R_API bool r_debug_is_dead(RDebug *dbg) {
|
||||
if (!dbg->current) {
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (dbg, current, plugin);
|
||||
if (!plugin) {
|
||||
return false;
|
||||
}
|
||||
// workaround for debug.io.. should be generic
|
||||
if (!strcmp (dbg->current->plugin.meta.name, "io")) {
|
||||
if (!strcmp (plugin->meta.name, "io")) {
|
||||
return false;
|
||||
}
|
||||
bool is_dead = (dbg->pid < 0 && strncmp (dbg->current->plugin.meta.name, "gdb", 3)) || (dbg->reason.type == R_DEBUG_REASON_DEAD);
|
||||
if (dbg->pid > 0 && dbg->current && dbg->current->plugin.kill) {
|
||||
is_dead = !dbg->current->plugin.kill (dbg, dbg->pid, false, 0);
|
||||
bool is_dead = (dbg->pid < 0 && strncmp (plugin->meta.name, "gdb", 3)) || (dbg->reason.type == R_DEBUG_REASON_DEAD);
|
||||
if (dbg->pid > 0 && plugin && plugin->kill) {
|
||||
is_dead = !plugin->kill (dbg, dbg->pid, false, 0);
|
||||
}
|
||||
#if 0
|
||||
if (!is_dead && dbg->current && dbg->current->plugin.kill) {
|
||||
@ -1695,28 +1706,32 @@ R_API bool r_debug_is_dead(RDebug *dbg) {
|
||||
}
|
||||
|
||||
R_API int r_debug_map_protect(RDebug *dbg, ut64 addr, int size, int perms) {
|
||||
if (dbg && dbg->current && dbg->current->plugin.map_protect) {
|
||||
return dbg->current->plugin.map_protect (dbg, addr, size, perms);
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (dbg, current, plugin);
|
||||
if (plugin && plugin->map_protect) {
|
||||
return plugin->map_protect (dbg, addr, size, perms);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
R_API void r_debug_drx_list(RDebug *dbg) {
|
||||
if (dbg && dbg->current && dbg->current->plugin.drx) {
|
||||
dbg->current->plugin.drx (dbg, 0, 0, 0, 0, 0, DRX_API_LIST);
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (dbg, current, plugin);
|
||||
if (plugin && plugin->drx) {
|
||||
plugin->drx (dbg, 0, 0, 0, 0, 0, DRX_API_LIST);
|
||||
}
|
||||
}
|
||||
|
||||
R_API int r_debug_drx_set(RDebug *dbg, int idx, ut64 addr, int len, int rwx, int g) {
|
||||
if (dbg && dbg->current && dbg->current->plugin.drx) {
|
||||
return dbg->current->plugin.drx (dbg, idx, addr, len, rwx, g, DRX_API_SET_BP);
|
||||
R_API bool r_debug_drx_set(RDebug *dbg, int idx, ut64 addr, int len, int rwx, int g) {
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (dbg, current, plugin);
|
||||
if (plugin && plugin->drx) {
|
||||
return plugin->drx (dbg, idx, addr, len, rwx, g, DRX_API_SET_BP);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
R_API int r_debug_drx_unset(RDebug *dbg, int idx) {
|
||||
if (dbg && dbg->current && dbg->current->plugin.drx) {
|
||||
return dbg->current->plugin.drx (dbg, idx, 0, -1, 0, 0, DRX_API_REMOVE_BP);
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (dbg, current, plugin);
|
||||
if (plugin && plugin->drx) {
|
||||
return plugin->drx (dbg, idx, 0, -1, 0, 0, DRX_API_REMOVE_BP);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -1779,8 +1794,9 @@ R_API ut64 r_debug_get_baddr(RDebug *dbg, const char *file) {
|
||||
}
|
||||
|
||||
R_API int r_debug_cmd(RDebug *dbg, const char *s) {
|
||||
if (dbg->current && dbg->current->plugin.cmd) {
|
||||
return dbg->current->plugin.cmd (dbg, s);
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (dbg, current, plugin);
|
||||
if (plugin && plugin->cmd) {
|
||||
return plugin->cmd (dbg, s);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -296,14 +296,15 @@ R_API RDebugMap *r_debug_map_new(char *name, ut64 addr, ut64 addr_end, int perm,
|
||||
}
|
||||
|
||||
R_API RList *r_debug_modules_list(RDebug *dbg) {
|
||||
return (dbg && dbg->current && dbg->current->plugin.modules_get)?
|
||||
dbg->current->plugin.modules_get (dbg): NULL;
|
||||
RDebugPlugin *ds = R_UNWRAP3 (dbg, current, plugin);
|
||||
return (ds && ds->modules_get)? ds->modules_get (dbg): NULL;
|
||||
}
|
||||
|
||||
R_API bool r_debug_map_sync(RDebug *dbg) {
|
||||
bool ret = false;
|
||||
if (dbg && dbg->current && dbg->current->plugin.map_get) {
|
||||
RList *newmaps = dbg->current->plugin.map_get (dbg);
|
||||
RDebugPlugin *ds = R_UNWRAP3 (dbg, current, plugin);
|
||||
if (ds && ds->map_get) {
|
||||
RList *newmaps = ds->map_get (dbg);
|
||||
if (newmaps) {
|
||||
r_list_free (dbg->maps);
|
||||
dbg->maps = newmaps;
|
||||
@ -314,17 +315,19 @@ R_API bool r_debug_map_sync(RDebug *dbg) {
|
||||
}
|
||||
|
||||
R_API RDebugMap* r_debug_map_alloc(RDebug *dbg, ut64 addr, int size, bool thp) {
|
||||
if (dbg && dbg->current && dbg->current->plugin.map_alloc) {
|
||||
return dbg->current->plugin.map_alloc (dbg, addr, size, thp);
|
||||
RDebugPlugin *ds = R_UNWRAP3 (dbg, current, plugin);
|
||||
if (ds && ds->map_alloc) {
|
||||
return ds->map_alloc (dbg, addr, size, thp);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
R_API int r_debug_map_dealloc(RDebug *dbg, RDebugMap *map) {
|
||||
RDebugPlugin *ds = R_UNWRAP3 (dbg, current, plugin);
|
||||
bool ret = false;
|
||||
ut64 addr = map->addr;
|
||||
if (dbg && dbg->current && dbg->current->plugin.map_dealloc) {
|
||||
if (dbg->current->plugin.map_dealloc (dbg, addr, map->size)) {
|
||||
if (ds->map_dealloc) {
|
||||
if (ds->map_dealloc (dbg, addr, map->size)) {
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
@ -353,9 +356,5 @@ R_API void r_debug_map_free(RDebugMap *map) {
|
||||
}
|
||||
|
||||
R_API RList *r_debug_map_list_new(void) {
|
||||
RList *list = r_list_new ();
|
||||
if (list) {
|
||||
list->free = (RListFree)r_debug_map_free;
|
||||
}
|
||||
return list;
|
||||
return r_list_newf ((RListFree)r_debug_map_free);
|
||||
}
|
||||
|
@ -5,12 +5,15 @@
|
||||
|
||||
R_API bool r_debug_reg_sync(RDebug *dbg, int type, int must_write) {
|
||||
r_return_val_if_fail (dbg && dbg->reg, false);
|
||||
// if dbg->current is null means that we didnt selected any debug plugin
|
||||
// this function is only needed to sync the local regstate into the target process
|
||||
if (dbg->current == NULL) {
|
||||
return true;
|
||||
}
|
||||
RDebugPlugin *plugin = &(dbg->current->plugin);
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (dbg, current, plugin);
|
||||
if (!plugin) {
|
||||
// if dbg->current is null means that we didnt selected any debug plugin
|
||||
// this function is only needed to sync the local regstate into the target process
|
||||
return true;
|
||||
}
|
||||
int n, size;
|
||||
if (r_debug_is_dead (dbg)) {
|
||||
return false;
|
||||
@ -34,7 +37,7 @@ R_API bool r_debug_reg_sync(RDebug *dbg, int type, int must_write) {
|
||||
// get regset mask
|
||||
int mask = dbg->reg->regset[n].maskregstype;
|
||||
// convert request arena to mask value
|
||||
int v = ((int)1 << i);
|
||||
ut32 v = ((ut32)1 << i);
|
||||
// skip checks on same request arena and check if this arena have inside the request arena type
|
||||
if (n != i && (mask & v)) {
|
||||
// eprintf(" req = %i arena = %i mask = %x search = %x \n", i, n, mask, v);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2014-2022 - pancake */
|
||||
/* radare - LGPL - Copyright 2014-2023 - pancake */
|
||||
|
||||
#include <r_debug.h>
|
||||
|
||||
@ -154,8 +154,8 @@ R_API int r_debug_signal_set(RDebug *dbg, int num, ut64 addr) {
|
||||
|
||||
/* TODO rename to _kill_ -> _signal_ */
|
||||
R_API RList *r_debug_kill_list(RDebug *dbg) {
|
||||
if (dbg->current->plugin.kill_list) {
|
||||
return dbg->current->plugin.kill_list (dbg);
|
||||
if (dbg->current->plugin->kill_list) {
|
||||
return dbg->current->plugin->kill_list (dbg);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ static RList *r_debug_native_map_get(RDebug *dbg) {
|
||||
return list;
|
||||
}
|
||||
|
||||
static int r_debug_bf_stop(RDebug *dbg) {
|
||||
static bool r_debug_bf_stop(RDebug *dbg) {
|
||||
if (!is_io_bf (dbg)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -348,7 +348,7 @@ static RDebugReasonType r_debug_bochs_wait(RDebug *dbg, int pid) {
|
||||
return R_DEBUG_REASON_NONE;
|
||||
}
|
||||
|
||||
static int r_debug_bochs_stop(RDebug *dbg) {
|
||||
static bool r_debug_bochs_stop(RDebug *dbg) {
|
||||
//eprintf("bochs_stop:\n");
|
||||
//RIOBdescbg *o = dbg->iob.io->desc->data;
|
||||
//BfvmCPU *c = o->bfvm;
|
||||
|
@ -121,7 +121,7 @@ static bool __esil_kill(RDebug *dbg, int pid, int tid, int sig) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static int __esil_stop(RDebug *dbg) {
|
||||
static bool __esil_stop(RDebug *dbg) {
|
||||
eprintf ("ESIL: stop\n");
|
||||
return true;
|
||||
}
|
||||
|
@ -202,7 +202,7 @@ static void interrupt_process(RDebug *dbg) {
|
||||
}
|
||||
#endif
|
||||
|
||||
static int r_debug_native_stop(RDebug *dbg) {
|
||||
static bool r_debug_native_stop(RDebug *dbg) {
|
||||
#if __linux__
|
||||
// Stop all running threads except the thread reported by waitpid
|
||||
return linux_stop_threads (dbg, dbg->reason.tid);
|
||||
@ -1260,7 +1260,7 @@ static bool r_debug_native_kill(RDebug *dbg, int pid, int tid, int sig) {
|
||||
}
|
||||
|
||||
static bool r_debug_native_init(RDebug *dbg) {
|
||||
dbg->current->plugin.desc = r_debug_desc_plugin_native;
|
||||
dbg->current->plugin->desc = r_debug_desc_plugin_native;
|
||||
#if R2__WINDOWS__
|
||||
r_w32_init ();
|
||||
if (!dbg->user && dbg->iob.io->dbgwrap) {
|
||||
|
@ -191,7 +191,7 @@ static RDebugReasonType r_debug_qnx_wait(RDebug *dbg, int pid) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int r_debug_qnx_stop(RDebug *dbg) {
|
||||
static bool r_debug_qnx_stop(RDebug *dbg) {
|
||||
PluginData *pd = R_UNWRAP3 (dbg, current, plugin_data);
|
||||
if (!pd) {
|
||||
return false;
|
||||
|
@ -184,7 +184,7 @@ static bool __rv32ima_kill(RDebug *dbg, int pid, int tid, int sig) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static int __rv32ima_stop(RDebug *dbg) {
|
||||
static bool __rv32ima_stop(RDebug *dbg) {
|
||||
eprintf ("ESIL: stop\n");
|
||||
return true;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2016 - Oscar Salvador */
|
||||
/* radare - LGPL - Copyright 2016-2023 - Oscar Salvador */
|
||||
|
||||
#include <r_debug.h>
|
||||
|
||||
@ -1038,14 +1038,14 @@ void write_note_hdr (note_type_t type, ut8 **note_data) {
|
||||
|
||||
static int *get_unique_thread_id(RDebug *dbg, int n_threads) {
|
||||
RListIter *it;
|
||||
RList *list;
|
||||
RDebugPid *th;
|
||||
int *thread_id = NULL;
|
||||
int i = 0;
|
||||
bool found = false;
|
||||
|
||||
if (dbg->current) {
|
||||
list = dbg->current->plugin.threads (dbg, dbg->pid);
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (dbg, current, plugin);
|
||||
if (plugin != NULL) {
|
||||
RList *list = plugin->threads (dbg, dbg->pid);
|
||||
if (!list) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -25,8 +25,9 @@ R_API RDebugPid *r_debug_pid_free(RDebugPid *pid) {
|
||||
}
|
||||
|
||||
R_API RList *r_debug_pids(RDebug *dbg, int pid) {
|
||||
if (dbg && dbg->current && dbg->current->plugin.pids) {
|
||||
return dbg->current->plugin.pids (dbg, pid);
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (dbg, current, plugin);
|
||||
if (plugin && plugin->pids) {
|
||||
return plugin->pids (dbg, pid);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@ -36,8 +37,9 @@ R_API int r_debug_pid_list(RDebug *dbg, int pid, char fmt) {
|
||||
RList *list;
|
||||
RListIter *iter;
|
||||
RDebugPid *p;
|
||||
if (dbg && dbg->current && dbg->current->plugin.pids) {
|
||||
list = dbg->current->plugin.pids (dbg, R_MAX (0, pid));
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (dbg, current, plugin);
|
||||
if (plugin && plugin->pids) {
|
||||
list = plugin->pids (dbg, R_MAX (0, pid));
|
||||
if (!list) {
|
||||
return false;
|
||||
}
|
||||
@ -82,8 +84,9 @@ R_API bool r_debug_thread_list(RDebug *dbg, int pid, char fmt) {
|
||||
if (pid == -1) {
|
||||
return false;
|
||||
}
|
||||
if (dbg && dbg->current && dbg->current->plugin.threads) {
|
||||
list = dbg->current->plugin.threads (dbg, pid);
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (dbg, current, plugin);
|
||||
if (plugin && plugin->threads) {
|
||||
list = plugin->threads (dbg, pid);
|
||||
if (!list) {
|
||||
return false;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <config.h>
|
||||
|
||||
static inline void debug_plugin_session_fini(RDebugPluginSession *ds) {
|
||||
if (ds->plugin.fini_plugin && !ds->plugin.fini_plugin (ds->dbg, ds)) {
|
||||
if (ds->plugin && ds->plugin->fini_plugin && !ds->plugin->fini_plugin (ds->dbg, ds)) {
|
||||
R_LOG_DEBUG ("Failed to finalize debug plugin");
|
||||
}
|
||||
R_FREE (ds->plugin_data);
|
||||
@ -31,7 +31,7 @@ R_API void r_debug_fini_plugins(RDebug *dbg) {
|
||||
}
|
||||
|
||||
static inline int find_plugin_by_name(const RDebugPluginSession *ds, const void *name) {
|
||||
return strcmp (ds->plugin.meta.name, name);
|
||||
return ds->plugin && strcmp (ds->plugin->meta.name, name);
|
||||
}
|
||||
|
||||
R_API bool r_debug_use(RDebug *dbg, const char *str) {
|
||||
@ -45,25 +45,26 @@ R_API bool r_debug_use(RDebug *dbg, const char *str) {
|
||||
const char *arch = dbg->anal->config->arch;
|
||||
r_debug_set_arch (dbg, arch, dbg->bits);
|
||||
}
|
||||
dbg->bp->breakpoint = dbg->current->plugin.breakpoint;
|
||||
dbg->bp->breakpoint = dbg->current->plugin->breakpoint;
|
||||
dbg->bp->user = dbg;
|
||||
}
|
||||
}
|
||||
if (dbg->current && dbg->current->plugin.reg_profile) {
|
||||
char *p = dbg->current->plugin.reg_profile (dbg);
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (dbg, current, plugin);
|
||||
if (plugin && plugin->reg_profile) {
|
||||
char *p = plugin->reg_profile (dbg);
|
||||
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;
|
||||
}
|
||||
if (dbg->current->plugin.init_debugger) {
|
||||
dbg->current->plugin.init_debugger (dbg);
|
||||
if (plugin && plugin->init_debugger) {
|
||||
plugin->init_debugger (dbg);
|
||||
}
|
||||
r_reg_set_profile_string (dbg->reg, p);
|
||||
free (p);
|
||||
} else {
|
||||
R_LOG_ERROR ("Cannot retrieve reg profile from debug plugin (%s)", dbg->current->plugin.meta.name);
|
||||
R_LOG_ERROR ("Cannot retrieve reg profile from debug plugin (%s)", plugin->meta.name); //dbg->current->plugin.meta.name);
|
||||
}
|
||||
}
|
||||
return dbg->current;
|
||||
@ -86,24 +87,25 @@ R_API bool r_debug_plugin_list(RDebug *dbg, int mode) {
|
||||
|
||||
RDebugPluginSession *ds;
|
||||
R_VEC_FOREACH (dbg->plugins, ds) {
|
||||
int sp = 8 - strlen (ds->plugin.meta.name);
|
||||
RPluginMeta meta = ds->plugin->meta;
|
||||
int sp = 8 - strlen (meta.name);
|
||||
spaces[sp] = 0;
|
||||
if (mode == 'q') {
|
||||
dbg->cb_printf ("%s\n", ds->plugin.meta.name);
|
||||
dbg->cb_printf ("%s\n", meta.name);
|
||||
} else if (mode == 'j') {
|
||||
pj_o (pj);
|
||||
pj_ks (pj, "name", ds->plugin.meta.name);
|
||||
pj_ks (pj, "license", ds->plugin.meta.license);
|
||||
pj_ks (pj, "author", ds->plugin.meta.author);
|
||||
pj_ks (pj, "desc", ds->plugin.meta.desc);
|
||||
if (ds->plugin.meta.version) {
|
||||
pj_ks (pj, "version", ds->plugin.meta.version);
|
||||
pj_ks (pj, "name", meta.name);
|
||||
pj_ks (pj, "license", meta.license);
|
||||
pj_ks (pj, "author", meta.author);
|
||||
pj_ks (pj, "desc", meta.desc);
|
||||
if (meta.version) {
|
||||
pj_ks (pj, "version", meta.version);
|
||||
}
|
||||
pj_end (pj);
|
||||
} else {
|
||||
dbg->cb_printf ("%d %s %s %s%s\n",
|
||||
count, (ds == dbg->current)? "dbg": "---",
|
||||
ds->plugin.meta.name, spaces, ds->plugin.meta.license);
|
||||
meta.name, spaces, meta.license);
|
||||
}
|
||||
spaces[sp] = ' ';
|
||||
count++;
|
||||
@ -125,10 +127,11 @@ R_API bool r_debug_plugin_add(RDebug *dbg, RDebugPlugin *plugin) {
|
||||
return false;
|
||||
}
|
||||
ds->dbg = dbg;
|
||||
memcpy (&ds->plugin, plugin, sizeof (RDebugPlugin));
|
||||
ds->plugin = plugin;
|
||||
// memcpy (&ds->plugin, plugin, sizeof (RDebugPlugin));
|
||||
ds->plugin_data = NULL;
|
||||
|
||||
if (ds->plugin.init_plugin && !ds->plugin.init_plugin (dbg, ds)) {
|
||||
if (ds->plugin && ds->plugin->init_plugin && !ds->plugin->init_plugin (dbg, ds)) {
|
||||
R_LOG_DEBUG ("Failed to initialize debug plugin");
|
||||
return false;
|
||||
}
|
||||
@ -154,8 +157,9 @@ R_API bool r_debug_plugin_set_reg_profile(RDebug *dbg, const char *profile) {
|
||||
R_LOG_ERROR ("r_debug_plugin_set_reg_profile: Cannot find '%s'", profile);
|
||||
return false;
|
||||
}
|
||||
if (dbg->current && dbg->current->plugin.set_reg_profile) {
|
||||
return dbg->current->plugin.set_reg_profile (dbg, str);
|
||||
RDebugPlugin *plugin = R_UNWRAP3 (dbg, current, plugin);
|
||||
if (plugin && plugin->set_reg_profile) {
|
||||
return plugin->set_reg_profile (dbg, str);
|
||||
}
|
||||
free (str);
|
||||
return false;
|
||||
|
@ -311,7 +311,7 @@ typedef struct r_debug_plugin_t {
|
||||
RList *(*tids)(RDebug *dbg, int pid);
|
||||
RList (*backtrace)(RDebug *dbg, int count);
|
||||
/* flow */
|
||||
int (*stop)(RDebug *dbg);
|
||||
bool (*stop)(RDebug *dbg);
|
||||
bool (*step)(RDebug *dbg);
|
||||
bool (*step_over)(RDebug *dbg);
|
||||
bool (*cont)(RDebug *dbg, int pid, int tid, int sig);
|
||||
@ -341,11 +341,11 @@ typedef struct r_debug_plugin_t {
|
||||
|
||||
typedef struct r_debug_plugin_session_t {
|
||||
RDebug *dbg;
|
||||
RDebugPlugin plugin;
|
||||
RDebugPlugin *plugin;
|
||||
void *plugin_data;
|
||||
} RDebugPluginSession;
|
||||
|
||||
R_VEC_FORWARD_DECLARE(RVecDebugPluginSession);
|
||||
R_VEC_FORWARD_DECLARE (RVecDebugPluginSession);
|
||||
|
||||
typedef struct r_debug_t {
|
||||
// R2_590 use RArchConfig instead
|
||||
@ -486,6 +486,7 @@ R_API int r_debug_continue_kill(RDebug *dbg, int signal);
|
||||
R_API int r_debug_continue_with_signal(RDebug *dbg);
|
||||
|
||||
/* process/thread handling */
|
||||
R_API bool r_debug_contsc(RDebug *dbg, int num);
|
||||
R_API bool r_debug_select(RDebug *dbg, int pid, int tid);
|
||||
//R_API int r_debug_pid_add(RDebug *dbg);
|
||||
//R_API int r_debug_pid_add_thread(RDebug *dbg);
|
||||
@ -514,7 +515,7 @@ R_API const char *r_debug_signal_resolve_i(RDebug *dbg, int signum);
|
||||
R_API void r_debug_signal_setup(RDebug *dbg, int num, int opt);
|
||||
R_API int r_debug_signal_set(RDebug *dbg, int num, ut64 addr);
|
||||
R_API void r_debug_signal_list(RDebug *dbg, int mode);
|
||||
R_API int r_debug_kill(RDebug *dbg, int pid, int tid, int sig);
|
||||
R_API bool r_debug_kill(RDebug *dbg, int pid, int tid, int sig);
|
||||
R_API RList *r_debug_kill_list(RDebug *dbg);
|
||||
// XXX: must be uint64 action
|
||||
R_API int r_debug_kill_setup(RDebug *dbg, int sig, int action);
|
||||
@ -560,7 +561,7 @@ R_API ut64 r_debug_reg_get_err(RDebug *dbg, const char *name, int *err, utX *val
|
||||
R_API bool r_debug_execute(RDebug *dbg, const ut8 *buf, int len, R_OUT ut64 *ret, bool restore, bool ignore_stack);
|
||||
R_API bool r_debug_map_sync(RDebug *dbg);
|
||||
|
||||
R_API int r_debug_stop(RDebug *dbg);
|
||||
R_API bool r_debug_stop(RDebug *dbg);
|
||||
|
||||
/* backtrace */
|
||||
R_API RList *r_debug_frames(RDebug *dbg, ut64 at);
|
||||
@ -595,7 +596,8 @@ R_API int r_debug_child_fork(RDebug *dbg);
|
||||
R_API int r_debug_child_clone(RDebug *dbg);
|
||||
|
||||
R_API void r_debug_drx_list(RDebug *dbg);
|
||||
R_API int r_debug_drx_set(RDebug *dbg, int idx, ut64 addr, int len, int rwx, int g);
|
||||
R_API bool r_debug_drx_set(RDebug *dbg, int idx, ut64 addr, int len, int rwx, int g);
|
||||
R_API int r_debug_drx_get(RDebug *dbg, ut64 addr);
|
||||
R_API int r_debug_drx_unset(RDebug *dbg, int idx);
|
||||
|
||||
/* esil */
|
||||
|
@ -444,11 +444,12 @@ static int get_pid_of(RIO *io, const char *procname) {
|
||||
return -1;
|
||||
}
|
||||
// check sandbox
|
||||
if (c && c->dbg && c->dbg->current) {
|
||||
RDebugPlugin *plugin = R_UNWRAP4 (c, dbg, current, plugin);
|
||||
if (plugin) {
|
||||
RListIter *iter;
|
||||
RDebugPid *proc;
|
||||
RDebug *d = c->dbg;
|
||||
RList *pids = d->current->plugin.pids (d, 0);
|
||||
RList *pids = plugin->pids (d, 0);
|
||||
r_list_foreach (pids, iter, proc) {
|
||||
if (strstr (proc->path, procname)) {
|
||||
R_LOG_INFO ("Matching PID %d %s", proc->pid, proc->path);
|
||||
|
Loading…
x
Reference in New Issue
Block a user