From 05a4ed6607dd89c6f028640a18c5ca04fa8fb316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Felipe=20Melchor?= Date: Tue, 7 Feb 2017 23:51:44 +0100 Subject: [PATCH] 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. --- libr/anal/op.c | 9 +++++++-- libr/core/cio.c | 5 ++--- libr/core/core.c | 9 +++++++-- libr/include/r_bind.h | 2 ++ libr/include/r_core.h | 2 +- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/libr/anal/op.c b/libr/anal/op.c index 66a8f4cb6f..4e035d7555 100644 --- a/libr/anal/op.c +++ b/libr/anal/op.c @@ -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); diff --git a/libr/core/cio.c b/libr/core/cio.c index 1b11bd1276..ad881ee0da 100644 --- a/libr/core/cio.c +++ b/libr/core/cio.c @@ -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) { diff --git a/libr/core/core.c b/libr/core/core.c index 8ad20437e4..6f06e3d2cd 100644 --- a/libr/core/core.c +++ b/libr/core/core.c @@ -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); diff --git a/libr/include/r_bind.h b/libr/include/r_bind.h index 2c22d09a13..d3a3be88cd 100644 --- a/libr/include/r_bind.h +++ b/libr/include/r_bind.h @@ -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 diff --git a/libr/include/r_core.h b/libr/include/r_core.h index af9cfb31f7..1874d5c434 100644 --- a/libr/include/r_core.h +++ b/libr/include/r_core.h @@ -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);