executable mmap

master
Xyc0 7 years ago
parent 39df01a782
commit d9c2cc7c48

@ -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())

@ -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='asm',
source='scrap.asm',
target='scrap')
bld(features='py', source=('sins.py'))
# gdb --args ./pic-linux scrap.asm.2.o
bld(features='asm', source='scrap.asm', target='scrap')

Loading…
Cancel
Save