|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // amastarterexe.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 |
|
19 #include <e32std.h> |
|
20 #include "amastartexe_patch.h" |
|
21 #include "amastart.h" |
|
22 |
|
23 LOCAL_C void AmaStarterL() |
|
24 { |
|
25 CActiveScheduler* sched = NULL; |
|
26 sched = new(ELeave) CActiveScheduler; |
|
27 CActiveScheduler::Install(sched); |
|
28 CleanupStack::PushL(sched); |
|
29 |
|
30 //The application should have capabilities at least what AMAStarter has (PowerMgmt, ReadDeviceData, ProtServ) |
|
31 //to prevent a process being able to get AMAStarter to perform operations it doesn't have the capabilities for. |
|
32 //The application should also have SID as expected to ensure that AMAStarter.exe cannot be launched by a malicious process |
|
33 if(!User::CreatorHasCapability(ECapabilityPowerMgmt, ECapabilityProtServ) || |
|
34 !User::CreatorHasCapability(ECapabilityReadDeviceData)|| |
|
35 (User::CreatorSecureId() != KSysStartSID)) |
|
36 { |
|
37 User::Leave(KErrPermissionDenied); // make sure we are being called by a trusted app for startup purposes |
|
38 } |
|
39 |
|
40 CAmaStart* const amaStart = CAmaStart::NewL(); |
|
41 CleanupStack::PushL(amaStart); |
|
42 |
|
43 //default DSC |
|
44 TUid id = TUid::Uid(KDefaultSymbianDsc); |
|
45 const TInt commandSize=User::CommandLineLength(); |
|
46 if (commandSize >0) |
|
47 { |
|
48 RBuf command; |
|
49 command.CreateL(commandSize); |
|
50 CleanupClosePushL(command); |
|
51 |
|
52 //get the command line argument |
|
53 User::CommandLine(command); |
|
54 |
|
55 TLex lex(command); |
|
56 TUint dscId=0; |
|
57 |
|
58 //Parses the string to extract a TUint32, using hexadecimal |
|
59 User::LeaveIfError(lex.Val(dscId, EHex)); |
|
60 id=TUid::Uid(dscId); |
|
61 |
|
62 CleanupStack::PopAndDestroy(&command); |
|
63 } |
|
64 |
|
65 amaStart->StartL(id); |
|
66 CleanupStack::PopAndDestroy(2);//amastart, sched |
|
67 } |
|
68 |
|
69 |
|
70 GLDEF_C TInt E32Main() |
|
71 { |
|
72 __UHEAP_MARK; // mark heap state |
|
73 |
|
74 CTrapCleanup* theTrapCleanup=CTrapCleanup::New(); |
|
75 |
|
76 TInt error=KErrNoMemory; |
|
77 |
|
78 if (theTrapCleanup) |
|
79 { |
|
80 TRAP(error, AmaStarterL()); |
|
81 delete theTrapCleanup; |
|
82 } |
|
83 |
|
84 __UHEAP_MARKEND; // check no memory leak |
|
85 |
|
86 return(error); |
|
87 } |