Implement r_io_bank_get_byname and the omnb= command ##io

This commit is contained in:
pancake 2023-09-14 23:33:08 +02:00 committed by GitHub
parent 14770f76c3
commit dec6b4614e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 3 deletions

View File

@ -77,6 +77,7 @@ static RCoreHelpMessage help_msg_omb = {
"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",
@ -133,7 +134,7 @@ static RCoreHelpMessage help_msg_om = {
"om,", " [query]", "list maps using table api",
"om=", "", "list all maps in ascii art",
"oma"," [fd]", "create a map covering all VA for given fd",
"omb", " ", "list/select memory map banks",
"omb", "[?]", "list/select memory map banks",
"omB", " mapid addr", "relocate map with corresponding id",
"omB.", " addr", "relocate current map",
"omd", " from to @ paddr", "simplified om; takes current seek, fd and perms",
@ -763,6 +764,16 @@ 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);
}
}
break;
case 'g': // "ombg"
{
ut32 mapid;
@ -860,7 +871,8 @@ static void cmd_open_banks(RCore *core, int argc, char *argv[]) {
break;
case 0: // "omb [id]"
{
if (!r_io_bank_use (core->io, r_num_get (NULL, argv[1]))) {
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]);
}
}

View File

@ -106,7 +106,6 @@ static inline void fini_access(REsilTraceAccess *access) {
if (access->is_reg) {
return;
}
free (access->mem.data);
}

View File

@ -398,6 +398,7 @@ R_API void r_io_bank_free(RIOBank *bank);
R_API void r_io_bank_init(RIO *io);
R_API void r_io_bank_fini(RIO *io);
R_API RIOBank *r_io_bank_get(RIO *io, const ut32 bankid);
R_API RIOBank *r_io_bank_get_byname(RIO *io, const char *bankname);
R_API bool r_io_bank_use(RIO *io, ut32 bankid);
R_API bool r_io_bank_map_add_top(RIO *io, const ut32 bankid, const ut32 mapid);
R_API bool r_io_bank_map_add_bottom(RIO *io, const ut32 bankid, const ut32 mapid);

View File

@ -75,6 +75,30 @@ R_API RIOBank *r_io_bank_get(RIO *io, const ut32 bankid) {
return (RIOBank *)r_id_storage_get (io->banks, bankid);
}
typedef struct {
RIO *io;
RIOBank *bank;
const char *name;
} Boring;
static bool find_bank(void *data, void *user, ut32 id) {
RIOBank *bank = (RIOBank *)user;
Boring *boo = (Boring *)data;
if (!strcmp (bank->name, boo->name)) {
boo->bank = bank;
return false;
}
return true;
}
R_API RIOBank *r_io_bank_get_byname(RIO *io, const char *bankname) {
r_return_val_if_fail (io && io->banks && bankname, NULL);
Boring boo = { .io = io, .name = bankname, .bank = NULL };
eprintf ("ooME (%s)\n", boo.name);
r_id_storage_foreach (io->banks, &find_bank, &boo);
return boo.bank;
}
R_API ut32 r_io_bank_first(RIO *io) {
r_return_val_if_fail (io, UT32_MAX);
ut32 bankid = -1;

View File

@ -18,6 +18,7 @@ EXPECT=<<EOF
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