mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-05 04:56:10 +00:00
Honor io.0xff in sparse RBuffers
This commit is contained in:
parent
34bdab65b7
commit
3adb70a753
@ -211,10 +211,11 @@ R_API void r_core_sysenv_end(RCore *core, const char *cmd) {
|
||||
}
|
||||
|
||||
#if DISCUSS
|
||||
EDITOR r_sys_setenv ("EDITOR", r_config_get (core->config, "cfg.editor"));
|
||||
EDITOR r_sys_setenv ("EDITOR", r_config_get (core->config, "cfg.editor"));
|
||||
CURSOR cursor position (offset from curseek)
|
||||
VERBOSE cfg.verbose
|
||||
#endif
|
||||
|
||||
R_API char *r_core_sysenv_begin(RCore * core, const char *cmd) {
|
||||
char *f, *ret = cmd? strdup (cmd): NULL;
|
||||
RIODesc *desc = core->file ? r_io_desc_get (core->io, core->file->fd) : NULL;
|
||||
|
@ -17,6 +17,7 @@ typedef struct r_buf_t {
|
||||
bool empty;
|
||||
bool ro; // read-only
|
||||
int fd;
|
||||
int Oxff;
|
||||
RList *sparse;
|
||||
} RBuffer;
|
||||
|
||||
@ -39,7 +40,7 @@ R_API RBuffer *r_buf_new_file(const char *file, bool newFile);
|
||||
R_API RBuffer *r_buf_new_slurp(const char *file);
|
||||
R_API RBuffer *r_buf_new_empty (ut64 len);
|
||||
R_API RBuffer *r_buf_mmap(const char *file, int flags);
|
||||
R_API RBuffer *r_buf_new_sparse(void);
|
||||
R_API RBuffer *r_buf_new_sparse(ut8 Oxff);
|
||||
R_API bool r_buf_dump (RBuffer *buf, const char *file);
|
||||
/* methods */
|
||||
R_API bool r_buf_set_bits(RBuffer *b, ut64 at, const ut8* buf, int bitoff, int count);
|
||||
|
@ -23,8 +23,6 @@ static bool __plugin_open(RIO *io, const char *file, bool many) {
|
||||
}
|
||||
|
||||
static int debug_gdb_read_at(ut8 *buf, int sz, ut64 addr) {
|
||||
ut32 x;
|
||||
int ret = 0;
|
||||
if (sz < 1 || addr >= UT64_MAX || !desc) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2013-2016 - pancake, fenugrec */
|
||||
/* radare - LGPL - Copyright 2013-2017 - pancake, fenugrec */
|
||||
|
||||
/*
|
||||
*** .hex format description : every line follows this pattern
|
||||
@ -89,7 +89,7 @@ static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) {
|
||||
tsiz = -addl0;
|
||||
addl0 = 0;
|
||||
if (fwblock (out, rbs->data, rbs->from, tsiz)) {
|
||||
eprintf("ihex:fwblock error\n");
|
||||
eprintf ("ihex:fwblock error\n");
|
||||
fclose (out);
|
||||
return -1;
|
||||
}
|
||||
@ -177,6 +177,7 @@ static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) {
|
||||
return -1;
|
||||
}
|
||||
Rihex *rih = fd->data;
|
||||
memset (buf, io->Oxff, count);
|
||||
if (r_buf_read_at (rih->rbuf, io->off, buf, count) != count) {
|
||||
return -1; //should never happen with a sparsebuf..
|
||||
}
|
||||
@ -315,17 +316,16 @@ static bool ihex_parse(RBuffer *rbuf, char *str) {
|
||||
}
|
||||
sec_size = 0;
|
||||
|
||||
eol = strchr (str+1, ':');
|
||||
eol = strchr (str + 1, ':');
|
||||
if (eol) *eol = 0;
|
||||
cksum = bc;
|
||||
cksum += addr_tmp>>8;
|
||||
cksum += addr_tmp;
|
||||
cksum += type;
|
||||
if ((bc !=2) || (addr_tmp != 0)) {
|
||||
if ((bc != 2) || (addr_tmp != 0)) {
|
||||
eprintf ("invalid type 02/04 record!\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if ((sscanf (str + 9 + 0, "%02x", &extH) !=1) ||
|
||||
(sscanf (str + 9 + 2, "%02x", &extL) !=1)) {
|
||||
eprintf ("unparsable data !\n");
|
||||
@ -375,13 +375,15 @@ static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) {
|
||||
char *str = NULL;
|
||||
if (__plugin_open (io, pathname, 0)) {
|
||||
str = r_file_slurp (pathname + 7, NULL);
|
||||
if (!str) return NULL;
|
||||
if (!str) {
|
||||
return NULL;
|
||||
}
|
||||
mal= R_NEW0 (Rihex);
|
||||
if (!mal) {
|
||||
free (str);
|
||||
return NULL;
|
||||
}
|
||||
mal->rbuf = r_buf_new_sparse ();
|
||||
mal->rbuf = r_buf_new_sparse (io->Oxff);
|
||||
if (!mal->rbuf) {
|
||||
free (str);
|
||||
free (mal);
|
||||
@ -402,8 +404,14 @@ static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) {
|
||||
}
|
||||
|
||||
static bool __resize(RIO *io, RIODesc *fd, ut64 size) {
|
||||
if (!fd) {
|
||||
return false;
|
||||
}
|
||||
Rihex *rih = fd->data;
|
||||
return r_buf_resize (rih->rbuf, size);
|
||||
if (rih) {
|
||||
return r_buf_resize (rih->rbuf, size);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
RIOPlugin r_io_plugin_ihex = {
|
||||
|
@ -69,13 +69,13 @@ static bool __plugin_open(struct r_io_t *io, const char *pathname, bool many) {
|
||||
static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) {
|
||||
if (__plugin_open (io, pathname,0)) {
|
||||
RIOSparse *mal = R_NEW0 (RIOSparse);
|
||||
int size = (int)r_num_math (NULL, pathname+9);
|
||||
mal->buf = r_buf_new_sparse ();
|
||||
int size = (int)r_num_math (NULL, pathname + 9);
|
||||
mal->buf = r_buf_new_sparse (io->Oxff);
|
||||
if (!mal->buf) {
|
||||
free (mal);
|
||||
return NULL;
|
||||
}
|
||||
if (size>0) {
|
||||
if (size > 0) {
|
||||
ut8 *data = malloc (size);
|
||||
if (!data) {
|
||||
eprintf ("Cannot allocate (%s) %d bytes\n",
|
||||
|
@ -147,11 +147,12 @@ R_API RBuffer *r_buf_new_with_buf(RBuffer *b) {
|
||||
return r_buf_new_with_bytes (b->buf, b->length);
|
||||
}
|
||||
|
||||
R_API RBuffer *r_buf_new_sparse() {
|
||||
R_API RBuffer *r_buf_new_sparse(ut8 Oxff) {
|
||||
RBuffer *b = r_buf_new ();
|
||||
if (!b) {
|
||||
return NULL;
|
||||
}
|
||||
b->Oxff = Oxff;
|
||||
b->sparse = r_list_newf ((RListFree)free);
|
||||
return b;
|
||||
}
|
||||
@ -466,7 +467,7 @@ static int r_buf_cpy(RBuffer *b, ut64 addr, ut8 *dst, const ut8 *src, int len, i
|
||||
}
|
||||
} else {
|
||||
// read from sparse and write into dst
|
||||
memset (dst, 0xff, len);
|
||||
memset (dst, b->Oxff, len);
|
||||
(void)sparse_read (b->sparse, addr, dst, len);
|
||||
}
|
||||
return len;
|
||||
@ -635,7 +636,7 @@ R_API int r_buf_read_at(RBuffer *b, ut64 addr, ut8 *buf, int len) {
|
||||
}
|
||||
pa = addr - b->base;
|
||||
if (pa + len > b->length) {
|
||||
memset (buf, 0xff, len);
|
||||
memset (buf, b->Oxff, len);
|
||||
len = b->length - pa;
|
||||
if (len < 0) {
|
||||
return 0;
|
||||
@ -751,7 +752,7 @@ R_API bool r_buf_resize (RBuffer *b, ut64 newsize) {
|
||||
if (buf_len > 0) {
|
||||
ut8 *buf = malloc (buf_len);
|
||||
if (buf) {
|
||||
memset (buf, 0xff, buf_len);
|
||||
memset (buf, b->Oxff, buf_len);
|
||||
sparse_write (b->sparse, last_addr, buf, buf_len);
|
||||
free (buf);
|
||||
return true;
|
||||
@ -764,7 +765,7 @@ R_API bool r_buf_resize (RBuffer *b, ut64 newsize) {
|
||||
if (buf) {
|
||||
ut32 len = R_MIN (newsize, b->length);
|
||||
memcpy (buf, b->buf, len);
|
||||
memset (buf + len, 0xff, newsize - len);
|
||||
memset (buf + len, b->Oxff, newsize - len);
|
||||
/* commit */
|
||||
free (b->buf);
|
||||
b->buf = buf;
|
||||
|
Loading…
x
Reference in New Issue
Block a user