* More split of core/cmd.c

* Fix 'dbc' argument parsing
* Fix V_q error message
* Remove unused code
This commit is contained in:
pancake 2012-02-27 03:07:32 +01:00
parent d37de2367d
commit 1b2c8064ff
8 changed files with 246 additions and 266 deletions

View File

@ -207,7 +207,7 @@ R_API int r_bp_list(RBreakpoint *bp, int rad) {
int n = 0;
RBreakpointItem *b;
RListIter *iter;
eprintf ("Breakpoint list:\n");
//eprintf ("Breakpoint list:\n");
r_list_foreach (bp->bps, iter, b) {
bp->printf ("0x%08"PFMT64x" - 0x%08"PFMT64x" %d %c%c%c %s %s %s cmd=\"%s\"\n",
b->addr, b->addr+b->size, b->size,

View File

@ -20,4 +20,4 @@ include ../rules.mk
cmd.o: cmd_hash.c cmd_debug.c cmd_zign.c cmd_section.c cmd_project.c \
cmd_open.c cmd_meta.c cmd_macro.c cmd_magic.c cmd_mount.c \
cmd_seek.c cmd_print.c cmd_help.c cmd_anal.c cmd_search.c \
cmd_cmp.c cmd_write.c
cmd_cmp.c cmd_write.c cmd_egg.c cmd_info.c

View File

@ -18,6 +18,8 @@ static void cmd_debug_reg(RCore *core, const char *str);
#include "cmd_anal.c"
#include "cmd_open.c"
#include "cmd_meta.c"
#include "cmd_egg.c"
#include "cmd_info.c"
#include "cmd_macro.c"
#include "cmd_magic.c"
#include "cmd_mount.c"
@ -79,24 +81,6 @@ static int cmd_rap(void *data, const char *input) {
default:
r_core_rtr_cmd (core, input);
}
#if 0
switch (input[0]) {
case '\0':
r_lib_list (core->lib);
r_io_plugin_list (core->io);
break;
case '?':
eprintf ("usage: =[fd] [cmd]\n"
"TODO: import the rest of functionality from r1\n");
break;
default:
r_io_set_fd (core->io, core->file->fd);
if (input[0]==' ')
input++;
r_io_system (core->io, input);
break;
}
#endif
return R_TRUE;
}
@ -254,235 +238,6 @@ static int cmd_bsize(void *data, const char *input) {
return 0;
}
static int cmd_info(void *data, const char *input) {
RCore *core = (RCore *)data;
ut64 offset = r_bin_get_offset (core->bin);
int va = core->io->va || core->io->debug;
int mode = (input[1]=='*')?R_CORE_BIN_RADARE:R_CORE_BIN_PRINT;
switch (*input) {
case 'S':
r_core_bin_info (core, R_CORE_BIN_ACC_SECTIONS|R_CORE_BIN_ACC_FIELDS, mode, va, NULL, offset);
break;
case 's':
r_core_bin_info (core, R_CORE_BIN_ACC_SYMBOLS, mode, va, NULL, offset);
break;
case 'i':
r_core_bin_info (core, R_CORE_BIN_ACC_IMPORTS, mode, va, NULL, offset);
break;
case 'I':
r_core_bin_info (core, R_CORE_BIN_ACC_INFO, mode, va, NULL, offset);
break;
case 'e':
r_core_bin_info (core, R_CORE_BIN_ACC_ENTRIES, mode, va, NULL, offset);
break;
case 'z':
r_core_bin_info (core, R_CORE_BIN_ACC_STRINGS, mode, va, NULL, offset);
break;
case 'a':
if (input[1]=='*') {
cmd_info (core, "I*");
cmd_info (core, "e*");
cmd_info (core, "i*");
cmd_info (core, "s*");
cmd_info (core, "S*");
cmd_info (core, "z*");
} else {
cmd_info (core, "I");
cmd_info (core, "e");
cmd_info (core, "i");
cmd_info (core, "s");
cmd_info (core, "S");
cmd_info (core, "z");
}
break;
case '?':
r_cons_printf (
"Usage: i[aeiIsSz]* ; get info from opened file\n"
"NOTE: Append a '*' to get the output in radare commands\n"
" ia ; show all info (imports, exports, sections..)\n"
" ii ; imports\n"
" iI ; binary info\n"
" ie ; entrypoint\n"
" is ; symbols\n"
" iS ; sections\n"
" iz ; strings\n");
break;
case '*':
break;
default:
if (core->file) {
const char *fn = NULL;
int dbg = r_config_get_i (core->config, "cfg.debug");
RBinInfo *info = r_bin_get_info (core->bin);
if (info) {
fn = info->file;
r_cons_printf ("type\t%s\n", info->type);
r_cons_printf ("os\t%s\n", info->os);
r_cons_printf ("arch\t%s\n", info->machine);
r_cons_printf ("bits\t%d\n", info->bits);
r_cons_printf ("endian\t%s\n", info->big_endian? "big": "little");
} else {
fn = core->file->filename;
}
r_cons_printf ("file\t%s\n", fn);
if (dbg) dbg = R_IO_WRITE | R_IO_EXEC;
r_cons_printf ("fd\t%d\n", core->file->fd->fd);
r_cons_printf ("size\t0x%x\n", core->file->size);
r_cons_printf ("mode\t%s\n", r_str_rwx_i (core->file->rwx | dbg));
r_cons_printf ("block\t0x%x\n", core->blocksize);
r_cons_printf ("uri\t%s\n", core->file->uri);
if (core->bin->curxtr)
r_cons_printf ("packet\t%s\n", core->bin->curxtr->name);
if (core->bin->curxtr)
r_cons_printf ("format\t%s\n", core->bin->curarch.curplugin->name);
} else eprintf ("No selected file\n");
}
return 0;
}
static int cmd_hexdump(void *data, const char *input) {
return cmd_print (data, input-1);
}
static void cmd_egg_option (REgg *egg, const char *key, const char *input) {
if (input[1]!=' ') {
char *a = r_egg_option_get (egg, key);
if (a) {
r_cons_printf ("%s\n", a);
free (a);
}
} else r_egg_option_set (egg, key, input+2);
}
static int cmd_egg_compile(REgg *egg) {
int i;
RBuffer *b;
int ret = R_FALSE;
char *p = r_egg_option_get (egg, "egg.shellcode");
if (p && *p) {
if (!r_egg_shellcode (egg, p)) {
free (p);
return R_FALSE;
}
free (p);
}
r_egg_compile (egg);
if (!r_egg_assemble (egg)) {
eprintf ("r_egg_assemble: invalid assembly\n");
return R_FALSE;
}
p = r_egg_option_get (egg, "egg.padding");
if (p && *p) {
r_egg_padding (egg, p);
free (p);
}
p = r_egg_option_get (egg, "egg.encoder");
if (p && *p) {
r_egg_encode (egg, p);
free (p);
}
if ((b = r_egg_get_bin (egg))) {
if (b->length>0) {
for (i=0; i<b->length; i++)
r_cons_printf ("%02x", b->buf[i]);
r_cons_printf ("\n");
}
ret = R_TRUE;
}
// we do not own this buffer!!
// r_buf_free (b);
r_egg_reset (egg);
return ret;
}
static int cmd_egg(void *data, const char *input) {
RCore *core = (RCore *)data;
REgg *egg = core->egg;
char *oa, *p;
r_egg_setup (egg,
r_config_get (core->config, "asm.arch"),
core->assembler->bits, 0,
r_config_get (core->config, "asm.os")); // XXX
switch (*input) {
case ' ':
r_egg_load (egg, input+2, 0);
if (!cmd_egg_compile (egg))
eprintf ("Cannot compile '%s'\n", input+2);
break;
case '\0':
if (!cmd_egg_compile (egg))
eprintf ("Cannot compile\n");
break;
case 'p':
cmd_egg_option (egg, "egg.padding", input);
break;
case 'e':
cmd_egg_option (egg, "egg.encoder", input);
break;
case 'i':
cmd_egg_option (egg, "egg.shellcode", input);
break;
case 'l':
{
RListIter *iter;
REggPlugin *p;
r_list_foreach (egg->plugins, iter, p) {
printf ("%s %6s : %s\n",
(p->type==R_EGG_PLUGIN_SHELLCODE)?
"shc":"enc", p->name, p->desc);
}
}
break;
case 'r':
cmd_egg_option (egg, "egg.padding", "");
cmd_egg_option (egg, "egg.shellcode", "");
cmd_egg_option (egg, "egg.encoder", "");
break;
case 'c':
// list, get, set egg options
switch (input[1]) {
case ' ':
oa = strdup (input+2);
p = strchr (oa, '=');
if (p) {
*p = 0;
r_egg_option_set (egg, oa, p+1);
} else {
char *o = r_egg_option_get (egg, oa);
if (o) {
r_cons_printf ("%s\n", o);
free (o);
}
}
break;
case '\0':
// list
r_pair_list (egg->pair,NULL);
eprintf ("list options\n");
break;
default:
eprintf ("Usage: gc [k=v]\n");
break;
}
break;
case '?':
eprintf ("Usage: g[wcilper] [arg]\n"
" g foo.r : compile r_egg source file\n"
" gw : compile and write\n"
" gc cmd=/bin/ls : set config option for shellcodes and encoders\n"
" gc : list all config options\n"
" gl : list plugins (shellcodes, encoders)\n"
" gi exec : compile shellcode. like ragg2 -i\n"
" gp padding : define padding for command\n"
" ge xor : specify an encoder\n"
" gr : reset r_egg\n"
"EVAL VARS: asm.arch, asm.bits, asm.os\n"
);
break;
}
return R_TRUE;
}
static int cmd_resize(void *data, const char *input) {
RCore *core = (RCore *)data;
ut64 oldsize, newsize;
@ -660,11 +415,11 @@ static int r_core_cmd_subst(RCore *core, char *cmd) {
while (rep--) {
int ret = r_core_cmd_subst_i (core, cmd);
if (ret) {
free (icmd);
free (icmd);
return ret;
}
}
free (icmd);
free (icmd);
return 0;
}
@ -1002,17 +757,6 @@ R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each) {
r_core_cmd (core, cmd, 0);
}
}
#if 0
/* ugly copypasta from tmpseek .. */
if (strstr(word, each)) {
if (word[i]=='+'||word[i]=='-')
core->offset = core->offset + r_num_math (get_math(core->num, word);
else core->offset = r_num_math (get_math(core->num, word);
radare_read(0);
cons_printf("; @@ 0x%08"PFMT64x"\n", core->offset);
radare_cmd(cmd,0);
}
#endif
r_cons_break (NULL, NULL);
core->cmd->macro.counter++ ;

View File

@ -514,6 +514,8 @@ static void r_core_cmd_bp(RCore *core, const char *input) {
RBreakpointItem *bpi = r_bp_get (core->dbg->bp, off);
if (bpi) {
char *arg = strchr (input+2, ' ');
if (arg)
arg = strchr (arg+1, ' ');
if (arg) {
free (bpi->data);
bpi->data = strdup (arg+1);

140
libr/core/cmd_egg.c Normal file
View File

@ -0,0 +1,140 @@
/* radare - LGPL - Copyright 2009-2012 // pancake<nopcode.org> */
static void cmd_egg_option (REgg *egg, const char *key, const char *input) {
if (input[1]!=' ') {
char *a = r_egg_option_get (egg, key);
if (a) {
r_cons_printf ("%s\n", a);
free (a);
}
} else r_egg_option_set (egg, key, input+2);
}
static int cmd_egg_compile(REgg *egg) {
int i;
RBuffer *b;
int ret = R_FALSE;
char *p = r_egg_option_get (egg, "egg.shellcode");
if (p && *p) {
if (!r_egg_shellcode (egg, p)) {
free (p);
return R_FALSE;
}
free (p);
}
r_egg_compile (egg);
if (!r_egg_assemble (egg)) {
eprintf ("r_egg_assemble: invalid assembly\n");
return R_FALSE;
}
p = r_egg_option_get (egg, "egg.padding");
if (p && *p) {
r_egg_padding (egg, p);
free (p);
}
p = r_egg_option_get (egg, "egg.encoder");
if (p && *p) {
r_egg_encode (egg, p);
free (p);
}
if ((b = r_egg_get_bin (egg))) {
if (b->length>0) {
for (i=0; i<b->length; i++)
r_cons_printf ("%02x", b->buf[i]);
r_cons_printf ("\n");
}
ret = R_TRUE;
}
// we do not own this buffer!!
// r_buf_free (b);
r_egg_reset (egg);
return ret;
}
static int cmd_egg(void *data, const char *input) {
RCore *core = (RCore *)data;
REgg *egg = core->egg;
char *oa, *p;
r_egg_setup (egg,
r_config_get (core->config, "asm.arch"),
core->assembler->bits, 0,
r_config_get (core->config, "asm.os")); // XXX
switch (*input) {
case ' ':
r_egg_load (egg, input+2, 0);
if (!cmd_egg_compile (egg))
eprintf ("Cannot compile '%s'\n", input+2);
break;
case '\0':
if (!cmd_egg_compile (egg))
eprintf ("Cannot compile\n");
break;
case 'p':
cmd_egg_option (egg, "egg.padding", input);
break;
case 'e':
cmd_egg_option (egg, "egg.encoder", input);
break;
case 'i':
cmd_egg_option (egg, "egg.shellcode", input);
break;
case 'l':
{
RListIter *iter;
REggPlugin *p;
r_list_foreach (egg->plugins, iter, p) {
printf ("%s %6s : %s\n",
(p->type==R_EGG_PLUGIN_SHELLCODE)?
"shc":"enc", p->name, p->desc);
}
}
break;
case 'r':
cmd_egg_option (egg, "egg.padding", "");
cmd_egg_option (egg, "egg.shellcode", "");
cmd_egg_option (egg, "egg.encoder", "");
break;
case 'c':
// list, get, set egg options
switch (input[1]) {
case ' ':
oa = strdup (input+2);
p = strchr (oa, '=');
if (p) {
*p = 0;
r_egg_option_set (egg, oa, p+1);
} else {
char *o = r_egg_option_get (egg, oa);
if (o) {
r_cons_printf ("%s\n", o);
free (o);
}
}
break;
case '\0':
// list
r_pair_list (egg->pair,NULL);
eprintf ("list options\n");
break;
default:
eprintf ("Usage: gc [k=v]\n");
break;
}
break;
case '?':
eprintf ("Usage: g[wcilper] [arg]\n"
" g foo.r : compile r_egg source file\n"
" gw : compile and write\n"
" gc cmd=/bin/ls : set config option for shellcodes and encoders\n"
" gc : list all config options\n"
" gl : list plugins (shellcodes, encoders)\n"
" gi exec : compile shellcode. like ragg2 -i\n"
" gp padding : define padding for command\n"
" ge xor : specify an encoder\n"
" gr : reset r_egg\n"
"EVAL VARS: asm.arch, asm.bits, asm.os\n"
);
break;
}
return R_TRUE;
}

88
libr/core/cmd_info.c Normal file
View File

@ -0,0 +1,88 @@
/* radare - LGPL - Copyright 2009-2012 // pancake<nopcode.org> */
static int cmd_info(void *data, const char *input) {
RCore *core = (RCore *)data;
ut64 offset = r_bin_get_offset (core->bin);
int va = core->io->va || core->io->debug;
int mode = (input[1]=='*')?R_CORE_BIN_RADARE:R_CORE_BIN_PRINT;
switch (*input) {
case 'S':
r_core_bin_info (core, R_CORE_BIN_ACC_SECTIONS|R_CORE_BIN_ACC_FIELDS, mode, va, NULL, offset);
break;
case 's':
r_core_bin_info (core, R_CORE_BIN_ACC_SYMBOLS, mode, va, NULL, offset);
break;
case 'i':
r_core_bin_info (core, R_CORE_BIN_ACC_IMPORTS, mode, va, NULL, offset);
break;
case 'I':
r_core_bin_info (core, R_CORE_BIN_ACC_INFO, mode, va, NULL, offset);
break;
case 'e':
r_core_bin_info (core, R_CORE_BIN_ACC_ENTRIES, mode, va, NULL, offset);
break;
case 'z':
r_core_bin_info (core, R_CORE_BIN_ACC_STRINGS, mode, va, NULL, offset);
break;
case 'a':
if (input[1]=='*') {
cmd_info (core, "I*");
cmd_info (core, "e*");
cmd_info (core, "i*");
cmd_info (core, "s*");
cmd_info (core, "S*");
cmd_info (core, "z*");
} else {
cmd_info (core, "I");
cmd_info (core, "e");
cmd_info (core, "i");
cmd_info (core, "s");
cmd_info (core, "S");
cmd_info (core, "z");
}
break;
case '?':
r_cons_printf (
"Usage: i[aeiIsSz]* ; get info from opened file\n"
"NOTE: Append a '*' to get the output in radare commands\n"
" ia ; show all info (imports, exports, sections..)\n"
" ii ; imports\n"
" iI ; binary info\n"
" ie ; entrypoint\n"
" is ; symbols\n"
" iS ; sections\n"
" iz ; strings\n");
break;
case '*':
break;
default:
if (core->file) {
const char *fn = NULL;
int dbg = r_config_get_i (core->config, "cfg.debug");
RBinInfo *info = r_bin_get_info (core->bin);
if (info) {
fn = info->file;
r_cons_printf ("type\t%s\n", info->type);
r_cons_printf ("os\t%s\n", info->os);
r_cons_printf ("arch\t%s\n", info->machine);
r_cons_printf ("bits\t%d\n", info->bits);
r_cons_printf ("endian\t%s\n", info->big_endian? "big": "little");
} else {
fn = core->file->filename;
}
r_cons_printf ("file\t%s\n", fn);
if (dbg) dbg = R_IO_WRITE | R_IO_EXEC;
r_cons_printf ("fd\t%d\n", core->file->fd->fd);
r_cons_printf ("size\t0x%x\n", core->file->size);
r_cons_printf ("mode\t%s\n", r_str_rwx_i (core->file->rwx | dbg));
r_cons_printf ("block\t0x%x\n", core->blocksize);
r_cons_printf ("uri\t%s\n", core->file->uri);
if (core->bin->curxtr)
r_cons_printf ("packet\t%s\n", core->bin->curxtr->name);
if (core->bin->curxtr)
r_cons_printf ("format\t%s\n", core->bin->curarch.curplugin->name);
} else eprintf ("No selected file\n");
}
return 0;
}

View File

@ -1,4 +1,5 @@
/* radare - LGPL - Copyright 2009-2012 // pancake<nopcode.org> */
static int printzoomcallback(void *user, int mode, ut64 addr, ut8 *bufz, ut64 size) {
RCore *core = (RCore *) user;
int j, ret = 0;
@ -459,3 +460,6 @@ return 0;
return 0;
}
static int cmd_hexdump(void *data, const char *input) {
return cmd_print (data, input-1);
}

View File

@ -26,10 +26,12 @@ static int r_core_visual_hud(RCore *core) {
if (homehud)
res = r_cons_hud_file (homehud);
// TODO: this file needs to be installed
if (!res)
res = r_cons_hud_file (R2_LIBDIR"/radare2/"R2_VERSION"/hud/main");
if (!res)
r_cons_message ("Cannot find hud file");
if (!res) {
const char *f = R2_LIBDIR"/radare2/"R2_VERSION"/hud/main";
if (r_file_exist (f))
res = r_cons_hud_file (f);
else r_cons_message ("Cannot find hud file");
}
r_cons_clear ();
if (res) {
p = strchr (res, '\t');