sl@0: // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\dll\t_xxver2w.cpp sl@0: // Overview: sl@0: // Check of DLL & EXE module info and DDL function ordinals sl@0: // API Information: sl@0: // RLibrary sl@0: // Details: sl@0: // - Use RLibrary::GetInfoFromHeader() and RLibrary::GetInfo() to get DLL sl@0: // information. Verify results are as expected. sl@0: // - Use RLibrary::GetInfoFromHeader() and RLibrary::GetInfo() to get EXE sl@0: // information. Verify results are as expected. sl@0: // - Load a DLL, lookup and verify the function at the specified ordinal sl@0: // within the DLL. sl@0: // Platforms/Drives/Compatibility: sl@0: // All. sl@0: // Assumptions/Requirement/Pre-requisites: sl@0: // Failures and causes: sl@0: // Base Port information: sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: RTest test(_L("T_XXVER2W")); sl@0: RLdrTest LdrTest; sl@0: sl@0: TFileName CopyBinaryFromZ(const TFileName& aFileName) sl@0: { sl@0: TParse parse; sl@0: test(parse.Set(aFileName,0,0)==KErrNone); sl@0: TFileName source = _L("z:"); sl@0: source.Append(parse.NameAndExt()); sl@0: sl@0: TBuf sName; sl@0: TInt r = MapEmulatedFileName(sName, parse.NameAndExt()); sl@0: test(r==KErrNone); sl@0: sl@0: TFileName destination = _S16("C:\\t_zzver2w.tmp"); sl@0: TBuf dName; sl@0: r = MapEmulatedFileName(dName, destination); sl@0: test(r==KErrNone); sl@0: sl@0: r=Emulator::CopyFile((LPCTSTR)sName.PtrZ(),(LPCTSTR)dName.PtrZ(),FALSE); sl@0: test(r); sl@0: sl@0: return destination; sl@0: } sl@0: sl@0: sl@0: void TestDllInfo() sl@0: { sl@0: TFileName fn; sl@0: if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)) sl@0: fn = _S16("Z:\\sys\\bin\\t_ver2.dll"); sl@0: else sl@0: fn = _S16("Z:\\system\\bin\\t_ver2.dll"); sl@0: test.Printf(_L("Getting info for %S\n"), &fn); sl@0: TBool formHeader=EFalse; sl@0: for(;;) sl@0: { sl@0: RLibrary::TInfo info; sl@0: TPckg infoBuf(info); sl@0: TInt r; sl@0: if(formHeader) sl@0: { sl@0: TUint8* buf; sl@0: sl@0: RFs fs; sl@0: test(fs.Connect()==KErrNone); sl@0: RFile file; sl@0: test((r=file.Open(fs,CopyBinaryFromZ(fn),0))==KErrNone); sl@0: TInt size; sl@0: test((r=file.Size(size))==KErrNone); sl@0: buf=new TUint8[size]; sl@0: test(buf!=0); sl@0: TPtr8 header(buf,size); sl@0: test((r=file.Read(header))==KErrNone); sl@0: file.Close(); sl@0: fs.Close(); sl@0: sl@0: r = RLibrary::GetInfoFromHeader(header, infoBuf); sl@0: test.Printf(_L("GetInfoFromHeader returns %d\n"), r); sl@0: sl@0: delete buf; sl@0: } sl@0: else sl@0: { sl@0: r = RLibrary::GetInfo(fn, infoBuf); sl@0: test.Printf(_L("GetInfo returns %d\n"), r); sl@0: } sl@0: sl@0: test(r==KErrNone); sl@0: const TUint32* uid = (const TUint32*)&info.iUids; sl@0: test.Printf(_L("VER %08x\n"), info.iModuleVersion); sl@0: test.Printf(_L("UID1 %08x\n"), uid[0]); sl@0: test.Printf(_L("UID2 %08x\n"), uid[1]); sl@0: test.Printf(_L("UID3 %08x\n"), uid[2]); sl@0: test.Printf(_L("SID %08x\n"), info.iSecurityInfo.iSecureId); sl@0: test.Printf(_L("VID %08x\n"), info.iSecurityInfo.iVendorId); sl@0: test.Printf(_L("CAP0 %08x\n"), ((SSecurityInfo&)info.iSecurityInfo).iCaps[0]); sl@0: test.Printf(_L("CAP1 %08x\n"), ((SSecurityInfo&)info.iSecurityInfo).iCaps[1]); sl@0: TUint32 v = 0x00030000u; sl@0: test(info.iModuleVersion == v); sl@0: test(uid[0] == (TUint32)KDynamicLibraryUidValue); sl@0: test(uid[2] == (TUint32)0x40abcdef); sl@0: TUint32 xsid = ((v>>16)<<4)|(v&0x0f)|0x89abcd00u; sl@0: test(info.iSecurityInfo.iSecureId == xsid); sl@0: test(info.iSecurityInfo.iVendorId == 0x01234500+(xsid&0xff)); sl@0: test(((SSecurityInfo&)info.iSecurityInfo).iCaps[0]==0x0002aaab); sl@0: test(((SSecurityInfo&)info.iSecurityInfo).iCaps[1]==0); sl@0: sl@0: if(formHeader) sl@0: break; sl@0: formHeader = ETrue; sl@0: } sl@0: } sl@0: sl@0: void TestExeInfo() sl@0: { sl@0: TFileName fn; sl@0: if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)) sl@0: fn = _S16("Z:\\sys\\bin\\t_xxver2w.exe"); sl@0: else sl@0: fn = _S16("Z:\\system\\bin\\t_xxver2w.exe"); sl@0: test.Printf(_L("Getting info for %S\n"), &fn); sl@0: TBool formHeader=EFalse; sl@0: for(;;) sl@0: { sl@0: RLibrary::TInfo info; sl@0: TPckg infoBuf(info); sl@0: TInt r; sl@0: if(formHeader) sl@0: { sl@0: TUint8* buf; sl@0: sl@0: RFs fs; sl@0: test(fs.Connect()==KErrNone); sl@0: RFile file; sl@0: test((r=file.Open(fs,CopyBinaryFromZ(fn),0))==KErrNone); sl@0: TInt size; sl@0: test((r=file.Size(size))==KErrNone); sl@0: buf=new TUint8[size]; sl@0: test(buf!=0); sl@0: TPtr8 header(buf,size); sl@0: test((r=file.Read(header))==KErrNone); sl@0: file.Close(); sl@0: fs.Close(); sl@0: sl@0: r = RLibrary::GetInfoFromHeader(header, infoBuf); sl@0: test.Printf(_L("GetInfoFromHeader returns %d\n"), r); sl@0: sl@0: delete buf; sl@0: } sl@0: else sl@0: { sl@0: r = RLibrary::GetInfo(fn, infoBuf); sl@0: test.Printf(_L("GetInfo returns %d\n"), r); sl@0: } sl@0: sl@0: test(r==KErrNone); sl@0: const TUint32* uid = (const TUint32*)&info.iUids; sl@0: test.Printf(_L("VER %08x\n"), info.iModuleVersion); sl@0: test.Printf(_L("UID1 %08x\n"), uid[0]); sl@0: test.Printf(_L("UID2 %08x\n"), uid[1]); sl@0: test.Printf(_L("UID3 %08x\n"), uid[2]); sl@0: test.Printf(_L("SID %08x\n"), info.iSecurityInfo.iSecureId); sl@0: test.Printf(_L("VID %08x\n"), info.iSecurityInfo.iVendorId); sl@0: test.Printf(_L("CAP0 %08x\n"), ((SSecurityInfo&)info.iSecurityInfo).iCaps[0]); sl@0: test.Printf(_L("CAP1 %08x\n"), ((SSecurityInfo&)info.iSecurityInfo).iCaps[1]); sl@0: test(info.iModuleVersion == 0x00010000); sl@0: test(uid[0] == (TUint32)KExecutableImageUidValue); sl@0: TUint32 xuid3 = 0x40abcd77u; sl@0: test(uid[2] == xuid3); sl@0: test(info.iSecurityInfo.iSecureId == xuid3); sl@0: test(info.iSecurityInfo.iVendorId == 0x01234577); sl@0: test(((SSecurityInfo&)info.iSecurityInfo).iCaps[0]==0x0002aaab); sl@0: test(((SSecurityInfo&)info.iSecurityInfo).iCaps[1]==0); sl@0: sl@0: if(formHeader) sl@0: break; sl@0: formHeader = ETrue; sl@0: } sl@0: } sl@0: sl@0: sl@0: struct SExportInfo sl@0: { sl@0: TInt iTotal; sl@0: TInt iHoles; sl@0: TInt iHole[1]; sl@0: }; sl@0: sl@0: const TInt DllExportInfo[] = {59,6,2,3,4,23,24,39}; sl@0: void CheckExports(RLibrary aLib) sl@0: { sl@0: const TFileName& fn = aLib.FileName(); sl@0: test.Printf(_L("Filename %S\n"), &fn); sl@0: const SExportInfo* e = (const SExportInfo*)DllExportInfo; sl@0: TAny* libcs = LdrTest.LibraryCodeSeg(aLib.Handle()); sl@0: test.Printf(_L("Code seg @%08x\n"), libcs); sl@0: test(libcs != NULL); sl@0: TInt n = e->iTotal; sl@0: TInt nh = e->iHoles; sl@0: TInt ord; sl@0: for (ord=1; ord<=n+1; ++ord) sl@0: { sl@0: TLibraryFunction f = aLib.Lookup(ord); sl@0: test.Printf(_L("Ord %3d->%08x\n"), ord, f); sl@0: if (ord>n) sl@0: { sl@0: test(!f); sl@0: continue; sl@0: } sl@0: TInt i; sl@0: for (i=0; iiHole[i]!=ord; ++i) {} sl@0: if (i