From cc35fbf14fe195c6198c300f4e59a8a7cc1f7cfe Mon Sep 17 00:00:00 2001 From: pancake Date: Wed, 30 Jun 2010 11:59:52 +0200 Subject: [PATCH] * Added file.desc * Cx/CX is not working again, needs more love * Implemented 'pdf' .. needs review --- TODO | 18 ++++---- libr/core/cmd.c | 112 +++++++++++++++++++++++++-------------------- libr/core/config.c | 1 + libr/meta/meta.c | 4 +- 4 files changed, 72 insertions(+), 63 deletions(-) diff --git a/TODO b/TODO index c2dfc4b540..f271a92cf8 100644 --- a/TODO +++ b/TODO @@ -11,13 +11,18 @@ Questions: ---------- +* There's dup of info between RMeta and RAnal .. functions.. oh fuck! * imports from PE doesnt works with /a because there's an indirect call * rabin2 doesnt works for osx-x86 mach0 bins..so io.va=1 fails * Store version information in libraries ? debian claims for it * Load symbol information from libraries (only the ones imported by rabin2?) +* Implement 'av' command we need it (really?) how about to eval with ? +* filter search results..? cc 8080 @@ hit* .. check for values that has changed. Bugs: ----- +* Vu doesnt seems to work always fine :/ +* Cx/CX are not displayed in disasm as they should.. (C! must die) * if we use objcopy --stripsymbols on a library..the stripped symbols are not listed by nm or rabin..but objcopy is able to see them O_O * anal bug: (fixed??) @@ -28,6 +33,7 @@ Bugs: TODO: ----- +* Add 'prj.name', 'prj.desc' * port r_sign to RList * pancake: implement callback for conditional breakpoints * nibble: trace counts after step..thats not correct! @@ -38,6 +44,7 @@ TODO: * pancake: FileDescriptors: dd -- copy from !fd in r1 * pancake: we need an api to define function signatures - arg/var set name/get value/ .. + - CF* must be used to define function shit - integrated with function signatures - offset -> formatstring (offset is the key to function signature) * pancake: implement RAnalCall (analyze function arguments, return values, propagate types..) @@ -107,6 +114,7 @@ Build system Refactoring =========== +* Add RLog API.. pipeable to disk and stderr..also hookable ..cool for ui * Move disasm loop into r_print (r_print should depend on r_asm) - thats hard :) * Move 'r_syscall_t' stuff into r_debug (sync r_core) @@ -122,16 +130,6 @@ Refactoring * semi-ok state (R_TRUFAE), implement r_errno and r_errstr in r_util? * Finish and import the spp's getopt owns implementation in r_util (like in p9) * Rename __UNIX__ as __POSIX__ - -Design -====== -* Implement 'av' command we need it (really?) how about to eval with ? -* filter search results.. - cc 8080 @@ hit* .. check for values that has changed. - - maybe we should 'cache' some memory regions -* Add 'prj.name', 'prj.desc' -* Add description to project e file.desc ? -* Add RLog API.. pipeable to disk and stderr..also hookable ..cool for ui Future ====== diff --git a/libr/core/cmd.c b/libr/core/cmd.c index 09439324d1..4c7acce90f 100644 --- a/libr/core/cmd.c +++ b/libr/core/cmd.c @@ -94,6 +94,7 @@ static void r_print_disasm(RPrint *p, RCore *core, ut64 addr, ut8 *buf, int len, } // TODO : line analysis must respect data types! shouldnt be interpreted as code line = r_anal_reflines_str (core->anal, core->reflines, addr, linesopts); + // TODO: implement ranged meta find (if not at the begging of function.. mi = r_meta_find (core->meta, (ut64)core->offset+idx, R_META_ANY, R_META_WHERE_HERE); ret = r_asm_disassemble (core->assembler, &asmop, buf+idx, len-idx); if (ret<1) { @@ -105,27 +106,26 @@ static void r_print_disasm(RPrint *p, RCore *core, ut64 addr, ut8 *buf, int len, r_anal_aop (core->anal, &analop, addr, buf+idx, (int)(len-idx)); // TODO: Show xrefs in both sides.. - if (mi) { - if (mi->from == addr) { - RListIter *iter; - RMetaItem *x; - r_list_foreach (mi->xrefs, iter, x) { - switch (x->type) { - case 'c': - case R_META_XREF_CODE: - r_cons_printf ("Cx # code xref from 0x%08llx\n", mi->to); - break; - case 'd': - case R_META_XREF_DATA: - r_cons_printf ("CX # data xref from 0x%08llx\n", mi->to); - break; - } + if (mi && mi->from == addr) { + RListIter *iter; + RMetaItem *x; + r_list_foreach (mi->xrefs, iter, x) { + switch (x->type) { + case 'c': + case R_META_XREF_CODE: + r_cons_printf ("Cx # code xref from 0x%08llx\n", mi->to); + break; + case 'd': + case R_META_XREF_DATA: + r_cons_printf ("CX # data xref from 0x%08llx\n", mi->to); + break; } } } if (adistrick) middle = r_anal_reflines_middle (core->anal, core->reflines, addr, analop.length); + /* XXX: This is really cpu consuming.. need to be fixed */ { int found = 0; RListIter *iter; @@ -1271,7 +1271,18 @@ static int cmd_print(void *data, const char *input) { switch (input[0]) { case 'D': case 'd': - r_print_disasm (core->print, core, core->offset, core->block, len, l); + if (input[1]=='f') { + RMetaItem *item = r_meta_find (core->meta, core->offset, R_META_FUNCTION, R_META_WHERE_HERE); + if (item) { + int blocklen = item->size; + ut8 *block = malloc (item->size+1); + if (block) { + r_core_read_at (core, core->offset, block, blocklen); + r_print_disasm (core->print, core, core->offset, block, blocklen, 9999); + free (block); + } + } else eprintf ("Cannot find function at 0x%08"PFMT64x"\n", core->offset); + } else r_print_disasm (core->print, core, core->offset, core->block, len, l); break; case 's': r_print_string (core->print, core->offset, core->block, len, 0, 1, 0); //, 78, 1); @@ -2376,49 +2387,50 @@ static int cmd_meta(void *data, const char *input) { case 'x': /* code xref */ case 'X': /* data xref */ case 'F': /* add function */ - if (input[1]=='-') { + switch (input[1]) { + case '-': if (input[2]==' ') addr = r_num_math (core->num, input+3); r_meta_del (core->meta, input[0], addr, addr+1, ""); - } else - if (input[1]=='\0'||input[1]=='*') { + break; + case '\0': + case '*': r_meta_list (core->meta, input[0]); - } else { - char fun_name[128]; + break; + default: { + char *t, *p, fun_name[128]; int type = input[0]; - char *t, *p = strchr (input+2, ' '); + t = strdup (input+2); + p = strchr (t, ' '); if (p) { - t = strdup (p+1); - p = strchr (t, ' '); - if (p) { - *p = '\0'; - strncpy (fun_name, p+1, sizeof (fun_name)); - } else - switch (type) { - case 'F': - sprintf (fun_name, "sub_%08"PFMT64x"", addr); - break; - case 's': - // TODO: filter \n and so on :) - r_core_read_at (core, addr, (ut8*)fun_name, sizeof (fun_name)); - break; - default: - { - RFlagItem *fi = r_flag_get_i (core->flags, addr); - if (fi) snprintf (fun_name, sizeof (fun_name), fi->name); - else sprintf (fun_name, "ptr_%08"PFMT64x"", addr); - } + *p = '\0'; + strncpy (fun_name, p+1, sizeof (fun_name)); + } else + switch (type) { + case 'F': + sprintf (fun_name, "sub_%08"PFMT64x"", addr); + break; + case 's': + // TODO: filter \n and so on :) + r_core_read_at (core, addr, (ut8*)fun_name, sizeof (fun_name)); + break; + default: + { + RFlagItem *fi = r_flag_get_i (core->flags, addr); + if (fi) snprintf (fun_name, sizeof (fun_name), fi->name); + else sprintf (fun_name, "ptr_%08"PFMT64x"", addr); } - addr = r_num_math (core->num, t); - if (addr==0LL) // TODO: handle this? eprintf ("FAIL. meta\n"); - addr = core->offset; - // only get abs address in Cx and CX - if (type == 'x' || type == 'X') - addr_end = r_num_math (core->num, input+2); - else addr_end = addr + atoi (input+1); - free (t); } + // only get abs address in Cx and CX + if (type == 'x' || type == 'X') { + if (p) { + addr = r_num_math (core->num, input+2); + addr_end = r_num_math (core->num, p+1); + } else addr_end = r_num_math (core->num, input+2); + } else addr_end = addr + atoi (input+1); + free (t); r_meta_add (core->meta, type, addr, addr_end, fun_name); + } } break; case '-': diff --git a/libr/core/config.c b/libr/core/config.c index c40c56415e..45c805bd17 100644 --- a/libr/core/config.c +++ b/libr/core/config.c @@ -216,6 +216,7 @@ R_API int r_core_config_init(RCore *core) { r_config_set_cb (cfg, "io.va", "true", &config_iova_callback); r_config_set_cb (cfg, "io.cache", "false", &config_iocache_callback); r_config_set (cfg, "file.path", ""); + r_config_set (cfg, "file.desc", ""); r_config_set (cfg, "file.project", ""); r_config_set (cfg, "file.md5", ""); r_config_set (cfg, "file.sha1", ""); diff --git a/libr/meta/meta.c b/libr/meta/meta.c index 409f9230d2..60c6fc9722 100644 --- a/libr/meta/meta.c +++ b/libr/meta/meta.c @@ -224,9 +224,7 @@ R_API int r_meta_add(RMeta *m, int type, ut64 from, ut64 to, const char *str) { R_API RMetaItem *r_meta_find(RMeta *m, ut64 off, int type, int where) { RMetaItem *d, *it = NULL; RListIter *iter; - if (off==0LL) - return NULL; - + if (off) r_list_foreach (m->data, iter, d) { if (d->type == type || type == R_META_ANY) { switch (where) {