Skip to content

Commit

Permalink
Remove bin.laddr too and extend i and ij ##bin
Browse files Browse the repository at this point in the history
  • Loading branch information
trufae authored and radare committed Sep 14, 2022
1 parent 241a905 commit 16b6c84
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 12 deletions.
3 changes: 2 additions & 1 deletion libr/core/cbin.c
Original file line number Diff line number Diff line change
Expand Up @@ -4250,7 +4250,8 @@ static bool bin_header(RCore *r, int mode) {
R_API bool r_core_bin_info(RCore *core, int action, PJ *pj, int mode, int va, RCoreBinFilter *filter, const char *chksum) {
bool ret = true;
const char *name = NULL;
ut64 at = UT64_MAX, loadaddr = r_bin_get_laddr (core->bin);
ut64 at = UT64_MAX;
ut64 loadaddr = r_bin_get_laddr (core->bin);
if (filter && filter->offset) {
at = filter->offset;
}
Expand Down
1 change: 0 additions & 1 deletion libr/core/cconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -3657,7 +3657,6 @@ R_API int r_core_config_init(RCore *core) {
SETCB("bin.demangle.trylib", "true", &cb_demangle_trylib, "try to use system available libraries to demangle");
SETBPREF ("bin.demangle.libs", "false", "show library name on demangled symbols names");
SETI ("bin.baddr", -1, "base address of the binary");
SETI ("bin.laddr", 0, "base address for loading library ('*.so')");
SETCB ("bin.dbginfo", "true", &cb_bindbginfo, "load debug information at startup if available");
SETBPREF ("bin.relocs", "true", "load relocs information at startup if available");
SETICB ("bin.minstr", 0, &cb_binminstr, "minimum string length for r_bin");
Expand Down
29 changes: 22 additions & 7 deletions libr/core/cfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,33 @@ static void loadGP(RCore *core) {
}
}

R_API ut64 r_core_get_cur_laddr(RCore *core) {
RListIter *iter;
RIOMap *map;
ut64 laddr = 0;
RIODesc *odesc = core->io ? core->io->desc : NULL;
if (odesc) {
RList *maps = r_io_map_get_by_fd (core->io, odesc->fd);
r_list_foreach (maps, iter, map) {
if (map->delta) {
continue;
}
if (map->itv.addr && (!laddr || map->itv.addr < laddr)) {
laddr = map->itv.addr;
}
}
}
return laddr;
}

R_API bool r_core_file_reopen(RCore *core, const char *args, int perm, int loadbin) {
const bool isdebug = r_config_get_b (core->config, "cfg.debug");
char *path;
ut64 laddr = r_config_get_i (core->config, "bin.laddr");
RIODesc *odesc = core->io ? core->io->desc : NULL;
RBinFile *bf = odesc ? r_bin_file_find_by_fd (core->bin, odesc->fd) : NULL;
char *ofilepath = NULL, *obinfilepath = (bf && bf->file)? strdup (bf->file): NULL;
ut64 laddr = r_core_get_cur_laddr (core);

bool ret = false;
ut64 origoff = core->offset;
if (odesc) {
Expand Down Expand Up @@ -603,7 +623,7 @@ static bool linkcb(void *user, void *data, ut32 id) {

R_API bool r_core_bin_load(RCore *r, const char *filenameuri, ut64 baddr) {
r_return_val_if_fail (r && r->io, false);
ut64 laddr = r_config_get_i (r->config, "bin.laddr");
ut64 laddr = r_core_get_cur_laddr (r);
RBinFile *binfile = NULL;
RBinPlugin *plugin = NULL;
const char *cmd_load;
Expand Down Expand Up @@ -911,11 +931,6 @@ R_API RIODesc *r_core_file_open(RCore *r, const char *file, int flags, ut64 load
}
}
}
//used by r_core_bin_load otherwise won't load correctly
//this should be argument of r_core_bin_load <shrug>
if (loadaddr != UT64_MAX) {
r_config_set_i (r->config, "bin.laddr", loadaddr);
}
r_core_cmd0 (r, "=!");
beach:
r->times->file_open_time = r_time_now_mono () - prev;
Expand Down
14 changes: 14 additions & 0 deletions libr/core/cmd_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ static void r_core_file_info(RCore *core, PJ *pj, int mode) {
pj_ks (pj, "referer", desc->referer);
}
}
ut64 laddr = r_core_get_cur_laddr (core);
if (laddr) {
pj_kn (pj, "laddr", laddr);
}
int v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MIN_OP_SIZE);
if (v > 0) {
pj_ki (pj, "minopsz", v);
Expand Down Expand Up @@ -292,6 +296,16 @@ static void r_core_file_info(RCore *core, PJ *pj, int mode) {
r_num_units (humansz, sizeof (humansz), fsz);
pair ("humansz", humansz);
}
ut64 laddr = r_core_get_cur_laddr (core);
if (laddr && laddr != UT64_MAX) {
char *laddrs = sdb_itoa (laddr, NULL, 16);
pair ("laddr", laddrs);
free (laddrs);
}
}
ut64 laddr = r_core_get_cur_laddr (core);
if (laddr) {
pair ("laddr", r_strf ("0x%"PFMT64x, laddr));
}
int v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MIN_OP_SIZE);
if (v > 0) {
Expand Down
4 changes: 2 additions & 2 deletions libr/core/cmd_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,7 @@ static bool __rebase_refs(void *user, const ut64 k, const void *v) {
static void __rebase_everything(RCore *core, RList *old_sections, ut64 old_base) {
RListIter *it, *itit, *ititit;
RAnalFunction *fcn;
ut64 new_base = core->bin->cur->o->baddr_shift;
ut64 new_base = (core->bin->cur && core->bin->cur->o)? core->bin->cur->o->baddr_shift: 0;
RBinSection *old_section;
ut64 diff = new_base - old_base;
if (!diff) {
Expand Down Expand Up @@ -1417,7 +1417,7 @@ R_API void r_core_file_reopen_debug(RCore *core, const char *args) {
}

RList *old_sections = __save_old_sections (core);
ut64 old_base = core->bin->cur->o->baddr_shift;
ut64 old_base = (core->bin->cur && core->bin->cur->o)? core->bin->cur->o->baddr_shift: 0;
int bits = core->rasm->config->bits;
char *bin_abspath = r_file_abspath (binpath);
if (strstr (bin_abspath, "://")) {
Expand Down
2 changes: 1 addition & 1 deletion libr/core/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -3695,7 +3695,7 @@ R_API bool r_core_serve(RCore *core, RIODesc *file) {
if (!ptr) {
r_cons_eprintf ("Cannot malloc in rmt-open len = %d\n", cmd);
} else {
ut64 baddr = r_config_get_i (core->config, "bin.laddr");
ut64 baddr = r_core_get_cur_laddr (core);
r_socket_read_block (c, ptr, cmd);
ptr[cmd] = 0;
ut32 perm = R_PERM_R;
Expand Down
1 change: 1 addition & 0 deletions libr/include/r_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ R_API int r_core_search_cb(RCore *core, ut64 from, ut64 to, RCoreSearchCallback
R_API bool r_core_serve(RCore *core, RIODesc *fd);

// RCoreFile APIs (bind, riodesc + rbinfile)
R_API ut64 r_core_get_cur_laddr(RCore *core);
R_API bool r_core_file_reopen(RCore *core, const char *args, int perm, int binload);
R_API void r_core_file_reopen_debug(RCore *core, const char *args);
R_API void r_core_file_reopen_remote_debug(RCore *core, char *uri, ut64 addr);
Expand Down

0 comments on commit 16b6c84

Please sign in to comment.