预期的LP_c_ubyte实例而不是str?

时间:2019-03-16 16:22:50

标签: python python-2.7 ctypes

# void _Z8oppitestPhiS_Pi(unsigned char *input, int size, unsigned char *out,int* outlen)
from ctypes import *
import ctypes
import codecs
import os
import sys

z8opp = cdll.LoadLibrary('/home/aada/Desktop/Developpement_1(1)/lib.so')

data = "ff70616464696e673dff6162636465664246ff4c41472d30313233ff3435363738393d0a2b12ff3d6432366138ff6265642d36396430" \
   "ff2d346631622d3935db31660462f66433373902db321c61682a000000000024ff"
data = data.decode('hex')

z8opp._Z8oppitestPhiS_Pi.argtypes = [ctypes.POINTER(ctypes.c_ubyte), ctypes.c_int, ctypes.POINTER(ctypes.c_ubyte),
                                 ctypes.POINTER(ctypes.c_int)]
z8opp._Z8oppitestPhiS_Pi.restype = None


def _Z8oppitestPhiS_Pi(input, out, outlen):
    global z8opp
    size = len(input)
    array_type = ctypes.c_ubyte * size
    out = ctypes.c_ubyte()
    outlen = ctypes.c_int()
    result = z8opp._Z8oppitestPhiS_Pi(array_type(*input), ctypes.c_int(size), byref(out), byref(outlen))
    return int(result)


out = ctypes.c_ubyte()
outlen = ctypes.c_int()

z8opp._Z8oppitestPhiS_Pi(data, len(data), byref(out), byref(outlen))

0 个答案:

没有答案