From d9c2cc7c4877a0fce089dfc63cc9e0e2dd48ca17 Mon Sep 17 00:00:00 2001 From: Xyc0 Date: Wed, 20 Apr 2016 01:45:44 +0000 Subject: [PATCH] executable mmap --- sins.py | 31 +++++++++++++++++++++++++++++++ wscript | 26 +++++++++----------------- 2 files changed, 40 insertions(+), 17 deletions(-) create mode 100755 sins.py diff --git a/sins.py b/sins.py new file mode 100755 index 0000000..d861fb2 --- /dev/null +++ b/sins.py @@ -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()) diff --git a/wscript b/wscript index 941545f..a338af3 100644 --- a/wscript +++ b/wscript @@ -1,24 +1,16 @@ -import sys - +#! /usr/bin/env python +# encoding: utf-8 def options(opt): - opt.load('nasm compiler_c') - + opt.load('nasm') + opt.load('python') def configure(conf): - conf.load('nasm compiler_c') - conf.check_cc(header_name='openssl/sha.h') - + conf.load('nasm') + conf.load('python') + conf.check_python_version((3,5,1)) def build(bld): - bld.program( - source='pic-linux.c', - target='pic-linux', - cflags='-g', - lib=['ssl', 'crypto']) + bld(features='py', source=('sins.py')) - bld(features='asm', - source='scrap.asm', - target='scrap') - - # gdb --args ./pic-linux scrap.asm.2.o + bld(features='asm', source='scrap.asm', target='scrap')