* 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'
This commit is contained in:
pancake 2010-08-19 20:28:25 +02:00
parent 4b052b53ee
commit 82d8b0f336
4 changed files with 100 additions and 74 deletions

22
TODO
View File

@ -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<addr> 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 :)

View File

@ -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<len;i++) {
if (i%2) tmp[i] = 0;
else tmp[i] = str[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;i<len;i++)
for (i=0;i<size;i++)
eprintf ("%02x", str[i]);
eprintf ("'\n");
}
} else eprintf ("Invalid string\n");
break;
}
}
break;
case 'v':
{
@ -2448,6 +2459,7 @@ static int cmd_visual(void *data, const char *input) {
}
static int cmd_system(void *data, const char *input) {
r_core_sysenv_update ((RCore*)data);
return r_sys_cmd (input);
}

View File

@ -8,6 +8,35 @@ R_API ut64 r_core_file_resize(struct r_core_t *core, ut64 newsize) {
return 0LL;
}
R_API void r_core_sysenv_update(RCore *core) {
char buf[64];
#if DISCUSS
EDITOR cfg.editor (vim or so)
CURSOR cursor position (offset from curseek)
COLOR scr.color?1:0
VERBOSE cfg.verbose
// only if cmd matches BYTES or BLOCK ?
BYTES hexpairs of current block
BLOCK temporally file with contents of current block
#endif
if (!core->file)
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);

View File

@ -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