Java Code Examples for soot.jimple.infoflow.android.data.AndroidMethod#setSource()

The following examples show how to use soot.jimple.infoflow.android.data.AndroidMethod#setSource() . 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: CategorizedAndroidSourceSinkParser.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public Set<AndroidMethod> parse() throws IOException {
	Set<AndroidMethod> methods = new HashSet<AndroidMethod>();
	
	BufferedReader rdr = readFile();
	if (rdr == null)
		throw new RuntimeException("Could not read source/sink file");
	
	String line = null;
	Pattern p = Pattern.compile(regex);
	
	while ((line = rdr.readLine()) != null) {
		Matcher m = p.matcher(line);
		if(m.find()) {
			CATEGORY cat = CATEGORY.valueOf(m.group(5));
			
			if(categories.contains(CATEGORY.ALL) || categories.contains(cat)){
				AndroidMethod method = parseMethod(m);
				method.setCategory(cat);
				
				if(isSources)
					method.setSource(true);
				else if(isSinks)
					method.setSink(true);
				else
					throw new RuntimeException("Oops, something went all wonky!");
				
				methods.add(method);
			}
		}
	}
	
	try {
		if (rdr != null)
			rdr.close();
	} catch (IOException e) {
		e.printStackTrace();
	}
	
	return methods;
}
 
Example 2
Source File: XMLSourceSinkParser.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
/**
	 * EventHandler for the End of an element. -> Putting the values into the objects. For additional information:
	 * startElement description. Starting with the innerst elements and switching up to the outer elements
	 * 
	 * - pathElement -> means field sensitive, adding SootFields
	 */
	@Override
	public void endElement(String uri, String localName, String qName) throws SAXException {
		String qNameLower = qName.toLowerCase();
		switch (qNameLower) {
		
		// Create the new method based on the data we have collected so far
		case XMLConstants.METHOD_TAG:
			if (methodSignature == null)
				break;
			
			AndroidMethod tempMeth = AndroidMethod.createFromSignature(methodSignature);			
			if (methodCategory != null) {
				String methodCategoryUpper = methodCategory.toUpperCase().trim();
				tempMeth.setCategory(CATEGORY.valueOf(methodCategoryUpper));
			}
			tempMeth.setSink(isSink);
			tempMeth.setSource(isSource);
			
			@SuppressWarnings("unchecked")
			SourceSinkDefinition ssd = new SourceSinkDefinition(tempMeth,
					baseAPs, paramAPs.toArray(new Set[paramAPs.size()]), returnAPs);
			if (sourcesAndSinks.containsKey(tempMeth))
				sourcesAndSinks.get(tempMeth).merge(ssd);
			else
				sourcesAndSinks.put(tempMeth, ssd);
			
			// Start a new method and discard our old data
			methodSignature = null;
			methodCategory = null;
			baseAPs = new HashSet<>();
			paramAPs = new ArrayList<>();
			returnAPs = new HashSet<>();
			break;
		
		case XMLConstants.ACCESSPATH_TAG:
			// Record the access path for the current element
			if (isSource || isSink) {
				// Clean up the path elements
				if (pathElements != null
						&& pathElements.length == 0
						&& pathElementTypes != null
						&& pathElementTypes.length == 0) {
					pathElements = null;
					pathElementTypes = null;
				}
				
				AccessPathTuple apt = AccessPathTuple.fromPathElements(
						pathElements, pathElementTypes, isSource, isSink);
				switch (accessPathParentElement) {
					case XMLConstants.BASE_TAG:
						baseAPs.add(apt);
						break;
					case XMLConstants.RETURN_TAG:
						returnAPs.add(apt);
						break;
					case XMLConstants.PARAM_TAG:
						while (paramAPs.size() <= paramIndex)
							paramAPs.add(new HashSet<AccessPathTuple>());
						paramAPs.get(paramIndex).add(apt);
				}
			}
			
			isSource = false;
			isSink = false;
			pathElements = null;
			pathElementTypes = null;
			break;
			
		case XMLConstants.BASE_TAG:
			accessPathParentElement = "";
//			baseType = "";
			break;
			
		case XMLConstants.RETURN_TAG:
			accessPathParentElement = "";
//			returnType = "";
			break;
			
		case XMLConstants.PARAM_TAG:
			accessPathParentElement = "";
			paramIndex = -1;
			paramTypes.clear();
//			paramType = "";
			break;
			
		case XMLConstants.PATHELEMENT_TAG:
			break;
		}
	}