|
1 /* |
|
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 /** |
|
20 @file |
|
21 @internalComponent |
|
22 @released |
|
23 */ |
|
24 |
|
25 #include <string> |
|
26 #include <algorithm> |
|
27 |
|
28 #include "sisfiledata.h" |
|
29 #include "blob.h" |
|
30 #include "utility.h" |
|
31 |
|
32 |
|
33 void CSISFileData::Load (const std::wstring& aFile, TUint64* aSize) |
|
34 |
|
35 { |
|
36 TUint64 size = 0; |
|
37 HANDLE file = OpenFileAndGetSize (aFile, &size); |
|
38 try |
|
39 { |
|
40 iData.Content ().SetByteCount (size); |
|
41 } |
|
42 catch (...) |
|
43 { |
|
44 ::CloseHandle(file); |
|
45 throw; |
|
46 } |
|
47 ReadAndCloseFile (file, size, iData.Content ().Data ()); |
|
48 if (aSize) |
|
49 { |
|
50 *aSize = size; |
|
51 } |
|
52 } |
|
53 |
|
54 TUint32 CSISFileData::GetSid() const |
|
55 { |
|
56 const int fileLength = UncompressedSize(); |
|
57 if(fileLength <= sizeof(TUint32)*0x05) |
|
58 { |
|
59 return 0; |
|
60 } |
|
61 |
|
62 const unsigned char* data8 = Data(); |
|
63 const TUint32* data32 = reinterpret_cast<const TUint32*>(data8); |
|
64 |
|
65 TUint32 ret = 0; |
|
66 // Check the file signature. If its a ARM based symbian executable |
|
67 // then the signature should be "EPOC". Check E32ImageHeader for more |
|
68 // details |
|
69 if ( data32[0x04] == KFileHeaderSignature ) |
|
70 { |
|
71 // If its a symbian executable then check the SID |
|
72 // of the executable. |
|
73 if(fileLength > (0x80 + sizeof(TUint32))) |
|
74 { |
|
75 ret = *((TUint32*) (data8 + 0x80 )); |
|
76 } |
|
77 } |
|
78 else if (data8[0] == 'M' && data8[1] == 'Z') |
|
79 { |
|
80 // Emulator executable has a different format. |
|
81 // All symbian emulator based executable will have ".SYMBIAN" |
|
82 // in it. Symbian header will be after this signature. |
|
83 // So search for this marker to read symbian file header. |
|
84 const char symbian[] = ".SYMBIAN"; |
|
85 const int len2 = sizeof(symbian)-1; |
|
86 |
|
87 const unsigned char* index = std::search(data8, data8+fileLength, symbian, symbian+len2); |
|
88 if (index != data8+fileLength) |
|
89 { |
|
90 index += KHeaderUidLength; |
|
91 TInt32 offset = *(TInt32*)index; |
|
92 |
|
93 // There should be enough data to read the UIDs from the file. |
|
94 if(fileLength <= (offset + 4*sizeof(TUint32))) |
|
95 { |
|
96 return 0; |
|
97 } |
|
98 |
|
99 const TUint32* x = (TUint32*)(data8+offset); |
|
100 // The three UIDs (12 bytes) of the file |
|
101 // x[0] = the structure of the file |
|
102 // x[1] = identifies the interface the polymorphic DLL implements |
|
103 // or for shared library DLLs that others link to, this value is always the same |
|
104 // or for executables the UID value has to be set to KUidApp or NULL |
|
105 // x[3] = distinguishes between objects with the same UID2 |
|
106 // and can be thought of as a project identifier |
|
107 if (x[0] == KExecutableImageUid) |
|
108 { |
|
109 ret = x[4]; |
|
110 } |
|
111 } |
|
112 } |
|
113 return ret; |
|
114 } |
|
115 |
|
116 |
|
117 bool CSISFileData::IsExecutable() const |
|
118 { |
|
119 return IsExecutableData(Data(), UncompressedSize()); |
|
120 } |
|
121 |
|
122 bool CSISFileData::IsEmulatorExecutable() const |
|
123 { |
|
124 return IsEmulatorExecutableData(Data(), UncompressedSize()); |
|
125 } |
|
126 |
|
127 bool CSISFileData::IsExe() const |
|
128 { |
|
129 return IsExeData(Data(), UncompressedSize()); |
|
130 } |
|
131 |
|
132 bool CSISFileData::IsDll() const |
|
133 { |
|
134 return IsDllData(Data(), UncompressedSize()); |
|
135 } |
|
136 |
|
137 |