(4-bytes) (Py_ssize_t) references count (4-bytes) (pointer) object type (4-bytes) (pointer) memory address of the buffer location (10-bytes) (array) preview (4-bytes) (Py_ssize_t) buffer size (4-bytes) (Py_ssize_t) string size Binary IO with structs 32-bit gives 4-billions addresses (that's enough addressing for max. 4G of memory) address arithmetic? overflow is when there isn't any space left to put a number -- i.e, fixed size. pmap $PYTHON_PID -> process map (check the heap) /proc/$PYTHON_PID/maps string needs to be NULL terminated strncpy as a for-loop Prototypes are for error-checking. You can't know how many arguments a function from an external object takes. Structures align the memory. Big/little endian 4-bytes chunks, MAXSIZE=10 has a size of 12 dynamic loading (dload.so) >>> import spam >>> s = spam.Spam() >>> s.put_stuff("Hello, I am the king of the world!") 34 >>> s.dump() % hd dump-file 00000000 02 00 00 00 80 41 f4 b7 60 dc 1c 08 48 65 6c 6c |.....A..`...Hell| 00000010 6f 2c 20 49 20 61 6d 20 00 01 00 00 22 00 00 00 |o, I am ...."...| 00000020 >>> def get_addr(bytes): ... return "0x" + "".join(reversed(bytes.split())) ... >>> mem = open("/proc/%i/mem" % os.getpid()) >>> get_addr("60 dc 1c 08") '0x081cdc60' >>> mem.seek(0x081cdc60) >>> f.read(34) 'Hello, I am the king of the world!' % cat /proc/21289/maps 08048000-0813f000 r-xp 00000000 08:01 1832494 /usr/bin/python2.5 0813f000-08164000 rw-p 000f6000 08:01 1832494 /usr/bin/python2.5 08164000-081dd000 rw-p 08164000 00:00 0 [heap] ... b7f43000-b7f44000 r-xp 00000000 08:02 1425420 /home/alex/code/python/ext/build/lib.linux-i686-2.5/spam.so b7f44000-b7f45000 rw-p 00001000 08:02 1425420 /home/alex/code/python/ext/build/lib.linux-i686-2.5/spam.so b7f45000-b7f48000 rw-p b7f45000 00:00 0 b7f48000-b7f61000 r-xp 00000000 08:01 2649039 /lib/ld-2.5.so b7f61000-b7f63000 rw-p 00019000 08:01 2649039 /lib/ld-2.5.so bfacf000-bfae5000 rw-p bfacf000 00:00 0 [stack] ffffe000-fffff000 r-xp 00000000 00:00 0 [vdso] >>> f = open("dump-file") >>> data = f.read() >>> import struct >>> struct.unpack("<12slll", data[12:]) ('Hello World!', 256, 12, 3) >>> s = struct.unpack(">> s (136109904, 'Hello World!', 256, 12, 3) >>> "%.8x" % s[0] '081cdf50'