EXPORT_C TInt RAknKeylock2::Connect()
	{
	TInt ret = KErrNotReady;
	CCoeEnv* coe = CCoeEnv::Static();
	if (!coe)
		{
		return KErrNotSupported; // we need that window group list
		}
    TApaTaskList list(CCoeEnv::Static()->WsSession());
    TApaTask task = list.FindApp(KAknCapServerUid);
    if (task.Exists() )
        {
        if ( Handle() == NULL)
            {
            _LIT(KServerNameFormat, "%08x_%08x_AppServer");
	        TFullName serverName;
	        TUid serviceUid = KAknNotifierServiceUid;
	        serverName.Format(KServerNameFormat, KUikonUidPluginInterfaceNotifiers, KAknCapServerUid);
			ret = CreateSession(serverName,*reinterpret_cast<TVersion*>(&serviceUid));           
            }
        else 
        	{
        	ret = KErrNone; // or should this be KErrAlreadyExist		
        	}
        }
	return ret;
	}
Beispiel #2
0
TInt CCpuMeter::Construct()
{
    iNumCpus = NumberOfCpus();
    iNullThreads = (RThread*)User::AllocZ(iNumCpus*sizeof(RThread));
    iDelta = (TInt*)User::AllocZ(iNumCpus*sizeof(TInt));
    iMeas[0] = (TTimeIntervalMicroSeconds*)User::AllocZ(iNumCpus*sizeof(TTimeIntervalMicroSeconds));
    iMeas[1] = (TTimeIntervalMicroSeconds*)User::AllocZ(iNumCpus*sizeof(TTimeIntervalMicroSeconds));
    if (!iNullThreads || !iDelta || !iMeas[0] || !iMeas[1])
        return KErrNoMemory;
    TFullName kname;
    _LIT(KLitKernelName, "ekern.exe*");
    _LIT(KLitNull, "::Null");
    TFindProcess fp(KLitKernelName);
    test_KErrNone(fp.Next(kname));
    test.Printf(_L("Found kernel process: %S\n"), &kname);
    kname.Append(KLitNull);
    TInt i;
    for (i=0; i<iNumCpus; ++i)
    {
        TFullName tname(kname);
        TFullName tname2;
        if (i>0)
            tname.AppendNum(i);
        TFindThread ft(tname);
        test_KErrNone(ft.Next(tname2));
        TInt r = iNullThreads[i].Open(ft);
        test_KErrNone(r);
        iNullThreads[i].FullName(tname2);
        test.Printf(_L("Found and opened %S\n"), &tname2);
    }
    for (i=0; i<iNumCpus; ++i)
        iNullThreads[i].GetCpuTime(iMeas[0][i]);
    iNextMeas = 1;
    return KErrNone;
}
/**
 * To start silent preinstallations.
 */
void CSilentMIDletInstall::Start()
{
    iState = EFindOutDeviceDrives;

    // Check if an explicit roll-back of a previous installation is needed
    // in the case there is nothing to pre-install (if there is something
    // to pre-install, the potential roll-back is done automatically)
    TUint attrs;
    TInt err = iFs.Att(KISJournalFile, attrs);
    LOG1(EJavaPreinstaller, EInfo,
         "Checking IS journal file \\private\\102033E6\\installer\\is\\isjournal.dat, status %d", err);
    if ((KErrNotFound == err) || (KErrPathNotFound == err))
    {
        iISRollbackNeeded = EFalse;
    }
    else
    {
        iISRollbackNeeded = ETrue;
        // If JavaInstaller is running, then existence of the Java Installer
        // integrity service directory is ok and rollback is not needed.
        TFullName processName;
        _LIT(KJavaInstallerProcess, "Installer*");
        TFindProcess finder(KJavaInstallerProcess);
        err = finder.Next(processName);
        if (err == KErrNone)
        {
            iISRollbackNeeded = EFalse;
            WLOG1(EJavaPreinstaller,
                  "Java Installer is running while checking need to rollback (%S)",
                  (wchar_t *)(processName.PtrZ()));
        }
    }

    CompleteRequest();
}
//This function is used in the test code to kill ECOMSERVER
//processes (or some other) when they leftover and may problem in ECOMSERVERTEST
static TInt KillProcess(const TDesC& aProcessName)
	{
	TFullName name;

	RDebug::Print(_L("Find and kill \"%S\" process.\n"), &aProcessName);

	TBuf<64> pattern(aProcessName);
	TInt length = pattern.Length();
	pattern += _L("*");
	TFindProcess procFinder(pattern);

	while(procFinder.Next(name) == KErrNone)
		{
		if(name.Length() > length) 
			{
			//If found name is a string containing aProcessName string.
			TChar c(name[length]);
			if(c.IsAlphaDigit() || c == TChar('_') || c == TChar('-'))
				{
				//If the found name is other valid application name starting with aProcessName string.
				RDebug::Print(_L(":: Process name: \"%S\".\n"), &name);
				continue;
				}
			}
		RProcess proc;
		if(proc.Open(name) == KErrNone)
			{
			proc.Kill(0);
			RDebug::Print(_L("\"%S\" process killed.\n"), &name);
			}
		proc.Close();
		}
	return KErrNone;
	}
