2019-03-08 13:22:59 +00:00
|
|
|
/* radare - LGPL - Copyright 2009-2019 - pancake */
|
2016-09-19 14:34:45 +00:00
|
|
|
|
2016-05-03 02:52:41 +00:00
|
|
|
#include "r_list.h"
|
|
|
|
#include "r_config.h"
|
|
|
|
#include "r_core.h"
|
2018-11-14 09:54:22 +00:00
|
|
|
#include "r_util.h"
|
2016-05-03 02:52:41 +00:00
|
|
|
#include "r_bin.h"
|
2017-06-14 06:48:46 +00:00
|
|
|
#include "r_debug.h"
|
2012-02-27 01:40:27 +00:00
|
|
|
|
2017-07-27 12:52:17 +00:00
|
|
|
static const char *help_msg_o[] = {
|
|
|
|
"Usage: o","[com- ] [file] ([offset])","",
|
|
|
|
"o","","list opened files",
|
2018-01-02 04:40:55 +00:00
|
|
|
"o","-1","close file descriptor 1",
|
2019-04-14 21:06:01 +00:00
|
|
|
"o"," [file]","open [file] file in read-only",
|
|
|
|
"o"," [file] 0x4000 rwx", "map file at 0x4000",
|
|
|
|
"o.","","show current filename (or o.q/oq to get the fd)",
|
|
|
|
"o:"," [len]","open a malloc://[len] copying the bytes from current offset",
|
2018-01-02 04:40:55 +00:00
|
|
|
"o-","!*","close all opened files",
|
|
|
|
"o--","","close all files, analysis, binfiles, flags, same as !r2 --",
|
|
|
|
"o+"," [file]","open file in read-write mode",
|
2017-11-13 17:53:46 +00:00
|
|
|
"oa","[-] [A] [B] [filename]","Specify arch and bits for given file",
|
2017-08-26 01:49:54 +00:00
|
|
|
"oq","","list all open files",
|
2017-07-27 12:52:17 +00:00
|
|
|
"o*","","list opened files in r2 commands",
|
2017-08-26 01:49:54 +00:00
|
|
|
"o=","","list opened files (ascii-art bars)",
|
2017-09-02 15:36:46 +00:00
|
|
|
"ob","[?] [lbdos] [...]","list opened binary files backed by fd",
|
2017-07-27 12:52:17 +00:00
|
|
|
"oc"," [file]","open core file, like relaunching r2",
|
2018-01-02 04:40:55 +00:00
|
|
|
"of"," [file]","open file and map it at addr 0 as read-only",
|
2017-07-27 12:52:17 +00:00
|
|
|
"oi","[-|idx]","alias for o, but using index instead of fd",
|
|
|
|
"oj","[?] ","list opened files in JSON format",
|
|
|
|
"oL","","list all IO plugins registered",
|
|
|
|
"om","[?]","create, list, remove IO maps",
|
|
|
|
"on"," [file] 0x4000","map raw file at 0x4000 (no r_bin involved)",
|
2019-04-14 21:06:01 +00:00
|
|
|
"oo","[?+bcdnm]","reopen current file (see oo?) (reload in rw or debugger)",
|
2018-08-29 18:23:31 +00:00
|
|
|
"op"," [fd]", "select the given fd as current file (see also ob)",
|
2017-08-22 07:42:16 +00:00
|
|
|
"ox", " fd fdx", "exchange the descs of fd and fdx and keep the mapping",
|
2017-07-27 12:52:17 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2017-11-22 13:58:09 +00:00
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2017-07-27 12:52:17 +00:00
|
|
|
static const char *help_msg_o_star[] = {
|
|
|
|
"Usage:", "o* [> files.r2]", "",
|
|
|
|
"o*", "", "list opened files in r2 commands", NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *help_msg_oa[] = {
|
2018-11-22 10:40:31 +00:00
|
|
|
"Usage:", "oba [addr] ([filename])", " # load bininfo and update flags",
|
2017-08-26 23:05:02 +00:00
|
|
|
"oba", " [addr]", "Open bin info from the given address",
|
2019-04-18 11:02:37 +00:00
|
|
|
"oba", " [addr] [baddr]", "Open file and load bin info at given address",
|
|
|
|
"oba", " [addr] [/abs/filename]", "Open file and load bin info at given address",
|
2017-08-26 23:05:02 +00:00
|
|
|
NULL
|
2017-07-27 12:52:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char *help_msg_ob[] = {
|
|
|
|
"Usage:", "ob", " # List open binary files backed by fd",
|
|
|
|
"ob", "", "List opened binary files and objid",
|
2017-09-04 03:01:56 +00:00
|
|
|
"ob*", "", "List opened binary files and objid (r2 commands)",
|
2019-04-18 09:39:40 +00:00
|
|
|
"ob", " [fd objid]", "Switch to open binary file by fd number and objid (DEPRECATED)",
|
|
|
|
"ob", " [objid]", "Switch to open given objid",
|
2019-04-18 11:02:37 +00:00
|
|
|
"obo", " [objid]", "Switch to open binary file by objid (DEPRECATED)",
|
|
|
|
"obb", " [fd]", "Switch to open binfile by fd number (DEPRECATED)",
|
2017-08-26 23:05:02 +00:00
|
|
|
"oba", " [addr]", "Open bin info from the given address",
|
2019-04-18 11:02:37 +00:00
|
|
|
"oba", " [addr] [baddr]", "Open file and load bin info at given address",
|
2017-08-26 23:05:02 +00:00
|
|
|
"oba", " [addr] [filename]", "Open file and load bin info at given address",
|
2018-01-27 23:45:29 +00:00
|
|
|
"obf", " ([file])", "Load bininfo for current file (useful for r2 -n)",
|
2017-09-04 03:01:56 +00:00
|
|
|
"obj", "", "List opened binary files and objid (JSON format)",
|
2017-07-27 12:52:17 +00:00
|
|
|
"obr", " [baddr]", "Rebase current bin object",
|
2019-04-16 18:11:32 +00:00
|
|
|
"obL", "", "Same as iL or Li",
|
2018-01-07 17:18:54 +00:00
|
|
|
"ob-", "[objid]", "Delete binfile by binobjid",
|
|
|
|
"ob-", "*", "Delete all binfiles",
|
2017-07-27 12:52:17 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *help_msg_oj[] = {
|
|
|
|
"Usage:", "oj [~{}]", " # Use ~{} to indent the JSON",
|
|
|
|
"oj", "", "list opened files in JSON format", NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *help_msg_om[] = {
|
|
|
|
"Usage:", "om[-] [arg]", " # map opened files",
|
|
|
|
"om", "", "list all defined IO maps",
|
2017-08-26 01:49:54 +00:00
|
|
|
"omq", "", "list all maps and their fds",
|
2019-03-08 13:22:59 +00:00
|
|
|
"omqq", "", "list all maps addresses (See $MM to get the size)",
|
2017-08-23 10:18:29 +00:00
|
|
|
"om*", "", "list all maps in r2 commands format",
|
2017-08-25 23:50:57 +00:00
|
|
|
"om=", "", "list all maps in ascii art",
|
2017-08-23 10:18:29 +00:00
|
|
|
"omj", "", "list all maps in json format",
|
|
|
|
"om", " [fd]", "list all defined IO maps for a specific fd",
|
2018-08-19 14:39:42 +00:00
|
|
|
"om-", "mapid", "remove the map with corresponding id",
|
|
|
|
"om-..", "", "hud view of all the maps to select the one to delete",
|
2017-10-17 23:27:49 +00:00
|
|
|
"om", " fd vaddr [size] [paddr] [rwx] [name]", "create new io map",
|
2019-02-04 11:54:11 +00:00
|
|
|
"oma"," [fd]", "create a map covering all VA for given fd",
|
2017-09-23 00:23:26 +00:00
|
|
|
"omm"," [fd]", "create default map for given fd. (omm `oq`)",
|
2017-08-22 07:42:16 +00:00
|
|
|
"om.", "", "show map, that is mapped to current offset",
|
2018-03-12 11:33:03 +00:00
|
|
|
"omn", " mapaddr [name]", "set/delete name for map which spans mapaddr",
|
|
|
|
"omni", " mapid [name]", "set/delete name for map with mapid",
|
2017-10-04 22:40:19 +00:00
|
|
|
"omn.", "([-|name])", "show/set/delete name for current map",
|
2017-08-23 22:57:15 +00:00
|
|
|
"omf", " [mapid] rwx", "change flags/perms for current/given map",
|
2017-08-27 15:39:53 +00:00
|
|
|
"omfg", "[+-]rwx", "change flags/perms for all maps (global)",
|
2017-09-15 09:25:38 +00:00
|
|
|
"omb", " mapid addr", "relocate map with corresponding id",
|
2017-10-04 22:40:19 +00:00
|
|
|
"omb.", " addr", "relocate current map",
|
2017-09-15 09:25:38 +00:00
|
|
|
"omr", " mapid newsize", "resize map with corresponding id",
|
2018-07-08 00:53:21 +00:00
|
|
|
"omo", " fd", "map the given fd with lowest priority",
|
2018-01-27 22:31:00 +00:00
|
|
|
"omp", " mapid", "prioritize map with corresponding id",
|
2018-07-07 23:55:24 +00:00
|
|
|
"ompd", " mapid", "deprioritize map with corresponding id",
|
2019-01-13 02:07:51 +00:00
|
|
|
"ompf", " [fd]", "prioritize map by fd",
|
|
|
|
"ompb", " [fd]", "prioritize maps of the bin associated with the binid",
|
2017-07-27 12:52:17 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *help_msg_oo[] = {
|
|
|
|
"Usage:", "oo[-] [arg]", " # map opened files",
|
|
|
|
"oo", "", "reopen current file",
|
|
|
|
"oo+", "", "reopen in read-write",
|
2019-04-15 09:50:34 +00:00
|
|
|
"oob", " [baddr]", "reopen loading rbin info (change base address?)",
|
2019-04-14 21:06:01 +00:00
|
|
|
"ooc", "", "reopen core with current file",
|
2017-07-27 12:52:17 +00:00
|
|
|
"ood", "", "reopen in debug mode",
|
|
|
|
"oom", "", "reopen in malloc://",
|
|
|
|
"oon", "", "reopen without loading rbin info",
|
|
|
|
"oon+", "", "reopen in read-write mode without loading rbin info",
|
|
|
|
"oonn", "", "reopen without loading rbin info, but with header flags",
|
|
|
|
"oonn+", "", "reopen in read-write mode without loading rbin info, but with",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *help_msg_oo_plus[] = {
|
2018-03-03 16:06:06 +00:00
|
|
|
"Usage:", "oo+", " # reopen in read-write",
|
2017-07-27 12:52:17 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *help_msg_oob[] = {
|
2018-03-03 16:06:06 +00:00
|
|
|
"Usage:", "oob", " # reopen loading rbin info",
|
2017-07-27 12:52:17 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *help_msg_ood[] = {
|
2018-03-03 16:06:06 +00:00
|
|
|
"Usage:", "ood [args]", " # reopen in debugger mode (with args)",
|
2017-12-24 00:13:32 +00:00
|
|
|
"oodr"," [rarun2]","same as dor ..;ood",
|
2017-07-27 12:52:17 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *help_msg_oon[] = {
|
2018-03-03 16:06:06 +00:00
|
|
|
"Usage:", "oon", " # reopen without loading rbin info",
|
2017-07-27 12:52:17 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *help_msg_oonn[] = {
|
2018-03-03 16:06:06 +00:00
|
|
|
"Usage:", "oonn", " # reopen without loading rbin info, but with header flags",
|
2017-07-27 12:52:17 +00:00
|
|
|
NULL
|
|
|
|
};
|
2015-11-09 14:14:41 +00:00
|
|
|
|
2018-10-24 14:54:57 +00:00
|
|
|
static RBinObject *find_binfile_by_id(RBin *bin, ut32 id) {
|
2018-01-07 17:18:54 +00:00
|
|
|
RListIter *it, *it2;
|
|
|
|
RBinFile *bf;
|
|
|
|
RBinObject *obj;
|
|
|
|
r_list_foreach (bin->binfiles, it, bf) {
|
|
|
|
r_list_foreach (bf->objs, it2, obj) {
|
|
|
|
if (obj->id == id) {
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-07-27 12:52:17 +00:00
|
|
|
static void cmd_open_init(RCore *core) {
|
|
|
|
DEFINE_CMD_DESCRIPTOR (core, o);
|
|
|
|
DEFINE_CMD_DESCRIPTOR_SPECIAL (core, o*, o_star);
|
|
|
|
DEFINE_CMD_DESCRIPTOR (core, oa);
|
|
|
|
DEFINE_CMD_DESCRIPTOR (core, ob);
|
|
|
|
DEFINE_CMD_DESCRIPTOR (core, oj);
|
|
|
|
DEFINE_CMD_DESCRIPTOR (core, om);
|
|
|
|
DEFINE_CMD_DESCRIPTOR (core, oo);
|
|
|
|
DEFINE_CMD_DESCRIPTOR_SPECIAL (core, oo+, oo_plus);
|
|
|
|
DEFINE_CMD_DESCRIPTOR (core, oob);
|
|
|
|
DEFINE_CMD_DESCRIPTOR (core, ood);
|
|
|
|
DEFINE_CMD_DESCRIPTOR (core, oon);
|
|
|
|
DEFINE_CMD_DESCRIPTOR (core, oonn);
|
|
|
|
}
|
|
|
|
|
2015-02-02 23:51:20 +00:00
|
|
|
static void cmd_open_bin(RCore *core, const char *input) {
|
|
|
|
const char *value = NULL;
|
|
|
|
ut32 binfile_num = -1, binobj_num = -1;
|
|
|
|
|
|
|
|
switch (input[1]) {
|
2019-04-16 18:11:32 +00:00
|
|
|
case 'L': // "obL"
|
|
|
|
r_core_cmd0 (core, "iL");
|
|
|
|
break;
|
2017-09-04 03:01:56 +00:00
|
|
|
case '\0': // "ob"
|
2018-01-08 09:28:32 +00:00
|
|
|
case 'q': // "obj"
|
2017-09-04 03:01:56 +00:00
|
|
|
case 'j': // "obj"
|
|
|
|
case '*': // "ob*"
|
2015-02-02 23:51:20 +00:00
|
|
|
r_core_bin_list (core, input[1]);
|
|
|
|
break;
|
2017-09-04 03:01:56 +00:00
|
|
|
case 'a': // "oba"
|
2017-08-27 01:04:35 +00:00
|
|
|
if ('?' == input[2]) {
|
|
|
|
r_core_cmd_help (core, help_msg_oa);
|
|
|
|
break;
|
|
|
|
}
|
2018-01-10 11:29:15 +00:00
|
|
|
if (input[2] && input[3]) {
|
2017-08-27 01:04:35 +00:00
|
|
|
char *arg = strdup (input + 3);
|
|
|
|
char *filename = strchr (arg, ' ');
|
2019-04-18 11:02:37 +00:00
|
|
|
if (filename && *filename && (filename[1] == '/' || filename[1] == '.')) {
|
2018-11-22 11:02:00 +00:00
|
|
|
int saved_fd = r_io_fd_get_current (core->io);
|
2018-09-21 00:16:54 +00:00
|
|
|
RIODesc *desc = r_io_open (core->io, filename + 1, R_PERM_R, 0);
|
2017-08-27 01:04:35 +00:00
|
|
|
if (desc) {
|
|
|
|
*filename = 0;
|
|
|
|
ut64 addr = r_num_math (core->num, arg);
|
2018-11-07 16:22:41 +00:00
|
|
|
RBinOptions opt;
|
|
|
|
r_bin_options_init (&opt, desc->fd, addr, 0, core->bin->rawstr);
|
|
|
|
r_bin_open_io (core->bin, &opt);
|
2017-08-27 01:04:35 +00:00
|
|
|
r_io_desc_close (desc);
|
|
|
|
r_core_cmd0 (core, ".is*");
|
2018-11-22 11:02:00 +00:00
|
|
|
r_io_use_fd (core->io, saved_fd);
|
2017-08-26 23:05:02 +00:00
|
|
|
} else {
|
2017-08-27 01:04:35 +00:00
|
|
|
eprintf ("Cannot open %s\n", filename + 1);
|
2017-08-26 23:05:02 +00:00
|
|
|
}
|
2019-04-18 11:02:37 +00:00
|
|
|
} else if (filename && *filename) {
|
|
|
|
ut64 baddr = r_num_math (core->num, filename);
|
|
|
|
ut64 addr = r_num_math (core->num, input + 2); // mapaddr
|
|
|
|
int fd = r_io_fd_get_current (core->io);
|
|
|
|
RIODesc *desc = r_io_desc_get (core->io, fd);
|
|
|
|
if (desc) {
|
|
|
|
RBinOptions opt;
|
|
|
|
opt.offset = addr;
|
|
|
|
opt.baseaddr = baddr;
|
|
|
|
opt.loadaddr = addr;
|
|
|
|
opt.sz = 1024*1024*1;
|
|
|
|
r_bin_options_init (&opt, desc->fd, baddr, addr, core->bin->rawstr);
|
|
|
|
r_bin_open_io (core->bin, &opt);
|
|
|
|
r_core_cmd0 (core, ".is*");
|
|
|
|
} else {
|
|
|
|
eprintf ("No file to load bin from?\n");
|
|
|
|
}
|
2017-08-26 23:05:02 +00:00
|
|
|
} else {
|
2017-08-27 01:04:35 +00:00
|
|
|
ut64 addr = r_num_math (core->num, input + 2);
|
2018-01-10 12:45:37 +00:00
|
|
|
int fd = r_io_fd_get_current (core->io);
|
|
|
|
RIODesc *desc = r_io_desc_get (core->io, fd);
|
|
|
|
if (desc) {
|
2018-11-07 16:22:41 +00:00
|
|
|
RBinOptions opt;
|
2019-04-17 21:44:22 +00:00
|
|
|
opt.offset = addr;
|
|
|
|
opt.baseaddr = addr;
|
|
|
|
opt.loadaddr = addr;
|
|
|
|
opt.sz = 1024*1024*1;
|
|
|
|
r_bin_options_init (&opt, desc->fd, addr, addr, core->bin->rawstr);
|
2018-11-07 16:22:41 +00:00
|
|
|
r_bin_open_io (core->bin, &opt);
|
2018-01-10 12:45:37 +00:00
|
|
|
r_core_cmd0 (core, ".is*");
|
|
|
|
} else {
|
|
|
|
eprintf ("No file to load bin from?\n");
|
2017-08-26 23:05:02 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-27 01:04:35 +00:00
|
|
|
free (arg);
|
|
|
|
} else {
|
2018-01-10 12:45:37 +00:00
|
|
|
RList *files = r_id_storage_list (core->io->files);
|
2017-08-27 01:04:35 +00:00
|
|
|
RIODesc *desc;
|
|
|
|
RListIter *iter;
|
2018-01-10 12:45:37 +00:00
|
|
|
r_list_foreach (files, iter, desc) {
|
2018-11-07 16:22:41 +00:00
|
|
|
RBinOptions opt;
|
|
|
|
r_bin_options_init (&opt, desc->fd, core->offset, 0, core->bin->rawstr);
|
|
|
|
r_bin_open_io (core->bin, &opt);
|
2019-04-18 11:02:37 +00:00
|
|
|
r_core_cmd0 (core, ".ies*");
|
2017-08-27 01:04:35 +00:00
|
|
|
break;
|
2017-08-26 23:05:02 +00:00
|
|
|
}
|
2018-01-10 12:45:37 +00:00
|
|
|
r_list_free (files);
|
2017-08-27 01:04:35 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'b': // "obb"
|
|
|
|
{
|
|
|
|
ut32 fd;
|
2018-04-05 08:49:25 +00:00
|
|
|
if (input[2] && input[3]) {
|
|
|
|
value = *(input + 3) ? input + 3 : NULL;
|
|
|
|
} else {
|
|
|
|
value = NULL;
|
|
|
|
}
|
2017-08-27 01:04:35 +00:00
|
|
|
if (!value) {
|
|
|
|
eprintf ("Invalid fd number.");
|
|
|
|
break;
|
|
|
|
}
|
2018-11-13 12:05:18 +00:00
|
|
|
fd = *value && r_is_valid_input_num_value (core->num, value)? r_get_input_num_value (core->num, value): UT32_MAX;
|
|
|
|
RBinFile *bf = r_bin_file_find_by_fd (core->bin, fd);
|
|
|
|
if (!bf) {
|
2017-08-27 01:04:35 +00:00
|
|
|
eprintf ("Invalid fd number.");
|
|
|
|
break;
|
|
|
|
}
|
2018-11-13 12:05:18 +00:00
|
|
|
r_core_bin_raise (core, bf->id, -1);
|
|
|
|
} break;
|
2017-09-04 03:01:56 +00:00
|
|
|
case ' ': // "ob "
|
2015-11-09 14:14:41 +00:00
|
|
|
{
|
|
|
|
ut32 fd;
|
|
|
|
int n;
|
|
|
|
const char *tmp;
|
|
|
|
char *v;
|
|
|
|
v = input[2] ? strdup (input + 2) : NULL;
|
|
|
|
if (!v) {
|
|
|
|
eprintf ("Invalid arguments");
|
2015-02-02 23:51:20 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-11-09 14:14:41 +00:00
|
|
|
n = r_str_word_set0 (v);
|
2017-10-20 00:38:04 +00:00
|
|
|
if (n < 1 || n > 2) {
|
2015-11-09 14:14:41 +00:00
|
|
|
eprintf ("Invalid arguments\n");
|
|
|
|
eprintf ("usage: ob fd obj\n");
|
|
|
|
free (v);
|
2015-02-02 23:51:20 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-11-09 14:14:41 +00:00
|
|
|
tmp = r_str_word_get0 (v, 0);
|
2019-04-18 09:39:40 +00:00
|
|
|
fd = *v && r_is_valid_input_num_value (core->num, tmp)
|
|
|
|
? r_get_input_num_value (core->num, tmp): UT32_MAX;
|
2017-10-20 00:38:04 +00:00
|
|
|
if (n == 2) {
|
|
|
|
tmp = r_str_word_get0 (v, 1);
|
2019-04-18 09:39:40 +00:00
|
|
|
binobj_num = *v && r_is_valid_input_num_value (core->num, tmp)
|
|
|
|
? r_get_input_num_value (core->num, tmp): UT32_MAX;
|
2017-10-20 00:38:04 +00:00
|
|
|
} else {
|
2019-04-18 09:39:40 +00:00
|
|
|
RBinFile *bf = r_bin_file_find_by_object_id (core->bin, fd);
|
|
|
|
binfile_num = fd;
|
|
|
|
binobj_num = bf? bf->id: UT32_MAX;
|
2017-10-20 00:38:04 +00:00
|
|
|
}
|
2015-11-09 14:14:41 +00:00
|
|
|
r_core_bin_raise (core, binfile_num, binobj_num);
|
|
|
|
free (v);
|
2015-02-02 23:51:20 +00:00
|
|
|
break;
|
2015-11-09 14:14:41 +00:00
|
|
|
}
|
2017-09-04 03:01:56 +00:00
|
|
|
case 'r': // "obr"
|
2017-03-18 20:40:01 +00:00
|
|
|
r_core_bin_rebase (core, r_num_math (core->num, input + 3));
|
|
|
|
r_core_cmd0 (core, ".is*");
|
|
|
|
break;
|
2018-01-27 23:45:29 +00:00
|
|
|
case 'f':
|
2018-05-22 15:48:34 +00:00
|
|
|
if (input[2] == ' ') {
|
|
|
|
r_core_cmdf (core, "oba 0 %s", input + 3);
|
|
|
|
} else {
|
|
|
|
r_core_bin_load (core, NULL, UT64_MAX);
|
|
|
|
value = input[2] ? input + 2 : NULL;
|
|
|
|
}
|
2018-01-27 23:45:29 +00:00
|
|
|
break;
|
2017-09-04 03:01:56 +00:00
|
|
|
case 'o': // "obo"
|
2018-01-27 23:45:29 +00:00
|
|
|
value = input[2] ? input + 2 : NULL;
|
2015-02-02 23:51:20 +00:00
|
|
|
if (!value) {
|
2015-11-09 14:14:41 +00:00
|
|
|
eprintf ("Invalid argument");
|
2015-02-02 23:51:20 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-01-27 23:45:29 +00:00
|
|
|
if (*value == ' ') value ++;
|
2015-11-09 14:14:41 +00:00
|
|
|
binobj_num = *value && r_is_valid_input_num_value (core->num, value) ?
|
|
|
|
r_get_input_num_value (core->num, value) : UT32_MAX;
|
2015-02-02 23:51:20 +00:00
|
|
|
if (binobj_num == UT32_MAX) {
|
2015-11-09 14:14:41 +00:00
|
|
|
eprintf ("Invalid binobj_num");
|
2015-02-02 23:51:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
r_core_bin_raise (core, -1, binobj_num);
|
|
|
|
break;
|
|
|
|
case '-': // "ob-"
|
|
|
|
if (input[2] == '*') {
|
2018-01-07 17:18:54 +00:00
|
|
|
r_bin_file_delete_all (core->bin);
|
2015-02-02 23:51:20 +00:00
|
|
|
} else {
|
2015-11-09 14:14:41 +00:00
|
|
|
ut32 fd;
|
2018-01-08 02:29:29 +00:00
|
|
|
value = r_str_trim_ro (input + 2);
|
2015-11-09 14:14:41 +00:00
|
|
|
if (!value) {
|
|
|
|
eprintf ("Invalid argument\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fd = *value && r_is_valid_input_num_value (core->num, value) ?
|
|
|
|
r_get_input_num_value (core->num, value) : UT32_MAX;
|
2018-01-07 17:18:54 +00:00
|
|
|
RBinObject *bo = find_binfile_by_id (core->bin, fd);
|
|
|
|
if (!bo) {
|
|
|
|
eprintf ("Invalid binid\n");
|
2015-11-09 14:14:41 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-01-07 17:18:54 +00:00
|
|
|
if (r_core_bin_delete (core, binfile_num, bo->id)) {
|
|
|
|
if (!r_bin_file_delete (core->bin, fd)) {
|
2016-01-04 01:19:02 +00:00
|
|
|
eprintf ("Cannot find an RBinFile associated with that fd.\n");
|
2018-01-07 17:18:54 +00:00
|
|
|
}
|
2015-02-02 23:51:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2017-09-04 03:01:56 +00:00
|
|
|
case '?': // "ob?"
|
2017-07-27 12:52:17 +00:00
|
|
|
r_core_cmd_help (core, help_msg_ob);
|
2015-02-02 23:51:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-23 10:18:29 +00:00
|
|
|
// TODO: discuss the output format
|
|
|
|
static void map_list(RIO *io, int mode, RPrint *print, int fd) {
|
2017-08-22 07:42:16 +00:00
|
|
|
SdbListIter *iter;
|
|
|
|
RIOMap *map;
|
|
|
|
if (!io || !io->maps || !print || !print->cb_printf) {
|
|
|
|
return;
|
|
|
|
}
|
2017-08-23 10:18:29 +00:00
|
|
|
if (mode == 'j') {
|
|
|
|
print->cb_printf ("[");
|
|
|
|
}
|
|
|
|
bool first = true;
|
2017-10-17 23:27:49 +00:00
|
|
|
ls_foreach_prev (io->maps, iter, map) { //this must be prev
|
2019-03-08 13:22:59 +00:00
|
|
|
if (fd >= 0 && map->fd != fd) {
|
2017-08-23 10:18:29 +00:00
|
|
|
continue;
|
|
|
|
}
|
2017-08-22 07:42:16 +00:00
|
|
|
switch (mode) {
|
2017-08-26 01:49:54 +00:00
|
|
|
case 'q':
|
2019-03-08 13:22:59 +00:00
|
|
|
if (fd == -2) {
|
|
|
|
print->cb_printf ("0x%08"PFMT64x"\n", map->itv.addr);
|
|
|
|
} else {
|
|
|
|
print->cb_printf ("%d %d\n", map->fd, map->id);
|
|
|
|
}
|
2017-08-26 01:49:54 +00:00
|
|
|
break;
|
2017-08-23 10:18:29 +00:00
|
|
|
case 'j':
|
2017-08-23 10:55:10 +00:00
|
|
|
if (!first) {
|
|
|
|
print->cb_printf (",");
|
|
|
|
}
|
|
|
|
first = false;
|
2017-09-14 08:20:26 +00:00
|
|
|
print->cb_printf ("{\"map\":%i,\"fd\":%d,\"delta\":%"PFMT64u",\"from\":%"PFMT64u
|
2018-09-21 00:16:54 +00:00
|
|
|
",\"to\":%"PFMT64u",\"perm\":\"%s\",\"name\":\"%s\"}", map->id, map->fd,
|
2017-09-01 06:41:03 +00:00
|
|
|
map->delta, map->itv.addr, r_itv_end (map->itv),
|
2018-09-21 00:16:54 +00:00
|
|
|
r_str_rwx_i (map->perm), (map->name ? map->name : ""));
|
2017-08-23 10:18:29 +00:00
|
|
|
break;
|
2017-08-22 07:42:16 +00:00
|
|
|
case 1:
|
2017-08-23 10:18:29 +00:00
|
|
|
case '*':
|
2017-08-22 07:42:16 +00:00
|
|
|
case 'r':
|
2018-10-30 11:36:01 +00:00
|
|
|
print->cb_printf ("om %d 0x%08"PFMT64x" 0x%08"PFMT64x" 0x%08"PFMT64x" %s%s%s\n", map->fd,
|
2018-09-21 00:16:54 +00:00
|
|
|
map->itv.addr, map->itv.size, map->delta, r_str_rwx_i(map->perm),
|
2017-10-17 23:27:49 +00:00
|
|
|
map->name ? " " : "", map->name ? map->name : "");
|
2017-08-22 07:42:16 +00:00
|
|
|
break;
|
|
|
|
default:
|
2017-08-26 10:21:01 +00:00
|
|
|
print->cb_printf ("%2d fd: %i +0x%08"PFMT64x" 0x%08"PFMT64x
|
|
|
|
" - 0x%08"PFMT64x" %s %s\n", map->id, map->fd,
|
2017-10-17 23:27:49 +00:00
|
|
|
map->delta, map->itv.addr, r_itv_end (map->itv) - 1,
|
2018-09-21 00:16:54 +00:00
|
|
|
r_str_rwx_i (map->perm), (map->name ? map->name : ""));
|
2017-08-23 10:18:29 +00:00
|
|
|
break;
|
2017-08-22 07:42:16 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-23 10:18:29 +00:00
|
|
|
if (mode == 'j') {
|
|
|
|
print->cb_printf ("]\n");
|
|
|
|
}
|
2017-08-22 07:42:16 +00:00
|
|
|
}
|
|
|
|
|
2018-10-24 14:54:57 +00:00
|
|
|
static void cmd_omfg(RCore *core, const char *input) {
|
2017-08-23 22:57:15 +00:00
|
|
|
SdbListIter *iter;
|
|
|
|
RIOMap *map;
|
2018-01-08 02:29:29 +00:00
|
|
|
input = r_str_trim_ro (input);
|
2017-08-27 15:39:53 +00:00
|
|
|
if (input) {
|
2018-09-21 00:16:54 +00:00
|
|
|
int perm = *input
|
2017-08-27 15:39:53 +00:00
|
|
|
? (*input == '+' || *input == '-')
|
|
|
|
? r_str_rwx (input + 1)
|
|
|
|
: r_str_rwx (input)
|
|
|
|
: 7;
|
|
|
|
switch (*input) {
|
|
|
|
case '+':
|
|
|
|
ls_foreach (core->io->maps, iter, map) {
|
2018-09-21 00:16:54 +00:00
|
|
|
map->perm |= perm;
|
2017-08-27 15:39:53 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
ls_foreach (core->io->maps, iter, map) {
|
2018-09-21 00:16:54 +00:00
|
|
|
map->perm &= ~perm;
|
2017-08-27 15:39:53 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ls_foreach (core->io->maps, iter, map) {
|
2018-09-21 00:16:54 +00:00
|
|
|
map->perm = perm;
|
2017-08-27 15:39:53 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-08-23 22:57:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-24 14:54:57 +00:00
|
|
|
static void cmd_omf(RCore *core, const char *input) {
|
2017-08-23 22:57:15 +00:00
|
|
|
SdbListIter *iter;
|
|
|
|
RIOMap *map;
|
2018-01-08 02:29:29 +00:00
|
|
|
char *arg = strdup (r_str_trim_ro (input));
|
2017-08-23 22:57:15 +00:00
|
|
|
if (!arg) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
char *sp = strchr (arg, ' ');
|
|
|
|
if (sp) {
|
|
|
|
// change perms of Nth map
|
|
|
|
*sp++ = 0;
|
2017-08-23 23:33:44 +00:00
|
|
|
int id = r_num_math (core->num, arg);
|
2018-09-21 00:16:54 +00:00
|
|
|
int perm = (*sp)? r_str_rwx (sp): R_PERM_RWX;
|
2017-08-23 22:57:15 +00:00
|
|
|
ls_foreach (core->io->maps, iter, map) {
|
2017-08-23 23:33:44 +00:00
|
|
|
if (map->id == id) {
|
2018-09-21 00:16:54 +00:00
|
|
|
map->perm = perm;
|
2017-08-23 22:57:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// change perms of current map
|
2018-09-21 00:16:54 +00:00
|
|
|
int perm = (arg && *arg)? r_str_rwx (arg): R_PERM_RWX;
|
2017-08-23 22:57:15 +00:00
|
|
|
ls_foreach (core->io->maps, iter, map) {
|
2017-09-01 06:41:03 +00:00
|
|
|
if (r_itv_contain (map->itv, core->offset)) {
|
2018-09-21 00:16:54 +00:00
|
|
|
map->perm = perm;
|
2017-08-23 22:57:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free (arg);
|
|
|
|
}
|
|
|
|
|
2017-09-04 20:05:59 +00:00
|
|
|
static void cmd_open_map(RCore *core, const char *input) {
|
2015-02-02 23:51:20 +00:00
|
|
|
ut64 fd = 0LL;
|
2017-08-22 07:42:16 +00:00
|
|
|
ut32 id = 0;
|
2018-03-12 11:33:03 +00:00
|
|
|
ut64 addr = 0;
|
2017-09-05 08:16:04 +00:00
|
|
|
char *s = NULL, *p = NULL, *q = NULL;
|
2017-08-22 07:42:16 +00:00
|
|
|
ut64 new;
|
2015-02-02 23:51:20 +00:00
|
|
|
RIOMap *map = NULL;
|
|
|
|
const char *P;
|
|
|
|
|
|
|
|
switch (input[1]) {
|
2017-08-22 07:42:16 +00:00
|
|
|
case '.':
|
2017-09-01 06:41:03 +00:00
|
|
|
map = r_io_map_get (core->io, core->offset);
|
2017-08-23 19:38:25 +00:00
|
|
|
if (map) {
|
|
|
|
core->print->cb_printf ("map: %i fd: %i +0x%"PFMT64x" 0x%"PFMT64x
|
2017-09-01 06:41:03 +00:00
|
|
|
" - 0x%"PFMT64x" ; %s : %s\n", map->id, map->fd,
|
|
|
|
map->delta, map->itv.addr, r_itv_end (map->itv),
|
2018-09-21 00:16:54 +00:00
|
|
|
r_str_rwx_i (map->perm), map->name ? map->name : "");
|
2017-08-23 19:38:25 +00:00
|
|
|
}
|
2017-08-22 07:42:16 +00:00
|
|
|
break;
|
2017-09-15 09:25:38 +00:00
|
|
|
case 'r': // "omr"
|
|
|
|
if (input[2] != ' ') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
P = strchr (input+3, ' ');
|
|
|
|
if (P) {
|
|
|
|
id = (ut32)r_num_math (core->num, input+3); //mapid
|
|
|
|
new = r_num_math (core->num, P+1);
|
|
|
|
r_io_map_resize (core->io, id, new);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'b': // "omb"
|
2017-10-04 22:40:19 +00:00
|
|
|
if (input[2] == '.') {
|
|
|
|
RIOMap *map = r_io_map_get (core->io, core->offset);
|
|
|
|
if (map) {
|
|
|
|
ut64 dst = r_num_math (core->num, input + 3);
|
|
|
|
r_io_map_remap (core->io, map->id, dst);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (input[2] != ' ') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
P = strchr (input + 3, ' ');
|
|
|
|
if (P) {
|
|
|
|
id = (ut32)r_num_math (core->num, input+3); //mapid
|
|
|
|
new = r_num_math (core->num, P + 1);
|
|
|
|
r_io_map_remap (core->io, id, new);
|
|
|
|
}
|
2017-08-22 07:42:16 +00:00
|
|
|
}
|
|
|
|
break;
|
2018-07-08 00:53:21 +00:00
|
|
|
case 'o': // "omo"
|
|
|
|
if (input[2] == ' ') {
|
|
|
|
r_core_cmdf (core, "om %s 0x%08" PFMT64x " $s r omo", input + 2);
|
|
|
|
} else {
|
|
|
|
r_core_cmd0 (core, "om `oq.` $B $s r");
|
|
|
|
}
|
2018-07-08 21:11:37 +00:00
|
|
|
r_core_cmd0 (core, "ompd `omq.`");
|
2018-07-08 00:53:21 +00:00
|
|
|
break;
|
2017-08-23 22:57:15 +00:00
|
|
|
case 'p':
|
|
|
|
switch (input[2]) {
|
2018-07-07 23:55:24 +00:00
|
|
|
case 'd': // "ompf"
|
|
|
|
id = r_num_math (core->num, input + 3); //mapid
|
|
|
|
if (r_io_map_exists_for_id (core->io, id)) {
|
|
|
|
r_io_map_depriorize (core->io, id);
|
|
|
|
} else {
|
|
|
|
eprintf ("Cannot find any map with mapid %d\n", id);
|
|
|
|
}
|
|
|
|
break;
|
2017-08-23 22:57:15 +00:00
|
|
|
case 'f': // "ompf"
|
|
|
|
fd = r_num_math (core->num, input + 3);
|
|
|
|
if (!r_io_map_priorize_for_fd (core->io, (int)fd)) {
|
2018-01-27 22:31:00 +00:00
|
|
|
eprintf ("Cannot prioritize any map for fd %d\n", (int)fd);
|
2017-08-23 22:57:15 +00:00
|
|
|
}
|
2017-08-22 07:42:16 +00:00
|
|
|
break;
|
2017-08-23 22:57:15 +00:00
|
|
|
case 'b': // "ompb"
|
|
|
|
id = (ut32)r_num_math (core->num, input + 4);
|
2019-01-13 02:07:51 +00:00
|
|
|
if (!r_bin_file_set_cur_by_id (core->bin, id)) {
|
|
|
|
eprintf ("Cannot prioritize bin with fd %d\n", id);
|
2017-08-23 22:57:15 +00:00
|
|
|
}
|
2017-08-22 07:42:16 +00:00
|
|
|
break;
|
2017-08-23 22:57:15 +00:00
|
|
|
case ' ': // "omp"
|
|
|
|
id = r_num_math (core->num, input + 3); //mapid
|
|
|
|
if (r_io_map_exists_for_id (core->io, id)) {
|
|
|
|
r_io_map_priorize (core->io, id);
|
2018-08-25 05:22:06 +00:00
|
|
|
r_core_block_read (core);
|
2017-08-23 22:57:15 +00:00
|
|
|
} else {
|
|
|
|
eprintf ("Cannot find any map with mapid %d\n", id);
|
|
|
|
}
|
2017-08-22 07:42:16 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-02-02 23:51:20 +00:00
|
|
|
break;
|
2017-08-26 21:29:30 +00:00
|
|
|
case ' ': // "om"
|
2017-08-19 18:05:21 +00:00
|
|
|
s = strdup (input + 2);
|
|
|
|
if (!s) {
|
|
|
|
break;
|
|
|
|
}
|
2017-09-04 20:05:59 +00:00
|
|
|
if (strchr (s, ' ')) {
|
2018-01-27 22:30:03 +00:00
|
|
|
int fd = 0, rwx = 0;
|
2017-09-04 20:05:59 +00:00
|
|
|
ut64 size = 0, vaddr = 0, paddr = 0;
|
|
|
|
const char *name = NULL;
|
2017-10-17 23:27:49 +00:00
|
|
|
bool rwx_arg = false;
|
2017-09-04 20:05:59 +00:00
|
|
|
RIODesc *desc = NULL;
|
2018-01-27 22:30:03 +00:00
|
|
|
int words = r_str_word_set0 (s);
|
2017-09-04 20:05:59 +00:00
|
|
|
switch (words) {
|
2017-10-17 23:27:49 +00:00
|
|
|
case 6:
|
|
|
|
name = r_str_word_get0 (s, 5);
|
|
|
|
case 5: //this sucks
|
|
|
|
rwx = r_str_rwx (r_str_word_get0 (s, 4));
|
|
|
|
rwx_arg = true;
|
2017-09-04 20:05:59 +00:00
|
|
|
case 4:
|
|
|
|
paddr = r_num_math (core->num, r_str_word_get0 (s, 3));
|
|
|
|
case 3:
|
|
|
|
size = r_num_math (core->num, r_str_word_get0 (s, 2));
|
|
|
|
case 2:
|
|
|
|
vaddr = r_num_math (core->num, r_str_word_get0 (s, 1));
|
|
|
|
case 1:
|
|
|
|
fd = r_num_math (core->num, r_str_word_get0 (s, 0));
|
|
|
|
}
|
|
|
|
if (fd < 3) {
|
|
|
|
eprintf ("wrong fd, it must be greater than 3\n");
|
2017-08-22 07:42:16 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-09-04 20:05:59 +00:00
|
|
|
desc = r_io_desc_get (core->io, fd);
|
|
|
|
if (desc) {
|
|
|
|
if (!size) {
|
|
|
|
size = r_io_fd_size (core->io, fd);
|
2017-08-18 18:03:29 +00:00
|
|
|
}
|
2018-09-21 00:16:54 +00:00
|
|
|
map = r_io_map_add (core->io, fd, rwx_arg ? rwx : desc->perm, paddr, vaddr, size);
|
2017-09-04 20:05:59 +00:00
|
|
|
r_io_map_set_name (map, name);
|
2017-08-27 21:13:48 +00:00
|
|
|
}
|
2017-08-18 18:03:29 +00:00
|
|
|
} else {
|
2017-09-04 20:05:59 +00:00
|
|
|
int fd = r_io_fd_get_current (core->io);
|
2017-08-26 21:29:30 +00:00
|
|
|
if (r_io_desc_get (core->io, fd)) {
|
2017-09-04 20:05:59 +00:00
|
|
|
map_list (core->io, 0, core->print, fd);
|
2017-08-26 21:29:30 +00:00
|
|
|
} else {
|
|
|
|
eprintf ("Invalid fd %d\n", (int)fd);
|
|
|
|
}
|
2017-08-18 18:03:29 +00:00
|
|
|
}
|
2017-09-05 05:06:38 +00:00
|
|
|
R_FREE (s);
|
2015-02-02 23:51:20 +00:00
|
|
|
break;
|
2017-10-04 22:40:19 +00:00
|
|
|
case 'n': // "omn"
|
|
|
|
if (input[2] == '.') { // "omn."
|
|
|
|
RIOMap *map = r_io_map_get (core->io, core->offset);
|
|
|
|
if (map) {
|
|
|
|
switch (input[3]) {
|
|
|
|
case '-':
|
|
|
|
r_io_map_del_name (map);
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
r_cons_printf ("%s\n", map->name);
|
|
|
|
break;
|
|
|
|
default:
|
2018-10-27 03:01:09 +00:00
|
|
|
r_io_map_set_name (map, r_str_trim_ro (input + 3));
|
2017-10-04 22:40:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2018-03-12 11:33:03 +00:00
|
|
|
bool use_id = (input[2] == 'i') ? true : false;
|
|
|
|
s = strdup ( use_id ? &input[3] : &input[2]);
|
|
|
|
if (!s) {
|
2017-10-04 22:40:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
p = s;
|
2018-03-12 11:33:03 +00:00
|
|
|
|
2017-10-04 22:40:19 +00:00
|
|
|
while (*s == ' ') {
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
if (*s == '\0') {
|
|
|
|
s = p;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!(q = strchr (s, ' '))) {
|
2018-03-12 11:33:03 +00:00
|
|
|
if (use_id) {
|
|
|
|
id = (ut32)r_num_math (core->num, s);
|
|
|
|
map = r_io_map_resolve (core->io, id);
|
|
|
|
} else {
|
|
|
|
addr = r_num_math (core->num, s);
|
|
|
|
map = r_io_map_get (core->io, addr);
|
|
|
|
}
|
2017-10-04 22:40:19 +00:00
|
|
|
r_io_map_del_name (map);
|
|
|
|
s = p;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*q = '\0';
|
|
|
|
q++;
|
2018-03-12 11:33:03 +00:00
|
|
|
if (use_id) {
|
|
|
|
id = (ut32)r_num_math (core->num, s);
|
|
|
|
map = r_io_map_resolve (core->io, id);
|
|
|
|
} else {
|
|
|
|
addr = r_num_math (core->num, s);
|
|
|
|
map = r_io_map_get (core->io, addr);
|
|
|
|
}
|
2017-10-04 22:40:19 +00:00
|
|
|
if (*q) {
|
|
|
|
r_io_map_set_name (map, q);
|
|
|
|
} else {
|
|
|
|
r_io_map_del_name (map);
|
|
|
|
}
|
2017-09-15 14:00:15 +00:00
|
|
|
s = p;
|
2017-08-26 17:27:45 +00:00
|
|
|
}
|
|
|
|
break;
|
2019-02-04 11:54:11 +00:00
|
|
|
case 'a': // "oma"
|
|
|
|
{
|
|
|
|
ut32 fd = input[2]? r_num_math (core->num, input + 2): r_io_fd_get_current (core->io);
|
|
|
|
RIODesc *desc = r_io_desc_get (core->io, fd);
|
|
|
|
if (desc) {
|
|
|
|
map = r_io_map_add (core->io, fd, desc->perm, 0, 0, UT64_MAX);
|
|
|
|
r_io_map_set_name (map, desc->name);
|
|
|
|
} else {
|
|
|
|
eprintf ("Usage: omm [fd]\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2017-09-12 22:23:26 +00:00
|
|
|
case 'm': // "omm"
|
|
|
|
{
|
2018-07-08 00:53:21 +00:00
|
|
|
ut32 fd = input[2]? r_num_math (core->num, input + 2): r_io_fd_get_current (core->io);
|
2017-09-12 22:23:26 +00:00
|
|
|
RIODesc *desc = r_io_desc_get (core->io, fd);
|
|
|
|
if (desc) {
|
|
|
|
ut64 size = r_io_desc_size (desc);
|
2018-09-21 00:16:54 +00:00
|
|
|
map = r_io_map_add (core->io, fd, desc->perm, 0, 0, size);
|
2017-09-12 22:23:26 +00:00
|
|
|
r_io_map_set_name (map, desc->name);
|
|
|
|
} else {
|
|
|
|
eprintf ("Usage: omm [fd]\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '-': // "om-"
|
2018-08-19 14:39:42 +00:00
|
|
|
if (!strcmp (input + 2, "..")) {
|
|
|
|
r_core_cmd0 (core, "om-`om~...`~[0]");
|
|
|
|
} else if (input[2] == '*') {
|
2017-09-12 22:23:26 +00:00
|
|
|
r_io_map_reset (core->io);
|
|
|
|
} else {
|
|
|
|
r_io_map_del (core->io, r_num_math (core->num, input + 2));
|
|
|
|
}
|
2015-02-02 23:51:20 +00:00
|
|
|
break;
|
2017-08-23 22:57:15 +00:00
|
|
|
case 'f': // "omf"
|
|
|
|
switch (input[2]) {
|
|
|
|
case 'g': // "omfg"
|
|
|
|
cmd_omfg (core, input + 3);
|
|
|
|
break;
|
|
|
|
case ' ': // "omf"
|
|
|
|
cmd_omf (core, input + 3);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
r_core_cmd_help (core, help_msg_om);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '\0': // "om"
|
|
|
|
case 'j': // "omj"
|
|
|
|
case '*': // "om*"
|
2017-08-26 01:49:54 +00:00
|
|
|
case 'q': // "omq"
|
2018-07-08 21:11:37 +00:00
|
|
|
if (input[1] && input[2] == '.') {
|
2018-07-08 00:05:01 +00:00
|
|
|
map = r_io_map_get (core->io, core->offset);
|
|
|
|
if (map) {
|
|
|
|
core->print->cb_printf ("%i\n", map->id);
|
|
|
|
}
|
|
|
|
} else {
|
2019-03-12 19:10:45 +00:00
|
|
|
if (input[1] && input[2] == 'q') { // "omqq"
|
2019-03-08 13:22:59 +00:00
|
|
|
map_list (core->io, input[1], core->print, -2);
|
|
|
|
} else {
|
|
|
|
map_list (core->io, input[1], core->print, -1);
|
|
|
|
}
|
2018-07-08 00:05:01 +00:00
|
|
|
}
|
2015-02-02 23:51:20 +00:00
|
|
|
break;
|
2019-04-09 06:07:17 +00:00
|
|
|
case '=': // "om="
|
|
|
|
{
|
|
|
|
RList *list = r_list_new ();
|
|
|
|
if (!list) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SdbListIter *iter;
|
|
|
|
RIOMap *map;
|
|
|
|
ls_foreach_prev (core->io->maps, iter, map) {
|
|
|
|
char temp[4];
|
|
|
|
ListInfo *info = R_NEW (ListInfo);
|
|
|
|
if (!info) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
info->name = map->name;
|
|
|
|
info->pitv = map->itv;
|
|
|
|
info->vitv = map->itv;
|
|
|
|
info->perm = map->perm;
|
|
|
|
info->extra = sdb_itoa (map->fd, temp, 10);
|
|
|
|
r_list_append (list, info);
|
|
|
|
}
|
|
|
|
r_core_visual_list (core, list, core->offset, core->blocksize,
|
2017-08-25 23:50:57 +00:00
|
|
|
r_cons_get_size (NULL), r_config_get_i (core->config, "scr.color"));
|
2019-04-09 06:07:17 +00:00
|
|
|
r_list_free (list);
|
|
|
|
} break;
|
2015-02-02 23:51:20 +00:00
|
|
|
default:
|
|
|
|
case '?':
|
2017-07-27 12:52:17 +00:00
|
|
|
r_core_cmd_help (core, help_msg_om);
|
2015-11-12 09:33:20 +00:00
|
|
|
break;
|
2015-02-02 23:51:20 +00:00
|
|
|
}
|
2017-09-05 05:06:38 +00:00
|
|
|
R_FREE (s);
|
2016-08-15 18:56:23 +00:00
|
|
|
r_core_block_read (core);
|
2015-02-02 23:51:20 +00:00
|
|
|
}
|
2017-01-09 16:40:58 +00:00
|
|
|
|
2018-05-16 10:12:12 +00:00
|
|
|
static bool reopen_in_malloc_cb(void *user, void *data, ut32 id) {
|
|
|
|
RIO *io = (RIO *)user;
|
|
|
|
RIODesc *desc = (RIODesc *)data;
|
|
|
|
|
|
|
|
if (r_io_desc_is_blockdevice (desc) || r_io_desc_is_dbg (desc)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strstr (desc->uri, "://")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ut64 size = r_io_desc_size (desc);
|
|
|
|
|
|
|
|
char *uri = r_str_newf ("malloc://%"PFMT64u, size);
|
|
|
|
if (!uri) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ut8 *buf = malloc (size);
|
|
|
|
// if malloc fails, we can just abort the loop by returning false
|
|
|
|
if (!buf) {
|
|
|
|
free (uri);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-21 00:16:54 +00:00
|
|
|
RIODesc *ndesc = r_io_open_nomap (io, uri, R_PERM_RW, 0);
|
2018-05-16 10:12:12 +00:00
|
|
|
free (uri);
|
|
|
|
if (!ndesc) {
|
2016-09-19 15:34:22 +00:00
|
|
|
free (buf);
|
2018-05-16 10:12:12 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
r_io_desc_read_at (desc, 0LL, buf, (int)size); //that cast o_O
|
|
|
|
r_io_desc_write_at (ndesc, 0LL, buf, (int)size);
|
|
|
|
free (buf);
|
|
|
|
r_io_desc_exchange (io, desc->fd, ndesc->fd);
|
|
|
|
|
|
|
|
r_io_desc_close (desc);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-10-24 14:54:57 +00:00
|
|
|
R_API void r_core_file_reopen_in_malloc(RCore *core) {
|
2018-05-16 10:12:12 +00:00
|
|
|
if (core && core->io && core->io->files) {
|
|
|
|
r_id_storage_foreach (core->io->files, reopen_in_malloc_cb, core->io);
|
2016-09-19 14:34:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-24 14:54:57 +00:00
|
|
|
R_API void r_core_file_reopen_debug(RCore *core, const char *args) {
|
2015-09-30 11:10:49 +00:00
|
|
|
RCoreFile *ofile = core->file;
|
2017-08-22 07:42:16 +00:00
|
|
|
RIODesc *desc;
|
|
|
|
if (!ofile || !(desc = r_io_desc_get (core->io, ofile->fd)) || !desc->uri) {
|
2015-08-28 23:41:34 +00:00
|
|
|
eprintf ("No file open?\n");
|
|
|
|
return;
|
|
|
|
}
|
2019-03-16 19:46:11 +00:00
|
|
|
RBinFile *bf = r_bin_file_find_by_fd (core->bin, ofile->fd);
|
|
|
|
char *binpath = (bf && bf->file) ? strdup (bf->file) : NULL;
|
2015-11-26 11:55:47 +00:00
|
|
|
if (!binpath) {
|
2017-08-22 07:42:16 +00:00
|
|
|
if (r_file_exists (desc->name)) {
|
|
|
|
binpath = strdup (desc->name);
|
2016-10-15 19:08:54 +00:00
|
|
|
}
|
2015-11-26 11:55:47 +00:00
|
|
|
}
|
2015-09-30 11:10:49 +00:00
|
|
|
if (!binpath) {
|
2016-10-15 19:08:54 +00:00
|
|
|
/* fallback to oo */
|
2016-10-15 21:42:12 +00:00
|
|
|
(void)r_core_cmd0 (core, "oo");
|
|
|
|
return;
|
2015-08-28 23:41:34 +00:00
|
|
|
}
|
2015-09-30 11:10:49 +00:00
|
|
|
int bits = core->assembler->bits;
|
2018-11-15 11:22:54 +00:00
|
|
|
char *bin_abspath = r_file_abspath (binpath);
|
|
|
|
char *escaped_path = r_str_arg_escape (bin_abspath);
|
2018-11-03 18:57:05 +00:00
|
|
|
char *newfile = r_str_newf ("dbg://%s %s", escaped_path, args);
|
2015-11-05 12:38:58 +00:00
|
|
|
char *newfile2 = strdup (newfile);
|
2017-08-22 07:42:16 +00:00
|
|
|
desc->uri = newfile;
|
|
|
|
desc->referer = NULL;
|
2015-09-30 11:10:49 +00:00
|
|
|
r_config_set_i (core->config, "asm.bits", bits);
|
|
|
|
r_config_set_i (core->config, "cfg.debug", true);
|
2016-12-21 08:07:58 +00:00
|
|
|
r_core_file_reopen (core, newfile, 0, 2);
|
2015-11-05 12:38:58 +00:00
|
|
|
newfile = newfile2;
|
2016-12-21 08:07:58 +00:00
|
|
|
#if !__WINDOWS__
|
2017-06-14 06:48:46 +00:00
|
|
|
ut64 new_baddr = r_debug_get_baddr (core->dbg, newfile);
|
2015-10-19 08:33:06 +00:00
|
|
|
ut64 old_baddr = r_config_get_i (core->config, "bin.baddr");
|
|
|
|
if (old_baddr != new_baddr) {
|
|
|
|
r_bin_set_baddr (core->bin, new_baddr);
|
|
|
|
r_config_set_i (core->config, "bin.baddr", new_baddr);
|
2017-03-18 20:40:01 +00:00
|
|
|
r_core_bin_rebase (core, new_baddr);
|
|
|
|
// r_core_bin_load (core, newfile, new_baddr);
|
|
|
|
// reload symbols with new baddr
|
2017-05-16 13:52:28 +00:00
|
|
|
r_core_cmd0 (core, ".is*");
|
|
|
|
r_core_cmd0 (core, ".ir*");
|
|
|
|
r_core_cmd0 (core, ".iz*");
|
|
|
|
r_core_cmd0 (core, ".iM*");
|
2015-10-19 08:33:06 +00:00
|
|
|
}
|
2016-12-21 08:07:58 +00:00
|
|
|
#endif
|
2015-10-31 00:57:52 +00:00
|
|
|
r_core_cmd0 (core, "sr PC");
|
2018-11-15 11:22:54 +00:00
|
|
|
free (bin_abspath);
|
2018-11-03 18:57:05 +00:00
|
|
|
free (escaped_path);
|
2015-10-07 03:51:35 +00:00
|
|
|
free (binpath);
|
2015-11-08 22:38:42 +00:00
|
|
|
free (newfile);
|
2015-08-28 23:41:34 +00:00
|
|
|
}
|
|
|
|
|
2017-08-25 23:50:57 +00:00
|
|
|
static int fdsz = 0;
|
|
|
|
|
|
|
|
static bool init_desc_list_visual_cb(void *user, void *data, ut32 id) {
|
|
|
|
RIODesc *desc = (RIODesc *)data;
|
|
|
|
ut64 sz = r_io_desc_size (desc);
|
|
|
|
if (sz > fdsz) {
|
|
|
|
fdsz = sz;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool desc_list_visual_cb(void *user, void *data, ut32 id) {
|
2017-05-03 15:19:49 +00:00
|
|
|
RPrint *p = (RPrint *)user;
|
|
|
|
RIODesc *desc = (RIODesc *)data;
|
2017-08-25 23:50:57 +00:00
|
|
|
ut64 sz = r_io_desc_size (desc);
|
2018-01-17 19:05:12 +00:00
|
|
|
r_cons_printf ("%2d %c %s 0x%08"PFMT64x" ", desc->fd,
|
2018-09-21 00:16:54 +00:00
|
|
|
(desc->io && (desc->io->desc == desc)) ? '*' : '-', r_str_rwx_i (desc->perm), sz);
|
2017-08-25 23:50:57 +00:00
|
|
|
int flags = p->flags;
|
|
|
|
p->flags &= ~R_PRINT_FLAGS_HEADER;
|
|
|
|
r_print_progressbar (p, sz * 100 / fdsz, r_cons_get_size (NULL) - 40);
|
|
|
|
p->flags = flags;
|
|
|
|
r_cons_printf (" %s\n", desc->uri);
|
2017-08-23 10:55:10 +00:00
|
|
|
#if 0
|
|
|
|
RIOMap *map;
|
|
|
|
SdbListIter *iter;
|
2017-05-03 15:19:49 +00:00
|
|
|
if (desc->io && desc->io->va && desc->io->maps) {
|
|
|
|
ls_foreach_prev (desc->io->maps, iter, map) {
|
|
|
|
if (map->fd == desc->fd) {
|
2017-08-14 00:55:47 +00:00
|
|
|
p->cb_printf (" +0x%"PFMT64x" 0x%"PFMT64x
|
2017-08-22 07:42:16 +00:00
|
|
|
" - 0x%"PFMT64x" : %s : %s : %s\n", map->delta,
|
|
|
|
map->from, map->to, r_str_rwx_i (map->flags), "",
|
|
|
|
map->name ? map->name : "");
|
2017-05-03 15:19:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-08-23 10:55:10 +00:00
|
|
|
#endif
|
2017-05-03 15:19:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-07-08 00:53:21 +00:00
|
|
|
static bool desc_list_quiet2_cb(void *user, void *data, ut32 id) {
|
|
|
|
RPrint *p = (RPrint *)user;
|
|
|
|
RIODesc *desc = (RIODesc *)data;
|
|
|
|
p->cb_printf ("%d\n", desc->fd);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-08-26 01:49:54 +00:00
|
|
|
static bool desc_list_quiet_cb(void *user, void *data, ut32 id) {
|
|
|
|
RPrint *p = (RPrint *)user;
|
|
|
|
RIODesc *desc = (RIODesc *)data;
|
|
|
|
p->cb_printf ("%d\n", desc->fd);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-08-25 23:50:57 +00:00
|
|
|
static bool desc_list_cb(void *user, void *data, ut32 id) {
|
|
|
|
RPrint *p = (RPrint *)user;
|
|
|
|
RIODesc *desc = (RIODesc *)data;
|
2018-01-17 19:05:12 +00:00
|
|
|
p->cb_printf ("%2d %c %s 0x%08"PFMT64x" %s\n", desc->fd,
|
2017-08-25 23:50:57 +00:00
|
|
|
(desc->io && (desc->io->desc == desc)) ? '*' : '-',
|
2018-09-21 00:16:54 +00:00
|
|
|
r_str_rwx_i (desc->perm), r_io_desc_size (desc), desc->uri);
|
2017-08-25 23:50:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-06-04 18:28:18 +00:00
|
|
|
static bool desc_list_json_cb(void *user, void *data, ut32 id) {
|
|
|
|
RPrint *p = (RPrint *)user;
|
|
|
|
RIODesc *desc = (RIODesc *)data;
|
|
|
|
// TODO: from is always 0? See libr/core/file.c:945
|
|
|
|
ut64 from = 0LL;
|
|
|
|
p->cb_printf ("{\"raised\":%s,\"fd\":%d,\"uri\":\"%s\",\"from\":%"
|
|
|
|
PFMT64d ",\"writable\":%s,\"size\":%" PFMT64d "}%s",
|
|
|
|
(desc->io && (desc->io->desc == desc)) ? "true" : "false",
|
|
|
|
desc->fd, desc->uri, from,
|
2018-09-21 00:16:54 +00:00
|
|
|
((desc->perm & R_PERM_W) ? "true": "false"),
|
2018-06-04 18:28:18 +00:00
|
|
|
r_io_desc_size (desc), (desc->io->files->top_id == id) ? "" : ",");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-02-27 01:40:27 +00:00
|
|
|
static int cmd_open(void *data, const char *input) {
|
|
|
|
RCore *core = (RCore*)data;
|
2018-09-21 00:16:54 +00:00
|
|
|
int perms = R_PERM_R;
|
2018-07-14 08:45:55 +00:00
|
|
|
ut64 baddr = r_config_get_i (core->config, "bin.baddr");
|
|
|
|
ut64 addr = 0LL;
|
|
|
|
int argc, fd = -1;
|
2012-02-27 01:40:27 +00:00
|
|
|
RCoreFile *file;
|
2018-09-08 16:28:31 +00:00
|
|
|
RIODesc *desc;
|
2017-10-18 01:07:39 +00:00
|
|
|
bool silence = false;
|
2018-01-17 19:05:12 +00:00
|
|
|
bool write = false;
|
2017-10-18 01:07:39 +00:00
|
|
|
const char *ptr = NULL;
|
|
|
|
char **argv = NULL;
|
2017-10-17 23:27:49 +00:00
|
|
|
|
|
|
|
switch (*input) {
|
2017-11-13 17:53:46 +00:00
|
|
|
case 'a':
|
|
|
|
switch (input[1]) {
|
|
|
|
case '*': // "oa*"
|
|
|
|
{
|
|
|
|
RListIter *iter;
|
|
|
|
RBinFile *bf = NULL;
|
|
|
|
r_list_foreach (core->bin->binfiles, iter, bf) {
|
|
|
|
if (bf && bf->o && bf->o->info) {
|
|
|
|
eprintf ("oa %s %d %s\n", bf->o->info->arch, bf->o->info->bits, bf->file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
case '?': // "oa?"
|
|
|
|
case ' ': // "oa "
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *ptr = strdup (input+2);
|
|
|
|
const char *arch = NULL;
|
|
|
|
ut16 bits = 0;
|
2017-11-13 20:25:04 +00:00
|
|
|
const char *filename = NULL;
|
2017-11-13 17:53:46 +00:00
|
|
|
i = r_str_word_set0 (ptr);
|
|
|
|
if (i < 2) {
|
|
|
|
eprintf ("Missing argument\n");
|
|
|
|
free (ptr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (i == 3) {
|
|
|
|
filename = r_str_word_get0 (ptr, 2);
|
|
|
|
}
|
|
|
|
bits = r_num_math (core->num, r_str_word_get0 (ptr, 1));
|
|
|
|
arch = r_str_word_get0 (ptr, 0);
|
|
|
|
r_core_bin_set_arch_bits (core, filename, arch, bits);
|
|
|
|
RBinFile *file = r_bin_file_find_by_name (core->bin, filename);
|
|
|
|
if (!file) {
|
|
|
|
eprintf ("Cannot find file %s\n", filename);
|
|
|
|
free (ptr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (file->o && file->o->info) {
|
|
|
|
file->o->info->arch = strdup(arch);
|
|
|
|
file->o->info->bits = bits;
|
|
|
|
r_core_bin_set_env (core, file);
|
|
|
|
}
|
|
|
|
free (ptr);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
eprintf ("Usage: oa[-][arch] [bits] [filename]\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2018-01-02 04:40:55 +00:00
|
|
|
case 'n': // "on"
|
2017-10-17 23:27:49 +00:00
|
|
|
if (input[1] == '*') {
|
|
|
|
r_core_file_list (core, 'n');
|
|
|
|
return 0;
|
2018-01-17 19:05:12 +00:00
|
|
|
} else if (input[1] == '+') { // "on+"
|
|
|
|
write = true;
|
2018-09-21 00:16:54 +00:00
|
|
|
perms |= R_PERM_W;
|
2018-01-17 19:05:12 +00:00
|
|
|
if (input[2] != ' ') {
|
|
|
|
eprintf ("Usage: on+ file [addr] [rwx]\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ptr = input + 3;
|
2018-01-02 04:40:55 +00:00
|
|
|
} else if (input[1] == 's') { // "ons"
|
2017-10-17 23:27:49 +00:00
|
|
|
silence = true;
|
2018-01-17 19:05:12 +00:00
|
|
|
if (input[2] == '+') { // "ons+"
|
|
|
|
write = true;
|
2018-09-21 00:16:54 +00:00
|
|
|
perms |= R_PERM_W;
|
2018-01-17 19:05:12 +00:00
|
|
|
if (input[3] != ' ') {
|
|
|
|
eprintf ("Usage: ons+ file [addr] [rwx]\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ptr = input + 4;
|
|
|
|
} else if (input[2] == ' ') {
|
|
|
|
ptr = input + 3;
|
|
|
|
} else {
|
2017-10-17 23:27:49 +00:00
|
|
|
eprintf ("Usage: ons file [addr] [rwx]\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else if (input[1] == ' ') {
|
2017-10-18 01:07:39 +00:00
|
|
|
ptr = input + 2;
|
2017-10-17 23:27:49 +00:00
|
|
|
} else {
|
|
|
|
eprintf ("Usage: on file [addr] [rwx]\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
argv = r_str_argv (ptr, &argc);
|
|
|
|
if (!argc) {
|
2018-01-17 19:05:12 +00:00
|
|
|
if (write) {
|
2018-01-17 19:38:01 +00:00
|
|
|
if (silence) eprintf ("Usage: ons+ file [addr] [rwx]\n");
|
|
|
|
else eprintf ("Usage: on+ file [addr] [rwx]\n");
|
2017-10-17 23:27:49 +00:00
|
|
|
} else {
|
2018-01-17 19:38:01 +00:00
|
|
|
if (silence) eprintf ("Usage: ons file [addr] [rwx]\n");
|
|
|
|
else eprintf ("Usage: on file [addr] [rwx]\n");
|
2017-10-17 23:27:49 +00:00
|
|
|
}
|
2018-01-17 19:38:01 +00:00
|
|
|
r_str_argv_free (argv);
|
|
|
|
return 0;
|
2017-10-17 23:27:49 +00:00
|
|
|
} else {
|
|
|
|
ptr = argv[0];
|
|
|
|
}
|
|
|
|
if (argc == 2) {
|
|
|
|
if (r_num_is_valid_input (core->num, argv[1])) {
|
|
|
|
addr = r_num_math (core->num, argv[1]);
|
|
|
|
} else {
|
|
|
|
perms = r_str_rwx (argv[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (argc == 3) {
|
|
|
|
addr = r_num_math (core->num, argv[1]);
|
|
|
|
perms = r_str_rwx (argv[2]);
|
|
|
|
}
|
2018-09-08 16:28:31 +00:00
|
|
|
if ((desc = r_io_open_at (core->io, ptr, perms, 0644, addr))) {
|
|
|
|
fd = desc->fd;
|
2017-10-17 23:27:49 +00:00
|
|
|
}
|
|
|
|
r_str_argv_free (argv);
|
|
|
|
if (!silence) {
|
|
|
|
eprintf ("%d\n", fd);
|
|
|
|
}
|
|
|
|
r_core_block_read (core);
|
|
|
|
return 0;
|
2018-01-10 12:45:37 +00:00
|
|
|
#if 1
|
|
|
|
// XXX projects use the of command, but i think we should deprecate it... keeping it for now
|
2018-01-02 04:40:55 +00:00
|
|
|
case 'f': // "of"
|
2017-10-17 23:27:49 +00:00
|
|
|
if ((input[1] == 's') && (input[2] == ' ')) {
|
|
|
|
silence = true;
|
2017-10-18 01:07:39 +00:00
|
|
|
ptr = input + 3;
|
2017-10-17 23:27:49 +00:00
|
|
|
} else if (input[1] == ' ') {
|
2017-10-18 01:07:39 +00:00
|
|
|
ptr = input + 2;
|
2017-10-17 23:27:49 +00:00
|
|
|
} else {
|
|
|
|
eprintf ("wrong\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
argv = r_str_argv (ptr, &argc);
|
|
|
|
if (argc == 0) {
|
|
|
|
eprintf ("wrong\n");
|
|
|
|
r_str_argv_free (argv);
|
|
|
|
return 0;
|
|
|
|
} else if (argc == 2) {
|
|
|
|
perms = r_str_rwx (argv[1]);
|
|
|
|
}
|
|
|
|
fd = r_io_fd_open (core->io, argv[0], perms, 0);
|
|
|
|
if (!silence) {
|
|
|
|
eprintf ("%d\n", fd);
|
|
|
|
}
|
|
|
|
r_str_argv_free (argv);
|
|
|
|
return 0;
|
2018-01-10 12:45:37 +00:00
|
|
|
#else
|
2017-10-19 23:12:45 +00:00
|
|
|
{
|
2018-01-10 12:45:37 +00:00
|
|
|
if ((input[1] == 's') && (input[2] == ' ')) {
|
|
|
|
silence = true;
|
|
|
|
input++;
|
2017-10-19 23:12:45 +00:00
|
|
|
}
|
2018-01-17 19:05:12 +00:00
|
|
|
addr = 0; // honor bin.baddr ?
|
2018-01-08 02:29:29 +00:00
|
|
|
const char *argv0 = r_str_trim_ro (input + 2);
|
2018-01-02 04:40:55 +00:00
|
|
|
if ((file = r_core_file_open (core, argv0, perms, addr))) {
|
|
|
|
fd = file->fd;
|
|
|
|
if (!silence) {
|
|
|
|
eprintf ("%d\n", fd);
|
|
|
|
}
|
|
|
|
r_core_bin_load (core, argv0, baddr);
|
2018-10-01 07:55:08 +00:00
|
|
|
} else {
|
2018-01-02 04:40:55 +00:00
|
|
|
eprintf ("cannot open file %s\n", argv0);
|
|
|
|
}
|
|
|
|
r_str_argv_free (argv);
|
|
|
|
}
|
|
|
|
r_core_block_read (core);
|
|
|
|
return 0;
|
|
|
|
break;
|
2018-01-10 12:45:37 +00:00
|
|
|
#endif
|
|
|
|
case 'p': // "op"
|
2018-01-27 22:31:00 +00:00
|
|
|
/* handle prioritize */
|
2018-06-26 23:02:24 +00:00
|
|
|
if (input[1]) {
|
2018-01-10 12:45:37 +00:00
|
|
|
int fd = r_num_math (core->num, input + 1);
|
|
|
|
if (fd) {
|
|
|
|
RIODesc *desc = r_io_desc_get (core->io, fd);
|
|
|
|
if (desc) {
|
|
|
|
// only useful for io.va=0
|
|
|
|
// load bininfo for given fd
|
2018-06-27 10:39:09 +00:00
|
|
|
r_core_cmdf (core, "obb %d", fd);
|
|
|
|
core->io->desc = desc;
|
2018-01-10 12:45:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
r_core_block_read (core);
|
2018-06-26 23:02:24 +00:00
|
|
|
} else {
|
|
|
|
r_cons_printf ("%d\n", core->io->desc->fd);
|
2018-01-10 12:45:37 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
break;
|
2017-10-20 00:58:42 +00:00
|
|
|
case '+': // "o+"
|
2018-09-21 00:16:54 +00:00
|
|
|
perms |= R_PERM_W;
|
2017-10-19 23:12:45 +00:00
|
|
|
case 's': // "os"
|
2017-10-17 23:27:49 +00:00
|
|
|
silence = true;
|
2018-01-02 04:40:55 +00:00
|
|
|
case ' ': // "o" "o "
|
2017-10-17 23:27:49 +00:00
|
|
|
if (silence) {
|
2017-10-18 01:07:39 +00:00
|
|
|
ptr = input + 2;
|
2017-10-17 23:27:49 +00:00
|
|
|
} else {
|
2017-10-18 01:07:39 +00:00
|
|
|
ptr = input + 1;
|
2017-10-17 23:27:49 +00:00
|
|
|
}
|
|
|
|
if (ptr[-1] != ' ') {
|
|
|
|
eprintf ("wrong\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2017-10-20 01:02:24 +00:00
|
|
|
argv = r_str_argv (ptr, &argc);
|
2017-10-17 23:27:49 +00:00
|
|
|
if (argc == 0) {
|
|
|
|
eprintf ("wrong\n");
|
|
|
|
r_str_argv_free (argv);
|
|
|
|
return 0;
|
|
|
|
}
|
2017-10-20 01:02:24 +00:00
|
|
|
if (argv) {
|
|
|
|
if (argc == 2) {
|
|
|
|
if (r_num_is_valid_input (core->num, argv[1])) {
|
|
|
|
addr = r_num_math (core->num, argv[1]);
|
|
|
|
} else {
|
|
|
|
perms = r_str_rwx (argv[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (argc == 3) {
|
2017-10-17 23:27:49 +00:00
|
|
|
addr = r_num_math (core->num, argv[1]);
|
2017-10-20 01:02:24 +00:00
|
|
|
perms = r_str_rwx (argv[2]);
|
2017-10-17 23:27:49 +00:00
|
|
|
}
|
|
|
|
}
|
2017-10-19 17:59:04 +00:00
|
|
|
{
|
|
|
|
const char *argv0 = argv ? argv[0] : ptr;
|
|
|
|
if ((file = r_core_file_open (core, argv0, perms, addr))) {
|
|
|
|
fd = file->fd;
|
|
|
|
if (!silence) {
|
|
|
|
eprintf ("%d\n", fd);
|
|
|
|
}
|
|
|
|
r_core_bin_load (core, argv0, baddr);
|
2018-10-01 07:55:08 +00:00
|
|
|
} else {
|
2017-10-19 17:59:04 +00:00
|
|
|
eprintf ("cannot open file %s\n", argv0);
|
2017-10-17 23:27:49 +00:00
|
|
|
}
|
2017-10-19 17:59:04 +00:00
|
|
|
r_str_argv_free (argv);
|
2017-10-17 23:27:49 +00:00
|
|
|
}
|
|
|
|
r_core_block_read (core);
|
|
|
|
return 0;
|
|
|
|
}
|
2012-02-27 01:40:27 +00:00
|
|
|
|
|
|
|
switch (*input) {
|
2017-08-25 23:50:57 +00:00
|
|
|
case '=': // "o="
|
|
|
|
fdsz = 0;
|
|
|
|
r_id_storage_foreach (core->io->files, init_desc_list_visual_cb, core->print);
|
|
|
|
r_id_storage_foreach (core->io->files, desc_list_visual_cb, core->print);
|
2015-01-27 14:35:42 +00:00
|
|
|
break;
|
2017-09-02 15:36:46 +00:00
|
|
|
case 'q': // "oq"
|
2018-07-08 00:53:21 +00:00
|
|
|
if (input[1] == '.') {
|
|
|
|
r_id_storage_foreach (core->io->files, desc_list_quiet2_cb, core->print);
|
|
|
|
} else {
|
|
|
|
r_id_storage_foreach (core->io->files, desc_list_quiet_cb, core->print);
|
|
|
|
}
|
2017-08-26 01:49:54 +00:00
|
|
|
break;
|
2017-09-02 15:36:46 +00:00
|
|
|
case '\0': // "o"
|
2017-05-03 15:19:49 +00:00
|
|
|
r_id_storage_foreach (core->io->files, desc_list_cb, core->print);
|
2016-03-27 12:55:22 +00:00
|
|
|
break;
|
2017-09-02 15:36:46 +00:00
|
|
|
case '*': // "o*"
|
2016-03-27 12:55:22 +00:00
|
|
|
if ('?' == input[1]) {
|
2017-07-27 12:52:17 +00:00
|
|
|
r_core_cmd_help (core, help_msg_o_star);
|
2016-03-27 12:55:22 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-08-25 23:50:57 +00:00
|
|
|
r_core_file_list (core, (int)(*input));
|
|
|
|
break;
|
2017-09-02 15:36:46 +00:00
|
|
|
case 'j': // "oj"
|
2016-03-27 12:55:22 +00:00
|
|
|
if ('?' == input[1]) {
|
2017-07-27 12:52:17 +00:00
|
|
|
r_core_cmd_help (core, help_msg_oj);
|
2016-03-27 12:55:22 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-06-04 18:28:18 +00:00
|
|
|
core->print->cb_printf("[");
|
|
|
|
r_id_storage_foreach (core->io->files, desc_list_json_cb, core->print);
|
|
|
|
core->print->cb_printf("]\n");
|
2012-02-27 01:40:27 +00:00
|
|
|
break;
|
2017-09-02 15:36:46 +00:00
|
|
|
case 'L': // "oL"
|
2014-12-19 01:08:58 +00:00
|
|
|
if (r_sandbox_enable (0)) {
|
|
|
|
eprintf ("This command is disabled in sandbox mode\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2017-10-19 23:12:45 +00:00
|
|
|
if (input[1] == ' ') {
|
2016-11-02 02:27:37 +00:00
|
|
|
if (r_lib_open (core->lib, input+2) == R_FAIL) {
|
2014-12-19 01:08:58 +00:00
|
|
|
eprintf ("Oops\n");
|
2016-11-02 02:27:37 +00:00
|
|
|
}
|
2014-12-19 01:08:58 +00:00
|
|
|
} else {
|
2017-11-04 19:55:26 +00:00
|
|
|
if ('j' == input[1]) {
|
|
|
|
r_io_plugin_list_json (core->io);
|
|
|
|
} else {
|
|
|
|
r_io_plugin_list (core->io);
|
|
|
|
}
|
2014-12-19 01:08:58 +00:00
|
|
|
}
|
|
|
|
break;
|
2016-11-02 02:27:37 +00:00
|
|
|
case 'i': // "oi"
|
|
|
|
switch (input[1]) {
|
|
|
|
case ' ': // "oi "
|
|
|
|
{
|
|
|
|
RListIter *iter = NULL;
|
|
|
|
RCoreFile *f;
|
|
|
|
int nth = r_num_math (core->num, input + 2);
|
|
|
|
int count = 0;
|
|
|
|
r_list_foreach (core->files, iter, f) {
|
|
|
|
if (count == nth) {
|
2017-08-22 07:42:16 +00:00
|
|
|
r_io_use_fd (core->io, f->fd);
|
2016-11-02 02:27:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '-': // "oi-"
|
|
|
|
{
|
|
|
|
RListIter *iter = NULL;
|
|
|
|
RCoreFile *f;
|
|
|
|
int nth = r_num_math (core->num, input + 2);
|
|
|
|
int count = 0;
|
|
|
|
r_list_foreach (core->files, iter, f) {
|
|
|
|
if (count == nth) {
|
2017-08-22 07:42:16 +00:00
|
|
|
r_core_file_close_fd (core, f->fd);
|
2016-11-02 02:27:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2017-09-02 15:36:46 +00:00
|
|
|
case 'j': // "oij"
|
|
|
|
case '*': // "oi*"
|
|
|
|
case 0: // "oi"
|
2016-11-02 02:27:37 +00:00
|
|
|
r_core_file_list (core, input[1]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2019-04-14 21:06:01 +00:00
|
|
|
case 'u': { // "ou"
|
2018-11-13 12:05:18 +00:00
|
|
|
RListIter *iter = NULL;
|
|
|
|
RCoreFile *f;
|
|
|
|
int binfile_num;
|
|
|
|
core->switch_file_view = 0;
|
|
|
|
int num = atoi (input + 2);
|
2017-10-17 23:27:49 +00:00
|
|
|
|
2018-11-13 12:05:18 +00:00
|
|
|
r_list_foreach (core->files, iter, f) {
|
|
|
|
if (f->fd == num) {
|
|
|
|
core->file = f;
|
2014-01-18 15:26:09 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-13 12:05:18 +00:00
|
|
|
r_io_use_fd (core->io, num);
|
|
|
|
RBinFile *bf = r_bin_file_find_by_fd (core->bin, num);
|
|
|
|
binfile_num = bf? bf->id: UT32_MAX;
|
|
|
|
r_core_bin_raise (core, binfile_num, -1);
|
2017-10-17 23:27:49 +00:00
|
|
|
r_core_block_read (core);
|
2012-02-27 01:40:27 +00:00
|
|
|
break;
|
2018-11-13 12:05:18 +00:00
|
|
|
}
|
2017-09-02 15:36:46 +00:00
|
|
|
case 'b': // "ob"
|
2015-02-02 23:51:20 +00:00
|
|
|
cmd_open_bin (core, input);
|
2014-04-27 07:06:50 +00:00
|
|
|
break;
|
2017-09-02 15:36:46 +00:00
|
|
|
case '-': // "o-"
|
2015-01-22 01:22:29 +00:00
|
|
|
switch (input[1]) {
|
2017-11-22 13:58:09 +00:00
|
|
|
case '!': // "o-!"
|
|
|
|
r_core_file_close_all_but (core);
|
|
|
|
break;
|
2015-02-04 02:06:27 +00:00
|
|
|
case '*': // "o-*"
|
2015-01-22 01:22:29 +00:00
|
|
|
r_core_file_close_fd (core, -1);
|
|
|
|
r_io_close_all (core->io);
|
|
|
|
r_bin_file_delete_all (core->bin);
|
2018-11-15 08:29:50 +00:00
|
|
|
if (core->files) {
|
|
|
|
r_list_purge (core->files);
|
|
|
|
}
|
2015-01-22 01:22:29 +00:00
|
|
|
break;
|
2015-02-04 02:06:27 +00:00
|
|
|
case '-': // "o--"
|
2015-01-22 01:22:29 +00:00
|
|
|
eprintf ("All core files, io, anal and flags info purged.\n");
|
|
|
|
r_core_file_close_fd (core, -1);
|
|
|
|
r_io_close_all (core->io);
|
|
|
|
r_bin_file_delete_all (core->bin);
|
|
|
|
|
|
|
|
// TODO: Move to a-- ?
|
|
|
|
r_anal_purge (core->anal);
|
|
|
|
// TODO: Move to f-- ?
|
|
|
|
r_flag_unset_all (core->flags);
|
|
|
|
// TODO: rbin?
|
|
|
|
break;
|
2015-02-04 02:06:27 +00:00
|
|
|
default:
|
2017-08-26 22:42:08 +00:00
|
|
|
{
|
|
|
|
int fd = (int)r_num_math (core->num, input + 1);
|
|
|
|
if (!r_core_file_close_fd (core, fd)) {
|
|
|
|
eprintf ("Unable to find filedescriptor %d\n", fd);
|
|
|
|
}
|
2016-11-02 02:27:37 +00:00
|
|
|
}
|
2015-01-22 01:22:29 +00:00
|
|
|
break;
|
2017-08-26 22:59:57 +00:00
|
|
|
case 0:
|
2015-02-04 02:06:27 +00:00
|
|
|
case '?':
|
2017-11-22 13:58:09 +00:00
|
|
|
r_core_cmd_help (core, help_msg_o_);
|
2015-01-22 01:22:29 +00:00
|
|
|
}
|
2012-02-27 01:40:27 +00:00
|
|
|
break;
|
2017-11-08 02:08:41 +00:00
|
|
|
case '.': // "o."
|
2019-04-14 21:06:01 +00:00
|
|
|
if (input[1] == 'q') { // "o.q" // same as oq
|
|
|
|
RIOMap *map = r_io_map_get (core->io, core->offset);
|
|
|
|
if (map) {
|
|
|
|
r_cons_printf ("%d\n", map->fd);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
RIOMap *map = r_io_map_get (core->io, core->offset);
|
|
|
|
if (map) {
|
|
|
|
RIODesc *desc = r_io_desc_get (core->io, map->fd);
|
|
|
|
if (desc) {
|
|
|
|
r_cons_printf ("%s\n", desc->uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ':': // "o:"
|
2017-11-08 02:08:41 +00:00
|
|
|
{
|
|
|
|
int len = r_num_math (core->num, input + 1);
|
|
|
|
if (len < 1) {
|
|
|
|
len = core->blocksize;
|
|
|
|
}
|
|
|
|
char *uri = r_str_newf ("malloc://%d", len);
|
|
|
|
ut8 *data = calloc (len, 1);
|
2018-05-21 21:06:00 +00:00
|
|
|
r_io_read_at (core->io, core->offset, data, len);
|
2018-09-21 00:16:54 +00:00
|
|
|
RIODesc *fd = r_io_open (core->io, uri, R_PERM_R | R_PERM_W, 0);
|
2017-11-08 02:08:41 +00:00
|
|
|
if (fd) {
|
|
|
|
r_io_desc_write (fd, data, len);
|
|
|
|
}
|
|
|
|
free (uri);
|
|
|
|
free (data);
|
|
|
|
}
|
|
|
|
break;
|
2017-09-02 15:36:46 +00:00
|
|
|
case 'm': // "om"
|
2015-02-02 23:51:20 +00:00
|
|
|
cmd_open_map (core, input);
|
2012-02-27 01:40:27 +00:00
|
|
|
break;
|
2017-09-02 15:36:46 +00:00
|
|
|
case 'o': // "oo"
|
2014-10-16 22:36:00 +00:00
|
|
|
switch (input[1]) {
|
2016-09-19 14:34:45 +00:00
|
|
|
case 'm': // "oom"
|
|
|
|
r_core_file_reopen_in_malloc (core);
|
|
|
|
break;
|
2015-08-19 13:13:08 +00:00
|
|
|
case 'd': // "ood" : reopen in debugger
|
2017-12-24 00:13:32 +00:00
|
|
|
if (input[2] == 'r') { // "oodr"
|
2018-02-27 23:18:09 +00:00
|
|
|
r_core_cmdf (core, "dor %s", input + 3);
|
2017-12-24 00:13:32 +00:00
|
|
|
r_core_file_reopen_debug (core, "");
|
|
|
|
} else if ('?' == input[2]) {
|
2017-07-27 12:52:17 +00:00
|
|
|
r_core_cmd_help (core, help_msg_ood);
|
2016-03-27 12:55:22 +00:00
|
|
|
} else {
|
|
|
|
r_core_file_reopen_debug (core, input + 2);
|
|
|
|
}
|
2015-08-19 13:13:08 +00:00
|
|
|
break;
|
2019-04-14 21:06:01 +00:00
|
|
|
case 'c': // "oob" : reopen with bin info
|
|
|
|
r_core_cmd0 (core, "oc `o.`");
|
|
|
|
break;
|
2014-10-16 22:36:00 +00:00
|
|
|
case 'b': // "oob" : reopen with bin info
|
2016-03-27 12:55:22 +00:00
|
|
|
if ('?' == input[2]) {
|
2017-07-27 12:52:17 +00:00
|
|
|
r_core_cmd_help (core, help_msg_oob);
|
2016-03-27 12:55:22 +00:00
|
|
|
} else {
|
|
|
|
r_core_file_reopen (core, input + 2, 0, 2);
|
|
|
|
}
|
2014-10-16 22:36:00 +00:00
|
|
|
break;
|
2017-09-02 15:36:46 +00:00
|
|
|
case 'n': // "oon"
|
2016-03-27 12:55:22 +00:00
|
|
|
if ('n' == input[2]) {
|
2017-08-22 07:42:16 +00:00
|
|
|
RIODesc *desc = r_io_desc_get (core->io, core->file->fd);
|
2016-03-27 12:55:22 +00:00
|
|
|
if ('?' == input[3]) {
|
2017-07-27 12:52:17 +00:00
|
|
|
r_core_cmd_help (core, help_msg_oonn);
|
2016-03-27 12:55:22 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-09-21 00:16:54 +00:00
|
|
|
perms = (input[3] == '+')? R_PERM_R|R_PERM_W: 0;
|
2015-10-22 01:20:30 +00:00
|
|
|
r_core_file_reopen (core, input + 4, perms, 0);
|
2016-02-16 01:42:44 +00:00
|
|
|
// TODO: Use API instead of !rabin2 -rk
|
2017-08-22 07:42:16 +00:00
|
|
|
if (desc) {
|
|
|
|
r_core_cmdf (core, ".!rabin2 -rk '' '%s'", desc->name);
|
|
|
|
}
|
2016-03-27 12:55:22 +00:00
|
|
|
} else if ('?' == input[2]) {
|
2017-07-27 12:52:17 +00:00
|
|
|
r_core_cmd_help (core, help_msg_oon);
|
2016-03-27 12:55:22 +00:00
|
|
|
break;
|
2015-10-21 00:30:28 +00:00
|
|
|
}
|
2016-03-27 12:55:22 +00:00
|
|
|
|
2018-09-21 00:16:54 +00:00
|
|
|
perms = ('+' == input[2])? R_PERM_R | R_PERM_W: 0;
|
2016-03-27 12:55:22 +00:00
|
|
|
r_core_file_reopen (core, input + 3, perms, 0);
|
2014-10-16 22:36:00 +00:00
|
|
|
break;
|
2017-09-02 15:36:46 +00:00
|
|
|
case '+': // "oo+"
|
2016-03-27 12:55:22 +00:00
|
|
|
if ('?' == input[2]) {
|
2017-07-27 12:52:17 +00:00
|
|
|
r_core_cmd_help (core, help_msg_oo_plus);
|
2017-08-22 07:42:16 +00:00
|
|
|
} else if (core && core->io && core->io->desc) {
|
|
|
|
int fd;
|
2018-09-21 00:16:54 +00:00
|
|
|
int perms = R_PERM_RW;
|
2017-08-22 07:42:16 +00:00
|
|
|
if ((ptr = strrchr (input, ' ')) && ptr[1]) {
|
|
|
|
fd = (int)r_num_math (core->num, ptr + 1);
|
|
|
|
} else {
|
|
|
|
fd = core->io->desc->fd;
|
2018-09-21 00:16:54 +00:00
|
|
|
perms |= core->io->desc->perm;
|
2017-08-22 07:42:16 +00:00
|
|
|
}
|
2018-02-20 22:28:17 +00:00
|
|
|
if (r_io_reopen (core->io, fd, perms, 644)) {
|
2017-09-04 09:01:17 +00:00
|
|
|
SdbListIter *iter;
|
|
|
|
RIOMap *map;
|
|
|
|
ls_foreach_prev (core->io->maps, iter, map) {
|
|
|
|
if (map->fd == fd) {
|
2018-09-21 00:16:54 +00:00
|
|
|
map->perm |= R_PERM_WX;
|
2017-09-04 09:01:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-27 12:55:22 +00:00
|
|
|
}
|
2014-10-16 22:36:00 +00:00
|
|
|
break;
|
2017-08-22 07:42:16 +00:00
|
|
|
case '\0': // "oo"
|
|
|
|
if (core && core->io && core->io->desc) {
|
|
|
|
//does not work for debugging
|
|
|
|
int fd;
|
|
|
|
if ((ptr = strrchr (input, ' ')) && ptr[1]) {
|
|
|
|
fd = (int)r_num_math (core->num, ptr + 1);
|
|
|
|
} else {
|
|
|
|
fd = core->io->desc->fd;
|
|
|
|
}
|
2018-06-26 22:24:31 +00:00
|
|
|
if (r_config_get_i (core->config, "cfg.debug")) {
|
|
|
|
RBinFile *bf = r_core_bin_cur (core);
|
|
|
|
if (bf && r_file_exists (bf->file)) {
|
|
|
|
char *file = strdup (bf->file);
|
|
|
|
r_core_cmd0 (core, "ob-*");
|
|
|
|
r_io_close_all (core->io);
|
|
|
|
r_config_set (core->config, "cfg.debug", "false");
|
2018-07-18 18:18:10 +00:00
|
|
|
ut64 orig_baddr = sdb_num_get (core->sdb, "orig_baddr", 0);
|
|
|
|
r_bin_set_baddr (core->bin, orig_baddr);
|
|
|
|
r_config_set_i (core->config, "bin.baddr", orig_baddr);
|
|
|
|
r_core_bin_rebase (core, orig_baddr);
|
2018-06-26 22:24:31 +00:00
|
|
|
r_core_cmdf (core, "o %s", file);
|
|
|
|
free (file);
|
|
|
|
} else {
|
|
|
|
eprintf ("Nothing to do.\n");
|
|
|
|
}
|
|
|
|
} else {
|
2018-09-21 00:16:54 +00:00
|
|
|
r_io_reopen (core->io, fd, R_PERM_R, 644);
|
2018-06-26 22:24:31 +00:00
|
|
|
}
|
2017-08-22 07:42:16 +00:00
|
|
|
}
|
2014-10-16 22:36:00 +00:00
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
default:
|
2015-02-02 23:51:20 +00:00
|
|
|
r_core_cmd_help (core, help_msg_oo);
|
2014-10-16 22:36:00 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-02-27 01:40:27 +00:00
|
|
|
break;
|
2017-09-02 15:36:46 +00:00
|
|
|
case 'c': // "oc"
|
2015-03-22 22:24:13 +00:00
|
|
|
if (input[1] && input[2]) {
|
2017-05-23 09:11:59 +00:00
|
|
|
if (r_sandbox_enable (0)) {
|
|
|
|
eprintf ("This command is disabled in sandbox mode\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2018-10-11 12:00:59 +00:00
|
|
|
if (core->current_task != core->main_task) {
|
|
|
|
eprintf ("This command can only be executed on the main task!\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2017-05-23 09:11:59 +00:00
|
|
|
// memleak? lose all settings wtf
|
|
|
|
// if load fails does not fallbacks to previous file
|
2018-10-11 12:00:59 +00:00
|
|
|
r_core_task_sync_end (core);
|
2017-05-23 09:11:59 +00:00
|
|
|
r_core_fini (core);
|
|
|
|
r_core_init (core);
|
2018-10-11 12:00:59 +00:00
|
|
|
r_core_task_sync_begin (core);
|
2018-09-21 00:16:54 +00:00
|
|
|
if (!r_core_file_open (core, input + 2, R_PERM_R, 0)) {
|
2015-03-22 22:24:13 +00:00
|
|
|
eprintf ("Cannot open file\n");
|
2016-09-19 14:34:45 +00:00
|
|
|
}
|
2017-08-23 10:39:10 +00:00
|
|
|
(void)r_core_bin_load (core, NULL, baddr);
|
2015-03-22 22:24:13 +00:00
|
|
|
} else {
|
|
|
|
eprintf ("Missing argument\n");
|
|
|
|
}
|
2012-09-07 01:26:38 +00:00
|
|
|
break;
|
2017-09-02 15:36:46 +00:00
|
|
|
case 'x': // "ox"
|
2017-10-20 00:25:30 +00:00
|
|
|
if (input[1] && input[1] != '?') {
|
2017-08-22 07:42:16 +00:00
|
|
|
int fd, fdx;
|
|
|
|
fd = fdx = -1;
|
2017-10-18 01:07:39 +00:00
|
|
|
char *ptr, *inp = strdup (input);
|
|
|
|
if ((ptr = strrchr (inp, ' '))) {
|
2017-08-22 07:42:16 +00:00
|
|
|
fdx = (int)r_num_math (core->num, ptr + 1);
|
|
|
|
*ptr = '\0';
|
2017-10-18 01:07:39 +00:00
|
|
|
if ((ptr = strchr (inp, ' '))) {
|
2017-08-22 07:42:16 +00:00
|
|
|
fd = r_num_math (core->num, ptr + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((fdx == -1) || (fd == -1) || (fdx == fd)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
r_io_desc_exchange (core->io, fd, fdx);
|
|
|
|
r_core_block_read (core);
|
2017-10-20 00:25:30 +00:00
|
|
|
} else {
|
|
|
|
eprintf ("Usage: ox [fd] [fdx] - exchange two file descriptors\n");
|
2017-08-22 07:42:16 +00:00
|
|
|
}
|
|
|
|
break;
|
2017-09-02 15:36:46 +00:00
|
|
|
case '?': // "o?"
|
2012-02-27 01:40:27 +00:00
|
|
|
default:
|
2017-07-27 12:52:17 +00:00
|
|
|
r_core_cmd_help (core, help_msg_o);
|
2012-02-27 01:40:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|