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

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


helper def:StrongPermission:Sequence(OclAny)=
	Sequence{--Signature
'android.permission.ACCESS_SURFACE_FLINGER','android.permission.ACCOUNT_MANAGER','android.permission.BRICK', 'android.permission.BIND_INPUT_METHOD', 'android.permission.SHUTDOWN',
'android.permission.SET_ACTIVITY_WATCHER', 'android.permission.SET_ORIENTATION', 'android.permission.HARDWARE_TEST','android.permission.UPDATE_DEVICE_STATS','android.permission.CLEAR_APP_USER_DATA',
'android.permission.COPY_PROTECTED_DATA','android.permission.CHANGE_COMPONENT_ENABLED_STATE','android.permission.FORCE_BACK','android.permission.INJECT_EVENTS', 'android.permission.INTERNAL_SYSTEM_WINDOW', 
'android.permission.MANAGE_APP_TOKENS', 'android.permission.BROADCAST_PACKAGE_REMOVED', 'android.permission.BROADCAST_SMS', 'android.permission.BROADCAST_WAP_PUSH', 'android.permission.PACKAGE_USAGE_STATS', 
'android.permission.CHANGE_BACKGROUND_DATA_SETTING', 'android.permission.BIND_DEVICE_ADMIN', 'android.permission.READ_FRAME_BUFFER', 'android.permission.DEVICE_POWER', 
'android.permission.DIAGNOSTIC', 'android.permission.FACTORY_TEST', 'android.permission.FORCE_STOP_PACKAGES', 'android.permission.GLOBAL_SEARCH_CONTROL', 
--SignatureOrSystem
'android.permission.ACCESS_CHECKIN_PROPERTIES','android.permission.BACKUP','android.permission.BIND_APPWIDGET','android.permission.BIND_WALLPAPER',
'android.permission.CALL_PRIVILEGED','android.permission.CONTROL_LOCATION_UPDATES','android.permission.DELETE_CACHE_FILES','android.permission.DELETE_PACKAGES',
'android.permission.GLOBAL_SEARCH','android.permission.INSTALL_LOCATION_PROVIDER','android.permission.INSTALL_PACKAGES','android.permission.MASTER_CLEAR',
'android.permission.REBOOT','android.permission.SET_TIME','android.permission.STATUS_BAR','android.permission.WRITE_GSERVICES','android.permission.WRITE_SECURE_SETTINGS'

};


helper def:Method_for_Activity:Sequence(OclAny)=
	Sequence{
	'startActivity',
    'startActivityForResult'
	
            };

helper def:Method_for_Service:Sequence(OclAny)=
	Sequence{
	'startService',
    'bindService'
	
            };
            
 helper def:Method_for_Receiver:Sequence(OclAny)=
	Sequence{
	'sendBroadcast',
 	'sendOrderedBroadcast',
    'sendStickyBroadcast',
    'sendStickyOrderedBroadcast'
	
            };          


