Skip to content

Commit

Permalink
Fix symbol range bug in isq. ##bin
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Oct 27, 2023
1 parent 6e57ac7 commit 5e543e1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 29 deletions.
10 changes: 6 additions & 4 deletions libr/core/cbin.c
Original file line number Diff line number Diff line change
Expand Up @@ -2458,13 +2458,15 @@ static bool bin_symbols(RCore *r, PJ *pj, int mode, ut64 laddr, int va, ut64 at,
continue;
}
ut64 addr = compute_addr (r->bin, symbol->paddr, symbol->vaddr, va);
ut32 len = symbol->size ? symbol->size : 32;
ut32 len = symbol->size ? symbol->size : 1;
if (at != UT64_MAX && (!symbol->size || !is_in_range (at, addr, symbol->size))) {
continue;
}
if ((printHere && !is_in_range (r->offset, symbol->paddr, len))
&& (printHere && !is_in_range (r->offset, addr, len))) {
continue;
if (printHere) {
// const ut64 addr = va? symbol->vaddr: symbol->paddr;
if (!is_in_range (r->offset, addr, len)) {
continue;
}
}
SymName sn = {0};
snInit (r, &sn, symbol, lang);
Expand Down
13 changes: 7 additions & 6 deletions libr/core/cmd_info.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1040,10 +1040,10 @@ static int cmd_info(void *data, const char *input) {
RList *objs = r_core_bin_files (core);
RListIter *iter;
RBinFile *bf;
if (input[1] == 'j' && input[2] == '.') {
if (input[1] == 'j' && input[2] == '.') { // "isj" "is."
mode = R_MODE_JSON;
INIT_PJ ();
} else if (input[1] == 'q' && input[2] == 'q') {
} else if (input[1] == 'q' && input[2] == 'q') { // "isq"
mode = R_MODE_SIMPLEST;
}
r_list_foreach (objs, iter, bf) {
Expand All @@ -1056,20 +1056,21 @@ static int cmd_info(void *data, const char *input) {
#if R2_590
// TODO: use obj->symbols_vec if obj->symbols is null
#else
size_t symcount = (obj && obj->symbols)? r_list_length (obj->symbols): 0;
if (input[1] == 'j' && input[2] == '.') {
RBININFO ("symbols", R_CORE_BIN_ACC_SYMBOLS, input + 2, (obj && obj->symbols)? r_list_length (obj->symbols): 0);
RBININFO ("symbols", R_CORE_BIN_ACC_SYMBOLS, input + 2, symcount);
} else if (input[1] == ',') {
R_FREE (core->table_query);
core->table_query = strdup (input + 2);
RBININFO ("symbols", R_CORE_BIN_ACC_SYMBOLS, input + 1, (obj && obj->symbols)? r_list_length (obj->symbols): 0);
RBININFO ("symbols", R_CORE_BIN_ACC_SYMBOLS, input + 1, symcount);
} else if (input[1] == 'q' && input[2] == 'q') {
mode = R_MODE_SIMPLEST;
RBININFO ("symbols", R_CORE_BIN_ACC_SYMBOLS, input + 3, (obj && obj->symbols)? r_list_length (obj->symbols): 0);
RBININFO ("symbols", R_CORE_BIN_ACC_SYMBOLS, input + 3, symcount);
} else if (input[1] == 'q' && input[2] == '.') {
mode = R_MODE_SIMPLE;
RBININFO ("symbols", R_CORE_BIN_ACC_SYMBOLS, input + 2, 0);
} else {
RBININFO ("symbols", R_CORE_BIN_ACC_SYMBOLS, input + 1, (obj && obj->symbols)? r_list_length (obj->symbols): 0);
RBININFO ("symbols", R_CORE_BIN_ACC_SYMBOLS, input + 1, symcount);
}
#endif
}
Expand Down
12 changes: 12 additions & 0 deletions test/db/cmd/cmd_i
Original file line number Diff line number Diff line change
Expand Up @@ -4241,3 +4241,15 @@ Cs 13 @ 0x080484b0
163
EOF
RUN

NAME=isqq bug
FILE=bins/mach0/WheresMyBrowser
CMDS=<<EOF
is.@0x100023b68
EOF
EXPECT=<<EOF
nth paddr vaddr bind type size lib name demangled
--------------------------------------------------------------------
1503 0x00023b68 0x100023b68 LOCAL FUNC 0 imp.memcpy
EOF
RUN
38 changes: 19 additions & 19 deletions test/db/formats/dwarf
Original file line number Diff line number Diff line change
Expand Up @@ -721,26 +721,26 @@ colu: 12
addr: 0x00001149
EOF
EXPECT_ERR=<<EOF
DEBUG: [cbin.c:3253] (section .dynstr) Css 141 @ 0x480
DEBUG: [cbin.c:3253] (section .rela.dyn) Cd 8[24] @ 0x550
DEBUG: [cbin.c:3253] (section .rela.plt) Cd 8[3] @ 0x610
DEBUG: [cbin.c:3253] (section .init_array) Cd 8[1] @ 0x3db8
DEBUG: [cbin.c:3253] (section .fini_array) Cd 8[1] @ 0x3dc0
DEBUG: [cbin.c:3253] (section .dynamic) Cd 8[62] @ 0x3dc8
DEBUG: [cbin.c:3253] (section .got) Cd 8[9] @ 0x3fb8
DEBUG: [cbin.c:3253] (section .dynstr) Css 141 @ 0x480
DEBUG: [cbin.c:3253] (section .rela.dyn) Cd 8[24] @ 0x550
DEBUG: [cbin.c:3253] (section .rela.plt) Cd 8[3] @ 0x610
DEBUG: [cbin.c:3253] (section .init_array) Cd 8[1] @ 0x3db8
DEBUG: [cbin.c:3253] (section .fini_array) Cd 8[1] @ 0x3dc0
DEBUG: [cbin.c:3253] (section .dynamic) Cd 8[62] @ 0x3dc8
DEBUG: [cbin.c:3253] (section .got) Cd 8[9] @ 0x3fb8
DEBUG: [cbin.c:3255] (section .dynstr) Css 141 @ 0x480
DEBUG: [cbin.c:3255] (section .rela.dyn) Cd 8[24] @ 0x550
DEBUG: [cbin.c:3255] (section .rela.plt) Cd 8[3] @ 0x610
DEBUG: [cbin.c:3255] (section .init_array) Cd 8[1] @ 0x3db8
DEBUG: [cbin.c:3255] (section .fini_array) Cd 8[1] @ 0x3dc0
DEBUG: [cbin.c:3255] (section .dynamic) Cd 8[62] @ 0x3dc8
DEBUG: [cbin.c:3255] (section .got) Cd 8[9] @ 0x3fb8
DEBUG: [cbin.c:3255] (section .dynstr) Css 141 @ 0x480
DEBUG: [cbin.c:3255] (section .rela.dyn) Cd 8[24] @ 0x550
DEBUG: [cbin.c:3255] (section .rela.plt) Cd 8[3] @ 0x610
DEBUG: [cbin.c:3255] (section .init_array) Cd 8[1] @ 0x3db8
DEBUG: [cbin.c:3255] (section .fini_array) Cd 8[1] @ 0x3dc0
DEBUG: [cbin.c:3255] (section .dynamic) Cd 8[62] @ 0x3dc8
DEBUG: [cbin.c:3255] (section .got) Cd 8[9] @ 0x3fb8
WARN: [cbin.c:1832] Relocs has not been applied. Please use `-e bin.relocs.apply=true` or `-e bin.cache=true` next time
DEBUG: [cbin.c:2518] Cannot resolve symbol address __libc_start_main
DEBUG: [cbin.c:2518] Cannot resolve symbol address _ITM_deregisterTMCloneTable
DEBUG: [cbin.c:2518] Cannot resolve symbol address __gmon_start__
DEBUG: [cbin.c:2518] Cannot resolve symbol address _ITM_registerTMCloneTable
DEBUG: [cbin.c:2518] Cannot resolve symbol address __cxa_finalize
DEBUG: [cbin.c:2520] Cannot resolve symbol address __libc_start_main
DEBUG: [cbin.c:2520] Cannot resolve symbol address _ITM_deregisterTMCloneTable
DEBUG: [cbin.c:2520] Cannot resolve symbol address __gmon_start__
DEBUG: [cbin.c:2520] Cannot resolve symbol address _ITM_registerTMCloneTable
DEBUG: [cbin.c:2520] Cannot resolve symbol address __cxa_finalize
EOF
RUN

Expand Down

0 comments on commit 5e543e1

Please sign in to comment.