soot.jimple.Jimple Java Examples

The following examples show how to use soot.jimple.Jimple. 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: DummyMainGenerator.java    From DroidRA with GNU Lesser General Public License v2.1 6 votes vote down vote up
public SootMethod generateFuzzyMethod(SootClass sootClass)
{
   	String name = "fuzzyMe";
    List<Type> parameters = new ArrayList<Type>();
    Type returnType = IntType.v();
    int modifiers = Modifier.PUBLIC;
    SootMethod fuzzyMeMethod = new SootMethod(name, parameters, returnType, modifiers);
    sootClass.addMethod(fuzzyMeMethod);
    
    {
    	Body b = Jimple.v().newBody(fuzzyMeMethod);
    	fuzzyMeMethod.setActiveBody(b);
    	LocalGenerator lg = new LocalGenerator(b);
        Local thisLocal = lg.generateLocal(sootClass.getType());
        Unit thisU = Jimple.v().newIdentityStmt(thisLocal, 
                Jimple.v().newThisRef(sootClass.getType()));
        Unit returnU = Jimple.v().newReturnStmt(IntConstant.v(1));
        b.getUnits().add(thisU);
        b.getUnits().add(returnU);
    }
        
    return fuzzyMeMethod;
}
 
Example #2
Source File: InstanceOfInstruction.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
public void jimplify (DexBody body) {
      Instruction22c i = (Instruction22c)instruction;
      int dest = i.getRegisterA();
      int source = i.getRegisterB();

      Type t = DexType.toSoot((TypeReference)(i.getReference()));

      InstanceOfExpr e = Jimple.v().newInstanceOfExpr(body.getRegisterLocal(source), t);
      assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), e);
      setUnit(assign);
      addTags(assign);
      body.add(assign);

if (IDalvikTyper.ENABLE_DVKTYPER) {
	Debug.printDbg(IDalvikTyper.DEBUG, "constraint: "+ assign);
        int op = (int)instruction.getOpcode().value;
        //DalvikTyper.v().?
      }
  }
 
Example #3
Source File: CastInstruction.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
public void jimplify (DexBody body) {
     TwoRegisterInstruction i = (TwoRegisterInstruction)instruction;
     int dest = i.getRegisterA();
     int source = i.getRegisterB();
     Type targetType = getTargetType();
     CastExpr cast = Jimple.v().newCastExpr(body.getRegisterLocal(source), targetType);
     assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), cast);
     assign.addTag (getTag());
     setUnit(assign);
     addTags(assign);
     body.add(assign);
     
     if (IDalvikTyper.ENABLE_DVKTYPER) {
Debug.printDbg(IDalvikTyper.DEBUG, "constraint cast: "+ assign +" castexpr type: "+ cast.getType()+" cast type: "+ cast.getCastType());
       int op = (int)instruction.getOpcode().value;
       DalvikTyper.v().setType(assign.getLeftOpBox(), cast.getType(), false);
       //DalvikTyper.v().captureAssign((JAssignStmt)assign, op);
     }
 }
 
Example #4
Source File: BDynamicInvokeInst.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
public void toString(UnitPrinter up)
{
    up.literal(Jimple.DYNAMICINVOKE);        
    up.literal(" \"" + methodRef.name() + "\" <" + SootMethod.getSubSignature(""/* no method name here*/, methodRef.parameterTypes(), methodRef.returnType()) +"> ");        
    up.methodRef(bsmRef);
    up.literal("(");
    
    for(int i = 0; i < bsmArgs.size(); i++)
    {
        if(i != 0)
            up.literal(", ");
            
        bsmArgs.get(i).toString(up);
    }

    up.literal(")");
}
 
Example #5
Source File: BDynamicInvokeInst.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
public String toString()
{
    StringBuffer buffer = new StringBuffer();

    buffer.append(Jimple.DYNAMICINVOKE);
    buffer.append(" \"");
    buffer.append(methodRef.name()); //quoted method name (can be any UTF8 string)
    buffer.append("\" <");
    buffer.append(SootMethod.getSubSignature(""/* no method name here*/, methodRef.parameterTypes(), methodRef.returnType()));
    buffer.append(">");
    buffer.append(bsmRef.getSignature());
    buffer.append("(");
    for(int i = 0; i < bsmArgs.size(); i++)
    {
        if(i != 0)
            buffer.append(", ");

        buffer.append(bsmArgs.get(i).toString());
    }
    buffer.append(")");

    return buffer.toString();
}
 
