Add `wta` support for appending dump.
This commit is contained in:
parent
6b2879c206
commit
87162dc8bf
|
@ -167,7 +167,7 @@ static int extract_binobj (const RBinFile *bf, const RBinObject *o, int idx) {
|
|||
eprintf ("Invalid offsets\n");
|
||||
res = R_FALSE;
|
||||
} else {
|
||||
if (!outfile || !r_file_dump (outfile, bytes+boffset, bin_size)) {
|
||||
if (!outfile || !r_file_dump (outfile, bytes+boffset, bin_size, 0)) {
|
||||
eprintf ("Error extracting %s\n", outfile);
|
||||
res = R_FALSE;
|
||||
} else {
|
||||
|
@ -253,7 +253,7 @@ static int rabin_dump_sections(char *scnname) {
|
|||
}
|
||||
r_buf_read_at (bin->cur->buf, section->paddr, buf, section->size);
|
||||
if (output) {
|
||||
r_file_dump (output, buf, section->size);
|
||||
r_file_dump (output, buf, section->size, 0);
|
||||
} else {
|
||||
r_hex_bin2str (buf, section->size, ret);
|
||||
printf ("%s\n", ret);
|
||||
|
@ -592,7 +592,7 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
b = r_bin_create (bin, code, codelen, data, datalen);
|
||||
if (b) {
|
||||
if (r_file_dump (file, b->buf, b->length)) {
|
||||
if (r_file_dump (file, b->buf, b->length, 0)) {
|
||||
eprintf ("Dumped %d bytes in '%s'\n", b->length, file);
|
||||
r_file_chmod (file, "+x", 0);
|
||||
} else eprintf ("Error dumping into a.out\n");
|
||||
|
|
|
@ -145,3 +145,4 @@ nothing personal, just bitness
|
|||
Too old to crash
|
||||
Finnished a beer
|
||||
ESIL ruined my life
|
||||
ESIL: The Aftersleep
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* radare - LGPL - Copyright 2009-2013 - nibble */
|
||||
/* radare - LGPL - Copyright 2009-2015 - pancake, nibble */
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_util.h>
|
||||
|
@ -30,5 +30,5 @@ R_API int r_bin_wr_output(RBin *bin, const char *filename) {
|
|||
|
||||
if (!binfile || !binfile->buf) return R_FALSE;
|
||||
return r_file_dump (filename, binfile->buf->buf,
|
||||
binfile->buf->length);
|
||||
binfile->buf->length, 0);
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ static void filesave () {
|
|||
lines[i]='\n';
|
||||
}
|
||||
}
|
||||
if (r_file_dump (path, (const ut8*)lines, bytes))
|
||||
if (r_file_dump (path, (const ut8*)lines, bytes, 0))
|
||||
eprintf ("File '%s' saved (%d bytes)\n", path, bytes);
|
||||
else eprintf ("Cannot save file\n");
|
||||
// restore back zeroes
|
||||
|
|
|
@ -548,7 +548,7 @@ static int cmd_debug_map(RCore *core, const char *input) {
|
|||
} else snprintf (file, sizeof (file),
|
||||
"0x%08"PFMT64x"-0x%08"PFMT64x"-%s.dmp",
|
||||
map->addr, map->addr_end, r_str_rwx_i (map->perm));
|
||||
if (!r_file_dump (file, buf, map->size)) {
|
||||
if (!r_file_dump (file, buf, map->size, 0)) {
|
||||
eprintf ("Cannot write '%s'\n", file);
|
||||
free (buf);
|
||||
return R_FALSE;
|
||||
|
|
|
@ -117,7 +117,7 @@ static int cmd_project(void *data, const char *input) {
|
|||
if (data) {
|
||||
char *str = r_core_project_notes_file (core, fileproject);
|
||||
if (str) {
|
||||
r_file_dump (str, data, strlen ((const char*)data));
|
||||
r_file_dump (str, data, strlen ((const char*)data), 0);
|
||||
free (str);
|
||||
}
|
||||
free (data);
|
||||
|
|
|
@ -103,7 +103,7 @@ static int cmd_section(void *data, const char *input) {
|
|||
snprintf (file, sizeof (file), "%s", input+2);
|
||||
} else snprintf (file, sizeof (file), "0x%08"PFMT64x"-0x%08"PFMT64x"-%s.dmp",
|
||||
s->vaddr, s->vaddr+s->size, r_str_rwx_i (s->rwx));
|
||||
if (!r_file_dump (file, buf, s->size)) {
|
||||
if (!r_file_dump (file, buf, s->size, 0)) {
|
||||
eprintf ("Cannot write '%s'\n", file);
|
||||
free (buf);
|
||||
return R_FALSE;
|
||||
|
|
|
@ -669,31 +669,45 @@ static int cmd_write(void *data, const char *input) {
|
|||
WSEEK (core, len);
|
||||
r_core_block_read (core, 0);
|
||||
break;
|
||||
case 't': {
|
||||
st64 sz = core->blocksize;
|
||||
case 't': // "wt"
|
||||
if (*str == '?') {
|
||||
eprintf ("Usage: wt file [size]\n");
|
||||
eprintf ("Usage: wt[a] file [size] write 'size' bytes in current block to file\n");
|
||||
free (ostr);
|
||||
return 0;
|
||||
} else
|
||||
if (*str != ' ') {
|
||||
const char* prefix = r_config_get (core->config, "cfg.prefixdump");
|
||||
snprintf(_fn, sizeof(_fn), "%s.0x%08"PFMT64x, prefix, core->offset);
|
||||
filename = _fn;
|
||||
} else filename = str+1;
|
||||
tmp = strchr (str+1, ' ');
|
||||
if (tmp) {
|
||||
sz = (st64) r_num_math (core->num, tmp+1);
|
||||
*tmp = 0;
|
||||
if (sz<1) eprintf ("Invalid length\n");
|
||||
else r_core_dump (core, filename, core->offset, (ut64)sz);
|
||||
} else {
|
||||
if (!r_file_dump (filename, core->block, core->blocksize)) {
|
||||
sz = 0;
|
||||
} else sz = core->blocksize;
|
||||
}
|
||||
eprintf ("Dumped %"PFMT64d" bytes from 0x%08"PFMT64x" into %s\n",
|
||||
sz, core->offset, filename);
|
||||
int append = 0;
|
||||
st64 sz = core->blocksize;
|
||||
if (*str=='a') { // "wta"
|
||||
append = 1;
|
||||
str++;
|
||||
if (str[0]==' ') {
|
||||
filename = str+1;
|
||||
} else {
|
||||
const char* prefix = r_config_get (core->config, "cfg.prefixdump");
|
||||
snprintf (_fn, sizeof (_fn), "%s.0x%08"PFMT64x, prefix, core->offset);
|
||||
filename = _fn;
|
||||
}
|
||||
} else if (*str != ' ') {
|
||||
const char* prefix = r_config_get (core->config, "cfg.prefixdump");
|
||||
snprintf(_fn, sizeof(_fn), "%s.0x%08"PFMT64x, prefix, core->offset);
|
||||
filename = _fn;
|
||||
} else filename = str+1;
|
||||
tmp = strchr (str+1, ' ');
|
||||
if (tmp) {
|
||||
sz = (st64) r_num_math (core->num, tmp+1);
|
||||
if (!sz) {
|
||||
sz = core->blocksize;
|
||||
}
|
||||
*tmp = 0;
|
||||
if (sz<1) eprintf ("Invalid length\n");
|
||||
else r_core_dump (core, filename, core->offset, (ut64)sz, append);
|
||||
} else {
|
||||
if (!r_file_dump (filename, core->block, core->blocksize, append)) {
|
||||
sz = 0;
|
||||
} else sz = core->blocksize;
|
||||
}
|
||||
eprintf ("Dumped %"PFMT64d" bytes from 0x%08"PFMT64x" into %s\n",
|
||||
sz, core->offset, filename);
|
||||
}
|
||||
break;
|
||||
case 'f':
|
||||
|
|
|
@ -224,7 +224,7 @@ R_API char *r_core_sysenv_begin(RCore *core, const char *cmd) {
|
|||
if (strstr (cmd, "BLOCK")) {
|
||||
// replace BLOCK in RET string
|
||||
if ((f = r_file_temp ("r2block"))) {
|
||||
if (r_file_dump (f, core->block, core->blocksize))
|
||||
if (r_file_dump (f, core->block, core->blocksize, 0))
|
||||
r_sys_setenv ("BLOCK", f);
|
||||
free (f);
|
||||
}
|
||||
|
|
|
@ -60,13 +60,17 @@ R_API int r_core_seek_base (RCore *core, const char *hex) {
|
|||
return r_core_seek (core, addr, 1);
|
||||
}
|
||||
|
||||
R_API int r_core_dump(RCore *core, const char *file, ut64 addr, ut64 size) {
|
||||
R_API int r_core_dump(RCore *core, const char *file, ut64 addr, ut64 size, int append) {
|
||||
ut64 i;
|
||||
ut8 *buf;
|
||||
int bs = core->blocksize;
|
||||
FILE *fd;
|
||||
r_sys_truncate (file, 0);
|
||||
fd = r_sandbox_fopen (file, "wb");
|
||||
if (append) {
|
||||
fd = r_sandbox_fopen (file, "ab");
|
||||
} else {
|
||||
r_sys_truncate (file, 0);
|
||||
fd = r_sandbox_fopen (file, "wb");
|
||||
}
|
||||
if (!fd) {
|
||||
eprintf ("Cannot open '%s' for writing\n", file);
|
||||
return R_FALSE;
|
||||
|
|
|
@ -671,7 +671,7 @@ static int r_core_rtr_http_run (RCore *core, int launch, const char *path) {
|
|||
r_config_get (core->config, "http.uproot"),
|
||||
rs->path + 4);
|
||||
eprintf ("UPLOADED '%s'\n", filename);
|
||||
r_file_dump (filename, ret, retlen);
|
||||
r_file_dump (filename, ret, retlen, 0);
|
||||
free (filename);
|
||||
snprintf (buf, sizeof (buf),
|
||||
"<html><body><h2>uploaded %d bytes. Thanks</h2>\n", retlen);
|
||||
|
|
|
@ -1120,7 +1120,7 @@ R_API void r_core_visual_mounts (RCore *core) {
|
|||
r_cons_fgets (buf, sizeof (buf)-1, 0, 0);
|
||||
r_cons_set_raw (1);
|
||||
r_cons_show_cursor (R_FALSE);
|
||||
r_file_dump (buf, file->data, file->size);
|
||||
r_file_dump (buf, file->data, file->size, 0);
|
||||
r_fs_close (core->fs, file);
|
||||
r_cons_printf ("Done\n");
|
||||
} else r_cons_printf ("Cannot dump file\n");
|
||||
|
|
|
@ -79,8 +79,8 @@ R_API int r_diff_buffers_radiff(RDiff *d, const ut8 *a, int la, const ut8 *b, in
|
|||
ooa = oob = 0LL;
|
||||
oop = -1;
|
||||
|
||||
r_file_dump (".a", a, la);
|
||||
r_file_dump (".b", b, lb);
|
||||
r_file_dump (".a", a, la, 0);
|
||||
r_file_dump (".b", b, lb, 0);
|
||||
r_sys_cmd ("radiff -d .a .b | rsc uncolor > .d");
|
||||
fd = fopen (".d", "r");
|
||||
|
||||
|
|
|
@ -282,7 +282,7 @@ R_API int r_fs_dir_dump (RFS* fs, const char *path, const char *name) {
|
|||
item = r_fs_open (fs, npath);
|
||||
if (item) {
|
||||
r_fs_read (fs, item, 0, item->size);
|
||||
r_file_dump (str, item->data, item->size);
|
||||
r_file_dump (str, item->data, item->size, 0);
|
||||
free (item->data);
|
||||
r_fs_close (fs, item);
|
||||
}
|
||||
|
@ -682,7 +682,7 @@ R_API int r_fs_prompt (RFS *fs, const char *root) {
|
|||
file = r_fs_open (fs, s);
|
||||
if (file) {
|
||||
r_fs_read (fs, file, 0, file->size);
|
||||
r_file_dump (input, file->data, file->size);
|
||||
r_file_dump (input, file->data, file->size, 0);
|
||||
free (file->data);
|
||||
r_fs_close (fs, file);
|
||||
} else {
|
||||
|
|
|
@ -424,7 +424,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 int r_core_dump(RCore *core, const char *file, ut64 addr, ut64 size, int append);
|
||||
R_API void r_core_diff_show(RCore *core, RCore *core2);
|
||||
|
||||
|
||||
|
|
|
@ -495,7 +495,7 @@ R_API char *r_file_slurp_range(const char *str, ut64 off, int sz, int *osz);
|
|||
R_API char *r_file_slurp_random_line(const char *file);
|
||||
R_API char *r_file_slurp_random_line_count(const char *file, int *linecount);
|
||||
R_API ut8 *r_file_slurp_hexpairs(const char *str, int *usz);
|
||||
R_API boolt r_file_dump(const char *file, const ut8 *buf, int len);
|
||||
R_API boolt r_file_dump(const char *file, const ut8 *buf, int len, int append);
|
||||
R_API boolt r_file_rm(const char *file);
|
||||
R_API boolt r_file_exists(const char *str);
|
||||
R_API boolt r_file_fexists(const char *fmt, ...);
|
||||
|
|
|
@ -593,7 +593,9 @@ R_API int r_run_start(RRunProfile *p) {
|
|||
if (p->_pidfile) {
|
||||
char pidstr[32];
|
||||
snprintf (pidstr, sizeof (pidstr), "%d\n", getpid ());
|
||||
r_file_dump (p->_pidfile, (const ut8*)pidstr, strlen (pidstr));
|
||||
r_file_dump (p->_pidfile,
|
||||
(const ut8*)pidstr,
|
||||
strlen (pidstr), 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* radare - LGPL - Copyright 2007-2014 - pancake */
|
||||
/* radare - LGPL - Copyright 2007-2015 - pancake */
|
||||
|
||||
#include "r_types.h"
|
||||
#include "r_util.h"
|
||||
|
@ -390,12 +390,19 @@ R_API char *r_file_root(const char *root, const char *path) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
R_API boolt r_file_dump(const char *file, const ut8 *buf, int len) {
|
||||
R_API boolt r_file_dump(const char *file, const ut8 *buf, int len, int append) {
|
||||
int ret;
|
||||
FILE *fd;
|
||||
if (!file || !*file || !buf)
|
||||
if (!file || !*file || !buf) {
|
||||
eprintf ("RET %p, buf %p\n", file, buf);
|
||||
return R_FALSE;
|
||||
fd = r_sandbox_fopen (file, "wb");
|
||||
}
|
||||
if (append) {
|
||||
fd = r_sandbox_fopen (file, "awb");
|
||||
} else {
|
||||
r_sys_truncate (file, 0);
|
||||
fd = r_sandbox_fopen (file, "wb");
|
||||
}
|
||||
if (fd == NULL) {
|
||||
eprintf ("Cannot open '%s' for writing\n", file);
|
||||
return R_FALSE;
|
||||
|
|
Loading…
Reference in New Issue