How to browse a C Library with Python

G

georg.heiss

Hello,
with Python it is simple to call direct functions from c-librarys.
Is there a way to browse over a library i.e. '/lib/libc.so' with
python, to see all possible functions in a library?

#!/python
import dl, time
i = 1
line = "Python ist geil, weil ich direkt auf C librarys zugreifen kann!
\n"
print line
a = dl.open('/lib/libc.so')
print 'call c-function direct from /lib/libc.so'
i = a.call('time')
print i
print 'call function from python'
i = time.time()
print i
#########################################################
Regards
Georg
 
G

Gabriel Genellina

with Python it is simple to call direct functions from c-librarys.
Is there a way to browse over a library i.e. '/lib/libc.so' with
python, to see all possible functions in a library?

You could use the subprocess module to execute 'nm /lib/libc.so' and look
at lines with type T.
 
R

Rafael Sachetto

with Python it is simple to call direct functions from c-librarys.
You could use the subprocess module to execute 'nm /lib/libc.so' and look
at lines with type T.

To do this on a dynamic library you have to use nm -D /lib/libc.so
 
R

Rafael Sachetto

This could be a solution

import commands

callables = commands.getoutput("nm -D /lib/libc.so.6 | egrep ' T '
").split("\n")
callables = [c.split()[2] for c in callables]

print callables
 
G

georg.heiss

This could be a solution

import commands

callables = commands.getoutput("nm -D /lib/libc.so.6 | egrep ' T '
").split("\n")
callables = [c.split()[2] for c in callables]

print callables

To do this on a dynamiclibraryyou have to use nm -D /lib/libc.so

--
Rafael Sachetto Oliveira

Sir - Simple Image Resizerhttp://rsachetto.googlepages.com- Zitierten Text ausblenden -

- Zitierten Text anzeigen -

works fine ..., thanks a lot georg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top