Example #6
Source File: UnitThrowAnalysisTest.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testJEnterMonitorStmt() {
    Stmt s = Jimple.v().newEnterMonitorStmt(StringConstant.v("test"));

    Set expectedRep = new ExceptionHashSet(utility.VM_ERRORS);
    Set expectedCatch = new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES);
    expectedRep.add(utility.NULL_POINTER_EXCEPTION);
    assertTrue(ExceptionTestUtility.sameMembers(expectedRep, Collections.EMPTY_SET,
                unitAnalysis.mightThrow(s)));

    expectedCatch.add(utility.NULL_POINTER_EXCEPTION);
    expectedCatch.add(utility.RUNTIME_EXCEPTION);
    expectedCatch.add(utility.EXCEPTION);
    assertEquals(expectedCatch,
            utility.catchableSubset(unitAnalysis.mightThrow(s)));
}
 
Example #7
Source File: BaseEntryPointCreator.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Constructs an array of the given type with a single element of this type
 * in the given method
 * @param body The body of the method in which to create the array
 * @param gen The local generator
 * @param tp The type of which to create the array
 * @param constructionStack Set of classes currently being built to avoid
 * constructor loops
 * @param parentClasses If a requested type is compatible with one of the
 * types in this list, the already-created object is used instead of
 * creating a new one.
 * @return The local referencing the newly created array, or null if the
 * array generation failed
 */
private Value buildArrayOfType(Body body, LocalGenerator gen, ArrayType tp,
		Set<SootClass> constructionStack, Set<SootClass> parentClasses) {
	Local local = gen.generateLocal(tp);

	// Generate a new single-element array
	NewArrayExpr newArrayExpr = Jimple.v().newNewArrayExpr(tp.getElementType(),
			IntConstant.v(1));
	AssignStmt assignArray = Jimple.v().newAssignStmt(local, newArrayExpr);
	body.getUnits().add(assignArray);
	
	// Generate a single element in the array
	AssignStmt assign = Jimple.v().newAssignStmt
			(Jimple.v().newArrayRef(local, IntConstant.v(0)),
			getValueForType(body, gen, tp.getElementType(), constructionStack, parentClasses));
	body.getUnits().add(assign);
	return local;
}
 
Example #8
Source File: ICCInstrumentDestination.java    From soot-infoflow-android-iccta with GNU Lesser General Public License v2.1 6 votes vote down vote up
public SootMethod generateFuzzyMethod(SootClass sootClass)
{
   	String name = "fuzzyMe";
    List<Type> parameters = new ArrayList<Type>();
    Type returnType = IntType.v();
    int modifiers = Modifier.PUBLIC;
    SootMethod fuzzyMeMethod = new SootMethod(name, parameters, returnType, modifiers);
    sootClass.addMethod(fuzzyMeMethod);
    
    {
    	Body b = Jimple.v().newBody(fuzzyMeMethod);
    	fuzzyMeMethod.setActiveBody(b);
    	LocalGenerator lg = new LocalGenerator(b);
        Local thisLocal = lg.generateLocal(sootClass.getType());
        Unit thisU = Jimple.v().newIdentityStmt(thisLocal, 
                Jimple.v().newThisRef(sootClass.getType()));
        Unit returnU = Jimple.v().newReturnStmt(IntConstant.v(1));
        b.getUnits().add(thisU);
        b.getUnits().add(returnU);
    }
        
    return fuzzyMeMethod;
}
 
