master
Xyc0 2016-04-20 02:10:33 +00:00
parent d9c2cc7c48
commit 3b87e6a693
1 changed files with 17 additions and 9 deletions

26
sins.py
View File

@ -8,24 +8,32 @@ import ctypes
class Sins: class Sins:
def __init__(self): def __init__(self):
self.seed = open('./build/scrap.asm.2.o', 'rb').read() self.seed = open('./build/scrap.asm.2.o', 'rb').read()
self.pic = self.pic_load() self.pic = self.pic_load(self.seed)
self.callback = ctypes.PYFUNCTYPE(None, ctypes.py_object)(self.callme)
def pic_load(self): def pic_load(self, seedling):
size = len(seedling)
prot = (mmap.PROT_READ | mmap.PROT_WRITE | mmap.PROT_EXEC) prot = (mmap.PROT_READ | mmap.PROT_WRITE | mmap.PROT_EXEC)
page = mmap.mmap(-1, len(self.seed), prot=prot) page = mmap.mmap(-1, size, prot=prot)
page.write(self.seed) page.write(seedling)
addr = ctypes.addressof((ctypes.c_char * len(self.seed)).from_buffer(page)) addr = ctypes.addressof((ctypes.c_char * size).from_buffer(page))
func = ctypes.CFUNCTYPE(ctypes.c_void_p, ctypes.c_void_p, ctypes.c_uint)(addr) func = ctypes.CFUNCTYPE(ctypes.c_void_p, ctypes.c_void_p, ctypes.c_uint)(addr)
func.page = page func.page = page
func.addr = addr
func.size = size
return func(addr, len(self.seed)) return func
def callme(self):
print('So Happy.')
if __name__ == '__main__': if __name__ == '__main__':
import pprint import pprint
pp = pprint.PrettyPrinter() pp = pprint.PrettyPrinter()
sins = Sins() sins = Sins()
print('Seed')
pp.pprint(sins.seed)
print('pic_load') print('pic_load')
pp.pprint(sins.pic_load())
pp.pprint(sins.pic(sins.callback, sins.pic.size))