| 1 | #!/usr/bin/perl
|
|---|
| 2 | #############################################################################
|
|---|
| 3 | ##
|
|---|
| 4 | ## Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 5 | ## All rights reserved.
|
|---|
| 6 | ## Contact: Nokia Corporation (qt-info@nokia.com)
|
|---|
| 7 | ##
|
|---|
| 8 | ## This file is part of the S60 port of the Qt Toolkit.
|
|---|
| 9 | ##
|
|---|
| 10 | ## $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 11 | ## Commercial Usage
|
|---|
| 12 | ## Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 13 | ## accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 14 | ## Software or, alternatively, in accordance with the terms contained in
|
|---|
| 15 | ## a written agreement between you and Nokia.
|
|---|
| 16 | ##
|
|---|
| 17 | ## GNU Lesser General Public License Usage
|
|---|
| 18 | ## Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 19 | ## General Public License version 2.1 as published by the Free Software
|
|---|
| 20 | ## Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 21 | ## packaging of this file. Please review the following information to
|
|---|
| 22 | ## ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 23 | ## will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 24 | ##
|
|---|
| 25 | ## In addition, as a special exception, Nokia gives you certain additional
|
|---|
| 26 | ## rights. These rights are described in the Nokia Qt LGPL Exception
|
|---|
| 27 | ## version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|---|
| 28 | ##
|
|---|
| 29 | ## GNU General Public License Usage
|
|---|
| 30 | ## Alternatively, this file may be used under the terms of the GNU
|
|---|
| 31 | ## General Public License version 3.0 as published by the Free Software
|
|---|
| 32 | ## Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 33 | ## packaging of this file. Please review the following information to
|
|---|
| 34 | ## ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 35 | ## met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 36 | ##
|
|---|
| 37 | ## If you have questions regarding the use of this file, please contact
|
|---|
| 38 | ## Nokia at qt-info@nokia.com.
|
|---|
| 39 | ## $QT_END_LICENSE$
|
|---|
| 40 | ##
|
|---|
| 41 | #############################################################################
|
|---|
| 42 |
|
|---|
| 43 | #######################################################################
|
|---|
| 44 | #
|
|---|
| 45 | # A script for setting binary capabilities based on .pkg file contents.
|
|---|
| 46 | #
|
|---|
| 47 | #######################################################################
|
|---|
| 48 |
|
|---|
| 49 | sub Usage() {
|
|---|
| 50 | print("This script can be used to set capabilities of all binaries\n");
|
|---|
| 51 | print("specified for deployment in a .pkg file.\n");
|
|---|
| 52 | print("If no capabilities are given, the binaries will be given the\n");
|
|---|
| 53 | print("capabilities supported by self-signed certificates.\n");
|
|---|
| 54 | print("\n *** NOTE: If *_template.pkg file is given, 'target-platform' is REQUIRED. ***\n");
|
|---|
| 55 | print("\nUsage: patch_capabilities.pl pkg_filename <target-platform> [capability list]\n");
|
|---|
| 56 | print("\nE.g. patch_capabilities.pl myapp_template.pkg release-armv5 \"All -TCB\"\n");
|
|---|
| 57 | exit();
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | my @capabilitiesToSet = ("LocalServices", "NetworkServices", "ReadUserData", "UserEnvironment", "WriteUserData");
|
|---|
| 61 |
|
|---|
| 62 | # If arguments were given to the script,
|
|---|
| 63 | if (@ARGV)
|
|---|
| 64 | {
|
|---|
| 65 | # Parse the first given script argument as a ".pkg" file name.
|
|---|
| 66 | my $pkgFileName = shift(@ARGV);
|
|---|
| 67 |
|
|---|
| 68 | # These variables will only be set for template .pkg files.
|
|---|
| 69 | my $target;
|
|---|
| 70 | my $platform;
|
|---|
| 71 |
|
|---|
| 72 | # Check if using template .pkg and set target/platform variables
|
|---|
| 73 | if (($pkgFileName =~ m|_template\.pkg$|i) && -r($pkgFileName))
|
|---|
| 74 | {
|
|---|
| 75 | my $targetplatform;
|
|---|
| 76 | unless ($targetplatform = shift(@ARGV))
|
|---|
| 77 | {
|
|---|
| 78 | Usage();
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | my @tmpvalues = split('-', $targetplatform);
|
|---|
| 82 | $target = $tmpvalues[0];
|
|---|
| 83 | $platform = $tmpvalues[1];
|
|---|
| 84 |
|
|---|
| 85 | # Convert visual target to real target (debug->udeb and release->urel)
|
|---|
| 86 | $target =~ s/debug/udeb/i;
|
|---|
| 87 | $target =~ s/release/urel/i;
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | # If the specified ".pkg" file exists (and can be read),
|
|---|
| 91 | if (($pkgFileName =~ m|\.pkg$|i) && -r($pkgFileName))
|
|---|
| 92 | {
|
|---|
| 93 | # If there are more arguments given, parse them as capabilities.
|
|---|
| 94 | if (@ARGV)
|
|---|
| 95 | {
|
|---|
| 96 | @capabilitiesToSet = ();
|
|---|
| 97 | while (@ARGV)
|
|---|
| 98 | {
|
|---|
| 99 | push (@capabilitiesToSet, pop(@ARGV));
|
|---|
| 100 | }
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | # Start with no binaries listed.
|
|---|
| 104 | my @binaries = ();
|
|---|
| 105 |
|
|---|
| 106 | my $tempPkgFileName = $pkgFileName."_@@TEMP@@";
|
|---|
| 107 | unlink($tempPkgFileName);
|
|---|
| 108 | open (NEW_PKG, ">>".$tempPkgFileName);
|
|---|
| 109 | open (PKG, "<".$pkgFileName);
|
|---|
| 110 |
|
|---|
| 111 | # Parse each line.
|
|---|
| 112 | while (<PKG>)
|
|---|
| 113 | {
|
|---|
| 114 | my $line = $_;
|
|---|
| 115 | my $newLine = $line;
|
|---|
| 116 | if ( $line =~ m/^\#.*\(0x[0-9|a-f|A-F]*\).*$/)
|
|---|
| 117 | {
|
|---|
| 118 | $newLine =~ s/\(0x./\(0xE/;
|
|---|
| 119 | }
|
|---|
| 120 | print NEW_PKG $newLine;
|
|---|
| 121 |
|
|---|
| 122 | chomp ($line);
|
|---|
| 123 |
|
|---|
| 124 | # If the line specifies a file, parse the source and destination locations.
|
|---|
| 125 | if ($line =~ m|\"([^\"]+)\"\s*\-\s*\"([^\"]+)\"|)
|
|---|
| 126 | {
|
|---|
| 127 | my $sourcePath = $1;
|
|---|
| 128 | my $destinationPath = $2;
|
|---|
| 129 |
|
|---|
| 130 | # If the given file is a binary, check the target and binary type (+ the actual filename) from its path.
|
|---|
| 131 | if ($sourcePath =~ m:/epoc32/release/([^/]+)/(udeb|urel|\$\(TARGET\))/(\w+(\.dll|\.exe)):i)
|
|---|
| 132 | {
|
|---|
| 133 | # Do preprocessing for template pkg,
|
|---|
| 134 | # In case of template pkg target and platform variables are set
|
|---|
| 135 | if(length($target) && length($platform))
|
|---|
| 136 | {
|
|---|
| 137 | $sourcePath =~ s/\$\(PLATFORM\)/$platform/gm;
|
|---|
| 138 | $sourcePath =~ s/\$\(TARGET\)/$target/gm;
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | push (@binaries, $sourcePath);
|
|---|
| 142 | }
|
|---|
| 143 | }
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | close (PKG);
|
|---|
| 147 | close (NEW_PKG);
|
|---|
| 148 |
|
|---|
| 149 | unlink($pkgFileName);
|
|---|
| 150 | rename($tempPkgFileName, $pkgFileName);
|
|---|
| 151 |
|
|---|
| 152 | print ("\n");
|
|---|
| 153 |
|
|---|
| 154 | my $baseCommandToExecute = "elftran -vid 0x0 -capability \"";
|
|---|
| 155 | if (@capabilitiesToSet)
|
|---|
| 156 | {
|
|---|
| 157 | $baseCommandToExecute .= join(" ", @capabilitiesToSet);
|
|---|
| 158 | }
|
|---|
| 159 | $baseCommandToExecute .= "\" ";
|
|---|
| 160 |
|
|---|
| 161 | # Actually set the capabilities of the listed binaries.
|
|---|
| 162 | foreach my $binaryPath(@binaries)
|
|---|
| 163 | {
|
|---|
| 164 | # Create the command line for setting the capabilities.
|
|---|
| 165 | my $commandToExecute = $baseCommandToExecute;
|
|---|
| 166 | $commandToExecute .= $binaryPath;
|
|---|
| 167 |
|
|---|
| 168 | # Actually execute the elftran command to set the capabilities.
|
|---|
| 169 | system ($commandToExecute." > NUL");
|
|---|
| 170 | print ("Executed ".$commandToExecute."\n");
|
|---|
| 171 |
|
|---|
| 172 | ## Create another command line to check that the set capabilities are correct.
|
|---|
| 173 | #$commandToExecute = "elftran -dump s ".$binaryPath;
|
|---|
| 174 | }
|
|---|
| 175 |
|
|---|
| 176 | print ("\n");
|
|---|
| 177 | }
|
|---|
| 178 | }
|
|---|
| 179 | else
|
|---|
| 180 | {
|
|---|
| 181 | Usage();
|
|---|
| 182 | }
|
|---|