Esempio n. 1
0
    def __init__(self):
        clib = cdll.LoadLibrary("libc.so.6")
        clib.iopl(3)

        opc = IN_PORT
        size = len(opc)
        code = (c_ubyte * size)(*opc)
        self.addr = mmap.mmap(-1,
                              mmap.PAGESIZE,
                              prot=mmap.PROT_READ | mmap.PROT_WRITE
                              | mmap.PROT_EXEC)
        self.addr.write(bytes(code))
        in_func_type = CFUNCTYPE(c_uint32, c_uint16)
        self.in_fp = c_void_p.from_buffer(self.addr)
        self.inl_ptr = in_func_type(addressof(self.in_fp))

        opc = OUT_PORT
        size = len(opc)
        code = (c_ubyte * size)(*opc)
        self.addr = mmap.mmap(-1,
                              mmap.PAGESIZE,
                              prot=mmap.PROT_READ | mmap.PROT_WRITE
                              | mmap.PROT_EXEC)
        self.addr.write(bytes(code))
        out_func_type = CFUNCTYPE(None, c_uint32, c_uint16)
        self.out_fp = c_void_p.from_buffer(self.addr)
        self.outl_ptr = out_func_type(addressof(self.out_fp))
Esempio n. 2
0
def sixel_encoder_encode_bytes(encoder, buf, width, height, pixelformat,
                               palette):

    depth = sixel_helper_compute_depth(pixelformat)

    if depth <= 0:
        raise ValueError("invalid pixelformat value : %d" % pixelformat)

    if len(buf) < width * height * depth:
        raise ValueError("buf.len is too short : %d < %d * %d * %d" %
                         (buf.len, width, height, depth))

    if not hasattr(buf, "readonly") or buf.readonly:
        cbuf = c_void_p.from_buffer_copy(buf)
    else:
        cbuf = c_void_p.from_buffer(buf)

    if palette:
        cpalettelen = len(palette)
        cpalette = (c_byte * cpalettelen)(*palette)
    else:
        cpalettelen = None
        cpalette = None

    _sixel.sixel_encoder_encode_bytes.restype = c_int
    _sixel.sixel_encoder_encode.argtypes = [
        c_void_p, c_void_p, c_int, c_int, c_int, c_void_p, c_int
    ]

    status = _sixel.sixel_encoder_encode_bytes(encoder, buf, width, height,
                                               pixelformat, cpalette,
                                               cpalettelen)
    if SIXEL_FAILED(status):
        message = sixel_helper_format_error(status)
        raise RuntimeError(message)
Esempio n. 3
0
 def insert_tail(self,item):
     elem = TAILQ_ENTRY.from_buffer(item[0],self.entries)
     elem.tqe_next = None
     elem.tqe_prev = self.ref[0].tqh_last
     tqh_last = c_void_p.from_buffer(self.ref[0].tqh_last.contents)
     tqh_last.value = ctypes.addressof(item[0])
     self.ref.tqh_last = pointer(elem.tqe_next)
Esempio n. 4
0
def sixel_encoder_encode_bytes(encoder, buf, width, height, pixelformat, palette):

    depth = sixel_helper_compute_depth(pixelformat)

    if depth <= 0:
        raise ValueError("invalid pixelformat value : %d" % pixelformat)

    if len(buf) < width * height * depth:
        raise ValueError("buf.len is too short : %d < %d * %d * %d" % (buf.len, width, height, depth))

    if not hasattr(buf, "readonly") or buf.readonly:
        cbuf = c_void_p.from_buffer_copy(buf)
    else:
        cbuf = c_void_p.from_buffer(buf)

    if palette:
        cpalettelen = len(palette)
        cpalette = (c_byte * cpalettelen)(*palette)
    else:
        cpalettelen = None
        cpalette = None

    _sixel.sixel_encoder_encode_bytes.restype = c_int
    _sixel.sixel_encoder_encode.argtypes = [c_void_p, c_void_p, c_int, c_int, c_int, c_void_p, c_int]

    status = _sixel.sixel_encoder_encode_bytes(encoder, buf, width, height, pixelformat, cpalette, cpalettelen)
    if SIXEL_FAILED(status):
        message = sixel_helper_format_error(status)
        raise RuntimeError(message)
Esempio n. 5
0
 def insert_tail(self,item):
     elem = TAILQ_ENTRY.from_buffer(item[0],self.entries)
     elem.tqe_next = None
     elem.tqe_prev = self.ref[0].tqh_last
     tqh_last = c_void_p.from_buffer(self.ref[0].tqh_last.contents)
     tqh_last.value = ctypes.addressof(item[0])
     self.ref.tqh_last = pointer(elem.tqe_next)
Esempio n. 6
0
    def __init__(self):
        if platform.machine() not in ("AMD64", "x86_64", "x86", "i686"):
            raise SystemError("Only available for x86")

        opc = _POSIX_64_OPC if is_64bit else _CDECL_32_OPC

        size = len(opc)
        code = (c_ubyte * size)(*opc)

        self.addr = mmap.mmap(-1,
                              mmap.PAGESIZE,
                              prot=mmap.PROT_READ | mmap.PROT_WRITE
                              | mmap.PROT_EXEC)
        self.addr.write(bytes(code))

        func_type = CFUNCTYPE(None, POINTER(CPUID_struct), c_uint32, c_uint32)
        self.fp = c_void_p.from_buffer(self.addr)
        self.func_ptr = func_type(addressof(self.fp))
Esempio n. 7
0
 def value(self,
           c_void_p=ctypes.c_void_p):
     addr = c_void_p.from_buffer(self).value
     return utf16tostr(addr)
Esempio n. 8
0
 def value(self, c_void_p=ctypes.c_void_p):
     addr = c_void_p.from_buffer(self).value
     return utf16tostr(addr)
def numpyBuffer(arr):
    return ctypes.addressof(c_void_p.from_buffer(arr))