Hello there,
I'm trying to find a better way to get the base address of an executable from within a module.
The library is loaded with LD_PRELOAD and gets initialized via the constructor attribute.
On windows it's possible to call (unsigned int)GetModuleHandle("nameofprog.exe") to get that address.
I tried it with dlopen but it doesn't seem to work, getting invalid returns as it's an executable.
My current approach is to iterate through all the modules of the process, which seems unnecessary.
static int callback(struct dl_phdr_info *info, size_t size, void *data)
{
if( info->dlpi_name[0] == 0 ){
debug_print("Process found.");
Dl_info dl;
int ret = dladdr( (void *) (info->dlpi_addr + info->dlpi_phdr[0].p_vaddr), &dl );
}
return 0;
}
void load()
{
dl_iterate_phdr(callback, NULL);
}
Purpose:
The library has no information exchange with the application, it loads and detours a specified address