Add o-! command and fix ood

This commit is contained in:
pancake 2017-11-22 14:58:09 +01:00
parent e7afd67991
commit 52145350d2
3 changed files with 37 additions and 8 deletions

View File

@ -30,7 +30,7 @@ static const char *help_msg_o[] = {
"op"," [fd]", "priorize given fd (see also ob)",
"o"," 4","Switch to open file on fd 4",
"o","-1","close file descriptor 1",
"o-","*","close all opened files",
"o-","!*","close all opened files",
"o--","","close all files, analysis, binfiles, flags, same as !r2 --",
"o"," [file]","open [file] file in read-only",
"o+"," [file]","open file in read-write mode",
@ -39,6 +39,14 @@ static const char *help_msg_o[] = {
NULL
};
static const char *help_msg_o_[] = {
"Usage: o-","[#!*]", "",
"o-*","","close all opened files",
"o-!","","close all files except the current one",
"o-3","","close fd=3",
NULL
};
static const char *help_msg_o_star[] = {
"Usage:", "o* [> files.r2]", "",
"o*", "", "list opened files in r2 commands", NULL
@ -807,7 +815,6 @@ R_API void r_core_file_reopen_debug (RCore *core, const char *args) {
char *newfile2 = strdup (newfile);
desc->uri = newfile;
desc->referer = NULL;
//r_core_file_reopen (core, newfile, 0, 2);
r_config_set_i (core->config, "asm.bits", bits);
r_config_set_i (core->config, "cfg.debug", true);
r_core_file_reopen (core, newfile, 0, 2);
@ -1204,11 +1211,14 @@ static int cmd_open(void *data, const char *input) {
break;
case '-': // "o-"
switch (input[1]) {
case '!': // "o-!"
r_core_file_close_all_but (core);
break;
case '*': // "o-*"
r_core_file_close_fd (core, -1);
r_io_close_all (core->io);
r_bin_file_delete_all (core->bin);
r_list_purge(core->files);
r_list_purge (core->files);
break;
case '-': // "o--"
eprintf ("All core files, io, anal and flags info purged.\n");
@ -1232,12 +1242,9 @@ static int cmd_open(void *data, const char *input) {
break;
case 0:
case '?':
eprintf ("Usage: o-# or o-*, where # is the filedescriptor number\n");
r_core_cmd_help (core, help_msg_o_);
eprintf ("Usage: o-#, o-! or o-*, where # is the filedescriptor number\n");
}
// hackaround to fix invalid read
//r_core_cmd0 (core, "oo");
// uninit deref
//r_core_block_read (core);
break;
case '.': // "o."
{

View File

@ -148,6 +148,10 @@ R_API int r_core_file_reopen(RCore *core, const char *args, int perm, int loadbi
}
// update anal io bind
r_io_bind (core->io, &(core->anal->iob));
if (core->file && core->file->fd >= 0) {
r_core_cmd0 (core, "o-!");
}
r_core_file_close_all_but (core);
// This is done to ensure that the file is correctly
// loaded into the view
free (obinfilepath);
@ -1001,6 +1005,23 @@ R_API int r_core_file_binlist(RCore *core) {
return count;
}
static bool close_but_cb (void *user, void *data, ut32 id) {
RCore *core = (RCore *)user;
RIODesc *desc = (RIODesc *)data;
if (core && desc && core->file) {
if (desc->fd != core->file->fd) {
// TODO: use the API
r_core_cmdf (core, "o-%d", desc->fd);
}
}
return true;
}
R_API bool r_core_file_close_all_but(RCore *core) {
r_id_storage_foreach (core->io->files, close_but_cb, core);
return true;
}
R_API bool r_core_file_close_fd(RCore *core, int fd) {
RCoreFile *file;
RListIter *iter;

View File

@ -300,6 +300,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 bool r_core_file_close_fd(RCore *core, int fd);
R_API bool r_core_file_close_all_but(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);