Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
i'm trying to retrieve library symbols addresses by name using DynaLoader.
I have compared the result with a C programm using this function"#!/usr/bin/perl # use DynaLoader; push(@dl_library_path,'/lib'); my $symbol=$ARGV[0]; @dl_resolve_using = DynaLoader::dl_findfile(qw(-ldl -lc)); my $lib_name='/lib/libc.so.6'; my $libref=DynaLoader::dl_load_file($lib_name,0x00001); if (not defined $libref) { die "load lib: $! \n";} my $symref =DynaLoader::dl_find_symbol($libref, $symbol); #$symref -= 0x74000; printf "%s : %4x \n",$symbol,$symref;
int search(char *pattern) { void *p; int addr; /* dlopen() the main program */ if ( !(p = dlopen(NULL, RTLD_LAZY)) ) { fprintf(stderr, "%s\n", dlerror()); exit(-1); } /* search for the pattern */ if ( !(addr = (int)dlsym(p, pattern)) ) { fprintf(stderr, "%s\n", dlerror()); exit(-1); } dlclose(p); return(addr); }
i have got an offset beetween the 2 results..
here the value is 0x74000$ ./lib.pl system system : 0x400c52f0 $ ./libcs -s system system: 0x400512f0 $ ./lib.pl printf printf : 0x400d0d44 $ ./libcs -s printf printf: 0x4005cd44
Thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: retrieve libs symbols with DynaLoader
by chromatic (Archbishop) on Jul 12, 2006 at 05:54 UTC | |
by Anonymous Monk on Jul 12, 2006 at 14:56 UTC | |
by chromatic (Archbishop) on Jul 12, 2006 at 16:23 UTC |