Skip to content

Commit

Permalink
fjaklsdf
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Dec 22, 2024
1 parent 9e893af commit 22e487f
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 87 deletions.
165 changes: 89 additions & 76 deletions libr/core/cmd_open.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -818,77 +818,31 @@ static void cmd_omd(RCore *core, const char* input) {
}

static void cmd_open_banks(RCore *core, int argc, char *argv[]) {
if (argc == 1) {
switch (argv[0][1]) {
case '=': // "omb=[name]"
{
RIOBank *bank = r_io_bank_get_byname (core->io, argv[0] + 2);
if (bank) {
r_io_bank_use (core->io, bank->id);
} else {
R_LOG_ERROR ("unknown bank name (%s)", argv[0] + 2);
}
switch (argv[0][1]) {
case '=': // "omb=[name]"
if (argc == 1) {
RIOBank *bank = r_io_bank_get_byname (core->io, argv[0] + 2);
if (bank) {
r_io_bank_use (core->io, bank->id);
} else {
R_LOG_ERROR ("unknown bank name (%s)", argv[0] + 2);
}
break;
case 'g': // "ombg"
{
ut32 mapid;
r_id_storage_get_lowest (&core->io->maps, &mapid);
do {
RIOMap *map = r_id_storage_get (&core->io->maps, mapid);
r_io_bank_map_add_top (core->io, core->io->bank, map->id);
} while (r_id_storage_get_next (&core->io->maps, &mapid));
} else {
RIOBank *bank = r_io_bank_get_byname (core->io, argv[1]);
if (bank) {
r_io_bank_use (core->io, bank->id);
} else {
R_LOG_ERROR ("unknown bank name (%s)", argv[1]);
}
break;
case 'q': // "ombq"
}
break;
case 'q': // "ombq"
if (argc != 1) {
R_LOG_ERROR ("ombq takes no arguments");
} else {
r_cons_printf ("%d\n", core->io->bank);
break;
case 0: // "omb"
{
ut32 bank_id = 0;
if (!r_id_storage_get_lowest (&core->io->banks, &bank_id)) {
break;
}
do {
RIOBank *bank = r_id_storage_get (&core->io->banks, bank_id);
const char ch = core->io->bank == bank_id? '*': '-';
r_cons_printf ("%c %d %s [", ch, bank->id, bank->name);
RIOMapRef *mapref;
RListIter *iter;
r_list_foreach (bank->maprefs, iter, mapref) {
r_cons_printf (" %d", mapref->id);
}
r_cons_printf (" ]\n");
// list all the associated maps
} while (r_id_storage_get_next (&core->io->banks, &bank_id));
}
break;
case '+': // "omb+ [name]"
{
const char *name = argv[0] + 2;
if (isdigit (*name)) {
// add a map to the current bank
// we cant name a bank with a number :?
r_io_bank_map_add_top (core->io, core->io->bank, atoi (name));
} else {
// add a new bank
RIOBank *bank = r_io_bank_new (name);
if (bank) {
r_io_bank_add (core->io, bank);
}
}
}
break;
case '?': // "omb?"
r_core_cmd_help (core, help_msg_omb);
break;
default:
r_core_return_invalid_command (core, "omb", argv[0][1]);
break;
}
return;
}
switch (argv[0][1]) {
break;
case 'a': // "omba"
if (isdigit (argv[1][0])) {
int mapid = atoi (argv[1]);
Expand All @@ -913,32 +867,91 @@ static void cmd_open_banks(RCore *core, int argc, char *argv[]) {
}
break;
case '-': // "omb-"
if (!strcmp ("*", argv[1])) {
r_io_bank_drain (core->io, core->io->bank);
core->io->bank = r_io_bank_first (core->io);
{
const char *arg = (argc == 1)? argv[0] + 2: argv[1];
if (R_STR_ISEMPTY (arg)) {
R_LOG_ERROR ("Missing argument for omb-");
} else if (!strcmp ("*", arg)) {
r_io_bank_drain (core->io, core->io->bank);
core->io->bank = r_io_bank_first (core->io);
} else {
int bank_id = r_num_math (core->num, arg);
if (core->num->nc.errors != 0) {
r_io_bank_del (core->io, bank_id);
} else {
R_LOG_ERROR ("Invalid number in %s", arg);
}
}
}
break;
case 'g': // "ombg"
if (argc == 1) {
ut32 mapid;
r_id_storage_get_lowest (&core->io->maps, &mapid);
do {
RIOMap *map = r_id_storage_get (&core->io->maps, mapid);
r_io_bank_map_add_top (core->io, core->io->bank, map->id);
} while (r_id_storage_get_next (&core->io->maps, &mapid));
} else {
int bank_id = atoi (argv[1]);
r_io_bank_del (core->io, bank_id);
R_LOG_ERROR ("ombg takes no arguments");
}
break;
case '+': // "omb+ [name]"
{
if (argc == 1) {
const char *name = argv[0] + 2;
if (isdigit (*name)) {
// add a map to the current bank
// we cant name a bank with a number :?
r_io_bank_map_add_top (core->io, core->io->bank, atoi (name));
} else {
// add a new bank
RIOBank *bank = r_io_bank_new (name);
if (bank) {
r_io_bank_add (core->io, bank);
} else {
R_LOG_ERROR ("Cannot create map from %s", name);
}
}
} else {
RIOBank *bank = r_io_bank_new (argv[1]);
r_io_bank_add (core->io, bank);
if (bank) {
r_io_bank_add (core->io, bank);
} else {
R_LOG_ERROR ("Cannot create map from %s", argv[1]);
}
}
break;
case 0: // "omb [id]"
{
if (argc == 1) {
ut32 bank_id = 0;
if (!r_id_storage_get_lowest (&core->io->banks, &bank_id)) {
break;
}
do {
RIOBank *bank = r_id_storage_get (&core->io->banks, bank_id);
const char ch = core->io->bank == bank_id? '*': '-';
r_cons_printf ("%c %d %s [", ch, bank->id, bank->name);
RIOMapRef *mapref;
RListIter *iter;
r_list_foreach (bank->maprefs, iter, mapref) {
r_cons_printf (" %d", mapref->id);
}
r_cons_printf (" ]\n");
// list all the associated maps
} while (r_id_storage_get_next (&core->io->banks, &bank_id));
} else {
int id = r_num_get (NULL, argv[1]);
if (!r_io_bank_use (core->io, id)) {
R_LOG_ERROR ("Cannot find bank by id %s", argv[1]);
}
}
break;
case '?': // "omb?"
default:
r_core_cmd_help (core, help_msg_omb);
break;
default:
r_core_return_invalid_command (core, "omb", argv[0][1]);
break;
}
}

Expand Down
14 changes: 3 additions & 11 deletions test/db/io/banks
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,9 @@ EXPECT=<<EOF
* 1 fd: 3 +0x00000000 0x00000000 - 0x000003ff rwx
* 1 fd: 3 +0x00000000 0x00000000 - 0x000003ff rwx
* 1 fd: 3 +0x00000000 0x00000000 - 0x000003ff rwx
Usage: omb[+-adgq] [fd] Operate on memory banks
| omb list all memory banks
| omb [id] switch to use a different bank
| omb=[name] same as 'omb id' but using its name
| omb+ [name] create a new bank with given name
| omba [id] adds a map to the bank
| ombd [id] delete a map from the bank
| omb-* delete all banks
| omb- [mapid] delete the bank with given id
| ombg associate all maps to the current bank
| ombq show current bankid
EOF
EXPECT_ERR=<<EOF
ERROR: Cannot find bank by id -1
EOF
RUN

Expand Down

0 comments on commit 22e487f

Please sign in to comment.