Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: remove bin.laddr #19691

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion libr/core/cbin.c
Original file line number Diff line number Diff line change
Expand Up @@ -4361,7 +4361,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 @@ -3697,7 +3697,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.str.min", 0, &cb_binminstr, "minimum string length for r_bin");
Expand Down
31 changes: 25 additions & 6 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 @@ -612,7 +632,11 @@ 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);
R_CRITICAL_ENTER (r);
#if 0
ut64 laddr = r_config_get_i (r->config, "bin.laddr");
#else
ut64 laddr = r_core_get_cur_laddr (r);
#endif
RBinFile *binfile = NULL;
RBinPlugin *plugin = NULL;
const char *cmd_load;
Expand Down Expand Up @@ -924,11 +948,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);
}
pj_ki (pj, "block", core->blocksize);
if (binfile) {
if (binfile->curxtr) {
Expand Down Expand Up @@ -276,6 +280,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 = r_str_newf ("0x%08"PFMT64x, laddr);
pair ("laddr", laddrs);
free (laddrs);
}
}
ut64 laddr = r_core_get_cur_laddr (core);
if (laddr) {
pair ("laddr", r_strf ("0x%"PFMT64x, laddr));
}
if (desc) {
pair ("mode", r_str_rwx_i (desc->perm & R_PERM_RWX));
Expand Down
2 changes: 1 addition & 1 deletion libr/core/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -3753,7 +3753,7 @@ R_API bool r_core_serve(RCore *core, RIODesc *file) {
if (!ptr) {
R_LOG_ERROR ("Cannot malloc in rmt-open len = %d", 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 @@ -537,6 +537,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