Python can read a pld header

This commit is contained in:
_ 2018-04-22 03:39:08 -07:00
parent 3f76eddbce
commit 71f6517a94

View File

@ -7,7 +7,7 @@ class PldHeader(ctypes.Structure):
("offsets", ctypes.POINTER(ctypes.c_int)) ("offsets", ctypes.POINTER(ctypes.c_int))
] ]
class Devil1FN_PLD(ctypes.Structure): class Devil1PLD_FN(ctypes.Structure):
_fields_ = [ _fields_ = [
("getheader" , ctypes.CFUNCTYPE(bool, ctypes.POINTER(PldHeader), ctypes.c_char_p)), ("getheader" , ctypes.CFUNCTYPE(bool, ctypes.POINTER(PldHeader), ctypes.c_char_p)),
("sizeofsector", ctypes.CFUNCTYPE(int, ctypes.POINTER(PldHeader), ctypes.c_int)), ("sizeofsector", ctypes.CFUNCTYPE(int, ctypes.POINTER(PldHeader), ctypes.c_int)),
@ -16,11 +16,21 @@ class Devil1FN_PLD(ctypes.Structure):
def main(): def main():
sharedlib='./lib3ddevil1.so' sharedlib='./lib3ddevil1.so'
libc = cdll.LoadLibrary(sharedlib) libc = ctypes.cdll.LoadLibrary(sharedlib)
if (not lib): if (not libc):
print("Couldn't load %s" % sharedlib) print("Couldn't load %s" % sharedlib)
return 1 return 1
print("OK") print("OK")
fn = Devil1PLD_FN.in_dll(libc, "DEVIL1PLD")
pldh = PldHeader()
with open("pl01.pld", "rb") as f: with open("pl01.pld", "rb") as f:
data = f.read() data = f.read()
p = PldHeader()
fn.getheader(ctypes.byref(pldh), data)
fn.printheader(ctypes.byref(pldh))
#---------------------------------------+
main()