-- @path ANO=/AnalysisOfSecurityAspectsInManifest/metamodels/ANO.ecore
-- @path ASEC=/AnalysisOfSecurityAspectsInManifest/metamodels/ASEC.ecore

module AnalysisOfActions;
create OUT : ANO from IN : ASEC;


--Check list for Malicious Actions:
helper def:all_actions_of_malicious_intentfilter:Sequence(OclAny)=
	Sequence{'android.intent.action.BOOT_COMPLETED',
	         'android.intent.action.SMS_RECEIVED',
			 'android.intent.action.CONNECTIVITY_CHANGE',
			 'android.intent.action.USER_PRESENT',
			 'android.intent.action.PHONE_STATE',
			 'android.intent.action.NEW_OUTGOING_CALL',
			 'android.intent.action.UNINSTALL_SHORTCUT',
			 'android.intent.action.INSTALL_SHORTCUT',
			 'android.intent.action.left_up',
			 'android.intent.action.right_up',
			 'android.intent.action.left_down',
			 'android.intent.action.right_down',
			 'android.intent.action.SIG_STR',
			 'android.intent.action.VEIW'
	         };

	
helper context ASEC!Action def:isMalicious: Boolean=
		if thisModule.all_actions_of_malicious_intentfilter.includes(self.name)  then
			true
		   else
		  false
	   endif;
	

--for detection Malicious Actions:
helper context ASEC!Action def:getMaliciousAction :Sequence(String) =
	let Actions_of_intents : Sequence(ASEC!Action) = self.refImmediateComposite().actions in
	Actions_of_intents->iterate(n ; output : Sequence(String) = Sequence{} | 
	

		if thisModule.all_actions_of_malicious_intentfilter.includes(self.name) then
			output->including(': The Application is Malicous because exist a IntentFilter with Malicous Action : ' + self.name )
			 else
			output->including('the application is safe')
		endif
													
		)->asSet()->asSequence();

	


--for transfer Action to MaliciousPermissions
rule Action2MaliciousActions{
	
	from
	    s:ASEC!Action (s.isMalicious)
	to
	   t:ANO!MaliciousActions (
	   	
	   description <- s.getMaliciousAction->iterate(ac; output: String = '' | output->concat(ac)+'\n')
	       
	   
	   )
	   do {
	t.trace<-Sequence{s};
}
}

