lib3ddevil1/bindings/py3devil1.py
2018-04-22 03:39:08 -07:00

37 lines
992 B
Python
Executable File

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