Skip to content

Commit bf03369

Browse files
author
Andreas Dann
committed
formating
1 parent 3292995 commit bf03369

24 files changed

+1068
-1051
lines changed

README.md

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,54 @@
11
![Maven Build](https://github.com/secure-software-engineering/sootdiff/actions/workflows/maven.yml/badge.svg)
22

3-
43
# SootDiff - Bytecode Comparison Across Different Java Compilers
54

6-
This repository hosts the SootDiff analysis tool. SootDiff allows the comparison of the Java ByteCode create by different Java compilers.
7-
To do so it uses static analysis and optimizations to unify the generated ByteCode, e.g. Constant Propagation, Dead Code Elimination, String Handling. Its goal is to provide researchers and practitioners with a tool and library on which they can base their own research projects and product implementations.
5+
This repository hosts the SootDiff analysis tool. SootDiff allows the comparison of the Java ByteCode create by
6+
different Java compilers. To do so it uses static analysis and optimizations to unify the generated ByteCode, e.g.
7+
Constant Propagation, Dead Code Elimination, String Handling. Its goal is to provide researchers and practitioners with
8+
a tool and library on which they can base their own research projects and product implementations.
89

910
## Obtaining SootDiff
11+
1012
You can either build SootDiff on your own using Maven, or you can download a release from here on Github.
1113

1214
### Downloading the Release
13-
The Release Page contains all pre-built JAR files for each release that we officially publish. We recommend using the latest and greatest version unless you have a specific issue that prevents you from doing so. In that case, please let us know.
1415

16+
The Release Page contains all pre-built JAR files for each release that we officially publish. We recommend using the
17+
latest and greatest version unless you have a specific issue that prevents you from doing so. In that case, please let
18+
us know.
1519

1620
### Building SootDiff with Maven
21+
1722
To build SootDiff with Maven run
23+
1824
```
1925
mvn install
2026
```
2127

2228
or to build a standalone `jar-with-dependencies` run
29+
2330
```
2431
mvn clean compile assembly:single
2532
```
2633

27-
2834
## Publications
29-
If you want to read the details on how SootDiff works, the published paper [SootDiff @SOAP'19,Phoenix, AZ, USA](https://dl.acm.org/citation.cfm?id=3329966) is a good place to start.
30-
3135

36+
If you want to read the details on how SootDiff works, the published
37+
paper [SootDiff @SOAP'19,Phoenix, AZ, USA](https://dl.acm.org/citation.cfm?id=3329966) is a good place to start.
3238

3339
## License
34-
SootDiff is licensed under the MIT license, see LICENSE file. This basically means that you are free to use the tool (even in commercial, closed-source projects).
3540

41+
SootDiff is licensed under the MIT license, see LICENSE file. This basically means that you are free to use the tool (
42+
even in commercial, closed-source projects).
3643

3744
# Use SootDiff to compare Jars
3845

39-
The class `src/test/java/MainCompareArtifacts.java` can be used to compare multiple jars on the basis of class sha,tlshs and timestamps and produces a markdown report of that.
46+
The class `src/test/java/MainCompareArtifacts.java` can be used to compare multiple jars on the basis of class sha,tlshs
47+
and timestamps and produces a markdown report of that.
4048

4149
Invoke the main method with parameters `-inJars jar1,jar2,jar3 -fileFilter pathToFilterFile.txt`
4250

43-
The filter file can be used to specify classes of interest (e.g. classes fixed in a fixing commit). Make sure to specify the files as they would be located in the analyzed jar, e.g., in a commit the change might be related to `src/main/java/pack/a/b.java`, in the jar it would be referenced from the package onwards and in class format: `pack/a/b.class`.
51+
The filter file can be used to specify classes of interest (e.g. classes fixed in a fixing commit). Make sure to specify
52+
the files as they would be located in the analyzed jar, e.g., in a commit the change might be related
53+
to `src/main/java/pack/a/b.java`, in the jar it would be referenced from the package onwards and in class
54+
format: `pack/a/b.class`.

pom.xml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="http://maven.apache.org/POM/4.0.0"
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66

@@ -102,12 +102,7 @@
102102
</dependency>
103103

104104

105-
<!-- tlsh -->
106-
<dependency>
107-
<groupId>com.trendmicro</groupId>
108-
<artifactId>tlsh</artifactId>
109-
<version>3.7.1</version>
110-
</dependency>
105+
111106

112107

113108
<!-- https://mvnrepository.com/artifact/commons-codec/commons-codec -->
Lines changed: 71 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import com.github.difflib.DiffUtils;
22
import com.github.difflib.algorithm.DiffException;
33
import com.github.difflib.patch.Patch;
4+
import org.junit.Assert;
5+
import org.junit.Ignore;
6+
import org.junit.Test;
7+
import org.junit.runner.RunWith;
8+
import org.junit.runners.Parameterized;
9+
import org.objectweb.asm.ClassReader;
10+
import org.objectweb.asm.util.TraceClassVisitor;
11+
412
import java.io.ByteArrayOutputStream;
513
import java.io.File;
614
import java.io.FileInputStream;
@@ -10,13 +18,6 @@
1018
import java.util.ArrayList;
1119
import java.util.Collection;
1220
import java.util.List;
13-
import org.junit.Assert;
14-
import org.junit.Ignore;
15-
import org.junit.Test;
16-
import org.junit.runner.RunWith;
17-
import org.junit.runners.Parameterized;
18-
import org.objectweb.asm.ClassReader;
19-
import org.objectweb.asm.util.TraceClassVisitor;
2021

2122
/**
2223
* Contains bytecode comparisons that are expected to fail
@@ -27,89 +28,89 @@
2728
@RunWith(Parameterized.class)
2829
public class ByteCodeCompareClasses {
2930

30-
private final String referenceFolder;
31-
private final String otherFolder;
32-
private final File filename;
31+
private final String referenceFolder;
32+
private final String otherFolder;
33+
private final File filename;
3334

34-
@Parameterized.Parameters
35-
public static Collection<Object[]> generateParams() {
36-
List<Object[]> params = new ArrayList<Object[]>();
35+
public ByteCodeCompareClasses(String referenceFolder, String otherFolder, File filename) {
36+
this.referenceFolder = referenceFolder;
37+
this.otherFolder = otherFolder;
38+
this.filename = filename;
39+
}
3740

38-
params.addAll(createParaList("reference", "1.5"));
39-
params.addAll(createParaList("reference", "1.6"));
40-
params.addAll(createParaList("reference", "1.7"));
41+
@Parameterized.Parameters
42+
public static Collection<Object[]> generateParams() {
43+
List<Object[]> params = new ArrayList<Object[]>();
4144

42-
params.addAll(createParaList("reference", "ecj1.5"));
43-
params.addAll(createParaList("reference", "ecj1.6"));
44-
params.addAll(createParaList("reference", "ecj1.7"));
45-
params.addAll(createParaList("reference", "ecj1.8"));
45+
params.addAll(createParaList("reference", "1.5"));
46+
params.addAll(createParaList("reference", "1.6"));
47+
params.addAll(createParaList("reference", "1.7"));
4648

47-
// params.addAll(createParaList("reference", "gcj1.5"));
48-
// params.addAll(createParaList("reference", "gcj1.6"));
49+
params.addAll(createParaList("reference", "ecj1.5"));
50+
params.addAll(createParaList("reference", "ecj1.6"));
51+
params.addAll(createParaList("reference", "ecj1.7"));
52+
params.addAll(createParaList("reference", "ecj1.8"));
4953

50-
return params;
51-
}
54+
// params.addAll(createParaList("reference", "gcj1.5"));
55+
// params.addAll(createParaList("reference", "gcj1.6"));
5256

53-
public static List<Object[]> createParaList(String refeFolder, String cmpFolder) {
54-
List<Object[]> params = new ArrayList<Object[]>();
57+
return params;
58+
}
5559

56-
URL url = ByteCodeCompareClasses.class.getResource("/" + refeFolder);
57-
File refClass = new File(url.getFile());
60+
public static List<Object[]> createParaList(String refeFolder, String cmpFolder) {
61+
List<Object[]> params = new ArrayList<Object[]>();
5862

59-
// the other class
60-
URL otherurl = ByteCodeCompareClasses.class.getResource("/" + cmpFolder);
61-
String otherFolder = new File(otherurl.getFile()).toString();
63+
URL url = ByteCodeCompareClasses.class.getResource("/" + refeFolder);
64+
File refClass = new File(url.getFile());
6265

63-
File[] listOfFiles = refClass.listFiles();
66+
// the other class
67+
URL otherurl = ByteCodeCompareClasses.class.getResource("/" + cmpFolder);
68+
String otherFolder = new File(otherurl.getFile()).toString();
6469

65-
for (File filename : listOfFiles) {
70+
File[] listOfFiles = refClass.listFiles();
6671

67-
params.add(new Object[] {refClass.toString(), otherFolder, filename});
68-
}
69-
return params;
70-
}
72+
for (File filename : listOfFiles) {
7173

72-
public ByteCodeCompareClasses(String referenceFolder, String otherFolder, File filename) {
73-
this.referenceFolder = referenceFolder;
74-
this.otherFolder = otherFolder;
75-
this.filename = filename;
76-
}
74+
params.add(new Object[]{refClass.toString(), otherFolder, filename});
75+
}
76+
return params;
77+
}
7778

78-
@Test
79-
public void test() throws IOException, DiffException {
80-
String qname = filename.getName().substring(0, filename.getName().indexOf("."));
79+
@Test
80+
public void test() throws IOException, DiffException {
81+
String qname = filename.getName().substring(0, filename.getName().indexOf("."));
8182

82-
System.out.println(
83-
"Compare " + referenceFolder + " against " + otherFolder + " using class " + qname);
83+
System.out.println(
84+
"Compare " + referenceFolder + " against " + otherFolder + " using class " + qname);
8485

85-
ClassReader cr = new ClassReader(new FileInputStream(filename));
86-
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
86+
ClassReader cr = new ClassReader(new FileInputStream(filename));
87+
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
8788

88-
cr.accept(
89-
new TraceClassVisitor(new PrintWriter(byteArrayOutputStream)), ClassReader.SKIP_DEBUG);
89+
cr.accept(
90+
new TraceClassVisitor(new PrintWriter(byteArrayOutputStream)), ClassReader.SKIP_DEBUG);
9091

91-
String filename2 = otherFolder + "/" + qname + ".class";
92-
ClassReader cr2 = new ClassReader(new FileInputStream(filename2));
93-
ByteArrayOutputStream byteArrayOutputStream2 = new ByteArrayOutputStream();
92+
String filename2 = otherFolder + "/" + qname + ".class";
93+
ClassReader cr2 = new ClassReader(new FileInputStream(filename2));
94+
ByteArrayOutputStream byteArrayOutputStream2 = new ByteArrayOutputStream();
9495

95-
cr2.accept(
96-
new TraceClassVisitor(new PrintWriter(byteArrayOutputStream2)), ClassReader.SKIP_DEBUG);
96+
cr2.accept(
97+
new TraceClassVisitor(new PrintWriter(byteArrayOutputStream2)), ClassReader.SKIP_DEBUG);
9798

98-
Patch<String> diff =
99-
DiffUtils.diff(byteArrayOutputStream.toString(), byteArrayOutputStream2.toString(), null);
100-
System.out.println("Number of diffs: " + diff.getDeltas().size());
101-
System.out.println(diff);
99+
Patch<String> diff =
100+
DiffUtils.diff(byteArrayOutputStream.toString(), byteArrayOutputStream2.toString(), null);
101+
System.out.println("Number of diffs: " + diff.getDeltas().size());
102+
System.out.println(diff);
102103

103-
boolean condition = diff.getDeltas().size() <= 1;
104+
boolean condition = diff.getDeltas().size() <= 1;
104105

105-
System.out.println(
106-
"Latex: "
107-
+ filename
108-
+ " "
109-
+ otherFolder.substring(otherFolder.lastIndexOf("/", otherFolder.length() - 1))
110-
+ " : "
111-
+ condition);
106+
System.out.println(
107+
"Latex: "
108+
+ filename
109+
+ " "
110+
+ otherFolder.substring(otherFolder.lastIndexOf("/", otherFolder.length() - 1))
111+
+ " : "
112+
+ condition);
112113

113-
Assert.assertTrue(condition);
114-
}
114+
Assert.assertTrue(condition);
115+
}
115116
}

0 commit comments

Comments
 (0)