mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-22 07:13:43 +00:00
Honor asm.bits in the RBreakpoint API
This commit is contained in:
parent
1e4638d27e
commit
d436d16cd4
@ -51,6 +51,10 @@ R_API int r_bp_get_bytes(RBreakpoint *bp, ut8 *buf, int len, int endian, int idx
|
|||||||
repeat:
|
repeat:
|
||||||
for (i=0; i<bp->cur->nbps; i++) {
|
for (i=0; i<bp->cur->nbps; i++) {
|
||||||
b = &bp->cur->bps[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) {
|
if (bp->cur->bps[i].length == len) {
|
||||||
memcpy (buf, b->bytes, b->length);
|
memcpy (buf, b->bytes, b->length);
|
||||||
return b->length;
|
return b->length;
|
||||||
|
@ -1,22 +1,23 @@
|
|||||||
/* radare - LGPL - Copyright 2009-2010 pancake<nopcode.org> */
|
/* radare - LGPL - Copyright 2009-2015 - pancake */
|
||||||
|
|
||||||
#include <r_bp.h>
|
#include <r_bp.h>
|
||||||
#include <r_lib.h>
|
#include <r_lib.h>
|
||||||
|
|
||||||
static struct r_bp_arch_t r_bp_plugin_arm_bps[] = {
|
static struct r_bp_arch_t r_bp_plugin_arm_bps[] = {
|
||||||
{ 4, 0, (const ut8*)"\x01\x00\x9f\xef" }, // le - linux only? (undefined instruction)
|
{ 64, 4, 0, (const ut8*)"\xfe\xde\xff\xe7" }, // le - arm64
|
||||||
{ 4, 1, (const ut8*)"\xef\x9f\x00\x01" }, // be
|
{ 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
|
#if 0
|
||||||
{ 4, 0, (const ut8*)"\xfe\xde\xff\xe7" }, // arm-le - from a gdb patch
|
{ 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, 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, 0, (const ut8*)"\xf0\x01\xf0\xe7" }, // eabi-le - undefined instruction - for all kernels
|
||||||
{ 4, 1, (const ut8*)"\xe7\xf0\x01\xf0" }, // eabi-be
|
{ 4, 1, (const ut8*)"\xe7\xf0\x01\xf0" }, // eabi-be
|
||||||
#endif
|
#endif
|
||||||
{ 2, 0, (const ut8*)"\xde\x01" }, // thumb-le
|
{ 16, 2, 0, (const ut8*)"\xde\x01" }, // thumb-le
|
||||||
{ 2, 1, (const ut8*)"\x01\xde" }, // thumb-be
|
{ 16, 2, 1, (const ut8*)"\x01\xde" }, // thumb-be
|
||||||
{ 2, 0, (const ut8*)"\xfe\xdf" }, // arm-thumb-le
|
{ 16, 2, 0, (const ut8*)"\xfe\xdf" }, // arm-thumb-le
|
||||||
{ 2, 1, (const ut8*)"\xdf\xfe" }, // arm-thumb-be
|
{ 16, 2, 1, (const ut8*)"\xdf\xfe" }, // arm-thumb-be
|
||||||
{ 0, 0, NULL }
|
{ 0, 0, 0, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct r_bp_plugin_t r_bp_plugin_arm = {
|
struct r_bp_plugin_t r_bp_plugin_arm = {
|
||||||
|
@ -4,9 +4,9 @@
|
|||||||
#include <r_lib.h>
|
#include <r_lib.h>
|
||||||
|
|
||||||
static struct r_bp_arch_t r_bp_plugin_bf_bps[] = {
|
static struct r_bp_arch_t r_bp_plugin_bf_bps[] = {
|
||||||
{ 1, 0, (const ut8*)"\xff" },
|
{ 0, 1, 0, (const ut8*)"\xff" },
|
||||||
{ 1, 0, (const ut8*)"\x00" },
|
{ 0, 1, 0, (const ut8*)"\x00" },
|
||||||
{ 0, 0, NULL },
|
{ 0, 0, 0, NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
struct r_bp_plugin_t r_bp_plugin_bf = {
|
struct r_bp_plugin_t r_bp_plugin_bf = {
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
/* radare2 - LGPL - Copyright 2010-2012 pancake<nopcode.org> */
|
/* radare2 - LGPL - Copyright 2010-2015 - pancake */
|
||||||
|
|
||||||
#include <r_bp.h>
|
#include <r_bp.h>
|
||||||
#include <r_lib.h>
|
#include <r_lib.h>
|
||||||
|
|
||||||
static struct r_bp_arch_t r_bp_plugin_mips_bps[] = {
|
static struct r_bp_arch_t r_bp_plugin_mips_bps[] = {
|
||||||
{ 4, 0, (const ut8*)"\x0d\x00\x00\x00" },
|
{ 32, 4, 0, (const ut8*)"\x0d\x00\x00\x00" },
|
||||||
{ 4, 1, (const ut8*)"\x00\x00\x00\x0d" },
|
{ 32, 4, 1, (const ut8*)"\x00\x00\x00\x0d" },
|
||||||
{ 0, 0, NULL }
|
{ 0, 0, 0, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct r_bp_plugin_t r_bp_plugin_mips = {
|
struct r_bp_plugin_t r_bp_plugin_mips = {
|
||||||
|
@ -5,9 +5,9 @@
|
|||||||
|
|
||||||
static struct r_bp_arch_t r_bp_plugin_ppc_bps[] = {
|
static struct r_bp_arch_t r_bp_plugin_ppc_bps[] = {
|
||||||
/* XXX: FIX those are not really breakpoint opcodes at all */
|
/* XXX: FIX those are not really breakpoint opcodes at all */
|
||||||
{ 4, 0, (const ut8*)"\x00\x00\x00\x0d" }, // little endian
|
{ 32, 4, 0, (const ut8*)"\x00\x00\x00\x0d" }, // little endian
|
||||||
{ 4, 1, (const ut8*)"\x0d\x00\x00\x00" }, // big endian
|
{ 32, 4, 1, (const ut8*)"\x0d\x00\x00\x00" }, // big endian
|
||||||
{ 0, 0, NULL }
|
{ 0, 0, 0, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct r_bp_plugin_t r_bp_plugin_ppc = {
|
struct r_bp_plugin_t r_bp_plugin_ppc = {
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
/* radare - LGPL - Copyright 2009 pancake<nopcode.org> */
|
/* radare - LGPL - Copyright 2009-2015 - pancake */
|
||||||
|
|
||||||
#include <r_bp.h>
|
#include <r_bp.h>
|
||||||
#include <r_lib.h>
|
#include <r_lib.h>
|
||||||
|
|
||||||
static struct r_bp_arch_t r_bp_plugin_sh_bps[] = {
|
static struct r_bp_arch_t r_bp_plugin_sh_bps[] = {
|
||||||
{ 2, 0, (const ut8*)"\x20\xc3" }, //Little endian bp
|
{ 32, 2, 0, (const ut8*)"\x20\xc3" }, //Little endian bp
|
||||||
{ 2, 1, (const ut8*)"\xc3\x20" }, //Big endian bp
|
{ 32, 2, 1, (const ut8*)"\xc3\x20" }, //Big endian bp
|
||||||
{ 0, 0, NULL },
|
{ 0, 0, 0, NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
struct r_bp_plugin_t r_bp_plugin_sh = {
|
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 = {
|
struct r_lib_struct_t radare_plugin = {
|
||||||
.type = R_LIB_TYPE_BP,
|
.type = R_LIB_TYPE_BP,
|
||||||
.data = &r_bp_plugin_sh,
|
.data = &r_bp_plugin_sh,
|
||||||
|
.version = R2_VERSION
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
/* radare - LGPL - Copyright 2009 pancake<nopcode.org> */
|
/* radare - LGPL - Copyright 2009-2015 - pancake */
|
||||||
|
|
||||||
#include <r_bp.h>
|
#include <r_bp.h>
|
||||||
#include <r_lib.h>
|
#include <r_lib.h>
|
||||||
|
|
||||||
static struct r_bp_arch_t r_bp_plugin_x86_bps[] = {
|
static struct r_bp_arch_t r_bp_plugin_x86_bps[] = {
|
||||||
{ 1, 0, (const ut8*)"\xcc" },
|
{ 0, 1, 0, (const ut8*)"\xcc" }, // valid for 16, 32, 64
|
||||||
{ 2, 0, (const ut8*)"\xcd\x03" },
|
{ 0, 2, 0, (const ut8*)"\xcd\x03" },
|
||||||
{ 0, 0, NULL },
|
{ 0, 0, 0, NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
struct r_bp_plugin_t r_bp_plugin_x86 = {
|
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 = {
|
struct r_lib_struct_t radare_plugin = {
|
||||||
.type = R_LIB_TYPE_BP,
|
.type = R_LIB_TYPE_BP,
|
||||||
.data = &r_bp_plugin_x86,
|
.data = &r_bp_plugin_x86,
|
||||||
|
.version = R2_VERSION
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/* radare - LGPL - Copyright 2009-2010 pancake<nopcode.org> */
|
/* radare - LGPL - Copyright 2009-2015 - pancake */
|
||||||
|
|
||||||
#include <r_bp.h>
|
#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
|
//TODO: r_bp_plugin_del
|
||||||
return R_FALSE;
|
return R_FALSE;
|
||||||
}
|
}
|
||||||
@ -24,8 +24,9 @@ R_API int r_bp_plugin_add(RBreakpoint *bp, RBreakpointPlugin *foo) {
|
|||||||
return R_TRUE;
|
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;
|
RListIter *iter;
|
||||||
|
bp->bits = bits;
|
||||||
RBreakpointPlugin *h;
|
RBreakpointPlugin *h;
|
||||||
r_list_foreach (bp->plugins, iter, h) {
|
r_list_foreach (bp->plugins, iter, h) {
|
||||||
if (!strcmp (h->name, name)) {
|
if (!strcmp (h->name, name)) {
|
||||||
|
@ -1375,7 +1375,7 @@ static void r_core_cmd_bp(RCore *core, const char *input) {
|
|||||||
case 'h':
|
case 'h':
|
||||||
switch (input[2]) {
|
switch (input[2]) {
|
||||||
case ' ':
|
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);
|
eprintf ("Invalid name: '%s'.\n", input+3);
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -274,6 +274,7 @@ static int cb_asmbits(void *user, void *data) {
|
|||||||
}
|
}
|
||||||
__setsegoff (core->config, asmarch, core->anal->bits);
|
__setsegoff (core->config, asmarch, core->anal->bits);
|
||||||
}
|
}
|
||||||
|
r_bp_use (core->dbg->bp, asmarch, core->anal->bits);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -936,13 +936,13 @@ R_API int r_core_init(RCore *core) {
|
|||||||
// TODO: get arch from r_bin or from native arch
|
// TODO: get arch from r_bin or from native arch
|
||||||
r_asm_use (core->assembler, R_SYS_ARCH);
|
r_asm_use (core->assembler, R_SYS_ARCH);
|
||||||
r_anal_use (core->anal, 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)
|
if (R_SYS_BITS & R_SYS_BITS_64)
|
||||||
r_config_set_i (core->config, "asm.bits", 64);
|
r_config_set_i (core->config, "asm.bits", 64);
|
||||||
else
|
else
|
||||||
if (R_SYS_BITS & R_SYS_BITS_32)
|
if (R_SYS_BITS & R_SYS_BITS_32)
|
||||||
r_config_set_i (core->config, "asm.bits", 32);
|
r_config_set_i (core->config, "asm.bits", 32);
|
||||||
r_config_set (core->config, "asm.arch", R_SYS_ARCH);
|
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);
|
update_sdb (core);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1037,13 +1037,29 @@ eprintf ("++ EFL = 0x%08x %d\n", ctx.EFlags, r_offsetof (CONTEXT, EFlags));
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#elif __arm__ || __arm64__ || __aarch64__
|
#elif __arm__ || __arm64__ || __aarch64__
|
||||||
if (dbg->bits==R_SYS_BITS_64) {
|
switch (type) {
|
||||||
ret = thread_get_state (inferior_threads[tid],
|
case R_REG_TYPE_FLG:
|
||||||
ARM_THREAD_STATE64, (thread_state_t) regs, &gp_count);
|
case R_REG_TYPE_GPR:
|
||||||
} else {
|
if (dbg->bits==R_SYS_BITS_64) {
|
||||||
ret = thread_get_state (inferior_threads[tid],
|
ret = thread_get_state (inferior_threads[tid],
|
||||||
ARM_THREAD_STATE, (thread_state_t) regs, &gp_count);
|
ARM_THREAD_STATE64, (thread_state_t) regs, &gp_count);
|
||||||
//R_DEBUG_STATE_T, (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
|
#else
|
||||||
eprintf ("Unknown architecture\n");
|
eprintf ("Unknown architecture\n");
|
||||||
|
@ -16,6 +16,7 @@ R_LIB_VERSION_HEADER(r_bp);
|
|||||||
#define R_BP_CONT_NORMAL 0
|
#define R_BP_CONT_NORMAL 0
|
||||||
|
|
||||||
typedef struct r_bp_arch_t {
|
typedef struct r_bp_arch_t {
|
||||||
|
int bits;
|
||||||
int length;
|
int length;
|
||||||
int endian;
|
int endian;
|
||||||
const ut8 *bytes;
|
const ut8 *bytes;
|
||||||
@ -58,6 +59,7 @@ typedef struct r_bp_t {
|
|||||||
void *user;
|
void *user;
|
||||||
int stepcont;
|
int stepcont;
|
||||||
int endian;
|
int endian;
|
||||||
|
int bits;
|
||||||
RIOBind iob; // compile time dependency
|
RIOBind iob; // compile time dependency
|
||||||
RBreakpointPlugin *cur;
|
RBreakpointPlugin *cur;
|
||||||
RList *traces; // XXX
|
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_del_all(RBreakpoint *bp);
|
||||||
|
|
||||||
R_API int r_bp_plugin_add(RBreakpoint *bp, RBreakpointPlugin *foo);
|
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 int r_bp_plugin_del(RBreakpoint *bp, const char *name);
|
||||||
R_API void r_bp_plugin_list(RBreakpoint *bp);
|
R_API void r_bp_plugin_list(RBreakpoint *bp);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user