From 382afaee42d294e84e45318790de6593b5b39219 Mon Sep 17 00:00:00 2001 From: "Anthony G. Basile" Date: Wed, 12 Dec 2012 19:50:12 +0000 Subject: Add logic for NEED_PAX_DECLS when gelf.h is present but lacks them On a gentoo system -#else +#endif + +#ifdef NEED_PAX_DECLS + #define PT_PAX_FLAGS 0x65041580 /* Indicates PaX flag markings */ #define PF_PAGEEXEC (1 << 4) /* Enable PAGEEXEC */ #define PF_NOPAGEEXEC (1 << 5) /* Disable PAGEEXEC */ #define PF_SEGMEXEC (1 << 6) /* Enable SEGMEXEC */ #define PF_NOSEGMEXEC (1 << 7) /* Disable SEGMEXEC */ #define PF_MPROTECT (1 << 8) /* Enable MPROTECT */ #define PF_NOMPROTECT (1 << 9) /* Disable MPROTECT */ + #define PF_RANDEXEC (1 << 10) /* DEPRECATED: Enable RANDEXEC */ + #define PF_NORANDEXEC (1 << 11) /* DEPRECATED: Disable RANDEXEC */ #define PF_EMUTRAMP (1 << 12) /* Enable EMUTRAMP */ #define PF_NOEMUTRAMP (1 << 13) /* Disable EMUTRAMP */ #define PF_RANDMMAP (1 << 14) /* Enable RANDMMAP */ diff --git a/scripts/setup.py b/scripts/setup.py index 528cfa0..0c6e9cc 100755 --- a/scripts/setup.py +++ b/scripts/setup.py @@ -1,40 +1,91 @@ #!/usr/bin/env python -import os +import sys, os, re from distutils.core import setup, Extension ptpax = os.getenv('PTPAX') xtpax = os.getenv('XTPAX') -if ptpax != None and xtpax == None: - module1 = Extension( - name='pax', - sources = ['paxmodule.c'], - libraries = ['elf'], - undef_macros = ['XTPAX'], - define_macros = [('PTPAX', 1)] - ) +# This is a bit hacky since we include gelf.h but +# the pax decls are in elf.h. The stacking goes as +# gelf.h +# libelf.h +# elf.h + -elif ptpax == None and xtpax != None: +# we want only XTPAX and so NEED_PAX_DECLS +if ptpax == None and xtpax != None: module1 = Extension( name='pax', sources = ['paxmodule.c'], libraries = ['attr'], undef_macros = ['PTPAX'], - define_macros = [('PTPAX', 1)] + define_macros = [('XTPAX', 1), ('NEED_PAX_DECLS', 1)] ) -if ptpax != None and xtpax != None: - module1 = Extension( - name='pax', - sources = ['paxmodule.c'], - libraries = ['elf', 'attr'], - define_macros = [('PTPAX', 1), ('XTPAX', 1)] - ) +# We want PTPAX but don't know if we NEED_PAX_DECLS +else: + try: + need_pax_decls = True + f = open('/usr/include/elf.h', 'r') + for line in f.readlines(): + if re.search('PF_PAGEEXEC', line): + need_pax_decls = False + f.close() + + except IOError as e: + print("Can't find elf.h in the usual place!") + sys.exit(1) + + # We NEED_PAX_DECLS + if need_pax_decls: + + # We want PTPAX but not XTPAX + if ptpax != None and xtpax == None: + module1 = Extension( + name='pax', + sources = ['paxmodule.c'], + libraries = ['elf'], + undef_macros = ['XTPAX'], + define_macros = [('PTPAX', 1), ('NEED_PAX_DECLS', 1)] + ) + + # We want both PTAPX and XTPAX + elif ptpax != None and xtpax != None: + module1 = Extension( + name='pax', + sources = ['paxmodule.c'], + libraries = ['elf', 'attr'], + define_macros = [('PTPAX', 1), ('XTPAX', 1), ('NEED_PAX_DECLS', 1)] + ) + + # We don't NEED_PAX_DECLS + else: + + # We want both PTAPX and XTPAX + if ptpax != None and xtpax == None: + module1 = Extension( + name='pax', + sources = ['paxmodule.c'], + libraries = ['elf'], + undef_macros = ['XTPAX', 'NEED_PAX_DECLS'], + define_macros = [('PTPAX', 1)] + ) + + # We want both PTAPX and XTPAX + elif ptpax != None and xtpax != None: + module1 = Extension( + name='pax', + sources = ['paxmodule.c'], + libraries = ['elf', 'attr'], + undef_macros = ['NEED_PAX_DECLS'], + define_macros = [('PTPAX', 1), ('XTPAX', 1)] + ) + setup( name = 'PaxPython', - version = '2.0', + version = '0.6.1', author = 'Anthony G. Basile', author_email = 'blueness@gentoo.org', url = 'http://dev.gentoo.org/~blueness/elfix', -- cgit v1.2.3-65-gdbad