soot.jimple.ClassConstant Java Examples

The following examples show how to use soot.jimple.ClassConstant. 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: BafASMBackend.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected int getMinJavaVersion(SootMethod method) {
	final BafBody body = getBafBody(method);		
	int minVersion = Options.java_version_1_1;

	for (Unit u : body.getUnits()) {
		if (u instanceof DynamicInvokeInst) {
			return Options.java_version_1_7;
		}
		if (u instanceof PushInst) {
			if (((PushInst) u).getConstant() instanceof ClassConstant) {
				minVersion = Options.java_version_1_5;
			}
		}
	}

	return minVersion;
}
 
Example #2
Source File: AsmMethodSource.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
private Value toSootValue(Object val) throws AssertionError {
	Value v;
	if (val instanceof Integer)
		v = IntConstant.v((Integer) val);
	else if (val instanceof Float)
		v = FloatConstant.v((Float) val);
	else if (val instanceof Long)
		v = LongConstant.v((Long) val);
	else if (val instanceof Double)
		v = DoubleConstant.v((Double) val);
	else if (val instanceof String)
		v = StringConstant.v(val.toString());
	else if (val instanceof org.objectweb.asm.Type)
		v = ClassConstant.v(((org.objectweb.asm.Type) val).getInternalName());
	else if (val instanceof Handle)
		v = MethodHandle.v(toSootMethodRef((Handle) val), ((Handle)val).getTag());
	else
		throw new AssertionError("Unknown constant type: " + val.getClass());
	return v;
}
 
Example #3
Source File: ConstClassInstruction.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
public void jimplify (DexBody body) {
      if(!(instruction instanceof Instruction21c))
          throw new IllegalArgumentException("Expected Instruction21c but got: "+instruction.getClass());

      ReferenceInstruction constClass = (ReferenceInstruction) this.instruction;

      TypeReference tidi = (TypeReference)(constClass.getReference());
      String type = tidi.getType();
      if (type.startsWith("L") && type.endsWith(";"))
        type = type.replaceAll("^L", "").replaceAll(";$", "");

      int dest = ((OneRegisterInstruction) instruction).getRegisterA();
      Constant cst = ClassConstant.v(type);
      assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), cst);
      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); //TODO: classtype could be null!
        DalvikTyper.v().setType(assign.getLeftOpBox(), cst.getType(), false);
      }
  }
 
Example #4
Source File: PointsToGraph.java    From vasco with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates a new node for a constant.
 */
private NewExpr constantNewExpr(Constant constant) {
	if (constant instanceof StringConstant) {
		return STRING_SITE;
	} else if (constant instanceof ClassConstant) {
		return CLASS_SITE;
	} else if (constant instanceof NullConstant) {
		return null;
	} else {
		throw new RuntimeException(constant.toString());
	}
}
 
Example #5
Source File: ClassValueAnalysis.java    From DroidRA with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns the set of possible values of a variable of type class.
 * 
 * @param value The variable whose value we are looking for.
 * @param start The statement where the analysis should start.
 * @return The set of possible values for the variable.
 */
@Override
public Set<Object> computeVariableValues(Value value, Stmt start) {
  if (value instanceof ClassConstant) {
    return Collections.singleton((Object) ((ClassConstant) value).getValue());
  } else if (value instanceof Local) {
    return processClassAssignments(
        findAssignmentsForLocal(start, (Local) value, true, new HashSet<Pair<Unit, Local>>()),
        new HashSet<Stmt>());
  } else {
    return Collections.singleton((Object) TOP_VALUE);
  }
}
 
Example #6
Source File: DavaUnitPrinter.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void constant( Constant c ) {
  if (c instanceof ClassConstant) {
    handleIndent();
    String fullClassName =
      ((ClassConstant)c).value.replaceAll("/", ".");
    output.append(fullClassName + ".class");
  } else {
    super.constant(c);
  }
}
 
