From 82d8b0f336e7b3ae66bac4933f80e2b8a7f8e7c3 Mon Sep 17 00:00:00 2001 From: pancake Date: Thu, 19 Aug 2010 20:28:25 +0200 Subject: [PATCH] * Implement r_core_sysenv_update() * Simplify some functions in core/cmd * Move CF -> afs - Add documentation for 'afs' command - Accept numeric argument - Add support for 'get' and 'set' --- TODO | 22 +++++---- libr/core/cmd.c | 102 +++++++++++++++++++++++------------------- libr/core/file.c | 49 +++++++++++--------- libr/include/r_core.h | 1 + 4 files changed, 100 insertions(+), 74 deletions(-) diff --git a/TODO b/TODO index f1609d5454..22d8d8e6eb 100644 --- a/TODO +++ b/TODO @@ -8,6 +8,7 @@ 0.6 RELEASE =========== +* Do not write a lot of spaces in r_line .. results in ugly copypasta and slow terminal * Trace contents of buffers: filter search results..? cc 8080 @@ hit* .. check for values that has changed. * Meld r_meta inside r_anal * Cx/CX are not displayed in disasm as they should.. (C! must die) @@ -50,19 +51,21 @@ TODO edu TODO pancake ------------ -* Implement fcn_from_string anal/fcn.c - - define function signature command: (afs? CF?) - > afs int foo(int var, char* str) @ fun.main - - How to define function variables? CFv? CFa for args? -* Display syscall information when disassembling svc/int/.. (edu?) +* Display syscall information when disassembling svc/int/.. - store last value of REG0 (EAX, R0, ...), select interrupt vector by aop->value and use r_syscall() -* we need an api to define function signatures - - CF void name(int foo, char* var) +{ + * we need an api to define local vars and accesses in function - arg/var set name/get value/ .. -* implement RAnalCall (analyze function arguments, return values, propagate types..) + - CFv{gs}.. => afv + CFv. ; show variables for current function + CFv 20 int ; define local var + CFvg 20 @ 0x8048000 ; access 'get' to delta 20 var (creates var if not exist) + CFvs 20 @ 0x8049000 ; access 'set' to delta 20 var ("") + CFV @ 0x8049000 ; Show local variables and arg values at function + * Implement RAnalCall (analyze function arguments, return values, propagate types..) - define number of arguments for given function - warn if signature and analysis differs in number of args or so.. -* Implement r_sys_setenv stuff from r1 in core/file.c:33 (!!?) +} TODO gerardo ------------ @@ -87,6 +90,7 @@ Bindings Refactoring =========== +* Discuss missing r_core_sysenv_update in core/file.c:33 * Add RLog API.. pipeable to disk and stderr..also hookable ..cool for ui (partially done) * Move disasm loop into r_print (r_print should depend on r_asm) - thats hard :) diff --git a/libr/core/cmd.c b/libr/core/cmd.c index 33871a25ff..a9e32f595f 100644 --- a/libr/core/cmd.c +++ b/libr/core/cmd.c @@ -1690,14 +1690,34 @@ static int cmd_anal(void *data, const char *input) { case '*': r_core_anal_fcn_list (core, input+2, 1); break; + case 's': { + ut64 addr; + RAnalFcn *f; + const char *arg = input+3; + if (input[2] && (addr = r_num_math (core->num, arg))) { + arg = strchr (arg, ' '); + if (arg) arg++; + } else addr = core->offset; + if ((f = r_anal_fcn_find (core->anal, addr))) { + if (arg && *arg) { + r_anal_fcn_from_string (core->anal, f, arg); + } else { + char *str = r_anal_fcn_to_string (core->anal, f); + r_cons_printf ("%s\n", str); + free (str); + } + } else eprintf("No function defined at 0x%08"PFMT64x"\n", addr); + } + break; case '?': r_cons_printf ( "Usage: af[?+-l*]\n" - " af @ [addr] ; Analyze functions (start at addr)\n" + " af @ [addr] ; Analyze functions (start at addr)\n" " af+ addr size name [diff] ; Add function\n" - " af- [addr] ; Clean all function analysis data (or function at addr)\n" - " afl [fcn name] ; List functions\n" - " af* ; Output radare commands\n"); + " af- [addr] ; Clean all function analysis data (or function at addr)\n" + " afl [fcn name] ; List functions\n" + " afs [addr] [fcnsign] ; Get/set function signature at current address\n" + " af* ; Output radare commands\n"); break; default: r_core_anal_fcn (core, core->offset, -1, @@ -1857,6 +1877,9 @@ static int cmd_anal(void *data, const char *input) { /* TODO: simplify using r_write */ static int cmd_write(void *data, const char *input) { + int size; + const char *arg; + ut8 *buf; int i, len = strlen (input); char *tmp, *str = alloca (len)+1; RCore *core = (RCore *)data; @@ -1921,47 +1944,39 @@ static int cmd_write(void *data, const char *input) { r_io_write_at (core->io, core->offset, (const ut8*)str, len); r_core_block_read (core, 0); break; - case 't': { - /* TODO: Support user defined size? */ - int len = core->blocksize; - const char *arg = (const char *)(input+((input[1]==' ')?2:1)); - const ut8 *buf = core->block; - r_file_dump (arg, buf, len); - } break; + case 't': + /* TODO: support userdefined size? */ + arg = (const char *)(input+((input[1]==' ')?2:1)); + r_file_dump (arg, core->block, core->blocksize); + break; case 'T': eprintf ("TODO\n"); break; - case 'f': { - int size; - const char *arg = (const char *)(input+((input[1]==' ')?2:1)); - ut8 *buf = (ut8*) r_file_slurp (arg, &size); - if (buf) { - r_io_set_fd (core->io, core->file->fd); - r_io_write_at (core->io, core->offset, buf, size); - free(buf); - } else eprintf ("Cannot open file '%s'\n", arg); - } break; - case 'F': { - int size; - const char *arg = (const char *)(input+((input[1]==' ')?2:1)); - ut8 *buf = r_file_slurp_hexpairs (arg, &size); - if (buf == NULL) { - r_io_set_fd (core->io, core->file->fd); - r_io_write_at (core->io, core->offset, buf, size); - free (buf); - } else eprintf ("Cannot open file '%s'\n", arg); - } break; + case 'f': + arg = (const char *)(input+((input[1]==' ')?2:1)); + if (!(buf = (ut8*) r_file_slurp (arg, &size))) { + r_io_set_fd (core->io, core->file->fd); + r_io_write_at (core->io, core->offset, buf, size); + free(buf); + } else eprintf ("Cannot open file '%s'\n", arg); + break; + case 'F': + arg = (const char *)(input+((input[1]==' ')?2:1)); + if (!(buf = r_file_slurp_hexpairs (arg, &size))) { + r_io_set_fd (core->io, core->file->fd); + r_io_write_at (core->io, core->offset, buf, size); + free (buf); + } else eprintf ("Cannot open file '%s'\n", arg); + break; case 'w': str = str+1; - len = len-1; - len *= 2; - tmp = alloca(len); + len = (len-1)<<1; + tmp = alloca (len); for (i=0;i>1]; } str = tmp; - r_io_set_fd (core->io, core->file->fd); r_io_write_at (core->io, core->offset, (const ut8*)str, len); r_core_block_read (core, 0); @@ -2003,8 +2018,7 @@ static int cmd_write(void *data, const char *input) { } break; case 'm': - { - int len = r_hex_str2bin (input+1, (ut8*)str); + size = r_hex_str2bin (input+1, (ut8*)str); switch (input[1]) { case '\0': eprintf ("Current write mask: TODO\n"); @@ -2017,19 +2031,16 @@ static int cmd_write(void *data, const char *input) { eprintf ("Write mask disabled\n"); break; case ' ': - if (len == 0) { - eprintf ("Invalid string\n"); - } else { - r_io_set_fd(core->io, core->file->fd); - r_io_set_write_mask(core->io, (const ut8*)str, len); + if (size>0) { + r_io_set_fd (core->io, core->file->fd); + r_io_set_write_mask (core->io, (const ut8*)str, size); eprintf ("Write mask set to '"); - for (i=0;ifile) + return; + if (core->file->filename) + r_sys_setenv ("FILE", core->file->filename); + snprintf (buf, sizeof (buf), "%"PFMT64d, core->offset); + r_sys_setenv ("OFFSET", buf); + snprintf (buf, sizeof (buf), "0x%08"PFMT64x, core->offset); + r_sys_setenv ("XOFFSET", buf); + snprintf (buf, sizeof (buf), "%"PFMT64d, core->file->size); + r_sys_setenv ("SIZE", buf); + r_sys_setenv ("ENDIAN", core->assembler->big_endian?"big":"little"); + snprintf (buf, sizeof (buf), "%d", core->blocksize); + r_sys_setenv ("BSIZE", buf); + r_sys_setenv ("ARCH", r_config_get (core->config, "asm.arch")); + r_sys_setenv ("DEBUG", r_config_get_i (core->config, "cfg.debug")?"1":"0"); + r_sys_setenv ("IOVA", r_config_get_i (core->config, "io.va")?"1":"0"); +} + R_API RCoreFile *r_core_file_open(RCore *r, const char *file, int mode) { RCoreFile *fh; const char *cp; @@ -28,26 +57,6 @@ R_API RCoreFile *r_core_file_open(RCore *r, const char *file, int mode) { fh->size = r_io_size (r->io, fd); list_add (&(fh->list), &r->files); - r_sys_setenv ("FILE", fh->filename); -#if 0 -TODO: clean this list add !!? and all those vars -Usage: !!shell program - DEBUG cfg.debug value as 0 or 1 - EDITOR cfg.editor (vim or so) - ARCH asm.arch value - OFFSET decimal value of current seek - XOFFSET hexadecimal value of cur seek - CURSOR cursor position (offset from curseek) - VADDR io.vaddr - COLOR scr.color?1:0 - VERBOSE cfg.verbose - FILE cfg.file - SIZE file size - BSIZE block size - ENDIAN 'big' or 'little' depending on cfg.bigendian - BYTES hexpairs of current block - BLOCK temporally file with contents of current block -#endif r_bin_load (r->bin, fh->filename, NULL); r_core_block_read (r, 0); diff --git a/libr/include/r_core.h b/libr/include/r_core.h index 21bb18cbb4..f726ef3aba 100644 --- a/libr/include/r_core.h +++ b/libr/include/r_core.h @@ -142,6 +142,7 @@ R_API int r_core_gdiff(struct r_core_t *core, char *file1, char *file2, int va); R_API int r_core_project_open(RCore *core, const char *file); R_API int r_core_project_save(RCore *core, const char *file); R_API char *r_core_project_info(RCore *core, const char *file); +R_API void r_core_sysenv_update(RCore *core); #endif