Example #9
Source File: AsmMethodSource.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
private void convertArrayStoreInsn(InsnNode insn) {
	int op = insn.getOpcode();
	boolean dword = op == LASTORE || op == DASTORE;
	StackFrame frame = getFrame(insn);
	if (!units.containsKey(insn)) {
		Operand valu = dword ? popImmediateDual() : popImmediate();
		Operand indx = popImmediate();
		Operand base = popLocal();
		ArrayRef ar = Jimple.v().newArrayRef(
				base.stackOrValue(), indx.stackOrValue());
		indx.addBox(ar.getIndexBox());
		base.addBox(ar.getBaseBox());
		AssignStmt as = Jimple.v().newAssignStmt(ar, valu.stackOrValue());
		valu.addBox(as.getRightOpBox());
		frame.in(valu, indx, base);
		frame.boxes(as.getRightOpBox(),
				ar.getIndexBox(), ar.getBaseBox());
		setUnit(insn, as);
	} else {
		frame.mergeIn(dword ? popDual() : pop(), pop(), pop());
	}
}
 
Example #10
Source File: UnitThrowAnalysisTest.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
@Ignore("Fails")
@Test
public void testJReturnVoidStmt() {
    Stmt s = Jimple.v().newReturnVoidStmt();

    Set expectedRep = new ExceptionHashSet(utility.VM_ERRORS);
    expectedRep.add(utility.ILLEGAL_MONITOR_STATE_EXCEPTION);
    assertTrue(ExceptionTestUtility.sameMembers(expectedRep, Collections.EMPTY_SET,
                unitAnalysis.mightThrow(s)));

    Set expectedCatch = new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES);
    expectedCatch.add(utility.ILLEGAL_MONITOR_STATE_EXCEPTION);
    expectedCatch.add(utility.RUNTIME_EXCEPTION);
    expectedCatch.add(utility.EXCEPTION);
    assertEquals(expectedCatch, 
            utility.catchableSubset(unitAnalysis.mightThrow(s)));
}
 
Example #11
Source File: ImplicitFlowAliasStrategy.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void computeAliasTaints(Abstraction d1, Stmt src, Value targetValue,
		Set<Abstraction> taintSet, SootMethod method, Abstraction newAbs) {
	// Use global aliasing
	Value baseValue = ((InstanceFieldRef) targetValue).getBase();
	Set<AccessPath> aliases = methodToAliases.getUnchecked(method).get
			(new AccessPath(baseValue, true));
	if (aliases != null)
		for (AccessPath ap : aliases) {
			Abstraction aliasAbs = newAbs.deriveNewAbstraction(
					ap.merge(newAbs.getAccessPath()), null);
			if (taintSet.add(aliasAbs))
				// We have found a new alias. This new base object may however yet
				// again alias with something, so we need to check again
				if (ap.isInstanceFieldRef()) {
					InstanceFieldRef aliasBaseVal = Jimple.v().newInstanceFieldRef
							(ap.getPlainValue(), ap.getFirstField().makeRef());
					computeAliasTaints(d1, src, aliasBaseVal, taintSet, method, aliasAbs);
				}
		}
}
 
Example #12
Source File: LibraryClassPatcher.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a synthetic "<init>(java.lang.Runnable)" method implementation
 * that stores the given runnable into a field for later use
 * @param smCons The <init>() method for which to create a synthetic
 * implementation
 * @param runnable The "java.lang.Runnable" interface
 * @param fldTarget The field receiving the Runnable
 */
private void patchThreadConstructor(SootMethod smCons, SootClass runnable,
		SootField fldTarget) {
	SootClass sc = smCons.getDeclaringClass();
	Body b = Jimple.v().newBody(smCons);
	smCons.setActiveBody(b);
	
	Local thisLocal = Jimple.v().newLocal("this", sc.getType());
	b.getLocals().add(thisLocal);
	b.getUnits().add(Jimple.v().newIdentityStmt(thisLocal,
			Jimple.v().newThisRef(sc.getType())));
	
	Local param0Local = Jimple.v().newLocal("p0", runnable.getType());
	b.getLocals().add(param0Local);
	b.getUnits().add(Jimple.v().newIdentityStmt(param0Local,
			Jimple.v().newParameterRef(runnable.getType(), 0)));
	
	b.getUnits().add(Jimple.v().newAssignStmt(Jimple.v().newInstanceFieldRef(thisLocal,
			fldTarget.makeRef()), param0Local));
	
	b.getUnits().add(Jimple.v().newReturnVoidStmt());
}
 
Example #13
Source File: UnopInstruction.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Return the appropriate Jimple Expression according to the OpCode
 */
