mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2024-11-22 13:53:02 +05:30
66 lines
1.9 KiB
Python
66 lines
1.9 KiB
Python
#!/usr/bin/python3
|
|
import ctypes, sys
|
|
|
|
sharedlib = './lib3ddevil1.so'
|
|
libc = ctypes.cdll.LoadLibrary(sharedlib)
|
|
if not libc:
|
|
print("Couldn't load %s" % sharedlib)
|
|
sys.exit()
|
|
del sys
|
|
print("\nlib3ddevil1 loaded.")
|
|
|
|
#--------------------------------------+
|
|
# Basic Struct
|
|
#--------------------------------------+
|
|
|
|
class PldHeader(ctypes.Structure):
|
|
_pack_ = 1
|
|
_fields_ = [
|
|
("numOffset", ctypes.c_int),
|
|
("offsets", ctypes.POINTER(ctypes.c_int))
|
|
]
|
|
|
|
class Devil1PLD_FN(ctypes.Structure):
|
|
_fields_ = [
|
|
("getheader" , ctypes.CFUNCTYPE(
|
|
ctypes.c_bool,
|
|
ctypes.POINTER(PldHeader),
|
|
ctypes.c_char_p)),
|
|
("sizeofsector", ctypes.CFUNCTYPE(
|
|
ctypes.c_int,
|
|
ctypes.POINTER(PldHeader),
|
|
ctypes.c_int)),
|
|
("printheader" , ctypes.CFUNCTYPE(None,
|
|
ctypes.POINTER(PldHeader)))
|
|
]
|
|
|
|
devil1pld = Devil1PLD_FN.in_dll(libc, "DEVIL1PLD")
|
|
|
|
#--------------------------------------+
|
|
# Pythonic Object
|
|
#--------------------------------------+
|
|
|
|
class PLDHeader:
|
|
def __init__(self, filedata = None):
|
|
# Store C Struct in order to call C functions
|
|
self.cstruct = PldHeader()
|
|
if filedata:
|
|
devil1pld.getheader(ctypes.byref(self.cstruct), filedata)
|
|
self.eof = len(filedata)
|
|
|
|
def show(self):
|
|
devil1pld.printheader(ctypes.byref(self.cstruct))
|
|
return
|
|
|
|
def getnumoffsets(self):
|
|
return self.cstruct.numOffsets
|
|
|
|
# return pythonic list of offsets
|
|
def getoffsets(self):
|
|
return self.cstruct.offsets[:self.cstruct.numOffset]
|
|
|
|
def sizeofsector(self, i):
|
|
ptr = ctypes.byref(self.cstruct)
|
|
return devil1pld.sizeofsector(ptr, i, self.eof)
|
|
|