Add new code analysis vars and update manpages

rasm2 defaults -o to 0 instead of 0x8048000
fixes in rarun2 to make it more userfriendly
update some manpages with examples
enhace output of 'afi' command
fix 'pi' bug setting blocksize
fix 'pdi' bug ignoring user defined len
add $C $J $X and $F $I code analysis variables
run r2irc.js in sandbox mode
This commit is contained in:
pancake 2012-10-22 02:28:42 +02:00
parent e48b9b2f30
commit 7f5a84b57a
20 changed files with 124 additions and 108 deletions

2
TODO
View File

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

View File

@ -1,4 +1,5 @@
/* radare2 - Copyleft 2011 - pancake<nopcode.org> */
/* radare2 - Copyleft 2011-2012 - pancake */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -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; i<argc; i++)
for (i=*file?1:2; i<argc; i++)
parseline (argv[i]);
}
return runfile ();

View File

@ -25,12 +25,12 @@ static void r_asm_list(RAsm *a) {
}
static int rasm_show_help() {
printf ("rasm2 [-e] [-o offset] [-a arch] [-s syntax] -d \"opcode\"|\"hexpairs\"|- [-f file ..]\n"
printf ("rasm2 [-de] [-o offset] [-a arch] [-s syntax] [-f file ..] \"code\"|hex|-\n"
" -d Disassemble from hexpair bytes\n"
" -D Disassemble showing hexpair and opcode\n"
" -f Read data from file\n"
" -F [in:out] Specify input and/or output filters (att2intel, x86.pseudo, ...)\n"
" -o [offset] Set start address for code (0x%08"PFMT64x")\n"
" -o [offset] Set start address for code (default 0)\n"
" -a [arch] Set assemble/disassemble plugin\n"
" -b [bits] Set cpu register size in bits (16, 32, 64)\n"
" -s [syntax] Select syntax (intel, att)\n"
@ -41,7 +41,7 @@ static int rasm_show_help() {
" -e Use big endian\n"
" -v Show version information\n"
" If '-l' value is greater than output length, output is padded with nops\n"
" If the last argument is '-' reads from stdin\n", R_SYS_BASE);
" If the last argument is '-' reads from stdin\n");
return 0;
}
@ -144,7 +144,7 @@ static int __lib_asm_dt(struct r_lib_plugin_t *pl, void *p, void *u) { return R_
int main(int argc, char *argv[]) {
char *arch = NULL, *file = NULL, *filters = NULL;
ut64 offset = R_SYS_BASE;
ut64 offset = 0;
int dis = 0, ascii = 0, bin = 0, ret = 0, bits = 32, c;
ut64 len = 0, idx = 0;

View File

@ -486,9 +486,11 @@ R_API int r_core_anal_fcn_list(RCore *core, const char *input, int rad) {
|| fcni->addr == 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 ();

View File

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

View File

@ -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; i<bs && j<len; i+=ret,j++ ) {
@ -229,9 +225,8 @@ static int cmd_print(void *data, const char *input) {
r_cons_printf ("???\n");
} else r_cons_printf ("%s\n", asmop.buf_asm);
}
if (tbs) r_core_block_size (core, tbs);
return err;
}
break;
case 'D':
case 'd':
switch (input[1]) {
@ -240,7 +235,7 @@ static int cmd_print(void *data, const char *input) {
int j, ret, err = 0;
const ut8 *buf = core->block;
if (l==0) l = len;
for (i=j=0; i<core->blocksize && j<len && j<l; i+=ret,j++ ) {
for (i=j=0; j<len && j<l; i+=ret,j++ ) {
ret = r_asm_disassemble (core->assembler, &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"

View File

@ -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') {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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 <pancake@nopcode.org>,
nibble <nibble@develsec.org>

View File

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

View File

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

View File

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

View File

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

View File

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