Java Code Examples for soot.jimple.infoflow.android.axml.AXmlNode#getChildren()

The following examples show how to use soot.jimple.infoflow.android.axml.AXmlNode#getChildren() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UtilApk.java    From FuzzDroid with Apache License 2.0 7 votes vote down vote up
@SuppressWarnings("unchecked")
private static void addMaxPrioForSMSReceiver(ProcessManifest manifest) {
	for(AXmlNode receiver : manifest.getReceivers()) {
		for(AXmlNode receiverChild : receiver.getChildren()) {
			if(receiverChild.getTag().equals("intent-filter")) {
				//search for SMS receiver
				for(AXmlNode childChild : receiverChild.getChildren()) {
					if(childChild.getTag().equals("action")) {
						if(childChild.hasAttribute("name") && ((String)childChild.getAttribute("name").getValue()).equalsIgnoreCase("android.provider.Telephony.SMS_RECEIVED")){
							//prepare the priority filter
							if(receiverChild.hasAttribute("priority")) 
								((AXmlAttribute<Integer>)receiverChild.getAttribute("priority")).setValue(Integer.MAX_VALUE);
							else {
								AXmlAttribute<Integer> attr = new AXmlAttribute<Integer>("priority", Integer.MAX_VALUE, ANDROID_NAMESPACE);
								receiverChild.addAttribute(attr);
							}
						}
					}
				}
			}
		}
	}
}
 
Example 2
Source File: ProcessManifest.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns all activity nodes that are "launchable", i.e. that are called when the user 
 * clicks on the button in the launcher.
 * @return
 */
public Set<AXmlNode> getLaunchableActivities() {
	Set<AXmlNode> allLaunchableActivities = new HashSet<AXmlNode>();
	
	for(AXmlNode activity : activities) {
		for(AXmlNode activityChildren : activity.getChildren()) {
			if(activityChildren.getTag().equals("intent-filter")) {
				boolean actionFilter = false;
				boolean categoryFilter = false;
				for(AXmlNode intentFilter : activityChildren.getChildren()) {
					if(intentFilter.toString().equals("<action name=\"android.intent.action.MAIN\">"))
						actionFilter = true;
					else if(intentFilter.toString().equals("<category name=\"android.intent.category.LAUNCHER\">"))
						categoryFilter = true;
				}
				
				if(actionFilter && categoryFilter)
					allLaunchableActivities.add(activity);
			}
		}
		
	}
	
	return allLaunchableActivities;
}
 
Example 3
Source File: ProcessManifest.java    From DroidRA with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns all activity nodes that are "launchable", i.e. that are called when the user 
 * clicks on the button in the launcher.
 * @return
 */
public Set<AXmlNode> getLaunchableActivities() {
	Set<AXmlNode> allLaunchableActivities = new HashSet<AXmlNode>();
	
	for(AXmlNode activity : activities) {
		for(AXmlNode activityChildren : activity.getChildren()) {
			if(activityChildren.getTag().equals("intent-filter")) {
				boolean actionFilter = false;
				boolean categoryFilter = false;
				for(AXmlNode intentFilter : activityChildren.getChildren()) {
					if(intentFilter.toString().equals("<action name=\"android.intent.action.MAIN\">"))
						actionFilter = true;
					else if(intentFilter.toString().equals("<category name=\"android.intent.category.LAUNCHER\">"))
						categoryFilter = true;
				}
				
				if(actionFilter && categoryFilter)
					allLaunchableActivities.add(activity);
			}
		}
		
	}
	
	return allLaunchableActivities;
}
 
Example 4
Source File: LayoutFileParser.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Parses the layout file with the given root node
 * @param layoutFile The full path and file name of the file being parsed
 * @param rootNode The root node from where to start parsing
 */
