Honor asm.bits in the RBreakpoint API

This commit is contained in:
pancake 2015-06-22 12:23:38 +02:00
parent 1e4638d27e
commit d436d16cd4
13 changed files with 66 additions and 39 deletions

View File

@ -51,6 +51,10 @@ R_API int r_bp_get_bytes(RBreakpoint *bp, ut8 *buf, int len, int endian, int idx
repeat:
for (i=0; i<bp->cur->nbps; i++) {
b = &bp->cur->bps[i];
if (bp->cur->bps[i].bits) {
if (bp->bits != bp->cur->bps[i].bits)
continue;
}
if (bp->cur->bps[i].length == len) {
memcpy (buf, b->bytes, b->length);
return b->length;

View File

@ -1,22 +1,23 @@
/* radare - LGPL - Copyright 2009-2010 pancake<nopcode.org> */
/* radare - LGPL - Copyright 2009-2015 - pancake */
#include <r_bp.h>
#include <r_lib.h>
static struct r_bp_arch_t r_bp_plugin_arm_bps[] = {
{ 4, 0, (const ut8*)"\x01\x00\x9f\xef" }, // le - linux only? (undefined instruction)
{ 4, 1, (const ut8*)"\xef\x9f\x00\x01" }, // be
{ 64, 4, 0, (const ut8*)"\xfe\xde\xff\xe7" }, // le - arm64
{ 32, 4, 0, (const ut8*)"\x01\x00\x9f\xef" }, // le - linux only? (undefined instruction)
{ 32, 4, 1, (const ut8*)"\xef\x9f\x00\x01" }, // be
#if 0
{ 4, 0, (const ut8*)"\xfe\xde\xff\xe7" }, // arm-le - from a gdb patch
{ 4, 1, (const ut8*)"\xe7\xff\xde\xfe" }, // arm-be
{ 4, 0, (const ut8*)"\xf0\x01\xf0\xe7" }, // eabi-le - undefined instruction - for all kernels
{ 4, 1, (const ut8*)"\xe7\xf0\x01\xf0" }, // eabi-be
#endif
{ 2, 0, (const ut8*)"\xde\x01" }, // thumb-le
{ 2, 1, (const ut8*)"\x01\xde" }, // thumb-be
{ 2, 0, (const ut8*)"\xfe\xdf" }, // arm-thumb-le
{ 2, 1, (const ut8*)"\xdf\xfe" }, // arm-thumb-be
{ 0, 0, NULL }
{ 16, 2, 0, (const ut8*)"\xde\x01" }, // thumb-le
{ 16, 2, 1, (const ut8*)"\x01\xde" }, // thumb-be
{ 16, 2, 0, (const ut8*)"\xfe\xdf" }, // arm-thumb-le
{ 16, 2, 1, (const ut8*)"\xdf\xfe" }, // arm-thumb-be
{ 0, 0, 0, NULL }
};
struct r_bp_plugin_t r_bp_plugin_arm = {

View File

@ -4,9 +4,9 @@
#include <r_lib.h>
static struct r_bp_arch_t r_bp_plugin_bf_bps[] = {
{ 1, 0, (const ut8*)"\xff" },
{ 1, 0, (const ut8*)"\x00" },
{ 0, 0, NULL },
{ 0, 1, 0, (const ut8*)"\xff" },
{ 0, 1, 0, (const ut8*)"\x00" },
{ 0, 0, 0, NULL },
};
struct r_bp_plugin_t r_bp_plugin_bf = {

View File

@ -1,12 +1,12 @@
/* radare2 - LGPL - Copyright 2010-2012 pancake<nopcode.org> */
/* radare2 - LGPL - Copyright 2010-2015 - pancake */
#include <r_bp.h>
#include <r_lib.h>
static struct r_bp_arch_t r_bp_plugin_mips_bps[] = {
{ 4, 0, (const ut8*)"\x0d\x00\x00\x00" },
{ 4, 1, (const ut8*)"\x00\x00\x00\x0d" },
{ 0, 0, NULL }
{ 32, 4, 0, (const ut8*)"\x0d\x00\x00\x00" },
{ 32, 4, 1, (const ut8*)"\x00\x00\x00\x0d" },
{ 0, 0, 0, NULL }
};
struct r_bp_plugin_t r_bp_plugin_mips = {

View File

@ -5,9 +5,9 @@
static struct r_bp_arch_t r_bp_plugin_ppc_bps[] = {
/* XXX: FIX those are not really breakpoint opcodes at all */
{ 4, 0, (const ut8*)"\x00\x00\x00\x0d" }, // little endian
{ 4, 1, (const ut8*)"\x0d\x00\x00\x00" }, // big endian
{ 0, 0, NULL }
{ 32, 4, 0, (const ut8*)"\x00\x00\x00\x0d" }, // little endian
{ 32, 4, 1, (const ut8*)"\x0d\x00\x00\x00" }, // big endian
{ 0, 0, 0, NULL }
};
struct r_bp_plugin_t r_bp_plugin_ppc = {

View File

@ -1,12 +1,12 @@
/* radare - LGPL - Copyright 2009 pancake<nopcode.org> */
/* radare - LGPL - Copyright 2009-2015 - pancake */
#include <r_bp.h>
#include <r_lib.h>
static struct r_bp_arch_t r_bp_plugin_sh_bps[] = {
{ 2, 0, (const ut8*)"\x20\xc3" }, //Little endian bp
{ 2, 1, (const ut8*)"\xc3\x20" }, //Big endian bp
{ 0, 0, NULL },
{ 32, 2, 0, (const ut8*)"\x20\xc3" }, //Little endian bp
{ 32, 2, 1, (const ut8*)"\xc3\x20" }, //Big endian bp
{ 0, 0, 0, NULL },
};
struct r_bp_plugin_t r_bp_plugin_sh = {
@ -20,5 +20,6 @@ struct r_bp_plugin_t r_bp_plugin_sh = {
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_BP,
.data = &r_bp_plugin_sh,
.version = R2_VERSION
};
#endif

View File

@ -1,12 +1,12 @@
/* radare - LGPL - Copyright 2009 pancake<nopcode.org> */
/* radare - LGPL - Copyright 2009-2015 - pancake */
#include <r_bp.h>
#include <r_lib.h>
static struct r_bp_arch_t r_bp_plugin_x86_bps[] = {
{ 1, 0, (const ut8*)"\xcc" },
{ 2, 0, (const ut8*)"\xcd\x03" },
{ 0, 0, NULL },
{ 0, 1, 0, (const ut8*)"\xcc" }, // valid for 16, 32, 64
{ 0, 2, 0, (const ut8*)"\xcd\x03" },
{ 0, 0, 0, NULL },
};
struct r_bp_plugin_t r_bp_plugin_x86 = {
@ -20,5 +20,6 @@ struct r_bp_plugin_t r_bp_plugin_x86 = {
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_BP,
.data = &r_bp_plugin_x86,
.version = R2_VERSION
};
#endif

View File

@ -1,8 +1,8 @@
/* radare - LGPL - Copyright 2009-2010 pancake<nopcode.org> */
/* radare - LGPL - Copyright 2009-2015 - pancake */
#include <r_bp.h>
R_API int r_bp_plugin_del(struct r_bp_t *bp, const char *name) {
R_API int r_bp_plugin_del(RBreakpoint *bp, const char *name) {
//TODO: r_bp_plugin_del
return R_FALSE;
}
@ -24,8 +24,9 @@ R_API int r_bp_plugin_add(RBreakpoint *bp, RBreakpointPlugin *foo) {
return R_TRUE;
}
R_API int r_bp_use(struct r_bp_t *bp, const char *name) {
R_API int r_bp_use(RBreakpoint *bp, const char *name, int bits) {
RListIter *iter;
bp->bits = bits;
RBreakpointPlugin *h;
r_list_foreach (bp->plugins, iter, h) {
if (!strcmp (h->name, name)) {

View File

@ -1375,7 +1375,7 @@ static void r_core_cmd_bp(RCore *core, const char *input) {
case 'h':
switch (input[2]) {
case ' ':
if (!r_bp_use (core->dbg->bp, input+3))
if (!r_bp_use (core->dbg->bp, input+3, core->anal->bits))
eprintf ("Invalid name: '%s'.\n", input+3);
break;
case 0:

View File

@ -274,6 +274,7 @@ static int cb_asmbits(void *user, void *data) {
}
__setsegoff (core->config, asmarch, core->anal->bits);
}
r_bp_use (core->dbg->bp, asmarch, core->anal->bits);
return ret;
}

View File

@ -936,13 +936,13 @@ R_API int r_core_init(RCore *core) {
// TODO: get arch from r_bin or from native arch
r_asm_use (core->assembler, R_SYS_ARCH);
r_anal_use (core->anal, R_SYS_ARCH);
r_bp_use (core->dbg->bp, R_SYS_ARCH);
if (R_SYS_BITS & R_SYS_BITS_64)
r_config_set_i (core->config, "asm.bits", 64);
else
if (R_SYS_BITS & R_SYS_BITS_32)
r_config_set_i (core->config, "asm.bits", 32);
r_config_set (core->config, "asm.arch", R_SYS_ARCH);
r_bp_use (core->dbg->bp, R_SYS_ARCH, core->anal->bits);
update_sdb (core);
return 0;
}

View File

@ -1037,13 +1037,29 @@ eprintf ("++ EFL = 0x%08x %d\n", ctx.EFlags, r_offsetof (CONTEXT, EFlags));
break;
}
#elif __arm__ || __arm64__ || __aarch64__
if (dbg->bits==R_SYS_BITS_64) {
ret = thread_get_state (inferior_threads[tid],
ARM_THREAD_STATE64, (thread_state_t) regs, &gp_count);
} else {
ret = thread_get_state (inferior_threads[tid],
ARM_THREAD_STATE, (thread_state_t) regs, &gp_count);
//R_DEBUG_STATE_T, (thread_state_t) regs, &gp_count);
switch (type) {
case R_REG_TYPE_FLG:
case R_REG_TYPE_GPR:
if (dbg->bits==R_SYS_BITS_64) {
ret = thread_get_state (inferior_threads[tid],
ARM_THREAD_STATE64, (thread_state_t) regs, &gp_count);
} else {
ret = thread_get_state (inferior_threads[tid],
ARM_THREAD_STATE, (thread_state_t) regs, &gp_count);
//R_DEBUG_STATE_T, (thread_state_t) regs, &gp_count);
}
break;
case R_REG_TYPE_DRX:
if (dbg->bits== R_SYS_BITS_64) {
ret = thread_get_state (inferior_threads[tid],
ARM_DEBUG_STATE64, (thread_state_t)
regs, &gp_count);
} else {
ret = thread_get_state (inferior_threads[tid],
ARM_DEBUG_STATE32, (thread_state_t)
regs, &gp_count);
}
break;
}
#else
eprintf ("Unknown architecture\n");

View File

@ -16,6 +16,7 @@ R_LIB_VERSION_HEADER(r_bp);
#define R_BP_CONT_NORMAL 0
typedef struct r_bp_arch_t {
int bits;
int length;
int endian;
const ut8 *bytes;
@ -58,6 +59,7 @@ typedef struct r_bp_t {
void *user;
int stepcont;
int endian;
int bits;
RIOBind iob; // compile time dependency
RBreakpointPlugin *cur;
RList *traces; // XXX
@ -95,7 +97,7 @@ R_API int r_bp_del(RBreakpoint *bp, ut64 addr);
R_API int r_bp_del_all(RBreakpoint *bp);
R_API int r_bp_plugin_add(RBreakpoint *bp, RBreakpointPlugin *foo);
R_API int r_bp_use(RBreakpoint *bp, const char *name);
R_API int r_bp_use(RBreakpoint *bp, const char *name, int bits);
R_API int r_bp_plugin_del(RBreakpoint *bp, const char *name);
R_API void r_bp_plugin_list(RBreakpoint *bp);