File: getshlib.c

package info (click to toggle)
paxtest 0.9.7-pre4-2
  • links: PTS
  • area: main
  • in suites: lenny, squeeze
  • size: 360 kB
  • ctags: 163
  • sloc: ansic: 981; makefile: 708; asm: 53; sh: 49
file content (35 lines) | stat: -rw-r--r-- 806 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* getshlib.c - Get the address of a function in a shared library and print it
 *
 * Copyright (c)2003 by Peter Busser <peter@adamantix.org>
 * This file has been released under the GNU Public Licence version 2 or later
 */

#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>

/* OpenBSD 3.5 doesn't define RTLD_DEFAULT */
/* OpenBSD 3.6 does but it doesn't actually handle (segfaults on) RTLD_DEFAULT, sigh... */
#ifdef __OpenBSD__
#define RTLD_DEFAULT "libc.so"
#endif

int main( int argc, char *argv[] )
{
	void *handle;

	handle = dlopen( RTLD_DEFAULT, RTLD_LAZY );
	if( handle != NULL ) {
		void *sprintf;

		dlerror(); /* clear any errors */
		sprintf = dlsym( handle, "sprintf" );

		if( dlerror() == NULL ) {
			printf( "%0p\n", sprintf );
		}

		dlclose( handle );
	}
}