1 #######################################################################
3 # A script for setting binary capabilities based on .pkg file contents.
5 # Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
6 # Contact: Nokia Corporation (qt-info@nokia.com)
8 #######################################################################
11 print("This script can be used to set capabilities of all binaries\n");
12 print("specified for deployment in a .pkg file.\n");
13 print("If no capabilities are given, the binaries will be given the\n");
14 print("capabilities supported by self-signed certificates.\n");
15 print("\nUsage: patch_capabilities.pl pkg_filename [target-platform] [capability list]\n");
16 print(" If template .pkg file is given, next agrument must be 'target-platform'.\n");
17 print("\nE.g. patch_capabilities.pl myapp_template.pkg release-armv5 \"All -TCB\"\n");
21 my @capabilitiesToSet = ("LocalServices", "NetworkServices", "ReadUserData", "UserEnvironment", "WriteUserData");
23 # If arguments were given to the script,
26 # Parse the first given script argument as a ".pkg" file name.
27 my $pkgFileName = shift(@ARGV);
29 # Check if using template .pkg and do preprocessing if needed
30 if (($pkgFileName =~ m
|_template\
.pkg
$|i
) && -r
($pkgFileName))
33 unless ($target = shift(@ARGV))
38 system ("createpackage.bat -p ".$pkgFileName." ".$target);
39 $pkgFileName =~ s/_template\.pkg/_${target}\.pkg/;
42 # If the specified ".pkg" file exists (and can be read),
43 if (($pkgFileName =~ m
|\
.pkg
$|i
) && -r
($pkgFileName))
45 # If there are more arguments given, parse them as capabilities.
48 @capabilitiesToSet = ();
51 push (@capabilitiesToSet, pop(@ARGV));
55 # Start with no binaries listed.
58 my $tempPkgFileName = $pkgFileName."_@@TEMP@@";
59 unlink($tempPkgFileName);
60 open (NEW_PKG
, ">>".$tempPkgFileName);
61 open (PKG
, "<".$pkgFileName);
68 if ( $line =~ m/^\#.*\(0x[0-9|a-f|A-F]*\).*$/)
70 $newLine =~ s/\(0x./\(0xE/;
72 print NEW_PKG
$newLine;
76 # If the line specifies a file, parse the source and destination locations.
77 if ($line =~ m
|\"([^\"]+)\"\s
*\
-\s
*\"([^\"]+)\"|)
80 my $destinationPath = $2;
82 # If the given file is a binary, check the target and binary type (+ the actual filename) from its path.
83 if ($sourcePath =~ m
:/epoc32/release
/([^/]+)/(udeb|urel)/(\w
+(\
.dll
|\
.exe
)):i
)
85 push (@binaries, $sourcePath);
94 rename($tempPkgFileName, $pkgFileName);
98 my $baseCommandToExecute = "elftran -vid 0x0 -capability \"";
99 if (@capabilitiesToSet)
101 $baseCommandToExecute .= join(" ", @capabilitiesToSet);
103 $baseCommandToExecute .= "\" ";
105 # Actually set the capabilities of the listed binaries.
106 foreach my $binaryPath(@binaries)
108 # Create the command line for setting the capabilities.
109 my $commandToExecute = $baseCommandToExecute;
110 $commandToExecute .= $binaryPath;
112 # Actually execute the elftran command to set the capabilities.
113 system ($commandToExecute." > NUL");
114 print ("Executed ".$commandToExecute."\n");
116 ## Create another command line to check that the set capabilities are correct.
117 #$commandToExecute = "elftran -dump s ".$binaryPath;