Example #7
Source File: ConstantVisitor.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public void caseClassConstant(ClassConstant c) {
	// "array class" types are unmodified
	boolean classIsArray = c.value.startsWith("[");
	String className = classIsArray ? c.value : SootToDexUtils.getDexClassName(c.value);
	BuilderReference referencedClass = dexFile.internTypeReference(className);
       stmtV.addInsn(new Insn21c(Opcode.CONST_CLASS, destinationReg, referencedClass), origStmt);
}
 
Example #8
Source File: NullnessAnalysis.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
private void handleRefTypeAssignment(DefinitionStmt assignStmt, AnalysisInfo out) {
	Value left = assignStmt.getLeftOp();
	Value right = assignStmt.getRightOp();
	
	//unbox casted value
	if(right instanceof JCastExpr) {
		JCastExpr castExpr = (JCastExpr) right;
		right = castExpr.getOp();
	}
	
	//if we have a definition (assignment) statement to a ref-like type, handle it,
	if ( isAlwaysNonNull(right)
	|| right instanceof NewExpr || right instanceof NewArrayExpr
	|| right instanceof NewMultiArrayExpr || right instanceof ThisRef
	|| right instanceof StringConstant || right instanceof ClassConstant
	|| right instanceof CaughtExceptionRef) {
		//if we assign new... or @this, the result is non-null
		out.put(left,NON_NULL);
	} else if(right==NullConstant.v()) {
		//if we assign null, well, it's null
		out.put(left, NULL);
	} else if(left instanceof Local && right instanceof Local) {
		out.put(left, out.get(right));
	} else {
		out.put(left, TOP);
	}
}
 
Example #9
Source File: PointsToSetInternal.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public Set<ClassConstant> possibleClassConstants() { 
    final HashSet<ClassConstant> ret = new HashSet<ClassConstant>();
    return this.forall( new P2SetVisitor() {
    public final void visit( Node n ) {
        if( n instanceof ClassConstantNode ) {
            ret.add( ((ClassConstantNode)n).getClassConstant() );
        } else {
            returnValue = true;
        }
    }} ) ? null : ret;
}
 
Example #10
Source File: PAG.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public AllocNode makeClassConstantNode( ClassConstant cc ) {
       if( opts.types_for_sites() || opts.vta() )
           return makeAllocNode( RefType.v( "java.lang.Class" ),
                   RefType.v( "java.lang.Class" ), null );
       ClassConstantNode ret = (ClassConstantNode) valToAllocNode.get(cc);
if( ret == null ) {
    valToAllocNode.put(cc, ret = new ClassConstantNode(this, cc));
           newAllocNodes.add( ret );
           addNodeTag( ret, null );
}
return ret;
   }
 
Example #11
Source File: AllocAndContextSet.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public Set<ClassConstant> possibleClassConstants() {
 Set<ClassConstant> res = new HashSet<ClassConstant>();
 for (AllocAndContext allocAndContext : this) {
        AllocNode n = allocAndContext.alloc;
        if( n instanceof ClassConstantNode ) {
	res.add( ((ClassConstantNode)n).getClassConstant() );
        } else {
      	  return null;
        }
    }
 return res;
}
 
Example #12
Source File: ValueTemplatePrinter.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public void caseClassConstant(ClassConstant v) {
	printConstant(v, "\""+v.value+"\"");
}
 
Example #13
Source File: ClassValueAnalysis.java    From DroidRA with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Returns the variable values that are associated with an call statement.
 * 
 * @param sourceStmt The statement at which we should start.
 * @param visitedStmts The set of visited statements.
 * @return The set of possible values.
 */