Beispiel #5
0
void CWsTop::NewSession(const CWsClient *aClient)
	{	
	if (iShellClient==NULL && iShell)
		{
#if defined(__WINS__)
		RThread proc;
		proc=aClient->Client();
#else
		RProcess proc;
		aClient->Client().Process(proc);
#endif
		TFullName procName = proc.FullName();
		// Before comparing the proc name with iShell name , truncate the proc name up to the actual name
		// referring to the process, by removing the part which starts with ':', if exists.
		TInt colonLocation = procName.Locate(':');
		if( KErrNotFound != colonLocation)
			{
			procName = procName.Left(colonLocation);
			}
		if (procName ==iShell->FullName())
			{
			iShellClient=aClient;
			if (!iPreviousShellClient)
				{
				iPreviousShellClient=ETrue;
				aClient->Screen()->RootWindow()->SetColorIfClear();
				}
			}
#if !defined(__WINS__)
		proc.Close();
#endif
		}	
	}
// -----------------------------------------------------------------------------
// CHtiFramework::IsHtiRunning
// Checks whether HTI Framework process is already running.
// -----------------------------------------------------------------------------
TBool CHtiFramework::IsHtiRunning()
    {
    HTI_LOG_FUNC_IN( "CHtiFramework::IsHtiRunning" );
    TInt htiInstanceCount = 0;
    TBool isRunning = EFalse;
    TFullName processName;
    TFindProcess finder( KHtiFrameworkMatchPattern );
    TInt err = finder.Next( processName );
    while ( err == KErrNone && processName.Length() > 0 )
        {
        HTI_LOG_FORMAT( "Found process %S", &processName );
        RProcess process;
        err = process.Open( finder );
        if ( err == KErrNone )
            {
            if ( process.ExitType() == EExitPending )
                {
                HTI_LOG_TEXT( "Process is running" );
                htiInstanceCount++;
                }
            process.Close();
            }
        err = finder.Next( processName );
        }
    if ( htiInstanceCount > 1 )
        {
        isRunning = ETrue;
        }
    HTI_LOG_FUNC_OUT( "CHtiFramework::IsHtiRunning" );
    return isRunning;
    }
Beispiel #7
0
LOCAL_C void ProfileAllThreads()
	{
	TFindThread ft(_L("*"));
	TFullName fullname;
	test.Console()->ClearScreen();
	FOREVER
		{
		TInt r=ft.Next(fullname);
		if (r!=KErrNone)
			break;
		RThread t;
		r=t.Open(ft);
		if (r==KErrNone)
			{
			TProfileData data;
			r=Profile.Read(t,data);
			if (r==KErrNone)
				{
				while(fullname.Length()<40)
					fullname.Append(TChar(' '));
				test.Printf(_L("%S T=%9d C=%9d Y=%9d\n"),
					&fullname,data.iTotalCpuTime,data.iMaxContinuousCpuTime,data.iMaxTimeBeforeYield);
				}
			t.Close();
			}
		}
	}
