Add oj and o*, to list opened files in JSON and r2 commands

This commit is contained in:
pancake 2014-12-19 13:46:04 +01:00
parent af49b74b49
commit 9a5a39a804
3 changed files with 41 additions and 10 deletions

View File

@ -13,7 +13,9 @@ static int cmd_open(void *data, const char *input) {
switch (*input) {
case '\0':
r_core_file_list (core);
case '*':
case 'j':
r_core_file_list (core, *input);
break;
case 'p':
if (r_sandbox_enable (0)) {
@ -317,6 +319,8 @@ static int cmd_open(void *data, const char *input) {
const char *help_msg[] = {
"Usage: o","[com- ] [file] ([offset])","",
"o","","list opened files",
"o*","","list opened files in r2 commands",
"oj","","list opened files in JSON format",
"oc"," [file]","open core file, like relaunching r2",
"op"," ["R_LIB_EXT"]","open r2 native plugin (asm, bin, core, ..)",
"oo","","reopen current file (kill+fork in debugger)",

View File

@ -767,22 +767,49 @@ R_API RCoreFile *r_core_file_get_by_fd(RCore *core, int fd) {
return NULL;
}
R_API int r_core_file_list(RCore *core) {
int count = 0;
R_API int r_core_file_list(RCore *core, int mode) {
int overlapped, count = 0;
RCoreFile *f;
ut64 from;
RListIter *iter;
if (mode=='j')
r_cons_printf ("[");
r_list_foreach (core->files, iter, f) {
if (f->map) {
int overlapped = r_io_map_overlaps (core->io, f->desc, f->map);
r_cons_printf ("%c %d %s @ 0x%"PFMT64x" ; %s size=%d %s\n",
core->io->raised == f->desc->fd?'*':'-',
from = f->map->from;
overlapped = r_io_map_overlaps (core->io, f->desc, f->map);
} else {
from = 0LL;
overlapped = R_FALSE;
}
switch (mode) {
case 'j':
r_cons_printf ("{\"raised\":%s,\"fd\":%d,\"uri\":\"%s\",\"from\":%"
PFMT64d",\"writable\":%s,\"size\":%d,\"overlaps\":%s}%s",
core->io->raised == f->desc->fd?"true":"false",
f->desc->fd, f->desc->uri, f->map->from,
f->desc->flags & R_IO_WRITE? "rw": "r",
f->desc->flags & R_IO_WRITE? "true": "false",
r_io_desc_size (core->io, f->desc),
overlapped?"overlaps":"");
} else r_cons_printf ("- %d %s\n", f->desc->fd, f->desc->uri);
overlapped?"true":"false",
iter->n? ",":"");
break;
case '*':
case 'r':
r_cons_printf ("o %s 0x%llx\n", f->desc->uri, from);
break;
default:
r_cons_printf ("%c %d %s @ 0x%"PFMT64x" ; %s size=%d %s\n",
core->io->raised == f->desc->fd?'*':'-',
f->desc->fd, f->desc->uri, from,
f->desc->flags & R_IO_WRITE? "rw": "r",
r_io_desc_size (core->io, f->desc),
overlapped?"overlaps":"");
break;
}
count++;
}
if (mode=='j')
r_cons_printf ("]\n");
return count;
}

View File

@ -235,7 +235,7 @@ R_API RCoreFile *r_core_file_open_many(RCore *r, const char *file, int flags, ut
R_API RCoreFile *r_core_file_get_by_fd(RCore *core, int fd);
R_API int r_core_file_close(RCore *core, RCoreFile *fh);
R_API int r_core_file_close_fd(RCore *core, int fd);
R_API int r_core_file_list(RCore *core);
R_API int r_core_file_list(RCore *core, int mode);
R_API int r_core_file_binlist(RCore *core);
R_API int r_core_file_bin_raise(RCore *core, ut32 num);
R_API int r_core_seek_delta(RCore *core, st64 addr);