Skip to content

Commit

Permalink
Merge branch 'develop' into ssa_correction
Browse files Browse the repository at this point in the history
  • Loading branch information
swissiety authored Jan 13, 2025
2 parents 01e94e8 + 5f1b50b commit 1f2d2bd
Show file tree
Hide file tree
Showing 45 changed files with 826 additions and 496 deletions.
14 changes: 7 additions & 7 deletions docs/callgraphs.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ You can construct a call graph with Qilin as follows:

==="SootUp"

```java
String MAINCLASS = "dacapo.antlr.Main"; // just an example
PTAPattern ptaPattern = new PTAPattern("insens"); // "2o"=>2OBJ, "1c"=>1CFA, etc.
PTA pta = PTAFactory.createPTA(ptaPattern, view, MAINCLASS);
pta.run();
CallGraph cg = pta.getCallGraph();
```
```java
String MAINCLASS = "dacapo.antlr.Main"; // just an example
PTAPattern ptaPattern = new PTAPattern("insens"); // "2o"=>2OBJ, "1c"=>1CFA, etc.
PTA pta = PTAFactory.createPTA(ptaPattern, view, MAINCLASS);
pta.run();
CallGraph cg = pta.getCallGraph();
```
2 changes: 1 addition & 1 deletion docs/docguide.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
this enables that tutorial code can be tested and will fail if its not up to date anymore :)

```
{{ include('basicSetup/BasicSetup.java')}}
{{ include('basicSetup/BasicSetupTest.java')}}
```
14 changes: 10 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,12 @@
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-util</artifactId>
<version>9.6</version>
<version>9.7.1</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-commons</artifactId>
<version>9.7</version>
<version>9.7.1</version>
</dependency>
<dependency>
<groupId>org.smali</groupId>
Expand Down Expand Up @@ -441,16 +441,22 @@
</dependency>

