Fix #55 and add Cj to list metadata in json format

This commit is contained in:
pancake 2013-03-01 12:20:18 +01:00
parent bf5d2ba3da
commit 3a0fdd6a24
5 changed files with 35 additions and 16 deletions

View File

@ -48,7 +48,7 @@ R_API char *r_meta_get_string(RMeta *m, int type, ut64 addr) {
RListIter *iter;
RMetaItem *d;
switch(type) {
switch (type) {
case R_META_TYPE_COMMENT:
case R_META_TYPE_HIDE:
case R_META_TYPE_ANY:
@ -259,6 +259,7 @@ int r_meta_get_bounds(RMeta *m, ut64 addr, int type, ut64 *from, ut64 *to)
R_API const char *r_meta_type_to_string(int type) {
// XXX: use type as '%c'
switch(type) {
case R_META_TYPE_HIDE: return "Ch";
case R_META_TYPE_CODE: return "Cc";
case R_META_TYPE_DATA: return "Cd";
case R_META_TYPE_STRING: return "Cs";
@ -292,13 +293,22 @@ static void printmetaitem(RMeta *m, RMetaItem *d, int rad) {
return;
r_name_filter (str, 0);
// XXX r_str_sanitize (str);
if (rad)
m->printf ("%s %d %s @ 0x%08"PFMT64x"\n",
r_meta_type_to_string (d->type),
(int)(d->to-d->from), str, d->from);
else
switch (rad) {
case 'j':
m->printf ("{\"offset\":%"PFMT64d", \"type\":\"%s\", \"name\":\"%s\"}",
d->from, r_meta_type_to_string (d->type), str);
break;
case 0:
m->printf ("0x%08"PFMT64x" %s\n",
d->from, str);
case 1:
case '*':
default:
m->printf ("%s %d %s@0x%08"PFMT64x"\n",
r_meta_type_to_string (d->type),
(int)(d->to-d->from), str, d->from);
break;
}
free (str);
}
}
@ -308,12 +318,15 @@ R_API int r_meta_list(RMeta *m, int type, int rad) {
int count = 0;
RListIter *iter;
RMetaItem *d;
if (rad=='j') m->printf ("[");
r_list_foreach (m->data, iter, d) {
if (d->type == type || type == R_META_TYPE_ANY) {
printmetaitem (m, d, rad);
count++;
if (rad=='j' && iter->n) m->printf (",");
}
}
if (rad=='j') m->printf ("]\n");
return count;
}

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2012 - pancake */
/* radare - LGPL - Copyright 2009-2013 - pancake */
#include <r_cons.h>
#include <string.h>

View File

@ -13,8 +13,9 @@ static int cmd_meta(void *data, const char *input) {
char file[1024];
switch (*input) {
case 'j':
case '*':
r_meta_list (core->anal->meta, R_META_TYPE_ANY, 1);
r_meta_list (core->anal->meta, R_META_TYPE_ANY, *input);
break;
case 'l':
// XXX: this should be moved to CL?

View File

@ -947,12 +947,17 @@ static ut64 addr = 0;
static int option = 0;
static void r_core_visual_anal_refresh (RCore *core) {
ut64 addr = core->offset;
char old[1024];
old[0]='\0';
int cols = r_cons_get_size (NULL);
RAnalFunction *fcn = r_anal_fcn_find (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); // once
RAnalFunction *fcn;
char *oprofile;
ut64 addr;
int cols;
char old[1024];
if (!core) return;
old[0]='\0';
cols = r_cons_get_size (NULL);
addr = core->offset;
fcn = r_anal_fcn_find (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); // once
cols -= 50;
if (cols> 60) cols = 60;
@ -965,7 +970,7 @@ static void r_core_visual_anal_refresh (RCore *core) {
oprofile = strdup (r_config_get (core->config, "asm.profile"));
r_config_set (core->config, "asm.profile", "simple");
r_core_cmdf (core, "pd @ 0x%"PFMT64x":32", addr);
r_core_cmdf (core, "pd @ 0x%"PFMT64x"!32", addr);
r_config_set (core->config, "asm.profile", oprofile);
free (oprofile);

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2012 pancake<nopcode.org> */
/* radare - LGPL - Copyright 2009-2013 - pancake */
#include <r_reg.h>
#include <r_util.h>
@ -270,7 +270,7 @@ R_API ut64 r_reg_cmp(RReg *reg, RRegItem *item) {
RRegArena *dst = r_list_head (reg->regset[item->type].pool)->n->data;
if (off+len>src->size) len = src->size-off;
if (off+len>dst->size) len = dst->size-off;
if (len>0 && memcmp (dst->bytes+off, src->bytes+off, len)) {
if (len>1 && memcmp (dst->bytes+off, src->bytes+off, len)) {
r_reg_arena_set (reg, ptr, 0);
ret = r_reg_get_value (reg, item);
r_reg_arena_set (reg, !ptr, 0);