master
Xyc0 7 years ago
parent d9c2cc7c48
commit 3b87e6a693

@ -8,24 +8,32 @@ import ctypes
class Sins:
def __init__(self):
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)
page = mmap.mmap(-1, len(self.seed), prot=prot)
page.write(self.seed)
addr = ctypes.addressof((ctypes.c_char * len(self.seed)).from_buffer(page))
page = mmap.mmap(-1, size, prot=prot)
page.write(seedling)
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.page = page
func.addr = addr
func.size = size
return func
return func(addr, len(self.seed))
def callme(self):
print('So Happy.')
if __name__ == '__main__':
import pprint
pp = pprint.PrettyPrinter()
sins = Sins()
print('Seed')
pp.pprint(sins.seed)
print('pic_load')
pp.pprint(sins.pic_load())
pp.pprint(sins.pic(sins.callback, sins.pic.size))

Loading…
Cancel
Save