Fix duplicated entry symbols in macho ##bin (#17277)

* Cleaner attempt to fix the ghost macho symbols ##bin

Co-authored-by: pancake <pancake@nopcode.org>
This commit is contained in:
pancake 2020-07-15 02:35:20 +02:00 committed by GitHub
parent d6ad8766e8
commit 2949708687
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 3 deletions

View File

@ -2948,7 +2948,9 @@ const struct symbol_t *MACH0_(get_symbols)(struct MACH0_(obj_t) *bin) {
for (i = 0; i < bin->nsymtab; i++) {
struct MACH0_(nlist) *st = &bin->symtab[i];
stridx = st->n_strx;
if (st->n_type & N_STAB) {
continue;
}
// 0 is for imports
// 1 is for symbols
// 2 is for func.eh (exception handlers?)
@ -2964,11 +2966,12 @@ const struct symbol_t *MACH0_(get_symbols)(struct MACH0_(obj_t) *bin) {
} else {
symbols[j].type = R_BIN_MACH0_SYMBOL_TYPE_LOCAL;
}
stridx = st->n_strx;
char *sym_name = get_name (bin, stridx, false);
if (sym_name) {
symbols[j].name = sym_name;
} else {
symbols[j].name = r_str_newf ("entry%d\n", i);
symbols[j].name = r_str_newf ("entry%d", i);
//symbols[j].name[0] = 0;
}
symbols[j].last = 0;

View File

@ -4482,4 +4482,16 @@ EOF
EXPECT_ERR=<<EOF
Warning: run r2 with -e io.cache=true to fix relocations in disassembly
EOF
RUN
RUN
NAME=macho-ghost-symbols
FILE=bins/mach0/libr_flag.dylib
CMDS=<<EOF
is~?
is~entry?
EOF
EXPECT=<<EOF
247
0
EOF
RUN