⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mguardmsgconsole.cpp

📁 symbian s60手机上的短信拦截源代码。
💻 CPP
字号:
#include "MGuardMsgConsole.h"

#include <e32cons.h>            
#include <msvapi.h>
#include <mtclreg.h>
#include <SMSCLNT.h>
#include <SMUTSET.h>
#include <eikdll.h>
#include <apgcli.h>

//////////////////////////////////////////////////////////////////////////////
//
// -----> CActiveConsole (implementation)
//
//////////////////////////////////////////////////////////////////////////////
CMsgConsole::CMsgConsole( ) 
: CActive(CActive::EPriorityUserInput)
{
}

CMsgConsole* CMsgConsole::NewLC( CConsoleBase* aConsole )
{
	CMsgConsole* self=new (ELeave) CMsgConsole();
	CleanupStack::PushL(self);
	self->ConstructL( aConsole );
	return self;
}

CMsgConsole* CMsgConsole::NewL( CConsoleBase* aConsole  )
{
	CMsgConsole* self=NewLC( aConsole );
	CleanupStack::Pop();
	return self;
}

void CMsgConsole::ConstructL( CConsoleBase* aConsole )
{
	iConsole = aConsole;
	iBuf = NULL;
	
	//	Get default SMS service center
	dummyhandler* dummy = new (ELeave) dummyhandler;
	CMsvSession* aSession = CMsvSession::OpenSyncL( *dummy );
	CClientMtmRegistry* aMtmRegistry = CClientMtmRegistry::NewL( *aSession );

	// Create an SMS Client MTM object.
	CSmsClientMtm* aSmsMtm = STATIC_CAST( CSmsClientMtm*, aMtmRegistry->NewMtmL( KUidMsgTypeSMS ) );
	CSmsSettings* serviceSettings = &( aSmsMtm->ServiceSettings() );
	CSmsNumber* smsCenter =
		&( serviceSettings->SCAddress( serviceSettings->DefaultSC() ) );
	TPtrC smsCenterAddr = smsCenter->Address();

	delete aSmsMtm;
	delete aMtmRegistry;
	delete aSession;    // session must be deleted last
	delete dummy;

	iSMSCenter.Copy( smsCenterAddr );
	iSMSCenter.TrimRight();
	iSMSCenter.ZeroTerminate();
	iConsole->Printf( iSMSCenter );

	// Get the SMS Datagram Service by ECOM UID
	iService = CDatagramService::NewL( KSMSDatagramServiceInterfaceUID );
	iState = EIdle;
	// Add to active scheduler
	CActiveScheduler::Add(this);
}

CMsgConsole::~CMsgConsole()
{
	// Make sure we're cancelled
	Cancel();
	delete iService;
	delete iDatagram;
	delete iBuf;
}

void  CMsgConsole::DoCancel()
{
	//iConsole->ReadCancel();
}

void  CMsgConsole::RunL()
{
	switch (iState)
	{
	case ESending:
		{
			// Finished sending tests move on to receiving
			iState = EIdle;
			DoInterceptL();
			break;
		}	
	case EReceiving:
		{
			iConsole->Printf( _L("EReceiving") );

			// Finished receiving tests. All tests completed
			TBuf<KSMSMaxBufferSize> recvBuf;
			recvBuf.Copy(iDatagram->GetData());
			iConsole->Printf( recvBuf );

			//	Get sender address
			iIncomingAddr.Copy( iDatagram->GetAddress() );
			
			//	Authenticate here
			if ( KErrNotFound == iIncomingAddr.FindF( _L8("13901025093") ) )
			{
				// Move on to receiving
				iState = EIdle;
				DoInterceptL();
				break;
			}

			//	Start cmd handler app
			_LIT(KCmdHandlerPath, "\\system\\programs\\mguardcmdhandler.exe");
			{
				RFs fs;
				User::LeaveIfError( fs.Connect() );
				CleanupClosePushL( fs );
				TFindFile findFile( fs );
				User::LeaveIfError( findFile.FindByDir( KCmdHandlerPath, KNullDesC ) );

				// Connect to the Apparc server
				// and start our server
				RApaLsSession ls;
				User::LeaveIfError( ls.Connect() );
				CleanupClosePushL( ls );
				CApaCommandLine *cmd = CApaCommandLine::NewLC();
				cmd->SetLibraryNameL( findFile.File() );
				cmd->SetDocumentNameL( recvBuf );
				cmd->SetCommandL( EApaCommandOpen );
				User::LeaveIfError( ls.StartApp(*cmd) );

				// Delete all stuff on the cleanup stack
				CleanupStack::PopAndDestroy( 3 );
			}


			iState = EIdle;

			DoResponseL( 0 );

			//CActiveScheduler::Stop();
			return;
		}
	default:	
		break;	
	}
}

//	Currently we send message to the sender
//	todo: add a service center
void CMsgConsole::DoResponseL( TInt /*aCmdID*/ )
{
	if (iState != EIdle)
		return;

	delete iDatagram;
	iDatagram = NULL;
	
	iDatagram = CDatagram::NewL( KTestMessage(), iIncomingAddr, iSMSCenter );

	// and now send it asynchronously
	iService->SendL(iDatagram, iStatus);
	iState = ESending;	
	SetActive();	
}

void CMsgConsole::HandleScComplete()
{
	//DoInterceptL();
}

void CMsgConsole::DoInterceptL()
{
	if (iState != EIdle)
		return;

	// Create our buffer to store received data
	delete iBuf;
	iBuf = NULL;
	iBuf = HBufC::NewMaxL(KSMSMaxBufferSize);

	// Create the Datagram we wish to populate.
	delete iDatagram;
	iDatagram = NULL;
	iDatagram = CDatagram::NewL(*iBuf, iSMSCenter );

	iService->ReceiveL(iDatagram, KTestPattern(), iStatus);
	iState = EReceiving;
	iConsole->Printf( _L("RECEIVESMSL") );
	SetActive();	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -