Basic usage

suggest change

Let’s say we want to use libc’s ntohl function.

First, we must load libc.so:

>>> from ctypes import *
>>> libc = cdll.LoadLibrary('libc.so.6')
>>> libc
<CDLL 'libc.so.6', handle baadf00d at 0xdeadbeef>

Then, we get the function object:

>>> ntohl = libc.ntohl
>>> ntohl
<_FuncPtr object at 0xbaadf00d>

And now, we can simply invoke the function:

>>> ntohl(0x6C)
1811939328
>>> hex(_)
'0x6c000000'

Which does exactly what we expect it to do.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents