Skip to content

Commit

Permalink
Merge branch 'develop' into add/intraprocedural
Browse files Browse the repository at this point in the history
# Conflicts:
#	sootup.java.bytecode/src/test/java/sootup/java/bytecode/Soot1577.java
#	sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java11/TypeInferenceLambdaTest.java
#	sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java8/MethodAcceptingLamExprTest.java
  • Loading branch information
swissiety committed Oct 23, 2023
2 parents 6717701 + 62a1d02 commit c84bd22
Show file tree
Hide file tree
Showing 57 changed files with 649 additions and 337 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<img width="350px" src="https://github.com/soot-oss/SootUp/blob/develop/docs/SootUpLogo.svg">
</p>

# SootUp library ![Java CI with Maven](https://github.com/soot-oss/SootUp/workflows/Java%20CI%20with%20Maven/badge.svg?branch=develop) [![codecov](https://codecov.io/gh/soot-oss/SootUp/branch/develop/graph/badge.svg?token=ELA7U7IAWD)](https://codecov.io/gh/soot-oss/SootUp)
# SootUp library ![Java CI with Maven](https://github.com/soot-oss/SootUp/workflows/Java%20CI%20with%20Maven/badge.svg?branch=develop) [![codecov](https://codecov.io/gh/soot-oss/SootUp/branch/develop/graph/badge.svg?token=ELA7U7IAWD)](https://codecov.io/gh/soot-oss/SootUp) [![javadoc](https://javadoc.io/badge2/org.soot-oss/sootup.core/javadoc.svg)](https://javadoc.io/doc/org.soot-oss/sootup.core)

