Fix partial IO read, show flags under visual cursor

Show flags in @@ and visual title with cursor
Port 80 is now default for r2 -C
Key 'q' will quit -C mode
Fix visual core_read() issue with chrome
Fix io.va issue in partial reads
Fix r_io_next_section() code
This commit is contained in:
pancake 2013-03-18 00:38:04 +01:00
parent 14eee2a325
commit c11bf6c1cb
6 changed files with 76 additions and 39 deletions

View file

@ -1157,7 +1157,8 @@ R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each) {
if (r_str_glob (flag->name, word)) {
r_core_seek (core, flag->offset, 1);
//r_cons_printf ("# @@ 0x%08"PFMT64x" (%s)\n", core->offset, flag->name);
r_cons_printf ("0x%08"PFMT64x" ", core->offset);
// r_cons_printf ("0x%08"PFMT64x" %s\n", core->offset, flag->name);
eprintf ("# 0x%08"PFMT64x": %s\n", addr, cmd);
r_core_cmd (core, cmd, 0);
}
}

View file

@ -163,7 +163,9 @@ R_API int r_core_block_read(RCore *core, int next) {
off = r_io_seek (core->io, core->offset+((next)?core->blocksize:0), R_IO_SEEK_SET);
if (off == UT64_MAX) {
memset (core->block, 0xff, core->blocksize);
return -1;
// TODO: do continuation in io
if (!core->io->va)
return -1;
}
return (int)r_io_read (core->io, core->block, core->blocksize);
}

View file