TBool IsAlreadyRunning()
{
	RDebug::Print(_L("TrkLauncher::IsAlreadyRunning()"));

	_LIT(KTrkConsoleSearchPattern, "*TRKPROCESS*");
	_LIT(KTrkConsoleProcessPattern, "*");
	
	TFindProcess finder;
	TFullName fullName;
	TBool found = EFalse;
	finder.Find(KTrkConsoleProcessPattern);

	while (!found && finder.Next(fullName) == KErrNone)
	{
		fullName.UpperCase();
		
		if (fullName.Match(KTrkConsoleSearchPattern) != KErrNotFound)
		{
			found = ETrue;
			RDebug::Print(_L("process found Inside while"));
			break;
		}
	}

	if (found)
	{
		RDebug::Print(_L("TrkLauncher - Process found outside while"));
	}
	else
	{
		RDebug::Print(_L("TrkLauncher - Process was never found"));
	}
		
	return found;
}
void CSuspendTest::CreateL()
	{
	//
	// Create the eraser thread
	//
	iEraser = new(ELeave) CEraser;
	iEraser->CreateL();

	//
	// Load the device drivers
	//
	TInt r;
#ifndef SKIP_PDD_LOAD
	test.Printf( _L("Loading %S\n"), &KLfsDriverName );
	r = User::LoadPhysicalDevice( KLfsDriverName );
	test( KErrNone == r || KErrAlreadyExists == r );
#endif

#ifdef UNMOUNT_DRIVE
	RFs fs;
	test( KErrNone == fs.Connect() );
	test( KErrNone == fs.SetSessionPath( _L("Z:\\") ) );
	TFullName name;
	fs.FileSystemName( name, KLffsLogicalDriveNumber );
	if( name.Length() > 0 )
		{
		test.Printf( _L("Unmounting drive") );
		test( KErrNone == fs.DismountFileSystem( _L("Lffs"), KLffsLogicalDriveNumber) );
		User::After( 2000000 );
		test.Printf( _L("Drive unmounted") );
		}
	fs.Close();
#endif

	//
	// Open a TBusLogicalDevice to it
	//
	test.Printf( _L("Opening media channel\n") );
	TBool changedFlag = EFalse;
	r = iDrive.Connect( KDriveNumber, changedFlag );
	User::LeaveIfError( r );
	iDriveOpened = ETrue;

	//
	// Get size of Flash drive, block size, block count
	//
	TLocalDriveCapsV2Buf info;
    iDrive.Caps(info);
	iFlashSize = I64LOW(info().iSize);
	iBlockSize = info().iEraseBlockSize;
	iBlockCount = iFlashSize / iBlockSize;

	test.Printf( _L("Flash size is 0x%x bytes\n"), iFlashSize );
	test.Printf( _L("Block size is 0x%x bytes\n"), iBlockSize );
	test.Printf( _L("Block count is %d\n"), iBlockCount );

	test.Printf( _L("CreateL complete\n") );
	}
Beispiel #10
0
/**
 * Writes the required process details to the stop mode response buffer in the form of a 
 * TProcessListEntry structure
 * @param aProc Process to write
 * @param aBuffer Buffer to write to
 * @param aBufferEnd Where the buffer ends
 * @return TInt KErrTooBig if there is no more space in buffer or one of the other system wide error codes
 */
TInt StopModeDebug::AppendProcessToBuffer(DProcess* aProc, TUint8* aBuffer, TUint8* aBufferEnd, TUint32& aProcSize)
	{
	TFullName procName;
	GetObjectFullName(aProc, procName);
	TUint32	dynamicNameLength = procName.Length();

	DCodeSeg* codeSeg = aProc->iCodeSeg;
	TUint16 fileNameLength = (codeSeg) ? (*codeSeg->iFileName).Length() : 0;

	//Struct size is unicode so the filenames are twice as long, plus the size of the struct minus one character that 
	//lives inside the struct itself. Also, this is word aligned
	TUint32 structSize = Align4( (2*fileNameLength) + (2*dynamicNameLength) + sizeof(TProcessListEntry) - sizeof(TUint16));
	aProcSize = structSize;

	//Is there space to write this to the buffer
	if(aBuffer + structSize < aBufferEnd)
		{
		TProcessListEntry& entry = *(TProcessListEntry*)(aBuffer);

		entry.iProcessId = (TUint64)aProc->iId;
		entry.iFileNameLength = fileNameLength;
		entry.iDynamicNameLength = dynamicNameLength;
		entry.iUid3 = aProc->iUids.iUid[2].iUid;
		entry.iAttributes = aProc->iAttributes;

		//Write the filename
		if(codeSeg)
			{
			//create TPtr to where the file name should be written
			TPtr name = TPtr((TUint8*)&(entry.iNames[0]), fileNameLength*2, fileNameLength*2);

			//copy the file name
			TInt err = CopyAndExpandDes(*codeSeg->iFileName, name);
			if(KErrNone != err)
				{
				return KErrGeneral;
				}
			}

		//create TPtr to where the dynamic name should be written
		TPtr name = TPtr((TUint8*)(&(entry.iNames[0]) + fileNameLength), dynamicNameLength*2, dynamicNameLength*2);

		//copy the dynamic name
		TInt err = CopyAndExpandDes(procName, name);
		if(KErrNone != err)
			{
			return KErrGeneral;
			}	

		return KErrNone;
		}
	else
		{
		return KErrTooBig;
		}
	}
