/** * Adds the given exception to the list of exceptions thrown by this method. */ public void addException(SootClass e) { logger.trace("Adding exception {}", e); if (exceptions == null) { exceptions = new ArrayList<SootClass>(); } else if (exceptions.contains(e)) { throw new RuntimeException("already throws exception " + e.getName()); } exceptions.add(e); }
/** * Determines and returns the internal name of a class. * * @param cls * the class. * @return corresponding internal name. */ public static String toInternalName(SootClass cls) { return toInternalName(cls.getName()); }
/** * Attempts to retrieve the method with the given name, parameters and return type. If no matching method can be found, an * exception is thrown. */ public SootMethod getMethod(String name, List<Type> parameterTypes, Type returnType) { SootMethod sm = getMethodUnsafe(name, parameterTypes, returnType); if (sm != null) { return sm; } throw new RuntimeException( "Class " + getName() + " doesn't have method " + name + "(" + parameterTypes + ")" + " : " + returnType); }
public boolean isIncluded(SootClass sc) { String name = sc.getName(); for (String inc : Options.v().include()) { if (name.equals(inc) || ((inc.endsWith(".*") || inc.endsWith("$*")) && name.startsWith(inc.substring(0, inc.length() - 1)))) { return true; } } return false; }
/** * Removes the given class from the list of interfaces which are directly implemented by this class. */ public void removeInterface(SootClass interfaceClass) { checkLevel(HIERARCHY); if (!implementsInterface(interfaceClass.getName())) { throw new RuntimeException("no such interface: " + interfaceClass.getName()); } interfaces.remove(interfaceClass); }
/** * WARNING: interfaces are subclasses of the java.lang.Object class! Returns the superclass of this class. (see * hasSuperclass()) */ public SootClass getSuperclass() { checkLevel(HIERARCHY); if (superClass == null && !isPhantom()) { throw new RuntimeException("no superclass for " + getName()); } else { return superClass; } }
/** * @param lvNode * @param cName * @param mName * @return */ private boolean isDefinedIn(LocalVarNode lvNode, String cName, String mName) { return lvNode.getMethod() != null && lvNode.getMethod().getDeclaringClass().getName().equals(cName) && lvNode.getMethod().getName().equals(mName); }
public void methodRef(SootMethodRef m) { handleIndent(); if (!baf && m.resolve().isStatic()) { output.append(m.declaringClass().getName()); literal("."); } output.append(m.name()); }
public SootMethod getMethod(String subsignature) { checkLevel(SIGNATURES); NumberedString numberedString = Scene.v().getSubSigNumberer().find(subsignature); if (numberedString == null) { throw new RuntimeException("No method " + subsignature + " in class " + getName()); } return getMethod(numberedString); }
public CPApplication(ASTMethodNode AST, HashMap<String, Object> constantValueFields, HashMap<String, SootField> classNameFieldNameToSootFieldMapping) { className = AST.getDavaBody().getMethod().getDeclaringClass().getName(); cp = new CP(AST, constantValueFields, classNameFieldNameToSootFieldMapping); }
@Override public void caseStaticGetInst(StaticGetInst i) { SootFieldRef field = i.getFieldRef(); mv.visitFieldInsn(Opcodes.GETSTATIC, slashify(field.declaringClass().getName()), field.name(), toTypeDesc(field.type())); }
@Override public void caseFieldGetInst(FieldGetInst i) { SootFieldRef field = i.getFieldRef(); mv.visitFieldInsn(Opcodes.GETFIELD, slashify(field.declaringClass().getName()), field.name(), toTypeDesc(field.type())); }
protected static MethodReference toMethodReference(SootMethodRef m) { List<String> parameters = new ArrayList<String>(); for (Type t : m.parameterTypes()) { parameters.add(SootToDexUtils.getDexTypeDescriptor(t)); } MethodReference methodRef = new ImmutableMethodReference(SootToDexUtils.getDexClassName(m.declaringClass().getName()), m.name(), parameters, SootToDexUtils.getDexTypeDescriptor(m.returnType())); return methodRef; }
@Override public void caseStaticInvokeInst(StaticInvokeInst i) { SootMethodRef m = i.getMethodRef(); mv.visitMethodInsn(Opcodes.INVOKESTATIC, slashify(m.declaringClass().getName()), m.name(), toTypeDesc(m), m.declaringClass().isInterface() && !m.isStatic()); }
@Override public void caseStaticPutInst(StaticPutInst i) { emit("putstatic " + slashify(i.getFieldRef().declaringClass().getName()) + "/" + i.getFieldRef().name() + " " + jasminDescriptorOf(i.getFieldRef().type())); }
@Override public void caseFieldGetInst(FieldGetInst i) { emit("getfield " + slashify(i.getFieldRef().declaringClass().getName()) + "/" + i.getFieldRef().name() + " " + jasminDescriptorOf(i.getFieldRef().type())); }
private synchronized void ensureClassHasBodies(SootClass cl) { assert Scene.v().hasFastHierarchy(); if (cl.resolvingLevel() < SootClass.BODIES) { Scene.v().forceResolve(cl.getName(), SootClass.BODIES); Scene.v().getOrMakeFastHierarchy(); } assert Scene.v().hasFastHierarchy(); }
public void caseSpecialInvokeExpr(SpecialInvokeExpr v) { SootMethodRef m = v.getMethodRef(); emitValue(v.getBase()); for (int i = 0; i < m.parameterTypes().size(); i++) { emitValue(v.getArg(i)); } emit("invokespecial " + slashify(m.declaringClass().getName()) + "/" + m.name() + jasminDescriptorOf(m), -(argCountOf(m) + 1) + sizeOfType(m.returnType())); }
public void caseVirtualInvokeExpr(VirtualInvokeExpr v) { SootMethodRef m = v.getMethodRef(); emitValue(v.getBase()); for (int i = 0; i < m.parameterTypes().size(); i++) { emitValue(v.getArg(i)); } emit("invokevirtual " + slashify(m.declaringClass().getName()) + "/" + m.name() + jasminDescriptorOf(m), -(argCountOf(m) + 1) + sizeOfType(m.returnType())); }
public void caseStaticFieldRef(StaticFieldRef v) { SootFieldRef field = v.getFieldRef(); emitValue(rvalue); emit("putstatic " + slashify(field.declaringClass().getName()) + "/" + field.name() + " " + jasminDescriptorOf(field.type()), -sizeOfType(v.getFieldRef().type())); } });