@ -382,17 +382,18 @@ R_API void r_core_rtr_add(RCore *core, const char *_input) {
host++;
if (!(ptr = strchr (host, ':'))) {
eprintf ("Error: Port is not specified\n");
return;
ptr = host;
port = "80";
} else {
*ptr++ = '\0';
port = ptr;
}
*ptr++ = '\0';
if (!(file = strchr (ptr, '/'))) {
eprintf("Error: Missing '/'\n");
return;
}
*file++ = 0;
port = ptr;
fd = r_socket_new (R_FALSE);
if (!fd) {
@ -416,6 +417,7 @@ R_API void r_core_rtr_add(RCore *core, const char *_input) {
for (;;) {
char *ptr, *str = r_line_readline ();
if (!str || !*str) break;
if (*str == 'q') break;
ptr = r_str_uri_encode (str);
if (ptr) str = ptr;
snprintf (uri, sizeof (uri), "http://%s:%s/%s%s",
@ -430,7 +432,7 @@ R_API void r_core_rtr_add(RCore *core, const char *_input) {
printf ("%s%s", res, (res[strlen (res)-1]=='\n')?"":"\n");
r_line_hist_add (str);
free (str);
} else eprintf ("http protocol fail\n");
}
}
return;
}

View file

@ -816,6 +816,7 @@ R_API int r_core_visual_cmd(RCore *core, int ch) {
setcursor (core, 0);
return R_FALSE;
}
r_core_block_read (core, 0);
return R_TRUE;
}
@ -851,12 +852,13 @@ R_API void r_core_visual_title (RCore *core, int color) {
filename = core->file->filename;
else filename = "";
{ /* get flag with delta */
RFlagItem *f = r_flag_get_at (core->flags, core->offset);
ut64 addr = core->offset + curset? cursor: 0;
RFlagItem *f = r_flag_get_at (core->flags, addr);
if (f) {
if (f->offset == core->offset)
if (f->offset == addr || !f->offset)
snprintf (pos, sizeof (pos), "@ %s", f->name);
else snprintf (pos, sizeof (pos), "@ %s+%d (0x%"PFMT64x")",
f->name, (int)(core->offset-f->offset), f->offset);
f->name, (int)(addr-f->offset), f->offset);
} else pos[0] = 0;
}
@ -870,9 +872,10 @@ R_API void r_core_visual_title (RCore *core, int color) {
bar[11] = '.'; // chop cmdfmt
bar[12] = 0; // chop cmdfmt
if (curset)
snprintf (foo, sizeof (foo), "[0x%08"PFMT64x" %d %s(0x%x:%d=%d)]> %s\n", core->offset,
core->blocksize, filename, cursor, ocursor,
ocursor==-1?1:R_ABS (cursor-ocursor)+1, bar);
snprintf (foo, sizeof (foo), "[0x%08"PFMT64x" %d (0x%x:%d=%d)]> %s %s\n",
core->offset, core->blocksize,
cursor, ocursor, ocursor==-1?1:R_ABS (cursor-ocursor)+1,
bar, pos);
else
snprintf (foo, sizeof (foo), "[0x%08"PFMT64x" %d %s]> %s %s\n",
core->offset, core->blocksize, filename, bar, pos);

View file

@ -178,7 +178,9 @@ R_API int r_io_read(RIO *io, ut8 *buf, int len) {
*/
return r_io_read_at (io, io->off, buf, len);
}
// XXX: this is buggy. must use seek+read
#define USE_CACHE 1
R_API int r_io_read_at(RIO *io, ut64 addr, ut8 *buf, int len) {
int ret, l, olen = len;
int w = 0;
@ -188,21 +190,30 @@ R_API int r_io_read_at(RIO *io, ut64 addr, ut8 *buf, int len) {
// XXX: this is buggy!
memset (buf, 0xff, len);
if (io->buffer_enabled) {
if (io->buffer_enabled)
return r_io_buffer_read (io, addr, buf, len);
}
while (len>0) {
int ms;
ut64 last = r_io_section_next (io, addr);
ut64 last2 = r_io_map_next (io, addr);
if (last == addr) last = last2;
else if (last2<last) last = last2;
l = (len > (last-addr))? (last-addr): len;
ut64 last = r_io_section_next (io, addr+w);
ut64 last2 = r_io_map_next (io, addr+w); // XXX: must use physical address
if (last == (addr+w)) last = last2;
//else if (last2<last) last = last2;
l = (len > (last-addr+w))? (last-addr+w): len;
if (l<1) l = len;
if (r_io_seek (io, addr+w, R_IO_SEEK_SET)==UT64_MAX) {
{
ut64 paddr = w? r_io_section_vaddr_to_offset (io, addr+w): addr;
st64 q = last-addr+w;
//if (q>0) l = q;
if (len>0 && l>len) l = len;
addr = paddr-w;
//eprintf ("next read is %llx %llx\n", addr, last);
//eprintf ("-_________----______ w = %d\n", w);
//eprintf ("//-------------------------// ADDR %llx len = %d\n", addr+w, l);
if (r_io_seek (io, paddr, R_IO_SEEK_SET)==UT64_MAX) {
memset (buf+w, 0xff, l);
return -1;
// return -1;
}
}
#if 0
if (io->zeromap)
if (!r_io_map_get (io, addr+w)) {
@ -216,27 +227,30 @@ eprintf ("RETRERET\n");
// XXX is this necessary?
ms = r_io_map_select (io, addr+w);
ret = r_io_read_internal (io, buf+w, l);
//eprintf ("READ %d = %02x %02x %02x\n", ret, buf[w], buf[w+1], buf[w+2]);
if (ret<1) {
memset (buf+w, 0xff, l); // reading out of file
ret = 1;
} else if (ret<l) {
l = ret;
}
#if USE_CACHE
if (io->cached) {
r_io_cache_read (io, addr+w, buf+w, len-w);
} else if (r_list_length (io->maps) >1) {
if (!io->debug && ms>0) {
//eprintf ("FAIL MS=%d l=%d d=%d\n", ms, l, d);
/* check if address is vaddred in sections */
ut64 o = r_io_section_offset_to_vaddr (io, addr);
ut64 o = r_io_section_offset_to_vaddr (io, addr+w);
if (o == UT64_MAX) {
ut64 o = r_io_section_vaddr_to_offset (io, addr);
ut64 o = r_io_section_vaddr_to_offset (io, addr+w);
if (o == UT64_MAX)
memset (buf+w, 0xff, l);
}
break;
}
}
#endif
w += l;
len -= l;
}

View file

@ -81,17 +81,19 @@ R_API void r_io_section_list(RIO *io, ut64 offset, int rad) {
if (rad) {
char *n = strdup (s->name);
r_name_filter (n, strlen (n));
io->printf ("f section.%s %"PFMT64d" 0x%"PFMT64x"\n", n, s->size, s->vaddr);
io->printf ("S 0x%08"PFMT64x" 0x%08"PFMT64x" 0x%08"PFMT64x" 0x%08"PFMT64x" %s %s\n",
s->offset, s->vaddr, s->size, s->vsize, n, r_str_rwx_i (s->rwx));
io->printf ("f section.%s %"PFMT64d" 0x%"PFMT64x"\n",
n, s->size, s->vaddr);
io->printf ("S 0x%08"PFMT64x" 0x%08"PFMT64x" 0x%08"
PFMT64x" 0x%08"PFMT64x" %s %s\n", s->offset,
s->vaddr, s->size, s->vsize, n, r_str_rwx_i (s->rwx));
} else {
io->printf ("[%.2d] %c 0x%08"PFMT64x" %s va=0x%08"PFMT64x" sz=0x%08"PFMT64x" vsz=%08"PFMT64x" %s",
io->printf ("[%.2d] %c 0x%08"PFMT64x" %s va=0x%08"PFMT64x
" sz=0x%08"PFMT64x" vsz=%08"PFMT64x" %s",
s->id, (offset>=s->offset && offset<s->offset+s->size)?'*':'.',
s->offset, r_str_rwx_i (s->rwx), s->vaddr, s->size, s->vsize, s->name);
if (s->arch && s->bits)
io->printf (" ; %s %d\n", r_sys_arch_str (s->arch), s->bits);
else io->printf ("\n");
}
i++;
}
@ -119,7 +121,7 @@ R_API void r_io_section_list_visual(RIO *io, ut64 seek, ut64 len) {
i = 0;
r_list_foreach (io->sections, iter, s) {
io->printf ("%02d%c 0x%08"PFMT64x" |",
i, (seek>=s->offset && seek<s->offset+s->size)?'*':' ', s->offset);
i, (seek>=s->offset && seek<s->offset+s->size)?'*':' ', s->offset);
for (j=0; j<width; j++) {
ut64 pos = min + (j*mul);
ut64 npos = min + ((j+1)*mul);
@ -246,24 +248,37 @@ R_API ut64 r_io_section_offset_to_vaddr(RIO *io, ut64 offset) {
}
R_API ut64 r_io_section_next(RIO *io, ut64 o) {
int oset = 0;
ut64 newsec = 0LL;
RListIter *iter;
RIOSection *s;
r_list_foreach (io->sections, iter, s) {
//eprintf (" o=%llx (%llx) (%llx)\n", o, s->offset, s->size);
ut64 addr = s->vaddr;
if (o < addr) {
if (newsec) {
if (addr<newsec)
newsec = addr;//s->offset;//addr;
} else newsec = addr; //s->offset; //addr;
}
if (o >= s->offset && o < (s->offset + s->size)) {
ut64 n = s->offset + s->size;
if (n>o) {
o = n;
oset = 1;
}
}
if (o >= s->vaddr && o < (s->vaddr + s->size)) {
ut64 n = s->vaddr + s->size;
if (n>o)
if (n>o) {
o = n;
#if 0
if (first) {
first = 0;
goto restart;
} else o = s->vaddr;
#endif
oset = 1;
}
}
}
return o;
//eprintf ("Newsec %d %llx\n", oset, newsec);
if (oset) return o;
return newsec? newsec: o;
}
R_API int r_io_section_set_archbits(RIO *io, ut64 addr, const char *arch, int bits) {