First public contribution.
1 // Copyright (c) 1999-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 // f32test\loader\t_ldrcheck.cpp
30 #if defined (WIN32) && !defined (__X86GCC__)
36 RTest test(_L("T_LDRCheck"));
38 GLDEF_D TChar gDriveToTest;
42 Copy modules from z:\\sys\\bin to c:\\sys\\bin
46 test.Next(_L("Copy Modules from ROM to disk"));
51 r=TheFs.MkDirAll(KSystemLibs);
52 test(r==KErrNone || r==KErrAlreadyExists);
54 CFileMan* fileMan=NULL;
55 TRAP(r,fileMan=CFileMan::NewL(TheFs));
58 TBuf<40> dllfilenames;
59 TBuf<40> dlldestination;
61 for(TInt i=0;i<14;i++)
63 dllfilenames=KDllfilename;
64 dllfilenames.AppendNum(i);
65 dllfilenames +=KDllExt;
66 dlldestination=KNewDllName;
67 dlldestination.AppendNum(i);
68 dlldestination+=KDllExt;
70 r=fileMan->Copy(dllfilenames,dlldestination, 0);
71 test(r==KErrNone || r==KErrAlreadyExists);
73 r=fileMan->Attribs(dlldestination,0, KEntryAttReadOnly,modtime,0);
78 TBuf<40> exefilenames;
79 TBuf<40> exedestination;
81 for(TInt j=14;j<16;j++)
83 exefilenames=KExefilename;
84 exefilenames.AppendNum(j);
85 exefilenames +=KExeExt;
86 exedestination=KNewExeName;
87 exedestination.AppendNum(j);
88 exedestination+=KExeExt;
90 r=fileMan->Copy(exefilenames,exedestination,0);
91 test(r==KErrNone || r==KErrAlreadyExists);
93 r=fileMan->Attribs(exedestination, 0, KEntryAttReadOnly, modtime, 0);
104 void ModifyModuleCapabilties(TUint32 aNewCap, TInt aModuleNumber)
106 // Assign new capabilties to a module using raw disk write
109 // test.Next(_L("Modify Module Capabilities"));
111 test(aModuleNumber<=15 && aModuleNumber>=0);
113 TBuf<40> dlldestination;
118 memset(&caps,0,sizeof(caps));
120 TPtrC8 theNewCaps((TUint8*)(&caps),sizeof(caps));
122 if(aModuleNumber < 14)
124 dlldestination=KNewDllName;
125 dlldestination.AppendNum(aModuleNumber);
126 dlldestination+=KDllExt;
130 dlldestination=KNewExeName;
131 dlldestination.AppendNum(aModuleNumber);
132 dlldestination+=KExeExt;
135 r=modFile.Open(TheFs, dlldestination, EFileWrite);
137 r=modFile.Write(_FOFF(E32ImageHeaderV,iS.iCaps), theNewCaps,4);
142 TCapabilitySet theCaps;
143 RLibrary::TInfoBuf info;
145 lib.GetInfo(dlldestination, info);
146 theCaps=info().iSecurityInfo.iCaps;
149 test(theCaps==aNewCap);
155 void ModifyModuleCapabilties(TUint32 aNewCap, TInt aModuleNumber)
157 // Wins version (poking values is not quite so simple
160 // test.Next(_L("Modify Module Capabilities"));
161 test(aModuleNumber<=15 && aModuleNumber>=0);
163 TBuf<40> dlldestination;
166 TPtrC8 theNewCaps((TUint8*)(&aNewCap),sizeof(TUint32));
169 if(aModuleNumber < 14)
171 dlldestination=KNewDllName;
172 dlldestination.AppendNum(aModuleNumber);
173 dlldestination+=KDllExt;
177 dlldestination=KNewExeName;
178 dlldestination.AppendNum(aModuleNumber);
179 dlldestination+=KExeExt;
183 TCapabilitySet theCaps2;
184 RLibrary::TInfoBuf info;
186 lib2.GetInfo(dlldestination, info);
187 theCaps2=info().iSecurityInfo.iCaps;
191 TBuf<MAX_PATH> fileName;
192 r = MapEmulatedFileName(fileName, dlldestination);
194 HANDLE hFile=Emulator::CreateFile((LPCTSTR)fileName.PtrZ(),GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL);
195 if (hFile==INVALID_HANDLE_VALUE)
198 TBuf8<sizeof(TCheckedUid)> checkedUidBuf;
199 checkedUidBuf.SetLength(sizeof(TCheckedUid));
200 ReadFile(hFile,&checkedUidBuf[0],sizeof(TCheckedUid),&ret,NULL);
201 if (ret!=sizeof(TCheckedUid))
204 //Look at PE file for UID section
206 const TInt KPeHeaderAddrAddr=0x3c;
207 const TInt KPeHeaderAddrSize=0x01;
208 const TInt KNumberOfSectionsOffset=0x06;
209 const TInt KNumberOfSectionsSize=0x02;
210 const TInt KSectionTableOffset=0xf8;
211 const TInt KSectionHeaderSize=0x28;
212 const TInt KSectionNameLength=0x08;
213 const TInt KPtrToRawDataOffset=0x14;
214 const TInt KPtrToRawDataSize=0x04;
215 const TText8 peText[4]={'P','E',0,0};
216 const TText8 uidText[8]={'.','S','Y','M','B','I','A','N'};
218 //Read address of start of PE header
219 if (SetFilePointer(hFile,KPeHeaderAddrAddr,0,FILE_BEGIN)==0xFFFFFFFF)
222 ReadFile(hFile,&peAddr,KPeHeaderAddrSize,&ret,NULL);
223 if (ret!=KPeHeaderAddrSize)
226 //Check it really is the start of PE header
227 if (SetFilePointer(hFile,peAddr,0,FILE_BEGIN)==0xFFFFFFFF)
230 ReadFile(hFile,text,4,&ret,NULL);
231 if (*(TInt32*)text!=*(TInt32*)peText)
234 //Read number of sections
235 if (SetFilePointer(hFile,peAddr+KNumberOfSectionsOffset,0,FILE_BEGIN)==0xFFFFFFFF)
238 ReadFile(hFile,§ions,KNumberOfSectionsSize,&ret,NULL);
239 if (ret!=KNumberOfSectionsSize)
242 //Go through section headers looking for UID section
243 if (SetFilePointer(hFile,peAddr+KSectionTableOffset,0,FILE_BEGIN)==0xFFFFFFFF)
248 TText8 name[KSectionNameLength];
249 ReadFile(hFile,name,KSectionNameLength,&ret,NULL);
250 if (ret!=KSectionNameLength)
252 if (*(TInt64*)name==*(TInt64*)uidText)
254 if (SetFilePointer(hFile,KSectionHeaderSize-KSectionNameLength,0,FILE_CURRENT)==0xFFFFFFFF)
261 if (SetFilePointer(hFile,KPtrToRawDataOffset-KSectionNameLength,0,FILE_CURRENT)==0xFFFFFFFF)
264 ReadFile(hFile,&uidOffset,KPtrToRawDataSize,&ret,NULL);
265 if (ret!=KPtrToRawDataSize)
269 if (SetFilePointer(hFile,uidOffset,0,FILE_BEGIN)==0xFFFFFFFF)
272 TEmulatorImageHeader header;
274 ReadFile(hFile,&header,sizeof(header),&ret,NULL);
275 if (ret!=sizeof(header))
278 // DON'T modify, for now header.iS.iCaps[0] = aNewCap; //assign new caps to binary
281 if (SetFilePointer(hFile,uidOffset,0,FILE_BEGIN)==0xFFFFFFFF)
284 BOOL b = WriteFile(hFile,&header,sizeof(header),&ret,NULL);
290 TCapabilitySet theCaps;
291 RLibrary::TInfoBuf info;
292 lib.GetInfo(dlldestination, info);
293 theCaps=info().iSecurityInfo.iCaps;
297 SCapabilitySet& realCaps = (SCapabilitySet&) theCaps;
298 // broke! test(realCaps[0] == aNewCap && realCaps[1] == 0);
311 void TestGetCapability()
313 // test RLibrary::GetCapabilites
318 test.Next(_L("Test RLibrary::GetCapabilities()"));
320 // These tests check the error code returned by the (deprecated) GetCapability method
321 // and now serve no useful purpose
322 // TCapability theCaps;
323 // r=library.GetCapability(theCaps,_L("Z:\\Mongolia"));
324 // test(r==KErrNotFound);
325 // r=library.GetCapability(theCaps,_L("C:\\Malawi.Fip"));
326 // test(r==KErrNotFound);
328 TCapabilitySet theCaps;
329 RLibrary::TInfoBuf info;
335 test.Next(_L("Get caps of an existing library"));
336 // r=lib1.GetCapability(theCaps,_L("ECONS"));
337 // test(r==KErrNone);
339 // r=lib1.GetInfo(_L("ECONS"), info);
340 r=lib1.GetInfo(_L("Z:\\SYS\\BIN\\ECONS"), info);
342 theCaps=info().iSecurityInfo.iCaps;
344 test.Next(_L("And again"));
345 // r=lib2.GetCapability(theCaps,_L("ECONS.DLL"));
346 // test(r==KErrNone);
348 lib2.GetInfo(_L("ECONS.DLL"), info);
349 theCaps=info().iSecurityInfo.iCaps;
352 // This test checks for the correct return value from the (deprecated)
353 // method GetCapability, and now serves no useful purpose??
354 // r=library.GetCapability(theCaps,_L("Malawi.Fip"));
355 // test(r==KErrNotSupported);
356 library.GetInfo(_L("Malawi.Fip"), info);
357 theCaps=info().iSecurityInfo.iCaps;
359 //TODO uncomment when in ssytem bin
361 // test.Next(_L("Get caps of an existing library"));
362 // r=lib1.GetCapability(theCaps,_L("ECONS"));
363 // r=lib1.GetCapability(theCaps,_L("Z:\\Sys\\Bin\\ECONS"));
364 // RDebug::Print(_L("r====%d"),r);
365 // test(r==KErrNone);
368 // test.Next(_L("And again"));
369 // r=lib2.GetCapability(theCaps,_L("Z:\\Sys\\Bin\\ECONS.DLL"));
370 // r=lib2.GetCapability(theCaps,_L("ECONS.DLL"));
371 // test(r==KErrNone);
374 test.Next(_L("And again, but searching"));
375 r=lib3.GetCapability(theCaps,_L("ECONS.DLL"));
376 test(r==KErrNotSupported);
381 test.Next(_L("Search through DLLs from t_ldrcheck"));
383 // Not sure of the benefit of this test ??
385 TBuf<40> dllfilenames;
387 // TCapability deecaps;
388 TCapabilitySet deecaps;
389 for(TInt i=0;i<13;i++)
391 dllfilenames=KDllfilename;
392 dllfilenames.AppendNum(i);
393 dllfilenames +=KDllExt;
394 // r=tlib.GetCapability(deecaps,dllfilenames);
395 tlib.GetInfo(dllfilenames, info);
396 theCaps=info().iSecurityInfo.iCaps;
399 test.Next(_L("Close()"));
407 TInt LoadExe(TInt aModuleNum, RProcess& aProcess)
414 // fn =KSystemLibs();
417 fn += MODULE_FILENAME(aModuleNum);
418 TInt r=aProcess.Create(fn, cmd);
423 void TestLoad(TInt aSequence)
425 // Test doing the loads using sequence number to get the results
428 test.Next(_L("Test all single EXE/DLL combinations\n"));
430 test.Next(_L("New EXE"));
434 test.Printf(_L("LoadExe(14)->%d, Expected %d, seq %d \n"),r,ModuleResultsA[aSequence], aSequence);
435 test(r==ModuleResultsA[aSequence]);
441 test.Printf(_L("LoadExe(15)->%d, seq %d\n"),r,aSequence);
442 test(r==ModuleResultsA[aSequence]);
449 void TestLoadLibrary()
451 // test using load library to load dlls with out rom time dependancies
454 test.Next(_L("Test loading libraries fromn this exe"));
458 //I want to load 6 7 and 11 as these are of most interest
460 for(TInt i=0;i<KTestCases;i++)
462 for(TInt mod=0 ; mod < 16 ; mod++) //each module
464 ModifyModuleCapabilties(ModuleCaps[mod][i],mod);
467 test.Printf(_L("mod11, iter=%d, ret=%d, exp=%d"),i,r,ModuleResultsB[i]);
468 test(r==ModuleResultsB[i]);
471 test.Printf(_L("mod6, iter=%d, ret=%d, exp=%d"),i,r,ModuleResultsB[i]);
472 test(r==ModuleResultsB[i]);
475 test.Printf(_L("mod7, iter=%d, ret=%d, exp=%d"),i,r,ModuleResultsC[i]);
476 test(r==ModuleResultsC[i]);
485 // test loading various dependancies
488 for(TInt tstcase=0; tstcase < KTestCases; tstcase++) //each test case
490 for(TInt mod=0 ; mod < 16 ; mod++) //each module
492 ModifyModuleCapabilties(ModuleCaps[mod][tstcase],mod);
500 _LIT(KSysHash,"?:\\Sys\\Hash\\");
501 const TInt KSlash='\\';
504 Creates a hash file in c:\\sys\\hash for a given file
506 @param aFileName full path to the file, which hash is to be created
508 void CreateFileHash(const TDesC& aFileName)
511 test.Printf(_L("Create Hash for the file %S\n"), &aFileName);
513 TInt readsize = 1024*2;//to go into header
514 HBufC8* block0 = HBufC8::NewL(readsize);
516 TPtr8 fileblock0(block0->Des());
517 CSHA1* hasher=CSHA1::NewL();
520 TInt r= fTarget.Open(TheFs, aFileName, EFileRead);
523 r=fTarget.Size(size);
526 if((size - offset) < readsize)
527 readsize = (size - offset);
528 r=fTarget.Read(offset, fileblock0, readsize);
530 hasher->Update(fileblock0);
533 while(offset < size);
535 r=fTarget.Read(fileblock0, (size - offset));
537 hasher->Update(fileblock0);
539 TBuf8<20> hash;//only outputs a 20 byte hash
540 hash = hasher->Final();
543 // const TUint8 * hptr=hash.Ptr();
544 // for(TInt i=0;i<20;i++)
546 // RDebug::Print(_L("install hash byte %d = 0x%x\n"),i,hptr[i]);
552 r=TheFs.Entry(aFileName,entry);
557 hashfile[0] = (TUint8) RFs::GetSystemDriveChar();
558 TInt slashpos = aFileName.LocateReverse(KSlash);
559 hashfile += aFileName.Mid(slashpos+1);
561 //-- create directory for dll hashes
562 r=TheFs.MkDirAll(hashfile);
563 test(r==KErrNone || r==KErrAlreadyExists);
565 //-- copy / replace given dll hash
566 r=fHash.Replace(TheFs, hashfile, EFileWrite);
572 test.Printf(_L("hash file size=%d\n"),size);
581 @param aFileName a full path to the file to corrupt
582 @return KErrNone on success
584 static TInt CorruptFile(const TDesC& aFileName)
586 test.Printf(_L("Corrupting file %S\n"), &aFileName);
589 CleanupClosePushL(corrFile);
591 TInt r=corrFile.Open(TheFs, aFileName, EFileWrite);
596 r=corrFile.Size(size);
601 r=corrFile.Read(size - 5, dat);
605 dat[0] = (TUint8) ~dat[0];
607 r=corrFile.Write(size - 5, dat);
611 CleanupStack::PopAndDestroy(1); //-- corrFile
618 void TestRemovableMediaWithHash()
620 // test loading from removable media and substed drives Both should fail
623 test.Next(_L("Testing Removable Media with hashing\n"));
625 CFileMan* fileMan=NULL;
626 TRAP(r,fileMan=CFileMan::NewL(TheFs));
629 TBuf<30> dllfilenames;
630 TBuf<30> dlldestination;
633 for(TInt i=0;i<14;i++)
635 dllfilenames=KNewDllName;
636 dllfilenames.AppendNum(i);
637 dllfilenames +=KDllExt;
639 dlldestination=KNewDllName;
640 dlldestination[0]=gDriveToTest;
641 dlldestination.AppendNum(i);
642 dlldestination+=KDllExt;
644 r=TheFs.MkDirAll(dlldestination);
645 test.Printf(_L("MkDirAll(%S) returned %d\n"), &dlldestination, r);
646 test(r==KErrNone || r==KErrAlreadyExists);
647 r=fileMan->Copy(dllfilenames,dlldestination, 0);
648 test(r==KErrNone || r==KErrAlreadyExists);
651 //take hash of binary
652 CreateFileHash(dlldestination);
655 r=lib.Load(dlldestination);
656 RDebug::Print(_L("t_ldrcheck: loading %S returned %d\n"),&dlldestination, r);
661 test.Printf(_L("Close lib on untouched load\n"));
664 r = CorruptFile(dlldestination);
666 test.Printf(_L("Binary %S now corrupted\n"), &dlldestination);
669 test.Printf(_L("loading %S\n"),&dlldestination);
670 r=lib.Load(dlldestination);
671 test.Printf(_L("load of %S returned %d\n"),&dlldestination,r);
672 test(r==KErrPermissionDenied);//as this process has Root caps and the dlls should be loaded with non
674 test.Printf(_L("Lib close 1\n"));
676 r=TheFs.Delete(dlldestination);
677 test.Printf(_L("Delete ret=%d\n"),r);
679 }//for(TInt i=0;i<14;i++)
682 TBuf<30> exefilenames;
683 TBuf<30> exedestination;
687 for(TInt j=14;j<16;j++)
689 exefilenames=KNewExeName;;
690 exefilenames.AppendNum(j);
691 exefilenames +=KExeExt;
693 exedestination=KNewExeName;
694 exedestination[0]=gDriveToTest;
695 exedestination.AppendNum(j);
696 exedestination+=KExeExt;
698 r=fileMan->Copy(exefilenames,exedestination,0);
699 test(r==KErrNone || r==KErrAlreadyExists);
701 CreateFileHash(exedestination);
703 r=p.Create(exedestination, cmd);
708 r = CorruptFile(exedestination);
711 test.Printf(_L("Binary %S now corrupted\n"), &exedestination);
713 r=p.Create(exedestination, cmd);
714 test(r==KErrPermissionDenied);
715 // p.Terminate(0); DON'T DO THIS SINCE CREATION FAILED - HANDLE NOT OPENED
718 r=TheFs.Delete(exedestination);
726 void TestRemovableMedia()
728 // test loading from removable media and substed drives Both should fail
731 test.Next(_L("Testing Removeable Media"));
733 CFileMan* fileMan=NULL;
734 TRAP(r,fileMan=CFileMan::NewL(TheFs));
737 TBuf<30> dllfilenames;
738 TBuf<30> dlldestination;
740 for(TInt i=0;i<14;i++)
742 dllfilenames=KNewDllName;
743 dllfilenames.AppendNum(i);
744 dllfilenames +=KDllExt;
746 dlldestination=KNewDllName;
747 dlldestination[0]='D';
748 dlldestination.AppendNum(i);
749 dlldestination+=KDllExt;
751 r=TheFs.MkDirAll(dlldestination);
752 test(r==KErrNone || r==KErrAlreadyExists);
754 r=fileMan->Copy(dllfilenames,dlldestination, 0);
755 test(r==KErrNone || r==KErrAlreadyExists);
757 r=lib.Load(dlldestination);
758 test.Printf(_L("load %S ret=%d"),&dlldestination,r);
759 RDebug::Print(_L("r=%d"),r);
760 test(r==KErrPermissionDenied);//as this process has Root caps and the dlls should be loaded with non
764 TBuf<30> exefilenames;
765 TBuf<30> exedestination;
769 for(TInt j=14;j<16;j++)
771 exefilenames=KNewExeName;;
772 exefilenames.AppendNum(j);
773 exefilenames +=KExeExt;
775 exedestination=KNewExeName;
776 exedestination[0]='D';
777 exedestination.AppendNum(j);
778 exedestination+=KExeExt;
780 r=fileMan->Copy(exefilenames,exedestination,0);
781 test(r==KErrNone || r==KErrAlreadyExists);
783 r=p.Create(exedestination, cmd);
784 test(r==KErrPermissionDenied);
791 void TestNonSystemSubsted()
793 // Test an internal drive on non system dir
796 test.Next(_L("Testing Non System and Subst"));
798 CFileMan* fileMan=NULL;
799 TRAP(r,fileMan=CFileMan::NewL(TheFs));
802 TBuf<50> dllfilenames;
803 TBuf<50> dlldestination;
806 for(TInt i=0;i<14;i++)
808 dllfilenames=KNewDllName;
809 dllfilenames.AppendNum(i);
810 dllfilenames +=KDllExt;
812 dlldestination=KAnyDirDll;
813 dlldestination+=_L("_X");
814 dlldestination.AppendNum(i);
815 dlldestination+=KDllExt;
819 r=TheFs.MkDirAll(dlldestination);
820 test(r==KErrNone || r==KErrAlreadyExists);
821 r=TheFs.SetSubst(KAnyDirShort(), EDriveN); //set up n as the substed drive
825 RDebug::Print(_L("copying from %S to %S"),&dllfilenames,&dlldestination);
826 r=fileMan->Copy(dllfilenames,dlldestination, 0);
827 test(r==KErrNone || r==KErrAlreadyExists);
830 // Test that loading from fully qualified path fails
831 // (ie - C:\Anyoldname\sys\bin\DLLTS_X0.DLL)
833 r=lib.Load(dlldestination);
834 RDebug::Print(_L("RLibrary::Load(%S) : r=%d"), &dlldestination, r);
835 test(r==KErrNotFound);
838 // Test that loading from substituted drive fails
839 // (ie - N:\sys\bin\DLLTS_X0.DLL, where N:\ == C:\Anyoldname\)
843 substed.AppendNum(i);
847 RDebug::Print(_L("RLibrary::Load(%S) : r=%d"), &substed, r);
848 test(r==KErrNotFound);
851 // Test that loader search does not find substituted drives when
852 // loading library with no drive or path specified.
854 substed=KJDllNameOnly;
856 substed.AppendNum(i);
860 RDebug::Print(_L("RLibrary::Load(%S) : r=%d"), &substed, r);
861 test(r==KErrNotFound);
864 TBuf<50> exefilenames;
865 TBuf<50> exedestination;
869 for(TInt j=14;j<16;j++)
871 exefilenames=KNewExeName;;
872 exefilenames.AppendNum(j);
873 exefilenames +=KExeExt;
875 exedestination=KAnyDirExe;
876 exedestination+=_L("_X");
877 exedestination.AppendNum(j);
878 exedestination+=KExeExt;
880 RDebug::Print(_L("copying from %S to %S"),&exefilenames,&exedestination);
881 r=fileMan->Copy(exefilenames,exedestination,0);
882 test(r==KErrNone || r==KErrAlreadyExists);
885 // Test that loading from fully qualified path fails
886 // (ie - C:\Anyoldname\sys\bin\EXETS_X14.EXE)
888 r=p.Create(exedestination, cmd);
889 RDebug::Print(_L("RProcess::Create(%S) : r=%d"), &exedestination, r);
890 test(r==KErrNotFound);
893 // Test that loading from substituted drive fails
894 // (ie - N:\sys\bin\EXETS_X14.EXE, where N:\ == C:\Anyoldname\)
898 substed.AppendNum(j);
901 r=p.Create(substed, cmd);
902 RDebug::Print(_L("RProcess::Create(%S) : r=%d"), &substed, r);
903 test(r==KErrNotFound);
906 // Test that loader search does not find substituted drives when
907 // loading process with no drive or path specified.
909 substed=KJExeNameOnly;
911 substed.AppendNum(j);
914 r=p.Create(substed, cmd);
915 RDebug::Print(_L("RProcess::Create(%S) : r=%d"), &substed, r);
916 test(r==KErrNotFound);
920 // Clear the substituted drive
921 r=TheFs.SetSubst(KNullDesC, EDriveN);
926 void TestSystemBinSubsted()
928 // Test an internal drive on system dir
931 test.Next(_L("Testing System bin -> Subst"));
933 CFileMan* fileMan=NULL;
934 TRAP(r,fileMan=CFileMan::NewL(TheFs));
937 TBuf<50> dllfilenames;
940 r=TheFs.SetSubst(KSystemLibs, 14); //set up O as the substed drive
942 for(TInt i=0;i<14;i++)
944 RDebug::Print(_L("doing modify caps = %d"),i);
945 ModifyModuleCapabilties(KCapabilityRoot,i);
946 dllfilenames=KNewDllName;
947 dllfilenames.AppendNum(i);
948 dllfilenames +=KDllExt;
950 RDebug::Print(_L("Module = %S"),&dllfilenames);
951 r=lib.Load(dllfilenames);
952 test(r==KErrNone);//as this process has Root caps and the dlls should be loaded with non
953 substed=_L("O:\\DLLTS");
954 substed.AppendNum(i);
961 TBuf<50> exefilenames;
965 for(TInt j=14;j<16;j++)
967 exefilenames=KNewExeName;
968 exefilenames.AppendNum(j);
969 exefilenames +=KExeExt;
970 ModifyModuleCapabilties(KCapabilityRoot,j);
971 r=p.Create(exefilenames, cmd);
977 substed=_L("O:\\EXETS");
978 substed.AppendNum(j);
980 RDebug::Print(_L("substed=%S"),&substed);
981 r=p.Create(substed, cmd);
995 // time how long to load a small dll 100 times and one large one
998 test.Next(_L("Next Do Bench Mark\n"));
999 TBuf<30> dlldestination;
1000 dlldestination=KNewDllName;
1001 dlldestination[0]='D';
1002 dlldestination.AppendNum(1);
1003 dlldestination+=KDllExt;
1006 TUint32 startcount = User::NTickCount();
1007 for (TInt i=0;i<100;i++)
1009 r=lib.Load(dlldestination);
1012 TUint32 endcount = User::NTickCount();
1014 RDebug::Print(_L("100 * 4k dll \n"));
1015 RDebug::Print(_L("start count=%d, end count=%d, dif=%d\n"),startcount,endcount,endcount-startcount);
1017 startcount = User::NTickCount();
1018 r=lib.Load(_L("D:\\sys\\bin\\euser.dll"));
1020 endcount = User::NTickCount();
1021 RDebug::Print(_L("r=%d"));
1022 // test(r==KErrNone);
1023 RDebug::Print(_L("1 * 233k dll \n"));
1024 RDebug::Print(_L("start count=%d, end count=%d, dif=%d\n"),startcount,endcount,endcount-startcount);
1027 //-------------------------------------------------------
1030 testing RLoader::CheckLibraryHash() API
1032 void TestCheckLibraryHash()
1034 test.Next(_L("Testing CheckLibraryHash API\n"));
1037 CFileMan* pFileMan=NULL;
1038 TRAP(r,pFileMan=CFileMan::NewL(TheFs));
1045 //-- 1. copy test DLL to the specified drive and create hash file for it.
1046 TBuf<40> dllFileName;
1047 TBuf<40> dllDestination;
1049 const TInt KDllNumber = 0;
1051 dllFileName=KDllfilename;
1052 dllFileName.AppendNum(KDllNumber);
1053 dllFileName+=KDllExt;
1055 dllDestination=KNewDllName;
1056 dllDestination[0]=(TUint16)gDriveToTest;
1057 dllDestination.AppendNum(KDllNumber);
1058 dllDestination+=KDllExt;
1060 test.Printf(_L("Copy %S to %S\n"), &dllFileName, &dllDestination);
1062 r=TheFs.MkDirAll(dllDestination);
1063 test(r==KErrNone || r==KErrAlreadyExists);
1065 r=pFileMan->Copy(dllFileName, dllDestination);
1066 test(r==KErrNone || r==KErrAlreadyExists);
1068 r=pFileMan->Attribs(dllDestination, 0, KEntryAttReadOnly, TTime(0) ,0);
1071 test.Printf(_L("Creating Dll hash.\n"));
1072 CreateFileHash(dllDestination);
1074 //-- 2. check if the hash exists
1075 r=loader.CheckLibraryHash(dllDestination);
1077 test.Printf(_L("Dll hash exists.\n"));
1079 //-- 2.1 check if the hash exists and valid
1080 r=loader.CheckLibraryHash(dllDestination, ETrue);
1083 test.Printf(_L("Dll hash exists and valid.\n"));
1086 r = CorruptFile(dllDestination);
1089 //-- 3.1 check that the hash exists, but is incorrect.
1090 r=loader.CheckLibraryHash(dllDestination);
1092 test.Printf(_L("Dll hash exists.\n"));
1094 r=loader.CheckLibraryHash(dllDestination, ETrue);
1095 test(r==KErrCorrupt);
1097 test.Printf(_L("Dll hash exists and INVALID.\n"));
1099 //-- 4. try to locte hash fo the unexisting dll.
1100 r=loader.CheckLibraryHash(_L("Z:\\sys\\bin\\NotExist.dll"));
1101 test(r==KErrNotFound);
1108 //-------------------------------------------------------
1110 void ParseCommandArguments()
1116 User::CommandLine(cmd);
1118 TPtrC token=lex.NextToken();
1119 TFileName thisfile=RProcess().FileName();
1120 if (token.MatchF(thisfile)==0)
1122 token.Set(lex.NextToken());
1124 test.Printf(_L("CLP=%S"),&token);
1126 if(token.Length()!=0)
1128 gDriveToTest=token[0];
1129 gDriveToTest.UpperCase();
1132 gDriveToTest='D'; //default to D:
1136 //-------------------------------------------------------
1140 test.Next(_L("Testing Exes presence.\n"));
1157 //-------------------------------------------------------
1159 static void CallTestsL(void)
1163 test.Printf(_L("Not testing on WINS !\n"));
1168 // TestGetCapability();
1169 CopyModules(); //copies modules from ROM to disk so they may be modified
1171 // TestLoadLibrary();
1175 if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
1176 TestRemovableMediaWithHash();
1178 // TestSystemBinSubsted();
1179 // TestRemovableMedia();
1180 TestNonSystemSubsted();
1184 TestCheckLibraryHash();
1186 #endif //#ifndef __WINS__
1190 //-------------------------------------------------------
1194 GLDEF_C TInt E32Main()
1196 ParseCommandArguments(); //need this for drive letter to test
1199 test.Start(_L("Setup\n"));
1200 CTrapCleanup* cleanup;
1201 cleanup=CTrapCleanup::New();
1208 r=TheFs.SessionPath(sessPath);
1212 RFs::CharToDrive(gDriveToTest, drive);
1214 r=TheFs.Drive(info, drive);
1217 if((info.iDriveAtt & KDriveAttRemovable) == 0)
1219 test.Printf(_L("Not testing on non-removable media !\n"));
1222 {//-- testing on removable media
1223 TRAP(r,CallTestsL());