protected Set<Object> handleInvokeExpression(Stmt sourceStmt, Set<Stmt> visitedStmts) {
  if (visitedStmts.contains(sourceStmt)) {
    return Collections.emptySet();
  } else {
    visitedStmts.add(sourceStmt);
  }
  Iterator<Edge> edges = Scene.v().getCallGraph().edgesOutOf(sourceStmt);
  Set<Object> result = new HashSet<>();

  while (edges.hasNext()) {
    Edge edge = edges.next();
    SootMethod target = edge.getTgt().method();
    if (target.isConcrete()) {
      for (Unit unit : target.getActiveBody().getUnits()) {
        if (unit instanceof ReturnStmt) {
          ReturnStmt returnStmt = (ReturnStmt) unit;

          Value returnValue = returnStmt.getOp();
          if (returnValue instanceof StringConstant) {
            result.add(((StringConstant) returnValue).value);
          } else if (returnValue instanceof ClassConstant) {
            result.add(((ClassConstant) returnValue).value);
          } else if (returnValue instanceof Local) {
            List<DefinitionStmt> assignStmts =
                findAssignmentsForLocal(returnStmt, (Local) returnValue, true,
                    new HashSet<Pair<Unit, Local>>());
            Set<Object> classConstants = processClassAssignments(assignStmts, visitedStmts);
            if (classConstants == null || classConstants.contains(TOP_VALUE)
                || classConstants.contains(Constants.ANY_STRING)) {
              return null;
            } else {
              result.addAll(classConstants);
            }
          } else {
            return null;
          }
        }
      }
    }
  }

  return result;
}
 
Example #14
Source File: Walker.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public void outAClzzConstant(AClzzConstant node)
{
 String s = (String)mProductions.removeLast();
 mProductions.addLast(ClassConstant.v(s));
}
 
Example #15
Source File: BackwardBoomerangResults.java    From SPDS with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Set<ClassConstant> possibleClassConstants() {
    throw new RuntimeException("Not implemented!");
}
 
Example #16
Source File: UnitThrowAnalysis.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public void caseClassConstant(ClassConstant c) {
}
 
Example #17
Source File: LazyContextSensitivePointsToSet.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public Set<ClassConstant> possibleClassConstants() {
	return delegate.possibleClassConstants();
}
 
Example #18
Source File: WrappedPointsToSet.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public Set<ClassConstant> possibleClassConstants() {
  return wrapped.possibleClassConstants();
}
 
Example #19
Source File: CONSTANT_Class_info.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public Value createJimpleConstantValue(cp_info[] constant_pool) {
    CONSTANT_Utf8_info ci = (CONSTANT_Utf8_info)(constant_pool[name_index]);
    String name = ci.convert();
	return ClassConstant.v(name);
}
 
Example #20
Source File: RegisterAllocator.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
private Register asConstant(Value v, ConstantVisitor constantV) {
	Constant c = (Constant) v;
	
	Register constantRegister = null;
	
	List<Register> rArray = null;
	AtomicInteger iI = null;
	if (c instanceof ClassConstant) {
	    rArray = classConstantReg;
	    iI = classI;
	} else if (c instanceof NullConstant) {
           rArray = nullConstantReg;
           iI = nullI;
       } else if (c instanceof FloatConstant) {
           rArray = floatConstantReg;
           iI = floatI;
       } else if (c instanceof IntConstant) {
           rArray = intConstantReg;
           iI = intI;
       } else if (c instanceof LongConstant) {
           rArray = longConstantReg;
           iI = longI;
       } else if (c instanceof DoubleConstant) {
           rArray = doubleConstantReg;
           iI = doubleI;
       } else if (c instanceof StringConstant) {
           rArray = stringConstantReg;
           iI = stringI;
       } else {
           throw new RuntimeException("Error. Unknown constant type: '"+ c.getType() +"'");
       }
	
	if (rArray.size() == 0 || iI.intValue() >= rArray.size()) {
	    rArray.add(new Register(c.getType(), nextRegNum));
	    nextRegNum += SootToDexUtils.getDexWords(c.getType());
	}
	
	constantRegister = rArray.get(iI.intValue()).clone();
	iI.set(iI.intValue() + 1);

	// "load" constant into the register...
	constantV.setDestination(constantRegister);
	c.apply(constantV);
	// ...but return an independent register object
	return constantRegister.clone();
}
 
