Skip to content

Commit

Permalink
Merge pull request #783 from soot-oss/fix/CallGraphAlgo_addClass
Browse files Browse the repository at this point in the history
Fix CallGraphAlgorithm.addClass(..) implementation
  • Loading branch information
kadirayk authored Dec 21, 2023
2 parents 129eeb7 + 54191f1 commit bc81639
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -313,16 +313,21 @@ protected abstract void postProcessingMethod(
@Nonnull
@Override
public CallGraph addClass(@Nonnull CallGraph oldCallGraph, @Nonnull JavaClassType classType) {
MutableCallGraph updated = oldCallGraph.copy();

SootClass<?> clazz = view.getClassOrThrow(classType);
Set<MethodSignature> newMethodSignatures =
clazz.getMethods().stream().map(Method::getSignature).collect(Collectors.toSet());
clazz.getMethods().stream()
.map(Method::getSignature)
.filter(methodSig -> !oldCallGraph.containsMethod(methodSig))
.collect(Collectors.toSet());

if (newMethodSignatures.stream().anyMatch(oldCallGraph::containsMethod)) {
throw new IllegalArgumentException("CallGraph already contains methods from " + classType);
// were all the added method signatures already visited in the CallGraph? i.e. is there
// something to add?
if (newMethodSignatures.isEmpty()) {
return oldCallGraph;
}

MutableCallGraph updated = oldCallGraph.copy();

// Step 1: Add edges from the new methods to other methods
Deque<MethodSignature> workList = new ArrayDeque<>(newMethodSignatures);
Set<MethodSignature> processed = new HashSet<>(oldCallGraph.getMethodSignatures());
Expand Down Expand Up @@ -354,8 +359,10 @@ public CallGraph addClass(@Nonnull CallGraph oldCallGraph, @Nonnull JavaClassTyp
MethodSignature overridingMethodSig =
clazz.getMethod(overriddenMethodSig.getSubSignature()).get().getSignature();

for (MethodSignature callingMethodSig : updated.callsTo(overriddenMethodSig)) {
updated.addCall(callingMethodSig, overridingMethodSig);
if (updated.containsMethod(overriddenMethodSig)) {
for (MethodSignature callingMethodSig : updated.callsTo(overriddenMethodSig)) {
updated.addCall(callingMethodSig, overridingMethodSig);
}
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import sootup.core.signatures.MethodSubSignature;
import sootup.core.types.ClassType;
import sootup.core.types.Type;
import sootup.java.core.types.JavaClassType;
import sootup.java.core.views.JavaView;

public class JavaSootClass extends SootClass<JavaSootClassSource> {
Expand All @@ -45,6 +46,12 @@ public JavaSootClass(JavaSootClassSource classSource, SourceType sourceType) {
super(classSource, sourceType);
}

@Nonnull
@Override
public JavaClassType getType() {
return (JavaClassType) super.getType();
}

/**
* Get all annotations on this class. If provided with a View, will also resolve all inherited
* annotations from super classes.
Expand Down

0 comments on commit bc81639

Please sign in to comment.