Beispiel #11
0
TBool IsProcessRunning(const TDesC& aProcessName)
	{
	TFullName name;
	TBool IsProcessRunning(EFalse);
	TBuf<64> pattern(aProcessName);
	TInt length = pattern.Length();
	pattern += _L("*");
	TFindProcess procFinder(pattern);

	while(procFinder.Next(name) == KErrNone)
		{
		if(name.Length() > length)
			{//If found name is a string containing aProcessName string.
			TChar c(name[length]);
			if(c.IsAlphaDigit() || c == TChar('_') || c == TChar('-'))
				{//If the found name is other valid application name starting with aProcessName string.
				RDebug::Print(_L(":: Process name: \"%S\".\n"), &name);
				continue;
				}
			}
		RProcess proc;
		if(proc.Open(name) == KErrNone)
			{
			if (EExitKill == proc.ExitType())
			    {
			    RDebug::Print(_L("\"%S\" process killed.\n"), &name);
			    proc.Close();
			    IsProcessRunning = EFalse;
			    }
			 else
			    {
			    IsProcessRunning = ETrue;
			    RDebug::Print(_L("\"%S\" process is running.\n"), &name);
			    }

			if(IsProcessRunning)
				{
				RDebug::Print(_L("Waiting additional time...\n"), &name);

				User::After(1000000);

				if (EExitKill == proc.ExitType())
					{
					RDebug::Print(_L("\"%S\" process now killed.\n"), &name);
			    	IsProcessRunning = EFalse;
					}

				proc.Close();
				}
			}


		}
	return IsProcessRunning;
	}
//-----------------------------------------------------------------------------
// RDynNotifier::Connect
//-----------------------------------------------------------------------------
//   
TInt RDynNotifier::Connect()
    {
    TInt ret = KErrNone;
    if ( Handle() == NULL)
        {
        _LIT(KServerNameFormat, "%08x_%08x_AppServer");
        TFullName serverName;
        TUid serviceUid = KAknNotifierServiceUid;
        serverName.Format(KServerNameFormat, KUikonUidPluginInterfaceNotifiers, KAknCapServerUid);
        ret = CreateSession(serverName,*reinterpret_cast<TVersion*>(&serviceUid));           
        }
  return ret;
  }   
Beispiel #13
0
/**
 * Reads the raw name for this object instead of using API in DObject,
 * as we can't meet the preconditions
 * @param DObject object whose name we want
 */
void StopModeDebug::GetObjectFullName(const DObject* aObj, TFullName& aName)
	{
	if(aObj->iOwner)
		{
		GetObjectFullName(aObj->iOwner, aName);
		aName.Append(KColonColon);
		}
	
    if (aObj->iName)
		{
        aName.Append(*aObj->iName);
		}
     else
        {
        aName.Append(KLitLocal);
        aName.AppendNumFixedWidth((TInt)aObj,EHex,8);
        }
	}
Beispiel #14
0
wchar_t * PosixFilesystem::getcwd (RFs& aFs, wchar_t* buf, unsigned long len, int& anErrno)
{
    TFullName name;
    TInt err = aFs.SessionPath(name);
    if (!err)
    {
        TPtr16 pathdes((TText16 *)buf, len);
        if (pathdes.MaxLength() >= (name.Length() + 1))	//+1 to allow for the null terminator
        {
            pathdes.Copy(name);
            pathdes.ZeroTerminate();
            return buf;
        }
        else
            err = ERANGE;		//out of range
    }
    MapError(err, anErrno);
    return 0;
}
Beispiel #15
0
TInt MountNTFS()
	{
	TBuf<256> cmd;
	User::CommandLine(cmd);
	TLex cmdlex(cmd);
	cmdlex.SkipSpace();
	TUint c = (TUint)cmdlex.Get();
	if (c>='a' && c<='z')
		c-=0x20;
	if (c<'A' || c>'Z')
		return KErrArgument;
	TBuf<4> driveLetter;
	driveLetter.SetLength(1);
	driveLetter[0] = (TText)c;
    RDebug::Print(_L("Drive %S"), &driveLetter);
    
    TInt driveNumber = TInt(c-'A') + TInt(EDriveA);
	TInt r;
	driveLetter.Append(_L(":\\"));
    
    RDebug::Print(_L("Add file system: %S"), &KFileSystemDllName);
    r=TheFs.AddFileSystem(KFileSystemDllName);
    if (r!=KErrNone && r!=KErrAlreadyExists)
		{
		RDebug::Print(_L("Failed: %d"), r);
		return r;
		}

	TFullName name;
	r = TheFs.FileSystemName(name, driveNumber);
	if (name.Length() != 0)
		{
        RDebug::Print(_L("Dismounting %S on drive %S\r\n"), &name, &driveLetter);
        r=TheFs.DismountFileSystem(name, driveNumber);
		RDebug::Print(_L("Dismount ret=%d"), r);
    	}

    RDebug::Print(_L("Mount NTFS on drive %S\r\n"), &driveLetter);
    r = TheFs.MountFileSystem(KFileSystemName, driveNumber);
	RDebug::Print(_L("Mount r=%d"),r);
	return KErrNone;
	}
