|
1 // Copyright (c) 2004-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 // e32tools/seclib/seclib.cpp |
|
15 // Get the capabilities of an emulator / e32image. |
|
16 // |
|
17 // |
|
18 |
|
19 #include <e32cmn.h> |
|
20 #include <e32ldr.h> |
|
21 #include <seclib.h> |
|
22 |
|
23 #include "e32image.h" |
|
24 #include "h_utl.h" |
|
25 |
|
26 #define __E32DEBUG_H__ |
|
27 #include "setcap.h" |
|
28 |
|
29 |
|
30 GLDEF_C TInt GetSecurityInfo(const char* aFileName, SBinarySecurityInfo& aInfo) |
|
31 { |
|
32 // Check we have a filename |
|
33 if (!aFileName) |
|
34 { |
|
35 return KErrNotFound; |
|
36 } |
|
37 |
|
38 // Zero the capabilities |
|
39 memset(aInfo.iCapabilities, 0, KCapabilitySetMaxSize); |
|
40 |
|
41 // We don't want to update the image's capabilities |
|
42 CapabilitySet = EFalse; |
|
43 |
|
44 // Try opening the file as an E32Image |
|
45 E32ImageFile f; |
|
46 TInt r = f.Open(aFileName); |
|
47 |
|
48 if (r==KErrCorrupt || r==KErrNotSupported || r==1) |
|
49 { |
|
50 #ifndef __LINUX__ |
|
51 // Try emulator format |
|
52 aInfo.iE32Image = EFalse; |
|
53 |
|
54 HANDLE file = CreateFileA(aFileName, |
|
55 GENERIC_READ|GENERIC_WRITE, |
|
56 FILE_SHARE_READ|FILE_SHARE_WRITE, |
|
57 NULL, |
|
58 OPEN_EXISTING, |
|
59 0, |
|
60 NULL); |
|
61 if (file == INVALID_HANDLE_VALUE) |
|
62 { |
|
63 return GetLastError(); |
|
64 } |
|
65 |
|
66 r = SetCap(file); |
|
67 #endif |
|
68 } |
|
69 else |
|
70 { |
|
71 // Extract caps from E32Image |
|
72 aInfo.iE32Image = ETrue; |
|
73 |
|
74 r = SetCap(f.iOrigHdr); |
|
75 } |
|
76 |
|
77 if (r == KErrNone) |
|
78 { |
|
79 aInfo.iSecureId = SecureId.iId; |
|
80 aInfo.iVendorId = VendorId.iId; |
|
81 *(SCapabilitySet*)(aInfo.iCapabilities) = Capability; |
|
82 } |
|
83 |
|
84 return r; |
|
85 } |
|
86 |
|
87 |
|
88 #ifndef __LINUX__ |
|
89 GLDEF_C TInt GetSecurityInfo(const wchar_t* aFileName, SBinarySecurityInfo& aInfo) |
|
90 { |
|
91 // Check we have a filename |
|
92 if (!aFileName) |
|
93 { |
|
94 return KErrNotFound; |
|
95 } |
|
96 |
|
97 // Zero the capabilities |
|
98 memset(aInfo.iCapabilities, 0, KCapabilitySetMaxSize); |
|
99 |
|
100 // We don't want to update the image's capabilities |
|
101 CapabilitySet = EFalse; |
|
102 |
|
103 // Try opening the file as an E32Image |
|
104 E32ImageFile f; |
|
105 TInt r = f.Open(aFileName); |
|
106 |
|
107 if (r==KErrCorrupt || r==KErrNotSupported) |
|
108 { |
|
109 // Try emulator format |
|
110 aInfo.iE32Image = EFalse; |
|
111 |
|
112 HANDLE file = CreateFileW(aFileName, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); |
|
113 if (file == INVALID_HANDLE_VALUE) |
|
114 { |
|
115 return GetLastError(); |
|
116 } |
|
117 |
|
118 r = SetCap(file); |
|
119 } |
|
120 else |
|
121 { |
|
122 // Extract caps from E32Image |
|
123 aInfo.iE32Image = ETrue; |
|
124 |
|
125 r = SetCap(f.iOrigHdr); |
|
126 } |
|
127 |
|
128 if (r == KErrNone) |
|
129 { |
|
130 aInfo.iSecureId = SecureId.iId; |
|
131 aInfo.iVendorId = VendorId.iId; |
|
132 *(SCapabilitySet*)(aInfo.iCapabilities) = Capability; |
|
133 } |
|
134 |
|
135 return r; |
|
136 } |
|
137 #endif |