You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
994 B
39 lines
994 B
#! /usr/bin/env python |
|
# encoding: utf-8 |
|
|
|
import struct |
|
import mmap |
|
import ctypes |
|
|
|
class Sins: |
|
def __init__(self): |
|
self.seed = open('./build/scrap.asm.2.o', 'rb').read() |
|
self.pic = self.pic_load(self.seed) |
|
self.callback = ctypes.PYFUNCTYPE(None, ctypes.py_object)(self.callme) |
|
|
|
def pic_load(self, seedling): |
|
size = len(seedling) |
|
prot = (mmap.PROT_READ | mmap.PROT_WRITE | mmap.PROT_EXEC) |
|
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 |
|
|
|
def callme(self): |
|
print('So Happy.') |
|
|
|
if __name__ == '__main__': |
|
import pprint |
|
pp = pprint.PrettyPrinter() |
|
|
|
sins = Sins() |
|
|
|
print('pic_load') |
|
|
|
pp.pprint(sins.pic(sins.callback, sins.pic.size))
|
|
|