executable mmap

master
Xyc0 2016-04-20 01:45:44 +00:00
parent 39df01a782
commit d9c2cc7c48
2 changed files with 40 additions and 17 deletions

31
sins.py Executable file
View File

@ -0,0 +1,31 @@
#! /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()
def pic_load(self):
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))
func = ctypes.CFUNCTYPE(ctypes.c_void_p, ctypes.c_void_p, ctypes.c_uint)(addr)
func.page = page
return func(addr, len(self.seed))
if __name__ == '__main__':
import pprint
pp = pprint.PrettyPrinter()
sins = Sins()
print('Seed')
pp.pprint(sins.seed)
print('pic_load')
pp.pprint(sins.pic_load())

26
wscript
View File

@ -1,24 +1,16 @@
import sys #! /usr/bin/env python
# encoding: utf-8
def options(opt): def options(opt):
opt.load('nasm compiler_c') opt.load('nasm')
opt.load('python')
def configure(conf): def configure(conf):
conf.load('nasm compiler_c') conf.load('nasm')
conf.check_cc(header_name='openssl/sha.h') conf.load('python')
conf.check_python_version((3,5,1))
def build(bld): def build(bld):
bld.program( bld(features='py', source=('sins.py'))
source='pic-linux.c',
target='pic-linux',
cflags='-g',
lib=['ssl', 'crypto'])
bld(features='asm', bld(features='asm', source='scrap.asm', target='scrap')
source='scrap.asm',
target='scrap')
# gdb --args ./pic-linux scrap.asm.2.o