from ctypes import *
libc = CDLL('libc.so.6')
print(libc)
print(libc.printf)
buf = create_string_buffer(50)
print(buf)
libc.sprintf(buf, b'Hello %s\n', b'World')
print(buf.value)
class Test(Structure):
_fields_ = (
('foo', c_int),
('bar', c_char))
t = Test()
t.foo = 1234
t.bar = b'A'
print(t)
from io import BytesIO
b = BytesIO()
b.write(t)
b.seek(0)
data = b.read()
print(data)
b = BytesIO(data)
t2 = Test()
b.readinto(t2)
print(t2.foo)
print(t2.bar)
import struct
struct.pack('<IQ4s', 10, 50, b'Test')
struct.unpack('<IQ4s', b'\n\x00\x00\x002\x00\x00\x00\x00\x00\x00\x00Test')