private Value getExpression(Local source) {
    Opcode opcode = instruction.getOpcode();
    switch(opcode) {
    case NEG_INT:
    case NEG_LONG:
    case NEG_FLOAT:
    case NEG_DOUBLE:
        return Jimple.v().newNegExpr(source);
    case NOT_LONG:
        return getNotLongExpr(source);
    case NOT_INT:
        return getNotIntExpr(source);
    default:
        throw new RuntimeException("Invalid Opcode: " + opcode);
    }

}
 
Example #14
Source File: PolicyEnforcementPoint.java    From DroidForce with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 
 * @param parameter
 * @param body
 * @return
 */
private Pair<Value, List<Unit>> generateParameterArray(List<Value> parameter, Body body){
	List<Unit> generated = new ArrayList<Unit>();
	
	NewArrayExpr arrayExpr = Jimple.v().newNewArrayExpr(RefType.v("java.lang.Object"), IntConstant.v(parameter.size()));
	
	Value newArrayLocal = generateFreshLocal(body, getParameterArrayType());
	Unit newAssignStmt = Jimple.v().newAssignStmt(newArrayLocal, arrayExpr);
	generated.add(newAssignStmt);
	
	for(int i = 0; i < parameter.size(); i++){
		Value index = IntConstant.v(i);
		ArrayRef leftSide = Jimple.v().newArrayRef(newArrayLocal, index);
		Value rightSide = generateCorrectObject(body, parameter.get(i), generated);
		
		Unit parameterInArray = Jimple.v().newAssignStmt(leftSide, rightSide);
		generated.add(parameterInArray);
	}
	
	return new Pair<Value, List<Unit>>(newArrayLocal, generated);
}
 
Example #15
Source File: IfTestInstruction.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
protected IfStmt ifStatement(DexBody body) {
      Instruction22t i = (Instruction22t) instruction;
      Local one = body.getRegisterLocal(i.getRegisterA());
      Local other = body.getRegisterLocal(i.getRegisterB());
      BinopExpr condition = getComparisonExpr(one, other);
      jif = (JIfStmt)Jimple.v().newIfStmt(condition, targetInstruction.getUnit());
      // setUnit() is called in ConditionalJumpInstruction

if (IDalvikTyper.ENABLE_DVKTYPER) {
    Debug.printDbg(IDalvikTyper.DEBUG, "constraint if: "+ jif +" condition: "+ condition);
    DalvikTyper.v().addConstraint(condition.getOp1Box(), condition.getOp2Box());
      }
      
      
      return jif;
      
  }
 
Example #16
Source File: JDynamicInvokeExpr.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
public JDynamicInvokeExpr(SootMethodRef bootstrapMethodRef, List<? extends Value> bootstrapArgs, SootMethodRef methodRef, int tag, List<? extends Value> methodArgs)
  {
  	super(methodRef, new ValueBox[methodArgs.size()]);
  	
if(!methodRef.getSignature().startsWith("<"+SootClass.INVOKEDYNAMIC_DUMMY_CLASS_NAME+": "))
  		throw new IllegalArgumentException("Receiver type of JDynamicInvokeExpr must be "+SootClass.INVOKEDYNAMIC_DUMMY_CLASS_NAME+"!");
if(!bootstrapMethodRef.returnType().equals(RefType.v("java.lang.invoke.CallSite"))) {
  		throw new IllegalArgumentException("Return type of bootstrap method must be java.lang.invoke.CallSite!");
}


  	this.bsmRef = bootstrapMethodRef;
      this.bsmArgBoxes = new ValueBox[bootstrapArgs.size()];
      this.tag = tag;

      for(int i = 0; i < bootstrapArgs.size(); i++)
      {
      	this.bsmArgBoxes[i] = Jimple.v().newImmediateBox(bootstrapArgs.get(i));	
      }
      for(int i = 0; i < methodArgs.size(); i++)
      {
      	this.argBoxes[i] = Jimple.v().newImmediateBox( methodArgs.get(i));	
      }
  }
 
