sl@0
|
1 |
// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// e32test\dll\t_xxver2w.cpp
|
sl@0
|
15 |
// Overview:
|
sl@0
|
16 |
// Check of DLL & EXE module info and DDL function ordinals
|
sl@0
|
17 |
// API Information:
|
sl@0
|
18 |
// RLibrary
|
sl@0
|
19 |
// Details:
|
sl@0
|
20 |
// - Use RLibrary::GetInfoFromHeader() and RLibrary::GetInfo() to get DLL
|
sl@0
|
21 |
// information. Verify results are as expected.
|
sl@0
|
22 |
// - Use RLibrary::GetInfoFromHeader() and RLibrary::GetInfo() to get EXE
|
sl@0
|
23 |
// information. Verify results are as expected.
|
sl@0
|
24 |
// - Load a DLL, lookup and verify the function at the specified ordinal
|
sl@0
|
25 |
// within the DLL.
|
sl@0
|
26 |
// Platforms/Drives/Compatibility:
|
sl@0
|
27 |
// All.
|
sl@0
|
28 |
// Assumptions/Requirement/Pre-requisites:
|
sl@0
|
29 |
// Failures and causes:
|
sl@0
|
30 |
// Base Port information:
|
sl@0
|
31 |
//
|
sl@0
|
32 |
//
|
sl@0
|
33 |
|
sl@0
|
34 |
#include <e32uid.h>
|
sl@0
|
35 |
#include <e32test.h>
|
sl@0
|
36 |
#include <f32file.h>
|
sl@0
|
37 |
|
sl@0
|
38 |
#include <e32wins.h>
|
sl@0
|
39 |
#include <emulator.h>
|
sl@0
|
40 |
#include <d_ldrtst.h>
|
sl@0
|
41 |
|
sl@0
|
42 |
RTest test(_L("T_XXVER2W"));
|
sl@0
|
43 |
RLdrTest LdrTest;
|
sl@0
|
44 |
|
sl@0
|
45 |
TFileName CopyBinaryFromZ(const TFileName& aFileName)
|
sl@0
|
46 |
{
|
sl@0
|
47 |
TParse parse;
|
sl@0
|
48 |
test(parse.Set(aFileName,0,0)==KErrNone);
|
sl@0
|
49 |
TFileName source = _L("z:");
|
sl@0
|
50 |
source.Append(parse.NameAndExt());
|
sl@0
|
51 |
|
sl@0
|
52 |
TBuf<MAX_PATH> sName;
|
sl@0
|
53 |
TInt r = MapEmulatedFileName(sName, parse.NameAndExt());
|
sl@0
|
54 |
test(r==KErrNone);
|
sl@0
|
55 |
|
sl@0
|
56 |
TFileName destination = _S16("C:\\t_zzver2w.tmp");
|
sl@0
|
57 |
TBuf<MAX_PATH> dName;
|
sl@0
|
58 |
r = MapEmulatedFileName(dName, destination);
|
sl@0
|
59 |
test(r==KErrNone);
|
sl@0
|
60 |
|
sl@0
|
61 |
r=Emulator::CopyFile((LPCTSTR)sName.PtrZ(),(LPCTSTR)dName.PtrZ(),FALSE);
|
sl@0
|
62 |
test(r);
|
sl@0
|
63 |
|
sl@0
|
64 |
return destination;
|
sl@0
|
65 |
}
|
sl@0
|
66 |
|
sl@0
|
67 |
|
sl@0
|
68 |
void TestDllInfo()
|
sl@0
|
69 |
{
|
sl@0
|
70 |
TFileName fn;
|
sl@0
|
71 |
if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
|
sl@0
|
72 |
fn = _S16("Z:\\sys\\bin\\t_ver2.dll");
|
sl@0
|
73 |
else
|
sl@0
|
74 |
fn = _S16("Z:\\system\\bin\\t_ver2.dll");
|
sl@0
|
75 |
test.Printf(_L("Getting info for %S\n"), &fn);
|
sl@0
|
76 |
TBool formHeader=EFalse;
|
sl@0
|
77 |
for(;;)
|
sl@0
|
78 |
{
|
sl@0
|
79 |
RLibrary::TInfo info;
|
sl@0
|
80 |
TPckg<RLibrary::TInfo> infoBuf(info);
|
sl@0
|
81 |
TInt r;
|
sl@0
|
82 |
if(formHeader)
|
sl@0
|
83 |
{
|
sl@0
|
84 |
TUint8* buf;
|
sl@0
|
85 |
|
sl@0
|
86 |
RFs fs;
|
sl@0
|
87 |
test(fs.Connect()==KErrNone);
|
sl@0
|
88 |
RFile file;
|
sl@0
|
89 |
test((r=file.Open(fs,CopyBinaryFromZ(fn),0))==KErrNone);
|
sl@0
|
90 |
TInt size;
|
sl@0
|
91 |
test((r=file.Size(size))==KErrNone);
|
sl@0
|
92 |
buf=new TUint8[size];
|
sl@0
|
93 |
test(buf!=0);
|
sl@0
|
94 |
TPtr8 header(buf,size);
|
sl@0
|
95 |
test((r=file.Read(header))==KErrNone);
|
sl@0
|
96 |
file.Close();
|
sl@0
|
97 |
fs.Close();
|
sl@0
|
98 |
|
sl@0
|
99 |
r = RLibrary::GetInfoFromHeader(header, infoBuf);
|
sl@0
|
100 |
test.Printf(_L("GetInfoFromHeader returns %d\n"), r);
|
sl@0
|
101 |
|
sl@0
|
102 |
delete buf;
|
sl@0
|
103 |
}
|
sl@0
|
104 |
else
|
sl@0
|
105 |
{
|
sl@0
|
106 |
r = RLibrary::GetInfo(fn, infoBuf);
|
sl@0
|
107 |
test.Printf(_L("GetInfo returns %d\n"), r);
|
sl@0
|
108 |
}
|
sl@0
|
109 |
|
sl@0
|
110 |
test(r==KErrNone);
|
sl@0
|
111 |
const TUint32* uid = (const TUint32*)&info.iUids;
|
sl@0
|
112 |
test.Printf(_L("VER %08x\n"), info.iModuleVersion);
|
sl@0
|
113 |
test.Printf(_L("UID1 %08x\n"), uid[0]);
|
sl@0
|
114 |
test.Printf(_L("UID2 %08x\n"), uid[1]);
|
sl@0
|
115 |
test.Printf(_L("UID3 %08x\n"), uid[2]);
|
sl@0
|
116 |
test.Printf(_L("SID %08x\n"), info.iSecurityInfo.iSecureId);
|
sl@0
|
117 |
test.Printf(_L("VID %08x\n"), info.iSecurityInfo.iVendorId);
|
sl@0
|
118 |
test.Printf(_L("CAP0 %08x\n"), ((SSecurityInfo&)info.iSecurityInfo).iCaps[0]);
|
sl@0
|
119 |
test.Printf(_L("CAP1 %08x\n"), ((SSecurityInfo&)info.iSecurityInfo).iCaps[1]);
|
sl@0
|
120 |
TUint32 v = 0x00030000u;
|
sl@0
|
121 |
test(info.iModuleVersion == v);
|
sl@0
|
122 |
test(uid[0] == (TUint32)KDynamicLibraryUidValue);
|
sl@0
|
123 |
test(uid[2] == (TUint32)0x40abcdef);
|
sl@0
|
124 |
TUint32 xsid = ((v>>16)<<4)|(v&0x0f)|0x89abcd00u;
|
sl@0
|
125 |
test(info.iSecurityInfo.iSecureId == xsid);
|
sl@0
|
126 |
test(info.iSecurityInfo.iVendorId == 0x01234500+(xsid&0xff));
|
sl@0
|
127 |
test(((SSecurityInfo&)info.iSecurityInfo).iCaps[0]==0x0002aaab);
|
sl@0
|
128 |
test(((SSecurityInfo&)info.iSecurityInfo).iCaps[1]==0);
|
sl@0
|
129 |
|
sl@0
|
130 |
if(formHeader)
|
sl@0
|
131 |
break;
|
sl@0
|
132 |
formHeader = ETrue;
|
sl@0
|
133 |
}
|
sl@0
|
134 |
}
|
sl@0
|
135 |
|
sl@0
|
136 |
void TestExeInfo()
|
sl@0
|
137 |
{
|
sl@0
|
138 |
TFileName fn;
|
sl@0
|
139 |
if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
|
sl@0
|
140 |
fn = _S16("Z:\\sys\\bin\\t_xxver2w.exe");
|
sl@0
|
141 |
else
|
sl@0
|
142 |
fn = _S16("Z:\\system\\bin\\t_xxver2w.exe");
|
sl@0
|
143 |
test.Printf(_L("Getting info for %S\n"), &fn);
|
sl@0
|
144 |
TBool formHeader=EFalse;
|
sl@0
|
145 |
for(;;)
|
sl@0
|
146 |
{
|
sl@0
|
147 |
RLibrary::TInfo info;
|
sl@0
|
148 |
TPckg<RLibrary::TInfo> infoBuf(info);
|
sl@0
|
149 |
TInt r;
|
sl@0
|
150 |
if(formHeader)
|
sl@0
|
151 |
{
|
sl@0
|
152 |
TUint8* buf;
|
sl@0
|
153 |
|
sl@0
|
154 |
RFs fs;
|
sl@0
|
155 |
test(fs.Connect()==KErrNone);
|
sl@0
|
156 |
RFile file;
|
sl@0
|
157 |
test((r=file.Open(fs,CopyBinaryFromZ(fn),0))==KErrNone);
|
sl@0
|
158 |
TInt size;
|
sl@0
|
159 |
test((r=file.Size(size))==KErrNone);
|
sl@0
|
160 |
buf=new TUint8[size];
|
sl@0
|
161 |
test(buf!=0);
|
sl@0
|
162 |
TPtr8 header(buf,size);
|
sl@0
|
163 |
test((r=file.Read(header))==KErrNone);
|
sl@0
|
164 |
file.Close();
|
sl@0
|
165 |
fs.Close();
|
sl@0
|
166 |
|
sl@0
|
167 |
r = RLibrary::GetInfoFromHeader(header, infoBuf);
|
sl@0
|
168 |
test.Printf(_L("GetInfoFromHeader returns %d\n"), r);
|
sl@0
|
169 |
|
sl@0
|
170 |
delete buf;
|
sl@0
|
171 |
}
|
sl@0
|
172 |
else
|
sl@0
|
173 |
{
|
sl@0
|
174 |
r = RLibrary::GetInfo(fn, infoBuf);
|
sl@0
|
175 |
test.Printf(_L("GetInfo returns %d\n"), r);
|
sl@0
|
176 |
}
|
sl@0
|
177 |
|
sl@0
|
178 |
test(r==KErrNone);
|
sl@0
|
179 |
const TUint32* uid = (const TUint32*)&info.iUids;
|
sl@0
|
180 |
test.Printf(_L("VER %08x\n"), info.iModuleVersion);
|
sl@0
|
181 |
test.Printf(_L("UID1 %08x\n"), uid[0]);
|
sl@0
|
182 |
test.Printf(_L("UID2 %08x\n"), uid[1]);
|
sl@0
|
183 |
test.Printf(_L("UID3 %08x\n"), uid[2]);
|
sl@0
|
184 |
test.Printf(_L("SID %08x\n"), info.iSecurityInfo.iSecureId);
|
sl@0
|
185 |
test.Printf(_L("VID %08x\n"), info.iSecurityInfo.iVendorId);
|
sl@0
|
186 |
test.Printf(_L("CAP0 %08x\n"), ((SSecurityInfo&)info.iSecurityInfo).iCaps[0]);
|
sl@0
|
187 |
test.Printf(_L("CAP1 %08x\n"), ((SSecurityInfo&)info.iSecurityInfo).iCaps[1]);
|
sl@0
|
188 |
test(info.iModuleVersion == 0x00010000);
|
sl@0
|
189 |
test(uid[0] == (TUint32)KExecutableImageUidValue);
|
sl@0
|
190 |
TUint32 xuid3 = 0x40abcd77u;
|
sl@0
|
191 |
test(uid[2] == xuid3);
|
sl@0
|
192 |
test(info.iSecurityInfo.iSecureId == xuid3);
|
sl@0
|
193 |
test(info.iSecurityInfo.iVendorId == 0x01234577);
|
sl@0
|
194 |
test(((SSecurityInfo&)info.iSecurityInfo).iCaps[0]==0x0002aaab);
|
sl@0
|
195 |
test(((SSecurityInfo&)info.iSecurityInfo).iCaps[1]==0);
|
sl@0
|
196 |
|
sl@0
|
197 |
if(formHeader)
|
sl@0
|
198 |
break;
|
sl@0
|
199 |
formHeader = ETrue;
|
sl@0
|
200 |
}
|
sl@0
|
201 |
}
|
sl@0
|
202 |
|
sl@0
|
203 |
|
sl@0
|
204 |
struct SExportInfo
|
sl@0
|
205 |
{
|
sl@0
|
206 |
TInt iTotal;
|
sl@0
|
207 |
TInt iHoles;
|
sl@0
|
208 |
TInt iHole[1];
|
sl@0
|
209 |
};
|
sl@0
|
210 |
|
sl@0
|
211 |
const TInt DllExportInfo[] = {59,6,2,3,4,23,24,39};
|
sl@0
|
212 |
void CheckExports(RLibrary aLib)
|
sl@0
|
213 |
{
|
sl@0
|
214 |
const TFileName& fn = aLib.FileName();
|
sl@0
|
215 |
test.Printf(_L("Filename %S\n"), &fn);
|
sl@0
|
216 |
const SExportInfo* e = (const SExportInfo*)DllExportInfo;
|
sl@0
|
217 |
TAny* libcs = LdrTest.LibraryCodeSeg(aLib.Handle());
|
sl@0
|
218 |
test.Printf(_L("Code seg @%08x\n"), libcs);
|
sl@0
|
219 |
test(libcs != NULL);
|
sl@0
|
220 |
TInt n = e->iTotal;
|
sl@0
|
221 |
TInt nh = e->iHoles;
|
sl@0
|
222 |
TInt ord;
|
sl@0
|
223 |
for (ord=1; ord<=n+1; ++ord)
|
sl@0
|
224 |
{
|
sl@0
|
225 |
TLibraryFunction f = aLib.Lookup(ord);
|
sl@0
|
226 |
test.Printf(_L("Ord %3d->%08x\n"), ord, f);
|
sl@0
|
227 |
if (ord>n)
|
sl@0
|
228 |
{
|
sl@0
|
229 |
test(!f);
|
sl@0
|
230 |
continue;
|
sl@0
|
231 |
}
|
sl@0
|
232 |
TInt i;
|
sl@0
|
233 |
for (i=0; i<nh && e->iHole[i]!=ord; ++i) {}
|
sl@0
|
234 |
if (i<nh)
|
sl@0
|
235 |
test(!f); // hole
|
sl@0
|
236 |
else
|
sl@0
|
237 |
test(f!=NULL);
|
sl@0
|
238 |
TAny* cs = LdrTest.CodeSegFromAddr((TLinAddr)f);
|
sl@0
|
239 |
test(f ? (cs==libcs) : !cs);
|
sl@0
|
240 |
}
|
sl@0
|
241 |
}
|
sl@0
|
242 |
|
sl@0
|
243 |
void TestMissingOrdinals()
|
sl@0
|
244 |
{
|
sl@0
|
245 |
RLibrary l;
|
sl@0
|
246 |
TFileName fn;
|
sl@0
|
247 |
if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
|
sl@0
|
248 |
fn = _S("Z:\\sys\\bin\\t_ver2.dll");
|
sl@0
|
249 |
else
|
sl@0
|
250 |
fn = _S("Z:\\system\\bin\\t_ver2.dll");
|
sl@0
|
251 |
TInt r = l.Load(fn);
|
sl@0
|
252 |
test.Printf(_L("Load %S returns %d\n"), &fn, r);
|
sl@0
|
253 |
CheckExports(l);
|
sl@0
|
254 |
l.Close();
|
sl@0
|
255 |
}
|
sl@0
|
256 |
|
sl@0
|
257 |
TInt E32Main()
|
sl@0
|
258 |
{
|
sl@0
|
259 |
test.Title();
|
sl@0
|
260 |
|
sl@0
|
261 |
test.Start(_L("Connect to test driver"));
|
sl@0
|
262 |
TInt r = User::LoadLogicalDevice(_L("d_ldrtst"));
|
sl@0
|
263 |
test(r==KErrNone || r==KErrAlreadyExists);
|
sl@0
|
264 |
r = LdrTest.Open();
|
sl@0
|
265 |
test(r==KErrNone);
|
sl@0
|
266 |
|
sl@0
|
267 |
test.Next(_L("Test DLL Info"));
|
sl@0
|
268 |
TestDllInfo();
|
sl@0
|
269 |
|
sl@0
|
270 |
test.Next(_L("Test EXE Info"));
|
sl@0
|
271 |
TestExeInfo();
|
sl@0
|
272 |
|
sl@0
|
273 |
test.Next(_L("Test Missing Ordinals"));
|
sl@0
|
274 |
TestMissingOrdinals();
|
sl@0
|
275 |
|
sl@0
|
276 |
LdrTest.Close();
|
sl@0
|
277 |
test.End();
|
sl@0
|
278 |
return KErrNone;
|
sl@0
|
279 |
}
|
sl@0
|
280 |
|