Update contrib.
1 // Copyright (c) 2003-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 the License "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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\dll\t_xxver2w.cpp
16 // Check of DLL & EXE module info and DDL function ordinals
20 // - Use RLibrary::GetInfoFromHeader() and RLibrary::GetInfo() to get DLL
21 // information. Verify results are as expected.
22 // - Use RLibrary::GetInfoFromHeader() and RLibrary::GetInfo() to get EXE
23 // information. Verify results are as expected.
24 // - Load a DLL, lookup and verify the function at the specified ordinal
26 // Platforms/Drives/Compatibility:
28 // Assumptions/Requirement/Pre-requisites:
29 // Failures and causes:
30 // Base Port information:
42 RTest test(_L("T_XXVER2W"));
45 TFileName CopyBinaryFromZ(const TFileName& aFileName)
48 test(parse.Set(aFileName,0,0)==KErrNone);
49 TFileName source = _L("z:");
50 source.Append(parse.NameAndExt());
53 TInt r = MapEmulatedFileName(sName, parse.NameAndExt());
56 TFileName destination = _S16("C:\\t_zzver2w.tmp");
58 r = MapEmulatedFileName(dName, destination);
61 r=Emulator::CopyFile((LPCTSTR)sName.PtrZ(),(LPCTSTR)dName.PtrZ(),FALSE);
71 if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
72 fn = _S16("Z:\\sys\\bin\\t_ver2.dll");
74 fn = _S16("Z:\\system\\bin\\t_ver2.dll");
75 test.Printf(_L("Getting info for %S\n"), &fn);
76 TBool formHeader=EFalse;
80 TPckg<RLibrary::TInfo> infoBuf(info);
87 test(fs.Connect()==KErrNone);
89 test((r=file.Open(fs,CopyBinaryFromZ(fn),0))==KErrNone);
91 test((r=file.Size(size))==KErrNone);
94 TPtr8 header(buf,size);
95 test((r=file.Read(header))==KErrNone);
99 r = RLibrary::GetInfoFromHeader(header, infoBuf);
100 test.Printf(_L("GetInfoFromHeader returns %d\n"), r);
106 r = RLibrary::GetInfo(fn, infoBuf);
107 test.Printf(_L("GetInfo returns %d\n"), r);
111 const TUint32* uid = (const TUint32*)&info.iUids;
112 test.Printf(_L("VER %08x\n"), info.iModuleVersion);
113 test.Printf(_L("UID1 %08x\n"), uid[0]);
114 test.Printf(_L("UID2 %08x\n"), uid[1]);
115 test.Printf(_L("UID3 %08x\n"), uid[2]);
116 test.Printf(_L("SID %08x\n"), info.iSecurityInfo.iSecureId);
117 test.Printf(_L("VID %08x\n"), info.iSecurityInfo.iVendorId);
118 test.Printf(_L("CAP0 %08x\n"), ((SSecurityInfo&)info.iSecurityInfo).iCaps[0]);
119 test.Printf(_L("CAP1 %08x\n"), ((SSecurityInfo&)info.iSecurityInfo).iCaps[1]);
120 TUint32 v = 0x00030000u;
121 test(info.iModuleVersion == v);
122 test(uid[0] == (TUint32)KDynamicLibraryUidValue);
123 test(uid[2] == (TUint32)0x40abcdef);
124 TUint32 xsid = ((v>>16)<<4)|(v&0x0f)|0x89abcd00u;
125 test(info.iSecurityInfo.iSecureId == xsid);
126 test(info.iSecurityInfo.iVendorId == 0x01234500+(xsid&0xff));
127 test(((SSecurityInfo&)info.iSecurityInfo).iCaps[0]==0x0002aaab);
128 test(((SSecurityInfo&)info.iSecurityInfo).iCaps[1]==0);
139 if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
140 fn = _S16("Z:\\sys\\bin\\t_xxver2w.exe");
142 fn = _S16("Z:\\system\\bin\\t_xxver2w.exe");
143 test.Printf(_L("Getting info for %S\n"), &fn);
144 TBool formHeader=EFalse;
147 RLibrary::TInfo info;
148 TPckg<RLibrary::TInfo> infoBuf(info);
155 test(fs.Connect()==KErrNone);
157 test((r=file.Open(fs,CopyBinaryFromZ(fn),0))==KErrNone);
159 test((r=file.Size(size))==KErrNone);
160 buf=new TUint8[size];
162 TPtr8 header(buf,size);
163 test((r=file.Read(header))==KErrNone);
167 r = RLibrary::GetInfoFromHeader(header, infoBuf);
168 test.Printf(_L("GetInfoFromHeader returns %d\n"), r);
174 r = RLibrary::GetInfo(fn, infoBuf);
175 test.Printf(_L("GetInfo returns %d\n"), r);
179 const TUint32* uid = (const TUint32*)&info.iUids;
180 test.Printf(_L("VER %08x\n"), info.iModuleVersion);
181 test.Printf(_L("UID1 %08x\n"), uid[0]);
182 test.Printf(_L("UID2 %08x\n"), uid[1]);
183 test.Printf(_L("UID3 %08x\n"), uid[2]);
184 test.Printf(_L("SID %08x\n"), info.iSecurityInfo.iSecureId);
185 test.Printf(_L("VID %08x\n"), info.iSecurityInfo.iVendorId);
186 test.Printf(_L("CAP0 %08x\n"), ((SSecurityInfo&)info.iSecurityInfo).iCaps[0]);
187 test.Printf(_L("CAP1 %08x\n"), ((SSecurityInfo&)info.iSecurityInfo).iCaps[1]);
188 test(info.iModuleVersion == 0x00010000);
189 test(uid[0] == (TUint32)KExecutableImageUidValue);
190 TUint32 xuid3 = 0x40abcd77u;
191 test(uid[2] == xuid3);
192 test(info.iSecurityInfo.iSecureId == xuid3);
193 test(info.iSecurityInfo.iVendorId == 0x01234577);
194 test(((SSecurityInfo&)info.iSecurityInfo).iCaps[0]==0x0002aaab);
195 test(((SSecurityInfo&)info.iSecurityInfo).iCaps[1]==0);
211 const TInt DllExportInfo[] = {59,6,2,3,4,23,24,39};
212 void CheckExports(RLibrary aLib)
214 const TFileName& fn = aLib.FileName();
215 test.Printf(_L("Filename %S\n"), &fn);
216 const SExportInfo* e = (const SExportInfo*)DllExportInfo;
217 TAny* libcs = LdrTest.LibraryCodeSeg(aLib.Handle());
218 test.Printf(_L("Code seg @%08x\n"), libcs);
223 for (ord=1; ord<=n+1; ++ord)
225 TLibraryFunction f = aLib.Lookup(ord);
226 test.Printf(_L("Ord %3d->%08x\n"), ord, f);
233 for (i=0; i<nh && e->iHole[i]!=ord; ++i) {}
238 TAny* cs = LdrTest.CodeSegFromAddr((TLinAddr)f);
239 test(f ? (cs==libcs) : !cs);
243 void TestMissingOrdinals()
247 if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
248 fn = _S("Z:\\sys\\bin\\t_ver2.dll");
250 fn = _S("Z:\\system\\bin\\t_ver2.dll");
252 test.Printf(_L("Load %S returns %d\n"), &fn, r);
261 test.Start(_L("Connect to test driver"));
262 TInt r = User::LoadLogicalDevice(_L("d_ldrtst"));
263 test(r==KErrNone || r==KErrAlreadyExists);
267 test.Next(_L("Test DLL Info"));
270 test.Next(_L("Test EXE Info"));
273 test.Next(_L("Test Missing Ordinals"));
274 TestMissingOrdinals();