public static boolean isResolvableCall(SootMethod invokedMethod) { // TODO make calls through invokespecial resolvable if (invokedMethod.isStatic()) { return true; } if (isConstructor(invokedMethod)) { return true; } return false; }
/** * Checks the following invariants on this Jimple body: * <ol> * <li>static initializer should have 'static' modifier * </ol> */ @Override public void validate(Body body, List<ValidationException> exceptions) { SootMethod method = body.getMethod(); if (method.isAbstract()) { return; } if (method.isStaticInitializer() && !method.isStatic()) { exceptions.add(new ValidationException(method, SootMethod.staticInitializerName + " should be static! Static initializer without 'static'('0x8') modifier" + " will cause problem when running on android platform: " + "\"<clinit> is not flagged correctly wrt/ static\"!")); } }
public SootMethodRef makeRef() { return Scene.v().makeMethodRef(declaringClass, name, parameterTypes == null ? null : Arrays.asList(parameterTypes), returnType, isStatic()); }
@Override protected int getMinJavaVersion(SootMethod method) { final BafBody body = getBafBody(method); int minVersion = Options.java_version_1_1; // http://hg.openjdk.java.net/jdk8/jdk8/hotspot/file/87ee5ee27509/src/share/vm/classfile/classFileParser.cpp if (method.getDeclaringClass().isInterface()) { if (method.isStatic() && !method.isStaticInitializer()) { return Options.java_version_1_8; } } 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; }
public Body(TypeDecl typeDecl, soot.jimple.JimpleBody body, ASTNode container) { this.typeDecl = typeDecl; this.body = body; chains = new java.util.Stack(); chains.push(body.getUnits()); setLine(container); if(!body.getMethod().isStatic()) emitThis(typeDecl); }
/** * @return yes, if this is a class initializer or main function. */ public boolean isEntryMethod() { if (isStatic() && subsignature.equals(VirtualCalls.v().sigClinit)) { return true; } return isMain(); }
public void methodRef(SootMethodRef m) { handleIndent(); if (!baf && m.resolve().isStatic()) { output.append(m.declaringClass().getName()); literal("."); } output.append(m.name()); }
private boolean isRenamingAllowed(SootMethod method) { if (soot.jbco.Main.getWeight(MethodRenamer.name, method.getSignature()) == 0) { return false; } final String subSignature = method.getSubSignature(); if (MAIN_METHOD_SUB_SIGNATURE.equals(subSignature) && method.isPublic() && method.isStatic()) { if (isVerbose()) { logger.info("Skipping renaming \"{}\" method as it is main one.", subSignature); } return false; // skip the main method } if (method.getName().equals(SootMethod.constructorName) || method.getName().equals(SootMethod.staticInitializerName)) { if (isVerbose()) { logger.info("Skipping renaming \"{}\" method as it is constructor or static initializer.", subSignature); } return false; // skip constructors/initializers } return true; }
@SuppressWarnings("unchecked") public static boolean noRefTypeParameters(SootMethod method) { if (!method.isStatic()) { return false; } Predicate<Type> notRefTypePred = new Predicate<Type>() { @Override public boolean test(Type obj_) { return !(obj_ instanceof RefType) && !(obj_ instanceof ArrayType); } }; return notRefTypePred.test(method.getReturnType()) && soot.jimple.spark.ondemand.genericutil.Util.forAll(method.getParameterTypes(), notRefTypePred); }
/** * * @return yes if this is the main method */ public boolean isMain() { if (isPublic() && isStatic()) { NumberedString main_sig = Scene.v().getSubSigNumberer().findOrAdd("void main(java.lang.String[])"); if (main_sig.equals(subsignature)) { return true; } } return false; }
/** Sets the method for which a graph is currently being built. */ private void setCurrentMethod(SootMethod m) { method = m; if (!m.isStatic()) { SootClass c = m.getDeclaringClass(); if (c == null) { throw new RuntimeException("Method " + m + " has no declaring class"); } caseThis(); } for (int i = 0; i < m.getParameterCount(); i++) { if (m.getParameterType(i) instanceof RefLikeType) { caseParm(i); } } Type retType = m.getReturnType(); if (retType instanceof RefLikeType) { caseRet(); } }
private void checkStatic(SootMethod method) { if ((Options.v().wrong_staticness() == Options.wrong_staticness_fail || Options.v().wrong_staticness() == Options.wrong_staticness_fixstrict) && method.isStatic() != isStatic() && !method.isPhantom()) { throw new ResolutionFailedException("Resolved " + this + " to " + method + " which has wrong static-ness"); } }
public static int getOutWordCount(Collection<Unit> units) { int outWords = 0; for (Unit u : units) { Stmt stmt = (Stmt) u; if (stmt.containsInvokeExpr()) { int wordsForParameters = 0; InvokeExpr invocation = stmt.getInvokeExpr(); List<Value> args = invocation.getArgs(); for (Value arg : args) { wordsForParameters += getDexWords(arg.getType()); } if (!invocation.getMethod().isStatic()) { wordsForParameters++; // extra word for "this" } if (wordsForParameters > outWords) { outWords = wordsForParameters; } } } return outWords; }
private void emitLocals() { JimpleBody jb = body; SootMethod m = jb.getMethod(); Collection<Local> jbl = jb.getLocals(); Collection<Unit> jbu = jb.getUnits(); int iloc = 0; if (!m.isStatic()) { Local l = getLocal(iloc++); jbu.add(Jimple.v().newIdentityStmt(l, Jimple.v().newThisRef(m.getDeclaringClass().getType()))); } int nrp = 0; for (Object ot : m.getParameterTypes()) { Type t = (Type) ot; Local l = getLocal(iloc); jbu.add(Jimple.v().newIdentityStmt(l, Jimple.v().newParameterRef(t, nrp++))); if (AsmUtil.isDWord(t)) { iloc += 2; } else { iloc++; } } for (Local l : locals.values()) { jbl.add(l); } }
@Override protected void internalTransform(Body b, String phaseName, Map<String, String> options) { for (Iterator<Unit> unitIt = b.getUnits().snapshotIterator(); unitIt.hasNext();) { Unit u = unitIt.next(); if (u instanceof Stmt) { Stmt s = (Stmt) u; if (s.containsInvokeExpr()) { InvokeExpr iexpr = s.getInvokeExpr(); if (iexpr instanceof StaticInvokeExpr) { if (isClassLoaded(iexpr.getMethodRef().declaringClass())) { SootMethod target = Scene.v().grabMethod(iexpr.getMethodRef().getSignature()); if (target != null && !target.isStatic()) { if (canBeMadeStatic(target)) { // Remove the this-assignment to prevent // 'this-assignment in a static method!' exception target.getActiveBody().getUnits().remove(target.getActiveBody().getThisUnit()); target.setModifiers(target.getModifiers() | Modifier.STATIC); logger.warn(target.getName() + " changed into a static method"); } } } } } } } }
protected void internalTransform(Body b, String phaseName, Map<String, String> options) { if (!b.getMethod().isSynchronized() || b.getMethod().isStatic()) { return; } Iterator<Unit> it = b.getUnits().snapshotIterator(); while (it.hasNext()) { Unit u = it.next(); if (u instanceof IdentityStmt) { continue; } // This the first real statement. If it is not a MonitorEnter // instruction, we generate one if (!(u instanceof EnterMonitorStmt)) { b.getUnits().insertBeforeNoRedirect(Jimple.v().newEnterMonitorStmt(b.getThisLocal()), u); // We also need to leave the monitor when the method terminates UnitGraph graph = new ExceptionalUnitGraph(b); for (Unit tail : graph.getTails()) { b.getUnits().insertBefore(Jimple.v().newExitMonitorStmt(b.getThisLocal()), tail); } } break; } } }
/** A constructor that doesn't run the analysis */ protected SimpleMethodInfoFlowAnalysis(UnitGraph g, InfoFlowAnalysis dfa, boolean ignoreNonRefTypeFlow, boolean dummyDontRunAnalysisYet) { super(g); this.sm = g.getBody().getMethod(); if (sm.isStatic()) { this.thisLocal = null; } else { this.thisLocal = g.getBody().getThisLocal(); } this.dfa = dfa; this.refOnly = ignoreNonRefTypeFlow; this.infoFlowGraph = new MemoryEfficientGraph<EquivalentValue>(); this.returnRef = new ParameterRef(g.getBody().getMethod().getReturnType(), -1); // it's a dummy parameter ref this.entrySet = new ArraySparseSet<Pair<EquivalentValue, EquivalentValue>>(); this.emptySet = new ArraySparseSet<Pair<EquivalentValue, EquivalentValue>>(); printMessages = false; }
public soot.Local emitThis(TypeDecl typeDecl) { if(thisName == null) { thisName = newLocal("this", typeDecl.getSootType()); if(body.getMethod().isStatic()) add(Jimple.v().newIdentityStmt(thisName, Jimple.v().newParameterRef(typeDecl.getSootType(), 0))); else add(Jimple.v().newIdentityStmt(thisName, Jimple.v().newThisRef(typeDecl.sootRef()))); } return thisName; }
protected void buildNative() { ValNode thisNode = null; ValNode retNode = null; if (!method.isStatic()) { thisNode = (ValNode) nodeFactory.caseThis(); } if (method.getReturnType() instanceof RefLikeType) { retNode = (ValNode) nodeFactory.caseRet(); // on library analysis we assume that the return type of an native method can // be anything matching to the declared type. if (pag.getCGOpts().library() != CGOptions.library_disabled) { Type retType = method.getReturnType(); retType.apply(new SparkLibraryHelper(pag, retNode, method)); } } ValNode[] args = new ValNode[method.getParameterCount()]; for (int i = 0; i < method.getParameterCount(); i++) { if (!(method.getParameterType(i) instanceof RefLikeType)) { continue; } args[i] = (ValNode) nodeFactory.caseParm(i); } pag.nativeMethodDriver.process(method, thisNode, retNode, args); }
public static EquivalentValue getNodeForFieldRef(SootMethod sm, SootField sf, Local realLocal) { if (sf.isStatic()) { return new CachedEquivalentValue(Jimple.v().newStaticFieldRef(sf.makeRef())); } else { // Jimple.v().newThisRef(sf.getDeclaringClass().getType()) if (sm.isConcrete() && !sm.isStatic() && sm.getDeclaringClass() == sf.getDeclaringClass() && realLocal == null) { JimpleLocal fakethis = new FakeJimpleLocal("fakethis", sf.getDeclaringClass().getType(), sm.retrieveActiveBody().getThisLocal()); return new CachedEquivalentValue(Jimple.v().newInstanceFieldRef(fakethis, sf.makeRef())); // fake thisLocal } else { // Pretends to be a this.<somefield> ref for a method without a body, // for a static method, or for an inner field JimpleLocal fakethis = new FakeJimpleLocal("fakethis", sf.getDeclaringClass().getType(), realLocal); return new CachedEquivalentValue(Jimple.v().newInstanceFieldRef(fakethis, sf.makeRef())); // fake thisLocal } } }