Add support for temporary block contents

Honor nullcallback again
Syntax is @f:<path-to-file> @s:<string> @b:<bytes>
This commit is contained in:
pancake 2012-09-20 03:38:48 +02:00
parent 689f2df0cb
commit 13d21461d5
4 changed files with 74 additions and 23 deletions

View File

@ -6,6 +6,10 @@ Install NDK in archlinux x86-64
To build r2 for android you need to install the NDK:
http://developer.android.com/tools/sdk/ndk/index.html
Edit ~/.r2androidrc to setup the paths to your ndk
sys/android-shell.sh
./configure --with-compiler=android --with-ostype=android --without-ssl --prefix=/data/radare2 --without-pic --with-nonpic --without-gmp
make -j 4

View File

@ -30,6 +30,15 @@ static void cmd_debug_reg(RCore *core, const char *str);
#include "cmd_help.c"
#include "cmd_search.c"
static int r_core_cmd_nullcallback(void *data) {
RCore *core = (RCore*) data;
if (core->cmdrepeat) {
r_core_cmd_repeat (core, 1);
return 1;
}
return 0;
}
// TODO: move somewhere else
R_API RAsmOp *r_core_disassemble (RCore *core, ut64 addr) {
int delta;
@ -493,6 +502,9 @@ static int r_core_cmd_subst(RCore *core, char *cmd) {
for (++colon; *colon ==';'; colon++);
r_core_cmd_subst (core, colon);
//*colon = ';';
} else {
if (!*cmd)
r_core_cmd_nullcallback(core);
}
free (icmd);
return 0;
@ -748,12 +760,55 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd) {
core->tmpseek = ptr? R_TRUE: R_FALSE;
if (ptr) {
ut64 tmpoff, tmpbsz, addr;
ut8 *buf;
ut32 sz;
const char *offstr;
char *ptr2 = strchr (ptr+1, ':');
*ptr = '\0';
cmd = r_str_clean (cmd);
char *f, *ptr2 = strchr (ptr+1, ':');
int len;
tmpoff = core->offset;
tmpbsz = core->blocksize;
*ptr = '\0';
for (ptr++;*ptr== ' ';ptr++); ptr--;
if (ptr[2]==':') {
switch (ptr[1]) {
case 'f':
f = r_file_slurp (ptr+3, &sz);
if (f) {
buf = malloc (sz);
if (buf) {
free (core->block);
core->block = buf;
core->blocksize = sz;
memcpy (core->block, f, sz);
} else eprintf ("Cannot alloc %d", sz);
free (f);
} else eprintf ("Cannot open '%s'\n", ptr+3);
break;
case '8':
case 'b':
buf = malloc (strlen (ptr+2));
if (!buf) {
eprintf ("cannot allocate\n");
return R_FALSE;
}
len = r_hex_str2bin (ptr+3, buf);
r_core_block_size (core, len);
memcpy (core->block, buf, len);
free (buf);
break;
case 's':
len = strlen (ptr+3);
r_core_block_size (core, len);
memcpy (core->block, ptr+3, len);
break;
}
ret = r_cmd_call (core->rcmd, r_str_trim_head (cmd));
*ptr = '@';
r_core_block_size (core, tmpbsz);
return ret;
}
for (ptr++;*ptr== ' ';ptr++); ptr--;
cmd = r_str_clean (cmd);
if (ptr2) {
*ptr2 = '\0';
r_core_block_size (core, r_num_math (core->num, ptr2+1));
@ -1121,15 +1176,6 @@ R_API void r_core_cmd_repeat(RCore *core, int next) {
}
}
static int r_core_cmd_nullcallback(void *data) {
RCore *core = (RCore*) data;
if (core->cmdrepeat) {
r_core_cmd_repeat (core, 1);
return 1;
}
return 0;
}
R_API void r_core_cmd_init(RCore *core) {
core->rcmd = r_cmd_new ();
core->rcmd->macro.printf = (PrintfCallback)r_cons_printf;

View File

@ -362,7 +362,7 @@ static int cmd_help(void *data, const char *input) {
" 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[?] [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"
@ -382,6 +382,9 @@ static int cmd_help(void *data, const char *input) {
" q [ret] ; quit program with a return value\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 '@s: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"

View File

@ -529,26 +529,24 @@ R_API int r_core_prompt_exec(RCore *r) {
}
R_API int r_core_block_size(RCore *core, int bsize) {
const ut8 *bump;
int ret = R_FALSE;
if (bsize == core->blocksize)
return R_FALSE;
if (bsize<1)
bsize = 1;
else if (bsize>core->blocksize_max) {
eprintf ("blocksize is bigger than io.maxblk. dimmed to 0x%x > 0x%x\n",
eprintf ("bsize is bigger than io.maxblk. dimmed to 0x%x > 0x%x\n",
bsize, core->blocksize_max);
bsize = core->blocksize_max;
} else ret = R_TRUE;
core->block = realloc (core->block, bsize+1);
if (core->block == NULL) {
bump = realloc (core->block, bsize+1);
if (bump == NULL) {
eprintf ("Oops. cannot allocate that much (%u)\n", bsize);
core->block = malloc (R_CORE_BLOCKSIZE);
core->blocksize = R_CORE_BLOCKSIZE;
if (core->block == NULL) {
eprintf ("Panic in the heap!\n");
exit (1);
}
} else core->blocksize = bsize;
return R_FALSE;
}
core->block = bump;
core->blocksize = bsize;
memset (core->block, 0xff, core->blocksize);
r_core_block_read (core, 0);
return ret;