-- @path ANOMM=/InterComponentCommunicationModeling/MetaModels/ANO.ecore
-- @path ICCMM=/InterComponentCommunicationModeling/MetaModels/ICCMM.ecore

module CustomPermissionVulnerabilityInterApp;
create OUT : ANOMM from IN : ICCMM;


helper context ICCMM!SenderApp def:checkSpecificPermInUsesPerms (perm_name: String) : Boolean =	
if self.usesPermissions->select(c | c.Name=perm_name).notEmpty() then
 true
else
	false
endif;

helper context ICCMM!SenderApp def:getSpecificPermInUsesPerms (perm_name: String) : ICCMM!UsesPermission =	
if self.usesPermissions->select(c | c.Name=perm_name).notEmpty() then
 self.usesPermissions->select(c | c.Name=perm_name).first()
else
	OclUndefined
endif;

helper context OclAny def:getImplicitCommunication :ICCMM!ImplicitCommunication =
 if self.oclIsTypeOf(ICCMM!ImplicitCommunication) then
  self
 else
	self.refImmediateComposite().getImplicitCommunication
 endif;

helper context ICCMM!ExplicitCommunication def:getCustomPermissionVulnerabilityExplicitCommunications :Sequence(String) =	
let ExplicitCommunicationsOfBundle : Sequence(ICCMM!ExplicitCommunication) = self.refImmediateComposite().explicit_communications in
ExplicitCommunicationsOfBundle->iterate(n ; output : Sequence(String) = Sequence{} | 

if not self.sender_app.Name.oclIsUndefined() then
    if not self.receiver_app.Name.oclIsUndefined() then
        if not self.sender_app.Name.toString().endsWith(self.receiver_app.Name.toString()) then
            if not self.intent.target_component.oclIsUndefined() then
			   if self.intent.target_component.component_enforcedPermissions.notEmpty() then
			       if self.intent.target_component.component_enforcedPermissions->select(c | c.CustomPerm).notEmpty() then
				       if self.sender_app.usesPermissions.notEmpty() then
					      if self.intent.target_component.component_enforcedPermissions->select(c | c.CustomPerm)->select(c | self.sender_app.checkSpecificPermInUsesPerms(c.Name)).notEmpty() then
						     if self.intent.target_component.component_enforcedPermissions->select(c | c.CustomPerm)->select(c | not (self.sender_app.getSpecificPermInUsesPerms(c.Name).PermissionKind=c.PermissionKind)).notEmpty() then
						        if self.intent.target_component.component_enforcedPermissions->select(c | c.CustomPerm)->select(c | (self.sender_app.getSpecificPermInUsesPerms(c.Name).PermissionKind=#Normal) and (c.PermissionKind=#Dangerous)).notEmpty() then
						            output->including(': This Bundle has Custom Permission vulnerability in the explicit communication with this specification:' + ' '+ '/Sender Component:'+ ' ' + self.intent.SendComponentName + ' /'+ ' ' + '/Sender App:'+ ' ' + self.sender_app.Name + ' /' + '/Receiver Component:'+ ' ' + self.intent.Receiver + ' /' + '/Receiver App:'+ ' ' + self.receiver_app.Name + ' /') 
								else
									if self.intent.target_component.component_enforcedPermissions->select(c | c.CustomPerm)->select(c | (self.sender_app.getSpecificPermInUsesPerms(c.Name).PermissionKind=#Normal) and (c.PermissionKind=#Signature)).notEmpty() then
						                   output->including(': This Bundle has Custom Permission vulnerability in the explicit communication with this specification:' + ' '+ '/Sender Component:'+ ' ' + self.intent.SendComponentName + ' /'+ ' ' + '/Sender App:'+ ' ' + self.sender_app.Name + ' /' + '/Receiver Component:'+ ' ' + self.intent.Receiver + ' /' + '/Receiver App:'+ ' ' + self.receiver_app.Name + ' /') 
									else
									    if self.intent.target_component.component_enforcedPermissions->select(c | c.CustomPerm)->select(c | (self.sender_app.getSpecificPermInUsesPerms(c.Name).PermissionKind=#Normal) and (c.PermissionKind=#SignatureOrSystem)).notEmpty() then
						                       output->including(': This Bundle has Custom Permission vulnerability in the explicit communication with this specification:' + ' '+ '/Sender Component:'+ ' ' + self.intent.SendComponentName + ' /'+ ' ' + '/Sender App:'+ ' ' + self.sender_app.Name + ' /' + '/Receiver Component:'+ ' ' + self.intent.Receiver + ' /' + '/Receiver App:'+ ' ' + self.receiver_app.Name + ' /') 
										else
											if self.intent.target_component.component_enforcedPermissions->select(c | c.CustomPerm)->select(c | (self.sender_app.getSpecificPermInUsesPerms(c.Name).PermissionKind=#Dangerous) and (c.PermissionKind=#Signature)).notEmpty() then
						                            output->including(': This Bundle has Custom Permission vulnerability in the explicit communication with this specification:' + ' '+ '/Sender Component:'+ ' ' + self.intent.SendComponentName + ' /'+ ' ' + '/Sender App:'+ ' ' + self.sender_app.Name + ' /' + '/Receiver Component:'+ ' ' + self.intent.Receiver + ' /' + '/Receiver App:'+ ' ' + self.receiver_app.Name + ' /') 
											else
												if self.intent.target_component.component_enforcedPermissions->select(c | c.CustomPerm)->select(c | (self.sender_app.getSpecificPermInUsesPerms(c.Name).PermissionKind=#Dangerous) and (c.PermissionKind=#SignatureOrSystem)).notEmpty() then
						                              output->including(': This Bundle has Custom Permission vulnerability in the explicit communication with this specification:' + ' '+ '/Sender Component:'+ ' ' + self.intent.SendComponentName + ' /'+ ' ' + '/Sender App:'+ ' ' + self.sender_app.Name + ' /' + '/Receiver Component:'+ ' ' + self.intent.Receiver + ' /' + '/Receiver App:'+ ' ' + self.receiver_app.Name + ' /') 
												else
													    output->including(': This Bundle has Custom Permission vulnerability in the explicit communication with this specification:' + ' '+ '/Sender Component:'+ ' ' + self.intent.SendComponentName + ' /'+ ' ' + '/Sender App:'+ ' ' + self.sender_app.Name + ' /' + '/Receiver Component:'+ ' ' + self.intent.Receiver + ' /' + '/Receiver App:'+ ' ' + self.receiver_app.Name + ' /') 
												endif
											endif
										endif
									endif
								endif
							 else
							 	output->reject(c | c.Name='')
							 endif
						  else
						  	output->reject(c | c.Name='')
						  endif
					   else
					   	output->reject(c | c.Name='')
					   endif
				   else
				   	output->reject(c | c.Name='')
				   endif
			   else
			   	 output->reject(c | c.Name='')
			   endif
			else
				output->reject(c | c.Name='')
			endif
        else
         output->reject(c | c.Name='')
        endif
    else
      output->reject(c | c.Name='')
     endif
else
output->reject(c | c.Name='')
endif
)->asSet()->asSequence();


helper context ICCMM!ImplicitTargetComponent def:getCustomPermissionVulnerabilityImplicitCommunications :Sequence(String) =	
let ImplicitTargetComponentsOfCommunication : Sequence(ICCMM!ImplicitTargetComponent) = self.refImmediateComposite().target_components in
ImplicitTargetComponentsOfCommunication->iterate(n ; output : Sequence(String) = Sequence{} | 

if not self.receiver_app.Name.toString().endsWith(self.refImmediateComposite().refImmediateComposite().sender_app.Name.toString()) then
    if self.component_enforcedPermissions.notEmpty() then
	   if self.component_enforcedPermissions->select(c | c.CustomPerm).notEmpty() then
	      if self.getImplicitCommunication.sender_app.usesPermissions.notEmpty() then
		     if self.component_enforcedPermissions->select(c | c.CustomPerm)->select(c | self.getImplicitCommunication.sender_app.checkSpecificPermInUsesPerms(c.Name)).notEmpty() then
			    if self.component_enforcedPermissions->select(c | c.CustomPerm)->select(c | not (self.getImplicitCommunication.sender_app.getSpecificPermInUsesPerms(c.Name).PermissionKind=c.PermissionKind)).notEmpty() then
				   if self.component_enforcedPermissions->select(c | c.CustomPerm)->select(c | (self.getImplicitCommunication.sender_app.getSpecificPermInUsesPerms(c.Name).PermissionKind=#Normal) and (c.PermissionKind=#Dangerous)).notEmpty() then
				     output->including(': This Bundle has Custom Permission vulnerability in the implicit communication with this specification:' + ' '+ '/Sender Component:'+ ' ' + self.refImmediateComposite().SendComponentName + ' /'+ ' ' + '/Sender App:'+ ' ' + self.refImmediateComposite().refImmediateComposite().sender_app.Name + ' /' + '/Target Component:'+ ' ' + self.Name + ' /' + '/Receiver App:'+ ' ' + self.receiver_app.Name + ' /') 
				   else
				   	  if self.component_enforcedPermissions->select(c | c.CustomPerm)->select(c | (self.getImplicitCommunication.sender_app.getSpecificPermInUsesPerms(c.Name).PermissionKind=#Normal) and (c.PermissionKind=#Signature)).notEmpty() then
				          output->including(': This Bundle has Custom Permission vulnerability in the implicit communication with this specification:' + ' '+ '/Sender Component:'+ ' ' + self.refImmediateComposite().SendComponentName + ' /'+ ' ' + '/Sender App:'+ ' ' + self.refImmediateComposite().refImmediateComposite().sender_app.Name + ' /' + '/Target Component:'+ ' ' + self.Name + ' /' + '/Receiver App:'+ ' ' + self.receiver_app.Name + ' /') 	   
					  else
					  	  if self.component_enforcedPermissions->select(c | c.CustomPerm)->select(c | (self.getImplicitCommunication.sender_app.getSpecificPermInUsesPerms(c.Name).PermissionKind=#Normal) and (c.PermissionKind=#SignatureOrSystem)).notEmpty() then
				             output->including(': This Bundle has Custom Permission vulnerability in the implicit communication with this specification:' + ' '+ '/Sender Component:'+ ' ' + self.refImmediateComposite().SendComponentName + ' /'+ ' ' + '/Sender App:'+ ' ' + self.refImmediateComposite().refImmediateComposite().sender_app.Name + ' /' + '/Target Component:'+ ' ' + self.Name + ' /' + '/Receiver App:'+ ' ' + self.receiver_app.Name + ' /') 		   
						  else
						  	  if self.component_enforcedPermissions->select(c | c.CustomPerm)->select(c | (self.getImplicitCommunication.sender_app.getSpecificPermInUsesPerms(c.Name).PermissionKind=#Dangerous) and (c.PermissionKind=#Signature)).notEmpty() then
				                 output->including(': This Bundle has Custom Permission vulnerability in the implicit communication with this specification:' + ' '+ '/Sender Component:'+ ' ' + self.refImmediateComposite().SendComponentName + ' /'+ ' ' + '/Sender App:'+ ' ' + self.refImmediateComposite().refImmediateComposite().sender_app.Name + ' /' + '/Target Component:'+ ' ' + self.Name + ' /' + '/Receiver App:'+ ' ' + self.receiver_app.Name + ' /') 
							  else
							  	  if self.component_enforcedPermissions->select(c | c.CustomPerm)->select(c | (self.getImplicitCommunication.sender_app.getSpecificPermInUsesPerms(c.Name).PermissionKind=#Dangerous) and (c.PermissionKind=#SignatureOrSystem)).notEmpty() then
				                        output->including(': This Bundle has Custom Permission vulnerability in the implicit communication with this specification:' + ' '+ '/Sender Component:'+ ' ' + self.refImmediateComposite().SendComponentName + ' /'+ ' ' + '/Sender App:'+ ' ' + self.refImmediateComposite().refImmediateComposite().sender_app.Name + ' /' + '/Target Component:'+ ' ' + self.Name + ' /' + '/Receiver App:'+ ' ' + self.receiver_app.Name + ' /') 
								  else
								  	output->reject(c | c.Name='')
								  endif
							  endif
						  endif
					  endif
					endif
				else
					output->reject(c | c.Name='')
				endif
			 else
			 	output->reject(c | c.Name='')
			 endif
		  else
		  	output->reject(c | c.Name='')
		  endif
	   else
	   	output->reject(c | c.Name='')
	   endif
	else
		output->reject(c | c.Name='')
	endif
else
output->reject(c | c.Name='')
endif
	
)->asSet()->asSequence();


helper context ICCMM!DataAccessCommunication def:getCustomPermissionVulnerabilityDataAccessCommunications :Sequence(String) =	
let DataAccessCommunicationsOfBundle : Sequence(ICCMM!DataAccessCommunication) = self.refImmediateComposite().dataAccess_communications in
DataAccessCommunicationsOfBundle->iterate(n ; output : Sequence(String) = Sequence{} | 
	
if not self.uri_of_DBR_request.receiver_ContentProvider.oclIsUndefined() then
    if not self.uri_of_DBR_request.receiver_ContentProvider.receiver_app.Name.toString().endsWith(self.sender_app.Name.toString()) then
        if not self.uri_of_DBR_request.receiver_ContentProvider.URIpermissions.notEmpty() then
		    if not self.uri_of_DBR_request.receiver_ContentProvider.pathPermissions.notEmpty() then
			    if not self.uri_of_DBR_request.receiver_ContentProvider.permissions.notEmpty() then
			      output->reject(c | c.Name='')
				else
					if self.sender_app.usesPermissions.notEmpty() then
			   	        if self.uri_of_DBR_request.receiver_ContentProvider.permissions->select(c | self.sender_app.checkSpecificPermInUsesPerms(c.Name)).notEmpty() then
					        if self.uri_of_DBR_request.receiver_ContentProvider.permissions->select(c | not (self.sender_app.getSpecificPermInUsesPerms(c.Name).PermissionKind=c.PermissionKind)).notEmpty() then
					            if self.uri_of_DBR_request.receiver_ContentProvider.permissions->select(c | (self.sender_app.getSpecificPermInUsesPerms(c.Name).PermissionKind=#Normal)and (c.PermissionKind=#Dangerous)).notEmpty() then
					             output->including(': This Bundle has Custom Permission vulnerability in the URI communication with this specification:' + ' '+ '/Sender App:'+ ' ' + self.sender_app.Name + ' /'+ ' ' + '/Sender Component:'+ ' ' + self.uri_of_DBR_request.SenderComponentName + '/' + ' ' + '/Receiver App:'+ ' ' + self.uri_of_DBR_request.receiver_ContentProvider.receiver_app.Name +'/' + ' '+ '/Receiver Content Provider:' + ' '+ self.uri_of_DBR_request.receiver_ContentProvider.Name +'/' + ' ' + ' /' + '/URI:'+ ' ' + self.uri_of_DBR_request.URI + ' /') 
						        else
						  	        if self.uri_of_DBR_request.receiver_ContentProvider.permissions->select(c | (self.sender_app.getSpecificPermInUsesPerms(c.Name).PermissionKind=#Normal)and (c.PermissionKind=#Signature)).notEmpty() then
					                 output->including(': This Bundle has Custom Permission vulnerability in the URI communication with this specification:' + ' '+ '/Sender App:'+ ' ' + self.sender_app.Name + ' /'+ ' ' + '/Sender Component:'+ ' ' + self.uri_of_DBR_request.SenderComponentName + '/' + ' ' + '/Receiver App:'+ ' ' + self.uri_of_DBR_request.receiver_ContentProvider.receiver_app.Name +'/' + ' '+ '/Receiver Content Provider:' + ' '+ self.uri_of_DBR_request.receiver_ContentProvider.Name +'/' + ' ' + ' /' + '/URI:'+ ' ' + self.uri_of_DBR_request.URI + ' /') 
							        else
					                    if self.uri_of_DBR_request.receiver_ContentProvider.permissions->select(c | (self.sender_app.getSpecificPermInUsesPerms(c.Name).PermissionKind=#Normal)and (c.PermissionKind=#SignatureOrSystem)).notEmpty() then
					                      output->including(': This Bundle has Custom Permission vulnerability in the URI communication with this specification:' + ' '+ '/Sender App:'+ ' ' + self.sender_app.Name + ' /'+ ' ' + '/Sender Component:'+ ' ' + self.uri_of_DBR_request.SenderComponentName + '/' + ' ' + '/Receiver App:'+ ' ' + self.uri_of_DBR_request.receiver_ContentProvider.receiver_app.Name +'/' + ' '+ '/Receiver Content Provider:' + ' '+ self.uri_of_DBR_request.receiver_ContentProvider.Name +'/' + ' ' + ' /' + '/URI:'+ ' ' + self.uri_of_DBR_request.URI + ' /')  
								        else
								  	        if self.uri_of_DBR_request.receiver_ContentProvider.permissions->select(c | (self.sender_app.getSpecificPermInUsesPerms(c.Name).PermissionKind=#Dangerous)and (c.PermissionKind=#Signature)).notEmpty() then
					                           output->including(': This Bundle has Custom Permission vulnerability in the URI communication with this specification:' + ' '+ '/Sender App:'+ ' ' + self.sender_app.Name + ' /'+ ' ' + '/Sender Component:'+ ' ' + self.uri_of_DBR_request.SenderComponentName + '/' + ' ' + '/Receiver App:'+ ' ' + self.uri_of_DBR_request.receiver_ContentProvider.receiver_app.Name +'/' + ' '+ '/Receiver Content Provider:' + ' '+ self.uri_of_DBR_request.receiver_ContentProvider.Name +'/' + ' ' + ' /' + '/URI:'+ ' ' + self.uri_of_DBR_request.URI + ' /') 
									        else
									  	        if self.uri_of_DBR_request.receiver_ContentProvider.permissions->select(c | (self.sender_app.getSpecificPermInUsesPerms(c.Name).PermissionKind=#Dangerous)and (c.PermissionKind=#SignatureOrSystem)).notEmpty() then
					                              output->including(': This Bundle has Custom Permission vulnerability in the URI communication with this specification:' + ' '+ '/Sender App:'+ ' ' + self.sender_app.Name + ' /'+ ' ' + '/Sender Component:'+ ' ' + self.uri_of_DBR_request.SenderComponentName + '/' + ' ' + '/Receiver App:'+ ' ' + self.uri_of_DBR_request.receiver_ContentProvider.receiver_app.Name +'/' + ' '+ '/Receiver Content Provider:' + ' '+ self.uri_of_DBR_request.receiver_ContentProvider.Name +'/' + ' ' + ' /' + '/URI:'+ ' ' + self.uri_of_DBR_request.URI + ' /') 
						                        else
						                  	     output->reject(c | c.Name='')
										        endif
									        endif
								        endif
							        endif
						        endif
						    else
							output->reject(c | c.Name='')
					        endif
					    else
					  	 output->reject(c | c.Name='')
					     endif
					else
					 output->reject(c | c.Name='')
					endif
				endif
		    else
			    if not self.uri_of_DBR_request.receiver_ContentProvider.pathPermissions->select(c | self.uri_of_DBR_request.URI.endsWith(c.Path)).notEmpty() then
				 output->reject(c | c.Name='')
			    else
				    if self.sender_app.usesPermissions.notEmpty() then
			  	        if self.uri_of_DBR_request.receiver_ContentProvider.pathPermissions->select(c | self.uri_of_DBR_request.URI.endsWith(c.Path))->select(c | c.permissions->exists(a | self.sender_app.checkSpecificPermInUsesPerms(a.Name))).notEmpty() then
				            if self.uri_of_DBR_request.receiver_ContentProvider.pathPermissions->select(c | self.uri_of_DBR_request.URI.endsWith(c.Path))->select(c | c.permissions->exists(a | not (self.sender_app.getSpecificPermInUsesPerms(a.Name).PermissionKind=a.PermissionKind))).notEmpty() then
				                if self.uri_of_DBR_request.receiver_ContentProvider.pathPermissions->select(c | self.uri_of_DBR_request.URI.endsWith(c.Path))->select(c | c.permissions->exists(a |  (self.sender_app.getSpecificPermInUsesPerms(a.Name).PermissionKind=#Normal) and (a.PermissionKind=#Dangerous))).notEmpty() then
						          output->including(': This Bundle has Custom Permission vulnerability in the URI communication with this specification:' + ' '+ '/Sender App:'+ ' ' + self.sender_app.Name + ' /'+ ' ' + '/Sender Component:'+ ' ' + self.uri_of_DBR_request.SenderComponentName + '/' + ' ' + '/Receiver App:'+ ' ' + self.uri_of_DBR_request.receiver_ContentProvider.receiver_app.Name +'/' + ' '+ '/Receiver Content Provider:' + ' '+ self.uri_of_DBR_request.receiver_ContentProvider.Name +'/' + ' ' + ' /' + '/URI:'+ ' ' + self.uri_of_DBR_request.URI + ' /') 
						        else
				                    if self.uri_of_DBR_request.receiver_ContentProvider.pathPermissions->select(c | self.uri_of_DBR_request.URI.endsWith(c.Path))->select(c | c.permissions->exists(a |  (self.sender_app.getSpecificPermInUsesPerms(a.Name).PermissionKind=#Normal) and (a.PermissionKind=#Signature))).notEmpty() then
				                      output->including(': This Bundle has Custom Permission vulnerability in the URI communication with this specification:' + ' '+ '/Sender App:'+ ' ' + self.sender_app.Name + ' /'+ ' ' + '/Sender Component:'+ ' ' + self.uri_of_DBR_request.SenderComponentName + '/' + ' ' + '/Receiver App:'+ ' ' + self.uri_of_DBR_request.receiver_ContentProvider.receiver_app.Name +'/' + ' '+ '/Receiver Content Provider:' + ' '+ self.uri_of_DBR_request.receiver_ContentProvider.Name +'/' + ' ' + ' /' + '/URI:'+ ' ' + self.uri_of_DBR_request.URI + ' /')      
							        else
							 	        if self.uri_of_DBR_request.receiver_ContentProvider.pathPermissions->select(c | self.uri_of_DBR_request.URI.endsWith(c.Path))->select(c | c.permissions->exists(a |  (self.sender_app.getSpecificPermInUsesPerms(a.Name).PermissionKind=#Normal) and (a.PermissionKind=#SignatureOrSystem))).notEmpty() then
				                        output->including(': This Bundle has Custom Permission vulnerability in the URI communication with this specification:' + ' '+ '/Sender App:'+ ' ' + self.sender_app.Name + ' /'+ ' ' + '/Sender Component:'+ ' ' + self.uri_of_DBR_request.SenderComponentName + '/' + ' ' + '/Receiver App:'+ ' ' + self.uri_of_DBR_request.receiver_ContentProvider.receiver_app.Name +'/' + ' '+ '/Receiver Content Provider:' + ' '+ self.uri_of_DBR_request.receiver_ContentProvider.Name +'/' + ' ' + ' /' + '/URI:'+ ' ' + self.uri_of_DBR_request.URI + ' /') 
								        else
								 	        if self.uri_of_DBR_request.receiver_ContentProvider.pathPermissions->select(c | self.uri_of_DBR_request.URI.endsWith(c.Path))->select(c | c.permissions->exists(a |  (self.sender_app.getSpecificPermInUsesPerms(a.Name).PermissionKind=#Dangerous) and (a.PermissionKind=#Signature))).notEmpty() then
				                              output->including(': This Bundle has Custom Permission vulnerability in the URI communication with this specification:' + ' '+ '/Sender App:'+ ' ' + self.sender_app.Name + ' /'+ ' ' + '/Sender Component:'+ ' ' + self.uri_of_DBR_request.SenderComponentName + '/' + ' ' + '/Receiver App:'+ ' ' + self.uri_of_DBR_request.receiver_ContentProvider.receiver_app.Name +'/' + ' '+ '/Receiver Content Provider:' + ' '+ self.uri_of_DBR_request.receiver_ContentProvider.Name +'/' + ' ' + ' /' + '/URI:'+ ' ' + self.uri_of_DBR_request.URI + ' /') 
									        else
									 	        if self.uri_of_DBR_request.receiver_ContentProvider.pathPermissions->select(c | self.uri_of_DBR_request.URI.endsWith(c.Path))->select(c | c.permissions->exists(a |  (self.sender_app.getSpecificPermInUsesPerms(a.Name).PermissionKind=#Dangerous) and (a.PermissionKind=#SignatureOrSystem))).notEmpty() then
				                                 output->including(': This Bundle has Custom Permission vulnerability in the URI communication with this specification:' + ' '+ '/Sender App:'+ ' ' + self.sender_app.Name + ' /'+ ' ' + '/Sender Component:'+ ' ' + self.uri_of_DBR_request.SenderComponentName + '/' + ' ' + '/Receiver App:'+ ' ' + self.uri_of_DBR_request.receiver_ContentProvider.receiver_app.Name +'/' + ' '+ '/Receiver Content Provider:' + ' '+ self.uri_of_DBR_request.receiver_ContentProvider.Name +'/' + ' ' + ' /' + '/URI:'+ ' ' + self.uri_of_DBR_request.URI + ' /')
									            else
									             output->reject(c | c.Name='')
									            endif
									        endif
								        endif
							        endif
						        endif
					        else
						     output->reject(c | c.Name='')
					        endif
				        else
				     	output->reject(c | c.Name='')
				        endif
				    else
				      output->reject(c | c.Name='')
				    endif
			    endif
		    endif
								  
	    else
		  	if self.uri_of_DBR_request.receiver_ContentProvider.URIpermissions->select(c | self.uri_of_DBR_request.URI.endsWith(c.path)).notEmpty() then
			  output->reject(c | c.Name='')
			else
			  output->reject(c | c.Name='')
			endif
	    endif
	else
		output->reject(c | c.Name='')
    endif
else
	output->reject(c | c.Name='')
endif      
)->asSet()->asSequence();


helper context ICCMM!DataManipulationCommunication def:getCustomPermissionVulnerabilityDataManipulationCommunications :Sequence(String) =	
let DataManipulationCommunicationsOfBundle : Sequence(ICCMM!DataManipulationCommunication) = self.refImmediateComposite().dataManipulation_communications in
DataManipulationCommunicationsOfBundle->iterate(n ; output : Sequence(String) = Sequence{} | 
	
if not self.uri_of_DBM_request.receiver_ContentProvider.oclIsUndefined() then
    if not self.uri_of_DBM_request.receiver_ContentProvider.receiver_app.Name.toString().endsWith(self.sender_app.Name.toString()) then
        if not self.uri_of_DBM_request.receiver_ContentProvider.URIpermissions.notEmpty() then
		    if not self.uri_of_DBM_request.receiver_ContentProvider.pathPermissions.notEmpty() then
			    if not self.uri_of_DBM_request.receiver_ContentProvider.permissions.notEmpty() then
			      output->reject(c | c.Name='')
				else
					if self.sender_app.usesPermissions.notEmpty() then
			   	        if self.uri_of_DBM_request.receiver_ContentProvider.permissions->select(c | self.sender_app.checkSpecificPermInUsesPerms(c.Name)).notEmpty() then
					        if self.uri_of_DBM_request.receiver_ContentProvider.permissions->select(c | not (self.sender_app.getSpecificPermInUsesPerms(c.Name).PermissionKind=c.PermissionKind)).notEmpty() then
					            if self.uri_of_DBM_request.receiver_ContentProvider.permissions->select(c | (self.sender_app.getSpecificPermInUsesPerms(c.Name).PermissionKind=#Normal)and (c.PermissionKind=#Dangerous)).notEmpty() then
					             output->including(': This Bundle has Custom Permission vulnerability in the URI communication with this specification:' + ' '+ '/Sender App:'+ ' ' + self.sender_app.Name + ' /'+ ' ' + '/Sender Component:'+ ' ' + self.uri_of_DBM_request.SenderComponentName + '/' + ' ' + '/Receiver App:'+ ' ' + self.uri_of_DBM_request.receiver_ContentProvider.receiver_app.Name +'/' + ' '+ '/Receiver Content Provider:' + ' '+ self.uri_of_DBM_request.receiver_ContentProvider.Name +'/' + ' ' + ' /' + '/URI:'+ ' ' + self.uri_of_DBM_request.URI + ' /') 
						        else
						  	        if self.uri_of_DBM_request.receiver_ContentProvider.permissions->select(c | (self.sender_app.getSpecificPermInUsesPerms(c.Name).PermissionKind=#Normal)and (c.PermissionKind=#Signature)).notEmpty() then
					                output->including(': This Bundle has Custom Permission vulnerability in the URI communication with this specification:' + ' '+ '/Sender App:'+ ' ' + self.sender_app.Name + ' /'+ ' ' + '/Sender Component:'+ ' ' + self.uri_of_DBM_request.SenderComponentName + '/' + ' ' + '/Receiver App:'+ ' ' + self.uri_of_DBM_request.receiver_ContentProvider.receiver_app.Name +'/' + ' '+ '/Receiver Content Provider:' + ' '+ self.uri_of_DBM_request.receiver_ContentProvider.Name +'/' + ' ' + ' /' + '/URI:'+ ' ' + self.uri_of_DBM_request.URI + ' /') 
									else
					                    if self.uri_of_DBM_request.receiver_ContentProvider.permissions->select(c | (self.sender_app.getSpecificPermInUsesPerms(c.Name).PermissionKind=#Normal)and (c.PermissionKind=#SignatureOrSystem)).notEmpty() then
					                    output->including(': This Bundle has Custom Permission vulnerability in the URI communication with this specification:' + ' '+ '/Sender App:'+ ' ' + self.sender_app.Name + ' /'+ ' ' + '/Sender Component:'+ ' ' + self.uri_of_DBM_request.SenderComponentName + '/' + ' ' + '/Receiver App:'+ ' ' + self.uri_of_DBM_request.receiver_ContentProvider.receiver_app.Name +'/' + ' '+ '/Receiver Content Provider:' + ' '+ self.uri_of_DBM_request.receiver_ContentProvider.Name +'/' + ' ' + ' /' + '/URI:'+ ' ' + self.uri_of_DBM_request.URI + ' /') 
										else
								  	        if self.uri_of_DBM_request.receiver_ContentProvider.permissions->select(c | (self.sender_app.getSpecificPermInUsesPerms(c.Name).PermissionKind=#Dangerous)and (c.PermissionKind=#Signature)).notEmpty() then
					                        output->including(': This Bundle has Custom Permission vulnerability in the URI communication with this specification:' + ' '+ '/Sender App:'+ ' ' + self.sender_app.Name + ' /'+ ' ' + '/Sender Component:'+ ' ' + self.uri_of_DBM_request.SenderComponentName + '/' + ' ' + '/Receiver App:'+ ' ' + self.uri_of_DBM_request.receiver_ContentProvider.receiver_app.Name +'/' + ' '+ '/Receiver Content Provider:' + ' '+ self.uri_of_DBM_request.receiver_ContentProvider.Name +'/' + ' ' + ' /' + '/URI:'+ ' ' + self.uri_of_DBM_request.URI + ' /') 
											else
									  	        if self.uri_of_DBM_request.receiver_ContentProvider.permissions->select(c | (self.sender_app.getSpecificPermInUsesPerms(c.Name).PermissionKind=#Dangerous)and (c.PermissionKind=#SignatureOrSystem)).notEmpty() then
					                            output->including(': This Bundle has Custom Permission vulnerability in the URI communication with this specification:' + ' '+ '/Sender App:'+ ' ' + self.sender_app.Name + ' /'+ ' ' + '/Sender Component:'+ ' ' + self.uri_of_DBM_request.SenderComponentName + '/' + ' ' + '/Receiver App:'+ ' ' + self.uri_of_DBM_request.receiver_ContentProvider.receiver_app.Name +'/' + ' '+ '/Receiver Content Provider:' + ' '+ self.uri_of_DBM_request.receiver_ContentProvider.Name +'/' + ' ' + ' /' + '/URI:'+ ' ' + self.uri_of_DBM_request.URI + ' /') 
												else
						                  	     output->reject(c | c.Name='')
										        endif
									        endif
								        endif
							        endif
						        endif
						    else
							output->reject(c | c.Name='')
					        endif
					    else
					  	 output->reject(c | c.Name='')
					     endif
					else
					 output->reject(c | c.Name='')
					endif
				endif
		    else
			    if not self.uri_of_DBM_request.receiver_ContentProvider.pathPermissions->select(c | self.uri_of_DBM_request.URI.endsWith(c.Path)).notEmpty() then
				 output->reject(c | c.Name='')
			    else
				    if self.sender_app.usesPermissions.notEmpty() then
			  	        if self.uri_of_DBM_request.receiver_ContentProvider.pathPermissions->select(c | self.uri_of_DBM_request.URI.endsWith(c.Path))->select(c | c.permissions->exists(a | self.sender_app.checkSpecificPermInUsesPerms(a.Name))).notEmpty() then
				            if self.uri_of_DBM_request.receiver_ContentProvider.pathPermissions->select(c | self.uri_of_DBM_request.URI.endsWith(c.Path))->select(c | c.permissions->exists(a | not (self.sender_app.getSpecificPermInUsesPerms(a.Name).PermissionKind=a.PermissionKind))).notEmpty() then
				                if self.uri_of_DBR_request.receiver_ContentProvider.pathPermissions->select(c | self.uri_of_DBR_request.URI.endsWith(c.Path))->select(c | c.permissions->exists(a |  (self.sender_app.getSpecificPermInUsesPerms(a.Name).PermissionKind=#Normal) and (a.PermissionKind=#Dangerous))).notEmpty() then
						        output->including(': This Bundle has Custom Permission vulnerability in the URI communication with this specification:' + ' '+ '/Sender App:'+ ' ' + self.sender_app.Name + ' /'+ ' ' + '/Sender Component:'+ ' ' + self.uri_of_DBM_request.SenderComponentName + '/' + ' ' + '/Receiver App:'+ ' ' + self.uri_of_DBM_request.receiver_ContentProvider.receiver_app.Name +'/' + ' '+ '/Receiver Content Provider:' + ' '+ self.uri_of_DBM_request.receiver_ContentProvider.Name +'/' + ' ' + ' /' + '/URI:'+ ' ' + self.uri_of_DBM_request.URI + ' /') 
								else
				                    if self.uri_of_DBM_request.receiver_ContentProvider.pathPermissions->select(c | self.uri_of_DBM_request.URI.endsWith(c.Path))->select(c | c.permissions->exists(a |  (self.sender_app.getSpecificPermInUsesPerms(a.Name).PermissionKind=#Normal) and (a.PermissionKind=#Signature))).notEmpty() then
				                    output->including(': This Bundle has Custom Permission vulnerability in the URI communication with this specification:' + ' '+ '/Sender App:'+ ' ' + self.sender_app.Name + ' /'+ ' ' + '/Sender Component:'+ ' ' + self.uri_of_DBM_request.SenderComponentName + '/' + ' ' + '/Receiver App:'+ ' ' + self.uri_of_DBM_request.receiver_ContentProvider.receiver_app.Name +'/' + ' '+ '/Receiver Content Provider:' + ' '+ self.uri_of_DBM_request.receiver_ContentProvider.Name +'/' + ' ' + ' /' + '/URI:'+ ' ' + self.uri_of_DBM_request.URI + ' /') 
									else
							 	        if self.uri_of_DBM_request.receiver_ContentProvider.pathPermissions->select(c | self.uri_of_DBM_request.URI.endsWith(c.Path))->select(c | c.permissions->exists(a |  (self.sender_app.getSpecificPermInUsesPerms(a.Name).PermissionKind=#Normal) and (a.PermissionKind=#SignatureOrSystem))).notEmpty() then
				                        output->including(': This Bundle has Custom Permission vulnerability in the URI communication with this specification:' + ' '+ '/Sender App:'+ ' ' + self.sender_app.Name + ' /'+ ' ' + '/Sender Component:'+ ' ' + self.uri_of_DBM_request.SenderComponentName + '/' + ' ' + '/Receiver App:'+ ' ' + self.uri_of_DBM_request.receiver_ContentProvider.receiver_app.Name +'/' + ' '+ '/Receiver Content Provider:' + ' '+ self.uri_of_DBM_request.receiver_ContentProvider.Name +'/' + ' ' + ' /' + '/URI:'+ ' ' + self.uri_of_DBM_request.URI + ' /') 
										else
								 	        if self.uri_of_DBM_request.receiver_ContentProvider.pathPermissions->select(c | self.uri_of_DBM_request.URI.endsWith(c.Path))->select(c | c.permissions->exists(a |  (self.sender_app.getSpecificPermInUsesPerms(a.Name).PermissionKind=#Dangerous) and (a.PermissionKind=#Signature))).notEmpty() then
				                            output->including(': This Bundle has Custom Permission vulnerability in the URI communication with this specification:' + ' '+ '/Sender App:'+ ' ' + self.sender_app.Name + ' /'+ ' ' + '/Sender Component:'+ ' ' + self.uri_of_DBM_request.SenderComponentName + '/' + ' ' + '/Receiver App:'+ ' ' + self.uri_of_DBM_request.receiver_ContentProvider.receiver_app.Name +'/' + ' '+ '/Receiver Content Provider:' + ' '+ self.uri_of_DBM_request.receiver_ContentProvider.Name +'/' + ' ' + ' /' + '/URI:'+ ' ' + self.uri_of_DBM_request.URI + ' /') 
											else
									 	        if self.uri_of_DBM_request.receiver_ContentProvider.pathPermissions->select(c | self.uri_of_DBM_request.URI.endsWith(c.Path))->select(c | c.permissions->exists(a |  (self.sender_app.getSpecificPermInUsesPerms(a.Name).PermissionKind=#Dangerous) and (a.PermissionKind=#SignatureOrSystem))).notEmpty() then
				                                output->including(': This Bundle has Custom Permission vulnerability in the URI communication with this specification:' + ' '+ '/Sender App:'+ ' ' + self.sender_app.Name + ' /'+ ' ' + '/Sender Component:'+ ' ' + self.uri_of_DBM_request.SenderComponentName + '/' + ' ' + '/Receiver App:'+ ' ' + self.uri_of_DBM_request.receiver_ContentProvider.receiver_app.Name +'/' + ' '+ '/Receiver Content Provider:' + ' '+ self.uri_of_DBM_request.receiver_ContentProvider.Name +'/' + ' ' + ' /' + '/URI:'+ ' ' + self.uri_of_DBM_request.URI + ' /') 
												else
									             output->reject(c | c.Name='')
									            endif
									        endif
								        endif
							        endif
						        endif
					        else
						     output->reject(c | c.Name='')
					        endif
				        else
				     	output->reject(c | c.Name='')
				        endif
				    else
				      output->reject(c | c.Name='')
				    endif
			    endif
		    endif
								  
	    else
		  	if self.uri_of_DBR_request.receiver_ContentProvider.URIpermissions->select(c | self.uri_of_DBR_request.URI.endsWith(c.path)).notEmpty() then
			  output->reject(c | c.Name='')
			else
			  output->reject(c | c.Name='')
			endif
	    endif
	else
		output->reject(c | c.Name='')
    endif
else
	output->reject(c | c.Name='')
endif      
)->asSet()->asSequence();




rule ExplicitCommunications2CustomPermission
 {
	from
	   s:ICCMM!ExplicitCommunication (not s.intent.target_component.oclIsUndefined())
	to
	   t:ANOMM!CustomPermission
	   (             
	 description <-
	 s.getCustomPermissionVulnerabilityExplicitCommunications->iterate(up; output: String = '' | output->concat(up)+'\n')  
	
	  
	 )
	  do {
	t.trace<-Sequence{s};
         }
  }

rule ImplicitCommunications2CustomPermission
 {
	from
	   s:ICCMM!ImplicitTargetComponent
	to
	   t:ANOMM!CustomPermission
	   (             
	 description <- 
	  s.getCustomPermissionVulnerabilityImplicitCommunications->iterate(up; output: String = '' | output->concat(up)+'\n')  
	  
	 )
	  do {
	t.trace<-Sequence{s};
         }
  }


rule DataAccessCommunications2CustomPermission
 {
	from
	   s:ICCMM!DataAccessCommunication (not s.uri_of_DBR_request.receiver_ContentProvider.oclIsUndefined())
	to
	   t:ANOMM!CustomPermission
	   (             
	 description <-
	  s.getCustomPermissionVulnerabilityDataAccessCommunications->iterate(up; output: String = '' | output->concat(up)+'\n')  
	  
	 )
	  do {
	t.trace<-Sequence{s};
         }
  }

rule DataManipulationCommunications2CustomPermission
 {
	from
	   s:ICCMM!DataManipulationCommunication (not s.uri_of_DBM_request.receiver_ContentProvider.oclIsUndefined())
	  
	to
	   t:ANOMM!CustomPermission
	   (
	                 
	 description <- s.getCustomPermissionVulnerabilityDataManipulationCommunications->iterate(up; output: String = '' | output->concat(up)+'\n')      
	   )
	  do {
	t.trace<-Sequence{s};
         }
  }