Example #17
Source File: AsmMethodSource.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
private void convertTableSwitchInsn(TableSwitchInsnNode insn) {
	StackFrame frame = getFrame(insn);
	if (units.containsKey(insn)) {
		frame.mergeIn(pop());
		return;
	}
	Operand key = popImmediate();
	UnitBox dflt = Jimple.v().newStmtBox(null);
	List<UnitBox> targets = new ArrayList<UnitBox>(insn.labels.size());
	labels.put(insn.dflt, dflt);
	for (LabelNode ln : insn.labels) {
		UnitBox box = Jimple.v().newStmtBox(null);
		targets.add(box);
		labels.put(ln, box);
	}
	TableSwitchStmt tss = Jimple.v().newTableSwitchStmt(key.stackOrValue(),
			insn.min, insn.max, targets, dflt);
	key.addBox(tss.getKeyBox());
	frame.in(key);
	frame.boxes(tss.getKeyBox());
	setUnit(insn, tss);
}
 
Example #18
Source File: UnopInstruction.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
public void jimplify (DexBody body) {
      if(!(instruction instanceof Instruction12x))
          throw new IllegalArgumentException("Expected Instruction12x but got: "+instruction.getClass());

      Instruction12x cmpInstr = (Instruction12x)instruction;
      int dest = cmpInstr.getRegisterA();

      Local source = body.getRegisterLocal(cmpInstr.getRegisterB());
      Value expr = getExpression(source);

      assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), expr);

      setUnit(assign);
      addTags(assign);
      body.add(assign);
      
if (IDalvikTyper.ENABLE_DVKTYPER) {
	Debug.printDbg(IDalvikTyper.DEBUG, "constraint: "+ assign);
        int op = (int)instruction.getOpcode().value;
        //DalvikTyper.v().captureAssign((JAssignStmt)assign, op);
        JAssignStmt jass = (JAssignStmt)assign;
        DalvikTyper.v().setType((expr instanceof JCastExpr) ? ((JCastExpr) expr).getOpBox() : ((UnopExpr) expr).getOpBox(), opUnType[op - 0x7b], true);
        DalvikTyper.v().setType(jass.leftBox, resUnType[op - 0x7b], false);
      }
  }
 
Example #19
Source File: Walker.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
public void outACaseStmt(ACaseStmt node)
   {        
String labelName = (String) mProductions.removeLast();
       UnitBox box = Jimple.v().newStmtBox(null);

       addBoxToPatch(labelName, box);
       
       Value labelValue = null;
       if(node.getCaseLabel() instanceof AConstantCaseLabel)
    labelValue = (Value) mProductions.removeLast();

       // if labelValue == null, this is the default label.
       if(labelValue == null)
    mProductions.addLast(box);
       else {            
           Object[] valueTargetPair = new Object[2];
           valueTargetPair[0] = labelValue;
           valueTargetPair[1] = box;
    mProductions.addLast(valueTargetPair);
       }        
   }
 
Example #20
Source File: DummyMainGenerator.java    From DroidRA with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void instrumentDummyMainMethod(SootMethod mainMethod)
{
	Body body = mainMethod.getActiveBody();
   	
   	PatchingChain<Unit> units = body.getUnits();
   	for (Iterator<Unit> iter = units.snapshotIterator(); iter.hasNext(); )
   	{
   		Stmt stmt = (Stmt) iter.next();
   		
   		if (stmt instanceof IdentityStmt)
   		{
   			continue;
   		}
   		   	
   		//For the purpose of confusion dex optimization (because of the strategy of generating dummyMain method)
		AssignStmt aStmt = (AssignStmt) stmt;
		SootMethod fuzzyMe = generateFuzzyMethod(mainMethod.getDeclaringClass());
		InvokeExpr invokeExpr = Jimple.v().newVirtualInvokeExpr(body.getThisLocal(), fuzzyMe.makeRef());
		Unit assignU = Jimple.v().newAssignStmt(aStmt.getLeftOp(), invokeExpr);
		units.insertAfter(assignU, aStmt);
		
		break;
   	}
}
 
