Java Code Examples for soot.jimple.infoflow.android.axml.AXmlAttribute#getValue()

The following examples show how to use soot.jimple.infoflow.android.axml.AXmlAttribute#getValue() . 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: LayoutFileParser.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Parses the attributes required for a layout file inclusion
 * @param layoutFile The full path and file name of the file being parsed
 * @param rootNode The AXml node containing the attributes
 */
private void parseIncludeAttributes(String layoutFile, AXmlNode rootNode) {
	for (Entry<String, AXmlAttribute<?>> entry : rootNode.getAttributes().entrySet()) {
		String attrName = entry.getKey().trim();
		AXmlAttribute<?> attr = entry.getValue();
		
   		if (attrName.equals("layout")) {
   			if ((attr.getType() == AxmlVisitor.TYPE_REFERENCE || attr.getType() == AxmlVisitor.TYPE_INT_HEX)
   					&& attr.getValue() instanceof Integer) {
   				// We need to get the target XML file from the binary manifest
   				AbstractResource targetRes = resParser.findResource((Integer) attr.getValue());
   				if (targetRes == null) {
   					System.err.println("Target resource " + attr.getValue() + " for layout include not found");
   					return;
   				}
   				if (!(targetRes instanceof StringResource)) {
   					System.err.println("Invalid target node for include tag in layout XML, was "
   							+ targetRes.getClass().getName());
   					return;
   				}
   				String targetFile = ((StringResource) targetRes).getValue();
   				
   				// If we have already processed the target file, we can
   				// simply copy the callbacks we have found there
       			if (callbackMethods.containsKey(targetFile))
       				for (String callback : callbackMethods.get(targetFile))
       					addCallbackMethod(layoutFile, callback);
       			else {
       				// We need to record a dependency to resolve later
       				addToMapSet(includeDependencies, targetFile, layoutFile);
       			}
   			}
   		}
	}
}
 
Example 2
Source File: ProcessManifest.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public String getPackageName() {
	if (cache_PackageName == null) {
		AXmlAttribute<?> attr = this.manifest.getAttribute("package");
		if (attr != null)
			cache_PackageName = (String) attr.getValue();
	}
	return cache_PackageName;
}
 
Example 3
Source File: ProcessManifest.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the minimum SDK version on which this application is supposed to run
 * @return The minimum SDK version on which this application is supposed to run
 */
public int getMinSdkVersion() {
	List<AXmlNode> usesSdk = this.manifest.getChildrenWithTag("uses-sdk");
	if (usesSdk == null || usesSdk.isEmpty())
		return -1;
	AXmlAttribute<?> attr = usesSdk.get(0).getAttribute("minSdkVersion");
	
	if (attr == null)
		return -1;
	
	if (attr.getValue() instanceof Integer)
		return (Integer) attr.getValue();
	
	return Integer.getInteger((String) attr.getValue());		
}
 
Example 4
Source File: ProcessManifest.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the target SDK version for which this application was developed
 * @return The target SDK version for which this application was developed
 */
public int targetSdkVersion() {
	List<AXmlNode> usesSdk = this.manifest.getChildrenWithTag("uses-sdk");
	if (usesSdk == null || usesSdk.isEmpty())
		return -1;
	AXmlAttribute<?> attr = usesSdk.get(0).getAttribute("targetSdkVersion");

	if (attr == null)
		return -1;
	
	if (attr.getValue() instanceof Integer)
		return (Integer) attr.getValue();
	
	return Integer.getInteger((String) attr.getValue());		
}
 
Example 5
Source File: ProcessManifest.java    From DroidRA with GNU Lesser General Public License v2.1 5 votes vote down vote up
public String getPackageName() {
	if (cache_PackageName == null) {
		AXmlAttribute<?> attr = this.manifest.getAttribute("package");
		if (attr != null)
			cache_PackageName = (String) attr.getValue();
	}
	return cache_PackageName;
}
 
Example 6
Source File: ProcessManifest.java    From DroidRA with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Gets the minimum SDK version on which this application is supposed to run
 * @return The minimum SDK version on which this application is supposed to run
 */
public int getMinSdkVersion() {
	List<AXmlNode> usesSdk = this.manifest.getChildrenWithTag("uses-sdk");
	if (usesSdk == null || usesSdk.isEmpty())
		return -1;
	AXmlAttribute<?> attr = usesSdk.get(0).getAttribute("minSdkVersion");
	
	if (attr == null)
		return -1;
	
	if (attr.getValue() instanceof Integer)
		return (Integer) attr.getValue();
	
	return Integer.parseInt("" + attr.getValue());		
}
 
Example 7
Source File: ProcessManifest.java    From DroidRA with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Gets the target SDK version for which this application was developed
 * @return The target SDK version for which this application was developed
 */
public int targetSdkVersion() {
	List<AXmlNode> usesSdk = this.manifest.getChildrenWithTag("uses-sdk");
	if (usesSdk == null || usesSdk.isEmpty())
		return -1;
	AXmlAttribute<?> attr = usesSdk.get(0).getAttribute("targetSdkVersion");

	if (attr == null)
		return -1;
	
	if (attr.getValue() instanceof Integer)
		return (Integer) attr.getValue();
	
	return Integer.parseInt("" + attr.getValue());		
}
 
