* Remove max blocksize hard limit

- Now configurable thru the io.maxblk var
* Add support for huge dumping with 'wt'
  - As requested by nics
This commit is contained in:
pancake 2012-04-21 14:28:53 +02:00
parent 1d9668cb8e
commit 58dfc4051d
6 changed files with 71 additions and 12 deletions

View File

@ -65,7 +65,7 @@ static int cmd_print(void *data, const char *input) {
}// else l = 0;
} else l = len;
i = r_config_get_i (core->config, "cfg.maxbsize");
i = r_config_get_i (core->config, "io.maxblk");
if (i && l > i) {
eprintf ("This block size is too big. Did you mean 'p%c @ %s' instead?\n",
*input, input+2);

View File

@ -132,12 +132,20 @@ static int cmd_write(void *data, const char *input) {
r_core_block_read (core, 0);
break;
case 't':
/* TODO: support userdefined size? */
arg = (const char *)(input+((input[1]==' ')?2:1));
r_file_dump (arg, core->block, core->blocksize);
if (*str != ' ') {
eprintf ("Usage: wt file [off]\n");
} else {
tmp = strchr (str+1, ' ');
if (tmp) {
st64 sz = (st64) r_num_math (core->num, tmp+1);
*tmp = 0;
if (sz<1) eprintf ("Invalid length\n");
else r_core_dump (core, str+1, core->offset, (ut64)sz);
} else r_file_dump (str+1, core->block, core->blocksize);
}
break;
case 'T':
eprintf ("TODO\n");
eprintf ("TODO: wT // why?\n");
break;
case 'f':
arg = (const char *)(input+((input[1]==' ')?2:1));

View File

@ -32,6 +32,15 @@ static int config_searchalign_callback(void *user, void *data) {
return R_TRUE;
}
static int config_iomaxblk_callback(void *user, void *data) {
RCore *core = (RCore *) user;
RConfigNode *node = (RConfigNode *) data;
if (node->i_value>1) {
core->blocksize_max = node->i_value;
return R_TRUE;
}
return R_FALSE;
}
static int config_ioffio_callback(void *user, void *data) {
RCore *core = (RCore *) user;
RConfigNode *node = (RConfigNode *) data;
@ -497,8 +506,6 @@ R_API int r_core_config_init(RCore *core) {
r_config_desc (cfg, "cfg.datefmt", "Date format (%d:%m:%Y %H:%M:%S %z)");
r_config_set (cfg, "cfg.fortunes", "true");
r_config_desc (cfg, "cfg.fortunes", "If enabled show tips at start");
r_config_set_i (cfg, "cfg.maxbsize", 524288);
r_config_desc (cfg, "cfg.maxbsize", "Max block size in print command");
r_config_set (cfg, "cfg.wseek", "false");
r_config_desc (cfg, "cfg.wseek", "Seek after write");
r_config_set_i (cfg, "cfg.hashlimit", SLURP_LIMIT);
@ -579,6 +586,14 @@ R_API int r_core_config_init(RCore *core) {
r_config_desc (cfg, "search.align", "Only catch aligned search hits");
r_config_set_cb (cfg, "scr.html", "false", &config_scrhtml_callback);
r_config_desc (cfg, "scr.html", "If enabled disassembly use HTML syntax");
{
char buf[128];
sprintf (buf, "%d", R_CORE_BLOCKSIZE_MAX);
r_config_set_cb (cfg, "io.maxblk", buf, &config_iomaxblk_callback);
r_config_desc (cfg, "io.maxblk", "set max block size (soft limit)");
}
r_config_set_cb (cfg, "io.ffio", "true", &config_ioffio_callback);
r_config_desc (cfg, "io.ffio", "fill invalid buffers with 0xff instead of returning error");
r_config_set_cb (cfg, "io.va", "true", &config_iova_callback);

View File

@ -482,9 +482,11 @@ R_API int r_core_block_size(RCore *core, int bsize) {
return R_FALSE;
if (bsize<1)
bsize = 1;
else if (bsize> R_CORE_BLOCKSIZE_MAX)
bsize = R_CORE_BLOCKSIZE_MAX;
else ret = R_TRUE;
else if (bsize>core->blocksize_max) {
eprintf ("blocksize is bigger than io.maxblk. dimmed to 0x%x\n",
core->blocksize_max);
bsize = core->blocksize_max;
} else ret = R_TRUE;
core->block = realloc (core->block, bsize+1);
if (core->block == NULL) {
eprintf ("Oops. cannot allocate that much (%u)\n", bsize);

View File

@ -2,6 +2,38 @@
#include "r_core.h"
R_API int r_core_dump(RCore *core, const char *file, ut64 addr, ut64 size) {
ut64 i;
ut8 *buf;
int bs = core->blocksize;
FILE *fd;
truncate (file, 0);
fd = fopen (file, "wb");
if (!fd) {
eprintf ("Cannot open '%s' for writing\n", file);
return R_FALSE;
}
buf = malloc (bs);
r_cons_break (NULL, NULL);
for (i=0; i<size; ) {
if (r_cons_singleton ()->breaked)
break;
if ((i+bs)>size)
bs = size-i;
r_io_read_at (core->io, addr+i, buf, bs);
if (fwrite (buf, bs, 1, fd) <1) {
eprintf ("write error\n");
break;
}
i += bs;
}
eprintf ("dumped 0x%"PFMT64x" bytes\n", i);
r_cons_break_end ();
fclose (fd);
free (buf);
return R_TRUE;
}
R_API int r_core_write_op(RCore *core, const char *arg, char op) {
char *str;
ut8 *buf;

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2011 pancake<nopcode.org> */
/* radare - LGPL - Copyright 2009-2012 pancake<nopcode.org> */
#ifndef _INCLUDE_R_CORE_H_
#define _INCLUDE_R_CORE_H_
@ -28,7 +28,7 @@
#define R_CORE_CMD_EXIT -2
#define R_CORE_BLOCKSIZE 64
#define R_CORE_BLOCKSIZE_MAX 0x40000 /* 4 MB */
#define R_CORE_BLOCKSIZE_MAX 0x40000 /* 256KB */
#define R_CORE_ANAL_GRAPHLINES 0x1
#define R_CORE_ANAL_GRAPHBODY 0x2
@ -75,6 +75,7 @@ typedef struct r_core_asmsteps_t {
typedef struct r_core_t {
ut64 offset;
ut32 blocksize;
ut32 blocksize_max;
ut8 *block;
ut8 *oobi; /* out of band input ; used to get input from file or multiline */
int ffio;
@ -274,6 +275,7 @@ R_API int r_core_patch (RCore *core, const char *patch);
R_API void r_core_hack_help(RCore *core);
R_API int r_core_hack(RCore *core, const char *op);
R_API int r_core_dump(RCore *core, const char *file, ut64 addr, ut64 size);
R_API void r_core_diff_show(RCore *c, RCore *c2);
#endif