<!-- testing -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.2</version>
<version>5.10.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.10.2</version>
<version>5.10.3</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,12 @@ protected AbstractCallGraphAlgorithm(@Nonnull View view) {
* This method starts the construction of the call graph algorithm. It initializes the needed
* objects for the call graph generation and calls processWorkList method.
*
* @param view the view contains all needed class files.
* @param entryPoints a list of method signatures that will be added to the work list in the call
* graph generation.
* @return the complete constructed call graph starting from the entry methods.
*/
@Nonnull
final CallGraph constructCompleteCallGraph(View view, List<MethodSignature> entryPoints) {
final CallGraph constructCompleteCallGraph(List<MethodSignature> entryPoints) {
Deque<MethodSignature> workList = new ArrayDeque<>(entryPoints);
Set<MethodSignature> processed = new HashSet<>();

Expand All @@ -83,7 +82,7 @@ final CallGraph constructCompleteCallGraph(View view, List<MethodSignature> entr
workList.addAll(clinits);
MutableCallGraph cg = initializeCallGraph(entryPoints, clinits);

processWorkList(view, workList, processed, cg);
processWorkList(workList, processed, cg);
return cg;
}

Expand Down Expand Up @@ -124,21 +123,17 @@ private Optional<MethodSignature> getSignatureOfImplementedStaticInitializer(

/**
* Processes all entries in the <code>workList</code>, skipping those present in <code>processed
* </code>, adding call edges to the graph. Newly discovered methods are added to the <code>
* workList</code> and processed as well. <code>cg</code> is updated accordingly. The method
* </code>, adding call edges to the graph. Newly discovered methods are added to the <code>
* workList</code> and processed as well. <code>cg</code> is updated accordingly. The method
* postProcessingMethod is called after a method is processed in the <code>workList</code>.
*
* @param view it contains the classes.
* @param workList it contains all method that have to be processed in the call graph generation.
* This list is filled in the execution with found call targets in the call graph algorithm.
* @param processed the list of processed method to only process the method once.
* @param cg the call graph object that is filled with the found methods and call edges.
*/
final void processWorkList(
View view,
Deque<MethodSignature> workList,
Set<MethodSignature> processed,
MutableCallGraph cg) {
Deque<MethodSignature> workList, Set<MethodSignature> processed, MutableCallGraph cg) {
while (!workList.isEmpty()) {
MethodSignature currentMethodSignature = workList.pop();
// skip if already processed
Expand All @@ -154,7 +149,7 @@ final void processWorkList(
}

// perform pre-processing if needed
preProcessingMethod(view, currentMethodSignature, workList, cg);
preProcessingMethod(currentMethodSignature, workList, cg);

// process the method
if (!cg.containsMethod(currentMethodSignature)) {
Expand All @@ -175,7 +170,7 @@ final void processWorkList(
processed.add(currentMethodSignature);

// perform post-processing if needed
postProcessingMethod(view, currentMethodSignature, workList, cg);
postProcessingMethod(currentMethodSignature, workList, cg);
}
}

Expand Down Expand Up @@ -351,27 +346,23 @@ private void addStaticInitializerCalls(
/**
* This method enables optional pre-processing of a method in the call graph algorithm
*
* @param view view
* @param sourceMethod the processed method
* @param workList the current work list that might be extended
* @param cg the current cg that might be extended
*/
protected abstract void preProcessingMethod(
View view,
MethodSignature sourceMethod,
@Nonnull Deque<MethodSignature> workList,
@Nonnull MutableCallGraph cg);

/**
* This method enables optional post-processing of a method in the call graph algorithm
*
* @param view it contains classes and the type hierarchy.
* @param sourceMethod the processed method
* @param workList the current work list that might be extended
* @param cg the current cg that might be extended
*/
protected abstract void postProcessingMethod(
View view,
MethodSignature sourceMethod,
@Nonnull Deque<MethodSignature> workList,
@Nonnull MutableCallGraph cg);
Expand All @@ -397,7 +388,7 @@ public CallGraph addClass(@Nonnull CallGraph oldCallGraph, @Nonnull ClassType cl
// Step 1: Add edges from the new methods to other methods
Deque<MethodSignature> workList = new ArrayDeque<>(newMethodSignatures);
Set<MethodSignature> processed = new HashSet<>(oldCallGraph.getMethodSignatures());
processWorkList(view, workList, processed, updated);
processWorkList(workList, processed, updated);

// Step 2: Add edges from old methods to methods overridden in the new class
Stream<ClassType> superClasses = view.getTypeHierarchy().superClassesOf(classType);
Expand Down Expand Up @@ -445,10 +436,9 @@ public CallGraph addClass(@Nonnull CallGraph oldCallGraph, @Nonnull ClassType cl
* <p>The method throws an exception if there is no main method in any of the classes or if there
* are more than one main method.
*
* @param view to get the view specific main method.
* @return - MethodSignature of main method.
*/
public MethodSignature findMainMethod(View view) {
public MethodSignature findMainMethod() {
Collection<SootMethod> mainMethods =
view.getClasses()
.filter(aClass -> !aClass.isLibraryClass())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ public ClassHierarchyAnalysisAlgorithm(@Nonnull View view) {
@Nonnull
@Override
public CallGraph initialize() {
return constructCompleteCallGraph(view, Collections.singletonList(findMainMethod(view)));
return constructCompleteCallGraph(Collections.singletonList(findMainMethod()));
}

@Nonnull
@Override
public CallGraph initialize(@Nonnull List<MethodSignature> entryPoints) {
return constructCompleteCallGraph(view, entryPoints);
return constructCompleteCallGraph(entryPoints);
}

/**
Expand Down Expand Up @@ -162,7 +162,6 @@ private List<MethodSignature> resolveAllCallTargets(

@Override
protected void postProcessingMethod(
View view,
MethodSignature sourceMethod,
@Nonnull Deque<MethodSignature> workList,
@Nonnull MutableCallGraph cg) {
Expand All @@ -171,7 +170,6 @@ protected void postProcessingMethod(

@Override
protected void preProcessingMethod(
View view,
MethodSignature sourceMethod,
@Nonnull Deque<MethodSignature> workList,
@Nonnull MutableCallGraph cg) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public RapidTypeAnalysisAlgorithm(@Nonnull View view) {
@Nonnull
@Override
public CallGraph initialize() {
List<MethodSignature> entryPoints = Collections.singletonList(findMainMethod(view));
List<MethodSignature> entryPoints = Collections.singletonList(findMainMethod());
return initialize(entryPoints);
}

Expand All @@ -74,7 +74,7 @@ public CallGraph initialize(@Nonnull List<MethodSignature> entryPoints) {
instantiatedClasses = new HashSet<>();
ignoredCalls = new HashMap<>();

CallGraph cg = constructCompleteCallGraph(view, entryPoints);
CallGraph cg = constructCompleteCallGraph(entryPoints);

// delete the data structures
instantiatedClasses = Collections.emptySet();
Expand Down Expand Up @@ -214,14 +214,12 @@ private void saveIgnoredCall(
* sourceMethod. If a new instantiated class has previously ignored calls to this class, they are
* added to call graph
*
* @param view view
* @param sourceMethod the processed method
* @param workList the current work list
* @param cg the current cg
*/
@Override
protected void preProcessingMethod(
View view,
MethodSignature sourceMethod,
@Nonnull Deque<MethodSignature> workList,
@Nonnull MutableCallGraph cg) {
Expand Down Expand Up @@ -272,14 +270,12 @@ protected void includeIgnoredCallsToClass(
/**
* Postprocessing is not needed in RTA
*
* @param view view
* @param sourceMethod the processed method
* @param workList the current worklist that is extended by methods that have to be analyzed.
* @param cg the current cg is extended by new call targets and calls
*/
@Override
protected void postProcessingMethod(
View view,
MethodSignature sourceMethod,
@Nonnull Deque<MethodSignature> workList,
@Nonnull MutableCallGraph cg) {
Expand Down
Loading

0 comments on commit 1f2d2bd

Please sign in to comment.