Rename l to T, add cfg.user and 'TT' chat prompt

* Add cfg.user variable
* Implement TT chat prompt
* Invoked from 'VT'
* Rename 'l' to 'T' command (log -> textlog)
* Add r_sys_whoami () -> set default username
* Add $$ trap instruction in ESIL
* Implement POP and STACK esil commands
This commit is contained in:
pancake 2014-08-28 03:11:13 +02:00
parent eab0f0020a
commit c6bc6f099d
9 changed files with 125 additions and 28 deletions

View File

@ -518,6 +518,22 @@ static int esil_syscall_linux_i386(RAnalEsil *esil) {
return 0;
}
static int esil_trap(RAnalEsil *esil) {
ut64 s, d;
char *dst = r_anal_esil_pop (esil);
char *src = r_anal_esil_pop (esil);
if (src && dst) {
if (r_anal_esil_get_parm (esil, src, &s)) {
if (r_anal_esil_get_parm (esil, dst, &d)) {
esil->trap = s;
esil->trap_code = d;
return 1;
} else eprintf ("FUCK\n");
} else eprintf ("JKWJKL\n");
}
return 0;
}
static int esil_syscall(RAnalEsil *esil) {
// pop number
// resolve arguments and run syscall handler
@ -760,11 +776,16 @@ R_API int r_anal_esil_dumpstack (RAnalEsil *esil) {
if (esil->stackptr<1)
return 0;
//eprintf ("StackDump:\n");
for (i=esil->stackptr-1;i>=0; i--) {
for (i=esil->stackptr-1; i>=0; i--) {
esil->anal->printf ("%s\n", esil->stack[i]);
}
return 1;
}
static int esil_pop(RAnalEsil *esil) {
char *dst = r_anal_esil_pop (esil);
free (dst);
return 1;
}
static int esil_div(RAnalEsil *esil) {
int ret = 0;
@ -1309,6 +1330,7 @@ R_API int r_anal_esil_setup (RAnalEsil *esil, RAnal *anal) {
esil->mem_read = internal_esil_mem_read;
esil->mem_write = internal_esil_mem_write;
r_anal_esil_set_op (esil, "$", esil_syscall);
r_anal_esil_set_op (esil, "$$", esil_trap);
r_anal_esil_set_op (esil, "==", esil_cmp);
r_anal_esil_set_op (esil, "<", esil_smaller);
r_anal_esil_set_op (esil, ">", esil_bigger);
@ -1347,6 +1369,8 @@ R_API int r_anal_esil_setup (RAnalEsil *esil, RAnal *anal) {
r_anal_esil_set_op (esil, "[2]", esil_peek2);
r_anal_esil_set_op (esil, "[4]", esil_peek4);
r_anal_esil_set_op (esil, "[8]", esil_peek8);
r_anal_esil_set_op (esil, "STACK", r_anal_esil_dumpstack);
r_anal_esil_set_op (esil, "POP", esil_pop);
if (anal->cur && anal->cur->esil_init && anal->cur->esil_fini)
return anal->cur->esil_init (esil);
return R_TRUE;

View File

@ -1647,7 +1647,7 @@ R_API void r_core_cmd_init(RCore *core) {
r_cmd_add (core->rcmd, "info", "get file info", &cmd_info);
r_cmd_add (core->rcmd, "cmp", "compare memory", &cmd_cmp);
r_cmd_add (core->rcmd, "seek", "seek to an offset", &cmd_seek);
r_cmd_add (core->rcmd, "log", "log utility", &cmd_log);
r_cmd_add (core->rcmd, "Text", "Text log utility", &cmd_log);
r_cmd_add (core->rcmd, "t", "type information (cparse)", &cmd_type);
r_cmd_add (core->rcmd, "zign", "zignatures", &cmd_zign);
r_cmd_add (core->rcmd, "Section", "setup section io information", &cmd_section);

View File

@ -150,9 +150,13 @@ static int cmd_info(void *data, const char *input) {
eprintf ("Usage: ik [sdb-query]\n");
}
break;
case 'o': r_core_bin_load (core, input[1]==' '?
input+2: cf->filename,
r_config_get_i (core->config, "bin.baddr"));
case 'o':
{
const char *fn = input[1]==' '? input+2: cf->filename;
ut64 laddr = UT64_MAX;
laddr = r_config_get_i (core->config, "bin.baddr");
r_core_bin_load (core, fn, laddr);
}
break;
#define RBININFO(n,x) \
if (is_array) { \

View File

@ -1,5 +1,51 @@
/* radare - LGPL - Copyright 2009-2014 - pancake */
static int textlog_chat (RCore *core) {
char prompt[64];
char buf[1024];
int lastmsg = 0;
const char *me = r_config_get (core->config, "cfg.user");
char msg[1024];
eprintf ("Type '/help' for commands:\n");
snprintf (prompt, sizeof (prompt)-1, "[%s]> ", me);
r_line_set_prompt (prompt);
for (;;) {
r_core_log_list (core, lastmsg, 0, 0);
lastmsg = core->log->last;
if (r_cons_fgets (buf, sizeof (buf)-1, 0, NULL)<0)
return 1;
if (!*buf) continue;
if (!strcmp (buf, "/help")) {
eprintf ("/quit quit the chat (same as ^D)\n");
eprintf ("/name <nick> set cfg.user name\n");
eprintf ("/log show full log\n");
eprintf ("/clear clear text log messages\n");
} else if (!strncmp (buf, "/name ", 6)) {
snprintf (msg, sizeof (msg)-1, "* '%s' is now known as '%s'", me, buf+6);
r_core_log_add (core, msg);
r_config_set (core->config, "cfg.user", buf+6);
me = r_config_get (core->config, "cfg.user");
snprintf (prompt, sizeof (prompt)-1, "[%s]> ", me);
r_line_set_prompt (prompt);
return 0;
} else if (!strcmp (buf, "/log")) {
r_core_log_list (core, 0, 0, 0);
return 0;
} else if (!strcmp (buf, "/clear")) {
//r_core_log_del (core, 0);
r_core_cmd0 (core, "T-");
return 0;
} else if (!strcmp (buf, "/quit")) {
return 0;
} else {
snprintf (msg, sizeof (msg)-1, "[%s] %s", me, buf);
r_core_log_add (core, msg);
}
}
return 1;
}
static int cmd_log(void *data, const char *input) {
RCore *core = (RCore *)data;
const char *input2 = input + 1;
@ -28,23 +74,27 @@ static int cmd_log(void *data, const char *input) {
break;
case '?':{
const char* help_msg[] = {
"Usage:", "l","[-][ num|msg]",
"l", "", "List all log messages",
"l", " new comment", "0x80480",
"l", " 123", "List log from 123",
"l", " 10 3", "List 3 log messages starting from 10",
"l*", "", "List in radare commands",
"l-", "", "Delete all logs",
"l-", " 123", "Delete logs before 123",
"ll", "", "Get last log message id",
"lj", "", "List in json format",
"lm", " [idx]", "Display log messages without index",
"ls", "", "List files in current directory (see pwd, cd)",
"lp", "[-plug]", "list, load, unload plugins",
"Usage:", "T","[-][ num|msg]",
"T", "", "List all Text log messages",
"T", " new comment", "0x80480",
"T", " 123", "List log from 123",
"T", " 10 3", "List 3 log messages starting from 10",
"T*", "", "List in radare commands",
"T-", "", "Delete all logs",
"T-", " 123", "Delete logs before 123",
"Tl", "", "Get last log message id",
"Tj", "", "List in json format",
"Tm", " [idx]", "Display log messages without index",
"Ts", "", "List files in current directory (see pwd, cd)",
"Tp", "[-plug]", "Tist, load, unload plugins",
"TT", "", "Enter into the text log chat console",
NULL};
r_core_cmd_help(core, help_msg);
r_core_cmd_help (core, help_msg);
}
break;
case 'T':
textlog_chat (core);
break;
case 'p':
switch (input[1]) {
case 0:
@ -58,10 +108,10 @@ static int cmd_log(void *data, const char *input) {
break;
case '?': {
const char* help_msg[] = {
"Usage:", "lp", "[-name][ file]",
"lp", "", "List all plugins loaded by RCore.lib",
"lp-", "duk", "Unload plugin matching in filename",
"lp", " blah."R_LIB_EXT, "Load plugin file",
"Usage:", "Tp", "[-name][ file]",
"Tp", "", "List all plugins loaded by RCore.lib",
"Tp-", "duk", "Unload plugin matching in filename",
"Tp", " blah."R_LIB_EXT, "Load plugin file",
NULL};
r_core_cmd_help(core, help_msg);
}

View File

@ -784,6 +784,10 @@ R_API int r_core_config_init(RCore *core) {
r_config_set (cfg, "cfg.editor", p? p: "vi");
#endif
free (p);
{
char username[128];
SETPREF("cfg.user", r_sys_whoami (username), "Set current username/pid");
}
r_config_desc (cfg, "cfg.editor", "Select default editor program");
SETPREF("cfg.fortunes", "true", "If enabled show tips at start");
SETI("cfg.hashlimit", SLURP_LIMIT, "If the file its bigger than hashlimit don't calculate the hash");

View File

@ -441,7 +441,8 @@ R_API int r_core_bin_load(RCore *r, const char *filenameuri, ut64 baddr) {
r_io_use_desc (r->io, desc);
}
if (cf && binfile && desc) binfile->fd = desc->fd;
if (cf && binfile && desc)
binfile->fd = desc->fd;
binfile = r_bin_cur (r->bin);
r_core_bin_set_env (r, binfile);
plugin = r_bin_file_cur_plugin (binfile);
@ -461,7 +462,8 @@ R_API int r_core_bin_load(RCore *r, const char *filenameuri, ut64 baddr) {
}
if (plugin && plugin->name && !strcmp (plugin->name, "dex")) {
r_core_cmd0 (r, "\"(fix-dex,wx `#sha1 $s-32 @32` @12 ; wx `#adler32 $s-12 @12` @8)\"\n");
r_core_cmd0 (r, "\"(fix-dex,wx `#sha1 $s-32 @32` @12 ;"
" wx `#adler32 $s-12 @12` @8)\"\n");
}
if (r_config_get_i (r->config, "file.analyze"))
@ -646,7 +648,6 @@ R_API RCoreFile *r_core_file_open(RCore *r, const char *file, int mode, ut64 loa
return fh;
}
R_API int r_core_files_free (const RCore *core, RCoreFile *cf) {
if (!core || !core->files || !cf) return R_FALSE;
return r_list_delete_data (core->files, cf);

View File

@ -99,10 +99,11 @@ static void visual_help() {
" o go/seek to given offset\n"
" p/P rotate print modes (hex, disasm, debug, words, buf)\n"
" q back to radare shell\n"
" r browse anal info and comments\n"
" R randomize color palette (ecr)\n"
" sS step / step over\n"
" t track flags (browse symbols, functions..)\n"
" T browse anal info and comments\n"
" T enter textlog chat console (TT)\n"
" v visual code analysis menu\n"
" V/W (V)iew graph using cmd.graph (agv?), open (W)ebUI\n"
" uU undo/redo seek\n"
@ -604,6 +605,9 @@ R_API int r_core_visual_cmd(RCore *core, int ch) {
} }
showcursor (core, R_FALSE);
break;
case 'T':
r_core_cmd0 (core, "TT");
break;
case 'F':
r_flag_unset_i (core->flags, core->offset + cursor, NULL);
break;
@ -724,7 +728,7 @@ R_API int r_core_visual_cmd(RCore *core, int ch) {
case 'X':
r_core_visual_xrefs_X (core);
break;
case 'T':
case 'r':
r_core_visual_comments (core);
break;
case 'W':

View File

@ -497,6 +497,7 @@ R_API int r_sys_sleep(int secs);
R_API int r_sys_usleep(int usecs);
R_API char *r_sys_getenv(const char *key);
R_API int r_sys_setenv(const char *key, const char *value);
R_API char *r_sys_whoami (char *buf);
R_API char *r_sys_getdir();
R_API int r_sys_chdir(const char *s);
R_API int r_sys_cmd_str_full(const char *cmd, const char *input, char **output, int *len, char **sterr);

View File

@ -619,3 +619,12 @@ eprintf ("SET %p\n", env);
R_API void r_sys_set_environ (char **e) {
env = e;
}
R_API char *r_sys_whoami (char *buf) {
char _buf[32];
int pid = getpid ();
int hasbuf = buf != 0;
if (!hasbuf) buf = _buf;
sprintf (buf, "pid%d", pid);
return hasbuf? strdup (buf): buf;
}