This is the home of the **SootUp** project.
A complete overhaul of the good, old static analysis framework [Soot](https://github.com/soot-oss/soot).
Expand All @@ -25,7 +25,7 @@ Do you have questions? Feel free to start a [Discussion](https://github.com/soot
#### (compared to its predecessor [Soot](https://github.com/soot-oss/soot).)
- [x] New Improved API (without Globals/Singletons)
- [x] Fully-Parallelizable Architecture
- [x] Enables lazyloading of classes (no interleaved loading of used/dependend classes anymore)
- [x] Enables lazyloading of classes (no interleaved loading of used/dependent classes anymore)
- [x] Fail early strategy - input validation while constructing/building objects
- [x] Up-to-Date (i.e. Java8!) Sourcecode Frontend
- [x] Full Java 21 Support for Bytecode
Expand Down
28 changes: 15 additions & 13 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ You can use bytecode analysis typically when you do not have access to the sourc
!!! example "Create a project to analyze Java bytecode"

~~~java
Path pathToBinary = Paths.get("src/test/resources/BasicSetup/binary");

AnalysisInputLocation<JavaSootClass> inputLocation =
PathBasedAnalysisInputLocation.createForClassContainer(pathToBinary);
new JavaClassPathAnalysisInputLocation("path2Binary");
JavaLanguage language = new JavaLanguage(8);

Expand All @@ -53,13 +51,15 @@ You can use bytecode analysis typically when you do not have access to the sourc

If you have access to the source code, it is also possible to create a project for analyzing source code. Following example shows how to create project for analyzing Java source code.

!!! info "Experimental"

The source code frontend is experimental and should only be used for testing purposes. You should compile the code for analysis first and use the bytecode frontend instead.

!!! example "Create a project to analyze Java source code"

~~~java
Path pathToSource = Paths.get("src/test/resources/BasicSetup/source");

AnalysisInputLocation<JavaSootClass> inputLocation =
new JavaSourcePathAnalysisInputLocation(pathToSource.toString());
new JavaSourcePathAnalysisInputLocation("path2Source");
JavaLanguage language = new JavaLanguage(8);

Expand All @@ -72,7 +72,7 @@ If you have a [Jimple](../jimple) file, you can create a project for analyzing j
!!! example "Create a project to analyze jimple code"

~~~java
Path pathToJimple = Paths.get("src/test/resources/BasicSetup/jimple");
Path pathToJimple = Paths.get("path2Jimple");

AnalysisInputLocation<JavaSootClass> inputLocation =
new JimpleAnalysisInputLocation(pathToJimple);
Expand Down Expand Up @@ -120,10 +120,13 @@ Let's say the following is the target program that we want to analyze:

}

public static void main(String[] var0) {

System.out.println("Hello World!");

public static void main(String[] args) {
HelloWorld hw = new HelloWorld();
hw.hello();
}

public void hello() {

}
}
Expand Down Expand Up @@ -209,9 +212,8 @@ Below we show a comparison of the code so far with the same functionality in soo
=== "SootUp"

``` java
Path pathToBinary = Paths.get("src/test/resources/BasicSetup/binary");
AnalysisInputLocation<JavaSootClass> inputLocation =
PathBasedAnalysisInputLocation.createForClassContainer(pathToBinary);
new JavaClassPathAnalysisInputLocation("path2Binary");

JavaLanguage language = new JavaLanguage(8);

Expand Down
Binary file added shared-test-resources/bugfixes/Indy.class
Binary file not shown.
17 changes: 17 additions & 0 deletions shared-test-resources/bugfixes/Indy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import java.time.LocalDate;
import java.time.Period;
import java.util.stream.Stream;
import java.util.stream.IntStream;

/** conversion failed when there is a merge (here: after the if) and an invokedynamic followed */
class Indy{
public IntStream test(IntStream s) {
int sign;
if (s.isParallel()) {
sign = 1;
}else{
sign = -1;
}
return s.map(n -> n+42);
}
}
Binary file modified shared-test-resources/java-miniapps/MiniApp.jar
Binary file not shown.
1 change: 1 addition & 0 deletions shared-test-resources/java-miniapps/src/NoClass.class
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is not a class
1 change: 1 addition & 0 deletions shared-test-resources/java-miniapps/src/junkclass
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is a test file to check if it recognized as class
Binary file modified shared-test-resources/jigsaw-examples/requires_exports/jar/modb.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is a test file to check if it recognized as class
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
record RecordTest(int a, String b) {
public RecordTest(int a, String b) {
this.a = a;
this.b = b;
}
}
1 change: 1 addition & 0 deletions shared-test-resources/wala-tests/FakeJava.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a fake java file
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ protected final <T extends Method> T findMethodInHierarchy(
if (optSc.isPresent()) {
SootClass<?> sc = optSc.get();

List<ClassType> superClasses = view.getTypeHierarchy().superClassesOf(sc.getType());
List<ClassType> superClasses = view.getTypeHierarchy().incompleteSuperClassesOf(sc.getType());
Set<ClassType> interfaces = view.getTypeHierarchy().implementedInterfacesOf(sc.getType());
superClasses.addAll(interfaces);

Expand Down Expand Up @@ -364,7 +364,7 @@ public CallGraph addClass(@Nonnull CallGraph oldCallGraph, @Nonnull JavaClassTyp
processWorkList(view, workList, processed, updated);

// Step 2: Add edges from old methods to methods overridden in the new class
List<ClassType> superClasses = view.getTypeHierarchy().superClassesOf(classType);
List<ClassType> superClasses = view.getTypeHierarchy().incompleteSuperClassesOf(classType);
Set<ClassType> implementedInterfaces =
view.getTypeHierarchy().implementedInterfacesOf(classType);
Stream<ClassType> superTypes =
Expand All @@ -376,7 +376,9 @@ public CallGraph addClass(@Nonnull CallGraph oldCallGraph, @Nonnull JavaClassTyp
.collect(Collectors.toSet());

superTypes
.map(view::getClassOrThrow)
.map(view::getClass)
.filter(Optional::isPresent)
.map(Optional::get)
.flatMap(superType -> superType.getMethods().stream())
.map(Method::getSignature)
.filter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@
import sootup.core.jimple.basic.Local;
import sootup.core.jimple.basic.Value;
import sootup.core.jimple.common.constant.BooleanConstant;
import sootup.core.jimple.common.constant.ClassConstant;
import sootup.core.jimple.common.constant.DoubleConstant;
import sootup.core.jimple.common.constant.EnumConstant;
import sootup.core.jimple.common.constant.FloatConstant;
import sootup.core.jimple.common.constant.IntConstant;
import sootup.core.jimple.common.constant.LongConstant;
import sootup.core.jimple.common.constant.MethodHandle;
import sootup.core.jimple.common.constant.MethodType;
import sootup.core.jimple.common.constant.StringConstant;
import sootup.core.jimple.common.expr.JAddExpr;
Expand Down Expand Up @@ -70,6 +67,7 @@
import sootup.java.bytecode.inputlocation.JavaClassPathAnalysisInputLocation;
import sootup.java.core.JavaProject;
import sootup.java.core.JavaSootClass;
import sootup.java.core.language.JavaJimple;
import sootup.java.core.language.JavaLanguage;

@Category(Java8Test.class)
Expand Down Expand Up @@ -153,10 +151,10 @@ private void fillList(List<Value> listWithAllValues, View<JavaSootClass> view) {
listWithAllValues.add(FloatConstant.getInstance(2.5f));
listWithAllValues.add(IntConstant.getInstance(3));
listWithAllValues.add(LongConstant.getInstance(3L));
listWithAllValues.add(new StringConstant("String", StringClass));
listWithAllValues.add(new EnumConstant("3", StringClass));
listWithAllValues.add(new ClassConstant("java/lang/String", StringClass));
listWithAllValues.add(new MethodHandle(toStringMethod, 3, StringClass));
listWithAllValues.add(stringConstant);
listWithAllValues.add(JavaJimple.getInstance().newEnumConstant("3", "EnumTest"));
listWithAllValues.add(JavaJimple.getInstance().newClassConstant("java/lang/String"));
listWithAllValues.add(JavaJimple.getInstance().newMethodHandle(toStringMethod, 5));
listWithAllValues.add(new MethodType(toStringMethod.getSubSignature(), StringClass));
listWithAllValues.add(new JAddExpr(stringConstant, stringConstant));
listWithAllValues.add(new JAndExpr(stringConstant, stringConstant));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
*/

import java.nio.file.Path;
import java.util.Optional;
import sootup.core.inputlocation.AnalysisInputLocation;
import sootup.core.inputlocation.FileType;
import sootup.core.model.AbstractClass;
import sootup.core.model.SootClass;
import sootup.core.types.ClassType;

Expand All @@ -34,9 +34,9 @@
*
* @author Manuel Benz
*/
public interface ClassProvider<T extends AbstractClass<? extends AbstractClassSource<T>>> {
public interface ClassProvider<T extends SootClass<? extends SootClassSource<T>>> {

AbstractClassSource<T> createClassSource(
Optional<SootClassSource<T>> createClassSource(
AnalysisInputLocation<? extends SootClass<?>> inputLocation,
Path sourcePath,
ClassType classSignature);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public enum FileType {
this.extension = fileExtension;
}

@Nonnull
public String getExtensionWithDot() {
return "." + extension;
}

@Nonnull
public String getExtension() {
return extension;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/

import javax.annotation.Nonnull;
import sootup.core.model.FullPosition;
import sootup.core.model.Position;
import sootup.core.util.Copyable;

Expand All @@ -34,7 +33,7 @@
* @author Linghui Luo, Markus Schmidt
*/
public class FullStmtPositionInfo extends SimpleStmtPositionInfo implements Copyable {
protected final FullPosition[] operandPositions;
@Nonnull protected final Position[] operandPositions;

/**
* Create an instance from given statement position and operand positions.
Expand All @@ -43,7 +42,7 @@ public class FullStmtPositionInfo extends SimpleStmtPositionInfo implements Copy
* @param operandPositions the operand positions
*/
public FullStmtPositionInfo(
@Nonnull Position stmtPosition, @Nonnull FullPosition[] operandPositions) {
@Nonnull Position stmtPosition, @Nonnull Position[] operandPositions) {
super(stmtPosition);
this.operandPositions = operandPositions;
}
Expand All @@ -65,7 +64,7 @@ public Position getStmtPosition() {
* @return the position of the given operand
*/
public Position getOperandPosition(int index) {
if (this.operandPositions != null && index >= 0 && index < this.operandPositions.length) {
if (index >= 0 && index < this.operandPositions.length) {
return this.operandPositions[index];
} else {
return NoPositionInformation.getInstance();
Expand All @@ -75,15 +74,10 @@ public Position getOperandPosition(int index) {
@Override
public String toString() {
StringBuilder s = new StringBuilder();
s.append("stmt at: ").append(getStmtPosition()).append("\n");
s.append(super.toString());
s.append("operands at: ");
if (operandPositions != null) {
s.append("\n");
for (int i = 0; i < operandPositions.length; i++) {
s.append(i).append(": ").append(operandPositions[i]).append(" ");
}
} else {
s.append("No position info");
for (int i = 0; i < operandPositions.length; i++) {
s.append(i).append(": ").append(operandPositions[i]).append(" ");
}
return s.toString();
}
Expand All @@ -94,7 +88,7 @@ public StmtPositionInfo withStmtPosition(@Nonnull Position stmtPosition) {
}

@Nonnull
public StmtPositionInfo withOperandPositions(@Nonnull FullPosition[] operandPositions) {
public StmtPositionInfo withOperandPositions(@Nonnull Position[] operandPositions) {
return new FullStmtPositionInfo(stmtPosition, operandPositions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import sootup.core.model.FullPosition;
import sootup.core.model.LinePosition;
import sootup.core.model.Position;

/**
Expand All @@ -47,7 +47,7 @@ public SimpleStmtPositionInfo(@Nonnull Position stmtPosition) {
* @param lineNumber the line number of the statement.
*/
public SimpleStmtPositionInfo(int lineNumber) {
stmtPosition = new FullPosition(lineNumber, -1, lineNumber, -1);
stmtPosition = new LinePosition(lineNumber);
}

@Nonnull
Expand All @@ -61,22 +61,4 @@ public Position getStmtPosition() {
public Position getOperandPosition(int index) {
return null;
}

public String toString() {
StringBuilder s = new StringBuilder();
s.append("stmt at:").append(getStmtPosition()).append("\n");
return s.toString();
}

@Nonnull
@Override
public StmtPositionInfo withStmtPosition(@Nonnull Position stmtPosition) {
return null;
}

@Nonnull
@Override
public StmtPositionInfo withOperandPositions(@Nonnull FullPosition[] operandPositions) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import sootup.core.model.FullPosition;
import sootup.core.model.Position;

/**
Expand All @@ -34,7 +33,7 @@
*/
public abstract class StmtPositionInfo {

protected static final StmtPositionInfo noPosition =
protected static final StmtPositionInfo NOPOSITION =
new StmtPositionInfo() {
@Nonnull
@Override
Expand All @@ -51,18 +50,6 @@ public Position getOperandPosition(int index) {
public String toString() {
return "No StmtPositionnfo";
}

@Nonnull
@Override
public StmtPositionInfo withStmtPosition(@Nonnull Position stmtPosition) {
return this;
}

@Nonnull
@Override
public StmtPositionInfo withOperandPositions(@Nonnull FullPosition[] operandPositions) {
return this;
}
};

/**
Expand All @@ -72,7 +59,7 @@ public StmtPositionInfo withOperandPositions(@Nonnull FullPosition[] operandPosi
*/
@Nonnull
public static StmtPositionInfo createNoStmtPositionInfo() {
return noPosition;
return NOPOSITION;
}

/**
Expand All @@ -93,11 +80,9 @@ public static StmtPositionInfo createNoStmtPositionInfo() {
public abstract Position getOperandPosition(int index);

@Override
public abstract String toString();

@Nonnull
public abstract StmtPositionInfo withStmtPosition(@Nonnull Position stmtPosition);

@Nonnull
public abstract StmtPositionInfo withOperandPositions(@Nonnull FullPosition[] operandPositions);
public String toString() {
StringBuilder s = new StringBuilder();
s.append("stmt at:").append(getStmtPosition());
return s.toString();
}
}
Loading

0 comments on commit c84bd22

Please sign in to comment.