Skip to content

Commit

Permalink
Report where ELF things got mmap()'d.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Feb 21, 2013
1 parent 88ad638 commit 6e3fd50
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
22 changes: 21 additions & 1 deletion macelf/macelf.c
Expand Up @@ -162,7 +162,18 @@ static LoadedLibrary *allocate_loaded_lib(const char *soname, void *handle)
lib->refcount = 1;
if (hash_insert(loaded_ELFs, socpy, lib) == 1)
{
//printf("Loaded ELF soname '%s'!\n", soname);
#if 1
if (!handle)
printf("Loaded native override for '%s'\n", soname);
else
{
void *addr = NULL;
unsigned long len = 0;
MOJOELF_getmmaprange(handle, &addr, &len);
printf("Loaded ELF soname '%s' => %p - %p (%lu bytes).\n",
soname, addr, ((uint8_t *) addr)+(len-1), len);
} // else
#endif
return lib;
} // if

Expand Down Expand Up @@ -675,6 +686,15 @@ int main(int argc, char **argv, char **envp)
return 1;
} // if

else
{
void *addr = NULL;
unsigned long len = 0;
MOJOELF_getmmaprange(lib, &addr, &len);
printf("Loaded ELF executable '%s' => %p - %p (%lu bytes).\n",
argv[startarg], addr, ((uint8_t *) addr)+(len-1), len);
} // else

if ((symbols_missing) || (dependencies_missing))
{
if (report_missing_symbols)
Expand Down
10 changes: 10 additions & 0 deletions mojoelf.c
Expand Up @@ -1297,5 +1297,15 @@ const void *MOJOELF_getentry(void *lib)
return h ? h->entry : NULL;
} // MOJOELF_getentry

void MOJOELF_getmmaprange(void *lib, void **addr, unsigned long *len)
{
const ElfHandle *h = (const ElfHandle *) lib;
if (addr)
*addr = h->mmapaddr;
if (len)
*len = (unsigned long) h->mmaplen;
} // MOJOELF_getmmaprange


// end of mojoelf.c ...

1 change: 1 addition & 0 deletions mojoelf.h
Expand Up @@ -30,6 +30,7 @@ void *MOJOELF_dlsym(void *lib, const char *sym);
void MOJOELF_dlclose(void *lib);
const char *MOJOELF_dlerror(void);
const void *MOJOELF_getentry(void *lib);
void MOJOELF_getmmaprange(void *lib, void **addr, unsigned long *len);

#ifdef __cplusplus
}
Expand Down

0 comments on commit 6e3fd50

Please sign in to comment.