blob: 87f627521b6cf3a78645493594ecb533bd18225f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
from ctypes import *
dll = CDLL("./libcreole.so")
class CIns(Structure):
_fields_ = [("opcode", c_int),
("w_flags", c_ubyte * 3),
("w", c_uint * 3)]
class CReader(Structure):
_fields_ = [("p", POINTER(c_ubyte)),
("left", c_size_t)]
def make_uchar_buf(s):
buf = (c_ubyte * len(s))()
buf[:] = s[:]
return buf
class CParseLineException(Exception):
pass
def parse_line(line):
buf = make_uchar_buf(line)
rd = CReader(buf, len(line))
ins = CIns()
ret = dll.creole_parse_line(byref(ins), byref(rd))
if ret != 0:
raise CParseLineException(ret)
return (ins.opcode, list(zip(ins.w_flags, ins.w)))
|