use of soot.SootMethod in project soot by Sable.
the class SootUtil method getAmbiguousMethodByName.
public static SootMethod getAmbiguousMethodByName(String methodName) {
SootClass sc = Scene.v().tryLoadClass(getClassName(methodName), SootClass.SIGNATURES);
SootMethod sm = sc.getMethodByName(getMethodName(methodName));
return sm;
}
use of soot.SootMethod 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.SootMethod 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.SootMethod in project soot by Sable.
the class FieldRenamer method setBooleanTo.
protected void setBooleanTo(SootClass sc, SootField f, boolean value) {
if (!value && f.getType() instanceof IntegerType && Rand.getInt() % 2 > 0) {
return;
}
RefType boolRef = Scene.v().getRefType(booleanClassName);
Body body;
boolean newInit = false;
if (!sc.declaresMethodByName(SootMethod.staticInitializerName)) {
SootMethod m = Scene.v().makeSootMethod(SootMethod.staticInitializerName, emptyList(), VoidType.v(), Modifier.STATIC);
sc.addMethod(m);
body = Jimple.v().newBody(m);
m.setActiveBody(body);
newInit = true;
} else {
SootMethod m = sc.getMethodByName(SootMethod.staticInitializerName);
body = m.getActiveBody();
}
PatchingChain<Unit> units = body.getUnits();
if (f.getType() instanceof IntegerType) {
units.addFirst(Jimple.v().newAssignStmt(Jimple.v().newStaticFieldRef(f.makeRef()), IntConstant.v(value ? 1 : 0)));
} else {
Local bool = Jimple.v().newLocal("boolLcl", boolRef);
body.getLocals().add(bool);
SootMethod boolInit = boolRef.getSootClass().getMethod("void <init>(boolean)");
units.addFirst(Jimple.v().newAssignStmt(Jimple.v().newStaticFieldRef(f.makeRef()), bool));
units.addFirst(Jimple.v().newInvokeStmt(Jimple.v().newSpecialInvokeExpr(bool, boolInit.makeRef(), IntConstant.v(value ? 1 : 0))));
units.addFirst(Jimple.v().newAssignStmt(bool, Jimple.v().newNewExpr(boolRef)));
}
if (newInit) {
units.addLast(Jimple.v().newReturnVoidStmt());
}
}
use of soot.SootMethod 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