[vlc-commits] peflags.py -> peflags.pl

Rafaël Carré git at videolan.org
Tue Nov 8 18:51:42 CET 2011


vlc | branch: master | Rafaël Carré <funman at videolan.org> | Tue Nov  8 12:51:11 2011 -0500| [4b4963f3133bd45f0051ec3db15f7fd8239a4d86] | committer: Rafaël Carré

peflags.py -> peflags.pl

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

 Makefile.am                     |    2 +-
 extras/package/win32/peflags.pl |   62 +++++++++++++++++++++++++++++++++++++++
 extras/package/win32/peflags.py |   57 -----------------------------------
 3 files changed, 63 insertions(+), 58 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 6216ae6..29ec841 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -767,7 +767,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
-	find $(win32_destdir) -type f \( -name '*$(LIBEXT)' -print -o -name '*$(EXEEXT)' -print \) -exec $(top_srcdir)/extras/package/win32/peflags.py {} \;
+	find $(win32_destdir) -type f \( -name '*$(LIBEXT)' -print -o -name '*$(EXEEXT)' -print \) -exec $(top_srcdir)/extras/package/win32/peflags.pl {} \;
 	find $(win32_destdir)/plugins/ -type f \( -name '*.a' -or -name '*.la' \) -exec rm -rvf {} \;
 
 package-win-base: package-win-common
diff --git a/extras/package/win32/peflags.pl b/extras/package/win32/peflags.pl
new file mode 100755
index 0000000..2acaed0
--- /dev/null
+++ b/extras/package/win32/peflags.pl
@@ -0,0 +1,62 @@
+#!/usr/bin/perl
+# 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.
+#
+
+use warnings;
+
+if ($#ARGV != 0) {
+    die "Need exactly one argument";
+}
+
+open F, "+<$ARGV[0]"
+    or die "Can't open `$ARGV[0]'";
+binmode F;
+
+seek F, 0x3c, 0;
+my $offset = get_le(4);
+seek F, $offset, 0;
+
+if (get_le(4) != 0x00004550) { # IMAGE_NT_SIGNATURE
+    die "Not a NT executable";
+}
+
+seek F, 20 + 70, 1;
+
+my $flags = get_le(2);
+seek F, -2, 1;
+
+$flags |= 0x100;  # NX Compat
+$flags |= 0x40;   # Dynamic Base
+
+printf F "%c%c", $flags & 0xff,($flags >> 8) & 0xff;
+
+close F;
+
+sub get_le {
+    my $bytes;
+    read F, $bytes, $_[0];
+    if (length $bytes ne $_[0]) {
+        die "Couldn't read";
+    }
+
+    my $ret = 0;
+    my @array = split //, $bytes;
+    for (my $shift = 0, my $i = 0; $i < $_[0]; $i++, $shift += 8) {
+        $ret += (ord $array[$i]) << $shift;
+    }
+    return $ret;
+}
diff --git a/extras/package/win32/peflags.py b/extras/package/win32/peflags.py
deleted file mode 100755
index eea3ccb..0000000
--- a/extras/package/win32/peflags.py
+++ /dev/null
@@ -1,57 +0,0 @@
-#!/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