Skip to content

Commit

Permalink
Merge pull request #784 from soot-oss/featur/removeGenerics
Browse files Browse the repository at this point in the history
Remove the over-complicated generics
  • Loading branch information
stschott authored Jan 10, 2024
2 parents 71d5508 + b1743b9 commit 570fd8b
Show file tree
Hide file tree
Showing 195 changed files with 886 additions and 962 deletions.
4 changes: 2 additions & 2 deletions docs/call-graph-construction.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Below, we show how to create a type hierarchy:
=== "SootUp"

```java
List<AnalysisInputLocation<JavaSootClass>> inputLocations = new ArrayList();
List<AnalysisInputLocation> inputLocations = new ArrayList();
inputLocations.add(new JavaClassPathAnalysisInputLocation("src/test/resources/Callgraph/binary"));
inputLocations.add(new DefaultRTJarAnalysisInputLocation());

Expand Down Expand Up @@ -46,7 +46,7 @@ All the call graph construction algorithms require an entry method to start with
=== "SootUp"

```java
ClassType classTypeA = view.getIdentifierFactory().getClassType("A");
JavaClassType classTypeA = view.getIdentifierFactory().getClassType("A");

MethodSignature entryMethodSignature =
view.getIdentifierFactory()
Expand Down
23 changes: 10 additions & 13 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ You can use bytecode analysis typically when you do not have access to the sourc
!!! example "Create a view to analyze Java bytecode"

~~~java
AnalysisInputLocation<JavaSootClass> inputLocation =
AnalysisInputLocation inputLocation =
new JavaClassPathAnalysisInputLocation("path2Binary");
JavaView view = new JavaView(inputLocation);
Expand All @@ -52,7 +52,7 @@ If you have access to the source code, it is also possible to create a view for
!!! example "Create a view to analyze Java source code"

~~~java
AnalysisInputLocation<JavaSootClass> inputLocation =
AnalysisInputLocation inputLocation =
new JavaSourcePathAnalysisInputLocation("path2Source");
JavaView view = new JavaView(inputLocation);
Expand All @@ -65,7 +65,7 @@ If you have a [Jimple](../jimple) file, you can create a view for analyzing jimp
~~~java
Path pathToJimple = Paths.get("path2Jimple");

AnalysisInputLocation<JavaSootClass> inputLocation =
AnalysisInputLocation inputLocation =
new JimpleAnalysisInputLocation(pathToJimple);

JimpleView view = new JimpleView(inputLocation);
Expand Down Expand Up @@ -120,7 +120,7 @@ Then, we could define the `ClassType` of the `HelloWorld` class as follows:
!!! example "Defining a ClassType"

```java
ClassType classType =
JavaClassType classType =
view.getIdentifierFactory().getClassType("example.HelloWorld");
```

Expand All @@ -129,8 +129,7 @@ Once we have a `ClassType` that identifies the `HelloWorld` class, we can use it
!!! example "Retrieving a SootClass"

```java
SootClass<JavaSootClassSource> sootClass =
(SootClass<JavaSootClassSource>) view.getClass(classType).get();
JavaSootClass sootClass = view.getClass(classType).get();
```

## Retrieving a Method
Expand Down Expand Up @@ -165,10 +164,10 @@ Alternatively, we can also retrieve a `SootMethod` from `SootClass` that contain
!!! example "Retrieving a SootMethod from a SootClass"

```java
Optional<? extends SootMethod> opt = sootClass.getMethod(methodSignature.getSubSignature());
Optional<JavaSootMethod> opt = sootClass.getMethod(methodSignature.getSubSignature());

if(opt.isPresent()){
SootMethod method = opt.get();
JavaSootMethod method = opt.get();
}
```

Expand Down Expand Up @@ -200,7 +199,7 @@ Below we show a comparison of the code so far with the same functionality in soo

JavaView view = new JavaView(inputLocation);

ClassType classType =
JavaClassType classType =
view.getIdentifierFactory().getClassType("HelloWorld");

MethodSignature methodSignature =
Expand All @@ -210,11 +209,9 @@ Below we show a comparison of the code so far with the same functionality in soo
"main", classType, "void",
Collections.singletonList("java.lang.String[]"));

