More work for cparse, Show type links in disasm. Fix some warns

This commit is contained in:
pancake 2013-09-04 02:01:42 +02:00
parent 5f91da3ab6
commit f61fa0565e
10 changed files with 73 additions and 21 deletions

View File

@ -37,9 +37,10 @@ static inline const char *condstring(RAnalCond *cond) {
}
R_API int r_anal_cond_eval(RAnal *anal, RAnalCond *cond) {
ut64 arg0 = r_anal_value_to_ut64 (anal, cond->arg[0]);
// XXX: sign issue here?
st64 arg0 = (st64) r_anal_value_to_ut64 (anal, cond->arg[0]);
if (cond->arg[1]) {
ut64 arg1 = r_anal_value_to_ut64 (anal, cond->arg[1]);
st64 arg1 = (st64) r_anal_value_to_ut64 (anal, cond->arg[1]);
switch (cond->type) {
case R_ANAL_COND_EQ: return arg0 == arg1;
case R_ANAL_COND_NE: return arg0 != arg1;

View File

@ -189,7 +189,7 @@ R_API int r_meta_add(RMeta *m, int type, ut64 from, ut64 to, const char *str) {
if (r_meta_comment_check (m, str, from))
return R_FALSE;
mi = r_meta_item_new (type);
mi->size = R_ABS (to-from);//size;
mi->size = to-from;
mi->type = type;
mi->from = from;
mi->to = to;

View File

@ -15,13 +15,15 @@ static void show_help() {
" td-foo undefine type 'foo'\n"
" tf addr view linked type at given address\n"
" ts k=v k=v @ link.addr set fields at given linked type\n"
" tl [type] [addr] link type to a given address\n");
" tl [type] ([addr]) show show / link type to a address\n");
}
static int sdbforcb (void *p, const char *k, const char *v) {
r_cons_printf ("%s=%s\n", k, v);
}
static int cmd_type(void *data, const char *input) {
RCore *core = (RCore*)data;
char *arg, pcmd[512];
RAnalType *t = NULL;
switch (input[0]) {
// t [typename] - show given type in C syntax
@ -65,7 +67,8 @@ static int cmd_type(void *data, const char *input) {
#endif
case 0:
// TODO: use r_cons here
sdb_list (core->anal->sdb_types);
//sdb_list (core->anal->sdb_types);
sdb_foreach (core->anal->sdb_types, sdbforcb, core);
break;
case 'o':
if (input[1] == ' ') {
@ -118,19 +121,20 @@ static int cmd_type(void *data, const char *input) {
break;
// tl - link a type to an address
case 'l':
{
ut64 addr = r_num_math (core->num, input+2);
char *ptr = strchr (input + 2, ' ');
if (ptr) {
addr = r_num_math (core->num, ptr + 1);
*ptr = '\0';
if (addr > 0) {
r_anal_type_link (core->anal, input+2, addr);
} else eprintf ("Wrong address to link!\n");
} else
if (input[1]=='?') {
eprintf("Usage: tl[...]\n"
" tl [typename|addr] ([addr])@[addr|function]\n");
}
} else if (input[1]) {
ut64 addr = r_num_math (core->num, input+2);
char *ptr = strchr (input + 2, ' ');
if (ptr) {
addr = r_num_math (core->num, ptr + 1);
*ptr = '\0';
} else addr = core->offset;
r_anal_type_link (core->anal, input+2, addr);
} else {
r_core_cmd0 (core, "t~^link");
}
break;
case '-':
if (input[1]=='*') {
@ -147,8 +151,21 @@ static int cmd_type(void *data, const char *input) {
break;
// tv - get/set type value linked to a given address
case 'f':
snprintf (pcmd, sizeof (pcmd), "pf `t %s`", input+2);
r_core_cmd0 (core, pcmd);
{
ut64 addr;
char *fmt, key[128];
const char *type;
if (input[1]) {
addr = r_num_math (core->num, input+1);
} else addr = core->offset;
snprintf (key, sizeof (key), "link.%"PFMT64x, addr);
type = sdb_getc (core->anal->sdb_types, key, 0);
fmt = r_anal_type_format (core->anal, type);
if (fmt) {
r_core_cmdf (core, "pf %s @ 0x%08"PFMT64x"\n", fmt, addr);
free (fmt);
}// else eprintf ("Cannot find '%s' type\n", input+1);
}
break;
case '?':
if (input[1]) {

View File

@ -1131,7 +1131,7 @@ R_API RBin *r_core_get_bin (RCore *core) { return core->bin; }
R_API RBuffer *r_core_syscall (RCore *core, const char *name, const char *args) {
int i, num;
RBuffer *b= NULL;
char code[1024], ptr[128];
char code[1024];
num = r_syscall_get_num (core->anal->syscall, name);
snprintf (code, sizeof (code),

View File

@ -370,6 +370,10 @@ toro:
refline = strdup ("");
refline2 = strdup ("");
}
/* show type links */
r_core_cmdf (core, "tf 0x%08"PFMT64x, at);
f = show_functions? r_anal_fcn_find (core->anal, at,
R_ANAL_FCN_TYPE_NULL): NULL;
if (!hint || !hint->bits) {

View File

@ -139,7 +139,7 @@ typedef struct r_cons_t {
int truecolor; // 1 = rgb 256), 2 = truecolor (16M)
RConsPalette pal;
struct r_line_t *line;
char **vline;
const char **vline;
} RCons;
// XXX THIS MUST BE A SINGLETON AND WRAPPED INTO RCons */
@ -263,6 +263,7 @@ R_API int r_cons_w32_print(ut8 *ptr, int empty);
#endif
/* control */
R_API char *r_cons_editor (const char *file);
R_API void r_cons_reset();
R_API void r_cons_reset_colors();
R_API void r_cons_print_clear();

View File

@ -181,6 +181,7 @@ R_API char *r_core_cmd_str(RCore *core, const char *cmd);
R_API char *r_core_cmd_strf(RCore *core, const char *fmt, ...);
R_API char *r_core_cmd_str_pipe(RCore *core, const char *cmd);
R_API int r_core_cmd_file(RCore *core, const char *file);
R_API int r_core_cmd_lines(RCore *core, const char *lines);
R_API int r_core_cmd_command(RCore *core, const char *command);
R_API int r_core_run_script (RCore *core, const char *file);
R_API boolt r_core_seek(RCore *core, ut64 addr, boolt rb);

View File

@ -89,6 +89,9 @@ int sdb_sync (Sdb*);
void sdb_kv_free (struct sdb_kv *kv);
void sdb_flush (Sdb* s);
typedef int (*SdbForeachCallback)(void *user, const char *k, const char *v);
void sdb_foreach (Sdb* s, SdbForeachCallback cb, void *user);
/* create db */
int sdb_create (Sdb* s);
int sdb_append (Sdb* s, const char *key, const char *val);

View File

@ -250,6 +250,28 @@ SDB_VISIBLE int sdb_set (Sdb* s, const char *key, const char *val, ut32 cas) {
return kv->cas;
}
SDB_VISIBLE void sdb_foreach (Sdb* s, SdbForeachCallback cb, void *user) {
SdbKv *kv;
SdbListIter *iter;
ls_foreach (s->ht->list, iter, kv) {
if (!kv->value || !*kv->value)
continue;
if (strchr (kv->value, SDB_RS)) {
char *o, *p = strdup (kv->value);
for (o=p; *o; o++) if (*o==SDB_RS) *o = ',';
o = malloc (strlen (kv->key)+3);
memcpy (o, "()", 2);
strcpy (o+2, kv->key);
cb (user, o, p);
free (o);
free (p);
} else {
cb (user, kv->key, kv->value);
}
}
}
// TODO: reuse sdb_foreach
SDB_VISIBLE void sdb_list (Sdb* s) {
SdbKv *kv;
SdbListIter *iter;

View File

@ -89,6 +89,9 @@ int sdb_sync (Sdb*);
void sdb_kv_free (struct sdb_kv *kv);
void sdb_flush (Sdb* s);
typedef int (*SdbForeachCallback)(void *user, const char *k, const char *v);
void sdb_foreach (Sdb* s, SdbForeachCallback cb, void *user);
/* create db */
int sdb_create (Sdb* s);
int sdb_append (Sdb* s, const char *key, const char *val);