diff --git a/CallgraphExample/.idea/misc.xml b/CallgraphExample/.idea/misc.xml
index 5d8d5c0..bce9fde 100644
--- a/CallgraphExample/.idea/misc.xml
+++ b/CallgraphExample/.idea/misc.xml
@@ -7,9 +7,8 @@
-
-
+
\ No newline at end of file
diff --git a/CallgraphExample/.idea/runConfigurations/Compile_Callgraph_Source.xml b/CallgraphExample/.idea/runConfigurations/Compile_Callgraph_Source.xml
new file mode 100644
index 0000000..6c712a5
--- /dev/null
+++ b/CallgraphExample/.idea/runConfigurations/Compile_Callgraph_Source.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/CallgraphExample/.idea/runConfigurations/Run_CallgraphExample.xml b/CallgraphExample/.idea/runConfigurations/Run_CallgraphExample.xml
new file mode 100644
index 0000000..9c09e64
--- /dev/null
+++ b/CallgraphExample/.idea/runConfigurations/Run_CallgraphExample.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/CallgraphExample/README.md b/CallgraphExample/README.md
index 885925a..546644c 100644
--- a/CallgraphExample/README.md
+++ b/CallgraphExample/README.md
@@ -1,2 +1,9 @@
# SootUp-Examples
Example code to help getting start with SootUp
+
+## How to install SootUp 2.0.0
+```
+git clone https://github.com/soot-oss/SootUp
+mvn install
+```
+This installs SootUp 2.0.0-SNAPSHOT version to your local Maven Repository
\ No newline at end of file
diff --git a/CallgraphExample/pom.xml b/CallgraphExample/pom.xml
index 5bc9e88..08e9f5c 100644
--- a/CallgraphExample/pom.xml
+++ b/CallgraphExample/pom.xml
@@ -8,53 +8,68 @@
org.soot-oss
sootup
- 1.1.2-SNAPSHOT
+ 2.0.0-SNAPSHOT
org.soot-oss
sootup.callgraph
- 1.1.2-SNAPSHOT
+ 2.0.0-SNAPSHOT
org.soot-oss
sootup.core
- 1.1.2-SNAPSHOT
+ 2.0.0-SNAPSHOT
org.soot-oss
- sootup.java.bytecode
- 1.1.2-SNAPSHOT
+ sootup.java.bytecode.frontend
+ 2.0.0-SNAPSHOT
org.soot-oss
sootup.java.core
- 1.1.2-SNAPSHOT
+ 2.0.0-SNAPSHOT
org.soot-oss
- sootup.java.sourcecode
- 1.1.2-SNAPSHOT
+ sootup.java.sourcecode.frontend
+ 2.0.0-SNAPSHOT
org.soot-oss
- sootup.jimple.parser
- 1.1.2-SNAPSHOT
+ sootup.jimple.frontend
+ 2.0.0-SNAPSHOT
+
+
+ org.soot-oss
+ sootup.qilin
+ 2.0.0-SNAPSHOT
+
+
+ org.soot-oss
+ sootup.interceptors
+ 2.0.0-SNAPSHOT
+
+
+ org.soot-oss
+ sootup.analysis.interprocedural
+ 2.0.0-SNAPSHOT
+
+
+ org.soot-oss
+ sootup.analysis.intraprocedural
+ 2.0.0-SNAPSHOT
-
-
-
-
- org.soot-oss
- sootup.java.sourcecode
- 1.1.2-SNAPSHOT
- pom
- import
-
-
-
+
+
+ ch.qos.logback
+ logback-classic
+ 1.4.14
+
+
@@ -66,6 +81,17 @@
true
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.1
+
+
+ ${project.basedir}/src/test/resources/Callgraph/source
+
+ ${project.basedir}/src/test/resources/Callgraph/binary
+
+
diff --git a/CallgraphExample/src/main/java/sootup/examples/CallgraphExample.java b/CallgraphExample/src/main/java/sootup/examples/CallgraphExample.java
index 5a8b02c..1144668 100644
--- a/CallgraphExample/src/main/java/sootup/examples/CallgraphExample.java
+++ b/CallgraphExample/src/main/java/sootup/examples/CallgraphExample.java
@@ -3,57 +3,109 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.HashSet;
+import qilin.CoreConfig;
+import qilin.core.PTA;
+import qilin.driver.PTAFactory;
+import qilin.driver.PTAPattern;
import sootup.callgraph.CallGraph;
import sootup.callgraph.CallGraphAlgorithm;
import sootup.callgraph.ClassHierarchyAnalysisAlgorithm;
+import sootup.callgraph.RapidTypeAnalysisAlgorithm;
import sootup.core.inputlocation.AnalysisInputLocation;
import sootup.core.signatures.MethodSignature;
import sootup.core.typehierarchy.ViewTypeHierarchy;
import sootup.core.types.ClassType;
-import sootup.core.types.VoidType;
-import sootup.java.bytecode.inputlocation.JavaClassPathAnalysisInputLocation;
+import sootup.core.types.PrimitiveType;
+
+import sootup.java.bytecode.frontend.inputlocation.JavaClassPathAnalysisInputLocation;
import sootup.java.core.JavaIdentifierFactory;
-//import sootup.java.core.JavaProject;
-import sootup.java.core.JavaSootClass;
-import sootup.java.core.language.JavaLanguage;
import sootup.java.core.views.JavaView;
+import org.slf4j.LoggerFactory;
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.Level;
+
public class CallgraphExample {
+ static {
+ // Set logger level programmatically
+ Logger rootLogger = (Logger) LoggerFactory.getLogger("sootup");
+ rootLogger.setLevel(Level.ERROR);
+
+ Logger callgraphLogger = (Logger) LoggerFactory.getLogger("sootup.callgraph");
+ callgraphLogger.setLevel(Level.ERROR);
+
+ Logger typeHierarchyLogger = (Logger) LoggerFactory.getLogger("sootup.core.typehierarchy");
+ typeHierarchyLogger.setLevel(Level.ERROR);
+ }
public static void main(String[] args) {
+// CoreConfig config = new CoreConfig();
+// System.out.println(config.getPtaConfig());
// Create a AnalysisInputLocation, which points to a directory. All class files will be loaded
// from the directory
List inputLocations = new ArrayList<>();
inputLocations.add(
new JavaClassPathAnalysisInputLocation("src/test/resources/Callgraph/binary"));
- inputLocations.add(
- new JavaClassPathAnalysisInputLocation(
- System.getProperty("java.home") + "/lib/rt.jar")); // add rt.jar
JavaView view = new JavaView(inputLocations);
// Get a MethodSignature
ClassType classTypeA = view.getIdentifierFactory().getClassType("A");
- ClassType classTypeB = view.getIdentifierFactory().getClassType("B");
+ ClassType classTypeC = view.getIdentifierFactory().getClassType("C");
MethodSignature entryMethodSignature =
JavaIdentifierFactory.getInstance()
.getMethodSignature(
- classTypeB,
+ classTypeC,
JavaIdentifierFactory.getInstance()
.getMethodSubSignature(
- "calc", VoidType.getInstance(), Collections.singletonList(classTypeA)));
+ "calc",
+ PrimitiveType.IntType.getInstance(),
+ Collections.singletonList(PrimitiveType.IntType.getInstance())
+ )
+ );
+
+// // Create type hierarchy and CHA
+// final ViewTypeHierarchy typeHierarchy = new ViewTypeHierarchy(view);
+// typeHierarchy.subclassesOf(classTypeA).forEach(System.out::println);
- // Create type hierarchy and CHA
- final ViewTypeHierarchy typeHierarchy = new ViewTypeHierarchy(view);
- System.out.println(typeHierarchy.subclassesOf(classTypeA));
- CallGraphAlgorithm cha = new ClassHierarchyAnalysisAlgorithm(view);
// Create CG by initializing CHA with entry method(s)
- CallGraph cg = cha.initialize(Collections.singletonList(entryMethodSignature));
+ System.out.println("-------------CHA---------------");
+ CallGraphAlgorithm cha = new ClassHierarchyAnalysisAlgorithm(view);
+ CallGraph cg1 = cha.initialize(Collections.singletonList(entryMethodSignature));
+// cg1.callsFrom(entryMethodSignature).forEach(System.out::println);
+ recursivePrint(entryMethodSignature, cg1, new HashSet<>(), "");
- cg.callsFrom(entryMethodSignature).forEach(System.out::println);
+ // Create CG by using RTA with entry method(s)
+ System.out.println("-------------RTA---------------");
+ CallGraphAlgorithm rta = new RapidTypeAnalysisAlgorithm(view);
+ CallGraph cg2 = rta.initialize(Collections.singletonList(entryMethodSignature));
+// cg2.callsFrom(entryMethodSignature).forEach(System.out::println);
+ recursivePrint(entryMethodSignature, cg2, new HashSet<>(), "");
+
+// // Create CG by using QPA with entry method(s)
+// System.out.println("-------------PTA---------------");
+// PTAPattern pattern = new PTAPattern("insens");
+// PTA pta = PTAFactory.createPTA(pattern, view, "C");
+// pta.run();
+// CallGraph cg3 = pta.getCallGraph();
+// cg3.callsFrom(entryMethodSignature).forEach(System.out::println);
}
+ public static void recursivePrint(MethodSignature m, CallGraph cg, HashSet visited, String indent) {
+ // Base case: if the method has already been visited, return to avoid infinite recursion
+ if (visited.contains(m.hashCode())) {
+ return;
+ }
+ // Pretty print the node
+ System.out.println(indent + " -> " + m);
+
+ // Mark the method as visited
+ visited.add(m.hashCode());
+ // Pretty print the children with indentation
+ cg.callTargetsFrom(m).forEach(child -> recursivePrint(child, cg, visited, indent + " "));
+ }
}
diff --git a/CallgraphExample/src/test/resources/Callgraph/binary/A.class b/CallgraphExample/src/test/resources/Callgraph/binary/A.class
index 3edb8c8..0cc4af3 100644
Binary files a/CallgraphExample/src/test/resources/Callgraph/binary/A.class and b/CallgraphExample/src/test/resources/Callgraph/binary/A.class differ
diff --git a/CallgraphExample/src/test/resources/Callgraph/binary/B.class b/CallgraphExample/src/test/resources/Callgraph/binary/B.class
index 0388f72..d74de2b 100644
Binary files a/CallgraphExample/src/test/resources/Callgraph/binary/B.class and b/CallgraphExample/src/test/resources/Callgraph/binary/B.class differ
diff --git a/CallgraphExample/src/test/resources/Callgraph/binary/C.class b/CallgraphExample/src/test/resources/Callgraph/binary/C.class
index dbcf5e4..5e4a695 100644
Binary files a/CallgraphExample/src/test/resources/Callgraph/binary/C.class and b/CallgraphExample/src/test/resources/Callgraph/binary/C.class differ
diff --git a/CallgraphExample/src/test/resources/Callgraph/binary/D.class b/CallgraphExample/src/test/resources/Callgraph/binary/D.class
index ea6682f..68bb813 100644
Binary files a/CallgraphExample/src/test/resources/Callgraph/binary/D.class and b/CallgraphExample/src/test/resources/Callgraph/binary/D.class differ
diff --git a/CallgraphExample/src/test/resources/Callgraph/source/A.java b/CallgraphExample/src/test/resources/Callgraph/source/A.java
index de78cd2..08fbfb1 100644
--- a/CallgraphExample/src/test/resources/Callgraph/source/A.java
+++ b/CallgraphExample/src/test/resources/Callgraph/source/A.java
@@ -2,4 +2,7 @@ public class A {
public int calc(int a) {
return a + 3;
}
+ public void bar() {
+ System.out.println("Bar");
+ }
}
\ No newline at end of file
diff --git a/CallgraphExample/src/test/resources/Callgraph/source/B.java b/CallgraphExample/src/test/resources/Callgraph/source/B.java
index be6169e..acd7d1c 100644
--- a/CallgraphExample/src/test/resources/Callgraph/source/B.java
+++ b/CallgraphExample/src/test/resources/Callgraph/source/B.java
@@ -2,4 +2,10 @@ public class B {
public void calc(A a) {
a.calc(1); // can be A.calc, B.calc, C.calc
}
+ public void foo(int x) {
+ // conditional instantiation check
+ A a = new A();
+ a.bar();
+ System.out.println("Foo");
+ }
}
\ No newline at end of file
diff --git a/CallgraphExample/src/test/resources/Callgraph/source/C.java b/CallgraphExample/src/test/resources/Callgraph/source/C.java
index 1a31fa5..261ce1f 100644
--- a/CallgraphExample/src/test/resources/Callgraph/source/C.java
+++ b/CallgraphExample/src/test/resources/Callgraph/source/C.java
@@ -1,5 +1,12 @@
public class C extends A {
public int calc(int a) {
+ B b = new B();
+ b.foo(a);
return a + 2;
}
+
+ public static void main(String[] args) {
+ C c = new C();
+ c.calc(1);
+ }
}
\ No newline at end of file