Example 8
Source File: UpdateManifestAndCodeForWaitPDP.java    From DroidForce with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Get the package name of the application
 * @param apkFileLocation
 * @return
 */
public static String getApplicationPackageName(String apkFileLocation) {
	String packageName = null;
	try {
		ProcessManifest pm = new ProcessManifest(apkFileLocation);
		AXmlHandler axmlh = pm.getAXml(); 
		
		// Find main activity and remove main intent-filter
		List<AXmlNode> anodes = axmlh.getNodesWithTag("manifest");
		for (AXmlNode an: anodes) {
			boolean hasMain = false;
			boolean hasLauncher = false;
			AXmlNode filter = null;
			
			AXmlAttribute aname = an.getAttribute("package");
			String aval = (String)aname.getValue();
			packageName = aval;
			System.out.println("package: "+ packageName);
			break;
			
		}
	} catch (IOException | XmlPullParserException ex) {
		System.err.println("Could not read Android manifest file: " + ex.getMessage());
		throw new RuntimeException(ex);
	}

	return packageName;
}
 
Example 9
Source File: LayoutFileParser.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Parses the layout attributes in the given AXml node 
 * @param layoutFile The full path and file name of the file being parsed
 * @param layoutClass The class for the attributes are parsed
 * @param rootNode The AXml node containing the attributes
 */
private void parseLayoutAttributes(String layoutFile, SootClass layoutClass, AXmlNode rootNode) {
	boolean isSensitive = false;
	int id = -1;
	
	for (Entry<String, AXmlAttribute<?>> entry : rootNode.getAttributes().entrySet()) {
		String attrName = entry.getKey().trim();
		AXmlAttribute<?> attr = entry.getValue();
		
		// On obfuscated Android malware, the attribute name may be empty
		if (attrName.isEmpty())
			continue;
		
		// Check that we're actually working on an android attribute
		if (!isAndroidNamespace(attr.getNamespace()))
			continue;
		
		// Read out the field data
		if (attrName.equals("id")
				&& (attr.getType() == AxmlVisitor.TYPE_REFERENCE || attr.getType() == AxmlVisitor.TYPE_INT_HEX))
			id = (Integer) attr.getValue();
		else if (attrName.equals("password")) {
			if (attr.getType() == AxmlVisitor.TYPE_INT_HEX)
				isSensitive = ((Integer) attr.getValue()) != 0; // -1 for true, 0 for false
			else if (attr.getType() == AxmlVisitor.TYPE_INT_BOOLEAN)
				isSensitive = (Boolean) attr.getValue();
			else
				throw new RuntimeException("Unknown representation of boolean data type");
		}
		else if (!isSensitive && attrName.equals("inputType") && attr.getType() == AxmlVisitor.TYPE_INT_HEX) {
			int tp = (Integer) attr.getValue();
			isSensitive = ((tp & TYPE_NUMBER_VARIATION_PASSWORD) == TYPE_NUMBER_VARIATION_PASSWORD)
					|| ((tp & TYPE_TEXT_VARIATION_PASSWORD) == TYPE_TEXT_VARIATION_PASSWORD)
					|| ((tp & TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) == TYPE_TEXT_VARIATION_VISIBLE_PASSWORD)
					|| ((tp & TYPE_TEXT_VARIATION_WEB_PASSWORD) == TYPE_TEXT_VARIATION_WEB_PASSWORD);
		}
		else if (isActionListener(attrName)
				&& attr.getType() == AxmlVisitor.TYPE_STRING
				&& attr.getValue() instanceof String) {
			String strData = ((String) attr.getValue()).trim();
			addCallbackMethod(layoutFile, strData);
		}
		else if (attr.getType() == AxmlVisitor.TYPE_STRING && attrName.equals("text")) {
			// To avoid unrecognized attribute for "text" field
		}
		else if (DEBUG && attr.getType() == AxmlVisitor.TYPE_STRING) {
			System.out.println("Found unrecognized XML attribute:  " + attrName);
		}
	}
	
	// Register the new user control
	addToMapSet(this.userControls, layoutFile, new LayoutControl(id, layoutClass, isSensitive));
}
 
Example 10
Source File: ProcessManifest.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Gets the application's version name as it is displayed to the user
 * @return The application#s version name as in pretty print
 */
public String getVersionName() {
	AXmlAttribute<?> attr = this.manifest.getAttribute("versionName");
	return attr == null ? null : (String) attr.getValue();
}
 
Example 11
Source File: ProcessManifest.java    From DroidRA with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Gets the application's version name as it is displayed to the user
 * @return The application#s version name as in pretty print
 */
public String getVersionName() {
	AXmlAttribute<?> attr = this.manifest.getAttribute("versionName");
	return attr == null ? null : (String) attr.getValue();
}
 
Example 12
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;
}