author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 12 Mar 2010 15:46:37 +0200 | |
branch | RCL_3 |
changeset 5 | d3bac044e0f0 |
parent 4 | 3b1da2848fc7 |
child 7 | 3f74d0d4af4c |
permissions | -rw-r--r-- |
0 | 1 |
#!/usr/bin/perl |
2 |
############################################################################# |
|
3 |
## |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4 |
## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 |
## No Commercial Usage |
|
12 |
## This file contains pre-release code and may not be distributed. |
|
13 |
## You may use this file in accordance with the terms and conditions |
|
14 |
## contained in the Technology Preview License Agreement accompanying |
|
15 |
## this package. |
|
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 |
## If you have questions regarding the use of this file, please contact |
|
30 |
## Nokia at qt-info@nokia.com. |
|
31 |
## |
|
32 |
## |
|
33 |
## |
|
34 |
## |
|
35 |
## |
|
36 |
## |
|
37 |
## |
|
38 |
## |
|
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 |
||
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
111 |
my $manufacturerElseBlock = 0; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
112 |
|
0 | 113 |
# Parse each line. |
114 |
while (<PKG>) |
|
115 |
{ |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
116 |
# Patch pkg UID |
0 | 117 |
my $line = $_; |
118 |
my $newLine = $line; |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
119 |
if ($line =~ m/^\#.*\(0x[0-9|a-f|A-F]*\).*$/) |
0 | 120 |
{ |
121 |
$newLine =~ s/\(0x./\(0xE/; |
|
122 |
} |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
123 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
124 |
# Patch embedded sis name and UID |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
125 |
if ($line =~ m/^@.*\.sis.*\(0x[0-9|a-f|A-F]*\).*$/) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
126 |
{ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
127 |
$newLine =~ s/\(0x./\(0xE/; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
128 |
if ($line !~ m/^.*_selfsigned.sis.*$/) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
129 |
{ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
130 |
$newLine =~ s/\.sis/_selfsigned\.sis/i; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
131 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
132 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
133 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
134 |
# Remove all dependencies to other packages to reduce unnecessary error messages |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
135 |
# from depended packages that are also patched and therefore have different UID. |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
136 |
if ($line =~ m/^\(0x[0-9|a-f|A-F]*\).*\{.*\}$/) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
137 |
{ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
138 |
$newLine = "\n" |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
139 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
140 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
141 |
# Remove manufacturer ifdef |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
142 |
if ($line =~ m/^.*\(MANUFACTURER\)\=\(.*\).*$/) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
143 |
{ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
144 |
$newLine = "\n"; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
145 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
146 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
147 |
if ($line =~ m/^ELSEIF.*MANUFACTURER$/) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
148 |
{ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
149 |
$manufacturerElseBlock = 1; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
150 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
151 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
152 |
if ($manufacturerElseBlock eq 1) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
153 |
{ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
154 |
$newLine = "\n"; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
155 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
156 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
157 |
if ($line =~ m/^ENDIF.*MANUFACTURER$/) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
158 |
{ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
159 |
$manufacturerElseBlock = 0; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
160 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
161 |
|
0 | 162 |
print NEW_PKG $newLine; |
163 |
||
164 |
chomp ($line); |
|
165 |
||
166 |
# If the line specifies a file, parse the source and destination locations. |
|
167 |
if ($line =~ m|\"([^\"]+)\"\s*\-\s*\"([^\"]+)\"|) |
|
168 |
{ |
|
169 |
my $sourcePath = $1; |
|
170 |
my $destinationPath = $2; |
|
171 |
||
172 |
# If the given file is a binary, check the target and binary type (+ the actual filename) from its path. |
|
173 |
if ($sourcePath =~ m:/epoc32/release/([^/]+)/(udeb|urel|\$\(TARGET\))/(\w+(\.dll|\.exe)):i) |
|
174 |
{ |
|
175 |
# Do preprocessing for template pkg, |
|
176 |
# In case of template pkg target and platform variables are set |
|
177 |
if(length($target) && length($platform)) |
|
178 |
{ |
|
179 |
$sourcePath =~ s/\$\(PLATFORM\)/$platform/gm; |
|
180 |
$sourcePath =~ s/\$\(TARGET\)/$target/gm; |
|
181 |
} |
|
182 |
||
183 |
push (@binaries, $sourcePath); |
|
184 |
} |
|
185 |
} |
|
186 |
} |
|
187 |
||
188 |
close (PKG); |
|
189 |
close (NEW_PKG); |
|
190 |
||
191 |
unlink($pkgFileName); |
|
192 |
rename($tempPkgFileName, $pkgFileName); |
|
193 |
||
194 |
print ("\n"); |
|
195 |
||
196 |
my $baseCommandToExecute = "elftran -vid 0x0 -capability \""; |
|
197 |
if (@capabilitiesToSet) |
|
198 |
{ |
|
199 |
$baseCommandToExecute .= join(" ", @capabilitiesToSet); |
|
200 |
} |
|
201 |
$baseCommandToExecute .= "\" "; |
|
202 |
||
203 |
# Actually set the capabilities of the listed binaries. |
|
204 |
foreach my $binaryPath(@binaries) |
|
205 |
{ |
|
206 |
# Create the command line for setting the capabilities. |
|
207 |
my $commandToExecute = $baseCommandToExecute; |
|
208 |
$commandToExecute .= $binaryPath; |
|
209 |
||
210 |
# Actually execute the elftran command to set the capabilities. |
|
211 |
system ($commandToExecute." > NUL"); |
|
212 |
print ("Executed ".$commandToExecute."\n"); |
|
213 |
||
214 |
## Create another command line to check that the set capabilities are correct. |
|
215 |
#$commandToExecute = "elftran -dump s ".$binaryPath; |
|
216 |
} |
|
217 |
||
218 |
print ("\n"); |
|
219 |
} |
|
220 |
} |
|
221 |
else |
|
222 |
{ |
|
223 |
Usage(); |
|
224 |
} |