private void parseLayoutNode(String layoutFile, AXmlNode rootNode) {
	if (rootNode.getTag() == null || rootNode.getTag().isEmpty()) {
		System.err.println("Encountered a null or empty node name "
				+ "in file " + layoutFile + ", skipping node...");
		return;
	}
	
	String tname = rootNode.getTag().trim();
	if (tname.equals("dummy")) {
		// dummy root node, ignore it
	}
	// Check for inclusions
	else if (tname.equals("include")) {
		parseIncludeAttributes(layoutFile, rootNode);
	}
	// The "merge" tag merges the next hierarchy level into the current
	// one for flattening hierarchies.
	else if (tname.equals("merge"))  {
		// do not consider any attributes of this elements, just
		// continue with the children
	}
	else if (tname.equals("fragment"))  {
		final AXmlAttribute<?> attr = rootNode.getAttribute("name");
		if (attr == null)
			System.err.println("Fragment without class name detected");
		else {
			if (attr.getType() != AxmlVisitor.TYPE_STRING)
				System.err.println("Invalid targer resource "+attr.getValue()+"for fragment class value");
			getLayoutClass(attr.getValue().toString());
		}
	}
	else {
		final SootClass childClass = getLayoutClass(tname);
		if (childClass != null && (isLayoutClass(childClass) || isViewClass(childClass)))
			parseLayoutAttributes(layoutFile, childClass, rootNode);
	}

	// Parse the child nodes
	for (AXmlNode childNode : rootNode.getChildren())
		parseLayoutNode(layoutFile, childNode);
}
 
Example 5
Source File: UpdateManifestAndCodeForWaitPDP.java    From DroidForce with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Get the name of the main activity in the AndroidManifest.xml file
 * @param apkFileLocation
 * @return
 */
public static String getMainActivityName(String apkFileLocation) {
	String mainActivityName = null;
	try {
		ProcessManifest pm = new ProcessManifest(apkFileLocation);
		AXmlHandler axmlh = pm.getAXml(); 
		
		// Find main activity and remove main intent-filter
		List<AXmlNode> anodes = axmlh.getNodesWithTag("activity");
		for (AXmlNode an: anodes) {
			boolean hasMain = false;
			boolean hasLauncher = false;
			AXmlNode filter = null;
			
			AXmlAttribute aname = an.getAttribute("name");
			String aval = (String)aname.getValue();
			System.out.println("activity: "+ aval);
			for (AXmlNode ch : an.getChildren()) {
				System.out.println("children: "+ ch);
			}
			List<AXmlNode> fnodes = an.getChildrenWithTag("intent-filter");
			for (AXmlNode fn: fnodes) {
				
				hasMain = false;
				hasLauncher = false;
				
				// check action
				List<AXmlNode> acnodes = fn.getChildrenWithTag("action");
				for (AXmlNode acn: acnodes) {
					AXmlAttribute acname = acn.getAttribute("name");
					String acval = (String)acname.getValue();
					System.out.println("action: "+ acval);
					if (acval.equals("android.intent.action.MAIN")) {
						hasMain = true;
					}
				}
				// check category
				List<AXmlNode> catnodes = fn.getChildrenWithTag("category");
				for (AXmlNode catn: catnodes) {
					AXmlAttribute catname = catn.getAttribute("name");
					String catval = (String)catname.getValue();
					System.out.println("category: "+ catval);
					if (catval.equals("android.intent.category.LAUNCHER")) {
						hasLauncher = true;
						filter = fn;
					}
				}
				if (hasLauncher && hasMain) {
					break;
				}
			}
			
			if (hasLauncher && hasMain) {
				// replace name with the activity waiting for the connection to the PDP
				System.out.println("main activity is: "+ aval);
				System.out.println("excluding filter: "+ filter);
				filter.exclude();
				mainActivityName = aval;
				break;
			}
			
		}
	} catch (IOException | XmlPullParserException ex) {
		System.err.println("Could not read Android manifest file: " + ex.getMessage());
		throw new RuntimeException(ex);
	}

	return mainActivityName;
}