// -----------------------------------------------------------------------------
// CDevEncStarterMmcObserver::CheckMMC
// 
// -----------------------------------------------------------------------------
TInt CDevEncStarterMmcObserver::CheckMMC()
    {
    // Check if MMC mounted, mount if required
    TFullName fsname;

    // If can't use the drive, returns KErrNotFound
    TInt err = iFs.FileSystemName( fsname, mmcDrive );

    if ( !err )
        {
        // MMC found. Checking if it is mounted
        if ( fsname.Length( ) == 0 )
            {
            // MMC not mounted ( file system name is empty ) 
            DFLOG( "Mmc not mounted" );
            err = KErrDisMounted;
            }
        }
    return err;
    }
Beispiel #17
0
/**
 * Opens a handle to the null thread.
 */
static TBool FindNullThread( RThread& aThread )
    {
    TFindProcess fp( KNullThreadProcessName );
    TFullName kernelName;
    if ( fp.Next( kernelName ) == KErrNone )
        {
        kernelName.Append( KNullThreadName );
        
        TFindThread ft( kernelName );
        TFullName threadName;
        if ( ft.Next( threadName ) == KErrNone )
            {
            if ( aThread.Open( threadName ) != KErrNone )
                {
                return EFalse;
                }
            }
        }        

    return ( aThread.Handle() != 0 );
    }
// ==============================================================
// ============ DoKillProcessL()                    =============
// ==============================================================
void DoKillProcessL( const TDesC& aProcessName )
    {
    TFullName psName;
    psName.Append( _L("*") );
    psName.Append( aProcessName );
    psName.Append( _L("*") );

    TFindProcess psFinder;
    psFinder.Find( psName );

    TInt killCount( 0 );
    while( psFinder.Next( psName ) != KErrNotFound )
        {
        RProcess ps;
        User::LeaveIfError( ps.Open( psFinder ) );
        ps.Kill( -666 );
        ps.Close();
        killCount++;
        }

    User::Leave( killCount );
    }
void CLogAlarmImpl::GetAlarm()
{
#ifndef __WINS__
	CALLSTACKITEM_N(_CL("CLogAlarmImpl"), _CL("GetAlarm"));
	TAlarmInfo info;
	TAlarmSetState state;

	TInt i, err=-1;
	auto_ptr<CAlarmIdArray> ids(new (ELeave) CAlarmIdArray(8));
	iAlarmServer.AlarmArrayPopulateL(*ids.get(), RAlarmServer::EArrayNext, 8);
	iValue()=TTime(0);
	for (i=0; i<ids->Count(); i++) {
		err=iAlarmServer.AlarmInfo(info, RAlarmServer::EInfoClock, ids->At(i));
		TFullName owner;
		if (err==KErrNone) {
			iAlarmServer.AlarmOwner(owner, ids->At(i));
		}
		if (err==KErrNone ) {
			state=iAlarmServer.AlarmState(info.iAlarmId);
			if (state!=EAlarmNotSet && state!=EAlarmDisabled && info.iType==EAlarmTypeClock &&
					owner.FindF(_L("Agenda"))==KErrNotFound)
				break;
		}
		if (err!=KErrNotFound) {
			User::LeaveIfError(err);
		}
		err=KErrNotFound;
	}
	if (err==KErrNone) {
		/* AlarmTime is when the alarm will next go off,
		 * e.g., after a snooze
		 */
		iValue()=info.iAlarmTime;
	}
#endif
}
static TInt KillProcess(const TDesC& aProcessName)
	{
	TFullName name;
	//TheTest.Printf(_L("Find and kill \"%S\" process.\n"), &aProcessName);
	TBuf<64> pattern(aProcessName);
	TInt length = pattern.Length();
	pattern += _L("*");
	TFindProcess procFinder(pattern);

	while (procFinder.Next(name) == KErrNone)
		{
		if (name.Length() > length)
			{//If found name is a string containing aProcessName string.
			TChar c(name[length]);
			if (c.IsAlphaDigit() ||
				c == TChar('_') ||
				c == TChar('-'))
				{
				// If the found name is other valid application name
				// starting with aProcessName string.
				//TheTest.Printf(_L(":: Process name: \"%S\".\n"), &name);
				continue;
				}
			}
		RProcess proc;
		if (proc.Open(name) == KErrNone)
			{
			//RPorcess::Kill() is expected to be used here.
			//But it is impossible, because the test application will need "PowerMgmt" capability.
			//But if the test application has "PowerMgmt" capability, then it won't be possible to use the 
			//sqlite3_secure library, which has "ProtServ" capability only.
			}
		proc.Close();
		}
	return KErrNone;
	}
