Fix data references and prefix after flag in disasm

This commit is contained in:
pancake 2014-01-20 00:14:00 +01:00
parent b7961ef00a
commit ae85c1c16b
6 changed files with 21 additions and 16 deletions

View File

@ -66,7 +66,7 @@ R_API int r_anal_fcn_xref_add (RAnal *anal, RAnalFunction *fcn, ut64 at, ut64 ad
ref->at = at; // from
ref->addr = addr; // to
ref->type = type;
r_anal_xrefs_set (anal, type=='d'?"data":"code", addr, at);
r_anal_xrefs_set (anal, type=='s'?"string":type=='d'?"data":"code", addr, at);
// TODO: ensure we are not dupping xrefs
r_list_append (fcn->refs, ref);
return R_TRUE;
@ -89,9 +89,8 @@ R_API int r_anal_fcn_xref_del (RAnal *anal, RAnalFunction *fcn, ut64 at, ut64 ad
R_API int r_anal_fcn_local_add (RAnal *anal, RAnalFunction *fcn, ut64 addr, const char *name) {
RAnalFcnLocal *l = R_NEW0 (RAnalFcnLocal);
if (!fcn || !anal) {
if (!fcn || !anal)
return R_FALSE;
}
l->addr = addr;
l->name = strdup (name);
// TODO: do not allow duplicate locals!
@ -243,9 +242,10 @@ static int fcn_recurse(RAnal *anal, RAnalFunction *fcn, ut64 addr, ut8 *buf, ut6
}
if (op.ptr && op.ptr != UT64_MAX) {
// swapped parameters wtf //
if (!r_anal_fcn_xref_add (anal, fcn, op.ptr, op.addr, 'd')) {
//if (!r_anal_fcn_xref_add (anal, fcn, op.ptr, op.addr, 'd')) {
if (!r_anal_fcn_xref_add (anal, fcn, op.addr, op.ptr, 'd')) {
r_anal_op_fini (&op);
FITFCNSZ();
FITFCNSZ ();
return R_ANAL_RET_ERROR;
}
}
@ -329,7 +329,6 @@ static int fcn_recurse(RAnal *anal, RAnalFunction *fcn, ut64 addr, ut8 *buf, ut6
}
R_API int r_anal_fcn(RAnal *anal, RAnalFunction *fcn, ut64 addr, ut8 *buf, ut64 len, int reftype) {
fcn->size = 0;
fcn->type = (reftype==R_ANAL_REF_TYPE_CODE)?
R_ANAL_FCN_TYPE_LOC: R_ANAL_FCN_TYPE_FCN;

View File

@ -269,6 +269,7 @@ R_API const char *r_meta_type_to_string(int type) {
case R_META_TYPE_DATA: return "Cd";
case R_META_TYPE_STRING: return "Cs";
case R_META_TYPE_FORMAT: return "Cf";
case R_META_TYPE_MAGIC: return "Cm";
case R_META_TYPE_COMMENT: return "CC";
}
return "(...)";

View File

@ -29,7 +29,7 @@ R_API void r_anal_ref_free(void *ref) {
R_API int r_anal_ref_add(RAnal *anal, ut64 addr, ut64 at, int type) {
#if USE_NEW_REFS
const char *types = type=='c'?"jmp":
type=='C'?"call": "data";
type=='C'?"call": type=='s'?"string": "data";
r_anal_xrefs_set (anal, types, at, addr);
#else
RAnalRef *ref = NULL, *refi;

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2013 - pancake, nibble */
/* radare - LGPL - Copyright 2009-2014 - pancake, nibble */
#include <r_anal.h>
#include <sdb.h>

View File

@ -365,8 +365,10 @@ R_API int r_core_anal_fcn(RCore *core, ut64 at, ut64 from, int reftype, int dept
ref->addr = from;
ref->at = at;
ref->type = reftype;
if (reftype == 'd') // XXX HACK TO AVOID INVALID REFS
if (reftype == 'd') {
// XXX HACK TO AVOID INVALID REFS
r_list_append (fcni->xrefs, ref);
}
#endif
}
return R_TRUE;
@ -478,11 +480,14 @@ fcn->name = r_str_newf ("fcn.%08"PFMT64x, at);
if (refi->addr != UT64_MAX) {
switch (refi->type) {
case 'd':
#if 0
// check if destination is in text. and analyze!
// commented because it doesnt seems to work in all conditions
if (iscodesection (core, refi->at)) {
//refi->type = 'c';
r_core_anal_fcn (core, refi->at, refi->addr, 0, depth-1);
}
#endif
break;
case R_ANAL_REF_TYPE_CODE:
case R_ANAL_REF_TYPE_CALL:
@ -1084,6 +1089,7 @@ R_API void r_core_anal_setup_enviroment (RCore *core) {
}
R_API int r_core_anal_data (RCore *core, ut64 addr, int count, int depth) {
RAnalData *d;
ut64 dstaddr = 0LL;
ut8 *buf = core->block;
int len = core->blocksize;
@ -1106,8 +1112,7 @@ R_API int r_core_anal_data (RCore *core, ut64 addr, int count, int depth) {
//eprintf ("load next %d\n", len);
continue;
}
RAnalData *d = r_anal_data (core->anal, addr+i,
buf+i, len-i);
d = r_anal_data (core->anal, addr+i, buf+i, len-i);
str = r_anal_data_to_string (d);
r_cons_printf ("%s\n", str);
@ -1116,8 +1121,7 @@ R_API int r_core_anal_data (RCore *core, ut64 addr, int count, int depth) {
r_cons_printf ("`- ");
dstaddr = r_mem_get_num (buf+i, word, !endi);
if (depth>0)
r_core_anal_data (core,
dstaddr, 1, depth-1);
r_core_anal_data (core, dstaddr, 1, depth-1);
i += word;
break;
case R_ANAL_DATA_TYPE_STRING:

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2013 - nibble, pancake */
/* radare - LGPL - Copyright 2009-2014 - nibble, pancake, dso */
#include "r_core.h"
#include "r_cons.h"
@ -642,7 +642,8 @@ static void handle_show_xrefs (RCore *core, RDisasmState *disasm_state) {
refi->type=='C'?"CODE (CALL)":"DATA", refi->at,
fun?fun->name:"unk");
} else {
r_cons_printf ("; %s XREF from 0x%08"PFMT64x" (%s)\n",
r_cons_printf ("%s; %s XREF from 0x%08"PFMT64x" (%s)\n",
disasm_state->pal_comment,
refi->type=='c'?"CODE (JMP)":
refi->type=='C'?"CODE (CALL)":"DATA", refi->at,
fun?fun->name: "unk");
@ -885,7 +886,7 @@ static void handle_show_flags_option(RCore *core, RDisasmState *disasm_state) {
if (disasm_state->show_color) r_cons_strcat (disasm_state->color_flag);
if (disasm_state->show_functions) r_cons_printf ("%s:\n", flag->name);
else r_cons_printf ("%s:\n", flag->name);
handle_set_pre (disasm_state, " ");
//handle_set_pre (disasm_state, " ");
if (disasm_state->show_color) {
r_cons_printf (Color_RESET"%s%s"Color_RESET, disasm_state->color_fline,
f ? disasm_state->pre : " ");