use of soot.SootClass in project soot by Sable.
the class ReflectionTraceInfo method inferSource.
private Set<SootMethod> inferSource(String source, int lineNumber) {
String className = source.substring(0, source.lastIndexOf("."));
String methodName = source.substring(source.lastIndexOf(".") + 1);
if (!Scene.v().containsClass(className)) {
Scene.v().addBasicClass(className, SootClass.BODIES);
Scene.v().loadBasicClasses();
if (!Scene.v().containsClass(className)) {
throw new RuntimeException("Trace file refers to unknown class: " + className);
}
}
SootClass sootClass = Scene.v().getSootClass(className);
Set<SootMethod> methodsWithRightName = new LinkedHashSet<SootMethod>();
for (SootMethod m : sootClass.getMethods()) {
if (m.isConcrete() && m.getName().equals(methodName)) {
methodsWithRightName.add(m);
}
}
if (methodsWithRightName.isEmpty()) {
throw new RuntimeException("Trace file refers to unknown method with name " + methodName + " in Class " + className);
} else if (methodsWithRightName.size() == 1) {
return Collections.singleton(methodsWithRightName.iterator().next());
} else {
// more than one method with that name
for (SootMethod sootMethod : methodsWithRightName) {
if (coversLineNumber(lineNumber, sootMethod)) {
return Collections.singleton(sootMethod);
}
if (sootMethod.isConcrete()) {
if (!sootMethod.hasActiveBody())
sootMethod.retrieveActiveBody();
Body body = sootMethod.getActiveBody();
if (coversLineNumber(lineNumber, body)) {
return Collections.singleton(sootMethod);
}
for (Unit u : body.getUnits()) {
if (coversLineNumber(lineNumber, u)) {
return Collections.singleton(sootMethod);
}
}
}
}
// be conservative and return all method that we found
return methodsWithRightName;
}
}
use of soot.SootClass in project soot by Sable.
the class MethodPAG method addMiscEdges.
protected void addMiscEdges() {
// Add node for parameter (String[]) in main method
final String signature = method.getSignature();
if (method.getSubSignature().equals(mainSubSignature)) {
addInEdge(pag().nodeFactory().caseArgv(), nodeFactory.caseParm(0));
} else if (signature.equals("<java.lang.Thread: void <init>(java.lang.ThreadGroup,java.lang.String)>")) {
addInEdge(pag().nodeFactory().caseMainThread(), nodeFactory.caseThis());
addInEdge(pag().nodeFactory().caseMainThreadGroup(), nodeFactory.caseParm(0));
} else if (signature.equals("<java.lang.ref.Finalizer: void <init>(java.lang.Object)>")) {
addInEdge(nodeFactory.caseThis(), pag().nodeFactory().caseFinalizeQueue());
} else if (signature.equals("<java.lang.ref.Finalizer: void runFinalizer()>")) {
addInEdge(pag.nodeFactory().caseFinalizeQueue(), nodeFactory.caseThis());
} else if (signature.equals("<java.lang.ref.Finalizer: void access$100(java.lang.Object)>")) {
addInEdge(pag.nodeFactory().caseFinalizeQueue(), nodeFactory.caseParm(0));
} else if (signature.equals("<java.lang.ClassLoader: void <init>()>")) {
addInEdge(pag.nodeFactory().caseDefaultClassLoader(), nodeFactory.caseThis());
} else if (signature.equals("<java.lang.Thread: void exit()>")) {
addInEdge(pag.nodeFactory().caseMainThread(), nodeFactory.caseThis());
} else if (signature.equals("<java.security.PrivilegedActionException: void <init>(java.lang.Exception)>")) {
addInEdge(pag.nodeFactory().caseThrow(), nodeFactory.caseParm(0));
addInEdge(pag.nodeFactory().casePrivilegedActionException(), nodeFactory.caseThis());
}
if (method.getNumberedSubSignature().equals(sigCanonicalize)) {
SootClass cl = method.getDeclaringClass();
while (cl != null) {
if (cl.equals(Scene.v().getSootClass("java.io.FileSystem"))) {
addInEdge(pag.nodeFactory().caseCanonicalPath(), nodeFactory.caseRet());
}
cl = cl.getSuperclassUnsafe();
}
}
boolean isImplicit = false;
for (SootMethod implicitMethod : EntryPoints.v().implicit()) {
if (implicitMethod.getNumberedSubSignature().equals(method.getNumberedSubSignature())) {
isImplicit = true;
break;
}
}
if (isImplicit) {
SootClass c = method.getDeclaringClass();
outer: do {
while (!c.getName().equals("java.lang.ClassLoader")) {
if (!c.hasSuperclass()) {
break outer;
}
c = c.getSuperclass();
}
if (method.getName().equals("<init>"))
continue;
addInEdge(pag().nodeFactory().caseDefaultClassLoader(), nodeFactory.caseThis());
addInEdge(pag().nodeFactory().caseMainClassNameString(), nodeFactory.caseParm(0));
} while (false);
}
}
use of soot.SootClass in project soot by Sable.
the class CollectConstants method isSuitableClassToAddFieldConstant.
private boolean isSuitableClassToAddFieldConstant(SootClass sc, Constant constant) {
if (sc.isInterface()) {
return false;
}
if (constant instanceof ClassConstant) {
ClassConstant classConstant = (ClassConstant) constant;
RefType type = (RefType) classConstant.toSootType();
SootClass classFromConstant = type.getSootClass();
Hierarchy hierarchy = Scene.v().getActiveHierarchy();
return hierarchy.isVisible(sc, classFromConstant);
}
return true;
}
use of soot.SootClass in project soot by Sable.
the class LibraryMethodWrappersBuilder method getVisibleApplicationClasses.
private static List<SootClass> getVisibleApplicationClasses(SootMethod visibleBy) {
final List<SootClass> result = new ArrayList<>();
final Iterator<SootClass> applicationClassesIterator = Scene.v().getApplicationClasses().snapshotIterator();
while (applicationClassesIterator.hasNext()) {
final SootClass applicationClass = applicationClassesIterator.next();
if (applicationClass.isConcrete() && !applicationClass.isInterface() && applicationClass.isPublic() && Scene.v().getActiveHierarchy().isVisible(applicationClass, visibleBy)) {
result.add(applicationClass);
}
}
return result;
}
use of soot.SootClass in project soot by Sable.
the class LibraryMethodWrappersBuilder method getMethodSafely.
private static SootMethod getMethodSafely(InvokeExpr invokeExpr) {
try {
final SootMethod invokedMethod = invokeExpr.getMethod();
if (invokedMethod == null) {
return null;
}
if (SootMethod.constructorName.equals(invokedMethod.getName()) || SootMethod.staticInitializerName.equals(invokedMethod.getName())) {
logger.debug("Skipping wrapping method {} as it is constructor/initializer.", invokedMethod);
return null;
}
final SootClass invokedMethodClass = invokedMethod.getDeclaringClass();
if (!invokedMethodClass.isLibraryClass()) {
logger.debug("Skipping wrapping method {} as it is not library one.", invokedMethod);
return null;
}
if (invokeExpr.getMethodRef().declaringClass().isInterface() && !invokedMethodClass.isInterface()) {
logger.debug("Skipping wrapping method {} as original code suppose to execute it on interface {}" + " but resolved code trying to execute it on class {}", invokedMethod, invokeExpr.getMethodRef().declaringClass(), invokedMethodClass);
return null;
}
return invokedMethod;
} catch (RuntimeException exception) {
logger.debug("Cannot resolve method of InvokeExpr: " + invokeExpr.toString(), exception);
return null;
}
}
Aggregations