Example #21
Source File: MoveResultInstruction.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
public void jimplify (DexBody body) {
//        if (local != null && expr != null)
//            throw new RuntimeException("Both local and expr are set to move.");

        int dest = ((OneRegisterInstruction)instruction).getRegisterA();

//        if (local != null)
//            assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), local);
//        else if (expr != null)
//            assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), expr);
//        else
//            throw new RuntimeException("Neither local and expr are set to move.");
        assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), body.getStoreResultLocal());
        setUnit(assign);
        addTags(assign);
        if (tag != null)
            assign.addTag(tag);
        body.add(assign);
        
		if (IDalvikTyper.ENABLE_DVKTYPER) {
			Debug.printDbg(IDalvikTyper.DEBUG, "constraint: "+ assign);
          int op = (int)instruction.getOpcode().value;
          JAssignStmt jassign = (JAssignStmt)assign;
          DalvikTyper.v().addConstraint(assign.getLeftOpBox(), assign.getRightOpBox());
        }
    }
 
Example #22
Source File: Walker.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public void outAInvokeStatement(AInvokeStatement node)
   {
Value op = (Value) mProductions.removeLast();

       Unit u = Jimple.v().newInvokeStmt(op);
       
mProductions.addLast(u);
   }
 
Example #23
Source File: AgetInstruction.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public void jimplify (DexBody body) throws InvalidDalvikBytecodeException {
      if(!(instruction instanceof Instruction23x))
          throw new IllegalArgumentException("Expected Instruction23x but got: "+instruction.getClass());

      Instruction23x aGetInstr = (Instruction23x)instruction;
      int dest = aGetInstr.getRegisterA();
     
      Local arrayBase = body.getRegisterLocal(aGetInstr.getRegisterB());
      Local index = body.getRegisterLocal(aGetInstr.getRegisterC());

      ArrayRef arrayRef = Jimple.v().newArrayRef(arrayBase, index);
      Local l = body.getRegisterLocal(dest);
      
      assign = Jimple.v().newAssignStmt(l, arrayRef);
      if (aGetInstr.getOpcode().value == Opcode.AGET_OBJECT.value)
        assign.addTag(new ObjectOpTag());

      setUnit(assign);
      addTags(assign);
      body.add(assign);
      
if (IDalvikTyper.ENABLE_DVKTYPER) {
	Debug.printDbg(IDalvikTyper.DEBUG, "constraint: "+ assign);
        DalvikTyper.v().addConstraint(assign.getLeftOpBox(), assign.getRightOpBox());
        DalvikTyper.v().setType(arrayRef.getIndexBox(), IntType.v(), true);
      }
  }
 
Example #24
Source File: Walker.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public void outAReturnStatement(AReturnStatement node) 
   {
   	Immediate v;
       Stmt s = null;
       if(node.getImmediate() != null) {
    v = (Immediate) mProductions.removeLast();
           s = Jimple.v().newReturnStmt(v);
       } else {
           s = Jimple.v().newReturnVoidStmt();
       }

mProductions.addLast(s);    
   }
 
Example #25
Source File: UnitThrowAnalysisTest.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testJIdentityStmt() {

    Stmt s = Jimple.v().newIdentityStmt(Grimp.v().newLocal("local0", 
                IntType.v()),
            Jimple.v().newCaughtExceptionRef());
    assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET,
                unitAnalysis.mightThrow(s)));
    assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 
            utility.catchableSubset(unitAnalysis.mightThrow(s)));

    s = Jimple.v().newIdentityStmt(Grimp.v().newLocal("local0",
                RefType.v("java.lang.NullPointerException")),
            Jimple.v().newThisRef(RefType.v("java.lang.NullPointerException")));
    assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET,
                unitAnalysis.mightThrow(s)));
    assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 
            utility.catchableSubset(unitAnalysis.mightThrow(s)));

    s = Jimple.v().newIdentityStmt(Grimp.v().newLocal("local0",
                RefType.v("java.lang.NullPointerException")),
            Jimple.v().newParameterRef(RefType.v("java.lang.NullPointerException"), 
                0));
    assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET,
                unitAnalysis.mightThrow(s)));
    assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 
            utility.catchableSubset(unitAnalysis.mightThrow(s)));
}
 