SootClass<JavaSootClassSource> sootClass =
(SootClass<JavaSootClassSource>) view.getClass(classType).get();
JavaSootClass sootClass = view.getClass(classType).get();

SootMethod sootMethod =
sootClass.getMethod(methodSignature.getSubSignature()).get();
JavaSootMethod sootMethod = sootClass.getMethod(methodSignature.getSubSignature()).get();

sootMethod.getBody().getStmts();
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@
import sootup.core.jimple.basic.Value;
import sootup.core.jimple.common.stmt.Stmt;
import sootup.core.model.Body;
import sootup.core.model.SootClass;
import sootup.core.model.SootMethod;
import sootup.core.views.View;

public abstract class AbstractJimpleBasedICFG implements BiDiInterproceduralCFG<Stmt, SootMethod> {

protected final boolean enableExceptions;

protected View<? extends SootClass<?>> view;
protected View view;

@DontSynchronize("written by single thread; read afterwards")
private final Map<Stmt, Body> stmtToOwner = createStmtToOwnerMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import sootup.callgraph.CallGraph;
import sootup.core.jimple.common.expr.*;
import sootup.core.jimple.common.stmt.Stmt;
import sootup.core.model.SootClass;
import sootup.core.model.SootMethod;
import sootup.core.signatures.MethodSignature;
import sootup.core.views.View;
Expand All @@ -53,7 +52,7 @@ public static CallGraphEdgeType findCallGraphEdgeType(AbstractInvokeExpr invokeE
}

public static Set<Pair<MethodSignature, CalleeMethodSignature>> getCallEdges(
View<? extends SootClass> view, CallGraph cg) {
View view, CallGraph cg) {
Set<MethodSignature> methodSigs = cg.getMethodSignatures();
Set<Pair<MethodSignature, CalleeMethodSignature>> callEdges = new HashSet<>();
for (MethodSignature caller : methodSigs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import sootup.core.jimple.common.expr.JNewExpr;
import sootup.core.jimple.common.stmt.JAssignStmt;
import sootup.core.jimple.common.stmt.Stmt;
import sootup.core.model.SootClass;
import sootup.core.model.SootMethod;
import sootup.core.signatures.MethodSignature;
import sootup.core.signatures.MethodSubSignature;
Expand All @@ -41,9 +40,7 @@
public class ICFGDotExporter {

public static String buildICFGGraph(
Map<MethodSignature, StmtGraph> signatureToStmtGraph,
View<? extends SootClass<?>> view,
CallGraph callGraph) {
Map<MethodSignature, StmtGraph> signatureToStmtGraph, View view, CallGraph callGraph) {
final StringBuilder sb = new StringBuilder();
DotExporter.buildDiGraphObject(sb);
Map<Integer, MethodSignature> calls;
Expand All @@ -61,9 +58,7 @@ public static String buildICFGGraph(
* methods.
*/
public static Map<Integer, MethodSignature> computeCalls(
Map<MethodSignature, StmtGraph> stmtGraphSet,
View<? extends SootClass<?>> view,
CallGraph callgraph) {
Map<MethodSignature, StmtGraph> stmtGraphSet, View view, CallGraph callgraph) {
Map<Integer, MethodSignature> calls = new HashMap<>();
for (Map.Entry<MethodSignature, StmtGraph> entry : stmtGraphSet.entrySet()) {
StmtGraph stmtGraph = entry.getValue();
Expand Down Expand Up @@ -126,7 +121,7 @@ public static Set<MethodSignature> getMethodSignatureInSubClass(
public static void connectEdgesToSubClasses(
MethodSignature source,
MethodSignature target,
View<? extends SootClass<?>> view,
View view,
Map<Integer, MethodSignature> calls,
CallGraph callgraph) {
Set<MethodSignature> methodSignatureInSubClass =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import sootup.callgraph.ClassHierarchyAnalysisAlgorithm;
import sootup.core.graph.StmtGraph;
import sootup.core.jimple.common.stmt.Stmt;
import sootup.core.model.SootClass;
import sootup.core.model.SootMethod;
import sootup.core.signatures.MethodSignature;
import sootup.core.views.View;
Expand Down Expand Up @@ -210,7 +209,7 @@ public Collection<Stmt> getCallersOf(@Nonnull SootMethod m) {
}

public static Set<Pair<MethodSignature, CalleeMethodSignature>> getCallEdges(
@Nonnull View<? extends SootClass<?>> view, @Nonnull CallGraph cg) {
@Nonnull View view, @Nonnull CallGraph cg) {
Set<MethodSignature> methodSigs = cg.getMethodSignatures();
Set<Pair<MethodSignature, CalleeMethodSignature>> callEdges = new HashSet<>();
for (MethodSignature caller : methodSigs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import sootup.java.bytecode.inputlocation.DefaultRTJarAnalysisInputLocation;
import sootup.java.bytecode.inputlocation.JavaClassPathAnalysisInputLocation;
import sootup.java.core.JavaIdentifierFactory;
import sootup.java.core.JavaSootClass;
import sootup.java.core.types.JavaClassType;
import sootup.java.core.views.JavaView;

Expand All @@ -40,7 +39,7 @@ public CallGraph loadCallGraph(JavaView view) {

@Test
public void ICFGDotExportTest() {
List<AnalysisInputLocation<? extends JavaSootClass>> inputLocations = new ArrayList<>();
List<AnalysisInputLocation> inputLocations = new ArrayList<>();
inputLocations.add(new DefaultRTJarAnalysisInputLocation());
inputLocations.add(new JavaClassPathAnalysisInputLocation("src/test/resources/icfg/binary"));

Expand All @@ -49,7 +48,7 @@ public void ICFGDotExportTest() {
JavaIdentifierFactory identifierFactory = JavaIdentifierFactory.getInstance();
JavaClassType mainClassSignature = identifierFactory.getClassType("ICFGExample");

SootClass<?> sc = view.getClass(mainClassSignature).get();
SootClass sc = view.getClass(mainClassSignature).get();
entryMethod =
sc.getMethods().stream().filter(e -> e.getName().equals("entryPoint")).findFirst().get();

Expand All @@ -75,7 +74,7 @@ public void ICFGDotExportTest() {

@Test
public void ICFGDotExportTest2() {
List<AnalysisInputLocation<? extends JavaSootClass>> inputLocations = new ArrayList<>();
List<AnalysisInputLocation> inputLocations = new ArrayList<>();
inputLocations.add(new DefaultRTJarAnalysisInputLocation());
inputLocations.add(new JavaClassPathAnalysisInputLocation("src/test/resources/icfg/binary"));

Expand All @@ -84,7 +83,7 @@ public void ICFGDotExportTest2() {
JavaIdentifierFactory identifierFactory = JavaIdentifierFactory.getInstance();
JavaClassType mainClassSignature = identifierFactory.getClassType("ICFGExample2");

SootClass<?> sc = view.getClass(mainClassSignature).get();
SootClass sc = view.getClass(mainClassSignature).get();
entryMethod =
sc.getMethods().stream().filter(e -> e.getName().equals("entryPoint")).findFirst().get();

Expand All @@ -110,7 +109,7 @@ public void ICFGDotExportTest2() {

@Test
public void ICFGArrayListDotExport() {
List<AnalysisInputLocation<? extends JavaSootClass>> inputLocations = new ArrayList<>();
List<AnalysisInputLocation> inputLocations = new ArrayList<>();
inputLocations.add(new DefaultRTJarAnalysisInputLocation());
inputLocations.add(new JavaClassPathAnalysisInputLocation("src/test/resources/icfg/binary"));

Expand All @@ -119,7 +118,7 @@ public void ICFGArrayListDotExport() {
JavaIdentifierFactory identifierFactory = JavaIdentifierFactory.getInstance();
JavaClassType mainClassSignature = identifierFactory.getClassType("ICFGArrayListExample");

SootClass<?> sc = view.getClass(mainClassSignature).get();
SootClass sc = view.getClass(mainClassSignature).get();
entryMethod =
sc.getMethods().stream().filter(e -> e.getName().equals("main")).findFirst().get();

Expand All @@ -137,7 +136,7 @@ public void ICFGArrayListDotExport() {

@Test
public void ICFGInterfaceDotExport() {
List<AnalysisInputLocation<? extends JavaSootClass>> inputLocations = new ArrayList<>();
List<AnalysisInputLocation> inputLocations = new ArrayList<>();
inputLocations.add(new DefaultRTJarAnalysisInputLocation());
inputLocations.add(new JavaClassPathAnalysisInputLocation("src/test/resources/icfg/binary"));

Expand All @@ -146,7 +145,7 @@ public void ICFGInterfaceDotExport() {
JavaIdentifierFactory identifierFactory = JavaIdentifierFactory.getInstance();
JavaClassType mainClassSignature = identifierFactory.getClassType("ICFGInterfaceExample");

SootClass<?> sc = view.getClass(mainClassSignature).get();
SootClass sc = view.getClass(mainClassSignature).get();
entryMethod =
sc.getMethods().stream().filter(e -> e.getName().equals("main")).findFirst().get();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import sootup.core.util.printer.StmtPrinter;
import sootup.java.bytecode.inputlocation.DefaultRTJarAnalysisInputLocation;
import sootup.java.core.JavaIdentifierFactory;
import sootup.java.core.JavaSootClass;
import sootup.java.core.types.JavaClassType;
import sootup.java.core.views.JavaView;
import sootup.java.sourcecode.inputlocation.JavaSourcePathAnalysisInputLocation;
Expand Down Expand Up @@ -136,7 +135,7 @@ public void testGetCallEdges() {
fail("The rt.jar is not available after Java 8. You are using version " + version);
}

List<AnalysisInputLocation<? extends JavaSootClass>> inputLocations = new ArrayList<>();
List<AnalysisInputLocation> inputLocations = new ArrayList<>();
inputLocations.add(new DefaultRTJarAnalysisInputLocation());
inputLocations.add(new JavaSourcePathAnalysisInputLocation("src/test/resources/callgraph/"));

Expand All @@ -148,7 +147,7 @@ public void testGetCallEdges() {
identifierFactory.getMethodSignature(
mainClassSignature, "main", "void", Collections.singletonList("java.lang.String[]"));

SootClass<?> sc = view.getClass(mainClassSignature).orElse(null);
SootClass sc = view.getClass(mainClassSignature).orElse(null);
assertNotNull(sc);
SootMethod m = sc.getMethod(mainMethodSignature.getSubSignature()).orElse(null);
assertNotNull(mainMethodSignature + " not found in classloader", m);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import sootup.java.bytecode.inputlocation.DefaultRTJarAnalysisInputLocation;
import sootup.java.bytecode.inputlocation.JavaClassPathAnalysisInputLocation;
import sootup.java.core.JavaIdentifierFactory;
import sootup.java.core.JavaSootClass;
import sootup.java.core.types.JavaClassType;
import sootup.java.core.views.JavaView;

Expand Down Expand Up @@ -74,7 +73,7 @@ private void runAnalysis() {
* classes.
*/
private void setupSoot(String targetTestClassName) {
List<AnalysisInputLocation<? extends JavaSootClass>> inputLocations = new ArrayList<>();
List<AnalysisInputLocation> inputLocations = new ArrayList<>();
inputLocations.add(new DefaultRTJarAnalysisInputLocation());
inputLocations.add(new JavaClassPathAnalysisInputLocation("src/test/resources/taint/binary"));

Expand All @@ -83,7 +82,7 @@ private void setupSoot(String targetTestClassName) {
JavaIdentifierFactory identifierFactory = JavaIdentifierFactory.getInstance();
JavaClassType mainClassSignature = identifierFactory.getClassType(targetTestClassName);

SootClass<?> sc = view.getClass(mainClassSignature).get();
SootClass sc = view.getClass(mainClassSignature).get();
entryMethod =
sc.getMethods().stream().filter(e -> e.getName().equals("entryPoint")).findFirst().get();

Expand Down
Loading

0 comments on commit 570fd8b

Please sign in to comment.