diff --git a/TODO b/TODO index 097101da62..4e66328442 100644 --- a/TODO +++ b/TODO @@ -14,6 +14,8 @@ Big number support ====[[ 0.9.4 ]]==== +* rap:/ doesnt works at all +* implement =. command to get data from a socket tothink: * Event system . allow to send and read queues of messages.. thats pubsub! * search for CALL instructions in text segment. diff --git a/binr/rarun2/rarun2.c b/binr/rarun2/rarun2.c index aee8ef762c..18a10a13a4 100644 --- a/binr/rarun2/rarun2.c +++ b/binr/rarun2/rarun2.c @@ -1,4 +1,5 @@ -/* radare2 - Copyleft 2011 - pancake */ +/* radare2 - Copyleft 2011-2012 - pancake */ + #include #include #include @@ -177,10 +178,9 @@ static int runfile () { int main(int argc, char **argv) { int i; FILE *fd; - char *file, buf[1024]; + char *file, buf[4096]; if (argc==1 || !strcmp (argv[1], "-h")) { - fprintf (stderr, "Usage: rarun2 [''|script.rr2] [options ...]\n" - "> options are file directives:\n"); + fprintf (stderr, "Usage: rarun2 [-v] [script.rr2] [directive ..]\n"); printf ( "program=/bin/ls\n" "arg1=/bin\n" @@ -201,8 +201,12 @@ int main(int argc, char **argv) { "# setegid=2001\n"); return 1; } + if (!strcmp (argv[1], "-v")) { + printf ("rarun2 "R2_VERSION"\n"); + return 0; + } file = argv[1]; - if (*file) { + if (*file && !strchr (file, '=')) { fd = fopen (file, "r"); if (!fd) { fprintf (stderr, "Cannot open %s\n", file); @@ -216,7 +220,7 @@ int main(int argc, char **argv) { } fclose (fd); } else { - for (i=2; iaddr == addr || !strcmp (fcni->name, input+1)) { if (!rad) { - r_cons_printf ("[0x%08"PFMT64x"] size=%"PFMT64d" name=%s", - fcni->addr, fcni->size, fcni->name); - r_cons_printf (" type=%s", + int nrefs = r_list_length (fcni->refs); + int nxrefs = r_list_length (fcni->xrefs); + r_cons_printf ("#\n offset: 0x%08"PFMT64x"\n name: %s\n size: %"PFMT64d, + fcni->addr, fcni->name, fcni->size); + r_cons_printf ("\n type: %s", fcni->type==R_ANAL_FCN_TYPE_SYM?"sym": fcni->type==R_ANAL_FCN_TYPE_IMP?"imp":"fcn"); if (fcni->type==R_ANAL_FCN_TYPE_FCN || fcni->type==R_ANAL_FCN_TYPE_SYM) @@ -496,42 +498,42 @@ R_API int r_core_anal_fcn_list(RCore *core, const char *input, int rad) { fcni->diff->type==R_ANAL_DIFF_TYPE_MATCH?"MATCH": fcni->diff->type==R_ANAL_DIFF_TYPE_UNMATCH?"UNMATCH":"NEW"); - r_cons_printf ("\n CODE refs: "); + r_cons_printf ("\n call-refs: "); r_list_foreach (fcni->refs, iter2, refi) if (refi->type == R_ANAL_REF_TYPE_CODE || refi->type == R_ANAL_REF_TYPE_CALL) - r_cons_printf ("0x%08"PFMT64x"(%c) ", refi->addr, + r_cons_printf ("0x%08"PFMT64x" %c ", refi->addr, refi->type==R_ANAL_REF_TYPE_CALL?'C':'J'); - r_cons_printf ("\n DATA refs: "); + r_cons_printf ("\n data-refs: "); r_list_foreach (fcni->refs, iter2, refi) if (refi->type == R_ANAL_REF_TYPE_DATA) r_cons_printf ("0x%08"PFMT64x" ", refi->addr); - r_cons_printf ("\n CODE xrefs: "); + r_cons_printf ("\n code-xrefs: "); r_list_foreach (fcni->xrefs, iter2, refi) if (refi->type == R_ANAL_REF_TYPE_CODE || refi->type == R_ANAL_REF_TYPE_CALL) - r_cons_printf ("0x%08"PFMT64x"(%c) ", refi->addr, + r_cons_printf ("0x%08"PFMT64x" %c ", refi->addr, refi->type==R_ANAL_REF_TYPE_CALL?'C':'J'); - r_cons_printf ("\n DATA xrefs: "); + r_cons_printf ("\n data-xrefs: "); r_list_foreach (fcni->xrefs, iter2, refi) if (refi->type == R_ANAL_REF_TYPE_DATA) r_cons_printf ("0x%08"PFMT64x" ", refi->addr); if (fcni->type==R_ANAL_FCN_TYPE_FCN || fcni->type==R_ANAL_FCN_TYPE_SYM) { - r_cons_printf ("\n vars:"); + r_cons_printf ("\n vars: %d"); r_list_foreach (fcni->vars, iter2, vari) - r_cons_printf ("\n %-10s delta=0x%02x type=%s", vari->name, - vari->delta, r_anal_type_to_str (core->anal, vari->type, ";")); - r_cons_printf ("\n diff: type=%s", + r_cons_printf ("\n %s %s @ 0x%02x", r_anal_type_to_str ( + core->anal, vari->type, ";"), vari->name, vari->delta); + r_cons_printf ("\n diff: type: %s", fcni->diff->type==R_ANAL_DIFF_TYPE_MATCH?"match": fcni->diff->type==R_ANAL_DIFF_TYPE_UNMATCH?"unmatch":"new"); if (fcni->diff->addr != -1) - r_cons_printf (" addr=0x%"PFMT64x, fcni->diff->addr); + r_cons_printf (" addr: 0x%"PFMT64x, fcni->diff->addr); if (fcni->diff->name != NULL) - r_cons_printf (" function=%s", + r_cons_printf (" function: %s", fcni->diff->name); } r_cons_newline (); diff --git a/libr/core/cmd_help.c b/libr/core/cmd_help.c index 493c6b2848..dd8f27cbef 100644 --- a/libr/core/cmd_help.c +++ b/libr/core/cmd_help.c @@ -336,6 +336,12 @@ static int cmd_help(void *data, const char *input) { " $b = block size\n" " $j = jump address (e.g. jmp 0x10, jz 0x10 => 0x10)\n" " $f = jump fail address (e.g. jz 0x10 => next instruction)\n" + " $I = number of instructions of current function\n" + " $F = current function size \n" + " $Jn = get nth jump of function\n" + " $Cn = get nth call of function\n" + " $Dn = get nth data reference in function\n" + " $Xn = get nth xref of function\n" " $r = opcode memory reference (e.g. mov eax,[0x10] => 0x10)\n" " $l = opcode length\n" " $e = 1 if end of block, else 0\n" diff --git a/libr/core/cmd_print.c b/libr/core/cmd_print.c index 3dfd06edd1..c80a777998 100644 --- a/libr/core/cmd_print.c +++ b/libr/core/cmd_print.c @@ -207,19 +207,15 @@ static int cmd_print(void *data, const char *input) { RAsmOp asmop; int j, ret, err = 0; const ut8 *buf = core->block; - int tbs = 0; int bs = core->blocksize; if (input[1]=='f') { RAnalFunction *f = r_anal_fcn_find (core->anal, core->offset, R_ANAL_FCN_TYPE_FCN|R_ANAL_FCN_TYPE_SYM); - if (f) { - len = bs = f->size; - tbs = core->blocksize; - } + if (f) len = bs = f->size; } - if (bs>core->blocksize) - r_core_block_size (core, tbs); + if (len>core->blocksize) + r_core_block_size (core, len); if (l==0) l = len; for (i=j=0; iblock; if (l==0) l = len; - for (i=j=0; iblocksize && jassembler, &asmop, buf+i, core->blocksize-i); if (ret<1) { ret = err = 1; @@ -597,7 +592,7 @@ static int cmd_print(void *data, const char *input) { " pd[lf] [l] disassemble N opcodes (see pd?)\n" " pD [len] disassemble N bytes\n" " pf [fmt] print formatted data\n" - " pi[f] [len] print N instructions (f=function)\n" + " pi[f] [len] print N instructions (f=function) (see pdi)\n" " pm [magic] print libmagic data (pm? for more information)\n" " pr [len] print N raw bytes\n" " ps[pwz] [len] print pascal/wide/zero-terminated strings\n" diff --git a/libr/core/core.c b/libr/core/core.c index 1cec7bf9ec..0e32640829 100644 --- a/libr/core/core.c +++ b/libr/core/core.c @@ -14,6 +14,23 @@ static int core_cmd_callback (void *user, const char *cmd) { return r_core_cmd0 (core, cmd); } +static ut64 getref (RCore *core, int n, char t, int type) { + RAnalFunction *fcn = r_anal_fcn_find (core->anal, core->offset, 0); + if (fcn) { + RList *list = t=='r'? fcn->refs: fcn->xrefs; + RListIter *iter; + RAnalRef *r; + int i=0; + r_list_foreach (list, iter, r) { + if (r->type == type) { + if (i == n) + return r->addr; + i++; + } + } + } + return UT64_MAX; +} static ut64 num_callback(RNum *userptr, const char *str, int *ok) { RCore *core = (RCore *)userptr; // XXX ? RFlagItem *flag; @@ -24,13 +41,13 @@ static ut64 num_callback(RNum *userptr, const char *str, int *ok) { int refsz = (core->assembler->bits & R_SYS_BITS_64)? 8: 4; const char *p = strchr (str+1, ':'); ut64 n; -// TODO: honor endian + // TODO: honor endian if (p) { refsz = atoi (str+1); str = p; } -// push state -{ + // push state + { const char *q = r_num_calc_index (core->num, NULL); n = r_num_math (core->num, str+1); r_num_calc_index (core->num, q); @@ -90,6 +107,22 @@ r_num_calc_index (core->num, q); case '?': return core->num->value; case '$': return core->offset; case 'o': return core->io->off; + case 'C': return getref (core, atoi (str+2), 'r', R_ANAL_REF_TYPE_CALL); + case 'J': return getref (core, atoi (str+2), 'r', R_ANAL_REF_TYPE_CODE); + case 'D': return getref (core, atoi (str+2), 'r', R_ANAL_REF_TYPE_DATA); + case 'X': return getref (core, atoi (str+2), 'x', R_ANAL_REF_TYPE_CALL); + case 'I': + { + RAnalFunction *fcn = r_anal_fcn_find (core->anal, core->offset, 0); + if (fcn) return fcn->ninstr; + return 0; + } + case 'F': + { + RAnalFunction *fcn = r_anal_fcn_find (core->anal, core->offset, 0); + if (fcn) return fcn->size; + return 0; + } } } else if (*str>'A') { diff --git a/man/rabin2.1 b/man/rabin2.1 index 035ca75a65..d9fe7c9ad9 100644 --- a/man/rabin2.1 +++ b/man/rabin2.1 @@ -1,4 +1,4 @@ -.Dd Mar 11, 2010 +.Dd Mar 11, 2012 .Dt RABIN2 1 .Os .Sh NAME @@ -81,13 +81,29 @@ Show version information .It Fl h Show usage help message. .El +.Sh EXAMPLES +.Pp +List symbols of a program +.Pp + $ rabin2 -s a.out +.Pp +Get offset of symbol +.Pp + $ rabin2 -n _main a.out +.Pp +Get entrypoint +.Pp + $ rabin2 -e a.out +.Pp +Load symbols and imports from radare +.Pp + .!rabin2 -rsi a.out .Sh SEE ALSO .Pp .Xr rahash2(1) , .Xr rafind2(1) , .Xr radare2(1) , .Xr radiff2(1) , -.Xr ranal2(1) , .Xr rasm2(1) , .Xr rax2(1) , .Xr rsc2(1) , diff --git a/man/radare2.1 b/man/radare2.1 index d78e808d81..7a4e3ab22c 100644 --- a/man/radare2.1 +++ b/man/radare2.1 @@ -88,7 +88,6 @@ path to the current working file .Xr rafind2(1) , .Xr rabin2(1) , .Xr radiff2(1) , -.Xr ranal2(1) , .Xr rasm2(1) , .Xr rax2(1) , .Xr ragg2(1) , diff --git a/man/radiff2.1 b/man/radiff2.1 index f89626fcb2..7c43fa9720 100644 --- a/man/radiff2.1 +++ b/man/radiff2.1 @@ -44,7 +44,6 @@ Show usage help message. .Xr rafind2(1) , .Xr rahash2(1) , .Xr rabin2(1) , -.Xr ranal2(1) , .Xr rasm2(1) , .Xr ragg2(1) , .Xr rarun2(1) , diff --git a/man/rafind2.1 b/man/rafind2.1 index acc60c6ecd..89b1806751 100644 --- a/man/rafind2.1 +++ b/man/rafind2.1 @@ -50,7 +50,6 @@ Print version and exit .Xr radare2(1) , .Xr rahash2(1) , .Xr rabin2(1) , -.Xr ranal2(1) , .Xr radiff2(1) , .Xr rasm2(1) , .Xr ragg2(1) , diff --git a/man/ragg2-cc.1 b/man/ragg2-cc.1 index 804eb5fc08..05e0fcd4b8 100644 --- a/man/ragg2-cc.1 +++ b/man/ragg2-cc.1 @@ -1,4 +1,4 @@ -.Dd Dec 5, 2011 +.Dd Dec 5, 2012 .Dt RAGG2-CC 1 .Os .Sh NAME @@ -79,7 +79,6 @@ show hexpair bytes .Xr rafind2(1) , .Xr rabin2(1) , .Xr rafind2(1) , -.Xr ranal2(1) , .Xr radiff2(1) , .Xr rasm2(1) , .Xr ragg2cc(1) , diff --git a/man/ragg2.1 b/man/ragg2.1 index 50d130f562..80f596ed71 100644 --- a/man/ragg2.1 +++ b/man/ragg2.1 @@ -107,7 +107,6 @@ execute (just-in-time) .Xr rafind2(1) , .Xr rabin2(1) , .Xr rafind2(1) , -.Xr ranal2(1) , .Xr radiff2(1) , .Xr rasm2(1) , .Sh AUTHORS diff --git a/man/rahash2.1 b/man/rahash2.1 index ba4c1104f8..4baca4a8b0 100644 --- a/man/rahash2.1 +++ b/man/rahash2.1 @@ -49,7 +49,6 @@ Show usage help message. .Xr rafind2(1) , .Xr rahash2(1) , .Xr rabin2(1) , -.Xr ranal2(1) , .Xr radiff2(1) , .Xr rasm2(1) , .Xr ragg2(1) , diff --git a/man/ranal2.1 b/man/ranal2.1 deleted file mode 100644 index eeb9e64213..0000000000 --- a/man/ranal2.1 +++ /dev/null @@ -1,48 +0,0 @@ -.Dd Oct 27, 2010 -.Dt RANAL2 1 -.Os -.Sh NAME -.Nm ranal2 -.Nd radare2 code analysis commandline frontend -.Sh SYNOPSIS -.Nm ranal2 -.Op -BhL -.Op -a arch -.Op -b bits -.Op -l inputlen -.Op -o offset -.Ar hexpairs|- -.Sh DESCRIPTION -ranal2 provides a commandline utility to test and perform some code analysis work on a provided hexpair as argument or from stdin if the argument is '-'. -.Pp -.Bl -tag -width Fl -.It Fl a Ar arch -Set a different architecture (x86, ppc, arm, java) -.It Fl b Ar bits -Specify bit size of registers: 8, 16, 32, 64 -.It Fl B -Input is binary, \-l is mandatory. Useful for stdin -.It Fl h -Show help message -.It Fl l Ar len -Specify length of input data -.It Fl L -List all supported code analysis plugins -.It Fl o Ar offset -Offset of the opcode to assemble -.El -.Sh SEE ALSO -.Pp -.Xr radare2(1) , -.Xr rafind2(1) , -.Xr rahash2(1) , -.Xr rabin2(1) , -.Xr radiff2(1) , -.Xr ragg2(1) , -.Xr rarun2(1) , -.Xr rasm2(1) , -.Xr rax2(1) , -.Sh AUTHORS -.Pp -pancake , -nibble diff --git a/man/rarun2.1 b/man/rarun2.1 index 21bb19e038..fc907e317d 100644 --- a/man/rarun2.1 +++ b/man/rarun2.1 @@ -1,4 +1,4 @@ -.Dd Oct 11, 2011 +.Dd Oct 17, 2012 .Dt RARUN2 1 .Os .Sh NAME @@ -44,7 +44,8 @@ set value for given environment variable .It Ar arg[0-3] set value for argument N passed to the program .El -.Sh EXAMPLE +.Sh EXAMPLES +Sample rarun2 script .Pp $ cat foo.rr2 #!/usr/bin/rarun2 @@ -55,13 +56,17 @@ set value for argument N passed to the program #chroot=. ./foo.rr2 .Pp +Connecting a program to a socket +.Pp + $ nc -l 9999 + $ rarun2 program=/bin/ls connect=localhost:9999 +.Pp .Sh SEE ALSO .Pp .Xr radare2(1) , .Xr rahash2(1) , .Xr rafind2(1) , .Xr rabin2(1) , -.Xr ranal2(1) , .Xr radiff2(1) , .Xr ragg2(1) , .Xr rasm2(1) , diff --git a/man/rasm2.1 b/man/rasm2.1 index cf6742fd3f..26b73c356e 100644 --- a/man/rasm2.1 +++ b/man/rasm2.1 @@ -1,9 +1,9 @@ -.Dd Mar 11, 2010 +.Dd Mar 11, 2012 .Dt RASM2 1 .Os .Sh NAME .Nm rasm2 -.Nd radare2 patch assembler and disassembler +.Nd radare2 assembler and disassembler tool .Sh SYNOPSIS .Nm rasm2 .Op Fl dDfBCLev @@ -27,7 +27,7 @@ Read data from file instead of ARG. .It Fl F Ar in:out Specify input and/or output filters (att2intel, x86.pseudo, ...) .It Fl o Ar offset -Offset of the opcode to assemble +Offset of the opcode to assemble (default is 0) .It Fl a Ar arch Set architecture plugin .It Fl b Ar bits @@ -45,15 +45,23 @@ List supported asm plugins .It Fl e Use big endian .It Fl h -.El Show usage help message. +.El +.Sh EXAMPLES +.Pp +Assemble opcode: +.Pp + $ rasm2 -a x86 -b 32 'mov eax, 33' +.Pp +Disassemble opcode: +.Pp + $ rasm2 -d 90 .Sh SEE ALSO .Pp .Xr radare2(1) , .Xr rafind2(1) , .Xr rahash2(1) , .Xr rabin2(1) , -.Xr ranal2(1) , .Xr radiff2(1) , .Xr ragg2(1) , .Xr rarun2(1) , diff --git a/man/rax2.1 b/man/rax2.1 index 836afb2b25..539123128f 100644 --- a/man/rax2.1 +++ b/man/rax2.1 @@ -75,7 +75,6 @@ It is very useful tool for scripting, so you can read floating point values, or .Xr rahash2(1) , .Xr rafind2(1) , .Xr rabin2(1) , -.Xr ranal2(1) , .Xr radiff2(1) , .Xr ragg2(1) , .Xr rarun2(1) , diff --git a/man/rsc2.1 b/man/rsc2.1 index bcba9619c4..c3df7b6b7a 100644 --- a/man/rsc2.1 +++ b/man/rsc2.1 @@ -24,7 +24,6 @@ Show usage help message. .Xr rafind2(1) , .Xr radare2(1) , .Xr radiff2(1) , -.Xr ranal2(1) , .Xr rasm2(1) , .Xr rax2(1) , .Xr ragg2(1) , diff --git a/r2-bindings/node-ffi/examples/r2irc.js b/r2-bindings/node-ffi/examples/r2irc.js index 96b5cd7afa..6c4758e480 100644 --- a/r2-bindings/node-ffi/examples/r2irc.js +++ b/r2-bindings/node-ffi/examples/r2irc.js @@ -55,10 +55,11 @@ core.cmd0 ('? entry0') core.cmd0 ('pd @entry0') /* initialize irc connection */ +core.config.set ("cfg.sandbox", "true"); print (Chi, "[=>] Connecting to irc ",Cend) -print (Chi, " HOST: ", host,":",port,Cend) -print (Chi, " NICK: ",nick," ",channel, Cend); +print (Chi, " HOST: ", host, ":", port, Cend) +print (Chi, " NICK: ", nick, " ", channel, Cend); var IRC = require ('irc.js'); irc = new IRC (host, port);