Skip to content

Commit

Permalink
Add dbg.glibc.path eval var to override magic guessing ##debug
Browse files Browse the repository at this point in the history
  • Loading branch information
radare authored and trufae committed Oct 6, 2023
1 parent 4eedb3a commit 3ff28b4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions libr/core/cconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -3575,6 +3575,7 @@ R_API int r_core_config_init(RCore *core) {
#endif
SETDESC (n, "choose malloc structure parser");
SETOPTIONS (n, "glibc", "jemalloc", NULL);
SETBPREF ("dbg.glibc.path", "", "if not empty, use the given path to resolve the libc");
#if __GLIBC_MINOR__ > 25
SETBPREF ("dbg.glibc.tcache", "true", "parse the tcache (glibc.minor > 2.25.x)");
#else
Expand Down
21 changes: 16 additions & 5 deletions libr/core/dmh_glibc.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,21 +393,32 @@ static bool GH(r_resolve_main_arena)(RCore *core, GHT *m_arena) {
GHT libc_addr_sta = GHT_MAX, libc_addr_end = 0;
GHT main_arena_sym = GHT_MAX;
const bool in_debugger = r_config_get_b (core->config, "cfg.debug");
bool first_libc = true;

if (in_debugger) {
const char *dbg_glibc_path = r_config_get (core->config, "dbg.glibc.path");
if (R_STR_ISEMPTY (dbg_glibc_path)) {
dbg_glibc_path = NULL;
}
bool first_libc = true;
RListIter *iter;
RDebugMap *map;
r_debug_map_sync (core->dbg);
r_list_foreach (core->dbg->maps, iter, map) {
if (dbg_glibc_path) {
if (map->perm == R_PERM_RW && strstr (map->name, dbg_glibc_path)) {
libc_addr_sta = map->addr;
libc_addr_end = map->addr_end;
main_arena_sym = GH (get_main_arena_with_symbol) (core, map);
break;
}
continue;
}
/* Try to find the main arena address using the glibc's symbols. */
if ((strstr (map->name, "/libc-") || strstr (map->name, "/libc."))
&& first_libc && main_arena_sym == GHT_MAX) {
if ((first_libc && main_arena_sym == GHT_MAX) && (strstr (map->name, "/libc-") || strstr (map->name, "/libc."))) {
first_libc = false;
main_arena_sym = GH (get_main_arena_with_symbol) (core, map);
}
if ((strstr (map->name, "/libc-") || strstr (map->name, "/libc."))
&& map->perm == R_PERM_RW) {
if (map->perm == R_PERM_RW && (strstr (map->name, "/libc-") || strstr (map->name, "/libc."))) {
libc_addr_sta = map->addr;
libc_addr_end = map->addr_end;
break;
Expand Down

0 comments on commit 3ff28b4

Please sign in to comment.