Beispiel #21
0
int PosixFilesystem::stat (RFs& aFs, const wchar_t* name, struct stat *st, int& anErrno)
{
    TFullName fullName;
    TInt err=GetFullFile(fullName,(const TText16*)name,aFs);
    if (!err)
    {
        TEntry entry;
        if (fullName.Length()==3)
        {
            entry.iAtt=KEntryAttDir;
            entry.iModified==TTime(0);
        }
        else
            err=aFs.Entry(fullName,entry);
        if (!err)
        {
            st->st_size = entry.iSize;
            st->st_dev = st->st_rdev = (dev_t)TDriveUnit(fullName);
            CFileDesc::MapStat(*st, entry.iModified, entry.iAtt);
            return 0;
        }
    }
    return MapError(err, anErrno);
}
Beispiel #22
0
void CBtraceReader::DecodeFrame(const TBtraceHeader& aHeader, const TDesC8& aFrame, TUint32)
{
    if (aHeader.iCategory == BTrace::EKernPrintf)
    {
        TUint32 threadId = *(TUint32*)aFrame.Ptr();
        TBuf<256> text;
        text.Copy(aFrame.Mid(4));
        if (iDebugConsole)
        {
            iDebugConsole->Printf(_L("Kern::Printf (0x%08x) \'%S\'\r\n"), &threadId, &text);
        }
    }
    else if (aHeader.iCategory == RMemSampler::EBtraceCategory)
    {
        switch (aHeader.iSubCategory)
        {
        case RMemSampler::ENewChunk:
        {
            TUint32 address = *(TUint32*)aFrame.Ptr();
            TInt maxSize = *((TUint32*)aFrame.Ptr() + 1);
            TFullName fullName;
            fullName.Copy(aFrame.Mid(8));
            if (iDebugConsole)
            {
                iDebugConsole->Printf(_L("New chunk - %S\r\n\taddress: 0x%08x max size: %d\r\n"), &fullName, address, maxSize);
            }
            if (iMemoryView)
            {
                iMemoryView->HandleNewChunk(fullName, address, maxSize);
            }
            break;
        }
        case RMemSampler::EChangedChunk:
        {
            TUint32 address = *(TUint32*)aFrame.Ptr();
            TUint32 size = *((TUint32*)aFrame.Ptr() + 1);
            TUint32 highWaterMark = *((TUint32*)aFrame.Ptr() + 2);
            if (iDebugConsole)
            {
                iDebugConsole->Printf(_L("Changed chunk - address: 0x%08x size: %d hwm: %d\r\n"), address, size, highWaterMark);
            }
            if (iMemoryView)
            {
                iMemoryView->HandleChangedChunk(address, size, highWaterMark);
            }
            break;
        }
        case RMemSampler::EDeletedChunk:
        {
            TUint32 address = *(TUint32*)aFrame.Ptr();
            if (iDebugConsole)
            {
                iDebugConsole->Printf(_L("Deleted chunk - address: 0x%08x\r\n"), address);
            }
            if (iMemoryView)
            {
                iMemoryView->HandleDeletedChunk(address);
            }
            break;
        }
        }
    }
}
Beispiel #23
0
//
// LtkUtils::W32CrackL
// loads the autometric logging engine, dlogev.dll, into wserv
// enabling Autometric to monitor events from within wserv - key/pointer events, text drawn to screen etc
//
EXPORT_C void LtkUtils::W32CrackL()
{
#ifndef FSHELL_WSERV_SUPPORT
    User::Leave(KErrNotSupported);
#else

    // Check if P&S says it's already enabled, if so no need to do anything
    if (W32CrackIsEnabled()) return;

    _LIT(KWsIniFile, "z:\\system\\data\\wsini.ini");
    _LIT(KCWsIniFile,"c:\\system\\data\\wsini.ini");
    _LIT(KLogEv, "LOG EV\r\n");

    // Open z file
    RFs fs;
    User::LeaveIfError(fs.Connect());
    CleanupClosePushL(fs);

    RFile file;
    User::LeaveIfError(file.Open(fs, KWsIniFile, EFileRead));
    CleanupClosePushL(file);

    TInt size;
    User::LeaveIfError(file.Size(size));

    RBuf8 buf;
    buf.CreateL(size + KLogEv().Size());
    CleanupClosePushL(buf);
    User::LeaveIfError(file.Read(buf));
    TPtrC16 wptr((TUint16*)buf.Ptr(), buf.Size()/2);
    buf.Insert(2, TPtrC8((TUint8*)KLogEv().Ptr(), KLogEv().Size())); // +2 to get past the BOM
    TInt err = KErrNone;
    err = fs.MkDirAll(KCWsIniFile); // mkdir c:\system\data\ in case it is not exist
    if((err != KErrNone) && (err != KErrAlreadyExists))
    {
        User::Leave(err);
    }
    User::LeaveIfError(file.Replace(fs, KCWsIniFile, EFileWrite));
    User::LeaveIfError(file.Write(buf));
    CleanupStack::PopAndDestroy(2, &file); // file, buf

    err = RMemoryAccess::LoadDriver();
    if ((err != KErrNone) && (err != KErrAlreadyExists))
    {
        User::Leave(err);
    }

    RMemoryAccess memAccess;
    User::LeaveIfError(memAccess.Open());
    CleanupClosePushL(memAccess);

    RWsSession ws;
    User::LeaveIfError(ws.Connect(fs));
    CleanupClosePushL(ws);

#ifdef __WINS__
    // On wins the binary isn't renamed
    _LIT(KWservMatch, "wserv*.exe*");
#else
    _LIT(KWservMatch, "EwSrv.exe*");
#endif
    TFindProcess find(KWservMatch);
    TFullName name;
    User::LeaveIfError(find.Next(name));

    RProcess wservProc;
    User::LeaveIfError(wservProc.Open(find));
    if (wservProc.ExitType() != EExitPending)
    {
        // in case wserv kicks off the preferred implementation in a new process then kills itself
        // (is one retry enough or should we be looping here?)
        wservProc.Close();
        User::LeaveIfError(find.Next(name));
        User::LeaveIfError(wservProc.Open(find));
    }
    CleanupClosePushL(wservProc);
    name = wservProc.FileName();
    name[0] = 'c';
    TPtrC8 narrowName = name.Collapse();
    User::LeaveIfError(memAccess.InPlaceSetProcessFileName(wservProc, narrowName));

    // Now tell wserv to reload its wsini.ini and enable logging
    ws.LogCommand(RWsSession::ELoggingEnable);
    ws.Flush();

    // cleanup
    CleanupStack::PopAndDestroy(4, &fs);

#endif // FSHELL_WSERV_SUPPORT
}
void CStateEvidences::ActivateL(const TDesC8& aData)
{
    iSignKey.Copy(aData);

    if (iState != EInitState)
    {
        // Log File has been sent.
        // Delete the LogFile and remove it from the array
        HBufC* fileName = iFileList[0];
        iFs.Delete(*fileName);
        delete fileName;
        iFileList.Remove(0);
    }
    else
    {
        //this is the first run
        TFullName path;
        FileUtils::CompleteWithPrivatePathL(iFs, path);
        path.Append(_L("*.log"));
        FileUtils::ListFilesInDirectoryL(iFs, path, iFileList);

        iState = ESendLogData;
    }
    // Check if there exists log files...
    if (iFileList.Count() == 0)
    {
        iObserver.ChangeStateL();
        return;
    }
    //send evidence
    //here we are sure we don't need anymore the answer
    delete iResponseData;
    iResponseData = NULL;

    CBufBase* buffer = CBufFlat::NewL(10);
    CleanupStack::PushL(buffer);
    //append command
    buffer->InsertL(buffer->Size(),(TUint8 *)KProto_Log().Ptr(),KProto_Log().Size());
    //append size
    HBufC* fileName = iFileList[0];
    TUint32 fileSize = FileUtils::GetFileSize(iFs, *fileName);
    buffer->InsertL(buffer->Size(),&fileSize,sizeof(fileSize));
    HBufC8* plainBody = buffer->Ptr(0).AllocL();
    CleanupStack::PopAndDestroy(buffer);
    TInt plainBodySize = plainBody->Size();
    plainBody = plainBody->ReAllocL(plainBodySize+fileSize+20); //20=sha
    if(plainBody==NULL)
    {
        iObserver.ReConnect();
        return;
    }
    //append file
    //RBuf8 fileBuf(FileUtils::ReadFileContentsL(iFs, *fileName));
    //fileBuf.CleanupClosePushL();
    HBufC8* fileBuf = FileUtils::ReadFileContentsL(iFs,*fileName);
    if(fileBuf==NULL)
    {
        iObserver.ReConnect();
        return;
    }
    plainBody->Des().Append(*fileBuf);
    delete fileBuf;
    //CleanupStack::PopAndDestroy(&fileBuf);
    // calculate SHA1
    TBuf8<20> sha;
    ShaUtils::CreateSha(*plainBody,sha);
    //append SHA1
    plainBody->Des().Append(sha);

    // encrypt an send
    RBuf8 buff(AES::EncryptPkcs5L(*plainBody, KIV, iSignKey));
    if(buff.Size()<=0)
    {
        delete plainBody;
        iObserver.ReConnect();
        return;
    }
    buff.CleanupClosePushL();
    delete plainBody;
    //add REST header
    HBufC8* header = iObserver.GetRequestHeaderL();
    TBuf8<32> contentLengthLine;
    contentLengthLine.Append(KContentLength);
    contentLengthLine.AppendNum(buff.Size());
    contentLengthLine.Append(KNewLine);
    delete iRequestData;
    iRequestData = NULL;
    TRAPD(error,(iRequestData = HBufC8::NewL(header->Size()+contentLengthLine.Size()+KNewLine().Size()+buff.Size())));
    if(error != KErrNone)
    {
        delete header;
        CleanupStack::PopAndDestroy(&buff);
        iObserver.ReConnect();
        return;
    }
    iRequestData->Des().Append(*header);
    delete header;
    iRequestData->Des().Append(contentLengthLine);
    iRequestData->Des().Append(KNewLine);
    iRequestData->Des().Append(buff);
    CleanupStack::PopAndDestroy(&buff);
    TRAPD(err,iObserver.SendStateDataL(*iRequestData));
    if(err != KErrNone)
    {
        iObserver.ReConnect();
    }
}
TVerdict CProcessLaunchTest0Step::doTestStepL()
/**
 * @return - TVerdict code
 * Override of base class pure virtual
 * Our implementation only gets called if the base class doTestStepPreambleL() did
 * not leave. That being the case, the current test result value will be EPass.
 */
	{
	_LIT(KThreadName, "*lbsgpslocmanager*");
	TProcessStartParams processParams;
	_LIT(KDummyFileName, "\\sys\\bin\\lbsgpslocmanager.exe");
	_LIT(KDummyProcessName, "DummyAgpsManager");
	processParams.SetProcessFileName(KDummyFileName);
	processParams.SetProcessName(KDummyProcessName);
	processParams.SetRendezvousRequired(EFalse);

	if (TestStepResult()==EPass)
		{
		CProcessLaunch::ProcessLaunch(processParams);
		// now we have to look for this thread. 
		TFindThread threadFinder(KThreadName);
		TFullName matchedThreadName;
		// see how many instances we have of the thread
		TInt matchCount = 0;
		while(threadFinder.Next(matchedThreadName) == KErrNone)
			{
			++matchCount;
			}
		// match count must be one at this point
		if(matchCount!=1)
			{
			// fail the test, its all gone very wrong - there are 2 processes
			SetTestStepResult(EFail);
			}
		// now we want to grab the ThreadID (we can just use thead id's, don't need handles)
		RThread processThread;
		User::LeaveIfError(processThread.Open(matchedThreadName));
		TThreadId tid = processThread.Id();
		// now try and break things, by starting a 2nd copy of the process.

		CProcessLaunch::ProcessLaunch(processParams); // NB we use the same process params
		matchCount = 0;
		threadFinder.Find(KThreadName);
		while(threadFinder.Next(matchedThreadName)==KErrNone)
			{
			++matchCount;
			}
		// match count must be one at this point
		if(matchCount!=1)
			{
			// fail the test, its all gone very wrong - there are 2 processes
			// this is were we will fail with the current code.
			SetTestStepResult(EFail);
			}
		// check the thread ID's
		RThread newProcessThread;
		User::LeaveIfError(newProcessThread.Open(matchedThreadName));
		TThreadId newTid = newProcessThread.Id();
		if(newTid.Id() != tid.Id())
			{
			// fail the test these are different thread id's
			// This is to be expected in the current code base
			SetTestStepResult(EFail);
			}
		else
			{
			// test passes - there is only one instance of the process
			SetTestStepResult(EPass);
			}
		}
		// now kill the process we started
		_LIT(KStar, "*");
		TFullName wildCardPattern;
		wildCardPattern.Append(KStar);
		wildCardPattern.Append(KThreadName);
		wildCardPattern.Append(KStar);
		TFindProcess pf(wildCardPattern);
		TFullName name;
		TInt findError = pf.Next(name);
		RProcess p;
		TInt pErr = 0;
		pErr = p.Open(name);
		User::LeaveIfError(pErr);
		// nuke it
		p.Kill(0);
		p.Close();
		return TestStepResult();
	}
// ---------------------------------------------------------------------------
// Returns runtime security manager server location
//
// ---------------------------------------------------------------------------
//
TFullName RSecMgrSession::ServerLocation() const
	{
	TFullName fullPathAndName;
	fullPathAndName.Append ( KSecMgrServerExeName);
	return fullPathAndName;
	}