Jump to content

  • Log In with Google      Sign In   
  • Create Account

[linux] getting the start address of an executable


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Gnarmock   Members   -  Reputation: 102

Like
0Likes
Like

Posted 19 January 2013 - 09:39 AM

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



Sponsor:

#2 kd7tck   Members   -  Reputation: 715

Like
0Likes
Like

Posted 19 January 2013 - 05:08 PM

You say you are in a module. Where is the module run from?

More detailed info is needed.

 

Look over the man pages and look for anything you might have missed. In the mean time I will think your situation over and get back to you in an hour or so.

 

edit: Possible solution, another.


Edited by kd7tck, 19 January 2013 - 05:24 PM.


#3 kd7tck   Members   -  Reputation: 715

Like
0Likes
Like

Posted 19 January 2013 - 05:59 PM

How exactly did you use dlopen? Also why must it obtain the address of an executable, would it not be easier to compile it as a library, then obtain that address. A library can just as easily be run like an executable, only it requires a separate launcher to do so.

 

Here is a link to something similar.


Edited by kd7tck, 19 January 2013 - 10:56 PM.


#4 Katie   Members   -  Reputation: 1331

Like
0Likes
Like

Posted 20 January 2013 - 12:05 PM

Why are you trying to do this -- what is that you're actually trying to achieve?






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS