我们都知道soinfo信息都会有指向下一个soinfo的信息.通过这个单向链表我们就可以定位所有的so文件.
那么要定位所有的so文件,首先要找到链表的第一个.
其实非常简单就是somain.
获取somain也非常简单,调用dlopen时name传入null即可.
代码如下:
#define LOGD(...) android_log_print(ANDROID_LOG_DEBUG, TAG, VA_ARGS__)
#define SOINFO_NAME_LEN 128
typedef void (*linker_function_t)();
struct link_map_t {
uintptr_t l_addr;
char l_name;
uintptr_t l_ld;
link_map_t l_next;
link_map_t* l_prev;
};
struct soinfo {
public:
char name[SOINFO_NAME_LEN];
const Elf32_Phdr* phdr;
size_t phnum;
Elf32_Addr entry;
Elf32_Addr base;
unsigned size;
#if defined(ANDROID_ARM_LINKER)
// ARM EABI section used for stack unwinding.
unsigned* ARM_exidx;
size_t ARM_exidx_count;
#elif defined(ANDROID_MIPS_LINKER)
unsigned mips_symtabno;
unsigned mips_local_gotno;
unsigned mips_gotsym;
#endif
private:
void CallArray(const char array_name, linker_function_t functions, size_t count, bool reverse);
void CallFunction(const char* function_name, linker_function_t function);
};
soinfo getsolist()
{
return (soinfo )dlopen(0,0);
}
//两行代码遍历所有的模块,而且信息更加的细致
void printAllModule()
{
soinfo somain = (soinfo )dlopen(0,0);
while(somain){LOGD("%s",somain->name);somain = somain->next;};
}
static soinfo find_loaded_library(const char name)
{
soinfo si;
const char bname;
}
soinfo find_containing_library(const void p) {
Elf32_Addr address = reinterpret_cast<Elf32_Addr>(p);
for (soinfo si = (soinfo )dlopen(0,0); si != NULL; si = si->next) {
if (address >= si->base && address - si->base < si->size) {
return si;
}
}
return NULL;
}
unsigned elfhash(const char _name) {
const unsigned char name = (const unsigned char*) _name;
unsigned h = 0, g;
}
static Elf32_Sym soinfo_elf_lookup(soinfo si, unsigned hash, const char name) {
Elf32_Sym symtab = si->symtab;
const char* strtab = si->strtab;
}
void my_dlsym(soinfo si,const char name)
{
Elf32_Sym s = soinfo_elf_lookup(si,elfhash(name),name);
if(sym)
{
return (void *)(s->st_value + si->load_bias);
}
else
{
return nullptr;
}
}
bool dumpso(soinfo so,const char savepath)
{
const Elf32_Phdr phdr;
char Filemem = (char *)malloc(so->size);
Elf32_Addr loadbias = so->load_bias;
size_t fileSize = 0;
if(!Filemem)
return false;
for(int i=0;i<so->phnum;i++)
{
phdr = &(so->phdr[i]);
if(phdr->p_type != PT_LOAD)
{
continue;
}
}
```
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课