Added new core binding to seek and set arch and bits

This born to handle arm/thumb since is a pain and we need to
track in which mode we are.
This commit is contained in:
Álvaro Felipe Melchor 2017-02-07 23:51:44 +01:00
parent db8154968e
commit 05a4ed6607
5 changed files with 19 additions and 8 deletions

View File

@ -95,6 +95,9 @@ R_API int r_anal_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le
}
memset (op, 0, sizeof (RAnalOp));
if (len > 0 && anal->cur && anal->cur->op) {
//use core binding to set asm.bits correctly based on the addr
//this is because of the hassle of arm/thumb
anal->coreb.archbits (anal->coreb.core, addr);
ret = anal->cur->op (anal, op, addr, data, len);
op->addr = addr;
/* consider at least 1 byte to be part of the opcode */
@ -122,9 +125,11 @@ R_API int r_anal_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le
return ret;
}
R_API RAnalOp *r_anal_op_copy (RAnalOp *op) {
R_API RAnalOp *r_anal_op_copy(RAnalOp *op) {
RAnalOp *nop = R_NEW0 (RAnalOp);
if (!nop) return NULL;
if (!nop) {
return NULL;
}
*nop = *op;
if (op->mnemonic) {
nop->mnemonic = strdup (op->mnemonic);

View File

@ -259,7 +259,7 @@ static void _set_bits(RCore *core, ut64 addr, int *bits) {
}
R_API int r_core_seek_archbits(RCore *core, ut64 addr) {
R_API void r_core_seek_archbits(RCore *core, ut64 addr) {
static char *oldarch = NULL;
static int oldbits = 0;
bool flag = false;
@ -292,7 +292,7 @@ R_API int r_core_seek_archbits(RCore *core, ut64 addr) {
}
}
free (arch);
return 1;
return;
}
if (oldarch) {
if (!(flag && arch && oldarch && !strcmp (oldarch, arch))) {
@ -304,7 +304,6 @@ R_API int r_core_seek_archbits(RCore *core, ut64 addr) {
r_config_set_i (core->config, "asm.bits", oldbits);
}
free (arch);
return 0;
}
R_API bool r_core_seek(RCore *core, ut64 addr, bool rb) {

View File

@ -203,6 +203,11 @@ static const char *getName(RCore *core, ut64 addr) {
return item ? item->name : NULL;
}
static void archbits(RCore *core, ut64 addr) {
r_anal_build_range_on_hints (core->anal);
r_core_seek_archbits (core, addr);
}
R_API int r_core_bind(RCore *core, RCoreBind *bnd) {
bnd->core = core;
bnd->bphit = (RCoreDebugBpHit)r_core_debug_breakpoint_hit;
@ -211,6 +216,7 @@ R_API int r_core_bind(RCore *core, RCoreBind *bnd) {
bnd->puts = (RCorePuts)r_cons_strcat;
bnd->setab = (RCoreSetArchBits)setab;
bnd->getName = (RCoreGetName)getName;
bnd->archbits = (RCoreSeekArchBits)archbits;
return true;
}
@ -1614,8 +1620,7 @@ R_API int r_core_init(RCore *core) {
r_core_bind (core, &(core->anal->coreb));
core->file = NULL;
core->files = r_list_new ();
core->files->free = (RListFree)r_core_file_free;
core->files = r_list_newf ((RListFree)r_core_file_free);
core->offset = 0LL;
r_core_cmd_init (core);
core->dbg = r_debug_new (true);

View File

@ -11,6 +11,7 @@ typedef char* (*RCoreCmdStr)(void *core, const char *cmd);
typedef void (*RCorePuts)(const char *cmd);
typedef void (*RCoreSetArchBits)(void *core, const char *arch, int bits);
typedef char *(*RCoreGetName)(void *core, ut64 off);
typedef void (*RCoreSeekArchBits)(void *core, ut64 addr);
typedef struct r_core_bind_t {
void *core;
@ -20,6 +21,7 @@ typedef struct r_core_bind_t {
RCoreDebugBpHit bphit;
RCoreSetArchBits setab;
RCoreGetName getName;
RCoreSeekArchBits archbits;
} RCoreBind;
#endif

View File

@ -222,7 +222,7 @@ R_API int r_core_seek_base (RCore *core, const char *hex);
R_API void r_core_seek_previous (RCore *core, const char *type);
R_API void r_core_seek_next (RCore *core, const char *type);
R_API int r_core_seek_align(RCore *core, ut64 align, int count);
R_API int r_core_seek_archbits (RCore *core, ut64 addr);
R_API void r_core_seek_archbits (RCore *core, ut64 addr);
R_API int r_core_block_read(RCore *core);
R_API int r_core_block_size(RCore *core, int bsize);
R_API int r_core_read_at(RCore *core, ut64 addr, ut8 *buf, int size);