[vlc-commits] peflags: rewrite needed features in python

Rafaël Carré git at videolan.org
Mon Nov 7 22:37:33 CET 2011


vlc | branch: master | Rafaël Carré <funman at videolan.org> | Mon Nov  7 16:18:48 2011 -0500| [1c173782961ca33e5547aac6cd7a4f0f11aa4aab] | committer: Rafaël Carré

peflags: rewrite needed features in python

remove conditional from configure.ac

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=1c173782961ca33e5547aac6cd7a4f0f11aa4aab
---

 Makefile.am                     |    4 +--
 configure.ac                    |   10 -------
 contrib/TODO                    |    4 ---
 extras/package/win32/peflags.py |   57 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 58 insertions(+), 17 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 68530b3..1ba4cf0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -773,9 +773,7 @@ endif
 	find $(win32_destdir) -type f \( -name "*xml" -or -name "*html" -or -name '*js' -or -name '*css' -or -name '*hosts' -or -iname '*txt' -or -name '*.cfg' -or -name '*.lua' \) -exec $(U2D) {} \;
 
 #Enable DEP and ASLR for all the binaries
-if USE_PEFLAGS
-	find $(win32_destdir) -type f \( -name '*$(LIBEXT)' -print -o -name '*$(EXEEXT)' -print \) -exec $(PEFLAGS) --dynamicbase=true --nxcompat=true {} \;
-endif
+	find $(win32_destdir) -type f \( -name '*$(LIBEXT)' -print -o -name '*$(EXEEXT)' -print \) -exec $(top_srcdir)/extras/package/win32/peflags.py {} \;
 	find $(win32_destdir)/plugins/ -type f \( -name '*.a' -or -name '*.la' \) -exec rm -rvf {} \;
 
 package-win-base: package-win-common
diff --git a/configure.ac b/configure.ac
index b688d8f..85919ea 100644
--- a/configure.ac
+++ b/configure.ac
@@ -343,15 +343,6 @@ case "${host_os}" in
         VLC_ADD_LDFLAGS([vlc],[-mwindows])
         VLC_ADD_LIBS([win32text],[-lgdi32])
         VLC_ADD_LIBS([cdda vcdx sdl_image vout_sdl],[-lwinmm])
-        dnl
-        dnl DEP and ASLR options
-        dnl
-        AC_ARG_WITH(peflags,
-          [AS_HELP_STRING([--with-peflags],
-            [use peflags (default enabled on Windows)])])
-        if test "${with_peflags}" != "no" ; then
-          AC_PATH_TOOL(PEFLAGS, peflags, :)
-        fi
         AC_CHECK_PROGS(U2D, [unix2dos todos], unix2dos)
         ac_default_prefix="`pwd`/_win32"
         DESTDIR="`pwd`/_win32/"
@@ -405,7 +396,6 @@ AM_CONDITIONAL(HAVE_WIN32,   test "${SYS}" = "mingw32")
 AM_CONDITIONAL(HAVE_WIN64,   test "${HAVE_WIN64}" = "1")
 AM_CONDITIONAL(HAVE_WINCE,   test "${SYS}" = "mingwce")
 AM_CONDITIONAL(HAVE_SYMBIAN, test "${SYS}" = "symbian")
-AM_CONDITIONAL(USE_PEFLAGS,  test "${with_peflags}" = "yes")
 
 dnl
 dnl Sadly autoconf doesn't think about testing foo.exe when ask to test
diff --git a/contrib/TODO b/contrib/TODO
index 063f652..1b31ec8 100644
--- a/contrib/TODO
+++ b/contrib/TODO
@@ -12,7 +12,3 @@ Sparkle
 vcdimager, cdio -- why are they used only in osx binaries, do we really need them?
 
 build tools     -- (autotools, libtool, yasm...) see extras/tools
-
-# Windows
-
-peflags         -- a build tool, only a single .c file; we should rather put it in git
diff --git a/extras/package/win32/peflags.py b/extras/package/win32/peflags.py
new file mode 100755
index 0000000..eea3ccb
--- /dev/null
+++ b/extras/package/win32/peflags.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python
+# -*- coding: utf8 -*-
+#
+# Copyright © 2011 Rafaël Carré <funman at videolanorg>
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software
+#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+#
+
+from os import SEEK_CUR
+from sys import argv
+
+def get_le(f, n):
+    array = bytearray(f.read(n))
+    if len(array) != n:
+        raise Exception('Reading failed!')
+    shift = 0
+    ret = 0
+    for c in array:
+        ret = ret + (c << shift)
+        shift = shift + 8
+    return ret
+
+###
+
+if len(argv) != 2:
+    exit(1)
+
+f = open(argv[1], 'r+b')
+
+f.seek(0x3c)
+f.seek(get_le(f, 4))
+
+if get_le(f, 4) != 0x00004550: # IMAGE_NT_SIGNATURE
+    raise Exception('Not a NT executable')
+
+f.seek(20 + 70, SEEK_CUR)
+
+flags = get_le(f, 2)
+f.seek(-2, SEEK_CUR)
+flags |= 0x100  # NX Compat
+flags |= 0x40   # Dynamic Base
+
+f.write(bytearray([flags & 0xff, (flags >> 8) & 0xff ]))
+
+f.close



More information about the vlc-commits mailing list