Better help for '?' '???' '?$?' '@' and others..

This commit is contained in:
pancake 2012-12-22 03:37:50 +01:00
parent 4d22fcb806
commit 1f1b0f32e9
5 changed files with 148 additions and 110 deletions

View File

@ -862,9 +862,11 @@ next2:
r_cons_grep (ptr);
/* seek commands */
if (*cmd!='(' && *cmd!='"')
if (*cmd!='(' && *cmd!='"') {
ptr = strchr (cmd, '@');
else ptr = NULL;
if (ptr == cmd+1 && *cmd=='?')
ptr = NULL;
} else ptr = NULL;
core->tmpseek = ptr? R_TRUE: R_FALSE;
if (ptr) {
ut64 tmpoff, tmpbsz, addr;

View File

@ -140,8 +140,61 @@ static int cmd_help(void *data, const char *input) {
r_core_cmd (core, input+1, 0);
} else r_cons_printf ("0x%"PFMT64x"\n", core->num->value);
break;
case '@':
r_cons_printf (
"Usage: ... @[(f|s|b)]:] [@iter] expr[!size] [~grep]\n"
"Pipes:\n"
" x > foo pipe output of 'x' command to 'foo' file\n"
" x >> foo concatenate output of 'x' in 'foo' file\n"
" x | less pipe output of 'x' command to less program\n"
"Command evaluation:\n"
" `pdi~push:0[0]` replace output of command inside the line\n"
" .!rabin2 -ri $FILE load imports by running rabin2\n"
" .:8080 expect commands at tcp port 8080\n"
"Special suffixes to temporary set the contents of block:\n"
" @f:/bin/ls from file contents\n"
" @s:hello from given string\n"
" @b:909192 from hex pairs string\n"
"Temporary seeks:\n"
" @ 0x1024 seek to 0x1024 offset\n"
" @ sym.main+3 seek to the evaluated math expressions\n"
" @ 32!128 blocksize = 128, offset = 32\n"
"Repeaters:\n"
" @@=1 2 3 repeat previous command at offsets 1, 2 and 3\n"
" @@ hit* repeat command for all flags matching 'hit*' glob\n"
// TODO: documentate @@ glob1 glob2 glob3
"Internal grep:\n"
" ~? count lines\n"
" ~mov grep lines matching 'mov'\n"
" ~!mov grep lines not matching 'mov'\n"
" ~mov[0] get first column of lines matching 'mov'\n"
" ~mov:3[0] get 1st column from the 4th line matching 'mov'\n"
);
return 0;
case '$':
return cmd_help (data, " $?");
r_cons_printf (
"$variables:\n"
" $$ = here (current virtual seek)\n"
" $o = here (current disk io offset)\n"
" $s = file size\n"
" $b = block size\n"
" $w = get word size, 4 if asm.bits=32, 8 if 64, ...\n"
" $S = section offset\n"
" $SS = section 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"
" ${eval} = get value of eval config variable # TODO: use ?k too\n"
" $? = last comparision value\n");
return R_TRUE;
case 'V':
r_cons_printf ("%s\n", R2_VERSION);
break;
@ -226,7 +279,7 @@ static int cmd_help(void *data, const char *input) {
if (s && s->name)
r_cons_printf ("%s\n", s->name);
} break;
case 'I': // hud input
case '_': // hud input
free (core->yank_buf);
for (input++; *input==' '; input++);
core->yank_buf = (ut8*)r_cons_hud_file (input);
@ -332,61 +385,38 @@ static int cmd_help(void *data, const char *input) {
}
r_cons_printf (
"Usage: ?[?[?]] expression\n"
" ? eip-0x804800 ; show hex and dec result for this math expr\n"
" ?v eip-0x804800 ; show hex value of math expr\n"
" ?vi rsp-rbp ; show decimal value of math expr\n"
" ?V ; show library version of r_core\n"
" ?= eip-0x804800 ; same as above without user feedback\n"
" ?? [cmd] ; ? == 0 run command when math matches\n"
" ?i[ynmkp] arg ; prompt for number or Yes,No,Msg,Key,Path and store in $$?\n"
#if DONE
//BUT NOT DOCUMENTED AT ALL
" ?iy prompt ; yesno input prompt\n"
" ?in prompt ; yesno input prompt\n"
" ?im message ; show message centered in screen\n"
" ?ik ; press any key input dialog\n"
#endif
" ?I hudfile ; load hud menu with given file\n"
" ?d opcode ; describe opcode for asm.arch\n"
" ?e string ; echo string\n"
" ?r [from] [to] ; generate random number between from-to\n"
" ?y [str] ; show contents of yank buffer, or set with string\n"
" ?k k[=v] ; key-value temporal storage for the user\n"
" ?b [num] ; show binary value of number\n"
" ?f [num] [str] ; map each bit of the number as flag string index\n"
" ?p vaddr ; get physical address for given virtual address\n"
" ?P paddr ; get virtual address for given physical one\n"
" ?s from to step ; sequence of numbers from to by steps\n"
" ?S addr ; return section name of given address\n"
" ?x num|0xnum|str; returns the hexpair of number or string\n"
" ?X num|expr ; returns the hexadecimal value numeric expr\n"
" ?l str ; returns the length of string (0 if null)\n"
" ?t cmd ; returns the time to run a command\n"
" ?! [cmd] ; ? != 0\n"
" ?+ [cmd] ; ? > 0\n"
" ?- [cmd] ; ? < 0\n"
" ??? ; show this help\n"
"$variables:\n"
" $$ = here (current virtual seek)\n"
" $o = here (current disk io offset)\n"
" $s = file size\n"
" $b = block size\n"
" $w = get word size, 4 if asm.bits=32, 8 if 64, ...\n"
" $S = section offset\n"
" $SS = section 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"
" ${eval} = get value of eval config variable # TODO: use ?k too\n"
" $? = last comparision value\n");
" ? eip-0x804800 show hex and dec result for this math expr\n"
" ?= eip-0x804800 same as above without user feedback\n"
" ?? show value of operation\n"
" ?? [cmd] ? == 0 run command when math matches\n"
" ?_ hudfile load hud menu with given file\n"
" ?b [num] show binary value of number\n"
" ?d opcode describe opcode for asm.arch\n"
" ?e string echo string\n"
" ?f [num] [str] map each bit of the number as flag string index\n"
" ?iy prompt yesno input prompt\n"
" ?i[ynmkp] arg prompt for number or Yes,No,Msg,Key,Path and store in $$?\n"
" ?in prompt yesno input prompt\n"
" ?im message show message centered in screen\n"
" ?ik press any key input dialog\n"
" ?k k[=v] key-value temporal storage for the user\n"
" ?l str returns the length of string (0 if null)\n"
" ?p vaddr get physical address for given virtual address\n"
" ?P paddr get virtual address for given physical one\n"
" ?r [from] [to] generate random number between from-to\n"
" ?s from to step sequence of numbers from to by steps\n"
" ?S addr return section name of given address\n"
" ?t cmd returns the time to run a command\n"
" ?v eip-0x804800 show hex value of math expr\n"
" ?vi rsp-rbp show decimal value of math expr\n"
" ?V show library version of r_core\n"
" ?x num|0xnum|str returns the hexpair of number or string\n"
" ?X num|expr returns the hexadecimal value numeric expr\n"
" ?y [str] show contents of yank buffer, or set with string\n"
" ?! [cmd] ? != 0\n"
" ?+ [cmd] ? > 0\n"
" ?- [cmd] ? < 0\n"
" ??? show this help\n");
return 0;
} else
if (input[1]) {
@ -397,43 +427,40 @@ static int cmd_help(void *data, const char *input) {
case '\0':
default:
r_cons_printf (
" a ; perform analysis of code\n"
" b [bsz] ; get or change block size\n"
" c[dqxXfg] [arg] ; compare block with given data\n"
" C[Cf..] ; Code metadata management\n"
" d[hrscb] ; debugger commands\n"
" e [a[=b]] ; list/get/set config evaluable vars\n"
" f [name][sz][at] ; set flag at current address\n"
" g[wcilper] [arg] ; go compile shellcodes with r_egg\n"
" i [file] ; get info about opened file\n"
" m[lyogfdps] ; mountpoints commands\n"
" o [file] (addr) ; open file at optional address\n"
" p[?] [len] ; print current block with format and length\n"
" P[osi?] ; project management utilities\n"
" r[+- ][len] ; resize file\n"
" s [addr] ; seek to address\n"
" S?[size] [vaddr] ; IO section manipulation information\n"
" V[vcmds] ; enter visual mode (vcmds=visualvisual keystrokes)\n"
" w[mode] [arg] ; multiple write operations\n"
" x [len] ; alias for 'px' (print hexadecimal)\n"
" y [len] [off] ; yank/paste bytes from/to memory\n"
" ?[??] [expr] ; help or evaluate math expression\n"
" /[xmp/] ; search for bytes, regexps, patterns, ..\n"
" ![cmd] ; run given command as in system(3)\n"
" = [cmd] ; run this command via rap://\n"
" (macro arg0 arg1) ; define scripting macros\n"
" #[algo] [len] ; calculate hash checksum of current block\n"
" .[ file|!cmd|cmd|(macro)] ; interpret as radare cmds\n"
" : ; list all command plugins\n"
" q [ret] ; quit program with a return value\n"
"Usage: [.][repeat][command][~grep][@[@iter]address!size][|>pipe]\n"
"Append '?' to any char command to get detailed help\n"
"Prefix with number to repeat command N times (f.ex: 3x)\n"
"Suffix '@f:/bin/ls' to set temporary block from file\n"
"Suffix '@s:hello' to set temporary block from given string\n"
"Suffix '@b:909192' to set temporary block from hex pairs\n"
"Suffix '@ addr[!bsize]' for a temporary seek and/or bsize\n"
"Suffix '@@ glob1 glob2i ..' space separated glob greps for flags to seek\n"
"Suffix '~string:linenumber[column]' to filter output\n"
" /[xmp/] search for bytes, regexps, patterns, ..\n"
" ![cmd] run given command as in system(3)\n"
" = [cmd] run this command via rap://\n"
" (macro arg0 arg1) define scripting macros\n"
" #[algo] [len] calculate hash checksum of current block\n"
" .[ file|!sh|cmd] interpret as radare commands\n"
" q [ret] quit program with a return value\n"
" : list and interact with the command plugins\n"
" a perform analysis of code\n"
" b [bsz] get or change block size\n"
" c[dqxXfg] [arg] compare block with given data\n"
" C[Cf..] code metadata management\n"
" d[hrscb] debugger commands\n"
" e [a[=b]] list/get/set config evaluable vars\n"
" f [name][sz][at] set flag at current address\n"
" g[wcilper] [arg] go compile shellcodes with r_egg\n"
" i [file] get info about opened file\n"
" m[lyogfdps] mountpoints commands\n"
" o [file] (addr) open file at optional address\n"
" p[?] [len] print current block with format and length\n"
" P[osi?] project management utilities\n"
" r[+- ][len] resize file\n"
" s [addr] seek to address\n"
" S?[size] [vaddr] io section manipulation information\n"
" V[vcmds] enter visual mode (vcmds=visualvisual keystrokes)\n"
" w[mode] [arg] multiple write operations\n"
" x [len] alias for 'px' (print hexadecimal)\n"
" y [len] [off] yank/paste bytes from/to memory\n"
" ?[??] [expr] help or evaluate math expression\n"
" ?$? show available '$' variables\n"
" ?@? show help for '@' and '~' suffix\n"
);
break;
}

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2012 // pancake<nopcode.org> */
/* radare - LGPL - Copyright 2009-2012 - pancake */
static int cmd_macro(void *data, const char *input) {
char *buf = NULL;

View File

@ -156,17 +156,20 @@ R_API int r_core_rtr_http(RCore *core, int launch) {
R_API void r_core_rtr_help(RCore *core) {
r_cons_printf (
" = ; list all open connections\n"
//" =:port [cmd] ; same as .: but allow to send command if cmd\n"
" =<[fd] cmd ; send output of local command to remote fd\n"
" =[fd] cmd ; exec cmd at remote 'fd' (last open is default one)\n"
" =! cmd ; run command via r_io_system\n"
" =+ [proto://]host ; add host (default=rap://, tcp://, udp://)\n"
" =-[fd] ; remove all hosts or host 'fd'\n"
" ==[fd] ; open remote session with host 'fd', 'q' to quit\n"
"remote commands:\n"
" =:host:port cmd run 'cmd' command on remote server.\n"
"rap commands:\n"
" = list all open connections\n"
//" =:port [cmd] ; same as .: but allow to send command if cmd\n"
" =<[fd] cmd send output of local command to remote fd\n"
" =[fd] cmd exec cmd at remote 'fd' (last open is default one)\n"
" =! cmd run command via r_io_system\n"
" =+ [proto://]host add host (default=rap://, tcp://, udp://)\n"
" =-[fd] remove all hosts or host 'fd'\n"
" ==[fd] open remote session with host 'fd', 'q' to quit\n"
"http server:\n"
" =h ; listen for http connections\n"
" =H ; launch browser and listen for http\n");
" =h listen for http connections (r2 -qc=H /bin/ls)\n"
" =H launch browser and listen for http\n");
}
R_API void r_core_rtr_pushout(RCore *core, const char *input) {
@ -240,7 +243,7 @@ R_API void r_core_rtr_add(RCore *core, const char *_input) {
proto = RTR_PROT_RAP;
host = input;
}
while (*host&&iswhitechar(*host))
while (*host && iswhitechar (*host))
host++;
if (!(ptr = strchr (host, ':'))) {
@ -460,13 +463,20 @@ R_API char *r_core_rtr_cmds_query (RCore *core, const char *host, const char *po
}
R_API int r_core_rtr_cmds (RCore *core, const char *port) {
char *str;
int i, ret;
unsigned char buf[4096];
RSocket *ch, *s;
int i, ret;
char *str;
RSocket *ch, *s = r_socket_new (0);
if (!port || port[0]=='?') {
r_cons_printf ("Usage: .:[tcp-port] run r2 commands for clients\n");
return R_FALSE;
}
s = r_socket_new (0);
if (!r_socket_listen (s, port, NULL)) {
eprintf ("Error listening on port %s\n", port);
r_socket_free (s);
return R_FALSE;
}

View File

@ -39,7 +39,6 @@ R_API void r_core_visual_asm(RCore *core) {
r_io_read_at (core->io, core->offset, cva.buf, sizeof (cva.buf));
cva.blocklen = r_hex_bin2str (cva.buf, sizeof (cva.buf), cva.blockbuf);
readline_callback (&cva, "");
r_line_readline_cb (readline_callback, &cva);
if (cva.acode && cva.acode->len>0)