Java Code Examples for soot.jimple.ArrayRef#getIndex()

The following examples show how to use soot.jimple.ArrayRef#getIndex() . 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: SmartConstantDataExtractorFuzzyAnalysis.java    From FuzzDroid with Apache License 2.0 6 votes vote down vote up
private boolean hasConstantIndexAtArrayForSplitDataFlow(Stmt[] dataflow) {
	Stmt firstAssign = dataflow[0];
	if(firstAssign instanceof AssignStmt) {
		AssignStmt ass = (AssignStmt)firstAssign;
		Value value = ass.getRightOp();
		if(value instanceof ArrayRef) {
			ArrayRef aRef = (ArrayRef)value;
			Value index = aRef.getIndex();
			
			if(index instanceof IntConstant)
				return true;
		}
	}
	else
		throw new RuntimeException("this should not happen - wrong assumption");
	
	return false;
}
 
Example 2
Source File: SmartConstantDataExtractorFuzzyAnalysis.java    From FuzzDroid with Apache License 2.0 6 votes vote down vote up
private int getConstantArrayIndexForSplitDataFlow(Stmt[] dataflow) {
	Stmt firstAssign = dataflow[0];
	if(firstAssign instanceof AssignStmt) {
		AssignStmt ass = (AssignStmt)firstAssign;
		Value value = ass.getRightOp();
		if(value instanceof ArrayRef) {
			ArrayRef aRef = (ArrayRef)value;
			Value index = aRef.getIndex();
			
			if(index instanceof IntConstant)
				return ((IntConstant) index).value;
		}
	}
	else
		throw new RuntimeException("this should not happen - wrong assumption");
	
	return -1;
}
 
Example 3
Source File: ValueTemplatePrinter.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
public void caseArrayRef(ArrayRef v) {
	String oldName = varName;
	
	Value base = v.getBase();
	suggestVariableName("base");
	String baseName = varName;
	base.apply(this);
	
	Value index = v.getIndex();
	suggestVariableName("index");
	String indexName = varName;
	index.apply(this);
	
	p.println("Value "+oldName+" = Jimple.v().newArrayRef("+baseName+", "+indexName+");");
	varName = oldName;
}
 
Example 4
Source File: JimpleExprVisitorImpl.java    From FuzzDroid with Apache License 2.0 5 votes vote down vote up
private int findMaxIndexOfArray(InvokeExpr invokeExpr) {
	Value array = null;
	int maxIndex = -1;
	for(Stmt stmt : stmtVisitor.getJimpleDataFlowStatements()) {
		if(stmt instanceof AssignStmt) {
			AssignStmt assign = (AssignStmt)stmt;
			if(array == null) {
				if(assign.getRightOp().equals(invokeExpr)) {
					array = assign.getLeftOp();
				}
			}
			else{
				Value rhs = assign.getRightOp();
				if(rhs instanceof ArrayRef) {
					ArrayRef arrayRef = (ArrayRef)rhs;
					if(arrayRef.getBase().equals(array)) {
						Value index = arrayRef.getIndex();
						if(index instanceof IntConstant) {
							IntConstant constant = (IntConstant)index;
							maxIndex = constant.value;
						}
					}
				}
			}
		}
	}
	return maxIndex;
}
 
Example 5
Source File: StmtVisitor.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
private Insn buildArrayPutInsn(ArrayRef destRef, Value source) {
	Value array = destRef.getBase();
	Register arrayReg = regAlloc.asLocal(array);
	Value index = destRef.getIndex();
	Register indexReg = regAlloc.asImmediate(index, constantV);
	Register sourceReg  = regAlloc.asImmediate(source, constantV);
	String arrayTypeDescriptor = SootToDexUtils.getArrayTypeDescriptor((ArrayType) array.getType());
	Opcode opc = getPutGetOpcodeWithTypeSuffix("aput", arrayTypeDescriptor);
	return new Insn23x(opc, sourceReg, arrayReg, indexReg);
}
 
Example 6
Source File: StmtVisitor.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
private Insn buildArrayGetInsn(Register destinationReg, ArrayRef sourceRef) {
	Value index = sourceRef.getIndex();
	Register indexReg = regAlloc.asImmediate(index, constantV);
	Value array = sourceRef.getBase();
	Register arrayReg = regAlloc.asLocal(array);
	String arrayTypeDescriptor = SootToDexUtils.getArrayTypeDescriptor((ArrayType) array.getType());
	Opcode opc = getPutGetOpcodeWithTypeSuffix("aget", arrayTypeDescriptor);
	return new Insn23x(opc, destinationReg, arrayReg, indexReg);
}
 
Example 7
Source File: ShortcutArrayInit.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public boolean isInSequenceAssignment(Stmt s, Value leftOp, int index){
	//DEBUG=false;
	if(!(s instanceof DefinitionStmt))
		return false;
	
	DefinitionStmt ds = (DefinitionStmt)s;
	Value leftValue = ds.getLeftOp();
	if(! (leftValue instanceof ArrayRef))
		return false;
	
	if(DEBUG){
		System.out.println("Stmt number "+index + " is an array ref assignment"+leftValue);
		System.out.println("Array is"+leftOp);
	}

	ArrayRef leftRef = (ArrayRef)leftValue;
	if(! (leftOp.equals(leftRef.getBase()))){
		if(DEBUG)
			System.out.println("Not assigning to same array");
		return false;
	}
		
	if( ! (leftRef.getIndex() instanceof IntConstant)){
		if(DEBUG)
			System.out.println("Cant determine index of assignment");
		return false;
	}
	
	IntConstant leftIndex = (IntConstant)leftRef.getIndex();
	if(leftIndex.value != index){
		if(DEBUG)
			System.out.println("Out of order assignment");
		return false;
	}
	
	return true;
}
 
Example 8
Source File: ShortcutArrayInit.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public boolean isInSequenceAssignmentPatternTwo(Stmt one, Stmt two, Value leftOp, int index){
	if(!(two instanceof DefinitionStmt))
		return false;
	
	DefinitionStmt ds = (DefinitionStmt)two;
	Value leftValue = ds.getLeftOp();
	if(! (leftValue instanceof ArrayRef))
		return false;
	
	ArrayRef leftRef = (ArrayRef)leftValue;
	if(! (leftOp.equals(leftRef.getBase()))){
		if(DEBUG)
			System.out.println("Not assigning to same array");
		return false;
	}
		
	if( ! (leftRef.getIndex() instanceof IntConstant)){
		if(DEBUG)
			System.out.println("Cant determine index of assignment");
		return false;
	}
	
	IntConstant leftIndex = (IntConstant)leftRef.getIndex();
	if(leftIndex.value != index){
		if(DEBUG)
			System.out.println("Out of order assignment");
		return false;
	}

	Value rightOp = ds.getRightOp();
	
	if(!(one instanceof DShortcutAssignStmt))
		return false;
	
	DShortcutAssignStmt shortcut = (DShortcutAssignStmt)one;
	Value shortcutVar = shortcut.getLeftOp();
	if(!shortcutVar.equals(rightOp))
		return false;

	return true;
}