Fix access to uninitialized memory
[qt-netbsd.git] / bin / patch_capabilities.pl
blobca80891a803915e51fa9a537c40b28d1affd06d9
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 #######################################################################
10 sub Usage() {
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");
18 exit();
21 my @capabilitiesToSet = ("LocalServices", "NetworkServices", "ReadUserData", "UserEnvironment", "WriteUserData");
23 # If arguments were given to the script,
24 if (@ARGV)
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))
32 my $target;
33 unless ($target = shift(@ARGV))
35 Usage();
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.
46 if (@ARGV)
48 @capabilitiesToSet = ();
49 while (@ARGV)
51 push (@capabilitiesToSet, pop(@ARGV));
55 # Start with no binaries listed.
56 my @binaries = ();
58 my $tempPkgFileName = $pkgFileName."_@@TEMP@@";
59 unlink($tempPkgFileName);
60 open (NEW_PKG, ">>".$tempPkgFileName);
61 open (PKG, "<".$pkgFileName);
63 # Parse each line.
64 while (<PKG>)
66 my $line = $_;
67 my $newLine = $line;
68 if ( $line =~ m/^\#.*\(0x[0-9|a-f|A-F]*\).*$/)
70 $newLine =~ s/\(0x./\(0xE/;
72 print NEW_PKG $newLine;
74 chomp ($line);
76 # If the line specifies a file, parse the source and destination locations.
77 if ($line =~ m|\"([^\"]+)\"\s*\-\s*\"([^\"]+)\"|)
79 my $sourcePath = $1;
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);
90 close (PKG);
91 close (NEW_PKG);
93 unlink($pkgFileName);
94 rename($tempPkgFileName, $pkgFileName);
96 print ("\n");
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;
120 print ("\n");
123 else
125 Usage();