30 lines
646 B
Python
30 lines
646 B
Python
|
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)))
|