import ffiimport uctypeslibc = ffi.open("libc.so.6")print("libc:", libc)print()# Declare few functionsperror = libc.func("v", "perror", "s")time = libc.func("i", "time", "p")open = libc.func("i", "open", "si")qsort = libc.func("v", "qsort", "piiC")# And one variableerrno = libc.var("i", "errno")print("time:", time)print("UNIX time is:", time(None))print()perror("perror before error")open("somethingnonexistent__", 0)print("errno object:", errno)print("errno value:", errno.get())perror("perror after error")print()def cmp(pa, pb):a = uctypes.bytearray_at(pa, 1)b = uctypes.bytearray_at(pb, 1)print("cmp:", a, b)return a[0] - b[0]cmp_cb = ffi.callback("i", cmp, "PP")print("callback:", cmp_cb)s = bytearray(b"foobar")print("org string:", s)qsort(s, len(s), 1, cmp_cb)print("qsort'ed string:", s)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。