Example #26
Source File: AsmMethodSource.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
private void convertGetFieldInsn(FieldInsnNode insn) {
	StackFrame frame = getFrame(insn);
	Operand[] out = frame.out();
	Operand opr;
	Type type;
	if (out == null) {
		SootClass declClass = Scene.v().getSootClass(
				AsmUtil.toQualifiedName(insn.owner));
		type = AsmUtil.toJimpleType(insn.desc);
		Value val;
		SootFieldRef ref;
		if (insn.getOpcode() == GETSTATIC) {
			ref = Scene.v().makeFieldRef(declClass, insn.name, type, true);
			val = Jimple.v().newStaticFieldRef(ref);
		} else {
			Operand base = popLocal();
			ref = Scene.v().makeFieldRef(declClass, insn.name, type, false);
			InstanceFieldRef ifr =
					Jimple.v().newInstanceFieldRef(
							base.stackOrValue(), ref);
			val = ifr;
			base.addBox(ifr.getBaseBox());
			frame.in(base);
			frame.boxes(ifr.getBaseBox());
		}
		opr = new Operand(insn, val);
		frame.out(opr);
	} else {
		opr = out[0];
		type = opr.<FieldRef>value().getFieldRef().type();
		if (insn.getOpcode() == GETFIELD)
			frame.mergeIn(pop());
	}
	push(type, opr);
}
 
Example #27
Source File: JDynamicInvokeExpr.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public void toString(UnitPrinter up)
{
    up.literal(Jimple.DYNAMICINVOKE);        
    up.literal(" \"" + methodRef.name() + "\" <" + SootMethod.getSubSignature(""/* no method name here*/, methodRef.parameterTypes(), methodRef.returnType()) +">(");        
    
    for(int i = 0; i < argBoxes.length; i++)
    {
        if(i != 0)
            up.literal(", ");
            
        argBoxes[i].toString(up);
    }

    up.literal(") ");
    up.methodRef(bsmRef);
    up.literal("(");
    
    for(int i = 0; i < bsmArgBoxes.length; i++)
    {
        if(i != 0)
            up.literal(", ");
            
        bsmArgBoxes[i].toString(up);
    }

    up.literal(")");
}
 
Example #28
Source File: NewArrayInstruction.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public void jimplify (DexBody body) {

        if(!(instruction instanceof Instruction22c))
            throw new IllegalArgumentException("Expected Instruction22c but got: "+instruction.getClass());

        Instruction22c newArray = (Instruction22c)instruction;
        int dest = newArray.getRegisterA();

        Value size = body.getRegisterLocal(newArray.getRegisterB());

        Type t = DexType.toSoot((TypeReference) newArray.getReference());
        // NewArrayExpr needs the ElementType as it increases the array dimension by 1
        Type arrayType = ((ArrayType) t).getElementType();
        Debug.printDbg("new array element type: ", arrayType);
        
        NewArrayExpr newArrayExpr = Jimple.v().newNewArrayExpr(arrayType, size);

        Local l = body.getRegisterLocal(dest);
        assign = Jimple.v().newAssignStmt(l, newArrayExpr);

        setUnit(assign);
        addTags(assign);
        body.add(assign);

		if (IDalvikTyper.ENABLE_DVKTYPER) {
			Debug.printDbg(IDalvikTyper.DEBUG, "constraint: "+ assign);
          int op = (int)instruction.getOpcode().value;
          DalvikTyper.v().setType(newArrayExpr.getSizeBox(), IntType.v(), true);
          DalvikTyper.v().setType(assign.getLeftOpBox(), newArrayExpr.getType(), false);
        }
    }
 
Example #29
Source File: EmptySwitchEliminator.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
protected void internalTransform(Body b, String phaseName, Map<String,String> options)
{
	Iterator<Unit> it = b.getUnits().snapshotIterator();
    while (it.hasNext()) {
    	Unit u = it.next();
    	if (u instanceof LookupSwitchStmt) {
    		LookupSwitchStmt sw = (LookupSwitchStmt) u;
    		if (sw.getTargetCount() == 0 && sw.getDefaultTarget() != null)
    			b.getUnits().swapWith(sw, Jimple.v().newGotoStmt(sw.getDefaultTarget()));
    	}
    }
    
}
 
Example #30
Source File: Walker.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public void outAInstanceofExpression(AInstanceofExpression node)
   {
Type nonvoidType = (Type) mProductions.removeLast();
Value immediate = (Value) mProductions.removeLast();  
mProductions.addLast(Jimple.v().newInstanceOfExpr(immediate, nonvoidType));

   }