]> git.sesse.net Git - vlc/commitdiff
peflags.py -> peflags.pl
authorRafaël Carré <funman@videolan.org>
Tue, 8 Nov 2011 17:51:11 +0000 (12:51 -0500)
committerRafaël Carré <funman@videolan.org>
Tue, 8 Nov 2011 17:51:11 +0000 (12:51 -0500)
Makefile.am
extras/package/win32/peflags.pl [new file with mode: 0755]
extras/package/win32/peflags.py [deleted file]

index 6216ae64a525ab25edd7de68362a3fd5283078d1..29ec8419e02822924b390fd94d5b728d8facddc5 100644 (file)
@@ -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 (executable)
index 0000000..2acaed0
--- /dev/null
@@ -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 (executable)
index eea3ccb..0000000
+++ /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