avs333/Nougat_dlfunctions

Why bias should set in fake_dlfcn?

Closed this issue · 1 comments

The fake_dlfcn.c is very useful, but I can't understand why set ctx->bias like that.

case SHT_PROGBITS: if(!ctx->dynstr || !ctx->dynsym) break; /* won't even bother checking against the section name */ ctx->bias = (off_t) sh->sh_addr - (off_t) sh->sh_offset; k = elf->e_shnum; /* exit for */ break;

There could be other SHT_PROGBITS in ELF file.
I read other hook code, it seems not set the bias at all. example: https://github.com/crmulliner/adbi/blob/master/hijack/hijack.c

I test the fake_dlfcn,It works OK。So Could you please tell me why set bias like that?

All leading PROGBITS sections go to the same segment, and we exit as soon as dynstr and dynsym offsets are known and we've found the bias of the first one after them. The bias value is required of course (take any large c++ lib to check that it's indeed so). Please see Android linker.cpp for details, and the excellent Oracle's "Linker and Libraries Guide" for that matter!