helper context ASEC!Intent def:getUnauthorizedIntentReceipt :Sequence(String) =
	
	let IntentsOfApp : Sequence(ASEC!Intent) = self.refImmediateComposite().Intents in
	IntentsOfApp->iterate(n ; output : Sequence(String) = Sequence{} | 
	  
	
	
	   if self.IntentKind=#explicit then
	        output->reject(c | c.name=self.name)
			
			  else 
	             if self.Action.oclIsUndefined() then
				       output->reject(c | c.name=self.name)
					   
		              else
	                      if self.Permission.oclIsUndefined() then
					             if self.Data='yes' then
								     if thisModule.Method_for_Activity.includes(self.MethodForSend) then
									     output->including(': The Application have Activity Hijacking(with data) attack in Intent with name:  '+ self.name +'and in Component with Package:'+ self.SendComponentName)
	                                     else
	                                       if thisModule.Method_for_Service.includes(self.MethodForSend) then
										        output->including(': The Application have Service Hijacking(with data) attack in Intent with name:  '+ self.name +'and in Component with Package:'+ self.SendComponentName)
	                                          else
	                                          	if thisModule.Method_for_Receiver.includes(self.MethodForSend) then
												     output->including(': The Application have Broadcast Theft(with data) attack in Intent with name:  '+ self.name +'and in Component with Package:'+ self.SendComponentName)
	                                                else
	                                                  output->reject(c | c.name=self.name)
													  
												endif
										   endif
									  endif
									 else
									   if thisModule.Method_for_Activity.includes(self.MethodForSend) then
									     output->including(': The Application have Activity Hijacking(without data) attack in Intent with name:  '+ self.name +'and in Component with Package:'+ self.SendComponentName)
	                                     else
	                                       if thisModule.Method_for_Service.includes(self.MethodForSend) then
										        output->including(': The Application have Service Hijacking(without data) attack in Intent with name:  '+ self.name +'and in Component with Package:'+ self.SendComponentName)
	                                          else
	                                          	if thisModule.Method_for_Receiver.includes(self.MethodForSend) then
												     output->including(': The Application have Broadcast Theft(without data) attack in Intent with name:  '+ self.name +'and in Component with Package:'+ self.SendComponentName)
	                                                else
	                                                  output->reject(c | c.name=self.name)
													  
												endif
										   endif
									  endif
									 endif
								else
								  if thisModule.StrongPermission.includes(self.Permission) then	   
	                                  output->reject(c | c.name=self.name)
									  
	                                     else
						                	if self.Data='yes' then
	                                            if thisModule.Method_for_Activity.includes(self.MethodForSend) then
									                output->including(': The Application have Activity Hijacking(with data) attack in Intent with name:  '+ self.name +'and in Component with Package:'+ self.SendComponentName)
	                                               else
	                                                   if thisModule.Method_for_Service.includes(self.MethodForSend) then
										                   output->including(': The Application have Service Hijacking(with data) attack in Intent with name:  '+ self.name +'and in Component with Package:'+ self.SendComponentName)
	                                                        else
	                                          	             if thisModule.Method_for_Receiver.includes(self.MethodForSend) then
												                output->including(': The Application have Broadcast Theft(with data) attack in Intent with name:  '+ self.name +'and in Component with Package:'+ self.SendComponentName)
	                                                             else
	                                                               output->reject(c | c.name=self.name)
																   
												             endif
										               endif
									           endif
									      else
									          if thisModule.Method_for_Activity.includes(self.MethodForSend) then
									              output->including(': The Application have Activity Hijacking(without data) attack in Intent with name:  '+ self.name +'and in Component with Package:'+ self.SendComponentName)
	                                                else
	                                                     if thisModule.Method_for_Service.includes(self.MethodForSend) then
										                   output->including(': The Application have Service Hijacking(without data) attack in Intent with name:  '+ self.name +'and in Component with Package:'+ self.SendComponentName)
	                                                        else
	                                          	              if thisModule.Method_for_Receiver.includes(self.MethodForSend) then
												                output->including(': The Application have Broadcast Theft(without data) attack in Intent with name:  '+ self.name +'and in Component with Package:'+ self.SendComponentName)
	                                                           else
	                                                            --output->reject(c | c.name=self.name)
																OclUndefined
												              endif
										                endif
									         endif
									      endif
										 endif
										endif
									endif
								endif
	
	
	
				  
					       
					  
	
	
	)->asSet()->asSequence();








rule Intent2ActionBased{
	
	from
	   s:ASEC!Intent (not s.Action.oclIsUndefined() and s.IntentKind=#implicit and thisModule.StrongPermission.excludes(s.Permission))
	to
	   t:ANO!UnauthorizedIntentReceipt (
	   	
	
  	  description <- s.getUnauthorizedIntentReceipt->iterate(up; output: String = '' | output->concat(up)+'\n')
	  
			
	  
	       
	   
	   )
	  do {
	t.trace<-Sequence{s};
}
}