Example #21
Source File: ConstraintCollector.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public void caseIfStmt(IfStmt stmt) {
	if (uses) {
		ConditionExpr cond = (ConditionExpr) stmt.getCondition();

		BinopExpr expr = cond;
		Value lv = expr.getOp1();
		Value rv = expr.getOp2();

		TypeVariable lop;
		TypeVariable rop;

		// ******** LEFT ********
		if (lv instanceof Local) {
			lop = resolver.typeVariable((Local) lv);
		} else if (lv instanceof DoubleConstant) {
			lop = resolver.typeVariable(DoubleType.v());
		} else if (lv instanceof FloatConstant) {
			lop = resolver.typeVariable(FloatType.v());
		} else if (lv instanceof IntConstant) {
			lop = resolver.typeVariable(IntType.v());
		} else if (lv instanceof LongConstant) {
			lop = resolver.typeVariable(LongType.v());
		} else if (lv instanceof NullConstant) {
			lop = resolver.typeVariable(NullType.v());
		} else if (lv instanceof StringConstant) {
			lop = resolver.typeVariable(RefType.v("java.lang.String"));
		} else if (lv instanceof ClassConstant) {
			lop = resolver.typeVariable(RefType.v("java.lang.Class"));
		} else {
			throw new RuntimeException("Unhandled binary expression left operand type: " + lv.getClass());
		}

		// ******** RIGHT ********
		if (rv instanceof Local) {
			rop = resolver.typeVariable((Local) rv);
		} else if (rv instanceof DoubleConstant) {
			rop = resolver.typeVariable(DoubleType.v());
		} else if (rv instanceof FloatConstant) {
			rop = resolver.typeVariable(FloatType.v());
		} else if (rv instanceof IntConstant) {
			rop = resolver.typeVariable(IntType.v());
		} else if (rv instanceof LongConstant) {
			rop = resolver.typeVariable(LongType.v());
		} else if (rv instanceof NullConstant) {
			rop = resolver.typeVariable(NullType.v());
		} else if (rv instanceof StringConstant) {
			rop = resolver.typeVariable(RefType.v("java.lang.String"));
		} else if (rv instanceof ClassConstant) {
			rop = resolver.typeVariable(RefType.v("java.lang.Class"));
		} else {
			throw new RuntimeException("Unhandled binary expression right operand type: " + rv.getClass());
		}

		TypeVariable common = resolver.typeVariable();
		rop.addParent(common);
		lop.addParent(common);
	}
}
 
Example #22
Source File: ClassConstantNode.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public ClassConstant getClassConstant() {
    return (ClassConstant) newExpr;
}
 
Example #23
Source File: ClassConstantNode.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
ClassConstantNode( PAG pag, ClassConstant cc ) {
    super( pag, cc, RefType.v( "java.lang.Class" ), null );
}
 
Example #24
Source File: PointsToSet.java    From JAADAS with GNU General Public License v3.0 2 votes vote down vote up
/** If this points-to set consists entirely of objects of
 * type java.lang.Class of a known class,
 * returns a set of ClassConstant's that are these classes.
 * If this point-to set may contain something else, returns null. */
public Set<ClassConstant> possibleClassConstants();
 
Example #25
Source File: PointsToSetEqualsWrapper.java    From JAADAS with GNU General Public License v3.0 2 votes vote down vote up
/**
 * @return
 * @see soot.PointsToSet#possibleClassConstants()
 */
public Set<ClassConstant> possibleClassConstants() {
    return pts.possibleClassConstants();
}
 
Example #26
Source File: Union.java    From JAADAS with GNU General Public License v3.0 votes vote down vote up
public Set<ClassConstant> possibleClassConstants() { return null; } 
Example #27
Source File: FullObjectSet.java    From JAADAS with GNU General Public License v3.0 votes vote down vote up
public Set<ClassConstant> possibleClassConstants() { return null; } 
Example #28
Source File: EmptyPointsToSet.java    From JAADAS with GNU General Public License v3.0 votes vote down vote up
public Set<ClassConstant> possibleClassConstants() { return Collections.emptySet(); }