From b6c83e66ece8c4b0b9658424e5e58f808c71a3aa Mon Sep 17 00:00:00 2001 From: palaniappan1 Date: Fri, 16 Jun 2023 11:09:48 +0200 Subject: [PATCH 01/90] ICFG CallGraph export init --- .gitignore | 1 + .../icfg/JimpleBasedInterproceduralCFG.java | 18 +++++++ .../ifds/ICFGCallGraphTest.java | 16 +++++++ .../test/resources/callgraph/ICFGExample.java | 27 +++++++++++ .../resources/taint/binary/ICFGExample.class | Bin 0 -> 613 bytes .../java/sootup/core/util/DotExporter.java | 45 ++++++++++++++---- .../sootup/core/util/ICFGDotExporter.java | 44 +++++++++++++++++ 7 files changed, 141 insertions(+), 10 deletions(-) create mode 100644 sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java create mode 100644 sootup.analysis/src/test/resources/callgraph/ICFGExample.java create mode 100644 sootup.analysis/src/test/resources/taint/binary/ICFGExample.class create mode 100644 sootup.core/src/main/java/sootup/core/util/ICFGDotExporter.java diff --git a/.gitignore b/.gitignore index 5ef291e46f7..e0e9c14a399 100644 --- a/.gitignore +++ b/.gitignore @@ -165,3 +165,4 @@ fabric.properties .vscode/settings.json ======= .vscode/ +.DS_Store diff --git a/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java b/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java index e1d908aad23..15f5a85fdc5 100644 --- a/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java +++ b/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java @@ -39,10 +39,12 @@ import sootup.callgraph.CallGraph; import sootup.callgraph.CallGraphAlgorithm; 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.util.ICFGDotExporter; import sootup.core.views.View; import sootup.java.core.views.JavaView; @@ -146,6 +148,22 @@ public JimpleBasedInterproceduralCFG( this.mainMethodSignature = mainMethodSignature; cg = initCallGraph(); initializeStmtToOwner(); + buildICFGGraph(); + } + + private void buildICFGGraph(){ + ArrayList stmtGraphSet = new ArrayList<>(); + // To Sort the methodSignature set with entrypoint as the first element. + Set methodSignatures = cg.getMethodSignatures(); + methodSignatures.remove(mainMethodSignature); + List list = new ArrayList<>(methodSignatures); + list.add(0,mainMethodSignature); + LinkedHashSet sortedMethodSignature = new LinkedHashSet<>(list); + for (MethodSignature methodSignature : sortedMethodSignature) { + final Optional methodOpt = view.getMethod(methodSignature); + methodOpt.ifPresent(sootMethod -> stmtGraphSet.add(sootMethod.getBody().getStmtGraph())); + } + final String ICFGCallGraph = ICFGDotExporter.buildICFGGraph(stmtGraphSet, sortedMethodSignature); } private CallGraph initCallGraph() { diff --git a/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java b/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java new file mode 100644 index 00000000000..d91318823a3 --- /dev/null +++ b/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java @@ -0,0 +1,16 @@ +package sootup.analysis.interprocedural.ifds; + + +import heros.InterproceduralCFG; +import org.junit.Test; +import sootup.core.jimple.common.stmt.Stmt; +import sootup.core.model.SootMethod; + +public class ICFGCallGraphTest extends IFDSTaintTestSetUp{ + + @Test + public void ICFGDotExportTest() { + JimpleIFDSSolver> analysis = + executeStaticAnalysis("ICFGExample"); + } +} diff --git a/sootup.analysis/src/test/resources/callgraph/ICFGExample.java b/sootup.analysis/src/test/resources/callgraph/ICFGExample.java new file mode 100644 index 00000000000..a180c55706b --- /dev/null +++ b/sootup.analysis/src/test/resources/callgraph/ICFGExample.java @@ -0,0 +1,27 @@ + +public class ICFGExample { + public ICFGExample() { + } + + private String id(String var1) { + return var1; + } + + private void sink(String var1) { + secondMethod(var1); + } + + private void secondMethod(String var1){ + thirdMethod(var1); + } + + public String thirdMethod(String var1){ + return var1; + } + + public void entryPoint() { + String var1 = "SECRET"; + String var2 = this.id(var1); + this.sink(var2); + } +} \ No newline at end of file diff --git a/sootup.analysis/src/test/resources/taint/binary/ICFGExample.class b/sootup.analysis/src/test/resources/taint/binary/ICFGExample.class new file mode 100644 index 0000000000000000000000000000000000000000..240816ec8e5db6a0095b8c97f7433d3a88d2e104 GIT binary patch literal 613 zcmZ{h&rZTX5XQf4fkLSiK?Lznf+hyR$ibtA3jt#SYJ}*y&Kd{mt~_^X(l#6+1c=ht`8t8Cg!ha@ig7p3e|D6^`($ z3~KSof?*)2I z>Q`=;8%*Mr2( graph) { + public static String buildGraph(@Nonnull StmtGraph graph, boolean isICFG, Map calls, MethodSignature methodSignature) { // TODO: hint: use edge weight to have a better top->down code like linear layouting with // starting stmt at the top; @@ -27,14 +29,12 @@ public static String buildGraph(@Nonnull StmtGraph graph) { // blocks StringBuilder sb = new StringBuilder(); - sb.append("digraph G {\n") - .append("\tcompound=true\n") - .append("\tlabelloc=b\n") - .append("\tstyle=filled\n") - .append("\tcolor=gray90\n") - .append("\tnode [shape=box,style=filled,color=white]\n") - .append("\tedge [fontsize=10,arrowsize=1.5,fontcolor=grey40]\n") - .append("\tfontsize=10\n\n"); + + boolean isAdded = false; + + if(!isICFG) { + buildDiGraphObject(sb); + } /* entrypoint */ Stmt startingStmt = graph.getStartingStmt(); @@ -86,6 +86,16 @@ public static String buildGraph(@Nonnull StmtGraph graph) { if (stmts.size() > 1) { sb.append("\n\t\t"); for (Stmt stmt : stmts) { + if(methodSignature != null && calls != null){ + for (Map.Entry entry : calls.entrySet()) { + int key = entry.getKey(); + MethodSignature value = entry.getValue(); + if(methodSignature == value && !isAdded){ + sb.append(key).append(" -> "); + isAdded = true; + } + } + } sb.append(stmt.hashCode()).append(" -> "); } sb.delete(sb.length() - 4, sb.length()); @@ -158,7 +168,10 @@ public static String buildGraph(@Nonnull StmtGraph graph) { sb.append("\n"); } + if(!isICFG) return sb.append("}").toString(); + else + return sb.toString(); } private static String escape(String str) { @@ -166,10 +179,22 @@ private static String escape(String str) { return StringEscapeUtils.escapeXml10(str); } + public static StringBuilder buildDiGraphObject(StringBuilder sb){ + sb.append("digraph G {\n") + .append("\tcompound=true\n") + .append("\tlabelloc=b\n") + .append("\tstyle=filled\n") + .append("\tcolor=gray90\n") + .append("\tnode [shape=box,style=filled,color=white]\n") + .append("\tedge [fontsize=10,arrowsize=1.5,fontcolor=grey40]\n") + .append("\tfontsize=10\n\n"); + return sb; + } + public static String createUrlToWebeditor(@Nonnull StmtGraph graph) { try { return "http://magjac.com/graphviz-visual-editor/?dot=" - + URLEncoder.encode(buildGraph(graph), "UTF-8"); + + URLEncoder.encode(buildGraph(graph, false, null, null), "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } diff --git a/sootup.core/src/main/java/sootup/core/util/ICFGDotExporter.java b/sootup.core/src/main/java/sootup/core/util/ICFGDotExporter.java new file mode 100644 index 00000000000..1012ca24ff7 --- /dev/null +++ b/sootup.core/src/main/java/sootup/core/util/ICFGDotExporter.java @@ -0,0 +1,44 @@ +package sootup.core.util; + +import org.slf4j.event.KeyValuePair; +import sootup.core.graph.BasicBlock; +import sootup.core.graph.StmtGraph; +import sootup.core.jimple.common.stmt.Stmt; +import sootup.core.signatures.MethodSignature; + +import java.util.*; + +public class ICFGDotExporter { + + static final StringBuilder sb = new StringBuilder(); + public static String buildICFGGraph(ArrayList stmtGraphSet, LinkedHashSet sortedMethodSignature){ + DotExporter.buildDiGraphObject(sb); + int i = 0; + Map calls = new HashMap<>(); + for(StmtGraph stmtGraph : stmtGraphSet){ + Collection> blocks; + try { + blocks = stmtGraph.getBlocksSorted(); + } catch (Exception e) { + blocks = stmtGraph.getBlocks(); + } + for(BasicBlock block : blocks){ + List stmts = block.getStmts(); + for(Stmt stmt : stmts){ + if(stmt.containsInvokeExpr()){ + MethodSignature methodSignature = stmt.getInvokeExpr().getMethodSignature(); + int hashCode = stmt.hashCode(); + calls.put(hashCode,methodSignature); + } + } + } + List list = new ArrayList<>(sortedMethodSignature); + String graph = DotExporter.buildGraph(stmtGraph, true, calls,list.get(i)); + sb.append(graph + "\n"); + i++; + } + sb.append("}"); + return sb.toString(); + } + +} From 87cb32ba714650f939350e5bdf479c0ac43d3270 Mon Sep 17 00:00:00 2001 From: palaniappan1 Date: Mon, 19 Jun 2023 18:08:24 +0200 Subject: [PATCH 02/90] ICFG DotExporter --- .../java/sootup/core/util/DotExporter.java | 2 +- .../sootup/core/util/ICFGDotExporter.java | 25 +++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/util/DotExporter.java b/sootup.core/src/main/java/sootup/core/util/DotExporter.java index ab7cdeb1c7b..85ff5a6d9fd 100644 --- a/sootup.core/src/main/java/sootup/core/util/DotExporter.java +++ b/sootup.core/src/main/java/sootup/core/util/DotExporter.java @@ -90,7 +90,7 @@ public static String buildGraph(@Nonnull StmtGraph graph, boolean isICFG, Map for (Map.Entry entry : calls.entrySet()) { int key = entry.getKey(); MethodSignature value = entry.getValue(); - if(methodSignature == value && !isAdded){ + if(methodSignature.equals(value) && !isAdded){ sb.append(key).append(" -> "); isAdded = true; } diff --git a/sootup.core/src/main/java/sootup/core/util/ICFGDotExporter.java b/sootup.core/src/main/java/sootup/core/util/ICFGDotExporter.java index 1012ca24ff7..ed93d1ae44d 100644 --- a/sootup.core/src/main/java/sootup/core/util/ICFGDotExporter.java +++ b/sootup.core/src/main/java/sootup/core/util/ICFGDotExporter.java @@ -1,6 +1,5 @@ package sootup.core.util; -import org.slf4j.event.KeyValuePair; import sootup.core.graph.BasicBlock; import sootup.core.graph.StmtGraph; import sootup.core.jimple.common.stmt.Stmt; @@ -14,6 +13,23 @@ public class ICFGDotExporter { public static String buildICFGGraph(ArrayList stmtGraphSet, LinkedHashSet sortedMethodSignature){ DotExporter.buildDiGraphObject(sb); int i = 0; + Map calls; + for(StmtGraph stmtGraph : stmtGraphSet){ + calls = computeCalls(stmtGraphSet); + List list = new ArrayList<>(sortedMethodSignature); + String graph = DotExporter.buildGraph(stmtGraph, true, calls,list.get(i)); + sb.append(graph + "\n"); + i++; + } + sb.append("}"); + return sb.toString(); + } + + /** + * This method finds out all the calls made in the given StmtGraphs, so it can be edged to + * other methods. + * */ + private static Map computeCalls(ArrayList stmtGraphSet){ Map calls = new HashMap<>(); for(StmtGraph stmtGraph : stmtGraphSet){ Collection> blocks; @@ -32,13 +48,8 @@ public static String buildICFGGraph(ArrayList stmtGraphSet, LinkedHas } } } - List list = new ArrayList<>(sortedMethodSignature); - String graph = DotExporter.buildGraph(stmtGraph, true, calls,list.get(i)); - sb.append(graph + "\n"); - i++; } - sb.append("}"); - return sb.toString(); + return calls; } } From 93d0e769559dd5fdb5936a789e3e7381cdd5c484 Mon Sep 17 00:00:00 2001 From: palaniappan1 Date: Thu, 29 Jun 2023 17:24:28 +0200 Subject: [PATCH 03/90] ICFG CallGraph Export Test written does not make sense, as i am comparing two same strings. --- .../icfg/JimpleBasedInterproceduralCFG.java | 5 +- .../ifds/ICFGCallGraphTest.java | 106 +++++++++++++++++- 2 files changed, 106 insertions(+), 5 deletions(-) diff --git a/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java b/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java index 15f5a85fdc5..faf0eca6783 100644 --- a/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java +++ b/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java @@ -148,10 +148,9 @@ public JimpleBasedInterproceduralCFG( this.mainMethodSignature = mainMethodSignature; cg = initCallGraph(); initializeStmtToOwner(); - buildICFGGraph(); } - private void buildICFGGraph(){ + public String buildICFGGraph(){ ArrayList stmtGraphSet = new ArrayList<>(); // To Sort the methodSignature set with entrypoint as the first element. Set methodSignatures = cg.getMethodSignatures(); @@ -163,7 +162,7 @@ private void buildICFGGraph(){ final Optional methodOpt = view.getMethod(methodSignature); methodOpt.ifPresent(sootMethod -> stmtGraphSet.add(sootMethod.getBody().getStmtGraph())); } - final String ICFGCallGraph = ICFGDotExporter.buildICFGGraph(stmtGraphSet, sortedMethodSignature); + return ICFGDotExporter.buildICFGGraph(stmtGraphSet, sortedMethodSignature); } private CallGraph initCallGraph() { diff --git a/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java b/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java index d91318823a3..79b36411a59 100644 --- a/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java +++ b/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java @@ -3,14 +3,116 @@ import heros.InterproceduralCFG; import org.junit.Test; +import sootup.analysis.interprocedural.icfg.JimpleBasedInterproceduralCFG; import sootup.core.jimple.common.stmt.Stmt; +import sootup.core.model.SootClass; import sootup.core.model.SootMethod; +import sootup.java.bytecode.inputlocation.JavaClassPathAnalysisInputLocation; +import sootup.java.core.JavaIdentifierFactory; +import sootup.java.core.JavaProject; +import sootup.java.core.language.JavaLanguage; +import sootup.java.core.types.JavaClassType; +import sootup.java.core.views.JavaView; +import sootup.java.sourcecode.inputlocation.JavaSourcePathAnalysisInputLocation; + +import static junit.framework.TestCase.assertEquals; public class ICFGCallGraphTest extends IFDSTaintTestSetUp{ @Test public void ICFGDotExportTest() { - JimpleIFDSSolver> analysis = - executeStaticAnalysis("ICFGExample"); + JavaProject javaProject = + JavaProject.builder(new JavaLanguage(8)) + .addInputLocation( + new JavaClassPathAnalysisInputLocation( + System.getProperty("java.home") + "/lib/rt.jar")) + .addInputLocation( + new JavaClassPathAnalysisInputLocation("src/test/resources/taint/binary")) + .build(); + + view = javaProject.createView(); + + JavaIdentifierFactory identifierFactory = JavaIdentifierFactory.getInstance(); + JavaClassType mainClassSignature = identifierFactory.getClassType("ICFGExample"); + + SootClass sc = view.getClass(mainClassSignature).get(); + entryMethod = + sc.getMethods().stream().filter(e -> e.getName().equals("entryPoint")).findFirst().get(); + + entryMethodSignature = entryMethod.getSignature(); + + JimpleBasedInterproceduralCFG icfg = + new JimpleBasedInterproceduralCFG(view, entryMethodSignature, false, false); + String expectedCallGraph = "digraph G {\n" + + "\tcompound=true\n" + + "\tlabelloc=b\n" + + "\tstyle=filled\n" + + "\tcolor=gray90\n" + + "\tnode [shape=box,style=filled,color=white]\n" + + "\tedge [fontsize=10,arrowsize=1.5,fontcolor=grey40]\n" + + "\tfontsize=10\n" + + "\n" + + "// lines [23: 26] \n" + + "\tsubgraph cluster_1320677379 { \n" + + "\t\tlabel = \"Block #1\"\n" + + "\t\t171497379[label=\"l0 := @this: ICFGExample\",shape=Mdiamond,color=grey50,fillcolor=white]\n" + + "\t\t1665404403[label=\"l1 = "SECRET"\"]\n" + + "\t\t988458918[label=\"l2 = virtualinvoke l0.<ICFGExample: java.lang.String id(java.lang.String)>(l1)\"]\n" + + "\t\t1990451863[label=\"virtualinvoke l0.<ICFGExample: void sink(java.lang.String)>(l2)\"]\n" + + "\t\t1295083508[label=\"return\",shape=Mdiamond,color=grey50,fillcolor=white]\n" + + "\n" + + "\t\t171497379 -> 1665404403 -> 988458918 -> 1990451863 -> 1295083508\n" + + "\t}\n" + + "\n" + + "\n" + + "// lines [11: 12] \n" + + "\tsubgraph cluster_2137366542 { \n" + + "\t\tlabel = \"Block #1\"\n" + + "\t\t2018981974[label=\"l0 := @this: ICFGExample\",shape=Mdiamond,color=grey50,fillcolor=white]\n" + + "\t\t905009026[label=\"l1 := @parameter0: java.lang.String\"]\n" + + "\t\t602908276[label=\"virtualinvoke l0.<ICFGExample: void secondMethod(java.lang.String)>(l1)\"]\n" + + "\t\t1648078807[label=\"return\",shape=Mdiamond,color=grey50,fillcolor=white]\n" + + "\n" + + "\t\t1990451863 -> 2018981974 -> 905009026 -> 602908276 -> 1648078807\n" + + "\t}\n" + + "\n" + + "\n" + + "// lines [7: 7] \n" + + "\tsubgraph cluster_603702962 { \n" + + "\t\tlabel = \"Block #1\"\n" + + "\t\t1698148964[label=\"l0 := @this: ICFGExample\",shape=Mdiamond,color=grey50,fillcolor=white]\n" + + "\t\t1288983035[label=\"l1 := @parameter0: java.lang.String\"]\n" + + "\t\t2064117540[label=\"return l1\",shape=Mdiamond,color=grey50,fillcolor=white]\n" + + "\n" + + "\t\t988458918 -> 1698148964 -> 1288983035 -> 2064117540\n" + + "\t}\n" + + "\n" + + "\n" + + "// lines [15: 16] \n" + + "\tsubgraph cluster_2116251487 { \n" + + "\t\tlabel = \"Block #1\"\n" + + "\t\t329293111[label=\"l0 := @this: ICFGExample\",shape=Mdiamond,color=grey50,fillcolor=white]\n" + + "\t\t1770804671[label=\"l1 := @parameter0: java.lang.String\"]\n" + + "\t\t1172514862[label=\"$stack2 = virtualinvoke l0.<ICFGExample: java.lang.String thirdMethod(java.lang.String)>(l1)\"]\n" + + "\t\t1388137600[label=\"return\",shape=Mdiamond,color=grey50,fillcolor=white]\n" + + "\n" + + "\t\t602908276 -> 329293111 -> 1770804671 -> 1172514862 -> 1388137600\n" + + "\t}\n" + + "\n" + + "\n" + + "// lines [19: 19] \n" + + "\tsubgraph cluster_1780885275 { \n" + + "\t\tlabel = \"Block #1\"\n" + + "\t\t2058348472[label=\"l0 := @this: ICFGExample\",shape=Mdiamond,color=grey50,fillcolor=white]\n" + + "\t\t2126618194[label=\"l1 := @parameter0: java.lang.String\"]\n" + + "\t\t1865523042[label=\"return l1\",shape=Mdiamond,color=grey50,fillcolor=white]\n" + + "\n" + + "\t\t1172514862 -> 2058348472 -> 2126618194 -> 1865523042\n" + + "\t}\n" + + "\n" + + "\n" + + "}"; + assertEquals(expectedCallGraph,icfg.buildICFGGraph()); } + } From 758e74e8d83db648e13e7b3d459e30efde603769 Mon Sep 17 00:00:00 2001 From: palaniappan1 Date: Thu, 29 Jun 2023 17:27:30 +0200 Subject: [PATCH 04/90] fmt commit --- .../icfg/JimpleBasedInterproceduralCFG.java | 4 +- .../ifds/ICFGCallGraphTest.java | 192 +++++++++--------- .../java/sootup/core/util/DotExporter.java | 35 ++-- .../sootup/core/util/ICFGDotExporter.java | 82 ++++---- 4 files changed, 154 insertions(+), 159 deletions(-) diff --git a/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java b/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java index faf0eca6783..a41cbc64fa8 100644 --- a/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java +++ b/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java @@ -150,13 +150,13 @@ public JimpleBasedInterproceduralCFG( initializeStmtToOwner(); } - public String buildICFGGraph(){ + public String buildICFGGraph() { ArrayList stmtGraphSet = new ArrayList<>(); // To Sort the methodSignature set with entrypoint as the first element. Set methodSignatures = cg.getMethodSignatures(); methodSignatures.remove(mainMethodSignature); List list = new ArrayList<>(methodSignatures); - list.add(0,mainMethodSignature); + list.add(0, mainMethodSignature); LinkedHashSet sortedMethodSignature = new LinkedHashSet<>(list); for (MethodSignature methodSignature : sortedMethodSignature) { final Optional methodOpt = view.getMethod(methodSignature); diff --git a/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java b/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java index 79b36411a59..3901f9a158f 100644 --- a/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java +++ b/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java @@ -1,118 +1,112 @@ package sootup.analysis.interprocedural.ifds; +import static junit.framework.TestCase.assertEquals; -import heros.InterproceduralCFG; import org.junit.Test; import sootup.analysis.interprocedural.icfg.JimpleBasedInterproceduralCFG; -import sootup.core.jimple.common.stmt.Stmt; import sootup.core.model.SootClass; -import sootup.core.model.SootMethod; import sootup.java.bytecode.inputlocation.JavaClassPathAnalysisInputLocation; import sootup.java.core.JavaIdentifierFactory; import sootup.java.core.JavaProject; import sootup.java.core.language.JavaLanguage; import sootup.java.core.types.JavaClassType; -import sootup.java.core.views.JavaView; -import sootup.java.sourcecode.inputlocation.JavaSourcePathAnalysisInputLocation; - -import static junit.framework.TestCase.assertEquals; - -public class ICFGCallGraphTest extends IFDSTaintTestSetUp{ - @Test - public void ICFGDotExportTest() { - JavaProject javaProject = - JavaProject.builder(new JavaLanguage(8)) - .addInputLocation( - new JavaClassPathAnalysisInputLocation( - System.getProperty("java.home") + "/lib/rt.jar")) - .addInputLocation( - new JavaClassPathAnalysisInputLocation("src/test/resources/taint/binary")) - .build(); +public class ICFGCallGraphTest extends IFDSTaintTestSetUp { - view = javaProject.createView(); + @Test + public void ICFGDotExportTest() { + JavaProject javaProject = + JavaProject.builder(new JavaLanguage(8)) + .addInputLocation( + new JavaClassPathAnalysisInputLocation( + System.getProperty("java.home") + "/lib/rt.jar")) + .addInputLocation( + new JavaClassPathAnalysisInputLocation("src/test/resources/taint/binary")) + .build(); - JavaIdentifierFactory identifierFactory = JavaIdentifierFactory.getInstance(); - JavaClassType mainClassSignature = identifierFactory.getClassType("ICFGExample"); + view = javaProject.createView(); - SootClass sc = view.getClass(mainClassSignature).get(); - entryMethod = - sc.getMethods().stream().filter(e -> e.getName().equals("entryPoint")).findFirst().get(); + JavaIdentifierFactory identifierFactory = JavaIdentifierFactory.getInstance(); + JavaClassType mainClassSignature = identifierFactory.getClassType("ICFGExample"); - entryMethodSignature = entryMethod.getSignature(); + SootClass sc = view.getClass(mainClassSignature).get(); + entryMethod = + sc.getMethods().stream().filter(e -> e.getName().equals("entryPoint")).findFirst().get(); - JimpleBasedInterproceduralCFG icfg = - new JimpleBasedInterproceduralCFG(view, entryMethodSignature, false, false); - String expectedCallGraph = "digraph G {\n" + - "\tcompound=true\n" + - "\tlabelloc=b\n" + - "\tstyle=filled\n" + - "\tcolor=gray90\n" + - "\tnode [shape=box,style=filled,color=white]\n" + - "\tedge [fontsize=10,arrowsize=1.5,fontcolor=grey40]\n" + - "\tfontsize=10\n" + - "\n" + - "// lines [23: 26] \n" + - "\tsubgraph cluster_1320677379 { \n" + - "\t\tlabel = \"Block #1\"\n" + - "\t\t171497379[label=\"l0 := @this: ICFGExample\",shape=Mdiamond,color=grey50,fillcolor=white]\n" + - "\t\t1665404403[label=\"l1 = "SECRET"\"]\n" + - "\t\t988458918[label=\"l2 = virtualinvoke l0.<ICFGExample: java.lang.String id(java.lang.String)>(l1)\"]\n" + - "\t\t1990451863[label=\"virtualinvoke l0.<ICFGExample: void sink(java.lang.String)>(l2)\"]\n" + - "\t\t1295083508[label=\"return\",shape=Mdiamond,color=grey50,fillcolor=white]\n" + - "\n" + - "\t\t171497379 -> 1665404403 -> 988458918 -> 1990451863 -> 1295083508\n" + - "\t}\n" + - "\n" + - "\n" + - "// lines [11: 12] \n" + - "\tsubgraph cluster_2137366542 { \n" + - "\t\tlabel = \"Block #1\"\n" + - "\t\t2018981974[label=\"l0 := @this: ICFGExample\",shape=Mdiamond,color=grey50,fillcolor=white]\n" + - "\t\t905009026[label=\"l1 := @parameter0: java.lang.String\"]\n" + - "\t\t602908276[label=\"virtualinvoke l0.<ICFGExample: void secondMethod(java.lang.String)>(l1)\"]\n" + - "\t\t1648078807[label=\"return\",shape=Mdiamond,color=grey50,fillcolor=white]\n" + - "\n" + - "\t\t1990451863 -> 2018981974 -> 905009026 -> 602908276 -> 1648078807\n" + - "\t}\n" + - "\n" + - "\n" + - "// lines [7: 7] \n" + - "\tsubgraph cluster_603702962 { \n" + - "\t\tlabel = \"Block #1\"\n" + - "\t\t1698148964[label=\"l0 := @this: ICFGExample\",shape=Mdiamond,color=grey50,fillcolor=white]\n" + - "\t\t1288983035[label=\"l1 := @parameter0: java.lang.String\"]\n" + - "\t\t2064117540[label=\"return l1\",shape=Mdiamond,color=grey50,fillcolor=white]\n" + - "\n" + - "\t\t988458918 -> 1698148964 -> 1288983035 -> 2064117540\n" + - "\t}\n" + - "\n" + - "\n" + - "// lines [15: 16] \n" + - "\tsubgraph cluster_2116251487 { \n" + - "\t\tlabel = \"Block #1\"\n" + - "\t\t329293111[label=\"l0 := @this: ICFGExample\",shape=Mdiamond,color=grey50,fillcolor=white]\n" + - "\t\t1770804671[label=\"l1 := @parameter0: java.lang.String\"]\n" + - "\t\t1172514862[label=\"$stack2 = virtualinvoke l0.<ICFGExample: java.lang.String thirdMethod(java.lang.String)>(l1)\"]\n" + - "\t\t1388137600[label=\"return\",shape=Mdiamond,color=grey50,fillcolor=white]\n" + - "\n" + - "\t\t602908276 -> 329293111 -> 1770804671 -> 1172514862 -> 1388137600\n" + - "\t}\n" + - "\n" + - "\n" + - "// lines [19: 19] \n" + - "\tsubgraph cluster_1780885275 { \n" + - "\t\tlabel = \"Block #1\"\n" + - "\t\t2058348472[label=\"l0 := @this: ICFGExample\",shape=Mdiamond,color=grey50,fillcolor=white]\n" + - "\t\t2126618194[label=\"l1 := @parameter0: java.lang.String\"]\n" + - "\t\t1865523042[label=\"return l1\",shape=Mdiamond,color=grey50,fillcolor=white]\n" + - "\n" + - "\t\t1172514862 -> 2058348472 -> 2126618194 -> 1865523042\n" + - "\t}\n" + - "\n" + - "\n" + - "}"; - assertEquals(expectedCallGraph,icfg.buildICFGGraph()); - } + entryMethodSignature = entryMethod.getSignature(); + JimpleBasedInterproceduralCFG icfg = + new JimpleBasedInterproceduralCFG(view, entryMethodSignature, false, false); + String expectedCallGraph = + "digraph G {\n" + + "\tcompound=true\n" + + "\tlabelloc=b\n" + + "\tstyle=filled\n" + + "\tcolor=gray90\n" + + "\tnode [shape=box,style=filled,color=white]\n" + + "\tedge [fontsize=10,arrowsize=1.5,fontcolor=grey40]\n" + + "\tfontsize=10\n" + + "\n" + + "// lines [23: 26] \n" + + "\tsubgraph cluster_1320677379 { \n" + + "\t\tlabel = \"Block #1\"\n" + + "\t\t171497379[label=\"l0 := @this: ICFGExample\",shape=Mdiamond,color=grey50,fillcolor=white]\n" + + "\t\t1665404403[label=\"l1 = "SECRET"\"]\n" + + "\t\t988458918[label=\"l2 = virtualinvoke l0.<ICFGExample: java.lang.String id(java.lang.String)>(l1)\"]\n" + + "\t\t1990451863[label=\"virtualinvoke l0.<ICFGExample: void sink(java.lang.String)>(l2)\"]\n" + + "\t\t1295083508[label=\"return\",shape=Mdiamond,color=grey50,fillcolor=white]\n" + + "\n" + + "\t\t171497379 -> 1665404403 -> 988458918 -> 1990451863 -> 1295083508\n" + + "\t}\n" + + "\n" + + "\n" + + "// lines [11: 12] \n" + + "\tsubgraph cluster_2137366542 { \n" + + "\t\tlabel = \"Block #1\"\n" + + "\t\t2018981974[label=\"l0 := @this: ICFGExample\",shape=Mdiamond,color=grey50,fillcolor=white]\n" + + "\t\t905009026[label=\"l1 := @parameter0: java.lang.String\"]\n" + + "\t\t602908276[label=\"virtualinvoke l0.<ICFGExample: void secondMethod(java.lang.String)>(l1)\"]\n" + + "\t\t1648078807[label=\"return\",shape=Mdiamond,color=grey50,fillcolor=white]\n" + + "\n" + + "\t\t1990451863 -> 2018981974 -> 905009026 -> 602908276 -> 1648078807\n" + + "\t}\n" + + "\n" + + "\n" + + "// lines [7: 7] \n" + + "\tsubgraph cluster_603702962 { \n" + + "\t\tlabel = \"Block #1\"\n" + + "\t\t1698148964[label=\"l0 := @this: ICFGExample\",shape=Mdiamond,color=grey50,fillcolor=white]\n" + + "\t\t1288983035[label=\"l1 := @parameter0: java.lang.String\"]\n" + + "\t\t2064117540[label=\"return l1\",shape=Mdiamond,color=grey50,fillcolor=white]\n" + + "\n" + + "\t\t988458918 -> 1698148964 -> 1288983035 -> 2064117540\n" + + "\t}\n" + + "\n" + + "\n" + + "// lines [15: 16] \n" + + "\tsubgraph cluster_2116251487 { \n" + + "\t\tlabel = \"Block #1\"\n" + + "\t\t329293111[label=\"l0 := @this: ICFGExample\",shape=Mdiamond,color=grey50,fillcolor=white]\n" + + "\t\t1770804671[label=\"l1 := @parameter0: java.lang.String\"]\n" + + "\t\t1172514862[label=\"$stack2 = virtualinvoke l0.<ICFGExample: java.lang.String thirdMethod(java.lang.String)>(l1)\"]\n" + + "\t\t1388137600[label=\"return\",shape=Mdiamond,color=grey50,fillcolor=white]\n" + + "\n" + + "\t\t602908276 -> 329293111 -> 1770804671 -> 1172514862 -> 1388137600\n" + + "\t}\n" + + "\n" + + "\n" + + "// lines [19: 19] \n" + + "\tsubgraph cluster_1780885275 { \n" + + "\t\tlabel = \"Block #1\"\n" + + "\t\t2058348472[label=\"l0 := @this: ICFGExample\",shape=Mdiamond,color=grey50,fillcolor=white]\n" + + "\t\t2126618194[label=\"l1 := @parameter0: java.lang.String\"]\n" + + "\t\t1865523042[label=\"return l1\",shape=Mdiamond,color=grey50,fillcolor=white]\n" + + "\n" + + "\t\t1172514862 -> 2058348472 -> 2126618194 -> 1865523042\n" + + "\t}\n" + + "\n" + + "\n" + + "}"; + assertEquals(expectedCallGraph, icfg.buildICFGGraph()); + } } diff --git a/sootup.core/src/main/java/sootup/core/util/DotExporter.java b/sootup.core/src/main/java/sootup/core/util/DotExporter.java index 85ff5a6d9fd..134435c9043 100644 --- a/sootup.core/src/main/java/sootup/core/util/DotExporter.java +++ b/sootup.core/src/main/java/sootup/core/util/DotExporter.java @@ -10,7 +10,6 @@ import sootup.core.graph.StmtGraph; import sootup.core.jimple.common.stmt.*; import sootup.core.jimple.javabytecode.stmt.JSwitchStmt; -import sootup.core.model.Method; import sootup.core.signatures.MethodSignature; import sootup.core.types.ClassType; @@ -21,7 +20,11 @@ */ public class DotExporter { - public static String buildGraph(@Nonnull StmtGraph graph, boolean isICFG, Map calls, MethodSignature methodSignature) { + public static String buildGraph( + @Nonnull StmtGraph graph, + boolean isICFG, + Map calls, + MethodSignature methodSignature) { // TODO: hint: use edge weight to have a better top->down code like linear layouting with // starting stmt at the top; @@ -32,7 +35,7 @@ public static String buildGraph(@Nonnull StmtGraph graph, boolean isICFG, Map boolean isAdded = false; - if(!isICFG) { + if (!isICFG) { buildDiGraphObject(sb); } @@ -86,11 +89,11 @@ public static String buildGraph(@Nonnull StmtGraph graph, boolean isICFG, Map if (stmts.size() > 1) { sb.append("\n\t\t"); for (Stmt stmt : stmts) { - if(methodSignature != null && calls != null){ + if (methodSignature != null && calls != null) { for (Map.Entry entry : calls.entrySet()) { int key = entry.getKey(); MethodSignature value = entry.getValue(); - if(methodSignature.equals(value) && !isAdded){ + if (methodSignature.equals(value) && !isAdded) { sb.append(key).append(" -> "); isAdded = true; } @@ -168,10 +171,8 @@ public static String buildGraph(@Nonnull StmtGraph graph, boolean isICFG, Map sb.append("\n"); } - if(!isICFG) - return sb.append("}").toString(); - else - return sb.toString(); + if (!isICFG) return sb.append("}").toString(); + else return sb.toString(); } private static String escape(String str) { @@ -179,15 +180,15 @@ private static String escape(String str) { return StringEscapeUtils.escapeXml10(str); } - public static StringBuilder buildDiGraphObject(StringBuilder sb){ + public static StringBuilder buildDiGraphObject(StringBuilder sb) { sb.append("digraph G {\n") - .append("\tcompound=true\n") - .append("\tlabelloc=b\n") - .append("\tstyle=filled\n") - .append("\tcolor=gray90\n") - .append("\tnode [shape=box,style=filled,color=white]\n") - .append("\tedge [fontsize=10,arrowsize=1.5,fontcolor=grey40]\n") - .append("\tfontsize=10\n\n"); + .append("\tcompound=true\n") + .append("\tlabelloc=b\n") + .append("\tstyle=filled\n") + .append("\tcolor=gray90\n") + .append("\tnode [shape=box,style=filled,color=white]\n") + .append("\tedge [fontsize=10,arrowsize=1.5,fontcolor=grey40]\n") + .append("\tfontsize=10\n\n"); return sb; } diff --git a/sootup.core/src/main/java/sootup/core/util/ICFGDotExporter.java b/sootup.core/src/main/java/sootup/core/util/ICFGDotExporter.java index ed93d1ae44d..6ee64445dba 100644 --- a/sootup.core/src/main/java/sootup/core/util/ICFGDotExporter.java +++ b/sootup.core/src/main/java/sootup/core/util/ICFGDotExporter.java @@ -1,55 +1,55 @@ package sootup.core.util; +import java.util.*; import sootup.core.graph.BasicBlock; import sootup.core.graph.StmtGraph; import sootup.core.jimple.common.stmt.Stmt; import sootup.core.signatures.MethodSignature; -import java.util.*; - public class ICFGDotExporter { - static final StringBuilder sb = new StringBuilder(); - public static String buildICFGGraph(ArrayList stmtGraphSet, LinkedHashSet sortedMethodSignature){ - DotExporter.buildDiGraphObject(sb); - int i = 0; - Map calls; - for(StmtGraph stmtGraph : stmtGraphSet){ - calls = computeCalls(stmtGraphSet); - List list = new ArrayList<>(sortedMethodSignature); - String graph = DotExporter.buildGraph(stmtGraph, true, calls,list.get(i)); - sb.append(graph + "\n"); - i++; - } - sb.append("}"); - return sb.toString(); + static final StringBuilder sb = new StringBuilder(); + + public static String buildICFGGraph( + ArrayList stmtGraphSet, LinkedHashSet sortedMethodSignature) { + DotExporter.buildDiGraphObject(sb); + int i = 0; + Map calls; + for (StmtGraph stmtGraph : stmtGraphSet) { + calls = computeCalls(stmtGraphSet); + List list = new ArrayList<>(sortedMethodSignature); + String graph = DotExporter.buildGraph(stmtGraph, true, calls, list.get(i)); + sb.append(graph + "\n"); + i++; } + sb.append("}"); + return sb.toString(); + } - /** - * This method finds out all the calls made in the given StmtGraphs, so it can be edged to - * other methods. - * */ - private static Map computeCalls(ArrayList stmtGraphSet){ - Map calls = new HashMap<>(); - for(StmtGraph stmtGraph : stmtGraphSet){ - Collection> blocks; - try { - blocks = stmtGraph.getBlocksSorted(); - } catch (Exception e) { - blocks = stmtGraph.getBlocks(); - } - for(BasicBlock block : blocks){ - List stmts = block.getStmts(); - for(Stmt stmt : stmts){ - if(stmt.containsInvokeExpr()){ - MethodSignature methodSignature = stmt.getInvokeExpr().getMethodSignature(); - int hashCode = stmt.hashCode(); - calls.put(hashCode,methodSignature); - } - } - } + /** + * This method finds out all the calls made in the given StmtGraphs, so it can be edged to other + * methods. + */ + private static Map computeCalls(ArrayList stmtGraphSet) { + Map calls = new HashMap<>(); + for (StmtGraph stmtGraph : stmtGraphSet) { + Collection> blocks; + try { + blocks = stmtGraph.getBlocksSorted(); + } catch (Exception e) { + blocks = stmtGraph.getBlocks(); + } + for (BasicBlock block : blocks) { + List stmts = block.getStmts(); + for (Stmt stmt : stmts) { + if (stmt.containsInvokeExpr()) { + MethodSignature methodSignature = stmt.getInvokeExpr().getMethodSignature(); + int hashCode = stmt.hashCode(); + calls.put(hashCode, methodSignature); + } } - return calls; + } } - + return calls; + } } From 7b059e9711792bf03c105c83cbaf157f3e993be1 Mon Sep 17 00:00:00 2001 From: palaniappan1 Date: Fri, 30 Jun 2023 08:34:32 +0200 Subject: [PATCH 05/90] Usage of Collection method changed --- .../icfg/JimpleBasedInterproceduralCFG.java | 10 +++++----- .../main/java/sootup/core/util/ICFGDotExporter.java | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java b/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java index a41cbc64fa8..27946eb9040 100644 --- a/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java +++ b/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java @@ -155,14 +155,14 @@ public String buildICFGGraph() { // To Sort the methodSignature set with entrypoint as the first element. Set methodSignatures = cg.getMethodSignatures(); methodSignatures.remove(mainMethodSignature); - List list = new ArrayList<>(methodSignatures); - list.add(0, mainMethodSignature); - LinkedHashSet sortedMethodSignature = new LinkedHashSet<>(list); - for (MethodSignature methodSignature : sortedMethodSignature) { + Set modifiedMethodSignatures = new LinkedHashSet<>(); + modifiedMethodSignatures.add(mainMethodSignature); + modifiedMethodSignatures.addAll(methodSignatures); + for (MethodSignature methodSignature : modifiedMethodSignatures) { final Optional methodOpt = view.getMethod(methodSignature); methodOpt.ifPresent(sootMethod -> stmtGraphSet.add(sootMethod.getBody().getStmtGraph())); } - return ICFGDotExporter.buildICFGGraph(stmtGraphSet, sortedMethodSignature); + return ICFGDotExporter.buildICFGGraph(stmtGraphSet, modifiedMethodSignatures); } private CallGraph initCallGraph() { diff --git a/sootup.core/src/main/java/sootup/core/util/ICFGDotExporter.java b/sootup.core/src/main/java/sootup/core/util/ICFGDotExporter.java index 6ee64445dba..602e1cce9e3 100644 --- a/sootup.core/src/main/java/sootup/core/util/ICFGDotExporter.java +++ b/sootup.core/src/main/java/sootup/core/util/ICFGDotExporter.java @@ -11,7 +11,7 @@ public class ICFGDotExporter { static final StringBuilder sb = new StringBuilder(); public static String buildICFGGraph( - ArrayList stmtGraphSet, LinkedHashSet sortedMethodSignature) { + ArrayList stmtGraphSet, Set sortedMethodSignature) { DotExporter.buildDiGraphObject(sb); int i = 0; Map calls; From 291a9a6a487969c9a4670413817dc795796a70c0 Mon Sep 17 00:00:00 2001 From: palaniappan1 Date: Fri, 30 Jun 2023 14:54:41 +0200 Subject: [PATCH 06/90] Dummy Change for test --- .../analysis/interprocedural/ifds/ICFGCallGraphTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java b/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java index 3901f9a158f..f96cbc75080 100644 --- a/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java +++ b/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java @@ -107,6 +107,7 @@ public void ICFGDotExportTest() { + "\n" + "\n" + "}"; - assertEquals(expectedCallGraph, icfg.buildICFGGraph()); + String callGraph = icfg.buildICFGGraph(); +// assertEquals(expectedCallGraph, icfg.buildICFGGraph()); } } From 59b547536a9980b619bb0d4e4f139b78a549e756 Mon Sep 17 00:00:00 2001 From: palaniappan1 Date: Tue, 4 Jul 2023 11:18:43 +0200 Subject: [PATCH 07/90] fmt commit --- .../analysis/interprocedural/ifds/ICFGCallGraphTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java b/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java index f96cbc75080..0907732c81f 100644 --- a/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java +++ b/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java @@ -1,6 +1,5 @@ package sootup.analysis.interprocedural.ifds; -import static junit.framework.TestCase.assertEquals; import org.junit.Test; import sootup.analysis.interprocedural.icfg.JimpleBasedInterproceduralCFG; @@ -108,6 +107,6 @@ public void ICFGDotExportTest() { + "\n" + "}"; String callGraph = icfg.buildICFGGraph(); -// assertEquals(expectedCallGraph, icfg.buildICFGGraph()); + // assertEquals(expectedCallGraph, icfg.buildICFGGraph()); } } From 285bb4aa5182489aa9ec537d5ef1ded3c2633847 Mon Sep 17 00:00:00 2001 From: palaniappan1 Date: Wed, 12 Jul 2023 12:36:25 +0200 Subject: [PATCH 08/90] Changes in ICFGDotExporter 1. One more test case added 2.ICFGDotExporter moved from core to callgraph module --- .../icfg}/ICFGDotExporter.java | 5 +-- .../icfg/JimpleBasedInterproceduralCFG.java | 21 +++++++----- .../ifds/ICFGCallGraphTest.java | 31 ++++++++++++++++-- .../resources/callgraph/ICFGExample2.java | 22 +++++++++++++ .../resources/taint/binary/ICFGExample2.class | Bin 0 -> 331 bytes .../resources/taint/binary/ICFGSubClass.class | Bin 0 -> 403 bytes .../taint/binary/ICFGSuperClass.class | Bin 0 -> 409 bytes 7 files changed, 66 insertions(+), 13 deletions(-) rename {sootup.core/src/main/java/sootup/core/util => sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg}/ICFGDotExporter.java (93%) create mode 100644 sootup.analysis/src/test/resources/callgraph/ICFGExample2.java create mode 100644 sootup.analysis/src/test/resources/taint/binary/ICFGExample2.class create mode 100644 sootup.analysis/src/test/resources/taint/binary/ICFGSubClass.class create mode 100644 sootup.analysis/src/test/resources/taint/binary/ICFGSuperClass.class diff --git a/sootup.core/src/main/java/sootup/core/util/ICFGDotExporter.java b/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/ICFGDotExporter.java similarity index 93% rename from sootup.core/src/main/java/sootup/core/util/ICFGDotExporter.java rename to sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/ICFGDotExporter.java index 602e1cce9e3..a19d3bf6f61 100644 --- a/sootup.core/src/main/java/sootup/core/util/ICFGDotExporter.java +++ b/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/ICFGDotExporter.java @@ -1,10 +1,11 @@ -package sootup.core.util; +package sootup.analysis.interprocedural.icfg; import java.util.*; import sootup.core.graph.BasicBlock; import sootup.core.graph.StmtGraph; import sootup.core.jimple.common.stmt.Stmt; import sootup.core.signatures.MethodSignature; +import sootup.core.util.DotExporter; public class ICFGDotExporter { @@ -15,8 +16,8 @@ public static String buildICFGGraph( DotExporter.buildDiGraphObject(sb); int i = 0; Map calls; + calls = computeCalls(stmtGraphSet); for (StmtGraph stmtGraph : stmtGraphSet) { - calls = computeCalls(stmtGraphSet); List list = new ArrayList<>(sortedMethodSignature); String graph = DotExporter.buildGraph(stmtGraph, true, calls, list.get(i)); sb.append(graph + "\n"); diff --git a/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java b/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java index 27946eb9040..af0de5f9f67 100644 --- a/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java +++ b/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java @@ -44,7 +44,6 @@ import sootup.core.model.SootClass; import sootup.core.model.SootMethod; import sootup.core.signatures.MethodSignature; -import sootup.core.util.ICFGDotExporter; import sootup.core.views.View; import sootup.java.core.views.JavaView; @@ -152,17 +151,21 @@ public JimpleBasedInterproceduralCFG( public String buildICFGGraph() { ArrayList stmtGraphSet = new ArrayList<>(); - // To Sort the methodSignature set with entrypoint as the first element. - Set methodSignatures = cg.getMethodSignatures(); - methodSignatures.remove(mainMethodSignature); - Set modifiedMethodSignatures = new LinkedHashSet<>(); - modifiedMethodSignatures.add(mainMethodSignature); - modifiedMethodSignatures.addAll(methodSignatures); - for (MethodSignature methodSignature : modifiedMethodSignatures) { + Set methodSignatures = + computeAllCalls(mainMethodSignature, new LinkedHashSet<>()); + for (MethodSignature methodSignature : methodSignatures) { final Optional methodOpt = view.getMethod(methodSignature); methodOpt.ifPresent(sootMethod -> stmtGraphSet.add(sootMethod.getBody().getStmtGraph())); } - return ICFGDotExporter.buildICFGGraph(stmtGraphSet, modifiedMethodSignatures); + return ICFGDotExporter.buildICFGGraph(stmtGraphSet, methodSignatures); + } + + private Set computeAllCalls( + MethodSignature methodSignature, Set methodSignatureSet) { + methodSignatureSet.add(methodSignature); + cg.callsFrom(methodSignature) + .forEach(nextMethodSignature -> computeAllCalls(nextMethodSignature, methodSignatureSet)); + return methodSignatureSet; } private CallGraph initCallGraph() { diff --git a/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java b/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java index 0907732c81f..b71d9065e93 100644 --- a/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java +++ b/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java @@ -36,7 +36,7 @@ public void ICFGDotExportTest() { JimpleBasedInterproceduralCFG icfg = new JimpleBasedInterproceduralCFG(view, entryMethodSignature, false, false); - String expectedCallGraph = + String actualCallGraph = "digraph G {\n" + "\tcompound=true\n" + "\tlabelloc=b\n" @@ -106,7 +106,34 @@ public void ICFGDotExportTest() { + "\n" + "\n" + "}"; - String callGraph = icfg.buildICFGGraph(); + String expectedCallGraph = icfg.buildICFGGraph(); // assertEquals(expectedCallGraph, icfg.buildICFGGraph()); } + + @Test + public void ICFGDotExportTest2() { + JavaProject javaProject = + JavaProject.builder(new JavaLanguage(8)) + .addInputLocation( + new JavaClassPathAnalysisInputLocation( + System.getProperty("java.home") + "/lib/rt.jar")) + .addInputLocation( + new JavaClassPathAnalysisInputLocation("src/test/resources/taint/binary")) + .build(); + + view = javaProject.createView(); + + JavaIdentifierFactory identifierFactory = JavaIdentifierFactory.getInstance(); + JavaClassType mainClassSignature = identifierFactory.getClassType("ICFGExample2"); + + SootClass sc = view.getClass(mainClassSignature).get(); + entryMethod = + sc.getMethods().stream().filter(e -> e.getName().equals("entryPoint")).findFirst().get(); + + entryMethodSignature = entryMethod.getSignature(); + + JimpleBasedInterproceduralCFG icfg = + new JimpleBasedInterproceduralCFG(view, entryMethodSignature, false, false); + String callGraph = icfg.buildICFGGraph(); + } } diff --git a/sootup.analysis/src/test/resources/callgraph/ICFGExample2.java b/sootup.analysis/src/test/resources/callgraph/ICFGExample2.java new file mode 100644 index 00000000000..2e344bf41f3 --- /dev/null +++ b/sootup.analysis/src/test/resources/callgraph/ICFGExample2.java @@ -0,0 +1,22 @@ +public class ICFGExample2{ + public ICFGExample2(){ + } + + public void entryPoint(){ + ICFGSuperClass polymorphicObj = new ICFGSubClass(); + polymorphicObj.m(); + } +} + +class ICFGSuperClass { + public void m() { + System.out.println("Superclass method"); + } +} + +class ICFGSubClass extends ICFGSuperClass { + @Override + public void m() { + System.out.println("Subclass method"); + } +} \ No newline at end of file diff --git a/sootup.analysis/src/test/resources/taint/binary/ICFGExample2.class b/sootup.analysis/src/test/resources/taint/binary/ICFGExample2.class new file mode 100644 index 0000000000000000000000000000000000000000..d4a79a84f70efdce3c4a252313abca7a5d414163 GIT binary patch literal 331 zcmYLE%Sr=55UkE_GI5-25?}Y+e4qi(lFO2a5LAc=9%thq6Lx3AW>@sHyckgM1M*Q~ zPkhaxx~ICjW@`2M_5omkJ&76ufl#522B9<4kGh{~_t3veW@cIv8fVtoazF_74{imT z1a%RQ&L>q8r+TrF5C|kTp#)kAk#~u{1#?rZB?QU@IzNlUC!Nhxb4m!~{N51SW9!Ui zl_jRQ(MigTG_EY3uXF48eL2aiVroX#PrBau*Wtu}7Cp2%gFiKpPr=ybTaPPotsgEy vFWeBe7=2(b4G}Q2{U<+W&QDtJ5O+&#jE`O+|JNdxgT+mbs~8D8Yn$CKeZ@D$ literal 0 HcmV?d00001 diff --git a/sootup.analysis/src/test/resources/taint/binary/ICFGSubClass.class b/sootup.analysis/src/test/resources/taint/binary/ICFGSubClass.class new file mode 100644 index 0000000000000000000000000000000000000000..c66c3e159282a9900f5fef6839af28618888bc98 GIT binary patch literal 403 zcmZut%Syvg5Ixh@rirm_`tU7uQ)pdSa9imnSP_Z{k?wEWOO51Fk{i*_(uINxKfsR? z=Ni$CcQJQ3bLPz9e0;vW1DN2@LJ4I96&o9<66%-k^uo*6GIc|dWrXTk5C>{PC=Z5n z6E&CyEE}7!3C%lkFGit=S0nE+Q!-*!k}E=Y_B{!b(RCWc%2TNn(YS^>q2cBJLQD4| zscw^{g(e&WEgNlg2gfS}*3hCmgVt6$k&JAo6?83VLW4z)fOUd_UK`gKG z$d~Dj@Iyw3ZCYNErwcg^G~npP^9K>FLwS0l4WNfE=c1pkoD2v%+#T^x8aaLiJ#jMJXiQWj zukz5B>8*)D|2$Mjbp6C_OMTgtbN8j8J2s=C-@k?4ceg!@8 oK-lG5e}j7=?EP4K9Mx*|8Ahx2g2u01HxJaf&^lZ8c`o4K3lXGJNB{r; literal 0 HcmV?d00001 From a144e166b14eb2c2312d4651cc9c554bc2c21de1 Mon Sep 17 00:00:00 2001 From: palaniappan1 Date: Wed, 12 Jul 2023 12:48:54 +0200 Subject: [PATCH 09/90] import changed and fmt commit --- .../analysis/interprocedural/icfg/ICFGDotExporter.java | 7 ++++++- .../analysis/interprocedural/ifds/ICFGCallGraphTest.java | 1 - 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/ICFGDotExporter.java b/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/ICFGDotExporter.java index a19d3bf6f61..74db69a6c1d 100644 --- a/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/ICFGDotExporter.java +++ b/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/ICFGDotExporter.java @@ -1,6 +1,11 @@ package sootup.analysis.interprocedural.icfg; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; import sootup.core.graph.BasicBlock; import sootup.core.graph.StmtGraph; import sootup.core.jimple.common.stmt.Stmt; diff --git a/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java b/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java index b71d9065e93..e9a70d287ea 100644 --- a/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java +++ b/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java @@ -1,6 +1,5 @@ package sootup.analysis.interprocedural.ifds; - import org.junit.Test; import sootup.analysis.interprocedural.icfg.JimpleBasedInterproceduralCFG; import sootup.core.model.SootClass; From ec8c8d9969c80099b00b1f4753744f0328e23785 Mon Sep 17 00:00:00 2001 From: Kadiray Karakaya Date: Wed, 12 Jul 2023 13:49:44 +0200 Subject: [PATCH 10/90] ICFGDotExporter --- .../interprocedural/icfg/ICFGDotExporter.java | 18 +++++-------- .../icfg/JimpleBasedInterproceduralCFG.java | 26 ++++++++++--------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/ICFGDotExporter.java b/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/ICFGDotExporter.java index 74db69a6c1d..48cce218541 100644 --- a/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/ICFGDotExporter.java +++ b/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/ICFGDotExporter.java @@ -1,11 +1,9 @@ package sootup.analysis.interprocedural.icfg; -import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Set; import sootup.core.graph.BasicBlock; import sootup.core.graph.StmtGraph; import sootup.core.jimple.common.stmt.Stmt; @@ -14,19 +12,15 @@ public class ICFGDotExporter { - static final StringBuilder sb = new StringBuilder(); - public static String buildICFGGraph( - ArrayList stmtGraphSet, Set sortedMethodSignature) { + Map signatureToStmtGraph) { + final StringBuilder sb = new StringBuilder(); DotExporter.buildDiGraphObject(sb); - int i = 0; Map calls; - calls = computeCalls(stmtGraphSet); - for (StmtGraph stmtGraph : stmtGraphSet) { - List list = new ArrayList<>(sortedMethodSignature); - String graph = DotExporter.buildGraph(stmtGraph, true, calls, list.get(i)); + calls = computeCalls(signatureToStmtGraph.values()); + for (Map.Entry entry : signatureToStmtGraph.entrySet()) { + String graph = DotExporter.buildGraph(entry.getValue(), true, calls, entry.getKey()); sb.append(graph + "\n"); - i++; } sb.append("}"); return sb.toString(); @@ -36,7 +30,7 @@ public static String buildICFGGraph( * This method finds out all the calls made in the given StmtGraphs, so it can be edged to other * methods. */ - private static Map computeCalls(ArrayList stmtGraphSet) { + private static Map computeCalls(Collection stmtGraphSet) { Map calls = new HashMap<>(); for (StmtGraph stmtGraph : stmtGraphSet) { Collection> blocks; diff --git a/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java b/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java index af0de5f9f67..8d5eb965759 100644 --- a/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java +++ b/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java @@ -151,21 +151,23 @@ public JimpleBasedInterproceduralCFG( public String buildICFGGraph() { ArrayList stmtGraphSet = new ArrayList<>(); - Set methodSignatures = - computeAllCalls(mainMethodSignature, new LinkedHashSet<>()); - for (MethodSignature methodSignature : methodSignatures) { - final Optional methodOpt = view.getMethod(methodSignature); - methodOpt.ifPresent(sootMethod -> stmtGraphSet.add(sootMethod.getBody().getStmtGraph())); - } - return ICFGDotExporter.buildICFGGraph(stmtGraphSet, methodSignatures); + Map signatureToStmtGraph = new LinkedHashMap<>(); + computeAllCalls(mainMethodSignature, signatureToStmtGraph); + return ICFGDotExporter.buildICFGGraph(signatureToStmtGraph); } - private Set computeAllCalls( - MethodSignature methodSignature, Set methodSignatureSet) { - methodSignatureSet.add(methodSignature); + private void computeAllCalls( + MethodSignature methodSignature, Map signatureToStmtGraph) { + final Optional methodOpt = view.getMethod(methodSignature); + if(methodOpt.isPresent()){ + SootMethod sootMethod = methodOpt.get(); + if(sootMethod.hasBody()){ + StmtGraph stmtGraph = sootMethod.getBody().getStmtGraph(); + signatureToStmtGraph.put(methodSignature, stmtGraph); + } + } cg.callsFrom(methodSignature) - .forEach(nextMethodSignature -> computeAllCalls(nextMethodSignature, methodSignatureSet)); - return methodSignatureSet; + .forEach(nextMethodSignature -> computeAllCalls(nextMethodSignature, signatureToStmtGraph)); } private CallGraph initCallGraph() { From b30451928b5137c9feb8164066a62096275b62e2 Mon Sep 17 00:00:00 2001 From: Kadiray Karakaya Date: Wed, 12 Jul 2023 13:50:11 +0200 Subject: [PATCH 11/90] fmt --- .../sootup/analysis/interprocedural/icfg/ICFGDotExporter.java | 3 +-- .../interprocedural/icfg/JimpleBasedInterproceduralCFG.java | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/ICFGDotExporter.java b/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/ICFGDotExporter.java index 48cce218541..3b0407b6d31 100644 --- a/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/ICFGDotExporter.java +++ b/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/ICFGDotExporter.java @@ -12,8 +12,7 @@ public class ICFGDotExporter { - public static String buildICFGGraph( - Map signatureToStmtGraph) { + public static String buildICFGGraph(Map signatureToStmtGraph) { final StringBuilder sb = new StringBuilder(); DotExporter.buildDiGraphObject(sb); Map calls; diff --git a/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java b/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java index 8d5eb965759..70a1f6444ff 100644 --- a/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java +++ b/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java @@ -159,9 +159,9 @@ public String buildICFGGraph() { private void computeAllCalls( MethodSignature methodSignature, Map signatureToStmtGraph) { final Optional methodOpt = view.getMethod(methodSignature); - if(methodOpt.isPresent()){ + if (methodOpt.isPresent()) { SootMethod sootMethod = methodOpt.get(); - if(sootMethod.hasBody()){ + if (sootMethod.hasBody()) { StmtGraph stmtGraph = sootMethod.getBody().getStmtGraph(); signatureToStmtGraph.put(methodSignature, stmtGraph); } From 2106ae523ec772c455dcc0a5408c4c0330bdea56 Mon Sep 17 00:00:00 2001 From: palaniappan1 Date: Thu, 13 Jul 2023 13:14:48 +0200 Subject: [PATCH 12/90] ICFG Changes 1. Created a folder ICFG in resources folder to add the files. 2. Converted the CallGraph String into Java Object for test --- .../interprocedural/icfg/ICFGDotExporter.java | 2 +- .../icfg/JimpleBasedInterproceduralCFG.java | 20 +- .../ifds/ICFGCallGraphTest.java | 252 ++++++++++++------ .../source}/ICFGExample.java | 0 .../source}/ICFGExample2.java | 4 +- .../resources/taint/binary/ICFGExample.class | Bin 613 -> 0 bytes .../resources/taint/binary/ICFGExample2.class | Bin 331 -> 0 bytes .../resources/taint/binary/ICFGSubClass.class | Bin 403 -> 0 bytes .../taint/binary/ICFGSuperClass.class | Bin 409 -> 0 bytes 9 files changed, 193 insertions(+), 85 deletions(-) rename sootup.analysis/src/test/resources/{callgraph => icfg/source}/ICFGExample.java (100%) rename sootup.analysis/src/test/resources/{callgraph => icfg/source}/ICFGExample2.java (77%) delete mode 100644 sootup.analysis/src/test/resources/taint/binary/ICFGExample.class delete mode 100644 sootup.analysis/src/test/resources/taint/binary/ICFGExample2.class delete mode 100644 sootup.analysis/src/test/resources/taint/binary/ICFGSubClass.class delete mode 100644 sootup.analysis/src/test/resources/taint/binary/ICFGSuperClass.class diff --git a/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/ICFGDotExporter.java b/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/ICFGDotExporter.java index 3b0407b6d31..f4f50e59667 100644 --- a/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/ICFGDotExporter.java +++ b/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/ICFGDotExporter.java @@ -29,7 +29,7 @@ public static String buildICFGGraph(Map signatureToS * This method finds out all the calls made in the given StmtGraphs, so it can be edged to other * methods. */ - private static Map computeCalls(Collection stmtGraphSet) { + public static Map computeCalls(Collection stmtGraphSet) { Map calls = new HashMap<>(); for (StmtGraph stmtGraph : stmtGraphSet) { Collection> blocks; diff --git a/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java b/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java index 70a1f6444ff..57f8a44167c 100644 --- a/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java +++ b/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java @@ -149,16 +149,19 @@ public JimpleBasedInterproceduralCFG( initializeStmtToOwner(); } - public String buildICFGGraph() { - ArrayList stmtGraphSet = new ArrayList<>(); + public String buildICFGGraph(CallGraph callGraph) { Map signatureToStmtGraph = new LinkedHashMap<>(); - computeAllCalls(mainMethodSignature, signatureToStmtGraph); + computeAllCalls(mainMethodSignature, signatureToStmtGraph, callGraph); return ICFGDotExporter.buildICFGGraph(signatureToStmtGraph); } - private void computeAllCalls( - MethodSignature methodSignature, Map signatureToStmtGraph) { + public void computeAllCalls( + MethodSignature methodSignature, + Map signatureToStmtGraph, + CallGraph callGraph) { final Optional methodOpt = view.getMethod(methodSignature); + // return if the methodSignature is already added to the hashMap to avoid stackoverflow error. + if (signatureToStmtGraph.containsKey(methodSignature)) return; if (methodOpt.isPresent()) { SootMethod sootMethod = methodOpt.get(); if (sootMethod.hasBody()) { @@ -166,8 +169,11 @@ private void computeAllCalls( signatureToStmtGraph.put(methodSignature, stmtGraph); } } - cg.callsFrom(methodSignature) - .forEach(nextMethodSignature -> computeAllCalls(nextMethodSignature, signatureToStmtGraph)); + callGraph + .callsFrom(methodSignature) + .forEach( + nextMethodSignature -> + computeAllCalls(nextMethodSignature, signatureToStmtGraph, callGraph)); } private CallGraph initCallGraph() { diff --git a/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java b/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java index e9a70d287ea..231936e83c9 100644 --- a/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java +++ b/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java @@ -1,16 +1,40 @@ package sootup.analysis.interprocedural.ifds; +import static junit.framework.TestCase.assertNotNull; +import static junit.framework.TestCase.assertTrue; + +import java.util.*; +import org.junit.Assert; import org.junit.Test; +import sootup.analysis.interprocedural.icfg.ICFGDotExporter; import sootup.analysis.interprocedural.icfg.JimpleBasedInterproceduralCFG; +import sootup.callgraph.CallGraph; +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.java.bytecode.inputlocation.JavaClassPathAnalysisInputLocation; import sootup.java.core.JavaIdentifierFactory; import sootup.java.core.JavaProject; import sootup.java.core.language.JavaLanguage; import sootup.java.core.types.JavaClassType; +import sootup.java.core.views.JavaView; public class ICFGCallGraphTest extends IFDSTaintTestSetUp { + public CallGraph loadCallGraph(JavaView view) { + CallGraph cg = + new ClassHierarchyAnalysisAlgorithm(view) + .initialize(Collections.singletonList(entryMethodSignature)); + assertNotNull(cg); + assertTrue( + entryMethodSignature + " is not found in CallGraph", + cg.containsMethod(entryMethodSignature)); + return cg; + } + @Test public void ICFGDotExportTest() { JavaProject javaProject = @@ -19,7 +43,7 @@ public void ICFGDotExportTest() { new JavaClassPathAnalysisInputLocation( System.getProperty("java.home") + "/lib/rt.jar")) .addInputLocation( - new JavaClassPathAnalysisInputLocation("src/test/resources/taint/binary")) + new JavaClassPathAnalysisInputLocation("src/test/resources/icfg/binary")) .build(); view = javaProject.createView(); @@ -35,78 +59,20 @@ public void ICFGDotExportTest() { JimpleBasedInterproceduralCFG icfg = new JimpleBasedInterproceduralCFG(view, entryMethodSignature, false, false); - String actualCallGraph = - "digraph G {\n" - + "\tcompound=true\n" - + "\tlabelloc=b\n" - + "\tstyle=filled\n" - + "\tcolor=gray90\n" - + "\tnode [shape=box,style=filled,color=white]\n" - + "\tedge [fontsize=10,arrowsize=1.5,fontcolor=grey40]\n" - + "\tfontsize=10\n" - + "\n" - + "// lines [23: 26] \n" - + "\tsubgraph cluster_1320677379 { \n" - + "\t\tlabel = \"Block #1\"\n" - + "\t\t171497379[label=\"l0 := @this: ICFGExample\",shape=Mdiamond,color=grey50,fillcolor=white]\n" - + "\t\t1665404403[label=\"l1 = "SECRET"\"]\n" - + "\t\t988458918[label=\"l2 = virtualinvoke l0.<ICFGExample: java.lang.String id(java.lang.String)>(l1)\"]\n" - + "\t\t1990451863[label=\"virtualinvoke l0.<ICFGExample: void sink(java.lang.String)>(l2)\"]\n" - + "\t\t1295083508[label=\"return\",shape=Mdiamond,color=grey50,fillcolor=white]\n" - + "\n" - + "\t\t171497379 -> 1665404403 -> 988458918 -> 1990451863 -> 1295083508\n" - + "\t}\n" - + "\n" - + "\n" - + "// lines [11: 12] \n" - + "\tsubgraph cluster_2137366542 { \n" - + "\t\tlabel = \"Block #1\"\n" - + "\t\t2018981974[label=\"l0 := @this: ICFGExample\",shape=Mdiamond,color=grey50,fillcolor=white]\n" - + "\t\t905009026[label=\"l1 := @parameter0: java.lang.String\"]\n" - + "\t\t602908276[label=\"virtualinvoke l0.<ICFGExample: void secondMethod(java.lang.String)>(l1)\"]\n" - + "\t\t1648078807[label=\"return\",shape=Mdiamond,color=grey50,fillcolor=white]\n" - + "\n" - + "\t\t1990451863 -> 2018981974 -> 905009026 -> 602908276 -> 1648078807\n" - + "\t}\n" - + "\n" - + "\n" - + "// lines [7: 7] \n" - + "\tsubgraph cluster_603702962 { \n" - + "\t\tlabel = \"Block #1\"\n" - + "\t\t1698148964[label=\"l0 := @this: ICFGExample\",shape=Mdiamond,color=grey50,fillcolor=white]\n" - + "\t\t1288983035[label=\"l1 := @parameter0: java.lang.String\"]\n" - + "\t\t2064117540[label=\"return l1\",shape=Mdiamond,color=grey50,fillcolor=white]\n" - + "\n" - + "\t\t988458918 -> 1698148964 -> 1288983035 -> 2064117540\n" - + "\t}\n" - + "\n" - + "\n" - + "// lines [15: 16] \n" - + "\tsubgraph cluster_2116251487 { \n" - + "\t\tlabel = \"Block #1\"\n" - + "\t\t329293111[label=\"l0 := @this: ICFGExample\",shape=Mdiamond,color=grey50,fillcolor=white]\n" - + "\t\t1770804671[label=\"l1 := @parameter0: java.lang.String\"]\n" - + "\t\t1172514862[label=\"$stack2 = virtualinvoke l0.<ICFGExample: java.lang.String thirdMethod(java.lang.String)>(l1)\"]\n" - + "\t\t1388137600[label=\"return\",shape=Mdiamond,color=grey50,fillcolor=white]\n" - + "\n" - + "\t\t602908276 -> 329293111 -> 1770804671 -> 1172514862 -> 1388137600\n" - + "\t}\n" - + "\n" - + "\n" - + "// lines [19: 19] \n" - + "\tsubgraph cluster_1780885275 { \n" - + "\t\tlabel = \"Block #1\"\n" - + "\t\t2058348472[label=\"l0 := @this: ICFGExample\",shape=Mdiamond,color=grey50,fillcolor=white]\n" - + "\t\t2126618194[label=\"l1 := @parameter0: java.lang.String\"]\n" - + "\t\t1865523042[label=\"return l1\",shape=Mdiamond,color=grey50,fillcolor=white]\n" - + "\n" - + "\t\t1172514862 -> 2058348472 -> 2126618194 -> 1865523042\n" - + "\t}\n" - + "\n" - + "\n" - + "}"; - String expectedCallGraph = icfg.buildICFGGraph(); - // assertEquals(expectedCallGraph, icfg.buildICFGGraph()); + CallGraph callGraph = loadCallGraph(view); + String expectedCallGraph = icfg.buildICFGGraph(callGraph); + Digraph digraph = parseDigraph(expectedCallGraph); + Assert.assertEquals(digraph.blocks.length, 5); + // As per the example code, the first block has no invoke calls, so the number of statements and + // edges should be same + Assert.assertEquals(digraph.blocks[0].statements.length, digraph.blocks[0].edges.size()); + // As per the example code, the second block has an invoke call, so the number of edges should + // be same one more than the statements, as one edge is for the invoke call + Assert.assertEquals(digraph.blocks[2].statements.length + 1, digraph.blocks[2].edges.size()); + // compute the edges from the callGraph and compare the edges with the ICFGCallGraph created + Assert.assertEquals( + edgesFromCallGraph(entryMethodSignature, icfg, callGraph), + String.join(" -> ", digraph.blocks[0].edges)); } @Test @@ -117,7 +83,7 @@ public void ICFGDotExportTest2() { new JavaClassPathAnalysisInputLocation( System.getProperty("java.home") + "/lib/rt.jar")) .addInputLocation( - new JavaClassPathAnalysisInputLocation("src/test/resources/taint/binary")) + new JavaClassPathAnalysisInputLocation("src/test/resources/icfg/binary")) .build(); view = javaProject.createView(); @@ -133,6 +99,142 @@ public void ICFGDotExportTest2() { JimpleBasedInterproceduralCFG icfg = new JimpleBasedInterproceduralCFG(view, entryMethodSignature, false, false); - String callGraph = icfg.buildICFGGraph(); + CallGraph callGraph = loadCallGraph(view); + String expectedCallGraph = icfg.buildICFGGraph(callGraph); + Digraph digraph = parseDigraph(expectedCallGraph); + Assert.assertEquals(digraph.blocks.length, 7); + // As per the example code, the first block has no invoke calls, so the number of statements and + // edges should be same + Assert.assertEquals(digraph.blocks[0].statements.length, digraph.blocks[0].edges.size()); + // As per the example code, the second block has an invoke call, so the number of edges should + // be same one more than the statements, as one edge is for the invoke call + Assert.assertEquals(digraph.blocks[2].statements.length + 1, digraph.blocks[2].edges.size()); + // compute the edges from the callGraph and compare the edges with the ICFGCallGraph created + Assert.assertEquals( + edgesFromCallGraph(entryMethodSignature, icfg, callGraph), + String.join(" -> ", digraph.blocks[0].edges)); + } + + /** Compute the Edges of the given methodSignature from the provided callGraph */ + public String edgesFromCallGraph( + MethodSignature methodSignature, JimpleBasedInterproceduralCFG icfg, CallGraph callGraph) { + Map signatureToStmtGraph = new LinkedHashMap<>(); + icfg.computeAllCalls(methodSignature, signatureToStmtGraph, callGraph); + Map calls; + calls = ICFGDotExporter.computeCalls(signatureToStmtGraph.values()); + final Optional methodOpt = view.getMethod(methodSignature); + if (methodOpt.isPresent()) { + SootMethod sootMethod = methodOpt.get(); + if (sootMethod.hasBody()) { + String edges = connectEdges(sootMethod.getBody().getStmts(), methodSignature, calls); + return edges; + } + } + return ""; + } + + /** + * Compute the possible edges which includes the hashcodes of each flowing statement from the + * given statements + * + * @param stmts + * @param methodSignature + * @param calls + * @return + */ + public String connectEdges( + List stmts, MethodSignature methodSignature, Map calls) { + StringBuilder sb = new StringBuilder(); + boolean isAdded = false; + for (Stmt stmt : stmts) { + if (methodSignature != null && calls != null) { + for (Map.Entry entry : calls.entrySet()) { + int key = entry.getKey(); + MethodSignature value = entry.getValue(); + if (methodSignature.equals(value) && !isAdded) { + sb.append(key).append(" -> "); + isAdded = true; + } + } + } + sb.append(stmt.hashCode()).append(" -> "); + } + sb.delete(sb.length() - 4, sb.length()); + return sb.toString(); + } + + /** A POJO class to convert the dot-exported string into java object */ + class Block { + String label; + String[] statements; + + List edges; + + public Block() { + edges = new ArrayList<>(); + } + } + + class Digraph { + Block[] blocks; + } + + public Digraph parseDigraph(String digraphString) { + Digraph digraph = new Digraph(); + Block currentBlock = null; + + String[] lines = digraphString.split("\n"); + for (String line : lines) { + line = line.trim(); + if (line.startsWith("subgraph cluster_")) { + String label = line.split("subgraph cluster_")[1].trim(); + currentBlock = new Block(); + currentBlock.label = label; + digraph.blocks = addBlock(digraph.blocks, currentBlock); + } else if (currentBlock != null && line.contains("label=")) { + String[] splitArray = line.split("="); + String[] newArray = new String[splitArray.length - 1]; + System.arraycopy(splitArray, 1, newArray, 0, splitArray.length - 1); + String join = String.join("", newArray); + String statement = line.split("=")[1].replace("\"", "").trim(); + currentBlock.statements = addStatement(currentBlock.statements, join); + } else if (line.contains("->")) { + String[] arrows = line.split("->"); + for (String arrow : arrows) { + String trimmedArrow = arrow.trim(); + if (!trimmedArrow.isEmpty()) { + currentBlock.edges.add(trimmedArrow); + } + } + } + } + + return digraph; + } + + public static Block[] addBlock(Block[] blocks, Block block) { + if (blocks == null) { + blocks = new Block[1]; + blocks[0] = block; + } else { + Block[] temp = new Block[blocks.length + 1]; + System.arraycopy(blocks, 0, temp, 0, blocks.length); + temp[blocks.length] = block; + blocks = temp; + } + return blocks; + } + + public static String[] addStatement(String[] statements, String statement) { + if (statements == null) { + statements = new String[1]; + statements[0] = statement; + } else { + String[] temp = new String[statements.length + 1]; + System.arraycopy(statements, 0, temp, 0, statements.length); + temp[statements.length] = statement; + statements = temp; + } + return statements; } } diff --git a/sootup.analysis/src/test/resources/callgraph/ICFGExample.java b/sootup.analysis/src/test/resources/icfg/source/ICFGExample.java similarity index 100% rename from sootup.analysis/src/test/resources/callgraph/ICFGExample.java rename to sootup.analysis/src/test/resources/icfg/source/ICFGExample.java diff --git a/sootup.analysis/src/test/resources/callgraph/ICFGExample2.java b/sootup.analysis/src/test/resources/icfg/source/ICFGExample2.java similarity index 77% rename from sootup.analysis/src/test/resources/callgraph/ICFGExample2.java rename to sootup.analysis/src/test/resources/icfg/source/ICFGExample2.java index 2e344bf41f3..b61b47b230c 100644 --- a/sootup.analysis/src/test/resources/callgraph/ICFGExample2.java +++ b/sootup.analysis/src/test/resources/icfg/source/ICFGExample2.java @@ -10,13 +10,13 @@ public void entryPoint(){ class ICFGSuperClass { public void m() { - System.out.println("Superclass method"); + } } class ICFGSubClass extends ICFGSuperClass { @Override public void m() { - System.out.println("Subclass method"); + } } \ No newline at end of file diff --git a/sootup.analysis/src/test/resources/taint/binary/ICFGExample.class b/sootup.analysis/src/test/resources/taint/binary/ICFGExample.class deleted file mode 100644 index 240816ec8e5db6a0095b8c97f7433d3a88d2e104..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 613 zcmZ{h&rZTX5XQf4fkLSiK?Lznf+hyR$ibtA3jt#SYJ}*y&Kd{mt~_^X(l#6+1c=ht`8t8Cg!ha@ig7p3e|D6^`($ z3~KSof?*)2I z>Q`=;8%*Mr2(@sHyckgM1M*Q~ zPkhaxx~ICjW@`2M_5omkJ&76ufl#522B9<4kGh{~_t3veW@cIv8fVtoazF_74{imT z1a%RQ&L>q8r+TrF5C|kTp#)kAk#~u{1#?rZB?QU@IzNlUC!Nhxb4m!~{N51SW9!Ui zl_jRQ(MigTG_EY3uXF48eL2aiVroX#PrBau*Wtu}7Cp2%gFiKpPr=ybTaPPotsgEy vFWeBe7=2(b4G}Q2{U<+W&QDtJ5O+&#jE`O+|JNdxgT+mbs~8D8Yn$CKeZ@D$ diff --git a/sootup.analysis/src/test/resources/taint/binary/ICFGSubClass.class b/sootup.analysis/src/test/resources/taint/binary/ICFGSubClass.class deleted file mode 100644 index c66c3e159282a9900f5fef6839af28618888bc98..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 403 zcmZut%Syvg5Ixh@rirm_`tU7uQ)pdSa9imnSP_Z{k?wEWOO51Fk{i*_(uINxKfsR? z=Ni$CcQJQ3bLPz9e0;vW1DN2@LJ4I96&o9<66%-k^uo*6GIc|dWrXTk5C>{PC=Z5n z6E&CyEE}7!3C%lkFGit=S0nE+Q!-*!k}E=Y_B{!b(RCWc%2TNn(YS^>q2cBJLQD4| zscw^{g(e&WEgNlg2gfS}*3hCmgVt6$k&JAo6?83VLW4z)fOUd_UK`gKG z$d~Dj@Iyw3ZCYNErwcg^G~npP^9K>FLwS0l4WNfE=c1pkoD2v%+#T^x8aaLiJ#jMJXiQWj zukz5B>8*)D|2$Mjbp6C_OMTgtbN8j8J2s=C-@k?4ceg!@8 oK-lG5e}j7=?EP4K9Mx*|8Ahx2g2u01HxJaf&^lZ8c`o4K3lXGJNB{r; From c7bce61666a8205a3db812809844ab3e01e954b7 Mon Sep 17 00:00:00 2001 From: palaniappan1 Date: Thu, 13 Jul 2023 14:09:57 +0200 Subject: [PATCH 13/90] Class files added --- .../test/resources/icfg/binary/ICFGExample.class | Bin 0 -> 613 bytes .../test/resources/icfg/binary/ICFGExample2.class | Bin 0 -> 331 bytes .../test/resources/icfg/binary/ICFGSubClass.class | Bin 0 -> 239 bytes .../resources/icfg/binary/ICFGSuperClass.class | Bin 0 -> 243 bytes 4 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 sootup.analysis/src/test/resources/icfg/binary/ICFGExample.class create mode 100644 sootup.analysis/src/test/resources/icfg/binary/ICFGExample2.class create mode 100644 sootup.analysis/src/test/resources/icfg/binary/ICFGSubClass.class create mode 100644 sootup.analysis/src/test/resources/icfg/binary/ICFGSuperClass.class diff --git a/sootup.analysis/src/test/resources/icfg/binary/ICFGExample.class b/sootup.analysis/src/test/resources/icfg/binary/ICFGExample.class new file mode 100644 index 0000000000000000000000000000000000000000..240816ec8e5db6a0095b8c97f7433d3a88d2e104 GIT binary patch literal 613 zcmZ{h&rZTX5XQf4fkLSiK?Lznf+hyR$ibtA3jt#SYJ}*y&Kd{mt~_^X(l#6+1c=ht`8t8Cg!ha@ig7p3e|D6^`($ z3~KSof?*)2I z>Q`=;8%*Mr2(@sHyckgM1M*Q~ zPkhaxx~ICjW@`2M_5omkJ&76ufl#522B9<4kGh{~_t3veW@cIv8fVtoazF_74{imT z1a%RQ&L>q8r+TrF5C|kTp#)kAk#~u{1#?rZB?QU@IzNlUC!Nhxb4m!~{N51SW9!Ui zl_jRQ(MigTG_EY3uXF48eL2aiVroX#PrBau*Wtu}7Cp2%gFiKpPr=ybTaPPotsgEy vFWeBe7=2(b4G}Q2{U<+W&QDtJ5O+&#jE`O+|JNdxgT+mbs~8D8Yn$CKeZ@D$ literal 0 HcmV?d00001 diff --git a/sootup.analysis/src/test/resources/icfg/binary/ICFGSubClass.class b/sootup.analysis/src/test/resources/icfg/binary/ICFGSubClass.class new file mode 100644 index 0000000000000000000000000000000000000000..25a910fb132a7643168a58e38a922f32cb887e3f GIT binary patch literal 239 zcmX^0Z`VEs1_nC@J}w3(24;2!79Ivx1~x_pK2K*i_u$fk)FS7c#NuK`1~!|_yv!0i zMh0dL%`kQb4n_tZh>|3z0v6}|lvG9rexJ;|RKL>Pq|~C2#H1Xc2xBfI16Oc&mNT3TC7#TQ$ELkAU2ollS&cL`4$N(Az fBtg;)41z$C8?ICmEDKbDu1plDj0Y&m#J~#xsCp$b literal 0 HcmV?d00001 diff --git a/sootup.analysis/src/test/resources/icfg/binary/ICFGSuperClass.class b/sootup.analysis/src/test/resources/icfg/binary/ICFGSuperClass.class new file mode 100644 index 0000000000000000000000000000000000000000..cb16103904f9d257487e3998f47293dc3d502645 GIT binary patch literal 243 zcmZ8by$-=(6g{^srKK1R5+eo@vsfAxi7-^`U+arh`Xi;{wM-I&2k=nheg=a(oO^Q4 zxj(P>;|X92$ASjkgi%8YWkT~HE@BjmbU#`L2N|9TOQQL@?ZJCkc&Zl*(0+1Tx=K`M5Cg}hG literal 0 HcmV?d00001 From 47ce8b73239cc5cae1539ddd4a92bf0d1cf7168d Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Fri, 14 Jul 2023 14:46:48 +0200 Subject: [PATCH 14/90] performance comparison --- .../core/jimple/common/expr/JNegExpr.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/jimple/common/expr/JNegExpr.java b/sootup.core/src/main/java/sootup/core/jimple/common/expr/JNegExpr.java index 2043869d9bc..c10ef2d8c0d 100644 --- a/sootup.core/src/main/java/sootup/core/jimple/common/expr/JNegExpr.java +++ b/sootup.core/src/main/java/sootup/core/jimple/common/expr/JNegExpr.java @@ -69,17 +69,18 @@ public void toString(@Nonnull StmtPrinter up) { public Type getType() { Value op = getOp(); - if (op.getType().equals(PrimitiveType.getInt()) - || op.getType().equals(PrimitiveType.getByte()) - || op.getType().equals(PrimitiveType.getShort()) - || op.getType().equals(PrimitiveType.getBoolean()) - || op.getType().equals(PrimitiveType.getChar())) { + // TODO ms: create a TypeVisitor for this -> O(1) + if (op.getType() == PrimitiveType.getInt() + || op.getType() == PrimitiveType.getByte() + || op.getType() == PrimitiveType.getShort() + || op.getType() == PrimitiveType.getBoolean() + || op.getType() == PrimitiveType.getChar()) { return PrimitiveType.getInt(); - } else if (op.getType().equals(PrimitiveType.getLong())) { + } else if (op.getType() == PrimitiveType.getLong()) { return PrimitiveType.getLong(); - } else if (op.getType().equals(PrimitiveType.getDouble())) { + } else if (op.getType() == PrimitiveType.getDouble()) { return PrimitiveType.getDouble(); - } else if (op.getType().equals(PrimitiveType.getFloat())) { + } else if (op.getType() == PrimitiveType.getFloat()) { return PrimitiveType.getFloat(); } else { return UnknownType.getInstance(); From e4cc90e3a6d37be81c6d18d823a255db3828f1be Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Sat, 15 Jul 2023 12:24:15 +0200 Subject: [PATCH 15/90] remove redundant identifierfactory references --- sootup.core/src/main/java/sootup/core/Language.java | 6 ++++++ sootup.core/src/main/java/sootup/core/Project.java | 13 ++----------- .../src/main/java/sootup/java/core/JavaProject.java | 2 +- .../sootup/java/core/language/JavaLanguage.java | 3 +-- .../java/sootup/jimple/parser/JimpleProject.java | 10 ++-------- 5 files changed, 12 insertions(+), 22 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/Language.java b/sootup.core/src/main/java/sootup/core/Language.java index 50c588d8708..62dbf1204af 100644 --- a/sootup.core/src/main/java/sootup/core/Language.java +++ b/sootup.core/src/main/java/sootup/core/Language.java @@ -27,9 +27,15 @@ * @author Markus Schmidt */ public abstract class Language { + public abstract String getName(); public abstract int getVersion(); public abstract IdentifierFactory getIdentifierFactory(); + + @Override + public String toString() { + return getName() + " " + getVersion(); + } } diff --git a/sootup.core/src/main/java/sootup/core/Project.java b/sootup.core/src/main/java/sootup/core/Project.java index c2b9573b6e2..a771fd45e5b 100644 --- a/sootup.core/src/main/java/sootup/core/Project.java +++ b/sootup.core/src/main/java/sootup/core/Project.java @@ -43,8 +43,6 @@ */ public abstract class Project, V extends View>> { - @Nonnull private final IdentifierFactory identifierFactory; - @Nonnull private final List> inputLocations; @Nonnull private final SourceTypeSpecifier sourceTypeSpecifier; @Nonnull private final Language language; @@ -59,11 +57,7 @@ public Project( @Nonnull Language language, @Nonnull AnalysisInputLocation inputLocation, @Nonnull SourceTypeSpecifier sourceTypeSpecifier) { - this( - language, - Collections.singletonList(inputLocation), - language.getIdentifierFactory(), - sourceTypeSpecifier); + this(language, Collections.singletonList(inputLocation), sourceTypeSpecifier); } /** @@ -71,13 +65,11 @@ public Project( * * @param language the language * @param inputLocations the input locations - * @param identifierFactory the identifier factory * @param sourceTypeSpecifier the source type specifier */ public Project( @Nonnull Language language, @Nonnull List> inputLocations, - @Nonnull IdentifierFactory identifierFactory, @Nonnull SourceTypeSpecifier sourceTypeSpecifier) { this.language = language; List> unmodifiableInputLocations = @@ -85,7 +77,6 @@ public Project( this.sourceTypeSpecifier = sourceTypeSpecifier; this.inputLocations = unmodifiableInputLocations; - this.identifierFactory = identifierFactory; } public void validate() { @@ -106,7 +97,7 @@ public List> getInputLocations() { @Nonnull public IdentifierFactory getIdentifierFactory() { - return this.identifierFactory; + return language.getIdentifierFactory(); } @Nonnull diff --git a/sootup.java.core/src/main/java/sootup/java/core/JavaProject.java b/sootup.java.core/src/main/java/sootup/java/core/JavaProject.java index d061b7f6a77..0c5af017d0c 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/JavaProject.java +++ b/sootup.java.core/src/main/java/sootup/java/core/JavaProject.java @@ -49,7 +49,7 @@ public JavaProject( JavaLanguage language, @Nonnull List> inputLocations, @Nonnull SourceTypeSpecifier sourceTypeSpecifier) { - super(language, inputLocations, JavaIdentifierFactory.getInstance(), sourceTypeSpecifier); + super(language, inputLocations, sourceTypeSpecifier); } @Nonnull diff --git a/sootup.java.core/src/main/java/sootup/java/core/language/JavaLanguage.java b/sootup.java.core/src/main/java/sootup/java/core/language/JavaLanguage.java index 04e7303997c..3aaf1bcc4ce 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/language/JavaLanguage.java +++ b/sootup.java.core/src/main/java/sootup/java/core/language/JavaLanguage.java @@ -28,7 +28,6 @@ import sootup.java.core.JavaIdentifierFactory; import sootup.java.core.JavaModuleIdentifierFactory; -// TODO: Auto-generated Javadoc /** * Language specific Configuration for Java. * @@ -40,7 +39,7 @@ public class JavaLanguage extends Language { /** The identifier factory. */ @Nonnull private final IdentifierFactory identifierFactory; - /** The version number. */ + /** The version number of Java. */ private final int version; /** diff --git a/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleProject.java b/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleProject.java index b4ce178bd46..7c434d11ba9 100644 --- a/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleProject.java +++ b/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleProject.java @@ -3,7 +3,6 @@ import java.util.List; import java.util.function.Function; import javax.annotation.Nonnull; -import sootup.core.IdentifierFactory; import sootup.core.Project; import sootup.core.SourceTypeSpecifier; import sootup.core.cache.provider.ClassCacheProvider; @@ -19,11 +18,7 @@ public JimpleProject(@Nonnull AnalysisInputLocation> inpu } public JimpleProject(@Nonnull List>> inputLocation) { - super( - JimpleLanguage.getInstance(), - inputLocation, - JimpleLanguage.getInstance().getIdentifierFactory(), - DefaultSourceTypeSpecifier.getInstance()); + super(JimpleLanguage.getInstance(), inputLocation, DefaultSourceTypeSpecifier.getInstance()); } public JimpleProject( @@ -34,9 +29,8 @@ public JimpleProject( public JimpleProject( @Nonnull List>> inputLocations, - @Nonnull IdentifierFactory identifierFactory, @Nonnull SourceTypeSpecifier sourceTypeSpecifier) { - super(JimpleLanguage.getInstance(), inputLocations, identifierFactory, sourceTypeSpecifier); + super(JimpleLanguage.getInstance(), inputLocations, sourceTypeSpecifier); } @Nonnull From 08a21a0385d66e0ed6ffe4c9e233c72db095e460 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Sat, 15 Jul 2023 13:28:18 +0200 Subject: [PATCH 16/90] refactor weird naming; current use is set to deprecated to not change the api for now --- .../src/main/java/sootup/core/signatures/PackageName.java | 6 ++++++ .../inputlocation/JrtFileSystemAnalysisInputLocation.java | 3 +-- .../main/java/sootup/java/core/JavaIdentifierFactory.java | 2 +- .../sootup/java/core/signatures/ModulePackageName.java | 4 ++-- .../main/java/sootup/java/core/types/JavaClassType.java | 8 ++++---- .../main/java/sootup/java/core/views/JavaModuleView.java | 4 ++-- .../core/signatures/JavaModuleIdentifierFactoryTest.java | 2 +- .../java/sootup/jimple/parser/JimpleConverterUtil.java | 4 ++-- 8 files changed, 19 insertions(+), 14 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/signatures/PackageName.java b/sootup.core/src/main/java/sootup/core/signatures/PackageName.java index 48e6bfb705a..56cbf6eed14 100644 --- a/sootup.core/src/main/java/sootup/core/signatures/PackageName.java +++ b/sootup.core/src/main/java/sootup/core/signatures/PackageName.java @@ -52,10 +52,16 @@ public PackageName(final String packageName) { /** The name of the package. */ @Nonnull + @Deprecated // "use getName()" public String getPackageName() { return packageName; } + @Nonnull + public String getName() { + return packageName; + } + @Override public boolean equals(Object o) { if (this == o) { diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JrtFileSystemAnalysisInputLocation.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JrtFileSystemAnalysisInputLocation.java index 6adc7520cc8..898f5c7d4c8 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JrtFileSystemAnalysisInputLocation.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JrtFileSystemAnalysisInputLocation.java @@ -214,8 +214,7 @@ private JavaClassType fromPath( if (identifierFactory instanceof JavaModuleIdentifierFactory) { return ((JavaModuleIdentifierFactory) identifierFactory) - .getClassType( - sig.getClassName(), sig.getPackageName().getPackageName(), moduleDir.toString()); + .getClassType(sig.getClassName(), sig.getPackageName().getName(), moduleDir.toString()); } // if we are using the normal signature factory, then trim the module from the path diff --git a/sootup.java.core/src/main/java/sootup/java/core/JavaIdentifierFactory.java b/sootup.java.core/src/main/java/sootup/java/core/JavaIdentifierFactory.java index d292734fdc7..bda893da40f 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/JavaIdentifierFactory.java +++ b/sootup.java.core/src/main/java/sootup/java/core/JavaIdentifierFactory.java @@ -77,7 +77,7 @@ public static JavaIdentifierFactory getInstance() { JavaIdentifierFactory() { /* Represents the default package. */ - packages.put(PackageName.DEFAULT_PACKAGE.getPackageName(), PackageName.DEFAULT_PACKAGE); + packages.put(PackageName.DEFAULT_PACKAGE.getName(), PackageName.DEFAULT_PACKAGE); // initialize primitive map primitiveTypeMap.put( diff --git a/sootup.java.core/src/main/java/sootup/java/core/signatures/ModulePackageName.java b/sootup.java.core/src/main/java/sootup/java/core/signatures/ModulePackageName.java index 82bd4f5aef5..5fbb4ac1724 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/signatures/ModulePackageName.java +++ b/sootup.java.core/src/main/java/sootup/java/core/signatures/ModulePackageName.java @@ -56,7 +56,7 @@ public boolean equals(Object o) { } ModulePackageName that = (ModulePackageName) o; return Objects.equal(moduleSignature, that.moduleSignature) - && Objects.equal(getPackageName(), that.getPackageName()); + && Objects.equal(getName(), that.getName()); } @Override @@ -73,7 +73,7 @@ public ModuleSignature getModuleSignature() { public String toString() { StringBuilder sb = new StringBuilder(); String moduleSignatureStr = getModuleSignature().toString(); - String pckgStr = getPackageName(); + String pckgStr = getName(); if (!moduleSignatureStr.isEmpty()) { sb.append(moduleSignatureStr).append("/"); } diff --git a/sootup.java.core/src/main/java/sootup/java/core/types/JavaClassType.java b/sootup.java.core/src/main/java/sootup/java/core/types/JavaClassType.java index 7462ac244ba..e45b87f503a 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/types/JavaClassType.java +++ b/sootup.java.core/src/main/java/sootup/java/core/types/JavaClassType.java @@ -86,8 +86,8 @@ public int hashCode() { */ public String getFullyQualifiedName() { StringBuilder sb = new StringBuilder(); - if (!packageName.getPackageName().isEmpty()) { - sb.append(packageName.getPackageName()); + if (!packageName.getName().isEmpty()) { + sb.append(packageName.getName()); sb.append('.'); } sb.append(className); @@ -100,7 +100,7 @@ public String toString() { String packageNameStr = packageName.toString(); if (!packageNameStr.isEmpty()) { sb.append(packageName); - if (!packageName.getPackageName().isEmpty()) { + if (!packageName.getName().isEmpty()) { sb.append('.'); } } @@ -128,6 +128,6 @@ public boolean isBuiltInClass() { String moduleName = ((ModulePackageName) packageName).getModuleSignature().toString(); return moduleName.startsWith("java.") || moduleName.startsWith("jdk."); } - return LIBRARY_CLASS_PATTERN.matcher(packageName.getPackageName()).find(); + return LIBRARY_CLASS_PATTERN.matcher(packageName.getName()).find(); } } diff --git a/sootup.java.core/src/main/java/sootup/java/core/views/JavaModuleView.java b/sootup.java.core/src/main/java/sootup/java/core/views/JavaModuleView.java index 3f80b44e808..c434e537f57 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/views/JavaModuleView.java +++ b/sootup.java.core/src/main/java/sootup/java/core/views/JavaModuleView.java @@ -426,8 +426,8 @@ private boolean isProvidedInterfaceImplementation(@Nonnull JavaClassType type) { for (JavaModuleInfo.InterfaceReference provides : moduleInfo.provides()) { JavaClassType interfaceType = provides.getInterfaceType(); - String packageName1 = interfaceType.getPackageName().getPackageName(); - String packageName2 = type.getPackageName().getPackageName(); + String packageName1 = interfaceType.getPackageName().getName(); + String packageName2 = type.getPackageName().getName(); if (packageName1.equals(packageName2)) { if (interfaceType.getClassName().equals(type.getClassName())) { return true; diff --git a/sootup.java.core/src/test/java/sootup/java/core/signatures/JavaModuleIdentifierFactoryTest.java b/sootup.java.core/src/test/java/sootup/java/core/signatures/JavaModuleIdentifierFactoryTest.java index 0ad5a6c9599..a52111a9336 100644 --- a/sootup.java.core/src/test/java/sootup/java/core/signatures/JavaModuleIdentifierFactoryTest.java +++ b/sootup.java.core/src/test/java/sootup/java/core/signatures/JavaModuleIdentifierFactoryTest.java @@ -80,7 +80,7 @@ public void getModulePackageSignatureDiffModule() { assertNotSame(packageSignature1, packageSignature2); assertNotSame(packageSignature1.getModuleSignature(), packageSignature2.getModuleSignature()); - assertSame(packageSignature1.getPackageName(), packageSignature2.getPackageName()); + assertSame(packageSignature1.getName(), packageSignature2.getName()); assertNotEquals(packageSignature1, packageSignature2); } diff --git a/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleConverterUtil.java b/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleConverterUtil.java index 676ae4e6e36..fe01543387c 100644 --- a/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleConverterUtil.java +++ b/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleConverterUtil.java @@ -43,7 +43,7 @@ public Type getType(String typename) { PackageName packageName = imports.get(typename); return packageName == null ? identifierFactory.getType(typename) - : identifierFactory.getType(packageName.getPackageName() + "." + typename); + : identifierFactory.getType(packageName.getName() + "." + typename); } public ClassType getClassType(String typename) { @@ -51,7 +51,7 @@ public ClassType getClassType(String typename) { PackageName packageName = this.imports.get(typename); return packageName == null ? this.identifierFactory.getClassType(typename) - : this.identifierFactory.getClassType(typename, packageName.getPackageName()); + : this.identifierFactory.getClassType(typename, packageName.getName()); } @Nonnull From 0c275aa99e2e39a290f2853b6a417f4826f1825a Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Sat, 15 Jul 2023 14:20:19 +0200 Subject: [PATCH 17/90] fix PathBasedInputLocation ctor #642 and cleanup related chaos --- .../PathBasedAnalysisInputLocation.java | 45 +++++++------------ .../PathBasedAnalysisInputLocationTest.java | 3 +- 2 files changed, 16 insertions(+), 32 deletions(-) diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java index 7a1bb82b264..6147bd4e051 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java @@ -78,39 +78,31 @@ public class PathBasedAnalysisInputLocation implements AnalysisInputLocation { protected Path path; - /** - * Variable to track if user has specified the SourceType. By default, it will be set to false. - */ - private SourceType srcType = null; - /** * Variable to store AnalysisInputLocation, which can be DirectoryBasedAnalysisInputLocation, * WarArchiveAnalysisInputLocation, MultiReleaseJarAnalysisInputLocation, * ArchiveBasedAnalysisInputLocation */ - PathBasedAnalysisInputLocation pathBasedAnalysisInputLocationObj; - - public PathBasedAnalysisInputLocation getPathBasedAnalysisInputLocationObj() { - return pathBasedAnalysisInputLocationObj; - } + PathBasedAnalysisInputLocation inputLocation; public PathBasedAnalysisInputLocation(@Nonnull Path path) { - this.path = path; + this(path, SourceType.Application); } public PathBasedAnalysisInputLocation(@Nonnull Path path, @Nullable SourceType srcType) { + this.path = path; if (Files.isDirectory(path)) { - pathBasedAnalysisInputLocationObj = new DirectoryBasedAnalysisInputLocation(path, srcType); + inputLocation = new DirectoryBasedAnalysisInputLocation(path, srcType); } else if (PathUtils.isArchive(path)) { if (PathUtils.hasExtension(path, FileType.WAR)) { - pathBasedAnalysisInputLocationObj = new WarArchiveAnalysisInputLocation(path, srcType); + inputLocation = new WarArchiveAnalysisInputLocation(path, srcType); } else if (isMultiReleaseJar(path)) { // check if mainfest contains multi release flag - pathBasedAnalysisInputLocationObj = new MultiReleaseJarAnalysisInputLocation(path, srcType); + inputLocation = new MultiReleaseJarAnalysisInputLocation(path, srcType); } else if (PathUtils.hasExtension(path, FileType.APK)) { - pathBasedAnalysisInputLocationObj = new ApkAnalysisInputLocation(path, srcType); + inputLocation = new ApkAnalysisInputLocation(path, srcType); } else { - pathBasedAnalysisInputLocationObj = new ArchiveBasedAnalysisInputLocation(path, srcType); + inputLocation = new ArchiveBasedAnalysisInputLocation(path, srcType); } } else { throw new IllegalArgumentException( @@ -120,13 +112,8 @@ public PathBasedAnalysisInputLocation(@Nonnull Path path, @Nullable SourceType s } } - /** - * The method sets the value of the variable srcType. - * - * @param srcType the source type for the path can be Library, Application, Phantom. - */ - public void setSpecifiedAsBuiltInByUser(@Nonnull SourceType srcType) { - this.srcType = srcType; + public PathBasedAnalysisInputLocation getInputLocation() { + return inputLocation; } /** @@ -140,7 +127,7 @@ public void setSpecifiedAsBuiltInByUser(@Nonnull SourceType srcType) { @Override public Optional> getClassSource( @Nonnull ClassType type, @Nonnull View view) { - return pathBasedAnalysisInputLocationObj.getClassSource(type, view); + return inputLocation.getClassSource(type, view); } /** @@ -153,12 +140,12 @@ public Optional> getClassSource( @Override public Collection> getClassSources( @Nonnull View view) { - return pathBasedAnalysisInputLocationObj.getClassSources(view); + return inputLocation.getClassSources(view); } @Override public SourceType getSourceType() { - return srcType; + return inputLocation.getSourceType(); } private static boolean isMultiReleaseJar(Path path) { @@ -234,8 +221,7 @@ protected Optional> getClassSourceI private static class DirectoryBasedAnalysisInputLocation extends PathBasedAnalysisInputLocation { private DirectoryBasedAnalysisInputLocation(@Nonnull Path path, @Nullable SourceType srcType) { - super(path); - super.setSpecifiedAsBuiltInByUser(srcType); + super(path, srcType); } @Override @@ -575,8 +561,7 @@ private static class ArchiveBasedAnalysisInputLocation extends PathBasedAnalysis })); private ArchiveBasedAnalysisInputLocation(@Nonnull Path path, @Nullable SourceType srcType) { - super(path); - super.setSpecifiedAsBuiltInByUser(srcType); + super(path, srcType); } @Override diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java index 847bf5daf87..336ddfdcdab 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java @@ -194,8 +194,7 @@ public void modularMultiReleaseJar() { .enableModules() .addInputLocation( (ModuleInfoAnalysisInputLocation) - new PathBasedAnalysisInputLocation(mmrj, null) - .getPathBasedAnalysisInputLocationObj()) + new PathBasedAnalysisInputLocation(mmrj, null).getInputLocation()) .build(); final JavaModuleView view_9 = project_9.createView(); From 249e05dbd39d86858115de39b09a3ecc0fb26880 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Sat, 15 Jul 2023 14:39:07 +0200 Subject: [PATCH 18/90] add SourceType to JavaModuleInputLcoation ctor; remove defaullt implemetation of getSourceType which returned null for some reason --- .../inputlocation/AnalysisInputLocation.java | 4 +--- .../JavaModulePathAnalysisInputLocation.java | 19 +++++++++++++++++-- .../PathBasedAnalysisInputLocation.java | 5 +++-- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/inputlocation/AnalysisInputLocation.java b/sootup.core/src/main/java/sootup/core/inputlocation/AnalysisInputLocation.java index 665ac0deb6f..8c66380901f 100644 --- a/sootup.core/src/main/java/sootup/core/inputlocation/AnalysisInputLocation.java +++ b/sootup.core/src/main/java/sootup/core/inputlocation/AnalysisInputLocation.java @@ -73,7 +73,5 @@ Optional> getClassSource( * @return returns null as source type */ @Nullable - default SourceType getSourceType() { - return null; - } + SourceType getSourceType(); } diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JavaModulePathAnalysisInputLocation.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JavaModulePathAnalysisInputLocation.java index 2bb04196305..fe55c72d6f5 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JavaModulePathAnalysisInputLocation.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JavaModulePathAnalysisInputLocation.java @@ -29,11 +29,13 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import sootup.core.IdentifierFactory; import sootup.core.frontend.AbstractClassSource; import sootup.core.frontend.ClassProvider; import sootup.core.frontend.SootClassSource; import sootup.core.inputlocation.AnalysisInputLocation; +import sootup.core.model.SourceType; import sootup.core.types.ClassType; import sootup.core.views.View; import sootup.java.core.JavaModuleIdentifierFactory; @@ -56,6 +58,7 @@ public class JavaModulePathAnalysisInputLocation implements ModuleInfoAnalysisInputLocation { @Nonnull private final ModuleFinder moduleFinder; + @Nonnull private final SourceType sourcetype; /** * Creates a {@link JavaModulePathAnalysisInputLocation} which locates classes in the given module @@ -65,7 +68,12 @@ public class JavaModulePathAnalysisInputLocation implements ModuleInfoAnalysisIn * SootClassSource}es for the files found on the class path */ public JavaModulePathAnalysisInputLocation(@Nonnull String modulePath) { - this(modulePath, FileSystems.getDefault()); + this(modulePath, FileSystems.getDefault(), SourceType.Application); + } + + public JavaModulePathAnalysisInputLocation( + @Nonnull String modulePath, @Nonnull SourceType sourcetype) { + this(modulePath, FileSystems.getDefault(), sourcetype); } /** @@ -77,7 +85,8 @@ public JavaModulePathAnalysisInputLocation(@Nonnull String modulePath) { * @param fileSystem filesystem for the path */ public JavaModulePathAnalysisInputLocation( - @Nonnull String modulePath, @Nonnull FileSystem fileSystem) { + @Nonnull String modulePath, @Nonnull FileSystem fileSystem, @Nonnull SourceType sourcetype) { + this.sourcetype = sourcetype; moduleFinder = new ModuleFinder(modulePath, fileSystem); } @@ -106,6 +115,12 @@ public Collection> getClassSources( .collect(Collectors.toList()); } + @Nullable + @Override + public SourceType getSourceType() { + return sourcetype; + } + @Override @Nonnull public Collection> getModulesClassSources( diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java index 6147bd4e051..1de105a7b28 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java @@ -144,6 +144,7 @@ public Collection> getClassSources( } @Override + @Nonnull public SourceType getSourceType() { return inputLocation.getSourceType(); } @@ -317,7 +318,7 @@ private void discoverInputLocations(@Nullable SourceType srcType) { ModuleSignature moduleSignature = moduleInfo.getModuleSignature(); JavaModulePathAnalysisInputLocation inputLocation = new JavaModulePathAnalysisInputLocation( - versionRoot.toString(), versionRoot.getFileSystem()); + versionRoot.toString(), versionRoot.getFileSystem(), getSourceType()); inputLocations.get(availableVersions[i]).add(inputLocation); moduleInfoMap.get(availableVersions[i]).put(moduleSignature, moduleInfo); @@ -331,7 +332,7 @@ private void discoverInputLocations(@Nullable SourceType srcType) { ModuleSignature moduleSignature = moduleInfo.getModuleSignature(); JavaModulePathAnalysisInputLocation inputLocation = new JavaModulePathAnalysisInputLocation( - versionRoot.toString(), versionRoot.getFileSystem()); + versionRoot.toString(), versionRoot.getFileSystem(), getSourceType()); inputLocations.get(availableVersions[i]).add(inputLocation); moduleInfoMap.get(availableVersions[i]).put(moduleSignature, moduleInfo); From 873090a6049e03301a45f379c163c83334218eee Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Sat, 15 Jul 2023 23:48:26 +0200 Subject: [PATCH 19/90] implement interface in EagerInputLocation as well --- .../core/inputlocation/EagerInputLocation.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/inputlocation/EagerInputLocation.java b/sootup.core/src/main/java/sootup/core/inputlocation/EagerInputLocation.java index 6f3e32cd3f3..4e41050a760 100644 --- a/sootup.core/src/main/java/sootup/core/inputlocation/EagerInputLocation.java +++ b/sootup.core/src/main/java/sootup/core/inputlocation/EagerInputLocation.java @@ -30,6 +30,7 @@ import sootup.core.frontend.AbstractClassSource; import sootup.core.frontend.SootClassSource; import sootup.core.model.SootClass; +import sootup.core.model.SourceType; import sootup.core.types.ClassType; import sootup.core.views.View; @@ -41,14 +42,17 @@ public class EagerInputLocation>> implements AnalysisInputLocation { + @Nonnull protected final SourceType sourceType; @Nonnull private final Map> map; /** not useful for retrieval of classes via view. remove inputlocation from sootclass? */ public EagerInputLocation() { - map = Collections.emptyMap(); + this(Collections.emptyMap(), SourceType.Application); } - public EagerInputLocation(@Nonnull Map> map) { + public EagerInputLocation( + @Nonnull Map> map, @Nonnull SourceType sourceType) { + this.sourceType = sourceType; this.map = ImmutableMap.copyOf(map); } @@ -66,6 +70,12 @@ public Collection> getClassSources(@Nullable Vi return map.values(); } + @Nullable + @Override + public SourceType getSourceType() { + return sourceType; + } + @Override public int hashCode() { return map.hashCode(); From 1fd2fe265b48fc03426004cbc8c5cafd5f63c774 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Mon, 17 Jul 2023 12:30:16 +0200 Subject: [PATCH 20/90] fix off by one: iterating over a all type items; adapt it according to old soots implementation --- .../sootup/java/bytecode/frontend/AsmMethodSource.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java index 067aa461843..a9f06720a6e 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java @@ -1345,7 +1345,7 @@ private void convertInvokeDynamicInsn(@Nonnull InvokeDynamicInsnNode insn) { // Generate parameters & returnType & parameterTypes List types = AsmUtil.toJimpleSignatureDesc(insn.desc); - int nrArgs = types.size() - 1; + int nrArgs = types.size() - 1; // don't handle the return type here List parameterTypes = new ArrayList<>(nrArgs); List methodArgs = new ArrayList<>(nrArgs); @@ -1383,12 +1383,12 @@ private void convertInvokeDynamicInsn(@Nonnull InvokeDynamicInsnNode insn) { AbstractInvokeExpr expr = (AbstractInvokeExpr) opr.value; List types = expr.getMethodSignature().getParameterTypes(); Operand[] oprs; - int nrArgs = types.size() - 1; + int nrArgs = types.size(); final boolean isStaticInvokeExpr = expr instanceof JStaticInvokeExpr; if (isStaticInvokeExpr) { - oprs = (nrArgs <= 0) ? null : new Operand[nrArgs]; + oprs = (nrArgs == 0) ? null : new Operand[nrArgs]; } else { - oprs = (nrArgs < 0) ? null : new Operand[nrArgs + 1]; + oprs = new Operand[nrArgs + 1]; } if (oprs != null) { while (nrArgs-- > 0) { From f5420790d9770eca114bb7d5114d2765364bd445 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Mon, 17 Jul 2023 12:30:31 +0200 Subject: [PATCH 21/90] cleanup --- .../bytecode/frontend/AsmMethodSource.java | 33 +++---------------- 1 file changed, 4 insertions(+), 29 deletions(-) diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java index a9f06720a6e..3fa2fdfdf04 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java @@ -1345,7 +1345,7 @@ private void convertInvokeDynamicInsn(@Nonnull InvokeDynamicInsnNode insn) { // Generate parameters & returnType & parameterTypes List types = AsmUtil.toJimpleSignatureDesc(insn.desc); - int nrArgs = types.size() - 1; // don't handle the return type here + int nrArgs = types.size() - 1; // don't handle the return type here List parameterTypes = new ArrayList<>(nrArgs); List methodArgs = new ArrayList<>(nrArgs); @@ -1353,8 +1353,9 @@ private void convertInvokeDynamicInsn(@Nonnull InvokeDynamicInsnNode insn) { // Beware: Call stack is FIFO, Jimple is linear for (int i = nrArgs - 1; i >= 0; i--) { - parameterTypes.add(types.get(i)); - args[i] = operandStack.popImmediate(types.get(i)); + final Type type = types.get(i); + parameterTypes.add(type); + args[i] = operandStack.popImmediate(type); methodArgs.add((Immediate) args[i].stackOrValue()); } if (methodArgs.size() > 1) { @@ -1418,32 +1419,6 @@ private void convertInvokeDynamicInsn(@Nonnull InvokeDynamicInsnNode insn) { addReadOperandAssignments(); } - // private @Nonnull MethodRef toSootMethodRef(@Nonnull Handle methodHandle) { - // String bsmClsName = AsmUtil.toQualifiedName(methodHandle.getOwner()); - // JavaClassType bsmCls = view.getIdentifierFactory().getClassSignature(bsmClsName); - // List bsmSigTypes = AsmUtil.toJimpleSignatureDesc(methodHandle.getDesc(), view); - // Type returnType = bsmSigTypes.remove(bsmSigTypes.size() - 1); - // MethodSignature methodSignature = - // view.getIdentifierFactory().getMethodSignature(methodHandle.getName(), bsmCls, - // returnType, bsmSigTypes); - // boolean isStatic = methodHandle.getTag() == MethodHandle.Kind.REF_INVOKE_STATIC.getValue(); - // return Jimple.createSymbolicMethodRef(methodSignature, isStatic); - // } - // - // private JFieldRef toSootFieldRef(Handle methodHandle) { - // String bsmClsName = AsmUtil.toQualifiedName(methodHandle.getOwner()); - // JavaClassType bsmCls = view.getIdentifierFactory().getClassSignature(bsmClsName); - // - // Type t = AsmUtil.toJimpleSignatureDesc(methodHandle.getDesc(), view).get(0); - // int kind = methodHandle.getTag(); - // boolean isStatic = kind == MethodHandle.Kind.REF_GET_FIELD_STATIC.getValue() - // || kind == MethodHandle.Kind.REF_PUT_FIELD_STATIC.getValue(); - // - // FieldSignature fieldSignature = - // view.getIdentifierFactory().getFieldSignature(methodHandle.getName(), bsmCls, t); - // return Jimple.createSymbolicFieldRef(fieldSignature, isStatic); - // } - private void convertMultiANewArrayInsn(@Nonnull MultiANewArrayInsnNode insn) { StackFrame frame = operandStack.getOrCreateStackframe(insn); Operand[] out = frame.getOut(); From b257c517ac0064e0fc80631f3089b4c99e3d3651 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Mon, 17 Jul 2023 17:17:49 +0200 Subject: [PATCH 22/90] remove obsolete construct from the View --- .../java/sootup/core/views/AbstractView.java | 16 ----- .../src/main/java/sootup/core/views/View.java | 60 +------------------ 2 files changed, 2 insertions(+), 74 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/views/AbstractView.java b/sootup.core/src/main/java/sootup/core/views/AbstractView.java index 4fca873cf45..dc2469f9b9c 100644 --- a/sootup.core/src/main/java/sootup/core/views/AbstractView.java +++ b/sootup.core/src/main/java/sootup/core/views/AbstractView.java @@ -22,8 +22,6 @@ * #L% */ -import java.util.HashMap; -import java.util.Map; import java.util.Optional; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -47,8 +45,6 @@ public abstract class AbstractView> implements View { @Nonnull private final Project> project; - @Nonnull private final Map, Object> moduleData = new HashMap<>(); - @Nullable private TypeHierarchy typeHierarchy; @Override @@ -105,18 +101,6 @@ public Optional getField(@Nonnull FieldSignature signature) return aClass.get().getField(signature.getSubSignature()); } - @SuppressWarnings("unchecked") // Safe because we only put T in putModuleData - @Override - @Nullable - public K getModuleData(@Nonnull ModuleDataKey key) { - return (K) moduleData.get(key); - } - - @Override - public void putModuleData(@Nonnull ModuleDataKey key, @Nonnull K value) { - moduleData.put(key, value); - } - @Override @Nonnull public Project> getProject() { diff --git a/sootup.core/src/main/java/sootup/core/views/View.java b/sootup.core/src/main/java/sootup/core/views/View.java index fe21929e580..84f254a5f86 100644 --- a/sootup.core/src/main/java/sootup/core/views/View.java +++ b/sootup.core/src/main/java/sootup/core/views/View.java @@ -25,14 +25,10 @@ import java.util.Collection; import java.util.List; import java.util.Optional; -import java.util.function.Function; -import java.util.function.Supplier; import javax.annotation.Nonnull; -import javax.annotation.Nullable; import sootup.core.IdentifierFactory; import sootup.core.Project; import sootup.core.Scope; -import sootup.core.frontend.ResolveException; import sootup.core.inputlocation.AnalysisInputLocation; import sootup.core.model.SootClass; import sootup.core.model.SootField; @@ -90,59 +86,7 @@ public interface View { @Nonnull default T getClassOrThrow(@Nonnull ClassType classType) { return getClass(classType) - .orElseThrow(() -> new ResolveException("Could not find " + classType + " in View.")); + .orElseThrow( + () -> new IllegalArgumentException("Could not find " + classType + " in View.")); } - - /** @see ModuleDataKey */ - void putModuleData(@Nonnull ModuleDataKey key, @Nonnull K value); - - /** @see ModuleDataKey */ - @Nullable - K getModuleData(@Nonnull ModuleDataKey key); - - /** - * @see java.util.Map#computeIfAbsent(Object, Function) - * @see ModuleDataKey - */ - default K computeModuleDataIfAbsent(@Nonnull ModuleDataKey key, Supplier dataSupplier) { - K moduleData = getModuleData(key); - if (moduleData != null) { - return moduleData; - } - - K computedModuleData = dataSupplier.get(); - putModuleData(key, computedModuleData); - return computedModuleData; - } - - /** - * A key for use with {@link #getModuleData(ModuleDataKey)}, {@link #putModuleData(ModuleDataKey, - * Object)} and {@link #computeModuleDataIfAbsent(ModuleDataKey, Supplier)}. This allows - * additional data to be stored or cached inside a {@link View} and to be retrieved in a type-safe - * manner. A {@link ModuleDataKey} of type T can only be used to store and retrieve - * data of type T. - * - *

Additionally, since it is an abstract class and not an interface, it can be assured that a - * given class can only be a key for a single type, which avoids clashes. - * - *

Example:
- *
- * - *

-   *   class StringDataKey extends ModuleDataKey<String> {
-   *     public static final StringDataKey instance = new StringDataKey();
-   *     private StringDataKey() {}
-   *   }
-   *
-   *   void storeInView(String str, View view) {
-   *     view.putModuleData(StringDataKey.instance, str);
-   *     String retrieved = view.getModuleData(StringDataKey.instance);
-   *   }
-   * 
- * - * @param The type of the stored and retrieved data that is associated with the key - * @author Christian Brüggemann - */ - @SuppressWarnings("unused") // Used in modules - abstract class ModuleDataKey {} } From 84e2aa2fa4ba9d6ddd3c0f8ae24a1cacb49e791f Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Fri, 21 Jul 2023 08:45:48 +0200 Subject: [PATCH 23/90] add linenumberinfos to stmts --- .../core/jimple/common/constant/ClassConstant.java | 5 +++-- .../java/bytecode/frontend/AsmMethodSource.java | 7 ++++++- .../java/bytecode/frontend/OperandStack.java | 14 ++++++++++---- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/jimple/common/constant/ClassConstant.java b/sootup.core/src/main/java/sootup/core/jimple/common/constant/ClassConstant.java index 3dde9e35457..8cc69a74997 100644 --- a/sootup.core/src/main/java/sootup/core/jimple/common/constant/ClassConstant.java +++ b/sootup.core/src/main/java/sootup/core/jimple/common/constant/ClassConstant.java @@ -58,7 +58,8 @@ public class ClassConstant implements Constant { public ClassConstant(@Nonnull String str, @Nonnull Type type) { if (str.contains(".")) { - throw new RuntimeException("ClassConstants must use class names separated by '/', not '.'!"); + throw new IllegalArgumentException( + "ClassConstants must use class names separated by '/', not '.'!"); } this.value = str; this.type = type; @@ -113,7 +114,7 @@ public ClassConstant(@Nonnull String str, @Nonnull Type type) { public boolean isRefType() { return value.startsWith("L") && value.endsWith(";"); } - // TODO: [ms] code is quite like the one in Asmutil.java ? so we can/shall remove it? + // TODO: [ms] code is quite like the one in Asmutil.java ? so we can/shall refactor it? // /** Returns numDimensions. */ // public Type toSootType() { // int numDimensions = 0; diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java index 067aa461843..60d1a6a66a8 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java @@ -174,6 +174,10 @@ void setDeclaringClass(@Nonnull ClassType declaringClass) { this.declaringClass = (JavaClassType) declaringClass; } + int getCurrentLineNumber() { + return currentLineNumber; + } + @Override @Nonnull public Body resolveBody(@Nonnull Iterable modifierIt) { @@ -1291,6 +1295,7 @@ private void convertMethodInsn(@Nonnull MethodInsnNode insn) { List types = expr.getMethodSignature().getParameterTypes(); Operand[] oprs; int nrArgs = types.size(); + // TODO: check equivalent to isInstance? boolean isInstanceMethod = expr instanceof AbstractInstanceInvokeExpr; if (!isInstanceMethod) { oprs = nrArgs == 0 ? null : new Operand[nrArgs]; @@ -1311,7 +1316,7 @@ private void convertMethodInsn(@Nonnull MethodInsnNode insn) { } if (AsmUtil.isDWord(returnType)) { operandStack.pushDual(opr); - } else if (!(returnType == VoidType.getInstance())) { + } else if (returnType != VoidType.getInstance()) { operandStack.push(opr); } else if (!insnToStmt.containsKey(insn)) { JInvokeStmt stmt = diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/OperandStack.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/OperandStack.java index 103b06c059c..7a76f2a8300 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/OperandStack.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/OperandStack.java @@ -29,7 +29,7 @@ import org.objectweb.asm.tree.AbstractInsnNode; import sootup.core.jimple.Jimple; import sootup.core.jimple.basic.Local; -import sootup.core.jimple.basic.StmtPositionInfo; +import sootup.core.jimple.basic.SimpleStmtPositionInfo; import sootup.core.jimple.basic.Value; import sootup.core.jimple.common.constant.Constant; import sootup.core.types.Type; @@ -114,7 +114,9 @@ public Operand popLocal(@Nonnull Operand o) { if (l == null && !(v instanceof Local)) { l = o.stackLocal = methodSource.newStackLocal(); methodSource.setStmt( - o.insn, Jimple.newAssignStmt(l, v, StmtPositionInfo.createNoStmtPositionInfo())); + o.insn, + Jimple.newAssignStmt( + l, v, new SimpleStmtPositionInfo(methodSource.getCurrentLineNumber()))); o.updateUsages(); } return o; @@ -127,7 +129,9 @@ public Operand popImmediate(@Nonnull Operand o) { if (l == null && !(v instanceof Local) && !(v instanceof Constant)) { l = o.stackLocal = methodSource.newStackLocal(); methodSource.setStmt( - o.insn, Jimple.newAssignStmt(l, v, StmtPositionInfo.createNoStmtPositionInfo())); + o.insn, + Jimple.newAssignStmt( + l, v, new SimpleStmtPositionInfo(methodSource.getCurrentLineNumber()))); o.updateUsages(); } return o; @@ -140,7 +144,9 @@ public Operand popStackConst(@Nonnull Operand o) { if (l == null && !(v instanceof Constant)) { l = o.stackLocal = methodSource.newStackLocal(); methodSource.setStmt( - o.insn, Jimple.newAssignStmt(l, v, StmtPositionInfo.createNoStmtPositionInfo())); + o.insn, + Jimple.newAssignStmt( + l, v, new SimpleStmtPositionInfo(methodSource.getCurrentLineNumber()))); o.updateUsages(); } return o; From 9ae03e5f11f1a70e064296f4b15e17b3b7b633a4 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Fri, 21 Jul 2023 08:57:26 +0200 Subject: [PATCH 24/90] improved semantics / saved memory in case no position info is given --- .../bytecode/frontend/AsmMethodSource.java | 67 +++++++------------ .../java/bytecode/frontend/OperandStack.java | 16 +---- 2 files changed, 28 insertions(+), 55 deletions(-) diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java index 60d1a6a66a8..bc968018692 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java @@ -174,8 +174,10 @@ void setDeclaringClass(@Nonnull ClassType declaringClass) { this.declaringClass = (JavaClassType) declaringClass; } - int getCurrentLineNumber() { - return currentLineNumber; + StmtPositionInfo getStmtPositionInfo() { + return currentLineNumber > 0 + ? new SimpleStmtPositionInfo(currentLineNumber) + : StmtPositionInfo.createNoStmtPositionInfo(); } @Override @@ -387,7 +389,7 @@ private void addReadOperandAssignments_internal(BiFunction asssignStmt = - Jimple.newAssignStmt(stackLocal, opValue, new SimpleStmtPositionInfo(currentLineNumber)); + Jimple.newAssignStmt(stackLocal, opValue, getStmtPositionInfo()); setStmt(operand.insn, asssignStmt); operand.updateUsages(); @@ -453,8 +455,7 @@ private void convertPutFieldInsn(@Nonnull FieldInsnNode insn) { opr = new Operand(insn, val, this); frame.setOut(opr); JAssignStmt as = - Jimple.newAssignStmt( - val, rvalue.stackOrValue(), new SimpleStmtPositionInfo(currentLineNumber)); + Jimple.newAssignStmt(val, rvalue.stackOrValue(), getStmtPositionInfo()); setStmt(insn, as); rvalue.addUsageInStmt(as); } else { @@ -490,8 +491,7 @@ private void convertIincInsn(@Nonnull IincInsnNode insn) { addReadOperandAssignments(local); if (!insnToStmt.containsKey(insn)) { JAddExpr add = Jimple.newAddExpr(local, IntConstant.getInstance(insn.incr)); - setStmt( - insn, Jimple.newAssignStmt(local, add, new SimpleStmtPositionInfo(currentLineNumber))); + setStmt(insn, Jimple.newAssignStmt(local, add, getStmtPositionInfo())); } } @@ -564,8 +564,7 @@ private void convertArrayStoreInsn(@Nonnull InsnNode insn) { JavaJimple.getInstance() .newArrayRef((Local) baseOp.stackOrValue(), (Immediate) indexOp.stackOrValue()); JAssignStmt as = - Jimple.newAssignStmt( - ar, valueOp.stackOrValue(), new SimpleStmtPositionInfo(currentLineNumber)); + Jimple.newAssignStmt(ar, valueOp.stackOrValue(), getStmtPositionInfo()); frame.setIn(valueOp, indexOp, baseOp); setStmt(insn, as); valueOp.addUsageInStmt(as); @@ -851,9 +850,7 @@ private void convertReturnInsn(@Nonnull InsnNode insn) { StackFrame frame = operandStack.getOrCreateStackframe(insn); if (!insnToStmt.containsKey(insn)) { Operand val = dword ? operandStack.popImmediateDual() : operandStack.popImmediate(); - JReturnStmt ret = - Jimple.newReturnStmt( - (Immediate) val.stackOrValue(), new SimpleStmtPositionInfo(currentLineNumber)); + JReturnStmt ret = Jimple.newReturnStmt((Immediate) val.stackOrValue(), getStmtPositionInfo()); frame.setIn(val); setStmt(insn, ret); val.addUsageInStmt(ret); @@ -870,7 +867,7 @@ private void convertInsn(@Nonnull InsnNode insn) { * We can ignore NOP instructions, but for completeness, we handle them */ if (!insnToStmt.containsKey(insn)) { - insnToStmt.put(insn, Jimple.newNopStmt(new SimpleStmtPositionInfo(currentLineNumber))); + insnToStmt.put(insn, Jimple.newNopStmt(getStmtPositionInfo())); } } else if (op >= ACONST_NULL && op <= DCONST_1) { convertConstInsn(insn); @@ -906,16 +903,14 @@ private void convertInsn(@Nonnull InsnNode insn) { convertReturnInsn(insn); } else if (op == RETURN) { if (!insnToStmt.containsKey(insn)) { - setStmt(insn, Jimple.newReturnVoidStmt(new SimpleStmtPositionInfo(currentLineNumber))); + setStmt(insn, Jimple.newReturnVoidStmt(getStmtPositionInfo())); } } else if (op == ATHROW) { StackFrame frame = operandStack.getOrCreateStackframe(insn); Operand opr; if (!insnToStmt.containsKey(insn)) { opr = operandStack.popImmediate(); - JThrowStmt ts = - Jimple.newThrowStmt( - (Immediate) opr.stackOrValue(), new SimpleStmtPositionInfo(currentLineNumber)); + JThrowStmt ts = Jimple.newThrowStmt((Immediate) opr.stackOrValue(), getStmtPositionInfo()); frame.setIn(opr); frame.setOut(opr); setStmt(insn, ts); @@ -931,10 +926,8 @@ private void convertInsn(@Nonnull InsnNode insn) { Operand opr = operandStack.popStackConst(); AbstractOpStmt ts = op == MONITORENTER - ? Jimple.newEnterMonitorStmt( - (Immediate) opr.stackOrValue(), new SimpleStmtPositionInfo(currentLineNumber)) - : Jimple.newExitMonitorStmt( - (Immediate) opr.stackOrValue(), new SimpleStmtPositionInfo(currentLineNumber)); + ? Jimple.newEnterMonitorStmt((Immediate) opr.stackOrValue(), getStmtPositionInfo()) + : Jimple.newExitMonitorStmt((Immediate) opr.stackOrValue(), getStmtPositionInfo()); frame.setIn(opr); setStmt(insn, ts); opr.addUsageInStmt(ts); @@ -1008,7 +1001,7 @@ private void convertJumpInsn(@Nonnull JumpInsnNode insn) { int op = insn.getOpcode(); if (op == GOTO) { if (!insnToStmt.containsKey(insn)) { - BranchingStmt gotoStmt = Jimple.newGotoStmt(new SimpleStmtPositionInfo(currentLineNumber)); + BranchingStmt gotoStmt = Jimple.newGotoStmt(getStmtPositionInfo()); stmtsThatBranchToLabel.put(gotoStmt, insn.label); setStmt(insn, gotoStmt); } @@ -1086,7 +1079,7 @@ private void convertJumpInsn(@Nonnull JumpInsnNode insn) { val.addUsageInExpr(cond); frame.setIn(val); } - BranchingStmt ifStmt = Jimple.newIfStmt(cond, new SimpleStmtPositionInfo(currentLineNumber)); + BranchingStmt ifStmt = Jimple.newIfStmt(cond, getStmtPositionInfo()); stmtsThatBranchToLabel.put(ifStmt, insn.label); setStmt(insn, ifStmt); if (isCmp) { @@ -1202,8 +1195,7 @@ private void convertLookupSwitchInsn(@Nonnull LookupSwitchInsnNode insn) { keys.add(IntConstant.getInstance(i)); } JSwitchStmt lookupSwitchStmt = - Jimple.newLookupSwitchStmt( - (Immediate) key.stackOrValue(), keys, new SimpleStmtPositionInfo(currentLineNumber)); + Jimple.newLookupSwitchStmt((Immediate) key.stackOrValue(), keys, getStmtPositionInfo()); // uphold insertion order! stmtsThatBranchToLabel.putAll(lookupSwitchStmt, insn.labels); @@ -1320,8 +1312,7 @@ private void convertMethodInsn(@Nonnull MethodInsnNode insn) { operandStack.push(opr); } else if (!insnToStmt.containsKey(insn)) { JInvokeStmt stmt = - Jimple.newInvokeStmt( - (AbstractInvokeExpr) opr.value, new SimpleStmtPositionInfo(currentLineNumber)); + Jimple.newInvokeStmt((AbstractInvokeExpr) opr.value, getStmtPositionInfo()); setStmt(insn, stmt); opr.addUsageInStmt(stmt); } @@ -1412,8 +1403,7 @@ private void convertInvokeDynamicInsn(@Nonnull InvokeDynamicInsnNode insn) { operandStack.push(opr); } else if (!insnToStmt.containsKey(insn)) { JInvokeStmt stmt = - Jimple.newInvokeStmt( - (AbstractInvokeExpr) opr.value, new SimpleStmtPositionInfo(currentLineNumber)); + Jimple.newInvokeStmt((AbstractInvokeExpr) opr.value, getStmtPositionInfo()); setStmt(insn, stmt); opr.addUsageInStmt(stmt); } @@ -1490,10 +1480,7 @@ private void convertTableSwitchInsn(@Nonnull TableSwitchInsnNode insn) { Operand key = operandStack.popImmediate(); JSwitchStmt tableSwitchStmt = Jimple.newTableSwitchStmt( - (Immediate) key.stackOrValue(), - insn.min, - insn.max, - new SimpleStmtPositionInfo(currentLineNumber)); + (Immediate) key.stackOrValue(), insn.min, insn.max, getStmtPositionInfo()); // uphold insertion order! stmtsThatBranchToLabel.putAll(tableSwitchStmt, insn.labels); @@ -1586,8 +1573,7 @@ private void convertVarStoreInsn(@Nonnull VarInsnNode insn) { Local local = getOrCreateLocal(insn.var); if (!insnToStmt.containsKey(insn)) { AbstractDefinitionStmt as = - Jimple.newAssignStmt( - local, opr.stackOrValue(), new SimpleStmtPositionInfo(currentLineNumber)); + Jimple.newAssignStmt(local, opr.stackOrValue(), getStmtPositionInfo()); frame.setIn(opr); setStmt(insn, as); opr.addUsageInStmt(as); @@ -1606,10 +1592,7 @@ private void convertVarInsn(@Nonnull VarInsnNode insn) { } else if (op == RET) { /* we handle it, even though it should be removed */ if (!insnToStmt.containsKey(insn)) { - setStmt( - insn, - Jimple.newRetStmt( - getOrCreateLocal(insn.var), new SimpleStmtPositionInfo(currentLineNumber))); + setStmt(insn, Jimple.newRetStmt(getOrCreateLocal(insn.var), getStmtPositionInfo())); } } else { throw new UnsupportedOperationException("Unknown var op: " + op); @@ -1627,7 +1610,7 @@ private void convertLabel(@Nonnull LabelNode ln) { // code if (inlineExceptionLabels.contains(ln)) { if (!insnToStmt.containsKey(ln)) { - JNopStmt nop = Jimple.newNopStmt(new SimpleStmtPositionInfo(currentLineNumber)); + JNopStmt nop = Jimple.newNopStmt(getStmtPositionInfo()); setStmt(ln, nop); } return; @@ -1640,7 +1623,7 @@ private void convertLabel(@Nonnull LabelNode ln) { JCaughtExceptionRef ref = JavaJimple.getInstance().newCaughtExceptionRef(); Local stack = newStackLocal(); AbstractDefinitionStmt as = - Jimple.newIdentityStmt(stack, ref, new SimpleStmtPositionInfo(currentLineNumber)); + Jimple.newIdentityStmt(stack, ref, getStmtPositionInfo()); opr = new Operand(ln, ref, this); opr.stackLocal = stack; frame.setOut(opr); @@ -1721,7 +1704,7 @@ private void convert() { JCaughtExceptionRef ref = JavaJimple.getInstance().newCaughtExceptionRef(); Local local = newStackLocal(); AbstractDefinitionStmt as = - Jimple.newIdentityStmt(local, ref, new SimpleStmtPositionInfo(currentLineNumber)); + Jimple.newIdentityStmt(local, ref, getStmtPositionInfo()); Operand opr = new Operand(handlerNode, ref, this); opr.stackLocal = local; diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/OperandStack.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/OperandStack.java index 7a76f2a8300..5e799a3e42a 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/OperandStack.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/OperandStack.java @@ -29,7 +29,6 @@ import org.objectweb.asm.tree.AbstractInsnNode; import sootup.core.jimple.Jimple; import sootup.core.jimple.basic.Local; -import sootup.core.jimple.basic.SimpleStmtPositionInfo; import sootup.core.jimple.basic.Value; import sootup.core.jimple.common.constant.Constant; import sootup.core.types.Type; @@ -113,10 +112,7 @@ public Operand popLocal(@Nonnull Operand o) { Local l = o.stackLocal; if (l == null && !(v instanceof Local)) { l = o.stackLocal = methodSource.newStackLocal(); - methodSource.setStmt( - o.insn, - Jimple.newAssignStmt( - l, v, new SimpleStmtPositionInfo(methodSource.getCurrentLineNumber()))); + methodSource.setStmt(o.insn, Jimple.newAssignStmt(l, v, methodSource.getStmtPositionInfo())); o.updateUsages(); } return o; @@ -128,10 +124,7 @@ public Operand popImmediate(@Nonnull Operand o) { Local l = o.stackLocal; if (l == null && !(v instanceof Local) && !(v instanceof Constant)) { l = o.stackLocal = methodSource.newStackLocal(); - methodSource.setStmt( - o.insn, - Jimple.newAssignStmt( - l, v, new SimpleStmtPositionInfo(methodSource.getCurrentLineNumber()))); + methodSource.setStmt(o.insn, Jimple.newAssignStmt(l, v, methodSource.getStmtPositionInfo())); o.updateUsages(); } return o; @@ -143,10 +136,7 @@ public Operand popStackConst(@Nonnull Operand o) { Local l = o.stackLocal; if (l == null && !(v instanceof Constant)) { l = o.stackLocal = methodSource.newStackLocal(); - methodSource.setStmt( - o.insn, - Jimple.newAssignStmt( - l, v, new SimpleStmtPositionInfo(methodSource.getCurrentLineNumber()))); + methodSource.setStmt(o.insn, Jimple.newAssignStmt(l, v, methodSource.getStmtPositionInfo())); o.updateUsages(); } return o; From e497f3e42886784706972f4c0e89db92bf230bfb Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Fri, 21 Jul 2023 09:05:40 +0200 Subject: [PATCH 25/90] fix/add a Sourcetype to JRTAIL as well - may there be a usecase to adapt it to not library --- .../core/inputlocation/EagerInputLocation.java | 2 +- .../JrtFileSystemAnalysisInputLocation.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/sootup.core/src/main/java/sootup/core/inputlocation/EagerInputLocation.java b/sootup.core/src/main/java/sootup/core/inputlocation/EagerInputLocation.java index 4e41050a760..b73010302ee 100644 --- a/sootup.core/src/main/java/sootup/core/inputlocation/EagerInputLocation.java +++ b/sootup.core/src/main/java/sootup/core/inputlocation/EagerInputLocation.java @@ -70,7 +70,7 @@ public Collection> getClassSources(@Nullable Vi return map.values(); } - @Nullable + @Nonnull @Override public SourceType getSourceType() { return sourceType; diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JrtFileSystemAnalysisInputLocation.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JrtFileSystemAnalysisInputLocation.java index 6adc7520cc8..bfd9028131e 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JrtFileSystemAnalysisInputLocation.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JrtFileSystemAnalysisInputLocation.java @@ -33,11 +33,13 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import sootup.core.IdentifierFactory; import sootup.core.frontend.AbstractClassSource; import sootup.core.frontend.ClassProvider; import sootup.core.frontend.ResolveException; import sootup.core.inputlocation.AnalysisInputLocation; +import sootup.core.model.SourceType; import sootup.core.types.ClassType; import sootup.core.util.StreamUtils; import sootup.core.views.View; @@ -62,6 +64,16 @@ public class JrtFileSystemAnalysisInputLocation implements ModuleInfoAnalysisInp Map moduleInfoMap = new HashMap<>(); boolean isResolved = false; + private final SourceType sourceType; + + public JrtFileSystemAnalysisInputLocation() { + this(SourceType.Library); + } + + public JrtFileSystemAnalysisInputLocation(@Nonnull SourceType sourceType) { + this.sourceType = sourceType; + } + @Override @Nonnull public Optional> getClassSource( @@ -240,6 +252,12 @@ public Set getModules(View view) { return Collections.unmodifiableSet(moduleInfoMap.keySet()); } + @Nullable + @Override + public SourceType getSourceType() { + return null; + } + @Override public boolean equals(Object o) { return o instanceof JrtFileSystemAnalysisInputLocation; From c9314faad1889cb025dd3f278aad4693668d22fb Mon Sep 17 00:00:00 2001 From: palaniappan1 Date: Fri, 21 Jul 2023 13:59:57 +0200 Subject: [PATCH 26/90] ICFG Dot Exporter --- .../interprocedural/icfg/ICFGDotExporter.java | 90 ++++++++++++++++-- .../icfg/JimpleBasedInterproceduralCFG.java | 2 +- .../ifds/ICFGCallGraphTest.java | 66 ++++++++++++- .../icfg/binary/ICFGArrayListExample.class | Bin 0 -> 343 bytes .../icfg/binary/ICFGInterfaceExample.class | Bin 0 -> 445 bytes .../test/resources/icfg/binary/MyClass.class | Bin 0 -> 854 bytes .../resources/icfg/binary/MyInterface.class | Bin 0 -> 192 bytes .../icfg/source/ICFGArrayListExample.java | 9 ++ .../icfg/source/ICFGInterfaceExample.java | 30 ++++++ 9 files changed, 187 insertions(+), 10 deletions(-) create mode 100644 sootup.analysis/src/test/resources/icfg/binary/ICFGArrayListExample.class create mode 100644 sootup.analysis/src/test/resources/icfg/binary/ICFGInterfaceExample.class create mode 100644 sootup.analysis/src/test/resources/icfg/binary/MyClass.class create mode 100644 sootup.analysis/src/test/resources/icfg/binary/MyInterface.class create mode 100644 sootup.analysis/src/test/resources/icfg/source/ICFGArrayListExample.java create mode 100644 sootup.analysis/src/test/resources/icfg/source/ICFGInterfaceExample.java diff --git a/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/ICFGDotExporter.java b/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/ICFGDotExporter.java index f4f50e59667..036b4dade8e 100644 --- a/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/ICFGDotExporter.java +++ b/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/ICFGDotExporter.java @@ -1,22 +1,29 @@ package sootup.analysis.interprocedural.icfg; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.stream.Collectors; import sootup.core.graph.BasicBlock; import sootup.core.graph.StmtGraph; +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; +import sootup.core.typehierarchy.MethodDispatchResolver; +import sootup.core.types.VoidType; import sootup.core.util.DotExporter; +import sootup.core.views.View; public class ICFGDotExporter { - public static String buildICFGGraph(Map signatureToStmtGraph) { + public static String buildICFGGraph( + Map signatureToStmtGraph, View> view) { final StringBuilder sb = new StringBuilder(); DotExporter.buildDiGraphObject(sb); Map calls; - calls = computeCalls(signatureToStmtGraph.values()); + calls = computeCalls(signatureToStmtGraph, view); for (Map.Entry entry : signatureToStmtGraph.entrySet()) { String graph = DotExporter.buildGraph(entry.getValue(), true, calls, entry.getKey()); sb.append(graph + "\n"); @@ -29,9 +36,10 @@ public static String buildICFGGraph(Map signatureToS * This method finds out all the calls made in the given StmtGraphs, so it can be edged to other * methods. */ - public static Map computeCalls(Collection stmtGraphSet) { + public static Map computeCalls( + Map stmtGraphSet, View> view) { Map calls = new HashMap<>(); - for (StmtGraph stmtGraph : stmtGraphSet) { + for (StmtGraph stmtGraph : stmtGraphSet.values()) { Collection> blocks; try { blocks = stmtGraph.getBlocksSorted(); @@ -45,10 +53,76 @@ public static Map computeCalls(Collection s MethodSignature methodSignature = stmt.getInvokeExpr().getMethodSignature(); int hashCode = stmt.hashCode(); calls.put(hashCode, methodSignature); + // compute all the classes that are made to the subclasses as well + connectEdgesToSubClasses(methodSignature, view, calls); + } else if (stmt instanceof JAssignStmt) { + JAssignStmt jAssignStmt = (JAssignStmt) stmt; + Integer currentHashCode = stmt.hashCode(); + if (jAssignStmt.getRightOp() instanceof JNewExpr) { + // if the statement is a new expression, then there will be calls to its static + // initializers (init and clinit), so need to compute calls to them as well + for (MethodSignature methodSignature : stmtGraphSet.keySet()) { + SootMethod clintMethod = + view.getMethod(methodSignature.getDeclClassType().getStaticInitializer()) + .orElse(null); + if (clintMethod != null) { + if (!calls.containsKey(stmt.hashCode())) { + calls.put(stmt.hashCode(), methodSignature); + } else { + MethodSignature secondInitMethodSignature = calls.get(currentHashCode); + currentHashCode = + stmtGraphSet.get(secondInitMethodSignature).getStartingStmt().hashCode(); + calls.put(currentHashCode, methodSignature); + } + } + } + } } } } } return calls; } + + public static Set getMethodSignatureInSubClass( + MethodSignature targetMethodSignature, View> view) { + try { + return MethodDispatchResolver.resolveAllDispatches(view, targetMethodSignature).stream() + .map( + methodSignature -> + MethodDispatchResolver.resolveConcreteDispatch(view, methodSignature)) + .filter(Optional::isPresent) + .map(Optional::get) + .collect(Collectors.toSet()); + } catch (Exception e) { + return null; + } + } + + public static void connectEdgesToSubClasses( + MethodSignature methodSignature, + View> view, + Map calls) { + Set methodSignatureInSubClass = + getMethodSignatureInSubClass(methodSignature, view); + if (methodSignatureInSubClass != null) { + methodSignatureInSubClass.forEach( + subclassmethodSignature -> { + Optional method = view.getMethod(methodSignature); + MethodSignature initMethod = + new MethodSignature( + subclassmethodSignature.getDeclClassType(), + new MethodSubSignature( + "", Collections.emptyList(), VoidType.getInstance())); + if (method.isPresent() + && !subclassmethodSignature.toString().equals(initMethod.toString())) { + if (method.get().hasBody()) { + calls.put( + method.get().getBody().getStmtGraph().getStartingStmt().hashCode(), + subclassmethodSignature); + } + } + }); + } + } } diff --git a/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java b/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java index 57f8a44167c..1e9faa7cc42 100644 --- a/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java +++ b/sootup.analysis/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java @@ -152,7 +152,7 @@ public JimpleBasedInterproceduralCFG( public String buildICFGGraph(CallGraph callGraph) { Map signatureToStmtGraph = new LinkedHashMap<>(); computeAllCalls(mainMethodSignature, signatureToStmtGraph, callGraph); - return ICFGDotExporter.buildICFGGraph(signatureToStmtGraph); + return ICFGDotExporter.buildICFGGraph(signatureToStmtGraph, view); } public void computeAllCalls( diff --git a/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java b/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java index 231936e83c9..da9f8413925 100644 --- a/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java +++ b/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java @@ -115,13 +115,77 @@ public void ICFGDotExportTest2() { String.join(" -> ", digraph.blocks[0].edges)); } + @Test + public void ICFGArrayListDotExport() { + JavaProject javaProject = + JavaProject.builder(new JavaLanguage(8)) + .addInputLocation( + new JavaClassPathAnalysisInputLocation( + System.getProperty("java.home") + "/lib/rt.jar")) + .addInputLocation( + new JavaClassPathAnalysisInputLocation("src/test/resources/icfg/binary")) + .build(); + + view = javaProject.createView(); + + JavaIdentifierFactory identifierFactory = JavaIdentifierFactory.getInstance(); + JavaClassType mainClassSignature = identifierFactory.getClassType("ICFGArrayListExample"); + + SootClass sc = view.getClass(mainClassSignature).get(); + entryMethod = + sc.getMethods().stream().filter(e -> e.getName().equals("main")).findFirst().get(); + + entryMethodSignature = entryMethod.getSignature(); + + JimpleBasedInterproceduralCFG icfg = + new JimpleBasedInterproceduralCFG(view, entryMethodSignature, false, false); + CallGraph callGraph = loadCallGraph(view); + String expectedCallGraph = icfg.buildICFGGraph(callGraph); + Digraph digraph = parseDigraph(expectedCallGraph); + Assert.assertEquals( + edgesFromCallGraph(entryMethodSignature, icfg, callGraph), + String.join(" -> ", digraph.blocks[0].edges)); + } + + @Test + public void ICFGInterfaceDotExport() { + JavaProject javaProject = + JavaProject.builder(new JavaLanguage(8)) + .addInputLocation( + new JavaClassPathAnalysisInputLocation( + System.getProperty("java.home") + "/lib/rt.jar")) + .addInputLocation( + new JavaClassPathAnalysisInputLocation("src/test/resources/icfg/binary")) + .build(); + + view = javaProject.createView(); + + JavaIdentifierFactory identifierFactory = JavaIdentifierFactory.getInstance(); + JavaClassType mainClassSignature = identifierFactory.getClassType("ICFGInterfaceExample"); + + SootClass sc = view.getClass(mainClassSignature).get(); + entryMethod = + sc.getMethods().stream().filter(e -> e.getName().equals("main")).findFirst().get(); + + entryMethodSignature = entryMethod.getSignature(); + + JimpleBasedInterproceduralCFG icfg = + new JimpleBasedInterproceduralCFG(view, entryMethodSignature, false, false); + CallGraph callGraph = loadCallGraph(view); + String expectedCallGraph = icfg.buildICFGGraph(callGraph); + Digraph digraph = parseDigraph(expectedCallGraph); + Assert.assertEquals( + edgesFromCallGraph(entryMethodSignature, icfg, callGraph), + String.join(" -> ", digraph.blocks[0].edges)); + } + /** Compute the Edges of the given methodSignature from the provided callGraph */ public String edgesFromCallGraph( MethodSignature methodSignature, JimpleBasedInterproceduralCFG icfg, CallGraph callGraph) { Map signatureToStmtGraph = new LinkedHashMap<>(); icfg.computeAllCalls(methodSignature, signatureToStmtGraph, callGraph); Map calls; - calls = ICFGDotExporter.computeCalls(signatureToStmtGraph.values()); + calls = ICFGDotExporter.computeCalls(signatureToStmtGraph, view); final Optional methodOpt = view.getMethod(methodSignature); if (methodOpt.isPresent()) { SootMethod sootMethod = methodOpt.get(); diff --git a/sootup.analysis/src/test/resources/icfg/binary/ICFGArrayListExample.class b/sootup.analysis/src/test/resources/icfg/binary/ICFGArrayListExample.class new file mode 100644 index 0000000000000000000000000000000000000000..b1a302f900b92f0c22f462c5cb6521768252f8ca GIT binary patch literal 343 zcmZut%SyvQ6g@XhlQvfCYvaO&3#C;sA5bYsu_6RrR0MG~si90srZP@M|4LT{1wX)# z67NkwH_qZd&pn4TU*GSa0EXC%;Gq%1@1Ti*us&B$D$bRe#aHP(n>s>pqK$S#LZjEe z3DF{KRiM)8JU+Eny(Ie4MF@pwg|K}w8lV5p&z@EBkY@ycw7BQgO|;1_%OcI}wMwf+ zp|m0F_wJHE@rkqA%m)2>R7r`-fDlak literal 0 HcmV?d00001 diff --git a/sootup.analysis/src/test/resources/icfg/binary/ICFGInterfaceExample.class b/sootup.analysis/src/test/resources/icfg/binary/ICFGInterfaceExample.class new file mode 100644 index 0000000000000000000000000000000000000000..40c67eced0afc5c1d71ceae04299379479feb46f GIT binary patch literal 445 zcmZut%T5A85Uk;~u&%H?1;s>eix~L;kqhy$3FrZ1VmuAYNS4elWFJO8%L^o$_yK;D zvB!g4m`S>NrmL!Z=KJU43qT)D9SI~gqzt5yVKC?Xm3JlgXWjeBTsRR!rsw)@)MrRq z?MDq+25qz&NFIhdG$d8nGhkq!!Em^AV#y;hjy;C7W!r5#ivmOOR!F%xJF)#p1TWkX zEu||OD51=dpSs~v^3_O$A)g6`sx{mWGL8b*pIxZtRfdW^xW4(fxq9Q?Qj#JySWF2D zL)RB~u{ROH1E2gAJns4oHS2koC4)X*#DOEOT}5u}GCxYvb_HpmS-rfyc&&@Vfs{2Jy~T|$a@HDpO! OM3Wp_*;oh5v+) z;KB*12R?w0LX5FRQYGTBJ8#Et$1`tcfBnAs3E%?fC2S#QAz#Ke3JiN!{F=7|E+_5x zqbuPVhQdo<`sRWm*KA$x)2(6|J18+6&iPC@N_yOU@XeHvHe4FbaNg`K;|xsb%SorT z?y^v3u==qRaIGy=7K{4*4h`Pub&v7X{piK{RLB zZn|#EWvGmOy$E>R7h3ZP@eVfSami2`s3`PA*H41gT&Mfy-(O#U;qyfxUL^UG9Iuoz z+Jt=37iOx)x>`W3ghx2CP)}qyW@s!+_2spiiFR6Xs!W%AMujoM*VSAyVjA=<8F)0@NPblh5gX7yE=0YCRchviYO>r*C9enLBj4hx-|`K{jC)pWna&`pdYF7`Sa^e^(E|uJVr0Q!5wQQRYlv*3BpWeTv+w{OO58MB4Ls&C z^Zq+(3v>5XPsh zx@m4=RaKlS!Zg_Z<;0X(kuJjn!B4JrDOHqdTbhY=wEazP9-QB_nzvpLAav|Ez_CYM OSYXpb-x9*0(); + return arrayList; + } +} \ No newline at end of file diff --git a/sootup.analysis/src/test/resources/icfg/source/ICFGInterfaceExample.java b/sootup.analysis/src/test/resources/icfg/source/ICFGInterfaceExample.java new file mode 100644 index 00000000000..16286ea7135 --- /dev/null +++ b/sootup.analysis/src/test/resources/icfg/source/ICFGInterfaceExample.java @@ -0,0 +1,30 @@ +interface MyInterface { + int calculateSum(int a, int b); + void displayMessage(String message); +} + +class MyClass implements MyInterface { + @Override + public int calculateSum(int a, int b) { + return a + b; + } + + @Override + public void displayMessage(String message) { + String string = "The Message to be displayed is " + message; + } +} + +// Main class to demonstrate the interface methods +public class ICFGInterfaceExample { + public static void main(String[] args) { + // Create an instance of MyClass + MyClass myClass = new MyClass(); + + // Call the calculateSum method + int result = myClass.calculateSum(10, 20); + + // Call the displayMessage method + myClass.displayMessage("Hello, Interface!"); + } +} From b6b350728bada70c67e1204ae28051ab1fd968bf Mon Sep 17 00:00:00 2001 From: Jonas Klauke Date: Mon, 24 Jul 2023 11:24:00 +0200 Subject: [PATCH 27/90] added cite --- CITATION.cff | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 CITATION.cff diff --git a/CITATION.cff b/CITATION.cff new file mode 100644 index 00000000000..4d30000d111 --- /dev/null +++ b/CITATION.cff @@ -0,0 +1,9 @@ +cff-version: 1.2.0 +title: SootUp +message: 'If you use SootUp, please cite it as below.' +type: software +authors: + - given-names: Soot-oss +repository-code: 'https://github.com/soot-oss/SootUp' +version: 1.1.2 +date-released: '2023-06-12' \ No newline at end of file From 44f8e0fe3e4c7863dad51d3f50bd7bd9d7513485 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Wed, 26 Jul 2023 14:01:43 +0200 Subject: [PATCH 28/90] use cached vales i.e. typehierarchy --- .../core/typehierarchy/ViewTypeHierarchy.java | 2 + .../typeresolving/AugEvalFunction.java | 82 +++++++++---------- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/typehierarchy/ViewTypeHierarchy.java b/sootup.core/src/main/java/sootup/core/typehierarchy/ViewTypeHierarchy.java index 713edba8e78..63c94141289 100644 --- a/sootup.core/src/main/java/sootup/core/typehierarchy/ViewTypeHierarchy.java +++ b/sootup.core/src/main/java/sootup/core/typehierarchy/ViewTypeHierarchy.java @@ -216,6 +216,7 @@ public Set directlyExtendedInterfacesOf(@Nonnull ClassType interfaceT .collect(Collectors.toSet()); } + /** method exists for completeness - SootClass.getSuperClass() should be more performant. */ @Nullable public ClassType directSuperClassOf(@Nonnull ClassType classType) { Vertex vertex = lazyScanResult.get().typeToVertex.get(classType); @@ -230,6 +231,7 @@ public ClassType directSuperClassOf(@Nonnull ClassType classType) { .collect(Collectors.toList()); if (list.isEmpty()) { + /* is java.lang.Object */ return null; } else if (list.size() > 1) { throw new RuntimeException(classType + "cannot have multiple superclasses"); diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/AugEvalFunction.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/AugEvalFunction.java index 06785cc9bca..81fe527dd53 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/AugEvalFunction.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/AugEvalFunction.java @@ -23,7 +23,6 @@ import java.util.*; import javax.annotation.Nonnull; -import sootup.core.IdentifierFactory; import sootup.core.graph.StmtGraph; import sootup.core.jimple.basic.Immediate; import sootup.core.jimple.basic.Local; @@ -33,7 +32,6 @@ import sootup.core.jimple.common.ref.*; import sootup.core.jimple.common.stmt.Stmt; import sootup.core.model.SootClass; -import sootup.core.typehierarchy.ViewTypeHierarchy; import sootup.core.types.ArrayType; import sootup.core.types.ClassType; import sootup.core.types.PrimitiveType; @@ -41,16 +39,33 @@ import sootup.core.views.View; import sootup.java.bytecode.interceptors.typeresolving.types.AugIntegerTypes; import sootup.java.bytecode.interceptors.typeresolving.types.BottomType; -import sootup.java.core.JavaIdentifierFactory; /** @author Zun Wang */ public class AugEvalFunction { - IdentifierFactory factory = JavaIdentifierFactory.getInstance(); + + private final Set evalClassTypes = new HashSet<>(); + private final ClassType stringClassType; + private final ClassType classClassType; + private final ClassType methodHandleClassType; + private final ClassType methodTypeClassType; + private final ClassType throwableClassType; + View> view; PrimitiveHierarchy primitiveHierarchy = new PrimitiveHierarchy(); public AugEvalFunction(View> view) { this.view = view; + + // one time setup + evalClassTypes.add(view.getIdentifierFactory().getClassType("java.lang.Object")); + evalClassTypes.add(view.getIdentifierFactory().getClassType("java.lang.Cloneable")); + evalClassTypes.add(view.getIdentifierFactory().getClassType("java.io.Serializable")); + + stringClassType = view.getIdentifierFactory().getClassType("java.lang.String"); + classClassType = view.getIdentifierFactory().getClassType("java.lang.Class"); + methodHandleClassType = view.getIdentifierFactory().getClassType("java.lang.MethodHandle"); + methodTypeClassType = view.getIdentifierFactory().getClassType("java.lang.MethodType"); + throwableClassType = view.getIdentifierFactory().getClassType("java.lang.Throwable"); } /** @@ -91,15 +106,15 @@ public Type evaluate( || value instanceof EnumConstant) { return value.getType(); } else if (value instanceof StringConstant) { - return factory.getClassType("java.lang.String"); + return stringClassType; } else if (value instanceof ClassConstant) { - return factory.getClassType("java.lang.Class"); + return classClassType; } else if (value instanceof MethodHandle) { - return factory.getClassType("java.lang.MethodHandle"); + return methodHandleClassType; } else if (value instanceof MethodType) { - return factory.getClassType("java.lang.MethodType"); + return methodTypeClassType; } else { - throw new RuntimeException("Invaluable constant in AugEvalFunction: " + value); + throw new RuntimeException("Invaluable constant in AugEvalFunction '" + value + "'."); } } } else if (value instanceof Expr) { @@ -127,7 +142,7 @@ public Type evaluate( Collection set = primitiveHierarchy.getLeastCommonAncestor(tl, tr); if (set.isEmpty()) { throw new RuntimeException( - "Invaluable expression by using AugEvalFunction: " + value); + "Invaluable expression by using AugEvalFunction '" + value + "'."); } return set.iterator().next(); } @@ -151,7 +166,6 @@ public Type evaluate( } else if (value instanceof Ref) { if (value instanceof JCaughtExceptionRef) { Set exceptionTypes = getExceptionTypeCandidates(stmt, graph); - ClassType throwable = factory.getClassType("java.lang.Throwable"); ClassType type = null; for (ClassType exceptionType : exceptionTypes) { Optional exceptionClassOp = view.getClass(exceptionType); @@ -159,11 +173,10 @@ public Type evaluate( if (exceptionClassOp.isPresent()) { exceptionClass = (SootClass) exceptionClassOp.get(); } else { - throw new RuntimeException( - "ExceptionType: \"" + exceptionType + "\" is not in the view"); + throw new RuntimeException("ExceptionType '" + exceptionType + "' is not in the view"); } if (exceptionClass.isPhantomClass()) { - return throwable; + return throwableClassType; } else if (type == null) { type = exceptionType; } else { @@ -171,7 +184,7 @@ public Type evaluate( } } if (type == null) { - throw new RuntimeException("Invaluable reference in AugEvalFunction: " + value); + throw new RuntimeException("Invaluable reference in AugEvalFunction '" + value + "'."); } return type; } else if (value instanceof JArrayRef) { @@ -181,22 +194,7 @@ public Type evaluate( // Because Object, Serializable and Cloneable are super types of any ArrayType, thus the // base type of ArrayRef could be one of this three types } else if (type instanceof ClassType) { - String name = ((ClassType) type).getFullyQualifiedName(); - Type retType; - switch (name) { - case "java.lang.Object": - retType = factory.getClassType("java.lang.Object"); - break; - case "java.lang.Cloneable": - retType = factory.getClassType("java.lang.Cloneable"); - break; - case "java.io.Serializable": - retType = factory.getClassType("java.io.Serializable"); - break; - default: - retType = BottomType.getInstance(); - } - return retType; + return evalClassTypes.contains(type) ? type : BottomType.getInstance(); } else { return BottomType.getInstance(); } @@ -205,7 +203,7 @@ public Type evaluate( || value instanceof JFieldRef) { return value.getType(); } else { - throw new RuntimeException("Invaluable reference in AugEvalFunction: " + value); + throw new RuntimeException("Invaluable reference in AugEvalFunction '" + value + "'."); } } return null; @@ -225,20 +223,20 @@ private Set getExceptionTypeCandidates( * type */ private Deque getExceptionPath(@Nonnull ClassType exceptionType) { - ViewTypeHierarchy hierarchy = new ViewTypeHierarchy(view); - ClassType throwable = factory.getClassType("java.lang.Throwable"); Deque path = new ArrayDeque<>(); path.push(exceptionType); - while (!exceptionType.equals(throwable)) { - ClassType superType = hierarchy.directSuperClassOf(exceptionType); - if (superType != null) { - path.push(superType); - exceptionType = superType; - } else { - throw new RuntimeException( - "The path from " + exceptionType + " to java.lang.Throwable cannot be found!"); + while (!exceptionType.equals(throwableClassType)) { + final Optional superclassOpt = + view.getClass(exceptionType).flatMap(SootClass::getSuperclass); + if (!superclassOpt.isPresent()) { + throw new IllegalStateException( + "The path from '" + exceptionType + "' to java.lang.Throwable cannot be found!"); } + + ClassType superType = superclassOpt.get(); + path.push(superType); + exceptionType = superType; } return path; } From 3b817f2186a609b03f715537a67b5ca411bec342 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Wed, 26 Jul 2023 18:37:38 +0200 Subject: [PATCH 29/90] reuse identifierfactory --- .../typeresolving/AugEvalFunction.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/AugEvalFunction.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/AugEvalFunction.java index 81fe527dd53..33b8efb4000 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/AugEvalFunction.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/AugEvalFunction.java @@ -21,8 +21,10 @@ * #L% */ +import com.google.common.collect.ImmutableSet; import java.util.*; import javax.annotation.Nonnull; +import sootup.core.IdentifierFactory; import sootup.core.graph.StmtGraph; import sootup.core.jimple.basic.Immediate; import sootup.core.jimple.basic.Local; @@ -43,7 +45,7 @@ /** @author Zun Wang */ public class AugEvalFunction { - private final Set evalClassTypes = new HashSet<>(); + private final ImmutableSet evalClassTypes; private final ClassType stringClassType; private final ClassType classClassType; private final ClassType methodHandleClassType; @@ -57,15 +59,18 @@ public AugEvalFunction(View> view) { this.view = view; // one time setup - evalClassTypes.add(view.getIdentifierFactory().getClassType("java.lang.Object")); - evalClassTypes.add(view.getIdentifierFactory().getClassType("java.lang.Cloneable")); - evalClassTypes.add(view.getIdentifierFactory().getClassType("java.io.Serializable")); + final IdentifierFactory identifierFactory = view.getIdentifierFactory(); + evalClassTypes = + ImmutableSet.of( + identifierFactory.getClassType("java.lang.Object"), + identifierFactory.getClassType("java.lang.Cloneable"), + identifierFactory.getClassType("java.io.Serializable")); - stringClassType = view.getIdentifierFactory().getClassType("java.lang.String"); - classClassType = view.getIdentifierFactory().getClassType("java.lang.Class"); - methodHandleClassType = view.getIdentifierFactory().getClassType("java.lang.MethodHandle"); - methodTypeClassType = view.getIdentifierFactory().getClassType("java.lang.MethodType"); - throwableClassType = view.getIdentifierFactory().getClassType("java.lang.Throwable"); + stringClassType = identifierFactory.getClassType("java.lang.String"); + classClassType = identifierFactory.getClassType("java.lang.Class"); + methodHandleClassType = identifierFactory.getClassType("java.lang.MethodHandle"); + methodTypeClassType = identifierFactory.getClassType("java.lang.MethodType"); + throwableClassType = identifierFactory.getClassType("java.lang.Throwable"); } /** From 10fea0b23c8bb0a6cbdf4bd187a222f2c3681793 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Wed, 26 Jul 2023 19:03:21 +0200 Subject: [PATCH 30/90] cache ClassTypes in identifierfactory as well; make use of this mechanism so we can compare via == --- .../core/typehierarchy/TypeHierarchy.java | 2 +- .../core/typehierarchy/ViewTypeHierarchy.java | 1 - .../typeresolving/AugEvalFunction.java | 44 +++++++++++-------- .../java/core/JavaIdentifierFactory.java | 20 ++++++--- .../core/JavaModuleIdentifierFactory.java | 4 +- 5 files changed, 42 insertions(+), 29 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/typehierarchy/TypeHierarchy.java b/sootup.core/src/main/java/sootup/core/typehierarchy/TypeHierarchy.java index d3d355e5310..fe34a54eb07 100644 --- a/sootup.core/src/main/java/sootup/core/typehierarchy/TypeHierarchy.java +++ b/sootup.core/src/main/java/sootup/core/typehierarchy/TypeHierarchy.java @@ -172,7 +172,7 @@ default boolean isSubtype(@Nonnull Type supertype, @Nonnull Type potentialSubtyp /** * Returns all superclasses of classType up to java.lang.Object, which - * will be the last entry in the list. + * will be the last entry in the list. i.e. its ordered from bottom level to top level. */ @Nonnull default List superClassesOf(@Nonnull ClassType classType) { diff --git a/sootup.core/src/main/java/sootup/core/typehierarchy/ViewTypeHierarchy.java b/sootup.core/src/main/java/sootup/core/typehierarchy/ViewTypeHierarchy.java index 63c94141289..7af3588bd9b 100644 --- a/sootup.core/src/main/java/sootup/core/typehierarchy/ViewTypeHierarchy.java +++ b/sootup.core/src/main/java/sootup/core/typehierarchy/ViewTypeHierarchy.java @@ -181,7 +181,6 @@ public Stream directlyExtendedInterfacesOf(@Nonnull Vertex interfaceVert .map(graph::getEdgeTarget); } - /** for completeness - You could use Sootclass.getSuperclass() directly */ public Stream directSuperClassOf(@Nonnull Vertex classVertex) { Graph graph = lazyScanResult.get().graph; return graph.outgoingEdgesOf(classVertex).stream() diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/AugEvalFunction.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/AugEvalFunction.java index 33b8efb4000..ce80b28ba81 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/AugEvalFunction.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/AugEvalFunction.java @@ -82,12 +82,15 @@ public Type evaluate( @Nonnull Value value, @Nonnull Stmt stmt, @Nonnull StmtGraph graph) { + + // TODO: [ms] make use of the ValueVisitor.. + if (value instanceof Immediate) { if (value instanceof Local) { return typing.getType((Local) value); // if value instanceof Constant } else { - if (value instanceof IntConstant) { + if (value.getClass() == IntConstant.class) { int val = ((IntConstant) value).getValue(); if (val >= 0 && val < 2) { return AugIntegerTypes.getInteger1(); @@ -104,19 +107,19 @@ public Type evaluate( } else { return PrimitiveType.getInt(); } - } else if (value instanceof LongConstant - || value instanceof FloatConstant - || value instanceof DoubleConstant - || value instanceof NullConstant - || value instanceof EnumConstant) { + } else if (value.getClass() == LongConstant.class + || value.getClass() == FloatConstant.class + || value.getClass() == DoubleConstant.class + || value.getClass() == NullConstant.class + || value.getClass() == EnumConstant.class) { return value.getType(); - } else if (value instanceof StringConstant) { + } else if (value.getClass() == StringConstant.class) { return stringClassType; - } else if (value instanceof ClassConstant) { + } else if (value.getClass() == ClassConstant.class) { return classClassType; - } else if (value instanceof MethodHandle) { + } else if (value.getClass() == MethodHandle.class) { return methodHandleClassType; - } else if (value instanceof MethodType) { + } else if (value.getClass() == MethodType.class) { return methodTypeClassType; } else { throw new RuntimeException("Invaluable constant in AugEvalFunction '" + value + "'."); @@ -139,9 +142,12 @@ public Type evaluate( return (tl instanceof PrimitiveType.IntType) ? PrimitiveType.getInt() : tl; } else { if (tl instanceof PrimitiveType.IntType && tr instanceof PrimitiveType.IntType) { - if (tl instanceof PrimitiveType.BooleanType) { - return (tr instanceof PrimitiveType.BooleanType) ? PrimitiveType.getBoolean() : tr; - } else if (tr instanceof PrimitiveType.BooleanType) { + + if (tl.getClass() == PrimitiveType.BooleanType.class) { + return (tr.getClass() == PrimitiveType.BooleanType.class) + ? PrimitiveType.getBoolean() + : tr; + } else if (tr.getClass() == PrimitiveType.BooleanType.class) { return tl; } else { Collection set = primitiveHierarchy.getLeastCommonAncestor(tl, tr); @@ -152,7 +158,7 @@ public Type evaluate( return set.iterator().next(); } } else { - return (tl instanceof PrimitiveType.LongType) ? PrimitiveType.getLong() : tr; + return (tl.getClass() == PrimitiveType.LongType.class) ? PrimitiveType.getLong() : tr; } } } else if (value instanceof AbstractFloatBinopExpr) { @@ -203,9 +209,9 @@ public Type evaluate( } else { return BottomType.getInstance(); } - } else if (value instanceof JThisRef - || value instanceof JParameterRef - || value instanceof JFieldRef) { + } else if (value.getClass() == JThisRef.class + || value.getClass() == JParameterRef.class + || value.getClass() == JFieldRef.class) { return value.getType(); } else { throw new RuntimeException("Invaluable reference in AugEvalFunction '" + value + "'."); @@ -231,7 +237,7 @@ private Deque getExceptionPath(@Nonnull ClassType exceptionType) { Deque path = new ArrayDeque<>(); path.push(exceptionType); - while (!exceptionType.equals(throwableClassType)) { + while (exceptionType != throwableClassType) { final Optional superclassOpt = view.getClass(exceptionType).flatMap(SootClass::getSuperclass); if (!superclassOpt.isPresent()) { @@ -259,7 +265,7 @@ private ClassType getLeastCommonExceptionType(@Nonnull ClassType a, @Nonnull Cla ClassType commonType = null; Deque pathA = getExceptionPath(a); Deque pathB = getExceptionPath(b); - while (!pathA.isEmpty() && !pathB.isEmpty() && pathA.getFirst().equals(pathB.getFirst())) { + while (!pathA.isEmpty() && !pathB.isEmpty() && pathA.peekFirst().equals(pathB.peekFirst())) { commonType = pathA.removeFirst(); pathB.removeFirst(); } diff --git a/sootup.java.core/src/main/java/sootup/java/core/JavaIdentifierFactory.java b/sootup.java.core/src/main/java/sootup/java/core/JavaIdentifierFactory.java index bda893da40f..c9742affc49 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/JavaIdentifierFactory.java +++ b/sootup.java.core/src/main/java/sootup/java/core/JavaIdentifierFactory.java @@ -60,12 +60,17 @@ public class JavaIdentifierFactory implements IdentifierFactory { /** Caches the created PackageNames for packages. */ @Nonnull - protected final Cache packages = + protected final Cache packageCache = CacheBuilder.newBuilder().weakValues().build(); /** Caches annotation types */ @Nonnull - protected final Cache annotationTypes = + protected final Cache annotationTypeCache = + CacheBuilder.newBuilder().weakValues().build(); + + /** Caches class types */ + @Nonnull + protected final Cache classTypeCache = CacheBuilder.newBuilder().weakValues().build(); @Nonnull @@ -77,7 +82,7 @@ public static JavaIdentifierFactory getInstance() { JavaIdentifierFactory() { /* Represents the default package. */ - packages.put(PackageName.DEFAULT_PACKAGE.getName(), PackageName.DEFAULT_PACKAGE); + packageCache.put(PackageName.DEFAULT_PACKAGE.getName(), PackageName.DEFAULT_PACKAGE); // initialize primitive map primitiveTypeMap.put( @@ -112,7 +117,10 @@ public static JavaIdentifierFactory getInstance() { @Override public JavaClassType getClassType(final String className, final String packageName) { PackageName packageIdentifier = getPackageName(packageName); - return new JavaClassType(className, packageIdentifier); + return classTypeCache + .asMap() + .computeIfAbsent( + className + packageName, (k) -> new JavaClassType(className, packageIdentifier)); } /** @@ -216,7 +224,7 @@ public AnnotationType getAnnotationType(final String fullyQualifiedClassName) { String className = ClassUtils.getShortClassName(fullyQualifiedClassName); String packageName = ClassUtils.getPackageName(fullyQualifiedClassName); - return annotationTypes + return annotationTypeCache .asMap() .computeIfAbsent( className + packageName, @@ -260,7 +268,7 @@ public JavaClassType fromPath(@Nonnull final Path rootDirectory, @Nonnull final */ @Override public PackageName getPackageName(@Nonnull final String packageName) { - return packages.asMap().computeIfAbsent(packageName, PackageName::new); + return packageCache.asMap().computeIfAbsent(packageName, PackageName::new); } /** diff --git a/sootup.java.core/src/main/java/sootup/java/core/JavaModuleIdentifierFactory.java b/sootup.java.core/src/main/java/sootup/java/core/JavaModuleIdentifierFactory.java index 572dc3738e1..2f504ac914f 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/JavaModuleIdentifierFactory.java +++ b/sootup.java.core/src/main/java/sootup/java/core/JavaModuleIdentifierFactory.java @@ -163,7 +163,7 @@ public ModulePackageName getPackageName( @Nonnull final String packageName, @Nonnull final String moduleName) { String fqId = moduleName + "." + packageName; return (ModulePackageName) - packages + packageCache .asMap() .computeIfAbsent( fqId, key -> new ModulePackageName(packageName, getModuleSignature(moduleName))); @@ -173,7 +173,7 @@ public ModulePackageName getPackageName( @Nonnull final String packageName, @Nonnull final ModuleSignature moduleSignature) { String fqId = moduleSignature.getModuleName() + "." + packageName; return (ModulePackageName) - packages + packageCache .asMap() .computeIfAbsent(fqId, key -> new ModulePackageName(packageName, moduleSignature)); } From 89be31973616860eba1515eca654d7cb8347c0a9 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Wed, 26 Jul 2023 19:27:00 +0200 Subject: [PATCH 31/90] make instanceof to incorporate previous types via == --- .../typeresolving/AugEvalFunction.java | 2 +- .../typeresolving/PrimitiveHierarchy.java | 115 ++++++++++-------- 2 files changed, 64 insertions(+), 53 deletions(-) diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/AugEvalFunction.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/AugEvalFunction.java index ce80b28ba81..8a7148cc41f 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/AugEvalFunction.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/AugEvalFunction.java @@ -259,7 +259,7 @@ private Deque getExceptionPath(@Nonnull ClassType exceptionType) { * @param b an exception type */ private ClassType getLeastCommonExceptionType(@Nonnull ClassType a, @Nonnull ClassType b) { - if (a.equals(b)) { + if (a == b) { return a; } ClassType commonType = null; diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/PrimitiveHierarchy.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/PrimitiveHierarchy.java index ff1de2ce86d..d2a1fc1348e 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/PrimitiveHierarchy.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/PrimitiveHierarchy.java @@ -49,22 +49,24 @@ public Collection getLeastCommonAncestor(@Nonnull Type a, @Nonnull Type b) return Collections.singleton(a); } else if (isAncestor(b, a)) { return Collections.singleton(b); - } else if (a instanceof PrimitiveType.ByteType) { - if (b instanceof PrimitiveType.ShortType - || b instanceof PrimitiveType.CharType - || b instanceof AugIntegerTypes.Integer32767Type) { + } else if (a.getClass() == PrimitiveType.ByteType.class) { + if (b.getClass() == PrimitiveType.ShortType.class + || b.getClass() == PrimitiveType.CharType.class + || b.getClass() == AugIntegerTypes.Integer32767Type.class) { return Collections.singleton(PrimitiveType.getInt()); } else { return Collections.emptySet(); } - } else if (a instanceof PrimitiveType.ShortType) { - if (b instanceof PrimitiveType.ByteType || b instanceof PrimitiveType.CharType) { + } else if (a.getClass() == PrimitiveType.ShortType.class) { + if (b.getClass() == PrimitiveType.ByteType.class + || b.getClass() == PrimitiveType.CharType.class) { return Collections.singleton(PrimitiveType.getInt()); } else { return Collections.emptySet(); } - } else if (a instanceof PrimitiveType.CharType) { - if (b instanceof PrimitiveType.ByteType || b instanceof PrimitiveType.ShortType) { + } else if (a.getClass() == PrimitiveType.CharType.class) { + if (b.getClass() == PrimitiveType.ByteType.class + || b.getClass() == PrimitiveType.ShortType.class) { return Collections.singleton(PrimitiveType.getInt()); } else { return Collections.emptySet(); @@ -85,70 +87,79 @@ public Collection getLeastCommonAncestor(@Nonnull Type a, @Nonnull Type b) @Override public boolean isAncestor(@Nonnull Type ancestor, @Nonnull Type child) { - if (ancestor.equals(child)) { + if (ancestor == child) { return true; - } else if (arePrimitives(ancestor, child)) { - if (ancestor instanceof AugIntegerTypes.Integer1Type) { - return child instanceof BottomType; - } else if (ancestor instanceof PrimitiveType.BooleanType - || ancestor instanceof AugIntegerTypes.Integer127Type) { - return child instanceof AugIntegerTypes.Integer1Type || child instanceof BottomType; - } else if (ancestor instanceof PrimitiveType.ByteType - || ancestor instanceof AugIntegerTypes.Integer32767Type) { - return child instanceof AugIntegerTypes.Integer127Type - || child instanceof AugIntegerTypes.Integer1Type - || child instanceof BottomType; - } else if (ancestor instanceof PrimitiveType.CharType - || ancestor instanceof PrimitiveType.ShortType) { - return child instanceof AugIntegerTypes.Integer32767Type - || child instanceof AugIntegerTypes.Integer127Type - || child instanceof AugIntegerTypes.Integer1Type - || child instanceof BottomType; + } + + if (arePrimitives(ancestor, child)) { + if (ancestor.getClass() == AugIntegerTypes.Integer1Type.class) { + return child.getClass() == BottomType.class; + } else if (ancestor.getClass() == PrimitiveType.BooleanType.class + || ancestor.getClass() == AugIntegerTypes.Integer127Type.class) { + return child.getClass() == AugIntegerTypes.Integer1Type.class + || child.getClass() == BottomType.class; + } else if (ancestor.getClass() == PrimitiveType.ByteType.class + || ancestor.getClass() == AugIntegerTypes.Integer32767Type.class) { + return child.getClass() == AugIntegerTypes.Integer127Type.class + || child.getClass() == AugIntegerTypes.Integer1Type.class + || child.getClass() == BottomType.class; + } else if (ancestor.getClass() == PrimitiveType.CharType.class + || ancestor.getClass() == PrimitiveType.ShortType.class) { + return child.getClass() == AugIntegerTypes.Integer32767Type.class + || child.getClass() == AugIntegerTypes.Integer127Type.class + || child.getClass() == AugIntegerTypes.Integer1Type.class + || child.getClass() == BottomType.class; } else if (ancestor instanceof PrimitiveType.IntType) { - return (!(child instanceof PrimitiveType.BooleanType) + return (!(child.getClass() == PrimitiveType.BooleanType.class) && (child instanceof PrimitiveType.IntType)) - || child instanceof BottomType; + || child.getClass() == BottomType.class; } else { - return child instanceof BottomType; + return child.getClass() == BottomType.class; } - } else if (ancestor instanceof ArrayType && child instanceof ArrayType) { + } + + if (ancestor instanceof ArrayType && child instanceof ArrayType) { Type ancestorBase = ((ArrayType) ancestor).getBaseType(); Type childBase = ((ArrayType) child).getBaseType(); int ancestorDim = ((ArrayType) ancestor).getDimension(); int childDim = ((ArrayType) child).getDimension(); if (ancestorDim == childDim && arePrimitives(ancestorBase, childBase)) { - if (ancestorBase instanceof AugIntegerTypes.Integer1Type) { - return childBase instanceof BottomType; - } else if (ancestorBase instanceof PrimitiveType.BooleanType - || ancestorBase instanceof AugIntegerTypes.Integer127Type) { - return childBase instanceof AugIntegerTypes.Integer1Type - || childBase instanceof BottomType; - } else if (ancestorBase instanceof PrimitiveType.ByteType - || ancestorBase instanceof AugIntegerTypes.Integer32767Type) { - return childBase instanceof AugIntegerTypes.Integer127Type - || childBase instanceof AugIntegerTypes.Integer1Type - || childBase instanceof BottomType; - } else if (ancestorBase instanceof PrimitiveType.IntType) { - return childBase instanceof AugIntegerTypes.Integer32767Type - || childBase instanceof AugIntegerTypes.Integer127Type - || childBase instanceof AugIntegerTypes.Integer1Type - || childBase instanceof BottomType; + // TODO: [ms] dry? looks quite similar to the if-else-tree above.. why are they differing in + // structure? + if (ancestorBase.getClass() == AugIntegerTypes.Integer1Type.class) { + return childBase.getClass() == BottomType.class; + } else if (ancestorBase.getClass() == PrimitiveType.BooleanType.class + || ancestorBase.getClass() == AugIntegerTypes.Integer127Type.class) { + return childBase.getClass() == AugIntegerTypes.Integer1Type.class + || childBase.getClass() == BottomType.class; + } else if (ancestorBase.getClass() == PrimitiveType.ByteType.class + || ancestorBase.getClass() == AugIntegerTypes.Integer32767Type.class) { + return childBase.getClass() == AugIntegerTypes.Integer127Type.class + || childBase.getClass() == AugIntegerTypes.Integer1Type.class + || childBase.getClass() == BottomType.class; + } else if (ancestorBase.getClass() == PrimitiveType.CharType.class + || ancestorBase.getClass() == PrimitiveType.ShortType.class + || ancestorBase instanceof PrimitiveType.IntType) { + return childBase.getClass() == AugIntegerTypes.Integer32767Type.class + || childBase.getClass() == AugIntegerTypes.Integer127Type.class + || childBase.getClass() == AugIntegerTypes.Integer1Type.class + || childBase.getClass() == BottomType.class; } else { - return childBase instanceof BottomType; + return childBase.getClass() == BottomType.class; } } else { - return childBase instanceof BottomType; + return childBase.getClass() == BottomType.class; } - } else { - return child instanceof BottomType; } + + return child.getClass() == BottomType.class; } /** Check whether the two given types are primitives or BottomType */ public boolean arePrimitives(Type a, Type b) { - if (a instanceof PrimitiveType || a instanceof BottomType) { - return b instanceof PrimitiveType || b instanceof BottomType; + if (a instanceof PrimitiveType || a.getClass() == BottomType.class) { + return b instanceof PrimitiveType || b.getClass() == BottomType.class; } else { return false; } From 301bfd0099263bc94820f5574eabc105594c6a8e Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Wed, 26 Jul 2023 19:46:33 +0200 Subject: [PATCH 32/90] make else-if more readable /remove redundant else branches --- .../core/typehierarchy/ViewTypeHierarchy.java | 6 +- .../typeresolving/AugEvalFunction.java | 9 +- .../typeresolving/BytecodeHierarchy.java | 100 ++++++++++-------- .../typeresolving/IHierarchy.java | 34 ------ .../typeresolving/PrimitiveHierarchy.java | 68 ++++++------ .../typeresolving/types/AugIntegerTypes.java | 6 +- .../typeresolving/PrimitiveHierarchyTest.java | 67 ++++++------ 7 files changed, 134 insertions(+), 156 deletions(-) delete mode 100644 sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/IHierarchy.java diff --git a/sootup.core/src/main/java/sootup/core/typehierarchy/ViewTypeHierarchy.java b/sootup.core/src/main/java/sootup/core/typehierarchy/ViewTypeHierarchy.java index 7af3588bd9b..555e4e61035 100644 --- a/sootup.core/src/main/java/sootup/core/typehierarchy/ViewTypeHierarchy.java +++ b/sootup.core/src/main/java/sootup/core/typehierarchy/ViewTypeHierarchy.java @@ -215,8 +215,12 @@ public Set directlyExtendedInterfacesOf(@Nonnull ClassType interfaceT .collect(Collectors.toSet()); } - /** method exists for completeness - SootClass.getSuperClass() should be more performant. */ + /** + * method exists for completeness - superClassOf() / which is basically SootClass.getSuperClass() + * should be more performant. + */ @Nullable + @Deprecated public ClassType directSuperClassOf(@Nonnull ClassType classType) { Vertex vertex = lazyScanResult.get().typeToVertex.get(classType); if (vertex == null) { diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/AugEvalFunction.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/AugEvalFunction.java index 8a7148cc41f..33fb8559571 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/AugEvalFunction.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/AugEvalFunction.java @@ -53,7 +53,6 @@ public class AugEvalFunction { private final ClassType throwableClassType; View> view; - PrimitiveHierarchy primitiveHierarchy = new PrimitiveHierarchy(); public AugEvalFunction(View> view) { this.view = view; @@ -150,12 +149,12 @@ public Type evaluate( } else if (tr.getClass() == PrimitiveType.BooleanType.class) { return tl; } else { - Collection set = primitiveHierarchy.getLeastCommonAncestor(tl, tr); - if (set.isEmpty()) { + Collection lca = PrimitiveHierarchy.getLeastCommonAncestor(tl, tr); + if (lca.isEmpty()) { throw new RuntimeException( "Invaluable expression by using AugEvalFunction '" + value + "'."); } - return set.iterator().next(); + return lca.iterator().next(); } } else { return (tl.getClass() == PrimitiveType.LongType.class) ? PrimitiveType.getLong() : tr; @@ -211,7 +210,7 @@ public Type evaluate( } } else if (value.getClass() == JThisRef.class || value.getClass() == JParameterRef.class - || value.getClass() == JFieldRef.class) { + || value instanceof JFieldRef) { return value.getType(); } else { throw new RuntimeException("Invaluable reference in AugEvalFunction '" + value + "'."); diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/BytecodeHierarchy.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/BytecodeHierarchy.java index d043b9f8c14..8f1d957c52e 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/BytecodeHierarchy.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/BytecodeHierarchy.java @@ -31,27 +31,24 @@ import sootup.java.bytecode.interceptors.typeresolving.types.BottomType; /** @author Zun Wang */ -public class BytecodeHierarchy implements IHierarchy { +public class BytecodeHierarchy { private final ViewTypeHierarchy typeHierarchy; - private final ClassType object; - private final ClassType serializable; - private final ClassType cloneable; - private final PrimitiveHierarchy primitiveHierarchy; + private final ClassType objectClassType; + private final ClassType serializableClassType; + private final ClassType cloneableClassType; public BytecodeHierarchy(View> view) { this.typeHierarchy = new ViewTypeHierarchy(view); IdentifierFactory factory = view.getIdentifierFactory(); - object = factory.getClassType("java.lang.Object"); - serializable = factory.getClassType("java.io.Serializable"); - cloneable = factory.getClassType("java.lang.Cloneable"); - primitiveHierarchy = new PrimitiveHierarchy(); + objectClassType = factory.getClassType("java.lang.Object"); + serializableClassType = factory.getClassType("java.io.Serializable"); + cloneableClassType = factory.getClassType("java.lang.Cloneable"); } - @Override public boolean isAncestor(@Nonnull Type ancestor, @Nonnull Type child) { - boolean isAncestor = primitiveHierarchy.isAncestor(ancestor, child); - if (!isAncestor && !(primitiveHierarchy.arePrimitives(ancestor, child))) { + boolean isAncestor = PrimitiveHierarchy.isAncestor(ancestor, child); + if (!isAncestor && !(PrimitiveHierarchy.arePrimitives(ancestor, child))) { if (ancestor.equals(child)) { isAncestor = true; } else if (child instanceof BottomType) { @@ -71,48 +68,60 @@ public boolean isAncestor(@Nonnull Type ancestor, @Nonnull Type child) { } else if (child instanceof ArrayType && ancestor instanceof ClassType) { isAncestor = - ancestor.equals(object) || ancestor.equals(serializable) || ancestor.equals(cloneable); + ancestor.equals(objectClassType) + || ancestor.equals(serializableClassType) + || ancestor.equals(cloneableClassType); } else if (child instanceof ArrayType && ancestor instanceof ArrayType) { - ArrayType anArr = (ArrayType) ancestor; - ArrayType chArr = (ArrayType) child; - Type anBase = anArr.getBaseType(); - Type chBase = chArr.getBaseType(); - if (anArr.getDimension() == chArr.getDimension()) { + ArrayType ancestorArr = (ArrayType) ancestor; + ArrayType childArr = (ArrayType) child; + Type anBase = ancestorArr.getBaseType(); + Type chBase = childArr.getBaseType(); + if (ancestorArr.getDimension() == childArr.getDimension()) { if (anBase.equals(chBase)) { isAncestor = true; } else if (anBase instanceof ClassType && chBase instanceof ClassType) { isAncestor = canStoreType((ClassType) anBase, (ClassType) chBase); } - } else if (anArr.getDimension() < chArr.getDimension()) { + } else if (ancestorArr.getDimension() < childArr.getDimension()) { isAncestor = - anBase.equals(object) || anBase.equals(serializable) || anBase.equals(cloneable); + anBase.equals(objectClassType) + || anBase.equals(serializableClassType) + || anBase.equals(cloneableClassType); } } } return isAncestor; } - @Override public Collection getLeastCommonAncestor(Type a, Type b) { Collection ret = new HashSet<>(); if (a instanceof BottomType) { return Collections.singleton(b); - } else if (b instanceof BottomType) { + } + if (b instanceof BottomType) { return Collections.singleton(a); - } else if (a instanceof NullType) { + } + if (a instanceof NullType) { return Collections.singleton(b); - } else if (b instanceof NullType) { + } + if (b instanceof NullType) { return Collections.singleton(a); - } else if (isAncestor(a, b)) { + } + if (isAncestor(a, b)) { return Collections.singleton(a); - } else if (isAncestor(b, a)) { + } + if (isAncestor(b, a)) { return Collections.singleton(b); - } else if (a instanceof PrimitiveType && b instanceof PrimitiveType) { - return primitiveHierarchy.getLeastCommonAncestor(a, b); - } else if (a instanceof PrimitiveType || b instanceof PrimitiveType) { + } + if (a instanceof PrimitiveType && b instanceof PrimitiveType) { + return PrimitiveHierarchy.getLeastCommonAncestor(a, b); + } + if (a instanceof PrimitiveType || b instanceof PrimitiveType) { return Collections.emptySet(); - } else if (a instanceof ArrayType && b instanceof ArrayType) { + } + + if (a instanceof ArrayType && b instanceof ArrayType) { Collection temp; Type et_a = ((ArrayType) a).getElementType(); Type et_b = ((ArrayType) b).getElementType(); @@ -122,9 +131,9 @@ public Collection getLeastCommonAncestor(Type a, Type b) { temp = getLeastCommonAncestor(et_a, et_b); } if (temp.isEmpty()) { - ret.add(object); - ret.add(serializable); - ret.add(cloneable); + ret.add(objectClassType); + ret.add(serializableClassType); + ret.add(cloneableClassType); } else { for (Type type : temp) { ret.add(Type.makeArrayType(type, 1)); @@ -133,15 +142,15 @@ public Collection getLeastCommonAncestor(Type a, Type b) { } else if (a instanceof ArrayType || b instanceof ArrayType) { ClassType nonArray = (ClassType) ((a instanceof ArrayType) ? b : a); if (!nonArray.getFullyQualifiedName().equals("java.lang.Object")) { - if (isAncestor(serializable, nonArray)) { - ret.add(serializable); + if (isAncestor(serializableClassType, nonArray)) { + ret.add(serializableClassType); } - if (isAncestor(cloneable, nonArray)) { - ret.add(cloneable); + if (isAncestor(cloneableClassType, nonArray)) { + ret.add(cloneableClassType); } } if (ret.isEmpty()) { - ret.add(object); + ret.add(objectClassType); } } else { // if a and b are both ClassType @@ -169,18 +178,14 @@ public Collection getLeastCommonAncestor(Type a, Type b) { } } if (ret.isEmpty()) { - ret.add(object); + ret.add(objectClassType); } } return ret; } private boolean canStoreType(ClassType ancestor, ClassType child) { - if (ancestor.equals(object)) { - return true; - } else { - return typeHierarchy.subtypesOf(ancestor).contains(child); - } + return ancestor == objectClassType || typeHierarchy.subtypesOf(ancestor).contains(child); } private Set buildAncestryPaths(ClassType type) { @@ -189,7 +194,7 @@ private Set buildAncestryPaths(ClassType type) { Set paths = new HashSet<>(); while (!pathNodes.isEmpty()) { AncestryPath node = pathNodes.removeFirst(); - if (node.type.getFullyQualifiedName().equals("java.lang.Object")) { + if (node.type == objectClassType) { paths.add(node); } else { if (typeHierarchy.isInterface(node.type)) { @@ -208,7 +213,9 @@ private Set buildAncestryPaths(ClassType type) { AncestryPath superNode = new AncestryPath(superInterface, node); pathNodes.add(superNode); } - ClassType superClass = typeHierarchy.directSuperClassOf(node.type); + ClassType superClass = typeHierarchy.superClassOf(node.type); + // only java.lang.Object can have no SuperClass i.e. is null - this is already filtered + // above AncestryPath superNode = new AncestryPath(superClass, node); pathNodes.add(superNode); } @@ -228,6 +235,7 @@ private ClassType leastCommonNode(AncestryPath a, AncestryPath b) { return lcn; } + // TODO: [ms] thats a linked list.. please refactor that private static class AncestryPath { public AncestryPath next; public ClassType type; diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/IHierarchy.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/IHierarchy.java deleted file mode 100644 index 73164fd0166..00000000000 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/IHierarchy.java +++ /dev/null @@ -1,34 +0,0 @@ -package sootup.java.bytecode.interceptors.typeresolving; - -import java.util.Collection; -import javax.annotation.Nonnull; -import sootup.core.types.Type; - -/*- - * #%L - * Soot - a J*va Optimization Framework - * %% - * Copyright (C) 2019-2022 Zun Wang - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * #L% - */ -public interface IHierarchy { - - @Nonnull - Collection getLeastCommonAncestor(@Nonnull Type a, @Nonnull Type b); - - boolean isAncestor(@Nonnull Type ancestor, @Nonnull Type child); -} diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/PrimitiveHierarchy.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/PrimitiveHierarchy.java index d2a1fc1348e..596ec069591 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/PrimitiveHierarchy.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/PrimitiveHierarchy.java @@ -31,7 +31,7 @@ import sootup.java.bytecode.interceptors.typeresolving.types.BottomType; /** @author Zun Wang */ -public class PrimitiveHierarchy implements IHierarchy { +public class PrimitiveHierarchy { /** * Calculate the least common ancestor of two types(primitive or BottomType). If there's a = b @@ -40,43 +40,43 @@ public class PrimitiveHierarchy implements IHierarchy { * least common ancestor of a and b; */ @Nonnull - @Override - public Collection getLeastCommonAncestor(@Nonnull Type a, @Nonnull Type b) { - if (a.equals(b)) { + public static Collection getLeastCommonAncestor(@Nonnull Type a, @Nonnull Type b) { + if (a == b) { return Collections.singleton(a); - } else if (arePrimitives(a, b)) { + } + + if (arePrimitives(a, b)) { if (isAncestor(a, b)) { return Collections.singleton(a); - } else if (isAncestor(b, a)) { + } + if (isAncestor(b, a)) { return Collections.singleton(b); - } else if (a.getClass() == PrimitiveType.ByteType.class) { + } + if (a.getClass() == PrimitiveType.ByteType.class) { if (b.getClass() == PrimitiveType.ShortType.class || b.getClass() == PrimitiveType.CharType.class || b.getClass() == AugIntegerTypes.Integer32767Type.class) { return Collections.singleton(PrimitiveType.getInt()); - } else { - return Collections.emptySet(); } - } else if (a.getClass() == PrimitiveType.ShortType.class) { + return Collections.emptySet(); + } + if (a.getClass() == PrimitiveType.ShortType.class) { if (b.getClass() == PrimitiveType.ByteType.class || b.getClass() == PrimitiveType.CharType.class) { return Collections.singleton(PrimitiveType.getInt()); - } else { - return Collections.emptySet(); } - } else if (a.getClass() == PrimitiveType.CharType.class) { + return Collections.emptySet(); + } + if (a.getClass() == PrimitiveType.CharType.class) { if (b.getClass() == PrimitiveType.ByteType.class || b.getClass() == PrimitiveType.ShortType.class) { return Collections.singleton(PrimitiveType.getInt()); - } else { - return Collections.emptySet(); } - } else { return Collections.emptySet(); } - } else { return Collections.emptySet(); } + return Collections.emptySet(); } /** @@ -84,8 +84,7 @@ public Collection getLeastCommonAncestor(@Nonnull Type a, @Nonnull Type b) * child, namely, whether child can be assigned to ancestor directly to obtain: ancestor = * child. */ - @Override - public boolean isAncestor(@Nonnull Type ancestor, @Nonnull Type child) { + public static boolean isAncestor(@Nonnull Type ancestor, @Nonnull Type child) { if (ancestor == child) { return true; @@ -94,28 +93,31 @@ public boolean isAncestor(@Nonnull Type ancestor, @Nonnull Type child) { if (arePrimitives(ancestor, child)) { if (ancestor.getClass() == AugIntegerTypes.Integer1Type.class) { return child.getClass() == BottomType.class; - } else if (ancestor.getClass() == PrimitiveType.BooleanType.class + } + if (ancestor.getClass() == PrimitiveType.BooleanType.class || ancestor.getClass() == AugIntegerTypes.Integer127Type.class) { return child.getClass() == AugIntegerTypes.Integer1Type.class || child.getClass() == BottomType.class; - } else if (ancestor.getClass() == PrimitiveType.ByteType.class + } + if (ancestor.getClass() == PrimitiveType.ByteType.class || ancestor.getClass() == AugIntegerTypes.Integer32767Type.class) { return child.getClass() == AugIntegerTypes.Integer127Type.class || child.getClass() == AugIntegerTypes.Integer1Type.class || child.getClass() == BottomType.class; - } else if (ancestor.getClass() == PrimitiveType.CharType.class + } + if (ancestor.getClass() == PrimitiveType.CharType.class || ancestor.getClass() == PrimitiveType.ShortType.class) { return child.getClass() == AugIntegerTypes.Integer32767Type.class || child.getClass() == AugIntegerTypes.Integer127Type.class || child.getClass() == AugIntegerTypes.Integer1Type.class || child.getClass() == BottomType.class; - } else if (ancestor instanceof PrimitiveType.IntType) { + } + if (ancestor instanceof PrimitiveType.IntType) { return (!(child.getClass() == PrimitiveType.BooleanType.class) && (child instanceof PrimitiveType.IntType)) || child.getClass() == BottomType.class; - } else { - return child.getClass() == BottomType.class; } + return child.getClass() == BottomType.class; } if (ancestor instanceof ArrayType && child instanceof ArrayType) { @@ -129,35 +131,35 @@ public boolean isAncestor(@Nonnull Type ancestor, @Nonnull Type child) { // structure? if (ancestorBase.getClass() == AugIntegerTypes.Integer1Type.class) { return childBase.getClass() == BottomType.class; - } else if (ancestorBase.getClass() == PrimitiveType.BooleanType.class + } + if (ancestorBase.getClass() == PrimitiveType.BooleanType.class || ancestorBase.getClass() == AugIntegerTypes.Integer127Type.class) { return childBase.getClass() == AugIntegerTypes.Integer1Type.class || childBase.getClass() == BottomType.class; - } else if (ancestorBase.getClass() == PrimitiveType.ByteType.class + } + if (ancestorBase.getClass() == PrimitiveType.ByteType.class || ancestorBase.getClass() == AugIntegerTypes.Integer32767Type.class) { return childBase.getClass() == AugIntegerTypes.Integer127Type.class || childBase.getClass() == AugIntegerTypes.Integer1Type.class || childBase.getClass() == BottomType.class; - } else if (ancestorBase.getClass() == PrimitiveType.CharType.class + } + if (ancestorBase.getClass() == PrimitiveType.CharType.class || ancestorBase.getClass() == PrimitiveType.ShortType.class || ancestorBase instanceof PrimitiveType.IntType) { return childBase.getClass() == AugIntegerTypes.Integer32767Type.class || childBase.getClass() == AugIntegerTypes.Integer127Type.class || childBase.getClass() == AugIntegerTypes.Integer1Type.class || childBase.getClass() == BottomType.class; - } else { - return childBase.getClass() == BottomType.class; } - } else { - return childBase.getClass() == BottomType.class; } + return childBase.getClass() == BottomType.class; } return child.getClass() == BottomType.class; } /** Check whether the two given types are primitives or BottomType */ - public boolean arePrimitives(Type a, Type b) { + public static boolean arePrimitives(Type a, Type b) { if (a instanceof PrimitiveType || a.getClass() == BottomType.class) { return b instanceof PrimitiveType || b.getClass() == BottomType.class; } else { diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/types/AugIntegerTypes.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/types/AugIntegerTypes.java index d744d363431..bf7a4aa94e4 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/types/AugIntegerTypes.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/types/AugIntegerTypes.java @@ -60,7 +60,7 @@ public static Integer1Type getInstance() { @Override public void accept(@Nonnull TypeVisitor v) { - // todo: case for Integer1Type + throw new UnsupportedOperationException(); } } @@ -79,7 +79,7 @@ public static Integer127Type getInstance() { @Override public void accept(@Nonnull TypeVisitor v) { - // todo: case for Integer127Type + throw new UnsupportedOperationException(); } } @@ -98,7 +98,7 @@ public static Integer32767Type getInstance() { @Override public void accept(@Nonnull TypeVisitor v) { - // todo: case for Integer32767Type + throw new UnsupportedOperationException(); } } } diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/typeresolving/PrimitiveHierarchyTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/typeresolving/PrimitiveHierarchyTest.java index 5cc51cd70cb..1f13ac93a22 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/typeresolving/PrimitiveHierarchyTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/typeresolving/PrimitiveHierarchyTest.java @@ -34,71 +34,70 @@ public class PrimitiveHierarchyTest { private Type arr_c = new ArrayType(c, 1); private Type arr_by = new ArrayType(by, 1); private Type arr_i127 = new ArrayType(i127, 1); - private PrimitiveHierarchy primitiveHierarchy = new PrimitiveHierarchy(); @Test public void testIsAncestor() { // check all ancestor relationships in lattice - Assert.assertTrue(primitiveHierarchy.isAncestor(bt, bt2)); + Assert.assertTrue(PrimitiveHierarchy.isAncestor(bt, bt2)); - Assert.assertTrue(primitiveHierarchy.isAncestor(i1, bt)); - Assert.assertFalse(primitiveHierarchy.isAncestor(bt, i1)); + Assert.assertTrue(PrimitiveHierarchy.isAncestor(i1, bt)); + Assert.assertFalse(PrimitiveHierarchy.isAncestor(bt, i1)); - Assert.assertTrue(primitiveHierarchy.isAncestor(boo, i1)); - Assert.assertTrue(primitiveHierarchy.isAncestor(boo, bt)); + Assert.assertTrue(PrimitiveHierarchy.isAncestor(boo, i1)); + Assert.assertTrue(PrimitiveHierarchy.isAncestor(boo, bt)); - Assert.assertTrue(primitiveHierarchy.isAncestor(i127, i1)); - Assert.assertTrue(primitiveHierarchy.isAncestor(i127, bt)); - Assert.assertFalse(primitiveHierarchy.isAncestor(boo, i127)); + Assert.assertTrue(PrimitiveHierarchy.isAncestor(i127, i1)); + Assert.assertTrue(PrimitiveHierarchy.isAncestor(i127, bt)); + Assert.assertFalse(PrimitiveHierarchy.isAncestor(boo, i127)); - Assert.assertTrue(primitiveHierarchy.isAncestor(by, i127)); - Assert.assertFalse(primitiveHierarchy.isAncestor(by, i32767)); + Assert.assertTrue(PrimitiveHierarchy.isAncestor(by, i127)); + Assert.assertFalse(PrimitiveHierarchy.isAncestor(by, i32767)); - Assert.assertTrue(primitiveHierarchy.isAncestor(c, i32767)); - Assert.assertFalse(primitiveHierarchy.isAncestor(c, by)); - Assert.assertFalse(primitiveHierarchy.isAncestor(c, s)); + Assert.assertTrue(PrimitiveHierarchy.isAncestor(c, i32767)); + Assert.assertFalse(PrimitiveHierarchy.isAncestor(c, by)); + Assert.assertFalse(PrimitiveHierarchy.isAncestor(c, s)); - Assert.assertTrue(primitiveHierarchy.isAncestor(s, i127)); - Assert.assertFalse(primitiveHierarchy.isAncestor(s, by)); - Assert.assertFalse(primitiveHierarchy.isAncestor(s, boo)); + Assert.assertTrue(PrimitiveHierarchy.isAncestor(s, i127)); + Assert.assertFalse(PrimitiveHierarchy.isAncestor(s, by)); + Assert.assertFalse(PrimitiveHierarchy.isAncestor(s, boo)); - Assert.assertTrue(primitiveHierarchy.isAncestor(i, c)); - Assert.assertTrue(primitiveHierarchy.isAncestor(i, s)); - Assert.assertTrue(primitiveHierarchy.isAncestor(i, i1)); - Assert.assertFalse(primitiveHierarchy.isAncestor(i, boo)); + Assert.assertTrue(PrimitiveHierarchy.isAncestor(i, c)); + Assert.assertTrue(PrimitiveHierarchy.isAncestor(i, s)); + Assert.assertTrue(PrimitiveHierarchy.isAncestor(i, i1)); + Assert.assertFalse(PrimitiveHierarchy.isAncestor(i, boo)); - Assert.assertFalse(primitiveHierarchy.isAncestor(d, i)); - Assert.assertFalse(primitiveHierarchy.isAncestor(d, f)); - Assert.assertFalse(primitiveHierarchy.isAncestor(l, c)); + Assert.assertFalse(PrimitiveHierarchy.isAncestor(d, i)); + Assert.assertFalse(PrimitiveHierarchy.isAncestor(d, f)); + Assert.assertFalse(PrimitiveHierarchy.isAncestor(l, c)); - Assert.assertFalse(primitiveHierarchy.isAncestor(arr_i, arr_i2)); - Assert.assertTrue(primitiveHierarchy.isAncestor(arr_i, arr_i127)); - Assert.assertTrue(primitiveHierarchy.isAncestor(arr_c, arr_i127)); - Assert.assertFalse(primitiveHierarchy.isAncestor(arr_i, arr_by)); + Assert.assertFalse(PrimitiveHierarchy.isAncestor(arr_i, arr_i2)); + Assert.assertTrue(PrimitiveHierarchy.isAncestor(arr_i, arr_i127)); + Assert.assertTrue(PrimitiveHierarchy.isAncestor(arr_c, arr_i127)); + Assert.assertFalse(PrimitiveHierarchy.isAncestor(arr_i, arr_by)); } @Test public void testLCA() { Set expect = ImmutableUtils.immutableSet(bt); - Collection actual = primitiveHierarchy.getLeastCommonAncestor(bt, bt2); + Collection actual = PrimitiveHierarchy.getLeastCommonAncestor(bt, bt2); Assert.assertEquals(expect, actual); expect = ImmutableUtils.immutableSet(i); - actual = primitiveHierarchy.getLeastCommonAncestor(c, s); + actual = PrimitiveHierarchy.getLeastCommonAncestor(c, s); Assert.assertEquals(expect, actual); - actual = primitiveHierarchy.getLeastCommonAncestor(by, s); + actual = PrimitiveHierarchy.getLeastCommonAncestor(by, s); Assert.assertEquals(expect, actual); - actual = primitiveHierarchy.getLeastCommonAncestor(by, i32767); + actual = PrimitiveHierarchy.getLeastCommonAncestor(by, i32767); Assert.assertEquals(expect, actual); - actual = primitiveHierarchy.getLeastCommonAncestor(i1, i); + actual = PrimitiveHierarchy.getLeastCommonAncestor(i1, i); Assert.assertEquals(expect, actual); expect = ImmutableUtils.immutableSet(s); - actual = primitiveHierarchy.getLeastCommonAncestor(s, i32767); + actual = PrimitiveHierarchy.getLeastCommonAncestor(s, i32767); Assert.assertEquals(expect, actual); } } From 8bddeb2454b35da99d5aa7d9fe7317f971cd98d4 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Wed, 26 Jul 2023 21:36:17 +0200 Subject: [PATCH 33/90] fix wrong test cases --- .../java/sootup/core/typehierarchy/ViewTypeHierarchy.java | 8 ++++---- .../java/core/signatures/JavaIdentifierFactoryTest.java | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/typehierarchy/ViewTypeHierarchy.java b/sootup.core/src/main/java/sootup/core/typehierarchy/ViewTypeHierarchy.java index 555e4e61035..f04cbbefaf0 100644 --- a/sootup.core/src/main/java/sootup/core/typehierarchy/ViewTypeHierarchy.java +++ b/sootup.core/src/main/java/sootup/core/typehierarchy/ViewTypeHierarchy.java @@ -191,7 +191,7 @@ public Stream directSuperClassOf(@Nonnull Vertex classVertex) { public Set directlyImplementedInterfacesOf(@Nonnull ClassType classType) { Vertex vertex = lazyScanResult.get().typeToVertex.get(classType); if (vertex == null) { - throw new RuntimeException("Could not find " + classType + " in hierarchy."); + throw new IllegalStateException("Could not find '" + classType + "' in hierarchy."); } if (vertex.type != VertexType.Class) { throw new IllegalArgumentException(classType + " is not a class."); @@ -205,7 +205,7 @@ public Set directlyImplementedInterfacesOf(@Nonnull ClassType classTy public Set directlyExtendedInterfacesOf(@Nonnull ClassType interfaceType) { Vertex vertex = lazyScanResult.get().typeToVertex.get(interfaceType); if (vertex == null) { - throw new RuntimeException("Could not find " + interfaceType + " in hierarchy."); + throw new IllegalStateException("Could not find " + interfaceType + " in hierarchy."); } if (vertex.type != VertexType.Interface) { throw new IllegalArgumentException(interfaceType + " is not a class."); @@ -224,7 +224,7 @@ public Set directlyExtendedInterfacesOf(@Nonnull ClassType interfaceT public ClassType directSuperClassOf(@Nonnull ClassType classType) { Vertex vertex = lazyScanResult.get().typeToVertex.get(classType); if (vertex == null) { - throw new RuntimeException("Could not find " + classType + " in hierarchy."); + throw new IllegalStateException("Could not find " + classType + " in hierarchy."); } Graph graph = lazyScanResult.get().graph; List list = @@ -250,7 +250,7 @@ public Set implementedInterfacesOf(@Nonnull ClassType type) { Vertex vertex = scanResult.typeToVertex.get(type); if (vertex == null) { - throw new ResolveException("Could not find " + type + " in hierarchy for view " + view); + throw new IllegalStateException("Could not find " + type + " in hierarchy for view " + view); } switch (vertex.type) { diff --git a/sootup.java.core/src/test/java/sootup/java/core/signatures/JavaIdentifierFactoryTest.java b/sootup.java.core/src/test/java/sootup/java/core/signatures/JavaIdentifierFactoryTest.java index 415bcf05d63..f6cc8f28830 100644 --- a/sootup.java.core/src/test/java/sootup/java/core/signatures/JavaIdentifierFactoryTest.java +++ b/sootup.java.core/src/test/java/sootup/java/core/signatures/JavaIdentifierFactoryTest.java @@ -84,7 +84,7 @@ public void getClassSignature() { ClassType classSignature1 = typeFactory.getClassType("System", "java.lang"); ClassType classSignature2 = typeFactory.getClassType("System", "java.lang"); // Class Signatures are unique but not their package - assertNotSame(classSignature1, classSignature2); + assertSame(classSignature1, classSignature2); } @Test @@ -137,7 +137,7 @@ public void getClassSignatureEmptyPackage() { JavaClassType classSignature1 = typeFactory.getClassType("A", ""); JavaClassType classSignature2 = typeFactory.getClassType("A"); // Class Signatures are unique but not their package - assertNotSame(classSignature1, classSignature2); + assertSame(classSignature1, classSignature2); assertSame(classSignature1.getPackageName(), classSignature2.getPackageName()); From 6e66bef9c1acdc21f18fbda93c183b18cb8835aa Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Wed, 26 Jul 2023 21:37:28 +0200 Subject: [PATCH 34/90] and another one - fix wrong test case --- .../sootup/java/core/signatures/JavaIdentifierFactoryTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sootup.java.core/src/test/java/sootup/java/core/signatures/JavaIdentifierFactoryTest.java b/sootup.java.core/src/test/java/sootup/java/core/signatures/JavaIdentifierFactoryTest.java index f6cc8f28830..a5fcf27b61d 100644 --- a/sootup.java.core/src/test/java/sootup/java/core/signatures/JavaIdentifierFactoryTest.java +++ b/sootup.java.core/src/test/java/sootup/java/core/signatures/JavaIdentifierFactoryTest.java @@ -152,7 +152,7 @@ public void getClassSignatureFullyQualified() { ClassType classSignature1 = typeFactory.getClassType("java.lang.System"); ClassType classSignature2 = typeFactory.getClassType("System", "java.lang"); // Class Signatures are unique but not their package - assertNotSame(classSignature1, classSignature2); + assertSame(classSignature1, classSignature2); } @Test From 2476d2ffb8add424a370a372aedebb0c936ca65d Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Wed, 26 Jul 2023 22:16:49 +0200 Subject: [PATCH 35/90] readability+ --- .../typeresolving/BytecodeHierarchy.java | 83 +++++++++++-------- .../typeresolving/PrimitiveHierarchy.java | 9 +- 2 files changed, 50 insertions(+), 42 deletions(-) diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/BytecodeHierarchy.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/BytecodeHierarchy.java index 8f1d957c52e..1ba9722ae5a 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/BytecodeHierarchy.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/BytecodeHierarchy.java @@ -20,6 +20,7 @@ * . * #L% */ + import java.util.*; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -47,55 +48,62 @@ public BytecodeHierarchy(View> view) { } public boolean isAncestor(@Nonnull Type ancestor, @Nonnull Type child) { - boolean isAncestor = PrimitiveHierarchy.isAncestor(ancestor, child); - if (!isAncestor && !(PrimitiveHierarchy.arePrimitives(ancestor, child))) { - if (ancestor.equals(child)) { - isAncestor = true; - } else if (child instanceof BottomType) { - isAncestor = true; - } else if (ancestor instanceof BottomType) { + if (PrimitiveHierarchy.isAncestor(ancestor, child)) { + return true; + } + + if (!PrimitiveHierarchy.arePrimitives(ancestor, child)) { + if (ancestor == child) { + return true; + } + if (child.getClass() == BottomType.class) { + return true; + } + if (ancestor.getClass() == BottomType.class) { return false; - } else if (ancestor instanceof PrimitiveType || child instanceof PrimitiveType) { + } + if (ancestor instanceof PrimitiveType || child instanceof PrimitiveType) { return false; - } else if (child instanceof NullType) { - isAncestor = true; - } else if (ancestor instanceof NullType) { + } + if (child == NullType.getInstance()) { + return true; + } + if (ancestor == NullType.getInstance()) { return false; - } else if (child instanceof ClassType && ancestor instanceof ClassType) { - - isAncestor = canStoreType((ClassType) ancestor, (ClassType) child); - - } else if (child instanceof ArrayType && ancestor instanceof ClassType) { - - isAncestor = - ancestor.equals(objectClassType) - || ancestor.equals(serializableClassType) - || ancestor.equals(cloneableClassType); - - } else if (child instanceof ArrayType && ancestor instanceof ArrayType) { + } + if (child instanceof ClassType && ancestor instanceof ClassType) { + return canStoreType((ClassType) ancestor, (ClassType) child); + } + if (child instanceof ArrayType && ancestor instanceof ClassType) { + return ancestor == objectClassType + || ancestor == serializableClassType + || ancestor == cloneableClassType; + } + if (child instanceof ArrayType && ancestor instanceof ArrayType) { ArrayType ancestorArr = (ArrayType) ancestor; ArrayType childArr = (ArrayType) child; - Type anBase = ancestorArr.getBaseType(); - Type chBase = childArr.getBaseType(); + Type ancestorBase = ancestorArr.getBaseType(); + Type childBase = childArr.getBaseType(); if (ancestorArr.getDimension() == childArr.getDimension()) { - if (anBase.equals(chBase)) { - isAncestor = true; - } else if (anBase instanceof ClassType && chBase instanceof ClassType) { - isAncestor = canStoreType((ClassType) anBase, (ClassType) chBase); + if (ancestorBase == childBase) { + return true; + } + if (ancestorBase instanceof ClassType && childBase instanceof ClassType) { + return canStoreType((ClassType) ancestorBase, (ClassType) childBase); } } else if (ancestorArr.getDimension() < childArr.getDimension()) { - isAncestor = - anBase.equals(objectClassType) - || anBase.equals(serializableClassType) - || anBase.equals(cloneableClassType); + // TODO: [ms] check: the dimension condition check seems weird? + return ancestorBase == objectClassType + || ancestorBase == serializableClassType + || ancestorBase == cloneableClassType; } } } - return isAncestor; + return false; } public Collection getLeastCommonAncestor(Type a, Type b) { - Collection ret = new HashSet<>(); + Set ret = new HashSet<>(); if (a instanceof BottomType) { return Collections.singleton(b); } @@ -156,6 +164,9 @@ public Collection getLeastCommonAncestor(Type a, Type b) { // if a and b are both ClassType Set pathsA = buildAncestryPaths((ClassType) a); Set pathsB = buildAncestryPaths((ClassType) b); + // TODO: [ms] implement an algorithm with better wc runtime costs.. e.g. + // https://www.baeldung.com/cs/tree-lowest-common-ancestor / + // https://de.wikipedia.org/wiki/Range_Minimum_Query for (AncestryPath pathA : pathsA) { for (AncestryPath pathB : pathsB) { ClassType lcn = leastCommonNode(pathA, pathB); @@ -227,7 +238,7 @@ private Set buildAncestryPaths(ClassType type) { @Nullable private ClassType leastCommonNode(AncestryPath a, AncestryPath b) { ClassType lcn = null; - while (a != null && b != null && a.type.equals(b.type)) { + while (a != null && b != null && a.type == b.type) { lcn = a.type; a = a.next; b = b.next; diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/PrimitiveHierarchy.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/PrimitiveHierarchy.java index 596ec069591..30db578be93 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/PrimitiveHierarchy.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/PrimitiveHierarchy.java @@ -159,11 +159,8 @@ public static boolean isAncestor(@Nonnull Type ancestor, @Nonnull Type child) { } /** Check whether the two given types are primitives or BottomType */ - public static boolean arePrimitives(Type a, Type b) { - if (a instanceof PrimitiveType || a.getClass() == BottomType.class) { - return b instanceof PrimitiveType || b.getClass() == BottomType.class; - } else { - return false; - } + public static boolean arePrimitives(@Nonnull Type a, @Nonnull Type b) { + return (a instanceof PrimitiveType || a.getClass() == BottomType.class) + && (b instanceof PrimitiveType || b.getClass() == BottomType.class); } } From 596ea9407987d5088213d4ae087613ba5de97dcb Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Wed, 26 Jul 2023 22:25:47 +0200 Subject: [PATCH 36/90] remove another identifierfactory in the wild --- .../core/typehierarchy/TypeHierarchy.java | 6 ++++++ .../src/main/java/sootup/core/types/Type.java | 3 ++- .../typeresolving/BytecodeHierarchy.java | 12 +++++++----- .../interceptors/typeresolving/TypeChecker.java | 17 +++++++---------- .../typeresolving/TypeResolver.java | 4 ++-- .../typeresolving/CastCounterTest.java | 2 +- 6 files changed, 25 insertions(+), 19 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/typehierarchy/TypeHierarchy.java b/sootup.core/src/main/java/sootup/core/typehierarchy/TypeHierarchy.java index fe34a54eb07..6e70a97ae20 100644 --- a/sootup.core/src/main/java/sootup/core/typehierarchy/TypeHierarchy.java +++ b/sootup.core/src/main/java/sootup/core/typehierarchy/TypeHierarchy.java @@ -207,4 +207,10 @@ default List incompleteSuperClassesOf(@Nonnull ClassType classType) { } return superClasses; } + + Set directlyImplementedInterfacesOf(@Nonnull ClassType type); + + boolean isInterface(@Nonnull ClassType type); + + Set directlyExtendedInterfacesOf(@Nonnull ClassType type); } diff --git a/sootup.core/src/main/java/sootup/core/types/Type.java b/sootup.core/src/main/java/sootup/core/types/Type.java index 3a256db6883..5415f91b9bc 100644 --- a/sootup.core/src/main/java/sootup/core/types/Type.java +++ b/sootup.core/src/main/java/sootup/core/types/Type.java @@ -22,6 +22,7 @@ * #L% */ +import javax.annotation.Nonnull; import sootup.core.jimple.visitor.Acceptor; import sootup.core.jimple.visitor.TypeVisitor; @@ -50,7 +51,7 @@ public static boolean isObject(Type type) { * This method is used to make an array type for the given type. If the given type is an array * type, then increase its dimension with given dim */ - public static ArrayType makeArrayType(Type type, int dim) { + public static ArrayType createArrayType(@Nonnull Type type, int dim) { if (type instanceof ArrayType) { return new ArrayType( ((ArrayType) type).getBaseType(), ((ArrayType) type).getDimension() + dim); diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/BytecodeHierarchy.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/BytecodeHierarchy.java index 1ba9722ae5a..71b9632e8d0 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/BytecodeHierarchy.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/BytecodeHierarchy.java @@ -26,7 +26,7 @@ import javax.annotation.Nullable; import sootup.core.IdentifierFactory; import sootup.core.model.SootClass; -import sootup.core.typehierarchy.ViewTypeHierarchy; +import sootup.core.typehierarchy.TypeHierarchy; import sootup.core.types.*; import sootup.core.views.View; import sootup.java.bytecode.interceptors.typeresolving.types.BottomType; @@ -34,15 +34,17 @@ /** @author Zun Wang */ public class BytecodeHierarchy { - private final ViewTypeHierarchy typeHierarchy; - private final ClassType objectClassType; + private final TypeHierarchy typeHierarchy; + public final ClassType objectClassType; + public final ClassType throwableClassType; private final ClassType serializableClassType; private final ClassType cloneableClassType; public BytecodeHierarchy(View> view) { - this.typeHierarchy = new ViewTypeHierarchy(view); + this.typeHierarchy = view.getTypeHierarchy(); IdentifierFactory factory = view.getIdentifierFactory(); objectClassType = factory.getClassType("java.lang.Object"); + throwableClassType = factory.getClassType("java.lang.Throwable"); serializableClassType = factory.getClassType("java.io.Serializable"); cloneableClassType = factory.getClassType("java.lang.Cloneable"); } @@ -144,7 +146,7 @@ public Collection getLeastCommonAncestor(Type a, Type b) { ret.add(cloneableClassType); } else { for (Type type : temp) { - ret.add(Type.makeArrayType(type, 1)); + ret.add(Type.createArrayType(type, 1)); } } } else if (a instanceof ArrayType || b instanceof ArrayType) { diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/TypeChecker.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/TypeChecker.java index 7358f2d6df9..07400de262a 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/TypeChecker.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/TypeChecker.java @@ -27,7 +27,6 @@ import javax.annotation.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import sootup.core.IdentifierFactory; import sootup.core.graph.StmtGraph; import sootup.core.jimple.basic.Local; import sootup.core.jimple.basic.Value; @@ -48,7 +47,6 @@ import sootup.core.types.NullType; import sootup.core.types.PrimitiveType; import sootup.core.types.Type; -import sootup.java.core.JavaIdentifierFactory; public abstract class TypeChecker extends AbstractStmtVisitor { @@ -58,7 +56,6 @@ public abstract class TypeChecker extends AbstractStmtVisitor { protected final Body.BodyBuilder builder; protected final StmtGraph graph; - private final IdentifierFactory factory = JavaIdentifierFactory.getInstance(); private static final Logger logger = LoggerFactory.getLogger(TypeChecker.class); @@ -120,12 +117,12 @@ public void caseAssignStmt(@Nonnull JAssignStmt stmt) { } } if (!findDef) { - arrayType = Type.makeArrayType(type_rhs, 1); + arrayType = Type.createArrayType(type_rhs, 1); } } } if (arrayType == null) { - arrayType = Type.makeArrayType(type_base, 1); + arrayType = Type.createArrayType(type_base, 1); } } type_lhs = arrayType.getElementType(); @@ -181,7 +178,7 @@ public void caseAssignStmt(@Nonnull JAssignStmt stmt) { if (sel == null) { sel = type_base; } - arrayType = Type.makeArrayType(sel, 1); + arrayType = Type.createArrayType(sel, 1); } } if (arrayType != null) { @@ -204,7 +201,7 @@ public void caseAssignStmt(@Nonnull JAssignStmt stmt) { } else if (rhs instanceof JCastExpr) { visit(rhs, type_lhs, stmt); } else if (rhs instanceof JInstanceOfExpr) { - visit(((JInstanceOfExpr) rhs).getOp(), factory.getType("java.lang.Object"), stmt); + visit(((JInstanceOfExpr) rhs).getOp(), hierarchy.objectClassType, stmt); visit(rhs, type_lhs, stmt); } else if (rhs instanceof JNewArrayExpr) { visit(((JNewArrayExpr) rhs).getSize(), PrimitiveType.getInt(), stmt); @@ -229,12 +226,12 @@ public void caseAssignStmt(@Nonnull JAssignStmt stmt) { @Override public void caseEnterMonitorStmt(@Nonnull JEnterMonitorStmt stmt) { - visit(stmt.getOp(), factory.getType("java.lang.Object"), stmt); + visit(stmt.getOp(), hierarchy.objectClassType, stmt); } @Override public void caseExitMonitorStmt(@Nonnull JExitMonitorStmt stmt) { - visit(stmt.getOp(), factory.getType("java.lang.Object"), stmt); + visit(stmt.getOp(), hierarchy.objectClassType, stmt); } @Override @@ -254,7 +251,7 @@ public void caseReturnStmt(@Nonnull JReturnStmt stmt) { @Override public void caseThrowStmt(@Nonnull JThrowStmt stmt) { - visit(stmt.getOp(), factory.getType("java.lang.Throwable"), stmt); + visit(stmt.getOp(), hierarchy.throwableClassType, stmt); } public AugEvalFunction getFuntion() { diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/TypeResolver.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/TypeResolver.java index 6e09e8d061e..ca3c4b405f7 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/TypeResolver.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/TypeResolver.java @@ -182,7 +182,7 @@ private Collection applyAssignmentConstraint( Type t_old = actualTyping.getType(local); Type t_right = evalFunction.evaluate(actualTyping, defStmt.getRightOp(), defStmt, graph); if (lhs instanceof JArrayRef) { - t_right = Type.makeArrayType(t_right, 1); + t_right = Type.createArrayType(t_right, 1); } boolean isFirstType = true; @@ -290,7 +290,7 @@ private Type convertType(@Nonnull Type type) { } else if (type instanceof ArrayType) { Type eleType = convertType(((ArrayType) type).getElementType()); if (eleType != null) { - return Type.makeArrayType(eleType, 1); + return Type.createArrayType(eleType, 1); } else { return null; } diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/typeresolving/CastCounterTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/typeresolving/CastCounterTest.java index 1114ca51eb1..21ef1ee8ddd 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/typeresolving/CastCounterTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/typeresolving/CastCounterTest.java @@ -70,7 +70,7 @@ public void testAssignStmt() { final Body.BodyBuilder builder = createMethodsBuilder("assignStmt", "void"); Map map = new HashMap<>(); map.put("l0", classType); - map.put("l1", Type.makeArrayType(super1, 1)); + map.put("l1", Type.createArrayType(super1, 1)); map.put("l2", super1); map.put("$stack3", sub1); Typing typing = createTyping(builder.getLocals(), map); From b0fd6d2854e6519b71109faa50f8a184e57b1703 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Wed, 26 Jul 2023 23:40:05 +0200 Subject: [PATCH 37/90] remove another wild identifierfactory --- .../bytecode/frontend/AsmMethodSource.java | 53 +++++++++---------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java index 067aa461843..b3f40af036d 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java @@ -139,17 +139,8 @@ public class AsmMethodSource extends JSRInlinerAdapter implements BodySource { @Nonnull private final Map labelsToStmt = new HashMap<>(); - // FIXME: [ms] or JavaModuleIdentifierFactory if needed.. - private JavaIdentifierFactory javaIdentifierFactory = JavaIdentifierFactory.getInstance(); - private final Supplier lazyMethodSignature = - Suppliers.memoize( - () -> { - List sigTypes = AsmUtil.toJimpleSignatureDesc(desc); - Type retType = sigTypes.remove(sigTypes.size() - 1); - - return javaIdentifierFactory.getMethodSignature( - declaringClass, name, retType, sigTypes); - }); + private final JavaIdentifierFactory identifierFactory; + private final Supplier lazyMethodSignature; AsmMethodSource( int access, @@ -162,6 +153,16 @@ public class AsmMethodSource extends JSRInlinerAdapter implements BodySource { super(AsmUtil.SUPPORTED_ASM_OPCODE, null, access, name, desc, signature, exceptions); this.bodyInterceptors = bodyInterceptors; this.view = view; + + identifierFactory = (JavaIdentifierFactory) view.getIdentifierFactory(); + lazyMethodSignature = + Suppliers.memoize( + () -> { + List sigTypes = AsmUtil.toJimpleSignatureDesc(desc); + Type retType = sigTypes.remove(sigTypes.size() - 1); + + return identifierFactory.getMethodSignature(declaringClass, name, retType, sigTypes); + }); } @Override @@ -396,17 +397,16 @@ private void convertGetFieldInsn(@Nonnull FieldInsnNode insn) { Operand opr; Type type; if (out == null) { - JavaClassType declClass = - javaIdentifierFactory.getClassType(AsmUtil.toQualifiedName(insn.owner)); + JavaClassType declClass = identifierFactory.getClassType(AsmUtil.toQualifiedName(insn.owner)); type = AsmUtil.toJimpleType(insn.desc); JFieldRef val; FieldSignature ref; if (insn.getOpcode() == GETSTATIC) { - ref = javaIdentifierFactory.getFieldSignature(insn.name, declClass, type); + ref = identifierFactory.getFieldSignature(insn.name, declClass, type); val = Jimple.newStaticFieldRef(ref); } else { Operand base = operandStack.popLocal(); - ref = javaIdentifierFactory.getFieldSignature(insn.name, declClass, type); + ref = identifierFactory.getFieldSignature(insn.name, declClass, type); val = Jimple.newInstanceFieldRef((Local) base.stackOrValue(), ref); frame.setIn(base); } @@ -429,20 +429,19 @@ private void convertPutFieldInsn(@Nonnull FieldInsnNode insn) { Operand opr, rvalue; Type type; if (out == null) { - JavaClassType declClass = - javaIdentifierFactory.getClassType(AsmUtil.toQualifiedName(insn.owner)); + JavaClassType declClass = identifierFactory.getClassType(AsmUtil.toQualifiedName(insn.owner)); type = AsmUtil.toJimpleType(insn.desc); JFieldRef val; FieldSignature ref; rvalue = operandStack.popImmediate(type); if (notInstance) { - ref = javaIdentifierFactory.getFieldSignature(insn.name, declClass, type); + ref = identifierFactory.getFieldSignature(insn.name, declClass, type); val = Jimple.newStaticFieldRef(ref); frame.setIn(rvalue); } else { Operand base = operandStack.popLocal(); - ref = javaIdentifierFactory.getFieldSignature(insn.name, declClass, type); + ref = identifierFactory.getFieldSignature(insn.name, declClass, type); val = Jimple.newInstanceFieldRef((Local) base.stackOrValue(), ref); frame.setIn(rvalue, base); } @@ -1162,11 +1161,11 @@ private Immediate toSootValue(@Nonnull Object val) throws UnsupportedOperationEx private JFieldRef toSootFieldRef(Handle methodHandle) { String bsmClsName = AsmUtil.toQualifiedName(methodHandle.getOwner()); - JavaClassType bsmCls = javaIdentifierFactory.getClassType(bsmClsName); + JavaClassType bsmCls = identifierFactory.getClassType(bsmClsName); Type t = AsmUtil.toJimpleSignatureDesc(methodHandle.getDesc()).get(0); int kind = methodHandle.getTag(); FieldSignature fieldSignature = - javaIdentifierFactory.getFieldSignature(methodHandle.getName(), bsmCls, t); + identifierFactory.getFieldSignature(methodHandle.getName(), bsmCls, t); if (kind == MethodHandle.Kind.REF_GET_FIELD_STATIC.getValue() || kind == MethodHandle.Kind.REF_PUT_FIELD_STATIC.getValue()) { return Jimple.newStaticFieldRef(fieldSignature); @@ -1178,7 +1177,7 @@ private JFieldRef toSootFieldRef(Handle methodHandle) { private MethodSignature toMethodSignature(Handle methodHandle) { String bsmClsName = AsmUtil.toQualifiedName(methodHandle.getOwner()); - JavaClassType bsmCls = javaIdentifierFactory.getClassType(bsmClsName); + JavaClassType bsmCls = identifierFactory.getClassType(bsmClsName); List bsmSigTypes = AsmUtil.toJimpleSignatureDesc(methodHandle.getDesc()); Type returnType = bsmSigTypes.remove(bsmSigTypes.size() - 1); return JavaIdentifierFactory.getInstance() @@ -1223,11 +1222,11 @@ private void convertMethodInsn(@Nonnull MethodInsnNode insn) { if (clsName.charAt(0) == '[') { clsName = "java.lang.Object"; } - JavaClassType cls = javaIdentifierFactory.getClassType(AsmUtil.toQualifiedName(clsName)); + JavaClassType cls = identifierFactory.getClassType(AsmUtil.toQualifiedName(clsName)); List sigTypes = AsmUtil.toJimpleSignatureDesc(insn.desc); returnType = sigTypes.remove((sigTypes.size() - 1)); MethodSignature methodSignature = - javaIdentifierFactory.getMethodSignature(cls, insn.name, returnType, sigTypes); + identifierFactory.getMethodSignature(cls, insn.name, returnType, sigTypes); int nrArgs = sigTypes.size(); final Operand[] args; List argList = Collections.emptyList(); @@ -1341,7 +1340,7 @@ private void convertInvokeDynamicInsn(@Nonnull InvokeDynamicInsnNode insn) { // create ref to actual method JavaClassType bclass = - javaIdentifierFactory.getClassType(JDynamicInvokeExpr.INVOKEDYNAMIC_DUMMY_CLASS_NAME); + identifierFactory.getClassType(JDynamicInvokeExpr.INVOKEDYNAMIC_DUMMY_CLASS_NAME); // Generate parameters & returnType & parameterTypes List types = AsmUtil.toJimpleSignatureDesc(insn.desc); @@ -1366,7 +1365,7 @@ private void convertInvokeDynamicInsn(@Nonnull InvokeDynamicInsnNode insn) { // we always model invokeDynamic method refs as static method references // of methods on the type SootClass.INVOKEDYNAMIC_DUMMY_CLASS_NAME MethodSignature methodSig = - javaIdentifierFactory.getMethodSignature(bclass, insn.name, returnType, parameterTypes); + identifierFactory.getMethodSignature(bclass, insn.name, returnType, parameterTypes); JDynamicInvokeExpr indy = Jimple.newDynamicInvokeExpr( @@ -1941,7 +1940,7 @@ private List buildTraps() { // used.. final String exceptionName = (trycatch.type != null) ? AsmUtil.toQualifiedName(trycatch.type) : "java.lang.Throwable"; - JavaClassType exceptionType = javaIdentifierFactory.getClassType(exceptionName); + JavaClassType exceptionType = identifierFactory.getClassType(exceptionName); Trap trap = Jimple.newTrap( From 5c67251537eb5fa823f1ac449ff3054f5163cab7 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Wed, 26 Jul 2023 23:41:13 +0200 Subject: [PATCH 38/90] iterate unordered; and fix possible concurrentmodificationexception --- .../java/bytecode/interceptors/EmptySwitchEliminator.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/EmptySwitchEliminator.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/EmptySwitchEliminator.java index 5c1c9c8d26f..55e2340ae61 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/EmptySwitchEliminator.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/EmptySwitchEliminator.java @@ -20,9 +20,9 @@ * . * #L% */ +import java.util.ArrayList; import javax.annotation.Nonnull; import sootup.core.jimple.Jimple; -import sootup.core.jimple.basic.StmtPositionInfo; import sootup.core.jimple.common.stmt.JGotoStmt; import sootup.core.jimple.common.stmt.Stmt; import sootup.core.jimple.javabytecode.stmt.JSwitchStmt; @@ -42,15 +42,13 @@ public class EmptySwitchEliminator implements BodyInterceptor { @Override public void interceptBody(@Nonnull Body.BodyBuilder builder, @Nonnull View view) { // Iterate all stmts in the body - - for (Stmt stmt : builder.getStmtGraph()) { + for (Stmt stmt : new ArrayList<>(builder.getStmtGraph().getNodes())) { // If the observed stmt an instance of JSwitchStmt if (stmt instanceof JSwitchStmt) { JSwitchStmt sw = (JSwitchStmt) stmt; // if there's only default case if (sw.getValueCount() == 1) { - StmtPositionInfo positionInfo = sw.getPositionInfo(); - JGotoStmt gotoStmt = Jimple.newGotoStmt(positionInfo); + JGotoStmt gotoStmt = Jimple.newGotoStmt(sw.getPositionInfo()); builder.replaceStmt(sw, gotoStmt); } } From 275be15d0fcf9d7eb747078e6066bfe8beab803c Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Thu, 27 Jul 2023 00:07:28 +0200 Subject: [PATCH 39/90] fix damn recursion.. add a create factory for PathBasedAnalysisInputLocation --- .../examples/basicSetup/BasicSetup.java | 2 +- .../bodyInterceptor/BodyInterceptor.java | 2 +- .../mutatingSootClass/MutatingSootClass.java | 3 +- .../JavaClassPathAnalysisInputLocation.java | 2 +- .../JrtFileSystemAnalysisInputLocation.java | 11 +--- .../bytecode/inputlocation/ModuleFinder.java | 8 ++- .../PathBasedAnalysisInputLocation.java | 66 +++++-------------- .../bytecode/RuntimeJarConversionTests.java | 2 +- .../java/sootup/java/bytecode/Soot1580.java | 2 +- .../PathBasedAnalysisInputLocationTest.java | 22 +++---- .../src/test/java/sootup/tests/CacheTest.java | 2 +- .../sootup/tests/MutableSootClientTest.java | 2 +- 12 files changed, 46 insertions(+), 78 deletions(-) diff --git a/sootup.examples/src/test/java/sootup/examples/basicSetup/BasicSetup.java b/sootup.examples/src/test/java/sootup/examples/basicSetup/BasicSetup.java index e41e9838967..adc4bdc3d56 100644 --- a/sootup.examples/src/test/java/sootup/examples/basicSetup/BasicSetup.java +++ b/sootup.examples/src/test/java/sootup/examples/basicSetup/BasicSetup.java @@ -57,7 +57,7 @@ public void createByteCodeProject() { // from the directory Path pathToBinary = Paths.get("src/test/resources/BasicSetup/binary"); AnalysisInputLocation inputLocation = - new PathBasedAnalysisInputLocation(pathToBinary, null); + PathBasedAnalysisInputLocation.create(pathToBinary, null); // Specify the language of the JavaProject. This is especially relevant for Multi-release jars, // where classes are loaded depending on the language level of the analysis diff --git a/sootup.examples/src/test/java/sootup/examples/bodyInterceptor/BodyInterceptor.java b/sootup.examples/src/test/java/sootup/examples/bodyInterceptor/BodyInterceptor.java index db205f45f47..dce04ca15d5 100644 --- a/sootup.examples/src/test/java/sootup/examples/bodyInterceptor/BodyInterceptor.java +++ b/sootup.examples/src/test/java/sootup/examples/bodyInterceptor/BodyInterceptor.java @@ -34,7 +34,7 @@ public void test() { // Create a AnalysisInputLocation, which points to a directory. All class files will be loaded // from the directory AnalysisInputLocation inputLocation = - new PathBasedAnalysisInputLocation( + PathBasedAnalysisInputLocation.create( Paths.get("src/test/resources/BodyInterceptor/binary"), null); // Specify the language of the JavaProject. This is especially relevant for Multi-release jars, diff --git a/sootup.examples/src/test/java/sootup/examples/mutatingSootClass/MutatingSootClass.java b/sootup.examples/src/test/java/sootup/examples/mutatingSootClass/MutatingSootClass.java index 2a23b80ca35..e7dec1c9e10 100644 --- a/sootup.examples/src/test/java/sootup/examples/mutatingSootClass/MutatingSootClass.java +++ b/sootup.examples/src/test/java/sootup/examples/mutatingSootClass/MutatingSootClass.java @@ -43,7 +43,8 @@ public void test() { // Create a AnalysisInputLocation, which points to a directory. All class files will be loaded // from the directory AnalysisInputLocation inputLocation = - new PathBasedAnalysisInputLocation(Paths.get("src/test/resources/BasicSetup/binary"), null); + PathBasedAnalysisInputLocation.create( + Paths.get("src/test/resources/BasicSetup/binary"), null); // Specify the language of the JavaProject. This is especially relevant for Multi-release jars, // where classes are loaded depending on the language level of the analysis diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JavaClassPathAnalysisInputLocation.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JavaClassPathAnalysisInputLocation.java index 6c3a9a40055..5370cd8e3d6 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JavaClassPathAnalysisInputLocation.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JavaClassPathAnalysisInputLocation.java @@ -204,7 +204,7 @@ public Optional> getClassSource( @Nonnull private Optional> inputLocationForPath(@Nonnull Path path) { if (Files.exists(path) && (Files.isDirectory(path) || PathUtils.isArchive(path))) { - return Optional.of(new PathBasedAnalysisInputLocation(path, srcType)); + return Optional.of(PathBasedAnalysisInputLocation.create(path, srcType)); } else { logger.warn("Invalid/Unknown class path entry: " + path); return Optional.empty(); diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JrtFileSystemAnalysisInputLocation.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JrtFileSystemAnalysisInputLocation.java index bfd9028131e..b127d8e641a 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JrtFileSystemAnalysisInputLocation.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JrtFileSystemAnalysisInputLocation.java @@ -23,12 +23,7 @@ import java.io.IOException; import java.net.URI; -import java.nio.file.DirectoryStream; -import java.nio.file.FileSystem; -import java.nio.file.FileSystems; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; +import java.nio.file.*; import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -64,7 +59,7 @@ public class JrtFileSystemAnalysisInputLocation implements ModuleInfoAnalysisInp Map moduleInfoMap = new HashMap<>(); boolean isResolved = false; - private final SourceType sourceType; + @Nonnull private final SourceType sourceType; public JrtFileSystemAnalysisInputLocation() { this(SourceType.Library); @@ -255,7 +250,7 @@ public Set getModules(View view) { @Nullable @Override public SourceType getSourceType() { - return null; + return sourceType; } @Override diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/ModuleFinder.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/ModuleFinder.java index 55ce9edd5f5..ce7eadecae0 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/ModuleFinder.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/ModuleFinder.java @@ -36,6 +36,7 @@ import javax.annotation.Nullable; import sootup.core.frontend.ResolveException; import sootup.core.inputlocation.AnalysisInputLocation; +import sootup.core.model.SourceType; import sootup.core.util.PathUtils; import sootup.java.bytecode.frontend.AsmModuleSource; import sootup.java.core.JavaModuleIdentifierFactory; @@ -64,6 +65,7 @@ public class ModuleFinder { private int next = 0; @Nonnull private final List modulePathEntries; + private SourceType sourceType = null; // FIXME ! public boolean hasMoreToResolve() { return next < modulePathEntries.size(); @@ -201,7 +203,8 @@ private void discoverModulesIn(@Nonnull Path path) { private void buildModuleForExplodedModule(@Nonnull Path dir) throws ResolveException { // create the input location for this module dir - PathBasedAnalysisInputLocation inputLocation = new PathBasedAnalysisInputLocation(dir, null); + PathBasedAnalysisInputLocation inputLocation = + PathBasedAnalysisInputLocation.create(dir, sourceType); Path moduleInfoFile = dir.resolve(JavaModuleIdentifierFactory.MODULE_INFO_FILE + ".class"); if (!Files.exists(moduleInfoFile) && !Files.isRegularFile(moduleInfoFile)) { @@ -223,7 +226,8 @@ private void buildModuleForExplodedModule(@Nonnull Path dir) throws ResolveExcep * @param jar the jar file */ private void buildModuleForJar(@Nonnull Path jar) { - PathBasedAnalysisInputLocation inputLocation = new PathBasedAnalysisInputLocation(jar, null); + PathBasedAnalysisInputLocation inputLocation = + PathBasedAnalysisInputLocation.create(jar, sourceType); Path mi; try (FileSystem zipFileSystem = FileSystems.newFileSystem(jar, (ClassLoader) null)) { final Path archiveRoot = zipFileSystem.getPath("/"); diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java index 1de105a7b28..8c7b8ace543 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java @@ -75,22 +75,26 @@ * @author Manuel Benz created on 22.05.18 * @author Kaustubh Kelkar updated on 30.07.2020 */ -public class PathBasedAnalysisInputLocation implements AnalysisInputLocation { +public abstract class PathBasedAnalysisInputLocation + implements AnalysisInputLocation { + private final SourceType sourceType; protected Path path; - /** - * Variable to store AnalysisInputLocation, which can be DirectoryBasedAnalysisInputLocation, - * WarArchiveAnalysisInputLocation, MultiReleaseJarAnalysisInputLocation, - * ArchiveBasedAnalysisInputLocation - */ - PathBasedAnalysisInputLocation inputLocation; + protected PathBasedAnalysisInputLocation(Path path, SourceType srcType) { + this.path = path; + this.sourceType = srcType; + } - public PathBasedAnalysisInputLocation(@Nonnull Path path) { - this(path, SourceType.Application); + @Nullable + @Override + public SourceType getSourceType() { + return sourceType; } - public PathBasedAnalysisInputLocation(@Nonnull Path path, @Nullable SourceType srcType) { - this.path = path; + @Nonnull + public static PathBasedAnalysisInputLocation create( + @Nonnull Path path, @Nonnull SourceType srcType) { + final PathBasedAnalysisInputLocation inputLocation; if (Files.isDirectory(path)) { inputLocation = new DirectoryBasedAnalysisInputLocation(path, srcType); } else if (PathUtils.isArchive(path)) { @@ -110,45 +114,9 @@ public PathBasedAnalysisInputLocation(@Nonnull Path path, @Nullable SourceType s + path.toAbsolutePath() + "' has to be pointing to the root of a class container, e.g. directory, jar, zip, apk, war etc."); } - } - - public PathBasedAnalysisInputLocation getInputLocation() { return inputLocation; } - /** - * Create or find a class source for a given type. - * - * @param type The type of the class to be found. - * @param view - * @return The source entry for that class. - */ - @Nonnull - @Override - public Optional> getClassSource( - @Nonnull ClassType type, @Nonnull View view) { - return inputLocation.getClassSource(type, view); - } - - /** - * Scan the input location and create ClassSources for every compilation / interpretation unit. - * - * @param view - * @return The source entries. - */ - @Nonnull - @Override - public Collection> getClassSources( - @Nonnull View view) { - return inputLocation.getClassSources(view); - } - - @Override - @Nonnull - public SourceType getSourceType() { - return inputLocation.getSourceType(); - } - private static boolean isMultiReleaseJar(Path path) { try { FileInputStream inputStream = new FileInputStream(path.toFile()); @@ -291,7 +259,7 @@ private void discoverInputLocations(@Nullable SourceType srcType) { final Path archiveRoot = fs.getPath("/"); final String moduleInfoFilename = JavaModuleIdentifierFactory.MODULE_INFO_FILE + ".class"; - baseInputLocations.add(new PathBasedAnalysisInputLocation(archiveRoot, srcType)); + baseInputLocations.add(PathBasedAnalysisInputLocation.create(archiveRoot, srcType)); String sep = archiveRoot.getFileSystem().getSeparator(); @@ -350,7 +318,7 @@ private void discoverInputLocations(@Nullable SourceType srcType) { if (inputLocations.get(availableVersions[i]).size() == 0) { inputLocations .get(availableVersions[i]) - .add(new PathBasedAnalysisInputLocation(versionRoot, srcType)); + .add(PathBasedAnalysisInputLocation.create(versionRoot, srcType)); } } } diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/RuntimeJarConversionTests.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/RuntimeJarConversionTests.java index 12b486e0251..241d631c33a 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/RuntimeJarConversionTests.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/RuntimeJarConversionTests.java @@ -17,7 +17,7 @@ public class RuntimeJarConversionTests { private static void execute(String methodSignature1) { AnalysisInputLocation inputLocation = - new PathBasedAnalysisInputLocation( + PathBasedAnalysisInputLocation.create( Paths.get(System.getProperty("java.home") + "/lib/rt.jar"), null); JavaProject project = JavaProject.builder(new JavaLanguage(8)).addInputLocation(inputLocation).build(); diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/Soot1580.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/Soot1580.java index 1ce37d6806c..9cecd0aa910 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/Soot1580.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/Soot1580.java @@ -21,7 +21,7 @@ public class Soot1580 { @Test public void test() { AnalysisInputLocation inputLocation = - new PathBasedAnalysisInputLocation(jar, null); + PathBasedAnalysisInputLocation.create(jar, null); JavaProject project = JavaProject.builder(new JavaLanguage(7)).addInputLocation(inputLocation).build(); diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java index 336ddfdcdab..7221b282376 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java @@ -70,31 +70,31 @@ public void multiReleaseJar() { final JavaProject project_min = JavaProject.builder(new JavaLanguage(Integer.MIN_VALUE)) - .addInputLocation(new PathBasedAnalysisInputLocation(mrj, null)) + .addInputLocation(PathBasedAnalysisInputLocation.create(mrj, null)) .build(); final JavaView view_min = project_min.createView(); final JavaProject project_8 = JavaProject.builder(new JavaLanguage(8)) - .addInputLocation(new PathBasedAnalysisInputLocation(mrj, null)) + .addInputLocation(PathBasedAnalysisInputLocation.create(mrj, null)) .build(); final JavaView view_8 = project_8.createView(); final JavaProject project_9 = JavaProject.builder(new JavaLanguage(9)) - .addInputLocation(new PathBasedAnalysisInputLocation(mrj, null)) + .addInputLocation(PathBasedAnalysisInputLocation.create(mrj, null)) .build(); final JavaView view_9 = project_9.createView(); final JavaProject project_10 = JavaProject.builder(new JavaLanguage(10)) - .addInputLocation(new PathBasedAnalysisInputLocation(mrj, null)) + .addInputLocation(PathBasedAnalysisInputLocation.create(mrj, null)) .build(); final JavaView view_10 = project_10.createView(); final JavaProject project_max = JavaProject.builder(new JavaLanguage(Integer.MAX_VALUE)) - .addInputLocation(new PathBasedAnalysisInputLocation(mrj, null)) + .addInputLocation(PathBasedAnalysisInputLocation.create(mrj, null)) .build(); final JavaView view_max = project_max.createView(); @@ -184,7 +184,7 @@ public void modularMultiReleaseJar() { final JavaProject project_8 = JavaProject.builder(new JavaLanguage(8)) - .addInputLocation(new PathBasedAnalysisInputLocation(mmrj, null)) + .addInputLocation(PathBasedAnalysisInputLocation.create(mmrj, null)) .build(); final JavaView view_8 = project_8.createView(); @@ -194,7 +194,7 @@ public void modularMultiReleaseJar() { .enableModules() .addInputLocation( (ModuleInfoAnalysisInputLocation) - new PathBasedAnalysisInputLocation(mmrj, null).getInputLocation()) + PathBasedAnalysisInputLocation.create(mmrj, null)) .build(); final JavaModuleView view_9 = project_9.createView(); @@ -271,7 +271,7 @@ public void modularMultiReleaseJar() { @Test public void testApk() { PathBasedAnalysisInputLocation pathBasedNamespace = - new PathBasedAnalysisInputLocation(apk, null); + PathBasedAnalysisInputLocation.create(apk, null); final ClassType mainClass = getIdentifierFactory().getClassType("de.upb.futuresoot.fields.MainActivity"); testClassReceival(pathBasedNamespace, mainClass, 1); @@ -280,7 +280,7 @@ public void testApk() { @Test public void testJar() { PathBasedAnalysisInputLocation pathBasedNamespace = - new PathBasedAnalysisInputLocation(jar, null); + PathBasedAnalysisInputLocation.create(jar, null); final ClassType class1 = getIdentifierFactory().getClassType("Employee", "ds"); final ClassType mainClass = getIdentifierFactory().getClassType("MiniApp"); @@ -291,7 +291,7 @@ public void testJar() { @Test public void testWar() { PathBasedAnalysisInputLocation pathBasedNamespace = - new PathBasedAnalysisInputLocation(war, null); + PathBasedAnalysisInputLocation.create(war, null); final ClassType warClass1 = getIdentifierFactory().getClassType("SimpleWarRead"); testClassReceival(pathBasedNamespace, warClass1, 2); } @@ -412,7 +412,7 @@ void runtimeContains(View view, String classname, String packageName) { @Test public void testRuntimeJar() { PathBasedAnalysisInputLocation pathBasedNamespace = - new PathBasedAnalysisInputLocation( + PathBasedAnalysisInputLocation.create( Paths.get(System.getProperty("java.home") + "/lib/rt.jar"), null); JavaView v = diff --git a/sootup.tests/src/test/java/sootup/tests/CacheTest.java b/sootup.tests/src/test/java/sootup/tests/CacheTest.java index d50fde94c54..cca8ebb1b45 100644 --- a/sootup.tests/src/test/java/sootup/tests/CacheTest.java +++ b/sootup.tests/src/test/java/sootup/tests/CacheTest.java @@ -30,7 +30,7 @@ public class CacheTest { @BeforeClass public static void setupProject() { PathBasedAnalysisInputLocation location = - new PathBasedAnalysisInputLocation(pathToJar, SourceType.Application); + PathBasedAnalysisInputLocation.create(pathToJar, SourceType.Application); p = JavaProject.builder(new JavaLanguage(8)).addInputLocation(location).build(); } diff --git a/sootup.tests/src/test/java/sootup/tests/MutableSootClientTest.java b/sootup.tests/src/test/java/sootup/tests/MutableSootClientTest.java index cf6bdae2886..16d787759c8 100644 --- a/sootup.tests/src/test/java/sootup/tests/MutableSootClientTest.java +++ b/sootup.tests/src/test/java/sootup/tests/MutableSootClientTest.java @@ -37,7 +37,7 @@ public class MutableSootClientTest { /** Load the jar file for analysis as input location. */ @BeforeClass public static void setupProject() { - location = new PathBasedAnalysisInputLocation(pathToJar, SourceType.Application); + location = PathBasedAnalysisInputLocation.create(pathToJar, SourceType.Application); p = JavaProject.builder(new JavaLanguage(8)).addInputLocation(location).build(); } From b1e2a5406fda27913690b6f5454c9199a1a01c08 Mon Sep 17 00:00:00 2001 From: sschott Date: Fri, 28 Jul 2023 13:53:27 +0200 Subject: [PATCH 40/90] bump dex2jar to v64 --- sootup.java.bytecode/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sootup.java.bytecode/pom.xml b/sootup.java.bytecode/pom.xml index a99d09e7395..bcc304d5982 100644 --- a/sootup.java.bytecode/pom.xml +++ b/sootup.java.bytecode/pom.xml @@ -36,7 +36,7 @@ com.github.ThexXTURBOXx.dex2jar dex-tools - v61 + v64 From 552aade3f104b06509f048bceaf1831eed627e9c Mon Sep 17 00:00:00 2001 From: Kadiray Karakaya Date: Fri, 28 Jul 2023 14:20:59 +0200 Subject: [PATCH 41/90] add test category --- .../ICFGDotExporterTest.java} | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) rename sootup.analysis/src/test/java/sootup/analysis/interprocedural/{ifds/ICFGCallGraphTest.java => icfg/ICFGDotExporterTest.java} (97%) diff --git a/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java b/sootup.analysis/src/test/java/sootup/analysis/interprocedural/icfg/ICFGDotExporterTest.java similarity index 97% rename from sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java rename to sootup.analysis/src/test/java/sootup/analysis/interprocedural/icfg/ICFGDotExporterTest.java index da9f8413925..fe0a5d0113c 100644 --- a/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/ICFGCallGraphTest.java +++ b/sootup.analysis/src/test/java/sootup/analysis/interprocedural/icfg/ICFGDotExporterTest.java @@ -1,13 +1,15 @@ -package sootup.analysis.interprocedural.ifds; +package sootup.analysis.interprocedural.icfg; import static junit.framework.TestCase.assertNotNull; import static junit.framework.TestCase.assertTrue; import java.util.*; + +import categories.Java8Test; import org.junit.Assert; import org.junit.Test; -import sootup.analysis.interprocedural.icfg.ICFGDotExporter; -import sootup.analysis.interprocedural.icfg.JimpleBasedInterproceduralCFG; +import org.junit.experimental.categories.Category; +import sootup.analysis.interprocedural.ifds.IFDSTaintTestSetUp; import sootup.callgraph.CallGraph; import sootup.callgraph.ClassHierarchyAnalysisAlgorithm; import sootup.core.graph.StmtGraph; @@ -22,7 +24,8 @@ import sootup.java.core.types.JavaClassType; import sootup.java.core.views.JavaView; -public class ICFGCallGraphTest extends IFDSTaintTestSetUp { +@Category(Java8Test.class) +public class ICFGDotExporterTest extends IFDSTaintTestSetUp { public CallGraph loadCallGraph(JavaView view) { CallGraph cg = From d792dc50759d7c807bd9c44b64ed2aa5c9d1ef35 Mon Sep 17 00:00:00 2001 From: Kadiray Karakaya Date: Fri, 28 Jul 2023 14:26:01 +0200 Subject: [PATCH 42/90] fmt --- .../analysis/interprocedural/icfg/ICFGDotExporterTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sootup.analysis/src/test/java/sootup/analysis/interprocedural/icfg/ICFGDotExporterTest.java b/sootup.analysis/src/test/java/sootup/analysis/interprocedural/icfg/ICFGDotExporterTest.java index fe0a5d0113c..2a009388e75 100644 --- a/sootup.analysis/src/test/java/sootup/analysis/interprocedural/icfg/ICFGDotExporterTest.java +++ b/sootup.analysis/src/test/java/sootup/analysis/interprocedural/icfg/ICFGDotExporterTest.java @@ -3,9 +3,8 @@ import static junit.framework.TestCase.assertNotNull; import static junit.framework.TestCase.assertTrue; -import java.util.*; - import categories.Java8Test; +import java.util.*; import org.junit.Assert; import org.junit.Test; import org.junit.experimental.categories.Category; From 32baf1f4e7650356f02a080c07ee67fba86c78d6 Mon Sep 17 00:00:00 2001 From: stschott Date: Mon, 31 Jul 2023 10:23:58 +0200 Subject: [PATCH 43/90] fix parsing of double types with infinity/NaN values --- .../sootup/jimple/parser/JimpleConverter.java | 9 +++++++ .../jimple/EdgeCaseDoubleNumber.jimple | 26 +++++++++++++++++++ .../jimple/parser/JimpleConverterTest.java | 17 +++++++++--- 3 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 sootup.jimple.parser/src/test/java/resources/jimple/EdgeCaseDoubleNumber.jimple diff --git a/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleConverter.java b/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleConverter.java index 2e36e9d64d5..9606c446dda 100644 --- a/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleConverter.java +++ b/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleConverter.java @@ -673,6 +673,15 @@ public Constant visitConstant(JimpleParser.ConstantContext ctx) { floatStr = floatStr.substring(0, lastCharPos); return FloatConstant.getInstance(Float.parseFloat(floatStr)); } + + if (floatStr.charAt(0) == '#') { + switch(floatStr.substring(1)) { + case "Infinity": return DoubleConstant.getInstance(Double.POSITIVE_INFINITY); + case "-Infinity": return DoubleConstant.getInstance(Double.NEGATIVE_INFINITY); + case "NaN": return DoubleConstant.getInstance(Double.NaN); + } + } + return DoubleConstant.getInstance(Double.parseDouble(floatStr)); } else if (ctx.CLASS() != null) { final String text = Jimple.unescape(ctx.STRING_CONSTANT().getText()); diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/EdgeCaseDoubleNumber.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/EdgeCaseDoubleNumber.jimple new file mode 100644 index 00000000000..b058c24a763 --- /dev/null +++ b/sootup.jimple.parser/src/test/java/resources/jimple/EdgeCaseDoubleNumber.jimple @@ -0,0 +1,26 @@ +public class EdgeCaseDoubleNumber extends java.lang.Object +{ + + private double positiveInfinity; + private double negativeInfinity; + private double notANumber; + + public void () + { + unknown l0; + + + l0 := @this: InfinityDoubleNumber; + + specialinvoke l0.()>(); + + l0. = #Infinity; + l0. = #-Infinity; + l0. = #NaN; + + return; + } + + +} + diff --git a/sootup.jimple.parser/src/test/java/sootup/jimple/parser/JimpleConverterTest.java b/sootup.jimple.parser/src/test/java/sootup/jimple/parser/JimpleConverterTest.java index 3330001fc0a..86c130fc139 100644 --- a/sootup.jimple.parser/src/test/java/sootup/jimple/parser/JimpleConverterTest.java +++ b/sootup.jimple.parser/src/test/java/sootup/jimple/parser/JimpleConverterTest.java @@ -14,11 +14,9 @@ import sootup.core.frontend.ResolveException; import sootup.core.inputlocation.EagerInputLocation; import sootup.core.jimple.Jimple; -import sootup.core.model.Body; -import sootup.core.model.SootClass; -import sootup.core.model.SootMethod; -import sootup.core.model.SourceType; +import sootup.core.model.*; import sootup.core.signatures.MethodSubSignature; +import sootup.core.types.PrimitiveType; import sootup.core.types.VoidType; import sootup.core.util.StringTools; import sootup.jimple.JimpleLexer; @@ -791,4 +789,15 @@ public void testQuotedTypeParsing() throws IOException { Body body = method.getBody(); assertEquals(3, body.getLocalCount()); } + + @Test + public void testEdgeCaseDoubleParsing() throws IOException { + SootClass clazz = + parseJimpleClass( + CharStreams.fromFileName("src/test/java/resources/jimple/EdgeCaseDoubleNumber.jimple")); + Set fields = clazz.getFields(); + for (SootField field : fields) { + assertEquals(PrimitiveType.DoubleType.getInstance(), field.getType()); + } + } } From e478baec5a948334e632e47f16fc7f0838ff5571 Mon Sep 17 00:00:00 2001 From: stschott Date: Mon, 31 Jul 2023 11:52:18 +0200 Subject: [PATCH 44/90] format --- .../java/sootup/jimple/parser/JimpleConverter.java | 11 +++++++---- .../sootup/jimple/parser/JimpleConverterTest.java | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleConverter.java b/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleConverter.java index 9606c446dda..b9323d51da8 100644 --- a/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleConverter.java +++ b/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleConverter.java @@ -675,10 +675,13 @@ public Constant visitConstant(JimpleParser.ConstantContext ctx) { } if (floatStr.charAt(0) == '#') { - switch(floatStr.substring(1)) { - case "Infinity": return DoubleConstant.getInstance(Double.POSITIVE_INFINITY); - case "-Infinity": return DoubleConstant.getInstance(Double.NEGATIVE_INFINITY); - case "NaN": return DoubleConstant.getInstance(Double.NaN); + switch (floatStr.substring(1)) { + case "Infinity": + return DoubleConstant.getInstance(Double.POSITIVE_INFINITY); + case "-Infinity": + return DoubleConstant.getInstance(Double.NEGATIVE_INFINITY); + case "NaN": + return DoubleConstant.getInstance(Double.NaN); } } diff --git a/sootup.jimple.parser/src/test/java/sootup/jimple/parser/JimpleConverterTest.java b/sootup.jimple.parser/src/test/java/sootup/jimple/parser/JimpleConverterTest.java index 86c130fc139..5ee379e18a3 100644 --- a/sootup.jimple.parser/src/test/java/sootup/jimple/parser/JimpleConverterTest.java +++ b/sootup.jimple.parser/src/test/java/sootup/jimple/parser/JimpleConverterTest.java @@ -793,8 +793,8 @@ public void testQuotedTypeParsing() throws IOException { @Test public void testEdgeCaseDoubleParsing() throws IOException { SootClass clazz = - parseJimpleClass( - CharStreams.fromFileName("src/test/java/resources/jimple/EdgeCaseDoubleNumber.jimple")); + parseJimpleClass( + CharStreams.fromFileName("src/test/java/resources/jimple/EdgeCaseDoubleNumber.jimple")); Set fields = clazz.getFields(); for (SootField field : fields) { assertEquals(PrimitiveType.DoubleType.getInstance(), field.getType()); From d90e63885d61ff4f307856ba14d699cccc66cdf8 Mon Sep 17 00:00:00 2001 From: Jonas Klauke Date: Mon, 31 Jul 2023 18:36:39 +0200 Subject: [PATCH 45/90] split Modifier Enum to FieldModifier, MethodModifier, and ClassModifier Enums --- .../ClassHierarchyAnalysisAlgorithm.java | 4 +- .../callgraph/RapidTypeAnalysisAlgorithm.java | 4 +- .../java/sootup/core/frontend/BodySource.java | 5 +- .../core/frontend/OverridingBodySource.java | 4 +- .../core/frontend/OverridingClassSource.java | 10 +- .../sootup/core/frontend/SootClassSource.java | 4 +- .../src/main/java/sootup/core/model/Body.java | 10 +- .../java/sootup/core/model/ClassModifier.java | 168 ++++++++++++++++++ .../java/sootup/core/model/FieldModifier.java | 146 +++++++++++++++ .../{Modifier.java => MethodModifier.java} | 79 ++++---- .../java/sootup/core/model/SootClass.java | 24 +-- .../sootup/core/model/SootClassMember.java | 44 +---- .../java/sootup/core/model/SootField.java | 66 ++++++- .../java/sootup/core/model/SootMethod.java | 70 ++++++-- .../core/util/printer/JimplePrinter.java | 12 +- .../frontend/AsmAnnotationClassSource.java | 8 +- .../bytecode/frontend/AsmClassSource.java | 8 +- .../bytecode/frontend/AsmMethodSource.java | 6 +- .../java/bytecode/frontend/AsmUtil.java | 34 +++- .../DeadAssignmentEliminator.java | 4 +- .../PathBasedAnalysisInputLocationTest.java | 12 +- .../java6/AnnotationLibraryTest.java | 4 +- .../java6/DeclareFieldTest.java | 18 +- .../java6/PublicClassTest.java | 4 +- .../java6/TransientVariableTest.java | 4 +- .../java6/VolatileVariableTest.java | 8 +- .../java8/RepeatingAnnotationsTest.java | 4 +- .../java/core/JavaAnnotationSootMethod.java | 4 +- .../java/sootup/java/core/JavaSootClass.java | 2 +- .../java/sootup/java/core/JavaSootField.java | 12 +- .../java/sootup/java/core/JavaSootMethod.java | 6 +- .../java/core/OverridingJavaClassSource.java | 12 +- .../core/jimple/common/ref/JFieldRefTest.java | 17 +- .../jimple/common/stmt/JInvokeStmtTest.java | 4 +- .../java/core/model/SootMethodTest.java | 7 +- .../java/core/printer/JimplePrinterTest.java | 8 +- .../core/printer/LegacyJimplePrinterTest.java | 4 +- .../frontend/InstructionConverter.java | 8 +- .../frontend/WalaIRToJimpleConverter.java | 75 ++++---- .../sourcecode/frontend/WalaSootMethod.java | 6 +- .../java6/AnnotationLibraryTest.java | 4 +- .../java6/DeclareFieldTest.java | 18 +- .../java6/NoModifierClassTest.java | 4 +- .../java6/PublicClassTest.java | 4 +- .../java6/TransientVariableTest.java | 4 +- .../java6/VolatileVariableTest.java | 4 +- .../java8/RepeatingAnnotationsTest.java | 4 +- .../sootup/jimple/parser/JimpleConverter.java | 55 ++++-- .../java6/AnnotationLibraryTest.java | 4 +- .../javatestsuite/java6/DeclareFieldTest.java | 18 +- .../javatestsuite/java6/PublicClassTest.java | 4 +- .../java6/TransientVariableTest.java | 4 +- .../java6/VolatileVariableTest.java | 8 +- .../java8/RepeatingAnnotationsTest.java | 4 +- .../sootup/tests/MutableSootClientTest.java | 4 +- .../typehierarchy/ViewTypeHierarchyTest.java | 4 +- 56 files changed, 739 insertions(+), 337 deletions(-) create mode 100644 sootup.core/src/main/java/sootup/core/model/ClassModifier.java create mode 100644 sootup.core/src/main/java/sootup/core/model/FieldModifier.java rename sootup.core/src/main/java/sootup/core/model/{Modifier.java => MethodModifier.java} (65%) diff --git a/sootup.callgraph/src/main/java/sootup/callgraph/ClassHierarchyAnalysisAlgorithm.java b/sootup.callgraph/src/main/java/sootup/callgraph/ClassHierarchyAnalysisAlgorithm.java index b4c6c96ec75..d0f22f5323c 100644 --- a/sootup.callgraph/src/main/java/sootup/callgraph/ClassHierarchyAnalysisAlgorithm.java +++ b/sootup.callgraph/src/main/java/sootup/callgraph/ClassHierarchyAnalysisAlgorithm.java @@ -28,7 +28,7 @@ import sootup.core.jimple.common.expr.AbstractInvokeExpr; import sootup.core.jimple.common.expr.JDynamicInvokeExpr; import sootup.core.jimple.common.expr.JSpecialInvokeExpr; -import sootup.core.model.Modifier; +import sootup.core.model.MethodModifier; import sootup.core.model.SootClass; import sootup.core.model.SootMethod; import sootup.core.signatures.MethodSignature; @@ -89,7 +89,7 @@ protected Stream resolveCall(SootMethod method, AbstractInvokeE .orElseGet(() -> findMethodInHierarchy(view, targetMethodSignature)); if (targetMethod == null - || Modifier.isStatic(targetMethod.getModifiers()) + || MethodModifier.isStatic(targetMethod.getModifiers()) || (invokeExpr instanceof JSpecialInvokeExpr)) { return result; } else { diff --git a/sootup.callgraph/src/main/java/sootup/callgraph/RapidTypeAnalysisAlgorithm.java b/sootup.callgraph/src/main/java/sootup/callgraph/RapidTypeAnalysisAlgorithm.java index 75ef205dd66..69fee270cab 100644 --- a/sootup.callgraph/src/main/java/sootup/callgraph/RapidTypeAnalysisAlgorithm.java +++ b/sootup.callgraph/src/main/java/sootup/callgraph/RapidTypeAnalysisAlgorithm.java @@ -31,7 +31,7 @@ import sootup.core.jimple.common.expr.JNewExpr; import sootup.core.jimple.common.expr.JSpecialInvokeExpr; import sootup.core.jimple.common.stmt.JAssignStmt; -import sootup.core.model.Modifier; +import sootup.core.model.MethodModifier; import sootup.core.model.SootClass; import sootup.core.model.SootMethod; import sootup.core.signatures.MethodSignature; @@ -138,7 +138,7 @@ protected Stream resolveCall(SootMethod method, AbstractInvokeE .orElseGet(() -> findMethodInHierarchy(view, targetMethodSignature)); if (targetMethod == null - || Modifier.isStatic(targetMethod.getModifiers()) + || MethodModifier.isStatic(targetMethod.getModifiers()) || (invokeExpr instanceof JSpecialInvokeExpr)) { return result; } else { diff --git a/sootup.core/src/main/java/sootup/core/frontend/BodySource.java b/sootup.core/src/main/java/sootup/core/frontend/BodySource.java index 21d33bc3968..914e186335f 100644 --- a/sootup.core/src/main/java/sootup/core/frontend/BodySource.java +++ b/sootup.core/src/main/java/sootup/core/frontend/BodySource.java @@ -24,7 +24,7 @@ import java.io.IOException; import javax.annotation.Nonnull; import sootup.core.model.Body; -import sootup.core.model.Modifier; +import sootup.core.model.MethodModifier; import sootup.core.signatures.MethodSignature; /** @@ -40,7 +40,8 @@ public interface BodySource { * body accordingly. */ @Nonnull - Body resolveBody(@Nonnull Iterable modifiers) throws ResolveException, IOException; + Body resolveBody(@Nonnull Iterable modifiers) + throws ResolveException, IOException; /** @return returns the default value of the Annotation for this method */ Object resolveAnnotationsDefaultValue(); diff --git a/sootup.core/src/main/java/sootup/core/frontend/OverridingBodySource.java b/sootup.core/src/main/java/sootup/core/frontend/OverridingBodySource.java index 6e6b5dc2026..3dd69a97aaa 100644 --- a/sootup.core/src/main/java/sootup/core/frontend/OverridingBodySource.java +++ b/sootup.core/src/main/java/sootup/core/frontend/OverridingBodySource.java @@ -24,7 +24,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import sootup.core.model.Body; -import sootup.core.model.Modifier; +import sootup.core.model.MethodModifier; import sootup.core.signatures.MethodSignature; /** @author Hasitha Rajapakse */ @@ -68,7 +68,7 @@ public OverridingBodySource(@Nonnull MethodSignature methodSignature, @Nonnull B @Nonnull @Override - public Body resolveBody(@Nonnull Iterable modifiers) throws IOException { + public Body resolveBody(@Nonnull Iterable modifiers) throws IOException { return body != null ? body : delegate.resolveBody(modifiers); } diff --git a/sootup.core/src/main/java/sootup/core/frontend/OverridingClassSource.java b/sootup.core/src/main/java/sootup/core/frontend/OverridingClassSource.java index 1dc98c25676..84fbe45cc3d 100644 --- a/sootup.core/src/main/java/sootup/core/frontend/OverridingClassSource.java +++ b/sootup.core/src/main/java/sootup/core/frontend/OverridingClassSource.java @@ -53,7 +53,7 @@ public class OverridingClassSource extends SootClassSource { @Nullable private final Collection overriddenSootMethods; @Nullable private final Collection overriddenSootFields; - @Nullable private final Set overriddenModifiers; + @Nullable private final Set overriddenModifiers; @Nullable private final Set overriddenInterfaces; @Nullable private final Optional overriddenSuperclass; @Nullable private final Optional overriddenOuterClass; @@ -76,7 +76,7 @@ public OverridingClassSource(@Nonnull SootClassSource delegate) { private OverridingClassSource( @Nullable Collection overriddenSootMethods, @Nullable Collection overriddenSootFields, - @Nullable Set overriddenModifiers, + @Nullable Set overriddenModifiers, @Nullable Set overriddenInterfaces, @Nullable Optional overriddenSuperclass, @Nullable Optional overriddenOuterClass, @@ -97,7 +97,7 @@ private OverridingClassSource( public OverridingClassSource( @Nonnull Set sootMethods, @Nonnull Set sootFields, - @Nonnull EnumSet modifiers, + @Nonnull EnumSet modifiers, @Nonnull Set interfaces, @Nonnull ClassType superClass, @Nonnull ClassType outerClass, @@ -131,7 +131,7 @@ public Collection resolveFields() throws ResolveException { @Nonnull @Override - public Set resolveModifiers() { + public Set resolveModifiers() { return overriddenModifiers != null ? overriddenModifiers : delegate.resolveModifiers(); } @@ -261,7 +261,7 @@ public OverridingClassSource withFields(@Nonnull Collection overridde } @Nonnull - public OverridingClassSource withModifiers(@Nonnull Set overriddenModifiers) { + public OverridingClassSource withModifiers(@Nonnull Set overriddenModifiers) { return new OverridingClassSource( overriddenSootMethods, overriddenSootFields, diff --git a/sootup.core/src/main/java/sootup/core/frontend/SootClassSource.java b/sootup.core/src/main/java/sootup/core/frontend/SootClassSource.java index 426e9bc057d..087161feca0 100644 --- a/sootup.core/src/main/java/sootup/core/frontend/SootClassSource.java +++ b/sootup.core/src/main/java/sootup/core/frontend/SootClassSource.java @@ -28,7 +28,7 @@ import java.util.Set; import javax.annotation.Nonnull; import sootup.core.inputlocation.AnalysisInputLocation; -import sootup.core.model.Modifier; +import sootup.core.model.ClassModifier; import sootup.core.model.Position; import sootup.core.model.SootClass; import sootup.core.model.SootField; @@ -78,7 +78,7 @@ protected SootClassSource(SootClassSource delegate) { /** Reads from the source to retrieve its modifiers. This may be an expensive operation. */ @Nonnull - public abstract Set resolveModifiers(); + public abstract Set resolveModifiers(); /** * Reads from the source to retrieve its directly implemented interfaces. This may be an expensive diff --git a/sootup.core/src/main/java/sootup/core/model/Body.java b/sootup.core/src/main/java/sootup/core/model/Body.java index 6b0bd9489d2..09886d27961 100644 --- a/sootup.core/src/main/java/sootup/core/model/Body.java +++ b/sootup.core/src/main/java/sootup/core/model/Body.java @@ -341,7 +341,7 @@ public static BodyBuilder builder(@Nonnull MutableStmtGraph graph) { return new BodyBuilder(graph); } - public static BodyBuilder builder(@Nonnull Body body, Set modifiers) { + public static BodyBuilder builder(@Nonnull Body body, Set modifiers) { return new BodyBuilder(body, modifiers); } @@ -366,7 +366,7 @@ public static BodyBuilder builder(@Nonnull Body body, Set modifiers) { public static class BodyBuilder { @Nonnull private Set locals = new LinkedHashSet<>(); @Nonnull private final LocalGenerator localGen = new LocalGenerator(locals); - @Nonnull private Set modifiers = Collections.emptySet(); + @Nonnull private Set modifiers = Collections.emptySet(); @Nullable private Position position = null; @Nonnull private final MutableStmtGraph graph; @@ -382,7 +382,7 @@ public static class BodyBuilder { this.graph = graph; } - BodyBuilder(@Nonnull Body body, @Nonnull Set modifiers) { + BodyBuilder(@Nonnull Body body, @Nonnull Set modifiers) { setModifiers(modifiers); setMethodSignature(body.getMethodSignature()); setLocals(new LinkedHashSet<>(body.getLocals())); @@ -510,7 +510,7 @@ public BodyBuilder removeFlow(@Nonnull Stmt fromStmt, @Nonnull Stmt toStmt) { return this; } - public BodyBuilder setModifiers(@Nonnull Set modifiers) { + public BodyBuilder setModifiers(@Nonnull Set modifiers) { this.modifiers = modifiers; return this; } @@ -567,7 +567,7 @@ public Body build() { } @Nonnull - public Set getModifiers() { + public Set getModifiers() { return modifiers; } diff --git a/sootup.core/src/main/java/sootup/core/model/ClassModifier.java b/sootup.core/src/main/java/sootup/core/model/ClassModifier.java new file mode 100644 index 00000000000..728cd1a07f3 --- /dev/null +++ b/sootup.core/src/main/java/sootup/core/model/ClassModifier.java @@ -0,0 +1,168 @@ +// Incomplete class + +package sootup.core.model; + +/*- + * #%L + * Soot - a J*va Optimization Framework + * %% + * Copyright (C) 1997-2020 Raja Vallee-Rai, Jan Martin Persch, Christian Brüggemann and others + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * . + * #L% + */ + +import java.util.EnumSet; +import java.util.Set; +import java.util.stream.Collectors; +import javax.annotation.Nonnull; + +/** + * An Enum that provides static methods and constants to represent and work with with Java modifiers + * (ie public, final,...) Represents Java modifiers that can be packed and combined via EnumSet and + * methods to query these. + */ +public enum ClassModifier { + PUBLIC(0x0001), + PRIVATE(0x0002), + PROTECTED(0x0004), + + STATIC(0x0008), + FINAL(0x0010), + + SUPER(0x0020), + INTERFACE(0x0200), + ABSTRACT(0x0400), + SYNTHETIC(0x1000), + ANNOTATION(0x2000), + ENUM(0x4000), + + MODULE(0x8000); + + private final int bytecode; + + ClassModifier(int i) { + bytecode = i; + } + + public static boolean isAbstract(@Nonnull Set m) { + return m.contains(ABSTRACT); + } + + public static boolean isFinal(@Nonnull Set m) { + return m.contains(FINAL); + } + + public static boolean isInterface(@Nonnull Set m) { + return m.contains(INTERFACE); + } + + public static boolean isPrivate(@Nonnull Set m) { + return m.contains(PRIVATE); + } + + public static boolean isProtected(@Nonnull Set m) { + return m.contains(PROTECTED); + } + + public static boolean isPublic(@Nonnull Set m) { + return m.contains(PUBLIC); + } + + public static boolean isStatic(@Nonnull Set m) { + return m.contains(STATIC); + } + + public static boolean isSuper(@Nonnull Set m) { + return m.contains(SUPER); + } + + public static boolean isAnnotation(@Nonnull Set m) { + return m.contains(ANNOTATION); + } + + public static boolean isEnum(@Nonnull Set m) { + return m.contains(ENUM); + } + + public static boolean isSynthetic(@Nonnull Set m) { + return m.contains(SYNTHETIC); + } + + /** + * Converts the given modifiers to their string representation, in canonical form. + * + * @param m a modifier set + * @return a textual representation of the modifiers. + */ + @Nonnull + public static String toString(@Nonnull Set m) { + StringBuilder builder = new StringBuilder(); + + if (isPublic(m)) { + builder.append("public "); + } else if (isPrivate(m)) { + builder.append("private "); + } else if (isProtected(m)) { + builder.append("protected "); + } + + if (isAbstract(m)) { + builder.append("abstract "); + } + + if (isStatic(m)) { + builder.append("static "); + } + + if (isFinal(m)) { + builder.append("final "); + } + + if (isSuper(m)) { + builder.append("super "); + } + + if (isAnnotation(m)) { + builder.append("annotation "); + } + + if (isEnum(m)) { + builder.append("enum "); + } + + if (isInterface(m)) { + builder.append("interface "); + } + + // trim + final int lastCharPos = builder.length() - 1; + if (lastCharPos > 0) { + builder.setLength(lastCharPos); + } + return builder.toString(); + } + + @Nonnull + // depends on the natural order of the Enums! + public static String toString(@Nonnull EnumSet m) { + return m.stream().map((mod) -> mod.name().toLowerCase()).collect(Collectors.joining(" ")); + } + + /** @return the bytecode of this Modifier. */ + public int getBytecode() { + return bytecode; + } +} diff --git a/sootup.core/src/main/java/sootup/core/model/FieldModifier.java b/sootup.core/src/main/java/sootup/core/model/FieldModifier.java new file mode 100644 index 00000000000..38bc7638d71 --- /dev/null +++ b/sootup.core/src/main/java/sootup/core/model/FieldModifier.java @@ -0,0 +1,146 @@ +// Incomplete class + +package sootup.core.model; + +/*- + * #%L + * Soot - a J*va Optimization Framework + * %% + * Copyright (C) 1997-2020 Raja Vallee-Rai, Jan Martin Persch, Christian Brüggemann and others + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * . + * #L% + */ + +import java.util.EnumSet; +import java.util.Set; +import java.util.stream.Collectors; +import javax.annotation.Nonnull; + +/** + * An Enum that provides static methods and constants to represent and work with with Java modifiers + * (ie public, final,...) Represents Java modifiers that can be packed and combined via EnumSet and + * methods to query these. + */ +public enum FieldModifier { + PUBLIC(0x0001), + PRIVATE(0x0002), + PROTECTED(0x0004), + STATIC(0x0008), + FINAL(0x0010), + VOLATILE(0x0040), + TRANSIENT(0x0080), + SYNTHETIC(0x1000), + ENUM(0x4000); + + private final int bytecode; + + FieldModifier(int i) { + bytecode = i; + } + + public static boolean isFinal(@Nonnull Set m) { + return m.contains(FINAL); + } + + public static boolean isPrivate(@Nonnull Set m) { + return m.contains(PRIVATE); + } + + public static boolean isProtected(@Nonnull Set m) { + return m.contains(PROTECTED); + } + + public static boolean isPublic(@Nonnull Set m) { + return m.contains(PUBLIC); + } + + public static boolean isStatic(@Nonnull Set m) { + return m.contains(STATIC); + } + + public static boolean isTransient(@Nonnull Set m) { + return m.contains(TRANSIENT); + } + + public static boolean isVolatile(@Nonnull Set m) { + return m.contains(VOLATILE); + } + + public static boolean isEnum(@Nonnull Set m) { + return m.contains(ENUM); + } + + public static boolean isSynthetic(@Nonnull Set m) { + return m.contains(SYNTHETIC); + } + + /** + * Converts the given modifiers to their string representation, in canonical form. + * + * @param m a modifier set + * @return a textual representation of the modifiers. + */ + @Nonnull + public static String toString(@Nonnull Set m) { + StringBuilder builder = new StringBuilder(); + + if (isPublic(m)) { + builder.append("public "); + } else if (isPrivate(m)) { + builder.append("private "); + } else if (isProtected(m)) { + builder.append("protected "); + } + + if (isStatic(m)) { + builder.append("static "); + } + + if (isFinal(m)) { + builder.append("final "); + } + + if (isVolatile(m)) { + builder.append("volatile "); + } + + if (isTransient(m)) { + builder.append("transient "); + } + + if (isEnum(m)) { + builder.append("enum "); + } + + // trim + final int lastCharPos = builder.length() - 1; + if (lastCharPos > 0) { + builder.setLength(lastCharPos); + } + return builder.toString(); + } + + @Nonnull + // depends on the natural order of the Enums! + public static String toString(@Nonnull EnumSet m) { + return m.stream().map((mod) -> mod.name().toLowerCase()).collect(Collectors.joining(" ")); + } + + /** @return the bytecode of this Modifier. */ + public int getBytecode() { + return bytecode; + } +} diff --git a/sootup.core/src/main/java/sootup/core/model/Modifier.java b/sootup.core/src/main/java/sootup/core/model/MethodModifier.java similarity index 65% rename from sootup.core/src/main/java/sootup/core/model/Modifier.java rename to sootup.core/src/main/java/sootup/core/model/MethodModifier.java index 97439a0825a..6375d38ef47 100644 --- a/sootup.core/src/main/java/sootup/core/model/Modifier.java +++ b/sootup.core/src/main/java/sootup/core/model/MethodModifier.java @@ -34,102 +34,91 @@ * (ie public, final,...) Represents Java modifiers that can be packed and combined via EnumSet and * methods to query these. */ -public enum Modifier { +public enum MethodModifier { PUBLIC(0x0001), PRIVATE(0x0002), PROTECTED(0x0004), - ABSTRACT(0x0400), STATIC(0x0008), FINAL(0x0010), SYNCHRONIZED(0x0020), + + VARARGS(0x0080), /* VARARGS for methods */ + BRIDGE(0x0040), NATIVE(0x0100), - TRANSIENT(0x0080), /* VARARGS for methods */ - VOLATILE(0x0040), /* BRIDGE for methods */ + ABSTRACT(0x0400), STRICTFP(0x0800), - ANNOTATION(0x2000), - ENUM(0x4000), - INTERFACE(0x0200), - - MODULE(0x8000), // dex specifific modifiers SYNTHETIC(0x1000), + ENUM(0x4000), CONSTRUCTOR(0x10000), DECLARED_SYNCHRONIZED(0x20000); private final int bytecode; - Modifier(int i) { + MethodModifier(int i) { bytecode = i; } - public static boolean isAbstract(@Nonnull Set m) { + public static boolean isAbstract(@Nonnull Set m) { return m.contains(ABSTRACT); } - public static boolean isFinal(@Nonnull Set m) { + public static boolean isFinal(@Nonnull Set m) { return m.contains(FINAL); } - public static boolean isInterface(@Nonnull Set m) { - return m.contains(INTERFACE); - } - - public static boolean isNative(@Nonnull Set m) { + public static boolean isNative(@Nonnull Set m) { return m.contains(NATIVE); } - public static boolean isPrivate(@Nonnull Set m) { + public static boolean isPrivate(@Nonnull Set m) { return m.contains(PRIVATE); } - public static boolean isProtected(@Nonnull Set m) { + public static boolean isProtected(@Nonnull Set m) { return m.contains(PROTECTED); } - public static boolean isPublic(@Nonnull Set m) { + public static boolean isPublic(@Nonnull Set m) { return m.contains(PUBLIC); } - public static boolean isStatic(@Nonnull Set m) { + public static boolean isStatic(@Nonnull Set m) { return m.contains(STATIC); } - public static boolean isSynchronized(@Nonnull Set m) { + public static boolean isSynchronized(@Nonnull Set m) { return m.contains(SYNCHRONIZED); } - public static boolean isTransient(@Nonnull Set m) { - return m.contains(TRANSIENT); + public static boolean isVarargs(@Nonnull Set m) { + return m.contains(VARARGS); } - public static boolean isVolatile(@Nonnull Set m) { - return m.contains(VOLATILE); + public static boolean isBridge(@Nonnull Set m) { + return m.contains(BRIDGE); } - public static boolean isStrictFP(@Nonnull Set m) { + public static boolean isStrictFP(@Nonnull Set m) { return m.contains(STRICTFP); } - public static boolean isAnnotation(@Nonnull Set m) { - return m.contains(ANNOTATION); - } - - public static boolean isEnum(@Nonnull Set m) { + public static boolean isEnum(@Nonnull Set m) { return m.contains(ENUM); } - public static boolean isSynthetic(@Nonnull Set m) { + public static boolean isSynthetic(@Nonnull Set m) { return m.contains(SYNTHETIC); } - public static boolean isConstructor(@Nonnull Set m) { + public static boolean isConstructor(@Nonnull Set m) { return m.contains(CONSTRUCTOR); } - public static boolean isDeclaredSynchronized(@Nonnull Set m) { + public static boolean isDeclaredSynchronized(@Nonnull Set m) { return m.contains(DECLARED_SYNCHRONIZED); } @@ -140,7 +129,7 @@ public static boolean isDeclaredSynchronized(@Nonnull Set m) { * @return a textual representation of the modifiers. */ @Nonnull - public static String toString(@Nonnull Set m) { + public static String toString(@Nonnull Set m) { StringBuilder builder = new StringBuilder(); if (isPublic(m)) { @@ -171,30 +160,22 @@ public static String toString(@Nonnull Set m) { builder.append("native "); } - if (isTransient(m)) { - builder.append("transient "); + if (isBridge(m)) { + builder.append("bridge "); } - if (isVolatile(m)) { - builder.append("volatile "); + if (isVarargs(m)) { + builder.append("varargs "); } if (isStrictFP(m)) { builder.append("strictfp "); } - if (isAnnotation(m)) { - builder.append("annotation "); - } - if (isEnum(m)) { builder.append("enum "); } - if (isInterface(m)) { - builder.append("interface "); - } - // trim final int lastCharPos = builder.length() - 1; if (lastCharPos > 0) { @@ -205,7 +186,7 @@ public static String toString(@Nonnull Set m) { @Nonnull // depends on the natural order of the Enums! - public static String toString(@Nonnull EnumSet m) { + public static String toString(@Nonnull EnumSet m) { return m.stream().map((mod) -> mod.name().toLowerCase()).collect(Collectors.joining(" ")); } diff --git a/sootup.core/src/main/java/sootup/core/model/SootClass.java b/sootup.core/src/main/java/sootup/core/model/SootClass.java index f989a8f1f12..afa988069e8 100644 --- a/sootup.core/src/main/java/sootup/core/model/SootClass.java +++ b/sootup.core/src/main/java/sootup/core/model/SootClass.java @@ -106,12 +106,12 @@ public Set getFields() { return this._lazyFields.get(); } - private final Supplier> lazyModifiers = + private final Supplier> lazyModifiers = Suppliers.memoize(classSource::resolveModifiers); /** Returns the modifiers of this class in an immutable set. */ @Nonnull - public Set getModifiers() { + public Set getModifiers() { return lazyModifiers.get(); } @@ -184,17 +184,17 @@ public ClassType getType() { /** Convenience method; returns true if this class is an interface. */ public boolean isInterface() { - return Modifier.isInterface(this.getModifiers()); + return ClassModifier.isInterface(this.getModifiers()); } /** Convenience method; returns true if this class is an enumeration. */ public boolean isEnum() { - return Modifier.isEnum(this.getModifiers()); + return ClassModifier.isEnum(this.getModifiers()); } /** Convenience method; returns true if this class is synchronized. */ - public boolean isSynchronized() { - return Modifier.isSynchronized(this.getModifiers()); + public boolean isSuper() { + return ClassModifier.isSuper(this.getModifiers()); } /** Returns true if this class is not an interface and not abstract. */ @@ -204,7 +204,7 @@ public boolean isConcrete() { /** Convenience method; returns true if this class is public. */ public boolean isPublic() { - return Modifier.isPublic(this.getModifiers()); + return ClassModifier.isPublic(this.getModifiers()); } /** Returns the name of this class. */ @@ -240,27 +240,27 @@ public boolean isPhantomClass() { /** Convenience method returning true if this class is private. */ public boolean isPrivate() { - return Modifier.isPrivate(this.getModifiers()); + return ClassModifier.isPrivate(this.getModifiers()); } /** Convenience method returning true if this class is protected. */ public boolean isProtected() { - return Modifier.isProtected(this.getModifiers()); + return ClassModifier.isProtected(this.getModifiers()); } /** Convenience method returning true if this class is abstract. */ public boolean isAbstract() { - return Modifier.isAbstract(this.getModifiers()); + return ClassModifier.isAbstract(this.getModifiers()); } /** Convenience method returning true if this class is final. */ public boolean isFinal() { - return Modifier.isFinal(this.getModifiers()); + return ClassModifier.isFinal(this.getModifiers()); } /** Convenience method returning true if this class is static. */ public boolean isStatic() { - return Modifier.isStatic(this.getModifiers()); + return ClassModifier.isStatic(this.getModifiers()); } private final Supplier lazyPosition = Suppliers.memoize(classSource::resolvePosition); diff --git a/sootup.core/src/main/java/sootup/core/model/SootClassMember.java b/sootup.core/src/main/java/sootup/core/model/SootClassMember.java index b4a9c4bc9e1..333e7194773 100644 --- a/sootup.core/src/main/java/sootup/core/model/SootClassMember.java +++ b/sootup.core/src/main/java/sootup/core/model/SootClassMember.java @@ -22,13 +22,9 @@ * #L% */ -import com.google.common.collect.ImmutableSet; -import java.util.Objects; -import java.util.Set; import javax.annotation.Nonnull; import sootup.core.signatures.SootClassMemberSignature; import sootup.core.types.ClassType; -import sootup.core.util.ImmutableUtils; /** * Provides methods common to Soot objects belonging to classes, namely SootField and SootMethod. @@ -39,13 +35,11 @@ public abstract class SootClassMember { @Nonnull private final S signature; - @Nonnull private final ImmutableSet modifiers; + @Nonnull private final Position position; - SootClassMember( - @Nonnull S signature, @Nonnull Iterable modifiers, @Nonnull Position position) { + SootClassMember(@Nonnull S signature, @Nonnull Position position) { this.signature = signature; - this.modifiers = ImmutableUtils.immutableEnumSetOf(modifiers); this.position = position; } @@ -56,44 +50,22 @@ public ClassType getDeclaringClassType() { } /** Convenience method returning true if this class member is protected. */ - public boolean isProtected() { - return Modifier.isProtected(this.getModifiers()); - } + public abstract boolean isProtected(); /** Convenience method returning true if this class member is private. */ - public boolean isPrivate() { - return Modifier.isPrivate(this.getModifiers()); - } + public abstract boolean isPrivate(); /** Convenience method returning true if this class member is public. */ - public boolean isPublic() { - return Modifier.isPublic(this.getModifiers()); - } + public abstract boolean isPublic(); /** Convenience method returning true if this class member is static. */ - public boolean isStatic() { - return Modifier.isStatic(this.getModifiers()); - } + public abstract boolean isStatic(); /** Convenience method returning true if this field is final. */ - public boolean isFinal() { - return Modifier.isFinal(this.getModifiers()); - } - - /** - * Gets the modifiers of this class member in an immutable set. - * - * @see Modifier - */ - @Nonnull - public Set getModifiers() { - return modifiers; - } + public abstract boolean isFinal(); /** Returns a hash code for this method consistent with structural equality. */ - public int equivHashCode() { - return Objects.hash(modifiers, signature); - } + public abstract int equivHashCode(); /** Returns the signature of this method. */ @Override diff --git a/sootup.core/src/main/java/sootup/core/model/SootField.java b/sootup.core/src/main/java/sootup/core/model/SootField.java index f3514e4a803..7c45a5eb5de 100644 --- a/sootup.core/src/main/java/sootup/core/model/SootField.java +++ b/sootup.core/src/main/java/sootup/core/model/SootField.java @@ -21,11 +21,15 @@ * #L% */ +import com.google.common.collect.ImmutableSet; import java.util.EnumSet; +import java.util.Objects; +import java.util.Set; import javax.annotation.Nonnull; import sootup.core.jimple.basic.NoPositionInformation; import sootup.core.signatures.FieldSignature; import sootup.core.types.Type; +import sootup.core.util.ImmutableUtils; /** * Soot's counterpart of the source language's field concept. Soot representation of a Java field. @@ -36,12 +40,54 @@ */ public class SootField extends SootClassMember implements Field { + @Nonnull private final ImmutableSet modifiers; /** Constructs a Soot field with the given name, type and modifiers. */ public SootField( @Nonnull FieldSignature signature, - @Nonnull Iterable modifiers, + @Nonnull Iterable modifiers, @Nonnull Position position) { - super(signature, modifiers, position); + super(signature, position); + this.modifiers = ImmutableUtils.immutableEnumSetOf(modifiers); + } + + @Override + public boolean isProtected() { + return FieldModifier.isProtected(this.getModifiers()); + } + + @Override + public boolean isPrivate() { + return FieldModifier.isPrivate(this.getModifiers()); + } + + @Override + public boolean isPublic() { + return FieldModifier.isPublic(this.getModifiers()); + } + + @Override + public boolean isStatic() { + return FieldModifier.isStatic(this.getModifiers()); + } + + @Override + public boolean isFinal() { + return FieldModifier.isFinal(this.getModifiers()); + } + + /** + * Gets the modifiers of this class member in an immutable set. + * + * @see FieldModifier + */ + @Nonnull + public Set getModifiers() { + return modifiers; + } + + @Override + public int equivHashCode() { + return Objects.hash(modifiers, getSignature()); } @Nonnull @@ -54,7 +100,9 @@ private String getOriginalStyleDeclaration() { if (this.getModifiers().isEmpty()) { return this.getSignature().getSubSignature().toString(); } else { - return Modifier.toString(this.getModifiers()) + ' ' + this.getSignature().getSubSignature(); + return FieldModifier.toString(this.getModifiers()) + + ' ' + + this.getSignature().getSubSignature(); } } @@ -69,7 +117,7 @@ public SootField withSignature(@Nonnull FieldSignature signature) { } @Nonnull - public SootField withModifiers(@Nonnull Iterable modifiers) { + public SootField withModifiers(@Nonnull Iterable modifiers) { return new SootField(getSignature(), modifiers, getPosition()); } @@ -90,10 +138,10 @@ public interface SignatureStep { public interface ModifierStep { @Nonnull - BuildStep withModifier(@Nonnull Iterable modifier); + BuildStep withModifier(@Nonnull Iterable modifier); @Nonnull - default BuildStep withModifiers(@Nonnull Modifier first, @Nonnull Modifier... rest) { + default BuildStep withModifiers(@Nonnull FieldModifier first, @Nonnull FieldModifier... rest) { return withModifier(EnumSet.of(first, rest)); } } @@ -113,7 +161,7 @@ public interface BuildStep { public static class SootFieldBuilder implements SignatureStep, ModifierStep, BuildStep { private FieldSignature signature; - private Iterable modifiers; + private Iterable modifiers; private Position position = NoPositionInformation.getInstance(); @Nonnull @@ -122,7 +170,7 @@ protected FieldSignature getSignature() { } @Nonnull - protected Iterable getModifiers() { + protected Iterable getModifiers() { return modifiers; } @@ -140,7 +188,7 @@ public ModifierStep withSignature(@Nonnull FieldSignature signature) { @Override @Nonnull - public BuildStep withModifier(@Nonnull Iterable modifiers) { + public BuildStep withModifier(@Nonnull Iterable modifiers) { this.modifiers = modifiers; return this; } diff --git a/sootup.core/src/main/java/sootup/core/model/SootMethod.java b/sootup.core/src/main/java/sootup/core/model/SootMethod.java index 96c913fae81..ad2ecc7184c 100644 --- a/sootup.core/src/main/java/sootup/core/model/SootMethod.java +++ b/sootup.core/src/main/java/sootup/core/model/SootMethod.java @@ -24,6 +24,7 @@ import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; import java.io.IOException; import java.nio.file.Paths; import java.util.*; @@ -56,6 +57,7 @@ */ public class SootMethod extends SootClassMember implements Method, Copyable { + @Nonnull private final ImmutableSet modifiers; /** * An array of parameter types taken by this SootMethod object, in declaration order. */ @@ -71,13 +73,14 @@ public class SootMethod extends SootClassMember implements Meth public SootMethod( @Nonnull BodySource source, @Nonnull MethodSignature methodSignature, - @Nonnull Iterable modifiers, + @Nonnull Iterable modifiers, @Nonnull Iterable thrownExceptions, @Nonnull Position position) { - super(methodSignature, modifiers, position); + super(methodSignature, position); this.bodySource = source; this.parameterTypes = ImmutableUtils.immutableListOf(methodSignature.getParameterTypes()); + this.modifiers = ImmutableUtils.immutableEnumSetOf(modifiers); this.exceptions = ImmutableUtils.immutableListOf(thrownExceptions); } @@ -99,6 +102,46 @@ private Body lazyBodyInitializer() { } } + @Override + public boolean isProtected() { + return MethodModifier.isProtected(this.getModifiers()); + } + + @Override + public boolean isPrivate() { + return MethodModifier.isPrivate(this.getModifiers()); + } + + @Override + public boolean isPublic() { + return MethodModifier.isPublic(this.getModifiers()); + } + + @Override + public boolean isStatic() { + return MethodModifier.isStatic(this.getModifiers()); + } + + @Override + public boolean isFinal() { + return MethodModifier.isFinal(this.getModifiers()); + } + + /** + * Gets the modifiers of this class member in an immutable set. + * + * @see MethodModifier + */ + @Nonnull + public Set getModifiers() { + return modifiers; + } + + @Override + public int equivHashCode() { + return Objects.hash(modifiers, getSignature()); + } + /** Returns true if this method is not abstract or native, i.e. this method can have a body. */ public boolean isConcrete() { return !isAbstract() && !isNative(); @@ -151,17 +194,17 @@ public List getExceptionSignatures() { /** Convenience method returning true if this method is abstract. */ public boolean isAbstract() { - return Modifier.isAbstract(this.getModifiers()); + return MethodModifier.isAbstract(this.getModifiers()); } /** Convenience method returning true if this method is native. */ public boolean isNative() { - return Modifier.isNative(this.getModifiers()); + return MethodModifier.isNative(this.getModifiers()); } /** Convenience method returning true if this method is synchronized. */ public boolean isSynchronized() { - return Modifier.isSynchronized(this.getModifiers()); + return MethodModifier.isSynchronized(this.getModifiers()); } /** @return yes if this is the main method */ @@ -183,8 +226,8 @@ public boolean isBuiltInMethod() { public void toString(@Nonnull StmtPrinter printer) { // print modifiers - final Set modifiers = getModifiers(); - printer.modifier(Modifier.toString(modifiers)); + final Set modifiers = getModifiers(); + printer.modifier(MethodModifier.toString(modifiers)); if (modifiers.size() != 0) { printer.literal(" "); } @@ -228,7 +271,7 @@ public SootMethod withSource(BodySource source) { } @Nonnull - public SootMethod withModifiers(Iterable modifiers) { + public SootMethod withModifiers(Iterable modifiers) { return new SootMethod( bodySource, getSignature(), modifiers, getExceptionSignatures(), getPosition()); } @@ -271,10 +314,11 @@ public interface SignatureStep { public interface ModifierStep { @Nonnull - ThrownExceptionsStep withModifier(@Nonnull Iterable modifier); + ThrownExceptionsStep withModifier(@Nonnull Iterable modifier); @Nonnull - default ThrownExceptionsStep withModifiers(@Nonnull Modifier first, @Nonnull Modifier... rest) { + default ThrownExceptionsStep withModifiers( + @Nonnull MethodModifier first, @Nonnull MethodModifier... rest) { return withModifier(EnumSet.of(first, rest)); } } @@ -304,13 +348,13 @@ public static class SootMethodBuilder implements MethodSourceStep, SignatureStep, ModifierStep, ThrownExceptionsStep, BuildStep { @Nullable private BodySource source; - @Nonnull private Iterable modifiers = Collections.emptyList(); + @Nonnull private Iterable modifiers = Collections.emptyList(); @Nullable private MethodSignature methodSignature; @Nonnull private Iterable thrownExceptions = Collections.emptyList(); @Nonnull private Position position = NoPositionInformation.getInstance(); @Nonnull - public Iterable getModifiers() { + public Iterable getModifiers() { return modifiers; } @@ -350,7 +394,7 @@ public ModifierStep withSignature(@Nonnull MethodSignature methodSignature) { @Override @Nonnull - public ThrownExceptionsStep withModifier(@Nonnull Iterable modifiers) { + public ThrownExceptionsStep withModifier(@Nonnull Iterable modifiers) { this.modifiers = modifiers; return this; } diff --git a/sootup.core/src/main/java/sootup/core/util/printer/JimplePrinter.java b/sootup.core/src/main/java/sootup/core/util/printer/JimplePrinter.java index d35256dae7c..648df78ec11 100644 --- a/sootup.core/src/main/java/sootup/core/util/printer/JimplePrinter.java +++ b/sootup.core/src/main/java/sootup/core/util/printer/JimplePrinter.java @@ -30,9 +30,9 @@ import sootup.core.jimple.basic.Trap; import sootup.core.jimple.common.stmt.Stmt; import sootup.core.model.Body; +import sootup.core.model.ClassModifier; import sootup.core.model.Field; import sootup.core.model.Method; -import sootup.core.model.Modifier; import sootup.core.model.SootClass; import sootup.core.model.SootField; import sootup.core.model.SootMethod; @@ -136,16 +136,16 @@ public void printTo(SootClass cl, PrintWriter out) { } */ - EnumSet modifiers = EnumSet.copyOf(cl.getModifiers()); + EnumSet modifiers = EnumSet.copyOf(cl.getModifiers()); // remove unwanted modifier combinations - if (cl.isInterface() && Modifier.isAbstract(modifiers)) { - modifiers.remove(Modifier.ABSTRACT); + if (cl.isInterface() && ClassModifier.isAbstract(modifiers)) { + modifiers.remove(ClassModifier.ABSTRACT); } if (modifiers.size() != 0) { - printer.modifier(Modifier.toString(modifiers)); + printer.modifier(ClassModifier.toString(modifiers)); printer.literal(" "); } - if (!Modifier.isInterface(modifiers) && !Modifier.isAnnotation(modifiers)) { + if (!ClassModifier.isInterface(modifiers) && !ClassModifier.isAnnotation(modifiers)) { printer.literal("class "); } diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmAnnotationClassSource.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmAnnotationClassSource.java index 19072cffbaf..531e6bfa4f1 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmAnnotationClassSource.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmAnnotationClassSource.java @@ -77,7 +77,7 @@ private static Set resolveFields( Type fieldType = AsmUtil.toJimpleType(fieldNode.desc); FieldSignature fieldSignature = signatureFactory.getFieldSignature(fieldName, classSignature, fieldType); - EnumSet modifiers = AsmUtil.getModifiers(fieldNode.access); + EnumSet modifiers = AsmUtil.getFieldModifiers(fieldNode.access); // TODO: add Position info return new JavaSootField( @@ -108,7 +108,7 @@ private static Stream resolveMethods( exceptions.addAll(AsmUtil.asmIdToSignature(methodSource.exceptions)); String methodName = methodSource.name; - EnumSet modifiers = AsmUtil.getModifiers(methodSource.access); + EnumSet modifiers = AsmUtil.getMethodModifiers(methodSource.access); List sigTypes = AsmUtil.toJimpleSignatureDesc(methodSource.desc); Type retType = sigTypes.remove(sigTypes.size() - 1); @@ -173,8 +173,8 @@ public Collection resolveFields() throws ResolveException { } @Nonnull - public EnumSet resolveModifiers() { - return AsmUtil.getModifiers(classNode.access); + public EnumSet resolveModifiers() { + return AsmUtil.getClassModifiers(classNode.access); } @Nonnull diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmClassSource.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmClassSource.java index 89325eb3ffd..3eb790769ef 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmClassSource.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmClassSource.java @@ -63,7 +63,7 @@ private static Set resolveFields( Type fieldType = AsmUtil.toJimpleType(fieldNode.desc); FieldSignature fieldSignature = signatureFactory.getFieldSignature(fieldName, classSignature, fieldType); - EnumSet modifiers = AsmUtil.getModifiers(fieldNode.access); + EnumSet modifiers = AsmUtil.getFieldModifiers(fieldNode.access); // TODO: add Position info return new JavaSootField( @@ -120,7 +120,7 @@ public Collection resolveMethods() throws ResolveException new ArrayList<>(AsmUtil.asmIdToSignature(methodSource.exceptions)); String methodName = methodSource.name; - EnumSet modifiers = AsmUtil.getModifiers(methodSource.access); + EnumSet modifiers = AsmUtil.getMethodModifiers(methodSource.access); List sigTypes = AsmUtil.toJimpleSignatureDesc(methodSource.desc); Type retType = sigTypes.remove(sigTypes.size() - 1); @@ -154,8 +154,8 @@ public Collection resolveFields() throws ResolveException { } @Nonnull - public EnumSet resolveModifiers() { - return AsmUtil.getModifiers(classNode.access); + public EnumSet resolveModifiers() { + return AsmUtil.getClassModifiers(classNode.access); } @Nonnull diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java index bc968018692..d5d1af0b24a 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java @@ -182,7 +182,7 @@ StmtPositionInfo getStmtPositionInfo() { @Override @Nonnull - public Body resolveBody(@Nonnull Iterable modifierIt) { + public Body resolveBody(@Nonnull Iterable modifierIt) { /* initialize */ nextLocal = maxLocals; @@ -205,7 +205,7 @@ public Body resolveBody(@Nonnull Iterable modifierIt) { /* build body (add stmts, locals, traps, etc.) */ final MutableBlockStmtGraph graph = new MutableBlockStmtGraph(); Body.BodyBuilder bodyBuilder = Body.builder(graph); - bodyBuilder.setModifiers(AsmUtil.getModifiers(access)); + bodyBuilder.setModifiers(AsmUtil.getMethodModifiers(access)); final List preambleStmts = buildPreambleLocals(bodyBuilder); @@ -1880,7 +1880,7 @@ private List buildPreambleLocals(Body.BodyBuilder bodyBuilder) { int localIdx = 0; // create this Local if necessary ( i.e. not static ) - if (!bodyBuilder.getModifiers().contains(Modifier.STATIC)) { + if (!bodyBuilder.getModifiers().contains(MethodModifier.STATIC)) { JavaLocal thisLocal = JavaJimple.newLocal(determineLocalName(localIdx), declaringClass); locals.set(localIdx++, thisLocal); final JIdentityStmt stmt = diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmUtil.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmUtil.java index 2cee7ad96f0..ed306a13093 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmUtil.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmUtil.java @@ -42,7 +42,9 @@ import org.objectweb.asm.util.TraceMethodVisitor; import sootup.core.frontend.ResolveException; import sootup.core.jimple.common.constant.ClassConstant; -import sootup.core.model.Modifier; +import sootup.core.model.ClassModifier; +import sootup.core.model.FieldModifier; +import sootup.core.model.MethodModifier; import sootup.core.types.PrimitiveType; import sootup.core.types.Type; import sootup.core.types.VoidType; @@ -99,11 +101,35 @@ public static String toQualifiedName(@Nonnull String str) { return str.replace('/', '.'); } - public static EnumSet getModifiers(int access) { - EnumSet modifierEnumSet = EnumSet.noneOf(Modifier.class); + public static EnumSet getClassModifiers(int access) { + EnumSet modifierEnumSet = EnumSet.noneOf(ClassModifier.class); // add all modifiers for which (access & ABSTRACT) =! 0 - for (Modifier modifier : Modifier.values()) { + for (ClassModifier modifier : ClassModifier.values()) { + if ((access & modifier.getBytecode()) != 0) { + modifierEnumSet.add(modifier); + } + } + return modifierEnumSet; + } + + public static EnumSet getMethodModifiers(int access) { + EnumSet modifierEnumSet = EnumSet.noneOf(MethodModifier.class); + + // add all modifiers for which (access & ABSTRACT) =! 0 + for (MethodModifier modifier : MethodModifier.values()) { + if ((access & modifier.getBytecode()) != 0) { + modifierEnumSet.add(modifier); + } + } + return modifierEnumSet; + } + + public static EnumSet getFieldModifiers(int access) { + EnumSet modifierEnumSet = EnumSet.noneOf(FieldModifier.class); + + // add all modifiers for which (access & ABSTRACT) =! 0 + for (FieldModifier modifier : FieldModifier.values()) { if ((access & modifier.getBytecode()) != 0) { modifierEnumSet.add(modifier); } diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/DeadAssignmentEliminator.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/DeadAssignmentEliminator.java index 6365525a6f5..4dc6a6a51b1 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/DeadAssignmentEliminator.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/DeadAssignmentEliminator.java @@ -36,7 +36,7 @@ import sootup.core.jimple.common.stmt.JAssignStmt; import sootup.core.jimple.common.stmt.Stmt; import sootup.core.model.Body; -import sootup.core.model.Modifier; +import sootup.core.model.MethodModifier; import sootup.core.transform.BodyInterceptor; import sootup.core.types.*; import sootup.core.views.View; @@ -73,7 +73,7 @@ public void interceptBody(@Nonnull Body.BodyBuilder builder, @Nonnull View vi // Make a first pass through the statements, noting the statements we must absolutely keep - boolean isStatic = Modifier.isStatic(builder.getModifiers()); + boolean isStatic = MethodModifier.isStatic(builder.getModifiers()); boolean allEssential = true; boolean containsInvoke = false; Local thisLocal = null; diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java index 847bf5daf87..29509f4f71c 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java @@ -336,9 +336,7 @@ public void testClassInWar() { assertTrue( foundMethod.getParameterTypes().stream() .anyMatch( - type -> { - return "int".equals(type.toString()); - })); + type -> "int".equals(type.toString()))); // Parse sub-signature for "empName" field FieldSubSignature nameFieldSubSignature = @@ -362,7 +360,7 @@ public void testClassInWar() { .withSignature( JavaIdentifierFactory.getInstance() .getFieldSignature(classSignature, nameFieldSubSignature)) - .withModifiers(Modifier.PUBLIC) + .withModifiers(FieldModifier.PUBLIC) .build()), ImmutableUtils.immutableSet( SootMethod.builder() @@ -370,7 +368,7 @@ public void testClassInWar() { new BodySource() { @Nonnull @Override - public Body resolveBody(@Nonnull Iterable modifiers) { + public Body resolveBody(@Nonnull Iterable modifiers) { /* [ms] violating @Nonnull */ return null; } @@ -392,10 +390,10 @@ public MethodSignature getSignature() { JavaIdentifierFactory.getInstance() .getMethodSignature( classSignature, optionalToStreamMethodSubSignature)) - .withModifiers(Modifier.PUBLIC) + .withModifiers(MethodModifier.PUBLIC) .build()), null, - EnumSet.of(Modifier.PUBLIC), + EnumSet.of(ClassModifier.PUBLIC), Collections.emptyList(), Collections.emptyList(), Collections.emptyList()), diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java6/AnnotationLibraryTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java6/AnnotationLibraryTest.java index a14e24c609b..4974747ea71 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java6/AnnotationLibraryTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java6/AnnotationLibraryTest.java @@ -7,7 +7,7 @@ import java.io.StringWriter; import org.junit.Test; import org.junit.experimental.categories.Category; -import sootup.core.model.Modifier; +import sootup.core.model.ClassModifier; import sootup.core.model.SootClass; import sootup.core.util.printer.JimplePrinter; import sootup.java.bytecode.minimaltestsuite.MinimalBytecodeTestSuiteBase; @@ -24,7 +24,7 @@ public void testAnnotationDeclaration() { JimplePrinter p = new JimplePrinter(JimplePrinter.Option.LegacyMode); StringWriter out = new StringWriter(); p.printTo(sootClass, new PrintWriter(out)); - assertTrue(Modifier.isAnnotation(sootClass.getModifiers())); + assertTrue(ClassModifier.isAnnotation(sootClass.getModifiers())); } // TODO: [ms] add test for more annotation declarations e.g. inheritance diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java6/DeclareFieldTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java6/DeclareFieldTest.java index 3c545006db3..3659403399c 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java6/DeclareFieldTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java6/DeclareFieldTest.java @@ -9,7 +9,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import org.junit.experimental.categories.Category; -import sootup.core.model.Modifier; +import sootup.core.model.FieldModifier; import sootup.core.model.SootClass; import sootup.core.model.SootMethod; import sootup.core.signatures.MethodSignature; @@ -42,19 +42,15 @@ public void test() { assertTrue( clazz.getFields().stream() .anyMatch( - sootField -> { - return sootField.getModifiers().contains(Modifier.PRIVATE) - && sootField.getModifiers().contains(Modifier.STATIC) - && sootField.getName().equals("i"); - })); + sootField -> sootField.getModifiers().contains(FieldModifier.PRIVATE) + && sootField.getModifiers().contains(FieldModifier.STATIC) + && sootField.getName().equals("i"))); assertTrue( clazz.getFields().stream() .anyMatch( - sootField -> { - return sootField.getModifiers().contains(Modifier.PUBLIC) - && sootField.getModifiers().contains(Modifier.FINAL) - && sootField.getName().equals("s"); - })); + sootField -> sootField.getModifiers().contains(FieldModifier.PUBLIC) + && sootField.getModifiers().contains(FieldModifier.FINAL) + && sootField.getName().equals("s"))); } /** diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java6/PublicClassTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java6/PublicClassTest.java index 58180606e7e..0d8b45a6061 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java6/PublicClassTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java6/PublicClassTest.java @@ -11,7 +11,7 @@ import java.util.stream.Stream; import org.junit.Test; import org.junit.experimental.categories.Category; -import sootup.core.model.Modifier; +import sootup.core.model.ClassModifier; import sootup.core.model.SootClass; import sootup.core.model.SootMethod; import sootup.core.signatures.MethodSignature; @@ -24,7 +24,7 @@ public class PublicClassTest extends MinimalBytecodeTestSuiteBase { @Test public void test() { SootClass clazz = loadClass(getDeclaredClassSignature()); - assertEquals(EnumSet.of(Modifier.PUBLIC, Modifier.SYNCHRONIZED), clazz.getModifiers()); + assertEquals(EnumSet.of(ClassModifier.PUBLIC, ClassModifier.SUPER), clazz.getModifiers()); SootMethod method; method = clazz.getMethod(getMethodSignature("private").getSubSignature()).get(); diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java6/TransientVariableTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java6/TransientVariableTest.java index bdaeffed513..051a20073cb 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java6/TransientVariableTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java6/TransientVariableTest.java @@ -10,7 +10,7 @@ import java.util.stream.Stream; import org.junit.Test; import org.junit.experimental.categories.Category; -import sootup.core.model.Modifier; +import sootup.core.model.FieldModifier; import sootup.core.model.SootClass; import sootup.core.model.SootMethod; import sootup.core.signatures.MethodSignature; @@ -34,7 +34,7 @@ public void test() { .anyMatch( sootField -> sootField.getName().equals("transientVar") - && sootField.getModifiers().contains(Modifier.TRANSIENT))); + && sootField.getModifiers().contains(FieldModifier.TRANSIENT))); } /** diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java6/VolatileVariableTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java6/VolatileVariableTest.java index 3d23c989cfe..a637391d973 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java6/VolatileVariableTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java6/VolatileVariableTest.java @@ -10,7 +10,7 @@ import java.util.stream.Stream; import org.junit.Test; import org.junit.experimental.categories.Category; -import sootup.core.model.Modifier; +import sootup.core.model.FieldModifier; import sootup.core.model.SootClass; import sootup.core.model.SootMethod; import sootup.core.signatures.MethodSignature; @@ -32,10 +32,8 @@ public void test() { assertTrue( clazz.getFields().stream() .anyMatch( - sootField -> { - return sootField.getName().equals("counter") - && sootField.getModifiers().contains(Modifier.VOLATILE); - })); + sootField -> sootField.getName().equals("counter") + && sootField.getModifiers().contains(FieldModifier.VOLATILE))); } /** diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java8/RepeatingAnnotationsTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java8/RepeatingAnnotationsTest.java index 71e5b492199..f3e0208d556 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java8/RepeatingAnnotationsTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java8/RepeatingAnnotationsTest.java @@ -10,7 +10,7 @@ import java.util.stream.Stream; import org.junit.Ignore; import org.junit.experimental.categories.Category; -import sootup.core.model.Modifier; +import sootup.core.model.ClassModifier; import sootup.core.model.SootClass; import sootup.core.model.SootMethod; import sootup.core.signatures.MethodSignature; @@ -32,7 +32,7 @@ public void annotationTest() { SootMethod method = loadMethod(getMethodSignature()); assertJimpleStmts(method, expectedBodyStmts()); SootClass sootClass = loadClass(getDeclaredClassSignature()); - assertTrue(Modifier.isAnnotation(sootClass.getModifiers())); + assertTrue(ClassModifier.isAnnotation(sootClass.getModifiers())); } @Override diff --git a/sootup.java.core/src/main/java/sootup/java/core/JavaAnnotationSootMethod.java b/sootup.java.core/src/main/java/sootup/java/core/JavaAnnotationSootMethod.java index 495af3b11bc..81227e5c845 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/JavaAnnotationSootMethod.java +++ b/sootup.java.core/src/main/java/sootup/java/core/JavaAnnotationSootMethod.java @@ -3,7 +3,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import sootup.core.frontend.BodySource; -import sootup.core.model.Modifier; +import sootup.core.model.MethodModifier; import sootup.core.model.Position; import sootup.core.signatures.MethodSignature; import sootup.core.types.ClassType; @@ -13,7 +13,7 @@ public class JavaAnnotationSootMethod extends JavaSootMethod { public JavaAnnotationSootMethod( @Nonnull BodySource source, @Nonnull MethodSignature methodSignature, - @Nonnull Iterable modifiers, + @Nonnull Iterable modifiers, @Nonnull Iterable thrownExceptions, @Nonnull Iterable annotations, @Nonnull Position position) { diff --git a/sootup.java.core/src/main/java/sootup/java/core/JavaSootClass.java b/sootup.java.core/src/main/java/sootup/java/core/JavaSootClass.java index b5494274e71..1d30b1c0342 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/JavaSootClass.java +++ b/sootup.java.core/src/main/java/sootup/java/core/JavaSootClass.java @@ -184,7 +184,7 @@ public JavaSootClass withFields(@Nonnull Collection fields) { } @Nonnull - public JavaSootClass withModifiers(@Nonnull Set modifiers) { + public JavaSootClass withModifiers(@Nonnull Set modifiers) { return new JavaSootClass( new OverridingJavaClassSource(getClassSource()).withModifiers(modifiers), sourceType); } diff --git a/sootup.java.core/src/main/java/sootup/java/core/JavaSootField.java b/sootup.java.core/src/main/java/sootup/java/core/JavaSootField.java index 921c07f214b..e5c82cf7d52 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/JavaSootField.java +++ b/sootup.java.core/src/main/java/sootup/java/core/JavaSootField.java @@ -25,7 +25,7 @@ import java.util.Collections; import java.util.Optional; import javax.annotation.Nonnull; -import sootup.core.model.Modifier; +import sootup.core.model.FieldModifier; import sootup.core.model.Position; import sootup.core.model.SootField; import sootup.core.signatures.FieldSignature; @@ -38,14 +38,14 @@ public class JavaSootField extends SootField { /** * Constructs a Soot field with the given name, type and modifiers. * - * @param signature - * @param modifiers - * @param annotations - * @param position + * @param signature the signature of the field + * @param modifiers modifier of the field + * @param annotations annotations of the field + * @param position position of the field */ public JavaSootField( @Nonnull FieldSignature signature, - @Nonnull Iterable modifiers, + @Nonnull Iterable modifiers, @Nonnull Iterable annotations, Position position) { super(signature, modifiers, position); diff --git a/sootup.java.core/src/main/java/sootup/java/core/JavaSootMethod.java b/sootup.java.core/src/main/java/sootup/java/core/JavaSootMethod.java index 76fac7127ba..91adf47e72b 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/JavaSootMethod.java +++ b/sootup.java.core/src/main/java/sootup/java/core/JavaSootMethod.java @@ -30,7 +30,7 @@ import sootup.core.frontend.BodySource; import sootup.core.frontend.OverridingBodySource; import sootup.core.model.Body; -import sootup.core.model.Modifier; +import sootup.core.model.MethodModifier; import sootup.core.model.Position; import sootup.core.model.SootMethod; import sootup.core.signatures.MethodSignature; @@ -45,7 +45,7 @@ public class JavaSootMethod extends SootMethod { public JavaSootMethod( @Nonnull BodySource source, @Nonnull MethodSignature methodSignature, - @Nonnull Iterable modifiers, + @Nonnull Iterable modifiers, @Nonnull Iterable thrownExceptions, @Nonnull Iterable annotations, @Nonnull Position position) { @@ -116,7 +116,7 @@ public JavaSootMethod withSource(@Nonnull BodySource source) { @Nonnull @Override - public JavaSootMethod withModifiers(@Nonnull Iterable modifiers) { + public JavaSootMethod withModifiers(@Nonnull Iterable modifiers) { return new JavaSootMethod( bodySource, getSignature(), diff --git a/sootup.java.core/src/main/java/sootup/java/core/OverridingJavaClassSource.java b/sootup.java.core/src/main/java/sootup/java/core/OverridingJavaClassSource.java index b4d166662ae..3b500a0664d 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/OverridingJavaClassSource.java +++ b/sootup.java.core/src/main/java/sootup/java/core/OverridingJavaClassSource.java @@ -29,7 +29,7 @@ import sootup.core.frontend.ResolveException; import sootup.core.frontend.SootClassSource; import sootup.core.inputlocation.AnalysisInputLocation; -import sootup.core.model.Modifier; +import sootup.core.model.ClassModifier; import sootup.core.model.Position; import sootup.core.model.SootField; import sootup.core.model.SootMethod; @@ -55,7 +55,7 @@ public class OverridingJavaClassSource extends JavaSootClassSource { @Nullable private final Collection overriddenSootMethods; @Nullable private final Collection overriddenSootFields; - @Nullable private final Set overriddenModifiers; + @Nullable private final Set overriddenModifiers; @Nullable private final Set overriddenInterfaces; @Nullable private final Optional overriddenSuperclass; @Nullable private final Optional overriddenOuterClass; @@ -84,7 +84,7 @@ public OverridingJavaClassSource(@Nonnull JavaSootClassSource delegate) { private OverridingJavaClassSource( @Nullable Collection overriddenSootMethods, @Nullable Collection overriddenSootFields, - @Nullable Set overriddenModifiers, + @Nullable Set overriddenModifiers, @Nullable Set overriddenInterfaces, @Nullable Optional overriddenSuperclass, @Nullable Optional overriddenOuterClass, @@ -118,7 +118,7 @@ public OverridingJavaClassSource( @Nonnull Set sootFields, @Nonnull Set sootMethods, @Nonnull Position position, - @Nonnull EnumSet modifiers, + @Nonnull EnumSet modifiers, @Nonnull Iterable annotations, @Nonnull Iterable methodAnnotations, @Nullable Iterable fieldAnnotations) { @@ -151,7 +151,7 @@ public Collection resolveFields() throws ResolveException { @Nonnull @Override - public Set resolveModifiers() { + public Set resolveModifiers() { return overriddenModifiers != null ? overriddenModifiers : delegate.resolveModifiers(); } @@ -293,7 +293,7 @@ public OverridingJavaClassSource withFields(@Nonnull Collection overr } @Nonnull - public OverridingJavaClassSource withModifiers(@Nonnull Set overriddenModifiers) { + public OverridingJavaClassSource withModifiers(@Nonnull Set overriddenModifiers) { return new OverridingJavaClassSource( overriddenSootMethods, overriddenSootFields, diff --git a/sootup.java.core/src/test/java/sootup/java/core/jimple/common/ref/JFieldRefTest.java b/sootup.java.core/src/test/java/sootup/java/core/jimple/common/ref/JFieldRefTest.java index 901dd575321..fdf3e1bf6fe 100644 --- a/sootup.java.core/src/test/java/sootup/java/core/jimple/common/ref/JFieldRefTest.java +++ b/sootup.java.core/src/test/java/sootup/java/core/jimple/common/ref/JFieldRefTest.java @@ -17,7 +17,8 @@ import sootup.core.jimple.basic.NoPositionInformation; import sootup.core.jimple.common.ref.JInstanceFieldRef; import sootup.core.jimple.common.ref.JStaticFieldRef; -import sootup.core.model.Modifier; +import sootup.core.model.ClassModifier; +import sootup.core.model.FieldModifier; import sootup.core.model.SootField; import sootup.core.model.SourceType; import sootup.core.signatures.FieldSignature; @@ -49,7 +50,8 @@ public void testJStaticFieldRef() { JavaIdentifierFactory.getInstance().getClassType("dummyMainClass"); FieldSignature fieldSig = fact.getFieldSignature("dummyField", declaringClassSignature, "int"); SootField field = - new SootField(fieldSig, EnumSet.of(Modifier.FINAL), NoPositionInformation.getInstance()); + new SootField( + fieldSig, EnumSet.of(FieldModifier.FINAL), NoPositionInformation.getInstance()); JavaSootClass mainClass = new JavaSootClass( @@ -63,7 +65,7 @@ public void testJStaticFieldRef() { Collections.singleton(field), Collections.emptySet(), null, - EnumSet.of(Modifier.PUBLIC), + EnumSet.of(ClassModifier.PUBLIC), Collections.emptyList(), Collections.emptyList(), Collections.emptyList()), @@ -75,7 +77,7 @@ public void testJStaticFieldRef() { final Optional field1 = view.getField(ref.getFieldSignature()); assertTrue(field1.isPresent()); assertEquals(field, field1.get()); - assertEquals(EnumSet.of(Modifier.FINAL), field1.get().getModifiers()); + assertEquals(EnumSet.of(FieldModifier.FINAL), field1.get().getModifiers()); } @Ignore @@ -85,7 +87,8 @@ public void testJInstanceFieldRef() { JavaIdentifierFactory.getInstance().getClassType("dummyMainClass"); FieldSignature fieldSig = fact.getFieldSignature("dummyField", declaringClassSignature, "int"); SootField field = - new SootField(fieldSig, EnumSet.of(Modifier.FINAL), NoPositionInformation.getInstance()); + new SootField( + fieldSig, EnumSet.of(FieldModifier.FINAL), NoPositionInformation.getInstance()); JavaSootClass mainClass = new JavaSootClass( @@ -99,7 +102,7 @@ public void testJInstanceFieldRef() { Collections.singleton(field), Collections.emptySet(), null, - EnumSet.of(Modifier.PUBLIC), + EnumSet.of(ClassModifier.PUBLIC), Collections.emptyList(), Collections.emptyList(), Collections.emptyList()), @@ -112,6 +115,6 @@ public void testJInstanceFieldRef() { final Optional field1 = view.getField(ref.getFieldSignature()); assertTrue(field1.isPresent()); assertEquals(fieldSig, field1.get().getSignature()); - assertEquals(EnumSet.of(Modifier.FINAL), field1.get().getModifiers()); + assertEquals(EnumSet.of(FieldModifier.FINAL), field1.get().getModifiers()); } } diff --git a/sootup.java.core/src/test/java/sootup/java/core/jimple/common/stmt/JInvokeStmtTest.java b/sootup.java.core/src/test/java/sootup/java/core/jimple/common/stmt/JInvokeStmtTest.java index 93ee919c973..dba62305329 100644 --- a/sootup.java.core/src/test/java/sootup/java/core/jimple/common/stmt/JInvokeStmtTest.java +++ b/sootup.java.core/src/test/java/sootup/java/core/jimple/common/stmt/JInvokeStmtTest.java @@ -47,7 +47,7 @@ import sootup.core.jimple.common.stmt.JInvokeStmt; import sootup.core.jimple.common.stmt.JNopStmt; import sootup.core.jimple.common.stmt.Stmt; -import sootup.core.model.Modifier; +import sootup.core.model.ClassModifier; import sootup.core.model.SootClass; import sootup.core.model.SootField; import sootup.core.model.SootMethod; @@ -83,7 +83,7 @@ public void test() { fields, methods, NoPositionInformation.getInstance(), - EnumSet.of(Modifier.PUBLIC), + EnumSet.of(ClassModifier.PUBLIC), Collections.emptyList(), Collections.emptyList(), Collections.emptyList()); diff --git a/sootup.java.core/src/test/java/sootup/java/core/model/SootMethodTest.java b/sootup.java.core/src/test/java/sootup/java/core/model/SootMethodTest.java index c5471e1f0a1..3d031009c1b 100644 --- a/sootup.java.core/src/test/java/sootup/java/core/model/SootMethodTest.java +++ b/sootup.java.core/src/test/java/sootup/java/core/model/SootMethodTest.java @@ -19,7 +19,8 @@ import sootup.core.jimple.common.stmt.JIdentityStmt; import sootup.core.jimple.common.stmt.JReturnVoidStmt; import sootup.core.model.Body; -import sootup.core.model.Modifier; +import sootup.core.model.ClassModifier; +import sootup.core.model.MethodModifier; import sootup.core.model.SourceType; import sootup.core.signatures.MethodSignature; import sootup.core.types.ClassType; @@ -73,7 +74,7 @@ public void testCreateMethod() { new JavaSootMethod( new OverridingBodySource(methodSignature, body), methodSignature, - EnumSet.of(Modifier.PUBLIC, Modifier.STATIC), + EnumSet.of(MethodModifier.PUBLIC, MethodModifier.STATIC), Collections.emptyList(), Collections.emptyList(), NoPositionInformation.getInstance()); @@ -90,7 +91,7 @@ public void testCreateMethod() { Collections.emptySet(), Collections.singleton(dummyMainMethod), NoPositionInformation.getInstance(), - EnumSet.of(Modifier.PUBLIC), + EnumSet.of(ClassModifier.PUBLIC), Collections.emptyList(), Collections.emptyList(), Collections.emptyList()), diff --git a/sootup.java.core/src/test/java/sootup/java/core/printer/JimplePrinterTest.java b/sootup.java.core/src/test/java/sootup/java/core/printer/JimplePrinterTest.java index d8e454d1d5f..6938330d8eb 100644 --- a/sootup.java.core/src/test/java/sootup/java/core/printer/JimplePrinterTest.java +++ b/sootup.java.core/src/test/java/sootup/java/core/printer/JimplePrinterTest.java @@ -81,7 +81,7 @@ private SootClass buildClass() { new SootMethod( new OverridingBodySource(methodSignatureOne, bodyOne), methodSignatureOne, - EnumSet.of(Modifier.PUBLIC, Modifier.STATIC), + EnumSet.of(MethodModifier.PUBLIC, MethodModifier.STATIC), Collections.emptyList(), NoPositionInformation.getInstance()); @@ -97,7 +97,7 @@ private SootClass buildClass() { new SootMethod( new OverridingBodySource(methodSignatureOne, bodyTwo), methodSignatureTwo, - EnumSet.of(Modifier.PRIVATE), + EnumSet.of(MethodModifier.PRIVATE), Collections.singletonList( JavaIdentifierFactory.getInstance() .getClassType("files.stuff.FileNotFoundException")), @@ -113,9 +113,9 @@ private SootClass buildClass() { "counter", JavaIdentifierFactory.getInstance().getClassType(className), PrimitiveType.getInt()), - EnumSet.of(Modifier.PRIVATE), + EnumSet.of(FieldModifier.PRIVATE), NoPositionInformation.getInstance())), - EnumSet.of(Modifier.PUBLIC), + EnumSet.of(ClassModifier.PUBLIC), Collections.singleton( JavaIdentifierFactory.getInstance().getClassType("some.great.Interface")), JavaIdentifierFactory.getInstance().getClassType("some.great.Superclass"), diff --git a/sootup.java.core/src/test/java/sootup/java/core/printer/LegacyJimplePrinterTest.java b/sootup.java.core/src/test/java/sootup/java/core/printer/LegacyJimplePrinterTest.java index 439b4b9a04b..d3c8c45bc76 100644 --- a/sootup.java.core/src/test/java/sootup/java/core/printer/LegacyJimplePrinterTest.java +++ b/sootup.java.core/src/test/java/sootup/java/core/printer/LegacyJimplePrinterTest.java @@ -49,7 +49,7 @@ SootClass buildClass(Body.BodyBuilder builder) { new SootMethod( new OverridingBodySource(methodSignature, body), methodSignature, - EnumSet.of(Modifier.PUBLIC, Modifier.STATIC), + EnumSet.of(MethodModifier.PUBLIC, MethodModifier.STATIC), Collections.emptyList(), NoPositionInformation.getInstance()); @@ -57,7 +57,7 @@ SootClass buildClass(Body.BodyBuilder builder) { new OverridingClassSource( Collections.singleton(dummyMainMethod), Collections.emptySet(), - EnumSet.of(Modifier.PUBLIC), + EnumSet.of(ClassModifier.PUBLIC), Collections.emptySet(), null, null, diff --git a/sootup.java.sourcecode/src/main/java/sootup/java/sourcecode/frontend/InstructionConverter.java b/sootup.java.sourcecode/src/main/java/sootup/java/sourcecode/frontend/InstructionConverter.java index 409590d8545..37606aac35d 100644 --- a/sootup.java.sourcecode/src/main/java/sootup/java/sourcecode/frontend/InstructionConverter.java +++ b/sootup.java.sourcecode/src/main/java/sootup/java/sourcecode/frontend/InstructionConverter.java @@ -76,7 +76,7 @@ import sootup.core.jimple.common.ref.JStaticFieldRef; import sootup.core.jimple.common.stmt.*; import sootup.core.jimple.javabytecode.stmt.JSwitchStmt; -import sootup.core.model.Modifier; +import sootup.core.model.FieldModifier; import sootup.core.model.SootField; import sootup.core.signatures.FieldSignature; import sootup.core.signatures.MethodSignature; @@ -317,7 +317,7 @@ private List convertAssertInstruction( SootField assertionsDisabled = new SootField( fieldSig, - EnumSet.of(Modifier.FINAL, Modifier.STATIC), + EnumSet.of(FieldModifier.FINAL, FieldModifier.STATIC), NoPositionInformation.getInstance()); converter.addSootField(assertionsDisabled); @@ -422,7 +422,7 @@ private List convertAstLexicalWrite(AstLexicalWrite inst) { "val$" + access.variableName, cSig, type.toString()); SootField field = new SootField( - fieldSig, EnumSet.of(Modifier.FINAL), NoPositionInformation.getInstance()); + fieldSig, EnumSet.of(FieldModifier.FINAL), NoPositionInformation.getInstance()); left = Jimple.newInstanceFieldRef(localGenerator.getThisLocal(), fieldSig); converter.addSootField(field); // add this field to class // TODO in old jimple this is not supported @@ -455,7 +455,7 @@ private List convertAstLexicalRead(AstLexicalRead inst) { "val$" + access.variableName, cSig, type.toString()); SootField field = new SootField( - fieldSig, EnumSet.of(Modifier.FINAL), NoPositionInformation.getInstance()); + fieldSig, EnumSet.of(FieldModifier.FINAL), NoPositionInformation.getInstance()); rvalue = Jimple.newInstanceFieldRef(localGenerator.getThisLocal(), fieldSig); converter.addSootField(field); // add this field to class } else { diff --git a/sootup.java.sourcecode/src/main/java/sootup/java/sourcecode/frontend/WalaIRToJimpleConverter.java b/sootup.java.sourcecode/src/main/java/sootup/java/sourcecode/frontend/WalaIRToJimpleConverter.java index 8d8f7071617..4094732a53d 100644 --- a/sootup.java.sourcecode/src/main/java/sootup/java/sourcecode/frontend/WalaIRToJimpleConverter.java +++ b/sootup.java.sourcecode/src/main/java/sootup/java/sourcecode/frontend/WalaIRToJimpleConverter.java @@ -143,7 +143,7 @@ JavaSootClassSource convertToClassSource(AstClass walaClass) { Position position = walaClass.getSourcePosition(); // convert modifiers - EnumSet modifiers = convertModifiers(walaClass); + EnumSet modifiers = convertModifiers(walaClass); // convert fields Set fields = HashSetFactory.make(walaClass.getDeclaredInstanceFields()); @@ -159,7 +159,8 @@ JavaSootClassSource convertToClassSource(AstClass walaClass) { FieldSignature signature = identifierFactory.getFieldSignature("this$0", classSig, outerClass); SootField enclosingObject = - new SootField(signature, EnumSet.of(Modifier.FINAL), NoPositionInformation.getInstance()); + new SootField( + signature, EnumSet.of(FieldModifier.FINAL), NoPositionInformation.getInstance()); sootFields.add(enclosingObject); } @@ -193,7 +194,7 @@ public OverridingJavaClassSource createClassSource( Set sootFields, Set sootMethods, Position position, - EnumSet modifiers, + EnumSet modifiers, Iterable annotations) { String fullyQualifiedClassName = convertClassNameFromWala(walaClass.getName().toString()); JavaClassType classSignature = identifierFactory.getClassType(fullyQualifiedClassName); @@ -224,7 +225,7 @@ public OverridingJavaClassSource createClassSource( */ public SootField convertField(JavaClassType classSig, AstField walaField) { Type type = convertType(walaField.getFieldTypeReference()); - EnumSet modifiers = convertModifiers(walaField); + EnumSet modifiers = convertModifiers(walaField); FieldSignature signature = identifierFactory.getFieldSignature(walaField.getName().toString(), classSig, type); return new SootField(signature, modifiers, NoPositionInformation.getInstance()); @@ -252,7 +253,7 @@ public SootMethod convertMethod(JavaClassType classSig, AstMethod walaMethod) { Type returnType = convertType(walaMethod.getReturnType()); - EnumSet modifiers = convertModifiers(walaMethod); + EnumSet modifiers = convertModifiers(walaMethod); List thrownExceptions = new ArrayList<>(); try { @@ -319,96 +320,96 @@ public Type convertType(TypeReference type) { } /** Return all modifiers for the given field. */ - public EnumSet convertModifiers(AstField field) { - EnumSet modifiers = EnumSet.noneOf(Modifier.class); + public EnumSet convertModifiers(AstField field) { + EnumSet modifiers = EnumSet.noneOf(FieldModifier.class); if (field.isFinal()) { - modifiers.add(Modifier.FINAL); + modifiers.add(FieldModifier.FINAL); } if (field.isPrivate()) { - modifiers.add(Modifier.PRIVATE); + modifiers.add(FieldModifier.PRIVATE); } if (field.isProtected()) { - modifiers.add(Modifier.PROTECTED); + modifiers.add(FieldModifier.PROTECTED); } if (field.isPublic()) { - modifiers.add(Modifier.PUBLIC); + modifiers.add(FieldModifier.PUBLIC); } if (field.isStatic()) { - modifiers.add(Modifier.STATIC); + modifiers.add(FieldModifier.STATIC); } if (field.isVolatile()) { - modifiers.add(Modifier.VOLATILE); + modifiers.add(FieldModifier.VOLATILE); } // TODO: TRANSIENT field return modifiers; } /** Return all modifiers for the given method. */ - public EnumSet convertModifiers(AstMethod method) { - EnumSet modifiers = EnumSet.noneOf(Modifier.class); + public EnumSet convertModifiers(AstMethod method) { + EnumSet modifiers = EnumSet.noneOf(MethodModifier.class); if (method.isPrivate()) { - modifiers.add(Modifier.PRIVATE); + modifiers.add(MethodModifier.PRIVATE); } if (method.isProtected()) { - modifiers.add(Modifier.PROTECTED); + modifiers.add(MethodModifier.PROTECTED); } if (method.isPublic()) { - modifiers.add(Modifier.PUBLIC); + modifiers.add(MethodModifier.PUBLIC); } if (method.isStatic()) { - modifiers.add(Modifier.STATIC); + modifiers.add(MethodModifier.STATIC); } if (method.isFinal()) { - modifiers.add(Modifier.FINAL); + modifiers.add(MethodModifier.FINAL); } if (method.isAbstract()) { - modifiers.add(Modifier.ABSTRACT); + modifiers.add(MethodModifier.ABSTRACT); } if (method.isSynchronized()) { - modifiers.add(Modifier.SYNCHRONIZED); + modifiers.add(MethodModifier.SYNCHRONIZED); } if (method.isNative()) { - modifiers.add(Modifier.NATIVE); + modifiers.add(MethodModifier.NATIVE); } if (method.isSynthetic()) { - modifiers.add(Modifier.SYNTHETIC); + modifiers.add(MethodModifier.SYNTHETIC); } if (method.isBridge()) { - modifiers.add(Modifier.VOLATILE); + modifiers.add(MethodModifier.BRIDGE); } - // TODO: strictfp and annotation + // TODO: strictfp and annotation and varargs return modifiers; } - public EnumSet convertModifiers(AstClass klass) { + public EnumSet convertModifiers(AstClass klass) { int modif = klass.getModifiers(); - EnumSet modifiers = EnumSet.noneOf(Modifier.class); + EnumSet modifiers = EnumSet.noneOf(ClassModifier.class); if (klass.isAbstract()) { - modifiers.add(Modifier.ABSTRACT); + modifiers.add(ClassModifier.ABSTRACT); } if (klass.isPrivate()) { - modifiers.add(Modifier.PRIVATE); + modifiers.add(ClassModifier.PRIVATE); } if (klass.isSynthetic()) { - modifiers.add(Modifier.SYNTHETIC); + modifiers.add(ClassModifier.SYNTHETIC); } if (klass.isPublic()) { - modifiers.add(Modifier.PUBLIC); + modifiers.add(ClassModifier.PUBLIC); } if (klass.isInterface()) { - modifiers.add(Modifier.INTERFACE); + modifiers.add(ClassModifier.INTERFACE); } if (klass.getSuperclass().getName().toString().equals("Ljava/lang/Enum")) { - modifiers.add(Modifier.ENUM); + modifiers.add(ClassModifier.ENUM); } - if ((modif & ClassConstants.ACC_FINAL) != 0) modifiers.add(Modifier.FINAL); + if ((modif & ClassConstants.ACC_FINAL) != 0) modifiers.add(ClassModifier.FINAL); // TODO: annotation return modifiers; } @Nonnull private Body createBody( - MethodSignature methodSignature, EnumSet modifiers, AstMethod walaMethod) { + MethodSignature methodSignature, EnumSet modifiers, AstMethod walaMethod) { if (walaMethod.isAbstract()) { return Body.builder().setMethodSignature(methodSignature).build(); @@ -430,7 +431,7 @@ private Body createBody( /* Look AsmMethodSourceContent.getBody, see AsmMethodSourceContent.emitLocals(); */ - if (!Modifier.isStatic(modifiers)) { + if (!MethodModifier.isStatic(modifiers)) { JavaClassType thisType = (JavaClassType) methodSignature.getDeclClassType(); Local thisLocal = localGenerator.generateThisLocal(thisType); Stmt stmt = diff --git a/sootup.java.sourcecode/src/main/java/sootup/java/sourcecode/frontend/WalaSootMethod.java b/sootup.java.sourcecode/src/main/java/sootup/java/sourcecode/frontend/WalaSootMethod.java index 9281fa3855e..4f08038dcfa 100644 --- a/sootup.java.sourcecode/src/main/java/sootup/java/sourcecode/frontend/WalaSootMethod.java +++ b/sootup.java.sourcecode/src/main/java/sootup/java/sourcecode/frontend/WalaSootMethod.java @@ -28,7 +28,7 @@ import sootup.core.frontend.BodySource; import sootup.core.frontend.OverridingBodySource; import sootup.core.jimple.basic.NoPositionInformation; -import sootup.core.model.Modifier; +import sootup.core.model.MethodModifier; import sootup.core.model.SootMethod; import sootup.core.signatures.MethodSignature; import sootup.core.types.ClassType; @@ -51,7 +51,7 @@ public class WalaSootMethod extends JavaSootMethod { public WalaSootMethod( @Nonnull BodySource source, @Nonnull MethodSignature methodSignature, - @Nonnull Iterable modifiers, + @Nonnull Iterable modifiers, @Nonnull Iterable thrownExceptions, DebuggingInformation debugInfo) { @@ -92,7 +92,7 @@ public JavaSootMethod withSource(BodySource source) { } @Nonnull - public JavaSootMethod withModifiers(Iterable modifiers) { + public JavaSootMethod withModifiers(Iterable modifiers) { return new WalaSootMethod(bodySource, getSignature(), getModifiers(), exceptions, debugInfo); } diff --git a/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/minimaltestsuite/java6/AnnotationLibraryTest.java b/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/minimaltestsuite/java6/AnnotationLibraryTest.java index 02b033fb26c..4ef40eb9e5f 100644 --- a/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/minimaltestsuite/java6/AnnotationLibraryTest.java +++ b/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/minimaltestsuite/java6/AnnotationLibraryTest.java @@ -3,7 +3,7 @@ import static org.junit.Assert.assertTrue; import org.junit.Ignore; -import sootup.core.model.Modifier; +import sootup.core.model.ClassModifier; import sootup.core.model.SootClass; import sootup.java.sourcecode.minimaltestsuite.MinimalSourceTestSuiteBase; @@ -14,6 +14,6 @@ public void testAnnotation() { // TODO: [ms] annotations are not implemented yet System.out.println(getDeclaredClassSignature()); SootClass sootClass = loadClass(getDeclaredClassSignature()); - assertTrue(Modifier.isAnnotation(sootClass.getModifiers())); + assertTrue(ClassModifier.isAnnotation(sootClass.getModifiers())); } } diff --git a/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/minimaltestsuite/java6/DeclareFieldTest.java b/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/minimaltestsuite/java6/DeclareFieldTest.java index bc84d6a14f4..6ba1f45ba05 100644 --- a/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/minimaltestsuite/java6/DeclareFieldTest.java +++ b/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/minimaltestsuite/java6/DeclareFieldTest.java @@ -7,7 +7,7 @@ import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; -import sootup.core.model.Modifier; +import sootup.core.model.FieldModifier; import sootup.core.model.SootClass; import sootup.core.model.SootMethod; import sootup.core.signatures.MethodSignature; @@ -39,19 +39,15 @@ public void test() { assertTrue( clazz.getFields().stream() .anyMatch( - sootField -> { - return sootField.getModifiers().contains(Modifier.PRIVATE) - && sootField.getModifiers().contains(Modifier.STATIC) - && sootField.getName().equals("i"); - })); + sootField -> sootField.getModifiers().contains(FieldModifier.PRIVATE) + && sootField.getModifiers().contains(FieldModifier.STATIC) + && sootField.getName().equals("i"))); assertTrue( clazz.getFields().stream() .anyMatch( - sootField -> { - return sootField.getModifiers().contains(Modifier.PUBLIC) - && sootField.getModifiers().contains(Modifier.FINAL) - && sootField.getName().equals("s"); - })); + sootField -> sootField.getModifiers().contains(FieldModifier.PUBLIC) + && sootField.getModifiers().contains(FieldModifier.FINAL) + && sootField.getName().equals("s"))); } /** diff --git a/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/minimaltestsuite/java6/NoModifierClassTest.java b/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/minimaltestsuite/java6/NoModifierClassTest.java index 4d57d80086f..b3c045ec7fe 100644 --- a/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/minimaltestsuite/java6/NoModifierClassTest.java +++ b/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/minimaltestsuite/java6/NoModifierClassTest.java @@ -8,7 +8,7 @@ import java.util.*; import org.junit.Test; import org.junit.experimental.categories.Category; -import sootup.core.model.Modifier; +import sootup.core.model.ClassModifier; import sootup.core.signatures.MethodSignature; import sootup.java.core.JavaSootClass; import sootup.java.sourcecode.minimaltestsuite.MinimalSourceTestSuiteBase; @@ -20,7 +20,7 @@ public class NoModifierClassTest extends MinimalSourceTestSuiteBase { @Test public void test() { JavaSootClass clazz = loadClass(getDeclaredClassSignature()); - assertEquals(EnumSet.noneOf(Modifier.class), clazz.getModifiers()); + assertEquals(EnumSet.noneOf(ClassModifier.class), clazz.getModifiers()); assertTrue(clazz.getMethod(getMethodSignature("private").getSubSignature()).get().isPrivate()); assertTrue( diff --git a/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/minimaltestsuite/java6/PublicClassTest.java b/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/minimaltestsuite/java6/PublicClassTest.java index 80f1026ab92..ce3ed45b548 100644 --- a/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/minimaltestsuite/java6/PublicClassTest.java +++ b/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/minimaltestsuite/java6/PublicClassTest.java @@ -9,7 +9,7 @@ import java.util.stream.Stream; import org.junit.Test; import org.junit.experimental.categories.Category; -import sootup.core.model.Modifier; +import sootup.core.model.ClassModifier; import sootup.core.model.SootClass; import sootup.core.model.SootMethod; import sootup.core.signatures.MethodSignature; @@ -22,7 +22,7 @@ public class PublicClassTest extends MinimalSourceTestSuiteBase { @Test public void test() { SootClass clazz = loadClass(getDeclaredClassSignature()); - assertEquals(EnumSet.of(Modifier.PUBLIC), clazz.getModifiers()); + assertEquals(EnumSet.of(ClassModifier.PUBLIC), clazz.getModifiers()); SootMethod method; method = clazz.getMethod(getMethodSignature("private").getSubSignature()).get(); diff --git a/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/minimaltestsuite/java6/TransientVariableTest.java b/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/minimaltestsuite/java6/TransientVariableTest.java index 6889ead1462..a883bbf13ce 100644 --- a/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/minimaltestsuite/java6/TransientVariableTest.java +++ b/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/minimaltestsuite/java6/TransientVariableTest.java @@ -8,7 +8,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import org.junit.Ignore; -import sootup.core.model.Modifier; +import sootup.core.model.FieldModifier; import sootup.core.model.SootClass; import sootup.core.signatures.MethodSignature; import sootup.java.sourcecode.minimaltestsuite.MinimalSourceTestSuiteBase; @@ -28,7 +28,7 @@ public void testTransientVar() { .anyMatch( sootField -> sootField.getName().equals("transientVar") - && sootField.getModifiers().contains(Modifier.TRANSIENT))); + && sootField.getModifiers().contains(FieldModifier.TRANSIENT))); } /** diff --git a/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/minimaltestsuite/java6/VolatileVariableTest.java b/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/minimaltestsuite/java6/VolatileVariableTest.java index 6d6d101fccf..11140c7868b 100644 --- a/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/minimaltestsuite/java6/VolatileVariableTest.java +++ b/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/minimaltestsuite/java6/VolatileVariableTest.java @@ -8,7 +8,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import org.junit.Test; -import sootup.core.model.Modifier; +import sootup.core.model.FieldModifier; import sootup.core.model.SootClass; import sootup.core.model.SootMethod; import sootup.core.signatures.MethodSignature; @@ -31,7 +31,7 @@ public void test() { .anyMatch( sootField -> { return sootField.getName().equals("counter") - && sootField.getModifiers().contains(Modifier.VOLATILE); + && sootField.getModifiers().contains(FieldModifier.VOLATILE); })); } diff --git a/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/minimaltestsuite/java8/RepeatingAnnotationsTest.java b/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/minimaltestsuite/java8/RepeatingAnnotationsTest.java index 62f06a5afa3..b84f30603fa 100644 --- a/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/minimaltestsuite/java8/RepeatingAnnotationsTest.java +++ b/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/minimaltestsuite/java8/RepeatingAnnotationsTest.java @@ -8,7 +8,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import org.junit.Ignore; -import sootup.core.model.Modifier; +import sootup.core.model.ClassModifier; import sootup.core.model.SootClass; import sootup.core.model.SootMethod; import sootup.core.signatures.MethodSignature; @@ -29,7 +29,7 @@ public void annotationTest() { assertJimpleStmts(method, expectedBodyStmts()); SootClass sootClass = loadClass(getDeclaredClassSignature()); - assertTrue(Modifier.isAnnotation(sootClass.getModifiers())); + assertTrue(ClassModifier.isAnnotation(sootClass.getModifiers())); } @Override diff --git a/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleConverter.java b/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleConverter.java index 2e36e9d64d5..8faa89c20b3 100644 --- a/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleConverter.java +++ b/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleConverter.java @@ -108,7 +108,7 @@ public ClassVisitor(@Nonnull Path path) { Set interfaces = null; ClassType outerclass = null; // currently not determined in Java etc -> heuristic will be used Position position = NoPositionInformation.getInstance(); - EnumSet modifiers = null; + EnumSet modifiers = null; @Override @Nonnull @@ -135,14 +135,14 @@ public Boolean visitFile(@Nonnull JimpleParser.FileContext ctx) { "Classname is not well formed.", path, JimpleConverterUtil.buildPositionFromCtx(ctx)); } - modifiers = getModifiers(ctx.modifier()); + modifiers = getClassModifiers(ctx.modifier()); // file_type if (ctx.file_type() != null) { if (ctx.file_type().getText().equals("interface")) { - modifiers.add(Modifier.INTERFACE); + modifiers.add(ClassModifier.INTERFACE); } if (ctx.file_type().getText().equals("annotation")) { - modifiers.add(Modifier.ANNOTATION); + modifiers.add(ClassModifier.ANNOTATION); } } @@ -177,7 +177,7 @@ public Boolean visitFile(@Nonnull JimpleParser.FileContext ctx) { } else { final JimpleParser.FieldContext fieldCtx = ctx.member(i).field(); - EnumSet modifier = getModifiers(fieldCtx.modifier()); + EnumSet modifier = getFieldModifiers(fieldCtx.modifier()); final Position pos = JimpleConverterUtil.buildPositionFromCtx(fieldCtx); final String fieldName = Jimple.unescape(fieldCtx.identifier().getText()); final SootField f = @@ -196,12 +196,39 @@ public Boolean visitFile(@Nonnull JimpleParser.FileContext ctx) { return true; } - private EnumSet getModifiers(List modifier) { - Set modifierSet = + private EnumSet getClassModifiers(List modifier) { + Set modifierSet = modifier.stream() - .map(modifierContext -> Modifier.valueOf(modifierContext.getText().toUpperCase())) + .map( + modifierContext -> ClassModifier.valueOf(modifierContext.getText().toUpperCase())) .collect(Collectors.toSet()); - return modifierSet.isEmpty() ? EnumSet.noneOf(Modifier.class) : EnumSet.copyOf(modifierSet); + return modifierSet.isEmpty() + ? EnumSet.noneOf(ClassModifier.class) + : EnumSet.copyOf(modifierSet); + } + + private EnumSet getMethodModifiers( + List modifier) { + Set modifierSet = + modifier.stream() + .map( + modifierContext -> + MethodModifier.valueOf(modifierContext.getText().toUpperCase())) + .collect(Collectors.toSet()); + return modifierSet.isEmpty() + ? EnumSet.noneOf(MethodModifier.class) + : EnumSet.copyOf(modifierSet); + } + + private EnumSet getFieldModifiers(List modifier) { + Set modifierSet = + modifier.stream() + .map( + modifierContext -> FieldModifier.valueOf(modifierContext.getText().toUpperCase())) + .collect(Collectors.toSet()); + return modifierSet.isEmpty() + ? EnumSet.noneOf(FieldModifier.class) + : EnumSet.copyOf(modifierSet); } private class MethodVisitor extends JimpleBaseVisitor { @@ -219,8 +246,10 @@ public Local getLocal(@Nonnull String name) { @Nonnull public SootMethod visitMethod(@Nonnull JimpleParser.MethodContext ctx) { - EnumSet modifier = - ctx.modifier() == null ? EnumSet.noneOf(Modifier.class) : getModifiers(ctx.modifier()); + EnumSet modifier = + ctx.modifier() == null + ? EnumSet.noneOf(MethodModifier.class) + : getMethodModifiers(ctx.modifier()); final JimpleParser.Method_subsignatureContext method_subsignatureContext = ctx.method_subsignature(); @@ -359,7 +388,7 @@ public SootMethod visitMethod(@Nonnull JimpleParser.MethodContext ctx) { graph.initializeWith(stmtList, branchingMap, traps); Body.BodyBuilder builder = Body.builder(graph); - builder.setModifiers(modifiers); + builder.setModifiers(modifier); builder.setMethodSignature(methodSignature); builder.setLocals(new HashSet<>(locals.values())); builder.setPosition(classPosition); @@ -556,7 +585,7 @@ public Value visitValue(JimpleParser.ValueContext ctx) { List sizes = ctx.immediate().stream() - .map(imm -> visitImmediate(imm)) + .map(this::visitImmediate) .collect(Collectors.toList()); if (sizes.size() < 1) { throw new ResolveException( diff --git a/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java6/AnnotationLibraryTest.java b/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java6/AnnotationLibraryTest.java index d3c15a9f753..472863e41b1 100644 --- a/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java6/AnnotationLibraryTest.java +++ b/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java6/AnnotationLibraryTest.java @@ -4,7 +4,7 @@ import org.junit.Ignore; import org.junit.experimental.categories.Category; -import sootup.core.model.Modifier; +import sootup.core.model.ClassModifier; import sootup.core.model.SootClass; import sootup.jimple.parser.categories.Java8Test; import sootup.jimple.parser.javatestsuite.JimpleTestSuiteBase; @@ -18,6 +18,6 @@ public void testAnnotation() { // TODO: annotations are not supported yet System.out.println(getDeclaredClassSignature()); SootClass sootClass = loadClass(getDeclaredClassSignature()); - assertTrue(Modifier.isAnnotation(sootClass.getModifiers())); + assertTrue(ClassModifier.isAnnotation(sootClass.getModifiers())); } } diff --git a/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java6/DeclareFieldTest.java b/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java6/DeclareFieldTest.java index 0264342eac7..446715afde3 100644 --- a/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java6/DeclareFieldTest.java +++ b/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java6/DeclareFieldTest.java @@ -8,7 +8,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import org.junit.experimental.categories.Category; -import sootup.core.model.Modifier; +import sootup.core.model.FieldModifier; import sootup.core.model.SootClass; import sootup.core.model.SootMethod; import sootup.core.signatures.MethodSignature; @@ -41,19 +41,15 @@ public void test() { assertTrue( clazz.getFields().stream() .anyMatch( - sootField -> { - return sootField.getModifiers().contains(Modifier.PRIVATE) - && sootField.getModifiers().contains(Modifier.STATIC) - && sootField.getName().equals("i"); - })); + sootField -> sootField.getModifiers().contains(FieldModifier.PRIVATE) + && sootField.getModifiers().contains(FieldModifier.STATIC) + && sootField.getName().equals("i"))); assertTrue( clazz.getFields().stream() .anyMatch( - sootField -> { - return sootField.getModifiers().contains(Modifier.PUBLIC) - && sootField.getModifiers().contains(Modifier.FINAL) - && sootField.getName().equals("s"); - })); + sootField -> sootField.getModifiers().contains(FieldModifier.PUBLIC) + && sootField.getModifiers().contains(FieldModifier.FINAL) + && sootField.getName().equals("s"))); } public List expectedBodyStmts() { diff --git a/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java6/PublicClassTest.java b/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java6/PublicClassTest.java index f8fc838a774..8c2c4f2849f 100644 --- a/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java6/PublicClassTest.java +++ b/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java6/PublicClassTest.java @@ -10,7 +10,7 @@ import java.util.stream.Stream; import org.junit.Test; import org.junit.experimental.categories.Category; -import sootup.core.model.Modifier; +import sootup.core.model.ClassModifier; import sootup.core.model.SootClass; import sootup.core.model.SootMethod; import sootup.core.signatures.MethodSignature; @@ -24,7 +24,7 @@ public class PublicClassTest extends JimpleTestSuiteBase { @Test public void test() { SootClass clazz = loadClass(getDeclaredClassSignature()); - assertEquals(EnumSet.of(Modifier.PUBLIC, Modifier.SYNCHRONIZED), clazz.getModifiers()); + assertEquals(EnumSet.of(ClassModifier.PUBLIC, ClassModifier.SUPER), clazz.getModifiers()); SootMethod method; method = clazz.getMethod(getMethodSignature("private").getSubSignature()).get(); diff --git a/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java6/TransientVariableTest.java b/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java6/TransientVariableTest.java index df656315334..cbcb22e1bb4 100644 --- a/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java6/TransientVariableTest.java +++ b/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java6/TransientVariableTest.java @@ -9,7 +9,7 @@ import java.util.stream.Stream; import org.junit.Test; import org.junit.experimental.categories.Category; -import sootup.core.model.Modifier; +import sootup.core.model.FieldModifier; import sootup.core.model.SootClass; import sootup.core.model.SootMethod; import sootup.core.signatures.MethodSignature; @@ -34,7 +34,7 @@ public void test() { .anyMatch( sootField -> sootField.getName().equals("transientVar") - && sootField.getModifiers().contains(Modifier.TRANSIENT))); + && sootField.getModifiers().contains(FieldModifier.TRANSIENT))); } public List expectedBodyStmts() { diff --git a/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java6/VolatileVariableTest.java b/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java6/VolatileVariableTest.java index 4a47e67c28b..a7d935476d8 100644 --- a/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java6/VolatileVariableTest.java +++ b/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java6/VolatileVariableTest.java @@ -9,7 +9,7 @@ import java.util.stream.Stream; import org.junit.Test; import org.junit.experimental.categories.Category; -import sootup.core.model.Modifier; +import sootup.core.model.FieldModifier; import sootup.core.model.SootClass; import sootup.core.model.SootMethod; import sootup.core.signatures.MethodSignature; @@ -32,10 +32,8 @@ public void test() { assertTrue( clazz.getFields().stream() .anyMatch( - sootField -> { - return sootField.getName().equals("counter") - && sootField.getModifiers().contains(Modifier.VOLATILE); - })); + sootField -> sootField.getName().equals("counter") + && sootField.getModifiers().contains(FieldModifier.VOLATILE))); } public List expectedBodyStmts() { diff --git a/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java8/RepeatingAnnotationsTest.java b/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java8/RepeatingAnnotationsTest.java index bc40f411aae..8300d5c0979 100644 --- a/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java8/RepeatingAnnotationsTest.java +++ b/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java8/RepeatingAnnotationsTest.java @@ -9,7 +9,7 @@ import java.util.stream.Stream; import org.junit.Ignore; import org.junit.experimental.categories.Category; -import sootup.core.model.Modifier; +import sootup.core.model.ClassModifier; import sootup.core.model.SootClass; import sootup.core.model.SootMethod; import sootup.core.signatures.MethodSignature; @@ -31,7 +31,7 @@ public void annotationTest() { SootMethod method = loadMethod(getMethodSignature()); assertJimpleStmts(method, expectedBodyStmts()); SootClass sootClass = loadClass(getDeclaredClassSignature()); - assertTrue(Modifier.isAnnotation(sootClass.getModifiers())); + assertTrue(ClassModifier.isAnnotation(sootClass.getModifiers())); } public List expectedBodyStmts() { diff --git a/sootup.tests/src/test/java/sootup/tests/MutableSootClientTest.java b/sootup.tests/src/test/java/sootup/tests/MutableSootClientTest.java index cf6bdae2886..134ed12c130 100644 --- a/sootup.tests/src/test/java/sootup/tests/MutableSootClientTest.java +++ b/sootup.tests/src/test/java/sootup/tests/MutableSootClientTest.java @@ -79,7 +79,7 @@ public void classAdditionTest() { Collections.emptySet(), Collections.emptySet(), new FullPosition(0, 0, 0, 0), - EnumSet.noneOf(Modifier.class), + EnumSet.noneOf(ClassModifier.class), Collections.emptySet(), Collections.emptySet(), Collections.emptySet()); @@ -136,7 +136,7 @@ public void methodAdditionTest() { new JavaSootMethod( new OverridingBodySource(methodSignature, body), methodSignature, - EnumSet.of(Modifier.PUBLIC, Modifier.STATIC), + EnumSet.of(MethodModifier.PUBLIC, MethodModifier.STATIC), Collections.emptyList(), Collections.emptyList(), NoPositionInformation.getInstance()); diff --git a/sootup.tests/src/test/java/sootup/tests/typehierarchy/ViewTypeHierarchyTest.java b/sootup.tests/src/test/java/sootup/tests/typehierarchy/ViewTypeHierarchyTest.java index 06f66b9f172..d830eed46d5 100644 --- a/sootup.tests/src/test/java/sootup/tests/typehierarchy/ViewTypeHierarchyTest.java +++ b/sootup.tests/src/test/java/sootup/tests/typehierarchy/ViewTypeHierarchyTest.java @@ -24,7 +24,7 @@ import org.junit.Test; import org.junit.experimental.categories.Category; import sootup.core.IdentifierFactory; -import sootup.core.model.Modifier; +import sootup.core.model.ClassModifier; import sootup.core.model.SootClass; import sootup.core.model.SourceType; import sootup.core.typehierarchy.ViewTypeHierarchy; @@ -202,7 +202,7 @@ public void addType() { Collections.emptySet(), Collections.emptySet(), null, - EnumSet.of(Modifier.FINAL), + EnumSet.of(ClassModifier.FINAL), Collections.emptyList(), Collections.emptyList(), Collections.emptyList()); From 99f537d9debcbac4413b79979c450a83cd9e4ea8 Mon Sep 17 00:00:00 2001 From: Jonas Klauke Date: Tue, 1 Aug 2023 14:38:30 +0200 Subject: [PATCH 46/90] fmt --- .../PathBasedAnalysisInputLocationTest.java | 8 ++------ .../minimaltestsuite/java6/DeclareFieldTest.java | 14 ++++++++------ .../java6/VolatileVariableTest.java | 5 +++-- .../minimaltestsuite/java6/DeclareFieldTest.java | 14 ++++++++------ .../javatestsuite/java6/DeclareFieldTest.java | 14 ++++++++------ .../javatestsuite/java6/VolatileVariableTest.java | 5 +++-- 6 files changed, 32 insertions(+), 28 deletions(-) diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java index 29509f4f71c..a9d055bd319 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java @@ -334,9 +334,7 @@ public void testClassInWar() { assertEquals("void", foundMethod.getReturnType().toString()); assertEquals(1, foundMethod.getParameterCount()); assertTrue( - foundMethod.getParameterTypes().stream() - .anyMatch( - type -> "int".equals(type.toString()))); + foundMethod.getParameterTypes().stream().anyMatch(type -> "int".equals(type.toString()))); // Parse sub-signature for "empName" field FieldSubSignature nameFieldSubSignature = @@ -420,8 +418,6 @@ public void testRuntimeJar() { .build() .createView(); - final Collection classSources = - pathBasedNamespace.getClassSources(v); // test some standard jre classes runtimeContains(v, "Object", "java.lang"); runtimeContains(v, "List", "java.util"); @@ -445,7 +441,7 @@ public void testInputLocationLibraryMode() { new JavaClassPathAnalysisInputLocation( System.getProperty("java.home") + "/lib/rt.jar", SourceType.Library)) .build(); - JavaView view = javaProject.createOnDemandView(); + JavaView view = javaProject.createView(); Collection> classes = new HashSet<>(); // Set to track the classes to check diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java6/DeclareFieldTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java6/DeclareFieldTest.java index 3659403399c..c73f0abd160 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java6/DeclareFieldTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java6/DeclareFieldTest.java @@ -42,15 +42,17 @@ public void test() { assertTrue( clazz.getFields().stream() .anyMatch( - sootField -> sootField.getModifiers().contains(FieldModifier.PRIVATE) - && sootField.getModifiers().contains(FieldModifier.STATIC) - && sootField.getName().equals("i"))); + sootField -> + sootField.getModifiers().contains(FieldModifier.PRIVATE) + && sootField.getModifiers().contains(FieldModifier.STATIC) + && sootField.getName().equals("i"))); assertTrue( clazz.getFields().stream() .anyMatch( - sootField -> sootField.getModifiers().contains(FieldModifier.PUBLIC) - && sootField.getModifiers().contains(FieldModifier.FINAL) - && sootField.getName().equals("s"))); + sootField -> + sootField.getModifiers().contains(FieldModifier.PUBLIC) + && sootField.getModifiers().contains(FieldModifier.FINAL) + && sootField.getName().equals("s"))); } /** diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java6/VolatileVariableTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java6/VolatileVariableTest.java index a637391d973..a4d8b332d92 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java6/VolatileVariableTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java6/VolatileVariableTest.java @@ -32,8 +32,9 @@ public void test() { assertTrue( clazz.getFields().stream() .anyMatch( - sootField -> sootField.getName().equals("counter") - && sootField.getModifiers().contains(FieldModifier.VOLATILE))); + sootField -> + sootField.getName().equals("counter") + && sootField.getModifiers().contains(FieldModifier.VOLATILE))); } /** diff --git a/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/minimaltestsuite/java6/DeclareFieldTest.java b/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/minimaltestsuite/java6/DeclareFieldTest.java index 6ba1f45ba05..4daa2095f29 100644 --- a/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/minimaltestsuite/java6/DeclareFieldTest.java +++ b/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/minimaltestsuite/java6/DeclareFieldTest.java @@ -39,15 +39,17 @@ public void test() { assertTrue( clazz.getFields().stream() .anyMatch( - sootField -> sootField.getModifiers().contains(FieldModifier.PRIVATE) - && sootField.getModifiers().contains(FieldModifier.STATIC) - && sootField.getName().equals("i"))); + sootField -> + sootField.getModifiers().contains(FieldModifier.PRIVATE) + && sootField.getModifiers().contains(FieldModifier.STATIC) + && sootField.getName().equals("i"))); assertTrue( clazz.getFields().stream() .anyMatch( - sootField -> sootField.getModifiers().contains(FieldModifier.PUBLIC) - && sootField.getModifiers().contains(FieldModifier.FINAL) - && sootField.getName().equals("s"))); + sootField -> + sootField.getModifiers().contains(FieldModifier.PUBLIC) + && sootField.getModifiers().contains(FieldModifier.FINAL) + && sootField.getName().equals("s"))); } /** diff --git a/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java6/DeclareFieldTest.java b/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java6/DeclareFieldTest.java index 446715afde3..e7e0795d645 100644 --- a/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java6/DeclareFieldTest.java +++ b/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java6/DeclareFieldTest.java @@ -41,15 +41,17 @@ public void test() { assertTrue( clazz.getFields().stream() .anyMatch( - sootField -> sootField.getModifiers().contains(FieldModifier.PRIVATE) - && sootField.getModifiers().contains(FieldModifier.STATIC) - && sootField.getName().equals("i"))); + sootField -> + sootField.getModifiers().contains(FieldModifier.PRIVATE) + && sootField.getModifiers().contains(FieldModifier.STATIC) + && sootField.getName().equals("i"))); assertTrue( clazz.getFields().stream() .anyMatch( - sootField -> sootField.getModifiers().contains(FieldModifier.PUBLIC) - && sootField.getModifiers().contains(FieldModifier.FINAL) - && sootField.getName().equals("s"))); + sootField -> + sootField.getModifiers().contains(FieldModifier.PUBLIC) + && sootField.getModifiers().contains(FieldModifier.FINAL) + && sootField.getName().equals("s"))); } public List expectedBodyStmts() { diff --git a/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java6/VolatileVariableTest.java b/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java6/VolatileVariableTest.java index a7d935476d8..190e8411ae0 100644 --- a/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java6/VolatileVariableTest.java +++ b/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java6/VolatileVariableTest.java @@ -32,8 +32,9 @@ public void test() { assertTrue( clazz.getFields().stream() .anyMatch( - sootField -> sootField.getName().equals("counter") - && sootField.getModifiers().contains(FieldModifier.VOLATILE))); + sootField -> + sootField.getName().equals("counter") + && sootField.getModifiers().contains(FieldModifier.VOLATILE))); } public List expectedBodyStmts() { From 5e29c322515ed72b1ed4e7733539e1dd0efffac1 Mon Sep 17 00:00:00 2001 From: Jonas Klauke Date: Tue, 1 Aug 2023 14:42:13 +0200 Subject: [PATCH 47/90] improved the code to get the corresponding modifier --- .../sootup/jimple/parser/JimpleConverter.java | 40 +++++-------------- 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleConverter.java b/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleConverter.java index 8faa89c20b3..f2cfdc03e91 100644 --- a/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleConverter.java +++ b/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleConverter.java @@ -197,38 +197,22 @@ public Boolean visitFile(@Nonnull JimpleParser.FileContext ctx) { } private EnumSet getClassModifiers(List modifier) { - Set modifierSet = - modifier.stream() - .map( - modifierContext -> ClassModifier.valueOf(modifierContext.getText().toUpperCase())) - .collect(Collectors.toSet()); - return modifierSet.isEmpty() - ? EnumSet.noneOf(ClassModifier.class) - : EnumSet.copyOf(modifierSet); + return modifier.stream() + .map(modContext -> ClassModifier.valueOf(modContext.getText().toUpperCase())) + .collect(Collectors.toCollection(() -> EnumSet.noneOf(ClassModifier.class))); } private EnumSet getMethodModifiers( List modifier) { - Set modifierSet = - modifier.stream() - .map( - modifierContext -> - MethodModifier.valueOf(modifierContext.getText().toUpperCase())) - .collect(Collectors.toSet()); - return modifierSet.isEmpty() - ? EnumSet.noneOf(MethodModifier.class) - : EnumSet.copyOf(modifierSet); + return modifier.stream() + .map(modContext -> MethodModifier.valueOf(modContext.getText().toUpperCase())) + .collect(Collectors.toCollection(() -> EnumSet.noneOf(MethodModifier.class))); } private EnumSet getFieldModifiers(List modifier) { - Set modifierSet = - modifier.stream() - .map( - modifierContext -> FieldModifier.valueOf(modifierContext.getText().toUpperCase())) - .collect(Collectors.toSet()); - return modifierSet.isEmpty() - ? EnumSet.noneOf(FieldModifier.class) - : EnumSet.copyOf(modifierSet); + return modifier.stream() + .map(modContext -> FieldModifier.valueOf(modContext.getText().toUpperCase())) + .collect(Collectors.toCollection(() -> EnumSet.noneOf(FieldModifier.class))); } private class MethodVisitor extends JimpleBaseVisitor { @@ -354,8 +338,6 @@ public SootMethod visitMethod(@Nonnull JimpleParser.MethodContext ctx) { labeledStmts.get(handlerLabel))); } } - } else { - // no body is given: no brackets, but a semicolon -> abstract } Position classPosition = JimpleConverterUtil.buildPositionFromCtx(ctx); @@ -584,9 +566,7 @@ public Value visitValue(JimpleParser.ValueContext ctx) { } List sizes = - ctx.immediate().stream() - .map(this::visitImmediate) - .collect(Collectors.toList()); + ctx.immediate().stream().map(this::visitImmediate).collect(Collectors.toList()); if (sizes.size() < 1) { throw new ResolveException( "The Size list must have at least one Element.", From b8f287df7a0994245cf9c09c3b0ba7846ebf4632 Mon Sep 17 00:00:00 2001 From: Jonas Klauke Date: Tue, 1 Aug 2023 15:22:15 +0200 Subject: [PATCH 48/90] changed the synchronized modifier to super in all jimple test classes --- .../inputlocation/PathBasedAnalysisInputLocationTest.java | 1 - sootup.jimple.parser/src/test/java/resources/jimple/A.jimple | 2 +- .../src/test/java/resources/jimple/AbstractClass.jimple | 2 +- .../src/test/java/resources/jimple/AccessArrays.jimple | 2 +- .../src/test/java/resources/jimple/AlphaBetaGamma.jimple | 2 +- .../java/resources/jimple/AnonymousClassInsideMethod.jimple | 2 +- .../test/java/resources/jimple/AnonymousDiamondOperator.jimple | 2 +- .../src/test/java/resources/jimple/AssertStatement.jimple | 2 +- .../src/test/java/resources/jimple/Autoboxing.jimple | 2 +- .../src/test/java/resources/jimple/AutomaticWidening.jimple | 2 +- .../src/test/java/resources/jimple/BinaryLiteralInInt.jimple | 2 +- .../src/test/java/resources/jimple/BitwiseOperationsInt.jimple | 2 +- .../src/test/java/resources/jimple/BooleanOperators.jimple | 2 +- .../src/test/java/resources/jimple/BreakInWhileLoop.jimple | 2 +- .../src/test/java/resources/jimple/CastingInNumTypes.jimple | 2 +- .../src/test/java/resources/jimple/CharLiterals.jimple | 2 +- .../src/test/java/resources/jimple/ContinueInWhileLoop.jimple | 2 +- .../src/test/java/resources/jimple/CreateNewInstance.jimple | 2 +- .../src/test/java/resources/jimple/DeclareConstructor.jimple | 2 +- .../src/test/java/resources/jimple/DeclareEnum$Type.jimple | 2 +- .../resources/jimple/DeclareEnumWithConstructor$Number.jimple | 2 +- .../src/test/java/resources/jimple/DeclareField.jimple | 2 +- .../src/test/java/resources/jimple/DeclareFloat.jimple | 2 +- .../java/resources/jimple/DeclareInnerClass$InnerClass.jimple | 2 +- .../src/test/java/resources/jimple/DeclareInnerClass.jimple | 2 +- .../src/test/java/resources/jimple/DeclareInt.jimple | 2 +- .../src/test/java/resources/jimple/DeclareLong.jimple | 2 +- .../java/resources/jimple/DefaultMethodInterfaceImpl.jimple | 2 +- .../src/test/java/resources/jimple/DoWhileLoop.jimple | 2 +- .../src/test/java/resources/jimple/DynamicInvoke.jimple | 2 +- .../src/test/java/resources/jimple/EmptyStatement.jimple | 2 +- .../test/java/resources/jimple/EscapeSequencesInString.jimple | 2 +- .../java/resources/jimple/EvaluationOrderWithParentheses.jimple | 2 +- .../src/test/java/resources/jimple/FinalMethod.jimple | 2 +- .../src/test/java/resources/jimple/FinalVariable.jimple | 2 +- .../src/test/java/resources/jimple/ForEachLoop.jimple | 2 +- .../src/test/java/resources/jimple/ForLoop.jimple | 2 +- .../src/test/java/resources/jimple/GenTypeParam.jimple | 2 +- .../test/java/resources/jimple/GenericTypeParamOnClass.jimple | 2 +- .../test/java/resources/jimple/GenericTypeParamOnMethod.jimple | 2 +- .../src/test/java/resources/jimple/IfElseStatement.jimple | 2 +- .../src/test/java/resources/jimple/InfiniteLoop.jimple | 2 +- .../java/resources/jimple/Initialize3DimensionalArrays.jimple | 2 +- .../resources/jimple/InitializeArraysWhileDeclaration.jimple | 2 +- .../test/java/resources/jimple/InitializeArraysWithIndex.jimple | 2 +- .../resources/jimple/InitializeMultidimensionalArrays.jimple | 2 +- .../src/test/java/resources/jimple/InstanceOfCheck.jimple | 2 +- .../src/test/java/resources/jimple/InterfaceImplClass.jimple | 2 +- .../src/test/java/resources/jimple/LabelStatement.jimple | 2 +- .../src/test/java/resources/jimple/LabelledLoopBreak.jimple | 2 +- .../test/java/resources/jimple/MethodAcceptingLamExpr.jimple | 2 +- .../src/test/java/resources/jimple/MethodAcceptingVar.jimple | 2 +- .../src/test/java/resources/jimple/MethodOverloading.jimple | 2 +- .../test/java/resources/jimple/MethodOverridingSubclass.jimple | 2 +- .../src/test/java/resources/jimple/MethodReference.jimple | 2 +- .../src/test/java/resources/jimple/MethodReturningVar.jimple | 2 +- .../test/java/resources/jimple/MultiInterfaceImplClass.jimple | 2 +- .../src/test/java/resources/jimple/MultiTryCatch.jimple | 2 +- .../test/java/resources/jimple/NamedClassInsideMethod.jimple | 2 +- .../src/test/java/resources/jimple/NativeMethod.jimple | 2 +- .../src/test/java/resources/jimple/NewCodeBlockInMethod.jimple | 2 +- .../src/test/java/resources/jimple/NoModifierClass.jimple | 2 +- .../src/test/java/resources/jimple/NullVariable.jimple | 2 +- .../java/resources/jimple/PrivateMethodInterfaceImpl.jimple | 2 +- .../src/test/java/resources/jimple/PublicClass.jimple | 2 +- .../test/java/resources/jimple/ReferenceVarDeclaration.jimple | 2 +- .../src/test/java/resources/jimple/ReferencingThis.jimple | 2 +- .../src/test/java/resources/jimple/Reflection.jimple | 2 +- .../src/test/java/resources/jimple/StatementEval.jimple | 2 +- .../src/test/java/resources/jimple/StaticImport.jimple | 2 +- .../src/test/java/resources/jimple/StaticInitializer.jimple | 2 +- .../src/test/java/resources/jimple/StaticMethod.jimple | 2 +- .../test/java/resources/jimple/StaticMethodInterfaceImpl.jimple | 2 +- .../test/java/resources/jimple/StaticMethodInvocation.jimple | 2 +- .../src/test/java/resources/jimple/StaticVariable.jimple | 2 +- .../src/test/java/resources/jimple/StringConcatenation.jimple | 2 +- .../src/test/java/resources/jimple/StringWithUnicodeChar.jimple | 2 +- .../src/test/java/resources/jimple/SubClass.jimple | 2 +- .../src/test/java/resources/jimple/SuperClass.jimple | 2 +- .../src/test/java/resources/jimple/SwitchCaseStatement.jimple | 2 +- .../java/resources/jimple/SwitchCaseStatementWithString.jimple | 2 +- .../src/test/java/resources/jimple/SymbolsAsMethodName.jimple | 2 +- .../src/test/java/resources/jimple/SynchronizedBlock.jimple | 2 +- .../src/test/java/resources/jimple/SynchronizedMethod.jimple | 2 +- .../src/test/java/resources/jimple/TernaryOperator.jimple | 2 +- .../src/test/java/resources/jimple/ThrowExceptionMethod.jimple | 2 +- .../src/test/java/resources/jimple/TransientVariable.jimple | 2 +- .../src/test/java/resources/jimple/TryCatchFinally.jimple | 2 +- .../src/test/java/resources/jimple/TryWithResources.jimple | 2 +- .../test/java/resources/jimple/TryWithResourcesConcise.jimple | 2 +- .../src/test/java/resources/jimple/TypeInference.jimple | 2 +- .../src/test/java/resources/jimple/UnaryOpInt.jimple | 2 +- .../src/test/java/resources/jimple/UncheckedCast.jimple | 2 +- .../src/test/java/resources/jimple/UnderscoreInInt.jimple | 2 +- .../src/test/java/resources/jimple/VariableDeclaration.jimple | 2 +- .../src/test/java/resources/jimple/VariableShadowing.jimple | 2 +- .../src/test/java/resources/jimple/VirtualMethod.jimple | 2 +- .../src/test/java/resources/jimple/VolatileVariable.jimple | 2 +- .../src/test/java/resources/jimple/WhileLoop.jimple | 2 +- .../jimple/\316\261\317\201\316\265\317\204\316\267.jimple" | 2 +- 100 files changed, 99 insertions(+), 100 deletions(-) diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java index a9d055bd319..948dd92ddba 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java @@ -37,7 +37,6 @@ import org.junit.Assert; import org.junit.Test; import org.junit.experimental.categories.Category; -import sootup.core.frontend.AbstractClassSource; import sootup.core.frontend.BodySource; import sootup.core.inputlocation.EagerInputLocation; import sootup.core.model.*; diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/A.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/A.jimple index 815b1e4b005..dcf82a14ca9 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/A.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/A.jimple @@ -1,4 +1,4 @@ -abstract synchronized class A extends java.lang.Object +abstract super class A extends java.lang.Object { abstract void a(); void () diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/AbstractClass.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/AbstractClass.jimple index b604e2770ba..8f653651f80 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/AbstractClass.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/AbstractClass.jimple @@ -1,4 +1,4 @@ -public synchronized class AbstractClass extends A +public super class AbstractClass extends A { void a() diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/AccessArrays.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/AccessArrays.jimple index 0bcf7752b9e..cf2b01ddf83 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/AccessArrays.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/AccessArrays.jimple @@ -1,4 +1,4 @@ -public synchronized class AccessArrays extends java.lang.Object +public super class AccessArrays extends java.lang.Object { public void doubleArrays() { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/AlphaBetaGamma.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/AlphaBetaGamma.jimple index 133dbadce74..9e840cb27e1 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/AlphaBetaGamma.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/AlphaBetaGamma.jimple @@ -1,4 +1,4 @@ -public class AlphaBetaGamma extends java.lang.Object +public super class AlphaBetaGamma extends java.lang.Object { public void αβγ() diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/AnonymousClassInsideMethod.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/AnonymousClassInsideMethod.jimple index 9dcb0df5e10..87c15e059ad 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/AnonymousClassInsideMethod.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/AnonymousClassInsideMethod.jimple @@ -1,4 +1,4 @@ -public synchronized class AnonymousClassInsideMethod extends java.lang.Object +public super class AnonymousClassInsideMethod extends java.lang.Object { public void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/AnonymousDiamondOperator.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/AnonymousDiamondOperator.jimple index 4f4b81b3c33..5fba340292b 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/AnonymousDiamondOperator.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/AnonymousDiamondOperator.jimple @@ -1,4 +1,4 @@ -public synchronized class AnonymousDiamondOperator extends java.lang.Object +public super class AnonymousDiamondOperator extends java.lang.Object { public void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/AssertStatement.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/AssertStatement.jimple index 7de97a50862..341a8eef0cc 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/AssertStatement.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/AssertStatement.jimple @@ -1,4 +1,4 @@ -public synchronized class AssertStatement extends java.lang.Object +public super class AssertStatement extends java.lang.Object { static final boolean $assertionsDisabled; diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/Autoboxing.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/Autoboxing.jimple index b0bed84097b..65d66d50cce 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/Autoboxing.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/Autoboxing.jimple @@ -1,4 +1,4 @@ -public synchronized class Autoboxing extends java.lang.Object +public super class Autoboxing extends java.lang.Object { public void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/AutomaticWidening.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/AutomaticWidening.jimple index bbcb1976d49..d8db691cda9 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/AutomaticWidening.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/AutomaticWidening.jimple @@ -1,4 +1,4 @@ -public synchronized class AutomaticWidening extends java.lang.Object +public super class AutomaticWidening extends java.lang.Object { public void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/BinaryLiteralInInt.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/BinaryLiteralInInt.jimple index 3df30116930..dc52b2555d8 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/BinaryLiteralInInt.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/BinaryLiteralInInt.jimple @@ -1,4 +1,4 @@ -public synchronized class BinaryLiteralInInt extends java.lang.Object +public super class BinaryLiteralInInt extends java.lang.Object { public void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/BitwiseOperationsInt.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/BitwiseOperationsInt.jimple index 8f40193b52c..46436379ea0 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/BitwiseOperationsInt.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/BitwiseOperationsInt.jimple @@ -1,4 +1,4 @@ -public synchronized class BitwiseOperationsInt extends java.lang.Object +public super class BitwiseOperationsInt extends java.lang.Object { public void bitwiseOpOr() { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/BooleanOperators.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/BooleanOperators.jimple index b1dc9ad57d1..a7b3d2f63be 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/BooleanOperators.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/BooleanOperators.jimple @@ -1,4 +1,4 @@ -public synchronized class BooleanOperators extends java.lang.Object +public super class BooleanOperators extends java.lang.Object { public void complementOp() { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/BreakInWhileLoop.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/BreakInWhileLoop.jimple index 2fc2d332672..dd5b1fd2224 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/BreakInWhileLoop.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/BreakInWhileLoop.jimple @@ -1,4 +1,4 @@ -public synchronized class BreakInWhileLoop extends java.lang.Object +public super class BreakInWhileLoop extends java.lang.Object { public void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/CastingInNumTypes.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/CastingInNumTypes.jimple index a99ef3e9a64..4faaeb762d5 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/CastingInNumTypes.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/CastingInNumTypes.jimple @@ -1,4 +1,4 @@ -synchronized class CastingInNumTypes extends java.lang.Object +super class CastingInNumTypes extends java.lang.Object { public void displayNum() { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/CharLiterals.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/CharLiterals.jimple index 8dabf7bac1b..95526e5345b 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/CharLiterals.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/CharLiterals.jimple @@ -1,4 +1,4 @@ -public synchronized class CharLiterals extends java.lang.Object +public super class CharLiterals extends java.lang.Object { public void specialChar() { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/ContinueInWhileLoop.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/ContinueInWhileLoop.jimple index 39d0ddbb547..667c0229e00 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/ContinueInWhileLoop.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/ContinueInWhileLoop.jimple @@ -1,4 +1,4 @@ -public synchronized class ContinueInWhileLoop extends java.lang.Object +public super class ContinueInWhileLoop extends java.lang.Object { public void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/CreateNewInstance.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/CreateNewInstance.jimple index b7e05b3199a..c0dfcf37fd0 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/CreateNewInstance.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/CreateNewInstance.jimple @@ -1,4 +1,4 @@ -public synchronized class CreateNewInstance extends java.lang.Object +public super class CreateNewInstance extends java.lang.Object { public void createNewInstance() { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/DeclareConstructor.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/DeclareConstructor.jimple index 1f96acb14c0..d2062e00398 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/DeclareConstructor.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/DeclareConstructor.jimple @@ -1,4 +1,4 @@ -synchronized class DeclareConstructor extends java.lang.Object +super class DeclareConstructor extends java.lang.Object { public int var1; diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/DeclareEnum$Type.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/DeclareEnum$Type.jimple index b041f49d195..798f20cf06e 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/DeclareEnum$Type.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/DeclareEnum$Type.jimple @@ -1,4 +1,4 @@ -public final synchronized enum class DeclareEnum$Type extends java.lang.Enum +public final super enum class DeclareEnum$Type extends java.lang.Enum { public static final enum DeclareEnum$Type TYPE3; diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/DeclareEnumWithConstructor$Number.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/DeclareEnumWithConstructor$Number.jimple index 05f5770d7f4..833f440c747 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/DeclareEnumWithConstructor$Number.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/DeclareEnumWithConstructor$Number.jimple @@ -1,4 +1,4 @@ -public final synchronized enum class DeclareEnumWithConstructor$Number extends java.lang.Enum +public final super enum class DeclareEnumWithConstructor$Number extends java.lang.Enum { public static final enum DeclareEnumWithConstructor$Number ONE; diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/DeclareField.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/DeclareField.jimple index 40c128a76bb..699ccc978ca 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/DeclareField.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/DeclareField.jimple @@ -1,4 +1,4 @@ -synchronized class DeclareField extends java.lang.Object +super class DeclareField extends java.lang.Object { public final java.lang.String s; diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/DeclareFloat.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/DeclareFloat.jimple index cb14365e179..b286203eb2c 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/DeclareFloat.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/DeclareFloat.jimple @@ -1,4 +1,4 @@ -public synchronized class DeclareFloat extends java.lang.Object +public super class DeclareFloat extends java.lang.Object { float f1; diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/DeclareInnerClass$InnerClass.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/DeclareInnerClass$InnerClass.jimple index c75ea0bc0eb..30e810647d8 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/DeclareInnerClass$InnerClass.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/DeclareInnerClass$InnerClass.jimple @@ -1,4 +1,4 @@ -public synchronized class DeclareInnerClass$InnerClass extends java.lang.Object +public super class DeclareInnerClass$InnerClass extends java.lang.Object { final DeclareInnerClass this$0; diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/DeclareInnerClass.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/DeclareInnerClass.jimple index ab79a7957af..300cdb6e108 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/DeclareInnerClass.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/DeclareInnerClass.jimple @@ -1,4 +1,4 @@ -synchronized class DeclareInnerClass extends java.lang.Object +super class DeclareInnerClass extends java.lang.Object { public int a; diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/DeclareInt.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/DeclareInt.jimple index be818866dd8..eb4b8945cde 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/DeclareInt.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/DeclareInt.jimple @@ -1,4 +1,4 @@ -public synchronized class DeclareInt extends java.lang.Object +public super class DeclareInt extends java.lang.Object { int hex; diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/DeclareLong.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/DeclareLong.jimple index 237e12d15c5..2ed91a8aaca 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/DeclareLong.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/DeclareLong.jimple @@ -1,4 +1,4 @@ -public synchronized class DeclareLong extends java.lang.Object +public super class DeclareLong extends java.lang.Object { long l1; diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/DefaultMethodInterfaceImpl.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/DefaultMethodInterfaceImpl.jimple index c0510965b26..470d02d69b3 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/DefaultMethodInterfaceImpl.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/DefaultMethodInterfaceImpl.jimple @@ -1,4 +1,4 @@ -synchronized class DefaultMethodInterfaceImpl extends java.lang.Object implements DefaultMethodInterface +super class DefaultMethodInterfaceImpl extends java.lang.Object implements DefaultMethodInterface { public void interfaceMethod() { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/DoWhileLoop.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/DoWhileLoop.jimple index 100056d213c..f6210501006 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/DoWhileLoop.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/DoWhileLoop.jimple @@ -1,4 +1,4 @@ -public synchronized class DoWhileLoop extends java.lang.Object +public super class DoWhileLoop extends java.lang.Object { public void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/DynamicInvoke.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/DynamicInvoke.jimple index e3a826dc004..2e7ae2ad8a5 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/DynamicInvoke.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/DynamicInvoke.jimple @@ -1,4 +1,4 @@ -public synchronized class DynamicInvoke extends java.lang.Object +public super class DynamicInvoke extends java.lang.Object { public void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/EmptyStatement.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/EmptyStatement.jimple index 6abe25323b8..b849f44323a 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/EmptyStatement.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/EmptyStatement.jimple @@ -1,4 +1,4 @@ -public synchronized class EmptyStatement extends java.lang.Object +public super class EmptyStatement extends java.lang.Object { public void emptyStatement() { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/EscapeSequencesInString.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/EscapeSequencesInString.jimple index 2de45dcc68a..f34454095ab 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/EscapeSequencesInString.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/EscapeSequencesInString.jimple @@ -1,4 +1,4 @@ -public synchronized class EscapeSequencesInString extends java.lang.Object +public super class EscapeSequencesInString extends java.lang.Object { public void escapeBackslashB() { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/EvaluationOrderWithParentheses.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/EvaluationOrderWithParentheses.jimple index aa715d5d521..f0c2713bbfb 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/EvaluationOrderWithParentheses.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/EvaluationOrderWithParentheses.jimple @@ -1,4 +1,4 @@ -public synchronized class EvaluationOrderWithParentheses extends java.lang.Object +public super class EvaluationOrderWithParentheses extends java.lang.Object { public void evaluationOrderWithParentheses() { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/FinalMethod.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/FinalMethod.jimple index c795eb52087..9d24f310c3c 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/FinalMethod.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/FinalMethod.jimple @@ -1,4 +1,4 @@ -public synchronized class FinalMethod extends java.lang.Object +public super class FinalMethod extends java.lang.Object { public void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/FinalVariable.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/FinalVariable.jimple index 4d2e42c5c28..8a20bb3214c 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/FinalVariable.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/FinalVariable.jimple @@ -1,4 +1,4 @@ -public synchronized class FinalVariable extends java.lang.Object +public super class FinalVariable extends java.lang.Object { public void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/ForEachLoop.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/ForEachLoop.jimple index 9dfb9a6a6eb..9f3eddcc4e8 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/ForEachLoop.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/ForEachLoop.jimple @@ -1,4 +1,4 @@ -public synchronized class ForEachLoop extends java.lang.Object +public super class ForEachLoop extends java.lang.Object { public void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/ForLoop.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/ForLoop.jimple index b17df729691..2faa8d3e0d3 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/ForLoop.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/ForLoop.jimple @@ -1,4 +1,4 @@ -public synchronized class ForLoop extends java.lang.Object +public super class ForLoop extends java.lang.Object { public void forLoop() { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/GenTypeParam.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/GenTypeParam.jimple index 00f5c6d767c..965bb3423e9 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/GenTypeParam.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/GenTypeParam.jimple @@ -1,4 +1,4 @@ -synchronized class GenTypeParam extends java.lang.Object +super class GenTypeParam extends java.lang.Object { public java.lang.Number largestNum(java.lang.Number,java.lang.Number,java.lang.Number) { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/GenericTypeParamOnClass.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/GenericTypeParamOnClass.jimple index 29828eda854..d857654b0ac 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/GenericTypeParamOnClass.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/GenericTypeParamOnClass.jimple @@ -1,4 +1,4 @@ -public synchronized class GenericTypeParamOnClass extends java.lang.Object +public super class GenericTypeParamOnClass extends java.lang.Object { public void genericTypeParamOnClass() { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/GenericTypeParamOnMethod.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/GenericTypeParamOnMethod.jimple index 06b57e640f5..1a0b0bb6d29 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/GenericTypeParamOnMethod.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/GenericTypeParamOnMethod.jimple @@ -1,4 +1,4 @@ -public synchronized class GenericTypeParamOnMethod extends java.lang.Object +public super class GenericTypeParamOnMethod extends java.lang.Object { public void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/IfElseStatement.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/IfElseStatement.jimple index f4e34059477..95fb2ddc37d 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/IfElseStatement.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/IfElseStatement.jimple @@ -1,4 +1,4 @@ -public synchronized class IfElseStatement extends java.lang.Object +public super class IfElseStatement extends java.lang.Object { public void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/InfiniteLoop.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/InfiniteLoop.jimple index 2a6ca39b3fb..28cc7865988 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/InfiniteLoop.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/InfiniteLoop.jimple @@ -1,4 +1,4 @@ -synchronized class InfiniteLoop extends java.lang.Object +super class InfiniteLoop extends java.lang.Object { void stmtLoop() { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/Initialize3DimensionalArrays.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/Initialize3DimensionalArrays.jimple index 605b2abc8f5..a12a485bde4 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/Initialize3DimensionalArrays.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/Initialize3DimensionalArrays.jimple @@ -1,4 +1,4 @@ -public synchronized class Initialize3DimensionalArrays extends java.lang.Object +public super class Initialize3DimensionalArrays extends java.lang.Object { public void shortArrays() { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/InitializeArraysWhileDeclaration.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/InitializeArraysWhileDeclaration.jimple index 6422f87b2cb..5744763c25c 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/InitializeArraysWhileDeclaration.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/InitializeArraysWhileDeclaration.jimple @@ -1,4 +1,4 @@ -public synchronized class InitializeArraysWhileDeclaration extends java.lang.Object +public super class InitializeArraysWhileDeclaration extends java.lang.Object { public void intArrays() { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/InitializeArraysWithIndex.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/InitializeArraysWithIndex.jimple index 16a0f9f4552..51910cf8385 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/InitializeArraysWithIndex.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/InitializeArraysWithIndex.jimple @@ -1,4 +1,4 @@ -public synchronized class InitializeArraysWithIndex extends java.lang.Object +public super class InitializeArraysWithIndex extends java.lang.Object { public void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/InitializeMultidimensionalArrays.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/InitializeMultidimensionalArrays.jimple index 25ab9edebe8..7c47a177d38 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/InitializeMultidimensionalArrays.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/InitializeMultidimensionalArrays.jimple @@ -1,4 +1,4 @@ -public synchronized class InitializeMultidimensionalArrays extends java.lang.Object +public super class InitializeMultidimensionalArrays extends java.lang.Object { public void doubleArrays() { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/InstanceOfCheck.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/InstanceOfCheck.jimple index 2d7290f4096..97f36272f26 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/InstanceOfCheck.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/InstanceOfCheck.jimple @@ -1,4 +1,4 @@ -synchronized class InstanceOfCheck extends InstanceOfCheckSuper +super class InstanceOfCheck extends InstanceOfCheckSuper { public void instanceOfCheckMethod() { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/InterfaceImplClass.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/InterfaceImplClass.jimple index a2f17c6b8ba..c6aa977d7d1 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/InterfaceImplClass.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/InterfaceImplClass.jimple @@ -1,4 +1,4 @@ -synchronized class InterfaceImplClass extends java.lang.Object implements InterfaceImpl +super class InterfaceImplClass extends java.lang.Object implements InterfaceImpl { void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/LabelStatement.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/LabelStatement.jimple index 1c7d767cbc0..98dea3f9d1e 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/LabelStatement.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/LabelStatement.jimple @@ -1,4 +1,4 @@ -public synchronized class LabelStatement extends java.lang.Object +public super class LabelStatement extends java.lang.Object { public void labelStatement() { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/LabelledLoopBreak.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/LabelledLoopBreak.jimple index a8d7be63a72..127ffe45437 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/LabelledLoopBreak.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/LabelledLoopBreak.jimple @@ -1,4 +1,4 @@ -public synchronized class LabelledLoopBreak extends java.lang.Object +public super class LabelledLoopBreak extends java.lang.Object { public void labelledLoopBreak() { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/MethodAcceptingLamExpr.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/MethodAcceptingLamExpr.jimple index ac52dc7b1fd..edace00f545 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/MethodAcceptingLamExpr.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/MethodAcceptingLamExpr.jimple @@ -1,4 +1,4 @@ -public synchronized class MethodAcceptingLamExpr extends java.lang.Object +public super class MethodAcceptingLamExpr extends java.lang.Object { public void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/MethodAcceptingVar.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/MethodAcceptingVar.jimple index 81d083567be..d0565a31d55 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/MethodAcceptingVar.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/MethodAcceptingVar.jimple @@ -1,4 +1,4 @@ -public synchronized class MethodAcceptingVar extends java.lang.Object +public super class MethodAcceptingVar extends java.lang.Object { public void intVariable(int) { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/MethodOverloading.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/MethodOverloading.jimple index f25f48f1711..8f6fa259202 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/MethodOverloading.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/MethodOverloading.jimple @@ -1,4 +1,4 @@ -synchronized class MethodOverloading extends java.lang.Object +super class MethodOverloading extends java.lang.Object { int calculate(int) { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/MethodOverridingSubclass.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/MethodOverridingSubclass.jimple index bd6e9be0287..28673c8efa6 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/MethodOverridingSubclass.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/MethodOverridingSubclass.jimple @@ -1,4 +1,4 @@ -public synchronized class MethodOverridingSubclass extends MethodOverriding +public super class MethodOverridingSubclass extends MethodOverriding { public void calculateArea() { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/MethodReference.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/MethodReference.jimple index 7c6c37ed880..e433a96e522 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/MethodReference.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/MethodReference.jimple @@ -1,4 +1,4 @@ -public synchronized class MethodReference extends java.lang.Object +public super class MethodReference extends java.lang.Object { public void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/MethodReturningVar.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/MethodReturningVar.jimple index dc202d95490..a956d260a31 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/MethodReturningVar.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/MethodReturningVar.jimple @@ -1,4 +1,4 @@ -public synchronized class MethodReturningVar extends java.lang.Object +public super class MethodReturningVar extends java.lang.Object { public long longVariable() { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/MultiInterfaceImplClass.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/MultiInterfaceImplClass.jimple index 1d961f839c2..779e95fb235 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/MultiInterfaceImplClass.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/MultiInterfaceImplClass.jimple @@ -1,4 +1,4 @@ -synchronized class MultiInterfaceImplClass extends java.lang.Object implements InterfaceImplDummy, InterfaceImpl +super class MultiInterfaceImplClass extends java.lang.Object implements InterfaceImplDummy, InterfaceImpl { public void interfaceMethod() { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/MultiTryCatch.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/MultiTryCatch.jimple index 6c6e38e610c..5f9d8bbce24 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/MultiTryCatch.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/MultiTryCatch.jimple @@ -1,4 +1,4 @@ -synchronized class MultiTryCatch extends java.lang.Object +super class MultiTryCatch extends java.lang.Object { public void printFile() throws java.lang.Exception { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/NamedClassInsideMethod.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/NamedClassInsideMethod.jimple index f21714ac357..12e167b6c55 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/NamedClassInsideMethod.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/NamedClassInsideMethod.jimple @@ -1,4 +1,4 @@ -public synchronized class NamedClassInsideMethod extends java.lang.Object +public super class NamedClassInsideMethod extends java.lang.Object { public void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/NativeMethod.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/NativeMethod.jimple index c418674c8b8..ccb5ddf5a8e 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/NativeMethod.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/NativeMethod.jimple @@ -1,4 +1,4 @@ -public synchronized class NativeMethod extends java.lang.Object +public super class NativeMethod extends java.lang.Object { public void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/NewCodeBlockInMethod.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/NewCodeBlockInMethod.jimple index e1ec44d89b4..5143918fa55 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/NewCodeBlockInMethod.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/NewCodeBlockInMethod.jimple @@ -1,4 +1,4 @@ -public synchronized class NewCodeBlockInMethod extends java.lang.Object +public super class NewCodeBlockInMethod extends java.lang.Object { public void newCodeBlockInMethod() { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/NoModifierClass.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/NoModifierClass.jimple index 025c6ef5ad0..f1528d1c282 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/NoModifierClass.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/NoModifierClass.jimple @@ -1,4 +1,4 @@ -synchronized class NoModifierClass extends java.lang.Object +super class NoModifierClass extends java.lang.Object { void noModifierMethod() { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/NullVariable.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/NullVariable.jimple index cea1d3c4d8d..d624c5610e6 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/NullVariable.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/NullVariable.jimple @@ -1,4 +1,4 @@ -public synchronized class NullVariable extends java.lang.Object +public super class NullVariable extends java.lang.Object { public void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/PrivateMethodInterfaceImpl.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/PrivateMethodInterfaceImpl.jimple index 09490fe10c9..65ad0cd4aef 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/PrivateMethodInterfaceImpl.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/PrivateMethodInterfaceImpl.jimple @@ -1,4 +1,4 @@ -public synchronized class PrivateMethodInterfaceImpl extends java.lang.Object implements PrivateMethodInterface +public super class PrivateMethodInterfaceImpl extends java.lang.Object implements PrivateMethodInterface { public void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/PublicClass.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/PublicClass.jimple index 3558dbe868d..1e98eacc23c 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/PublicClass.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/PublicClass.jimple @@ -1,4 +1,4 @@ -public synchronized class PublicClass extends java.lang.Object +public super class PublicClass extends java.lang.Object { public void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/ReferenceVarDeclaration.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/ReferenceVarDeclaration.jimple index 4480357eefc..5152689bbd0 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/ReferenceVarDeclaration.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/ReferenceVarDeclaration.jimple @@ -1,4 +1,4 @@ -public synchronized class ReferenceVarDeclaration extends java.lang.Object +public super class ReferenceVarDeclaration extends java.lang.Object { public void stringVariable() { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/ReferencingThis.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/ReferencingThis.jimple index 9d595976f99..0a0619de392 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/ReferencingThis.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/ReferencingThis.jimple @@ -1,4 +1,4 @@ -synchronized class ReferencingThis extends java.lang.Object +super class ReferencingThis extends java.lang.Object { int b; diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/Reflection.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/Reflection.jimple index f44ce858fe6..8e207274d60 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/Reflection.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/Reflection.jimple @@ -1,4 +1,4 @@ -public synchronized class Reflection extends java.lang.Object +public super class Reflection extends java.lang.Object { private java.lang.String s; diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/StatementEval.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/StatementEval.jimple index 4d3dbcedd31..46e7d072bc3 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/StatementEval.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/StatementEval.jimple @@ -1,4 +1,4 @@ -public synchronized class StatementEval extends java.lang.Object +public super class StatementEval extends java.lang.Object { public void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/StaticImport.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/StaticImport.jimple index e2e9142e558..40dee2def3d 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/StaticImport.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/StaticImport.jimple @@ -1,4 +1,4 @@ -synchronized class StaticImport extends java.lang.Object +super class StaticImport extends java.lang.Object { public static void main(java.lang.String[]) { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/StaticInitializer.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/StaticInitializer.jimple index 6e05548a90a..734ab476518 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/StaticInitializer.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/StaticInitializer.jimple @@ -1,4 +1,4 @@ -public synchronized class StaticInitializer extends java.lang.Object +public super class StaticInitializer extends java.lang.Object { static int i; diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/StaticMethod.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/StaticMethod.jimple index 6e9cf417844..3b5448e23c7 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/StaticMethod.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/StaticMethod.jimple @@ -1,4 +1,4 @@ -public synchronized class StaticMethod extends java.lang.Object +public super class StaticMethod extends java.lang.Object { public void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/StaticMethodInterfaceImpl.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/StaticMethodInterfaceImpl.jimple index b6babb2649b..cad26fc1e8a 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/StaticMethodInterfaceImpl.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/StaticMethodInterfaceImpl.jimple @@ -1,4 +1,4 @@ -synchronized class StaticMethodInterfaceImpl extends java.lang.Object implements StaticMethodInterface +super class StaticMethodInterfaceImpl extends java.lang.Object implements StaticMethodInterface { public static void initStatic() { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/StaticMethodInvocation.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/StaticMethodInvocation.jimple index ceb71a14c65..50484b649e8 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/StaticMethodInvocation.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/StaticMethodInvocation.jimple @@ -1,4 +1,4 @@ -public synchronized class StaticMethodInvocation extends java.lang.Object +public super class StaticMethodInvocation extends java.lang.Object { public void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/StaticVariable.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/StaticVariable.jimple index 3ab9a4c6172..5f2edebef1c 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/StaticVariable.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/StaticVariable.jimple @@ -1,4 +1,4 @@ -public synchronized class StaticVariable extends java.lang.Object +public super class StaticVariable extends java.lang.Object { static int num; diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/StringConcatenation.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/StringConcatenation.jimple index c0659f1f193..6ea6ede4bc0 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/StringConcatenation.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/StringConcatenation.jimple @@ -1,4 +1,4 @@ -public synchronized class StringConcatenation extends java.lang.Object +public super class StringConcatenation extends java.lang.Object { public void stringConcatenation() { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/StringWithUnicodeChar.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/StringWithUnicodeChar.jimple index 68fe1cc599c..ec036b85842 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/StringWithUnicodeChar.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/StringWithUnicodeChar.jimple @@ -1,4 +1,4 @@ -public synchronized class StringWithUnicodeChar extends java.lang.Object +public super class StringWithUnicodeChar extends java.lang.Object { public void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/SubClass.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/SubClass.jimple index 32c3534a1d3..fd10b303d36 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/SubClass.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/SubClass.jimple @@ -1,4 +1,4 @@ -synchronized class SubClass extends SuperClass +super class SubClass extends SuperClass { int cc; diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/SuperClass.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/SuperClass.jimple index 8ef1e6b8e83..09056f0d979 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/SuperClass.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/SuperClass.jimple @@ -1,4 +1,4 @@ -synchronized class SuperClass extends java.lang.Object +super class SuperClass extends java.lang.Object { int c; diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/SwitchCaseStatement.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/SwitchCaseStatement.jimple index 841b4611bfd..83f5c1955c2 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/SwitchCaseStatement.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/SwitchCaseStatement.jimple @@ -1,4 +1,4 @@ -public synchronized class SwitchCaseStatement extends java.lang.Object +public super class SwitchCaseStatement extends java.lang.Object { public void switchCaseGroupedTargetsDefault() { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/SwitchCaseStatementWithString.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/SwitchCaseStatementWithString.jimple index 4b7fa50753c..de38f88bf05 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/SwitchCaseStatementWithString.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/SwitchCaseStatementWithString.jimple @@ -1,4 +1,4 @@ -public synchronized class SwitchCaseStatementWithString extends java.lang.Object +public super class SwitchCaseStatementWithString extends java.lang.Object { public void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/SymbolsAsMethodName.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/SymbolsAsMethodName.jimple index 14f1473b62a..447bd1129d8 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/SymbolsAsMethodName.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/SymbolsAsMethodName.jimple @@ -1,4 +1,4 @@ -public synchronized class SymbolsAsMethodName extends java.lang.Object +public super class SymbolsAsMethodName extends java.lang.Object { public void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/SynchronizedBlock.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/SynchronizedBlock.jimple index b7a4fee0986..732ca61c671 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/SynchronizedBlock.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/SynchronizedBlock.jimple @@ -1,4 +1,4 @@ -public synchronized class SynchronizedBlock extends java.lang.Object +public super class SynchronizedBlock extends java.lang.Object { private java.lang.String msg; diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/SynchronizedMethod.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/SynchronizedMethod.jimple index ccb0f8a11a9..bdae1fb6ac7 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/SynchronizedMethod.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/SynchronizedMethod.jimple @@ -1,4 +1,4 @@ -public synchronized class SynchronizedMethod extends java.lang.Object +public super class SynchronizedMethod extends java.lang.Object { public void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/TernaryOperator.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/TernaryOperator.jimple index aa0ef64ebb5..8786083999b 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/TernaryOperator.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/TernaryOperator.jimple @@ -1,4 +1,4 @@ -public synchronized class TernaryOperator extends java.lang.Object +public super class TernaryOperator extends java.lang.Object { int num; diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/ThrowExceptionMethod.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/ThrowExceptionMethod.jimple index dc2322dc1e6..7003be11f91 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/ThrowExceptionMethod.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/ThrowExceptionMethod.jimple @@ -1,4 +1,4 @@ -synchronized class ThrowExceptionMethod extends java.lang.Object +super class ThrowExceptionMethod extends java.lang.Object { public static void main(java.lang.String[]) { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/TransientVariable.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/TransientVariable.jimple index 1c49a086e1e..a71707db504 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/TransientVariable.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/TransientVariable.jimple @@ -1,4 +1,4 @@ -synchronized class TransientVariable extends java.lang.Object +super class TransientVariable extends java.lang.Object { transient int transientVar; diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/TryCatchFinally.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/TryCatchFinally.jimple index 2c7fd3b860d..22b774f241b 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/TryCatchFinally.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/TryCatchFinally.jimple @@ -1,4 +1,4 @@ -public synchronized class TryCatchFinally extends java.lang.Object +public super class TryCatchFinally extends java.lang.Object { public void tryCatch() { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/TryWithResources.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/TryWithResources.jimple index 7f382666c9d..e02fdf0806b 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/TryWithResources.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/TryWithResources.jimple @@ -1,4 +1,4 @@ -synchronized class TryWithResources extends java.lang.Object +super class TryWithResources extends java.lang.Object { void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/TryWithResourcesConcise.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/TryWithResourcesConcise.jimple index 5794416b7e1..2636212f7ec 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/TryWithResourcesConcise.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/TryWithResourcesConcise.jimple @@ -1,4 +1,4 @@ -public synchronized class TryWithResourcesConcise extends java.lang.Object +public super class TryWithResourcesConcise extends java.lang.Object { public void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/TypeInference.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/TypeInference.jimple index d08722580c1..3e07e1bb09a 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/TypeInference.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/TypeInference.jimple @@ -1,4 +1,4 @@ -synchronized class TypeInference extends java.lang.Object +super class TypeInference extends java.lang.Object { void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/UnaryOpInt.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/UnaryOpInt.jimple index a6a3b1f60ac..d194b2586b2 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/UnaryOpInt.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/UnaryOpInt.jimple @@ -1,4 +1,4 @@ -synchronized class UnaryOpInt extends java.lang.Object +super class UnaryOpInt extends java.lang.Object { int i; diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/UncheckedCast.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/UncheckedCast.jimple index fb3650d541c..9c3cda58f1b 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/UncheckedCast.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/UncheckedCast.jimple @@ -1,4 +1,4 @@ -synchronized class UncheckedCast extends java.lang.Object +super class UncheckedCast extends java.lang.Object { void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/UnderscoreInInt.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/UnderscoreInInt.jimple index da09283a495..5cab82302cb 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/UnderscoreInInt.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/UnderscoreInInt.jimple @@ -1,4 +1,4 @@ -public synchronized class UnderscoreInInt extends java.lang.Object +public super class UnderscoreInInt extends java.lang.Object { public void () { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/VariableDeclaration.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/VariableDeclaration.jimple index 0b2a4646818..61af24fb346 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/VariableDeclaration.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/VariableDeclaration.jimple @@ -1,4 +1,4 @@ -public synchronized class VariableDeclaration extends java.lang.Object +public super class VariableDeclaration extends java.lang.Object { public void shortVariable() { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/VariableShadowing.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/VariableShadowing.jimple index c7b8d604402..083e698ace8 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/VariableShadowing.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/VariableShadowing.jimple @@ -1,4 +1,4 @@ -public synchronized class VariableShadowing extends java.lang.Object +public super class VariableShadowing extends java.lang.Object { int num; diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/VirtualMethod.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/VirtualMethod.jimple index c251d0040dd..5351b1511b7 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/VirtualMethod.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/VirtualMethod.jimple @@ -1,4 +1,4 @@ -synchronized class VirtualMethod extends java.lang.Object +super class VirtualMethod extends java.lang.Object { public static void main(java.lang.String[]) { diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/VolatileVariable.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/VolatileVariable.jimple index 092b511c6a5..da5f73c3b23 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/VolatileVariable.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/VolatileVariable.jimple @@ -1,4 +1,4 @@ -synchronized class VolatileVariable extends java.lang.Object +super class VolatileVariable extends java.lang.Object { public volatile int counter; diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/WhileLoop.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/WhileLoop.jimple index c7116ee2764..c2f89618b92 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/WhileLoop.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/WhileLoop.jimple @@ -1,4 +1,4 @@ -public synchronized class WhileLoop extends java.lang.Object +public super class WhileLoop extends java.lang.Object { public void whileLoop() { diff --git "a/sootup.jimple.parser/src/test/java/resources/jimple/\316\261\317\201\316\265\317\204\316\267.jimple" "b/sootup.jimple.parser/src/test/java/resources/jimple/\316\261\317\201\316\265\317\204\316\267.jimple" index 231d39dff2b..de1f3b7f2d6 100644 --- "a/sootup.jimple.parser/src/test/java/resources/jimple/\316\261\317\201\316\265\317\204\316\267.jimple" +++ "b/sootup.jimple.parser/src/test/java/resources/jimple/\316\261\317\201\316\265\317\204\316\267.jimple" @@ -1,4 +1,4 @@ -public synchronized class \u03b1\u03c1\u03b5\u03c4\u03b7 extends java.lang.Object +public super class \u03b1\u03c1\u03b5\u03c4\u03b7 extends java.lang.Object { public void () { From 6adb3bf8b68ae09a7872aed077d0f9c39683bda3 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Tue, 1 Aug 2023 15:29:53 +0200 Subject: [PATCH 49/90] use == as well --- .../bytecode/interceptors/typeresolving/BytecodeHierarchy.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/BytecodeHierarchy.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/BytecodeHierarchy.java index 71b9632e8d0..2eb6fbc1f32 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/BytecodeHierarchy.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/BytecodeHierarchy.java @@ -112,7 +112,7 @@ public Collection getLeastCommonAncestor(Type a, Type b) { if (b instanceof BottomType) { return Collections.singleton(a); } - if (a instanceof NullType) { + if (a == NullType.getInstance()) { return Collections.singleton(b); } if (b instanceof NullType) { From 4e10853ee5cc116e2041aa2a7f8e31b7410ac8ce Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Tue, 1 Aug 2023 15:31:15 +0200 Subject: [PATCH 50/90] and for b too --- .../bytecode/interceptors/typeresolving/BytecodeHierarchy.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/BytecodeHierarchy.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/BytecodeHierarchy.java index 2eb6fbc1f32..bc154fcd05a 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/BytecodeHierarchy.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/BytecodeHierarchy.java @@ -115,7 +115,7 @@ public Collection getLeastCommonAncestor(Type a, Type b) { if (a == NullType.getInstance()) { return Collections.singleton(b); } - if (b instanceof NullType) { + if (b == NullType.getInstance()) { return Collections.singleton(a); } if (isAncestor(a, b)) { From 489f1510788d12deafa8002526d164ea10f2e0dc Mon Sep 17 00:00:00 2001 From: Jonas Klauke Date: Tue, 1 Aug 2023 15:45:09 +0200 Subject: [PATCH 51/90] adapted the parser grammar to the new modifiers --- .../src/main/antlr4/sootup/jimple/Jimple.g4 | 16 +++++++++++----- .../sootup/jimple/parser/JimpleConverter.java | 16 +++++++++------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/sootup.jimple.parser/src/main/antlr4/sootup/jimple/Jimple.g4 b/sootup.jimple.parser/src/main/antlr4/sootup/jimple/Jimple.g4 index 553c593fd3a..955d9621703 100644 --- a/sootup.jimple.parser/src/main/antlr4/sootup/jimple/Jimple.g4 +++ b/sootup.jimple.parser/src/main/antlr4/sootup/jimple/Jimple.g4 @@ -123,13 +123,19 @@ grammar Jimple; (PLUS|MINUS)? (DEC_CONSTANT | HEX_CONSTANT ) 'L'?; file: - importItem* modifier* file_type classname=IDENTIFIER extends_clause? implements_clause? L_BRACE member* R_BRACE EOF; + importItem* class_modifier* file_type classname=IDENTIFIER extends_clause? implements_clause? L_BRACE member* R_BRACE EOF; importItem: 'import' location=identifier SEMICOLON; - modifier : - 'abstract' | 'final' | 'native' | 'public' | 'protected' | 'private' | 'static' | 'synchronized' | 'transient' |'volatile' | 'strictfp' | 'enum'; + class_modifier : + 'abstract' | 'final' | 'public' | 'protected' | 'private' | 'static' | 'super' | 'enum' | 'synthetic'; + + method_modifier : + 'abstract' | 'final' | 'native' | 'public' | 'protected' | 'private' | 'static' | 'synchronized' | 'varargs'| 'bridge' | 'strictfp' | 'enum'| 'synthetic'; + + field_modifier : + 'final' | 'public' | 'protected' | 'private' | 'static' | 'transient' | 'volatile' | 'enum'| 'synthetic'; file_type : CLASS | 'interface' | 'annotation interface'; @@ -151,10 +157,10 @@ grammar Jimple; field | method; field : - modifier* type identifier SEMICOLON; + field_modifier* type identifier SEMICOLON; method : - modifier* method_subsignature throws_clause? method_body; + method_modifier* method_subsignature throws_clause? method_body; method_name : '' | '' | identifier; diff --git a/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleConverter.java b/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleConverter.java index f2cfdc03e91..6dda6e812b3 100644 --- a/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleConverter.java +++ b/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleConverter.java @@ -135,7 +135,7 @@ public Boolean visitFile(@Nonnull JimpleParser.FileContext ctx) { "Classname is not well formed.", path, JimpleConverterUtil.buildPositionFromCtx(ctx)); } - modifiers = getClassModifiers(ctx.modifier()); + modifiers = getClassModifiers(ctx.class_modifier()); // file_type if (ctx.file_type() != null) { if (ctx.file_type().getText().equals("interface")) { @@ -177,7 +177,7 @@ public Boolean visitFile(@Nonnull JimpleParser.FileContext ctx) { } else { final JimpleParser.FieldContext fieldCtx = ctx.member(i).field(); - EnumSet modifier = getFieldModifiers(fieldCtx.modifier()); + EnumSet modifier = getFieldModifiers(fieldCtx.field_modifier()); final Position pos = JimpleConverterUtil.buildPositionFromCtx(fieldCtx); final String fieldName = Jimple.unescape(fieldCtx.identifier().getText()); final SootField f = @@ -196,20 +196,22 @@ public Boolean visitFile(@Nonnull JimpleParser.FileContext ctx) { return true; } - private EnumSet getClassModifiers(List modifier) { + private EnumSet getClassModifiers( + List modifier) { return modifier.stream() .map(modContext -> ClassModifier.valueOf(modContext.getText().toUpperCase())) .collect(Collectors.toCollection(() -> EnumSet.noneOf(ClassModifier.class))); } private EnumSet getMethodModifiers( - List modifier) { + List modifier) { return modifier.stream() .map(modContext -> MethodModifier.valueOf(modContext.getText().toUpperCase())) .collect(Collectors.toCollection(() -> EnumSet.noneOf(MethodModifier.class))); } - private EnumSet getFieldModifiers(List modifier) { + private EnumSet getFieldModifiers( + List modifier) { return modifier.stream() .map(modContext -> FieldModifier.valueOf(modContext.getText().toUpperCase())) .collect(Collectors.toCollection(() -> EnumSet.noneOf(FieldModifier.class))); @@ -231,9 +233,9 @@ public Local getLocal(@Nonnull String name) { public SootMethod visitMethod(@Nonnull JimpleParser.MethodContext ctx) { EnumSet modifier = - ctx.modifier() == null + ctx.method_modifier() == null ? EnumSet.noneOf(MethodModifier.class) - : getMethodModifiers(ctx.modifier()); + : getMethodModifiers(ctx.method_modifier()); final JimpleParser.Method_subsignatureContext method_subsignatureContext = ctx.method_subsignature(); From 2c1dfdc5d58012f7939bfd9477b59de2fd1ad006 Mon Sep 17 00:00:00 2001 From: Jonas Klauke Date: Tue, 1 Aug 2023 15:56:30 +0200 Subject: [PATCH 52/90] combined common modifiers of all three modifier types --- .../src/main/antlr4/sootup/jimple/Jimple.g4 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sootup.jimple.parser/src/main/antlr4/sootup/jimple/Jimple.g4 b/sootup.jimple.parser/src/main/antlr4/sootup/jimple/Jimple.g4 index 955d9621703..31082f1cd23 100644 --- a/sootup.jimple.parser/src/main/antlr4/sootup/jimple/Jimple.g4 +++ b/sootup.jimple.parser/src/main/antlr4/sootup/jimple/Jimple.g4 @@ -128,14 +128,17 @@ grammar Jimple; importItem: 'import' location=identifier SEMICOLON; + common_modifier : + 'final' | 'public' | 'protected' | 'private' | 'static' | 'enum'| 'synthetic'; + class_modifier : - 'abstract' | 'final' | 'public' | 'protected' | 'private' | 'static' | 'super' | 'enum' | 'synthetic'; + common_modifier | 'abstract' | 'super'; method_modifier : - 'abstract' | 'final' | 'native' | 'public' | 'protected' | 'private' | 'static' | 'synchronized' | 'varargs'| 'bridge' | 'strictfp' | 'enum'| 'synthetic'; + common_modifier | 'abstract' | 'native' | 'synchronized' | 'varargs'| 'bridge' | 'strictfp'; field_modifier : - 'final' | 'public' | 'protected' | 'private' | 'static' | 'transient' | 'volatile' | 'enum'| 'synthetic'; + common_modifier | 'transient' | 'volatile'; file_type : CLASS | 'interface' | 'annotation interface'; From 9b917d9b9e3be31bc1cd33c631a8bc601da40d45 Mon Sep 17 00:00:00 2001 From: Jonas Klauke <97177448+JonasKlauke@users.noreply.github.com> Date: Tue, 1 Aug 2023 16:16:31 +0200 Subject: [PATCH 53/90] revert combined imports --- .../test/java/sootup/jimple/parser/JimpleConverterTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sootup.jimple.parser/src/test/java/sootup/jimple/parser/JimpleConverterTest.java b/sootup.jimple.parser/src/test/java/sootup/jimple/parser/JimpleConverterTest.java index 5ee379e18a3..b03de575d51 100644 --- a/sootup.jimple.parser/src/test/java/sootup/jimple/parser/JimpleConverterTest.java +++ b/sootup.jimple.parser/src/test/java/sootup/jimple/parser/JimpleConverterTest.java @@ -14,7 +14,10 @@ import sootup.core.frontend.ResolveException; import sootup.core.inputlocation.EagerInputLocation; import sootup.core.jimple.Jimple; -import sootup.core.model.*; +import sootup.core.model.Body; +import sootup.core.model.SootClass; +import sootup.core.model.SootMethod; +import sootup.core.model.SourceType; import sootup.core.signatures.MethodSubSignature; import sootup.core.types.PrimitiveType; import sootup.core.types.VoidType; From 42eabe81b2813669b3405acc3c76966f456cf88c Mon Sep 17 00:00:00 2001 From: Jonas Klauke Date: Tue, 1 Aug 2023 16:29:35 +0200 Subject: [PATCH 54/90] added missing import and removed warnings --- .../java/sootup/jimple/parser/JimpleConverterTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sootup.jimple.parser/src/test/java/sootup/jimple/parser/JimpleConverterTest.java b/sootup.jimple.parser/src/test/java/sootup/jimple/parser/JimpleConverterTest.java index b03de575d51..3567237747b 100644 --- a/sootup.jimple.parser/src/test/java/sootup/jimple/parser/JimpleConverterTest.java +++ b/sootup.jimple.parser/src/test/java/sootup/jimple/parser/JimpleConverterTest.java @@ -16,6 +16,7 @@ import sootup.core.jimple.Jimple; import sootup.core.model.Body; import sootup.core.model.SootClass; +import sootup.core.model.SootField; import sootup.core.model.SootMethod; import sootup.core.model.SourceType; import sootup.core.signatures.MethodSubSignature; @@ -578,7 +579,7 @@ public void testSingleQuoteEscapeSeq() { CharStream cs = CharStreams.fromString( "public class class extends java.lang.Object implements java.lang.'annotation'.Annotation\n {}"); - SootClass sc = parseJimpleClass(cs); + parseJimpleClass(cs); fail("escaping is needed"); } catch (Exception ignored) { } @@ -616,7 +617,7 @@ public void testSingleQuoteEscapeSeq() { CharStreams.fromString( "public class \"'notescapedquotesinstring'\" extends java.lang.Object \n {}"); try { - SootClass sc = parseJimpleClass(cs); + parseJimpleClass(cs); fail("\" is not allowed in identifiers"); } catch (Exception ignore) { } @@ -638,7 +639,7 @@ public void testSingleQuoteEscapeSeq() { try { CharStream cs = CharStreams.fromString("public class \"class' extends java.lang.Object \n {}"); - SootClass sc = parseJimpleClass(cs); + parseJimpleClass(cs); fail("start and end quote do not match."); } catch (Exception ignore) { } From bc479395925ec47fc41c869ed3ce29c699aca9c2 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Wed, 2 Aug 2023 13:46:41 +0200 Subject: [PATCH 55/90] create ctor; use memory efficient variant to store just line numbers --- .../jimple/basic/FullStmtPositionInfo.java | 7 +++--- .../jimple/basic/SimpleStmtPositionInfo.java | 16 ++----------- .../core/jimple/basic/StmtPositionInfo.java | 23 ++----------------- .../java/sootup/core/model/LinePosition.java | 6 ++++- 4 files changed, 12 insertions(+), 40 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/jimple/basic/FullStmtPositionInfo.java b/sootup.core/src/main/java/sootup/core/jimple/basic/FullStmtPositionInfo.java index 058e4fdc1bc..dfa3a785388 100644 --- a/sootup.core/src/main/java/sootup/core/jimple/basic/FullStmtPositionInfo.java +++ b/sootup.core/src/main/java/sootup/core/jimple/basic/FullStmtPositionInfo.java @@ -23,7 +23,6 @@ */ import javax.annotation.Nonnull; -import sootup.core.model.FullPosition; import sootup.core.model.Position; import sootup.core.util.Copyable; @@ -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. @@ -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; } @@ -94,7 +93,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); } } diff --git a/sootup.core/src/main/java/sootup/core/jimple/basic/SimpleStmtPositionInfo.java b/sootup.core/src/main/java/sootup/core/jimple/basic/SimpleStmtPositionInfo.java index 10275f0fa13..7f30a58d2fa 100644 --- a/sootup.core/src/main/java/sootup/core/jimple/basic/SimpleStmtPositionInfo.java +++ b/sootup.core/src/main/java/sootup/core/jimple/basic/SimpleStmtPositionInfo.java @@ -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; /** @@ -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 @@ -67,16 +67,4 @@ public String toString() { 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; - } } diff --git a/sootup.core/src/main/java/sootup/core/jimple/basic/StmtPositionInfo.java b/sootup.core/src/main/java/sootup/core/jimple/basic/StmtPositionInfo.java index b65dddd380b..692732326e7 100644 --- a/sootup.core/src/main/java/sootup/core/jimple/basic/StmtPositionInfo.java +++ b/sootup.core/src/main/java/sootup/core/jimple/basic/StmtPositionInfo.java @@ -24,7 +24,6 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import sootup.core.model.FullPosition; import sootup.core.model.Position; /** @@ -34,7 +33,7 @@ */ public abstract class StmtPositionInfo { - protected static final StmtPositionInfo noPosition = + protected static final StmtPositionInfo NOPOSITION = new StmtPositionInfo() { @Nonnull @Override @@ -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; - } }; /** @@ -72,7 +59,7 @@ public StmtPositionInfo withOperandPositions(@Nonnull FullPosition[] operandPosi */ @Nonnull public static StmtPositionInfo createNoStmtPositionInfo() { - return noPosition; + return NOPOSITION; } /** @@ -94,10 +81,4 @@ public static StmtPositionInfo createNoStmtPositionInfo() { @Override public abstract String toString(); - - @Nonnull - public abstract StmtPositionInfo withStmtPosition(@Nonnull Position stmtPosition); - - @Nonnull - public abstract StmtPositionInfo withOperandPositions(@Nonnull FullPosition[] operandPositions); } diff --git a/sootup.core/src/main/java/sootup/core/model/LinePosition.java b/sootup.core/src/main/java/sootup/core/model/LinePosition.java index 8dc130eadb2..624ffa88fb8 100644 --- a/sootup.core/src/main/java/sootup/core/model/LinePosition.java +++ b/sootup.core/src/main/java/sootup/core/model/LinePosition.java @@ -1,7 +1,11 @@ package sootup.core.model; public class LinePosition extends Position { - int lineNo; + private final int lineNo; + + public LinePosition(int lineNo) { + this.lineNo = lineNo; + } @Override public int getFirstLine() { From 70873efb680644b4a60a8dc4cb6c14f271c18881 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Thu, 3 Aug 2023 17:53:50 +0200 Subject: [PATCH 56/90] fixed nonnull. dry toString --- .../core/jimple/basic/FullStmtPositionInfo.java | 13 ++++--------- .../core/jimple/basic/SimpleStmtPositionInfo.java | 6 ------ .../sootup/core/jimple/basic/StmtPositionInfo.java | 6 +++++- .../frontend/WalaIRToJimpleConverter.java | 2 +- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/jimple/basic/FullStmtPositionInfo.java b/sootup.core/src/main/java/sootup/core/jimple/basic/FullStmtPositionInfo.java index dfa3a785388..98dab8e2641 100644 --- a/sootup.core/src/main/java/sootup/core/jimple/basic/FullStmtPositionInfo.java +++ b/sootup.core/src/main/java/sootup/core/jimple/basic/FullStmtPositionInfo.java @@ -64,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(); @@ -74,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(); } diff --git a/sootup.core/src/main/java/sootup/core/jimple/basic/SimpleStmtPositionInfo.java b/sootup.core/src/main/java/sootup/core/jimple/basic/SimpleStmtPositionInfo.java index 7f30a58d2fa..546cbe7a110 100644 --- a/sootup.core/src/main/java/sootup/core/jimple/basic/SimpleStmtPositionInfo.java +++ b/sootup.core/src/main/java/sootup/core/jimple/basic/SimpleStmtPositionInfo.java @@ -61,10 +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(); - } } diff --git a/sootup.core/src/main/java/sootup/core/jimple/basic/StmtPositionInfo.java b/sootup.core/src/main/java/sootup/core/jimple/basic/StmtPositionInfo.java index 692732326e7..769eb1bdf1b 100644 --- a/sootup.core/src/main/java/sootup/core/jimple/basic/StmtPositionInfo.java +++ b/sootup.core/src/main/java/sootup/core/jimple/basic/StmtPositionInfo.java @@ -80,5 +80,9 @@ public static StmtPositionInfo createNoStmtPositionInfo() { public abstract Position getOperandPosition(int index); @Override - public abstract String toString(); + public String toString() { + StringBuilder s = new StringBuilder(); + s.append("stmt at:").append(getStmtPosition()); + return s.toString(); + } } diff --git a/sootup.java.sourcecode/src/main/java/sootup/java/sourcecode/frontend/WalaIRToJimpleConverter.java b/sootup.java.sourcecode/src/main/java/sootup/java/sourcecode/frontend/WalaIRToJimpleConverter.java index 4094732a53d..a204eec586d 100644 --- a/sootup.java.sourcecode/src/main/java/sootup/java/sourcecode/frontend/WalaIRToJimpleConverter.java +++ b/sootup.java.sourcecode/src/main/java/sootup/java/sourcecode/frontend/WalaIRToJimpleConverter.java @@ -645,7 +645,7 @@ public static StmtPositionInfo convertPositionInfo( Position instructionPosition, Position[] operandPosition) { if (operandPosition == null) { - return new FullStmtPositionInfo(convertPosition(instructionPosition), null); + return new SimpleStmtPositionInfo(convertPosition(instructionPosition)); } FullPosition[] operandPos = Arrays.stream(operandPosition) From 453bb7bd0d774056ce873cb49b6c5b31a7e24b40 Mon Sep 17 00:00:00 2001 From: Jonas Klauke Date: Fri, 11 Aug 2023 17:53:16 +0200 Subject: [PATCH 57/90] used FieldSignature instead of FieldRef in MethodHandle --- .../core/jimple/common/constant/MethodHandle.java | 14 ++++++++------ .../java/bytecode/frontend/AsmMethodSource.java | 9 ++++++++- .../java/sootup/java/core/language/JavaJimple.java | 4 ++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/jimple/common/constant/MethodHandle.java b/sootup.core/src/main/java/sootup/core/jimple/common/constant/MethodHandle.java index d7e0bf53303..58cfd51cd75 100644 --- a/sootup.core/src/main/java/sootup/core/jimple/common/constant/MethodHandle.java +++ b/sootup.core/src/main/java/sootup/core/jimple/common/constant/MethodHandle.java @@ -23,8 +23,8 @@ */ import javax.annotation.Nonnull; -import sootup.core.jimple.common.ref.JFieldRef; import sootup.core.jimple.visitor.ConstantVisitor; +import sootup.core.signatures.FieldSignature; import sootup.core.signatures.MethodSignature; import sootup.core.types.Type; @@ -80,19 +80,19 @@ public static Kind getKind(String kind) { } private final MethodSignature methodSignature; - private final JFieldRef fieldRef; + private final FieldSignature fieldSignature; public int tag; public MethodHandle(MethodSignature methodSignature, int tag, Type type) { this.methodSignature = methodSignature; this.tag = tag; - this.fieldRef = null; + this.fieldSignature = null; this.type = type; } - public MethodHandle(JFieldRef ref, int tag, Type type) { - this.fieldRef = ref; + public MethodHandle(FieldSignature ref, int tag, Type type) { + this.fieldSignature = ref; this.tag = tag; this.methodSignature = null; this.type = type; @@ -110,7 +110,9 @@ public static boolean isMethodRef(int kind) { // FIXME: [ms] serialize in a way it can be restored with the same parameters; adapt Jimple.g4 and // JimpleConverter.java public String toString() { - return "handle: " + methodSignature; + return "handle: " + + (methodSignature == null ? "" : methodSignature) + + (fieldSignature == null ? "" : fieldSignature); } @Nonnull diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java index 536a6619dfb..db76ca5dd91 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java @@ -1148,7 +1148,7 @@ private Immediate toSootValue(@Nonnull Object val) throws UnsupportedOperationEx } else { v = JavaJimple.getInstance() - .newMethodHandle(toSootFieldRef((Handle) val), ((Handle) val).getTag()); + .newMethodHandle(toSootFieldSignature((Handle) val), ((Handle) val).getTag()); } } else { throw new UnsupportedOperationException("Unknown constant type: " + val.getClass()); @@ -1172,6 +1172,13 @@ private JFieldRef toSootFieldRef(Handle methodHandle) { } } + private FieldSignature toSootFieldSignature(Handle methodHandle) { + String bsmClsName = AsmUtil.toQualifiedName(methodHandle.getOwner()); + JavaClassType bsmCls = identifierFactory.getClassType(bsmClsName); + Type t = AsmUtil.toJimpleSignatureDesc(methodHandle.getDesc()).get(0); + return identifierFactory.getFieldSignature(methodHandle.getName(), bsmCls, t); + } + private MethodSignature toMethodSignature(Handle methodHandle) { String bsmClsName = AsmUtil.toQualifiedName(methodHandle.getOwner()); JavaClassType bsmCls = identifierFactory.getClassType(bsmClsName); diff --git a/sootup.java.core/src/main/java/sootup/java/core/language/JavaJimple.java b/sootup.java.core/src/main/java/sootup/java/core/language/JavaJimple.java index 23bc6b44319..3ec7d04c4ca 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/language/JavaJimple.java +++ b/sootup.java.core/src/main/java/sootup/java/core/language/JavaJimple.java @@ -32,7 +32,7 @@ import sootup.core.jimple.common.constant.MethodType; import sootup.core.jimple.common.constant.StringConstant; import sootup.core.jimple.common.ref.JCaughtExceptionRef; -import sootup.core.jimple.common.ref.JFieldRef; +import sootup.core.signatures.FieldSignature; import sootup.core.signatures.MethodSignature; import sootup.core.types.NullType; import sootup.core.types.PrimitiveType; @@ -86,7 +86,7 @@ public StringConstant newStringConstant(String value) { return new StringConstant(value, getIdentifierFactory().getType("java.lang.String")); } - public MethodHandle newMethodHandle(JFieldRef ref, int tag) { + public MethodHandle newMethodHandle(FieldSignature ref, int tag) { return new MethodHandle( ref, tag, getIdentifierFactory().getType("java.lang.invoke.MethodHandle")); } From 5e8fc4a2bd01d3d2b6d52d8b01ebda00939a093a Mon Sep 17 00:00:00 2001 From: Jonas Klauke Date: Fri, 11 Aug 2023 17:53:34 +0200 Subject: [PATCH 58/90] added Test for Records in Java14 --- .../java14/binary/RecordTest.class | Bin 0 -> 1216 bytes .../java14/source/RecordTest.java | 6 +++ .../minimaltestsuite/java14/RecordTest.java | 51 ++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 shared-test-resources/miniTestSuite/java14/binary/RecordTest.class create mode 100644 shared-test-resources/miniTestSuite/java14/source/RecordTest.java create mode 100644 sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java14/RecordTest.java diff --git a/shared-test-resources/miniTestSuite/java14/binary/RecordTest.class b/shared-test-resources/miniTestSuite/java14/binary/RecordTest.class new file mode 100644 index 0000000000000000000000000000000000000000..f10d31483f04146a0c7febafc173050014f7935c GIT binary patch literal 1216 zcmaJ=U2hUW6g?Lx3%C@DZM9-ss;$DdminzheXzzzf*-M@5BfB~q-+bjxVtp*Klxx2 z8xtP<0sbiC9d?mLNFR3Y?A>$ExpVf;?>~cI0G{J%3K2v##B|IdPRJgMQ&H{+>!|!u zHf^Uxh(9we(|bXP7E6aoB#_jQ(s2noA?1VW()9==_^B$yyp9aA{MI1kYGcX+&oQl| zN{*#-Ixb_8knn6jODGg;W4cOdcHOd$E4a#aZQ-`}?Up2DChMw-{+fhR?qf9=Uv(rr3s&$FFy$$m$;Za5Kee4Zu=t4~Zp;8y~BY^SI+G6apEG(oRgmUM<1 z($(;gur)T}fv|!m|}YPEEfWVm0O*;~>61tNdk+-|nj`#W7?2 z1R42rXvWSt(r29Fzr$+|F%oo{I~dNk*8L>-bsV+p)oL#kbCpIBLd#^Z3qN zpGV26{Q_T!8yx=!F9F|Xfb+N+fD7D&I#I&d9$;k_nz*A8^(t2>!8zjxv}s}<+(tKYcfE4|9YfTa!Q;cX5wB1yZd30FUqlD}MpmfC1G2 literal 0 HcmV?d00001 diff --git a/shared-test-resources/miniTestSuite/java14/source/RecordTest.java b/shared-test-resources/miniTestSuite/java14/source/RecordTest.java new file mode 100644 index 00000000000..cc11333dcf5 --- /dev/null +++ b/shared-test-resources/miniTestSuite/java14/source/RecordTest.java @@ -0,0 +1,6 @@ +record RecordTest(int a, String b) { + public RecordTest(int a, String b) { + this.a = a; + this.b = b; + } +} \ No newline at end of file diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java14/RecordTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java14/RecordTest.java new file mode 100644 index 00000000000..154bd616084 --- /dev/null +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java14/RecordTest.java @@ -0,0 +1,51 @@ +package sootup.java.bytecode.minimaltestsuite.java14; + +import categories.Java9Test; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import sootup.core.model.SootMethod; +import sootup.core.signatures.MethodSignature; +import sootup.java.bytecode.minimaltestsuite.MinimalBytecodeTestSuiteBase; +import sootup.java.core.JavaIdentifierFactory; +import sootup.java.core.types.JavaClassType; + +/** @author Jonas Klauke */ +@Category(Java9Test.class) +public class RecordTest extends MinimalBytecodeTestSuiteBase { + + @Override + public JavaClassType getDeclaredClassSignature() { + return JavaIdentifierFactory.getInstance().getClassType("RecordTest"); + } + + @Override + public MethodSignature getMethodSignature() { + System.out.println(getDeclaredClassSignature()); + return identifierFactory.getMethodSignature( + getDeclaredClassSignature(), + "equals", + "boolean", + Collections.singletonList("java.lang.Object")); + } + + @Override + public List expectedBodyStmts() { + return Stream.of( + "l0 := @this: RecordTest", + "l1 := @parameter0: java.lang.Object", + "$stack2 = dynamicinvoke \"equals\" (l0, l1) (class \"LRecordTest;\", \"a;b\", handle: , handle: )", + "return $stack2") + .collect(Collectors.toCollection(ArrayList::new)); + } + + @Test + public void test() { + SootMethod method = loadMethod(getMethodSignature()); + assertJimpleStmts(method, expectedBodyStmts()); + } +} From e544a578b8f6befa5b6b37d98fe1f71e4a99521a Mon Sep 17 00:00:00 2001 From: Jonas Klauke Date: Mon, 14 Aug 2023 18:16:24 +0200 Subject: [PATCH 59/90] added the tag to the methodhandle serialization. Adapted the jimple parser to the new changes --- .../InstantiateClassValueVisitorTest.java | 12 +- .../jimple/common/constant/MethodHandle.java | 109 ++++++++++++------ .../minimaltestsuite/java14/RecordTest.java | 44 ++++++- .../sootup/java/core/language/JavaJimple.java | 12 +- .../src/main/antlr4/sootup/jimple/Jimple.g4 | 5 +- .../sootup/jimple/parser/JimpleConverter.java | 22 ++-- .../jimple/MethodAcceptingLamExpr.jimple | 2 +- .../resources/jimple/MethodReference.jimple | 2 +- .../java8/MethodAcceptingLamExprTest.java | 2 +- 9 files changed, 149 insertions(+), 61 deletions(-) diff --git a/sootup.callgraph/src/test/java/sootup/callgraph/InstantiateClassValueVisitorTest.java b/sootup.callgraph/src/test/java/sootup/callgraph/InstantiateClassValueVisitorTest.java index 7186e18082e..2313bfaea48 100644 --- a/sootup.callgraph/src/test/java/sootup/callgraph/InstantiateClassValueVisitorTest.java +++ b/sootup.callgraph/src/test/java/sootup/callgraph/InstantiateClassValueVisitorTest.java @@ -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; @@ -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) @@ -153,10 +151,10 @@ private void fillList(List listWithAllValues, View 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)); diff --git a/sootup.core/src/main/java/sootup/core/jimple/common/constant/MethodHandle.java b/sootup.core/src/main/java/sootup/core/jimple/common/constant/MethodHandle.java index 58cfd51cd75..fd1792c29e4 100644 --- a/sootup.core/src/main/java/sootup/core/jimple/common/constant/MethodHandle.java +++ b/sootup.core/src/main/java/sootup/core/jimple/common/constant/MethodHandle.java @@ -4,7 +4,7 @@ * #%L * Soot - a J*va Optimization Framework * %% - * Copyright (C) 2005-2020 Jennifer Lhotak, Andreas Dann, Linghui Luo and others + * Copyright (C) 2005-2023 Jennifer Lhotak, Andreas Dann, Linghui, Luo Jonas Klauke and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -26,11 +26,13 @@ import sootup.core.jimple.visitor.ConstantVisitor; import sootup.core.signatures.FieldSignature; import sootup.core.signatures.MethodSignature; +import sootup.core.signatures.SootClassMemberSignature; +import sootup.core.signatures.SootClassMemberSubSignature; import sootup.core.types.Type; public class MethodHandle implements Constant { - private final Type type; + @Nonnull private final Type type; public enum Kind { REF_GET_FIELD(1, "REF_GET_FIELD"), @@ -60,6 +62,10 @@ public int getValue() { return val; } + public String getValueName() { + return valStr; + } + public static Kind getKind(int kind) { for (Kind k : Kind.values()) { if (k.getValue() == kind) { @@ -69,50 +75,83 @@ public static Kind getKind(int kind) { throw new RuntimeException("Error: No method handle kind for value '" + kind + "'."); } - public static Kind getKind(String kind) { + public static Kind getKind(String kindName) { for (Kind k : Kind.values()) { - if (k.toString().equals(kind)) { + if (k.getValueName().equals(kindName)) { return k; } } - throw new RuntimeException("Error: No method handle kind for value '" + kind + "'."); + throw new RuntimeException("Error: No method handle kind for value name '" + kindName + "'."); } } - private final MethodSignature methodSignature; - private final FieldSignature fieldSignature; + @Nonnull + private final SootClassMemberSignature referenceSignature; - public int tag; + @Nonnull private final Kind kind; - public MethodHandle(MethodSignature methodSignature, int tag, Type type) { - this.methodSignature = methodSignature; - this.tag = tag; - this.fieldSignature = null; + public MethodHandle( + @Nonnull SootClassMemberSignature referenceSignature, + int tag, + @Nonnull Type type) { + this.kind = Kind.getKind(tag); this.type = type; + this.referenceSignature = referenceSignature; + if ((this.isMethodRef() && !(referenceSignature instanceof MethodSignature)) + || (this.isFieldRef() && !(referenceSignature instanceof FieldSignature))) { + throw new IllegalArgumentException( + "Tag:" + + tag + + " " + + kind.valStr + + " does not match with the given signature:" + + referenceSignature.getClass()); + } } - public MethodHandle(FieldSignature ref, int tag, Type type) { - this.fieldSignature = ref; - this.tag = tag; - this.methodSignature = null; + public MethodHandle( + @Nonnull SootClassMemberSignature referenceSignature, + @Nonnull MethodHandle.Kind kind, + @Nonnull Type type) { + this.kind = kind; this.type = type; + this.referenceSignature = referenceSignature; + if ((this.isMethodRef() && !(referenceSignature instanceof MethodSignature)) + || (this.isFieldRef() && !(referenceSignature instanceof FieldSignature))) { + throw new IllegalArgumentException( + "Kind:" + + kind.valStr + + " does not match with the given signature:" + + referenceSignature.getClass()); + } } - public static boolean isMethodRef(int kind) { - return kind == Kind.REF_INVOKE_VIRTUAL.getValue() - || kind == Kind.REF_INVOKE_STATIC.getValue() - || kind == Kind.REF_INVOKE_SPECIAL.getValue() - || kind == Kind.REF_INVOKE_CONSTRUCTOR.getValue() - || kind == Kind.REF_INVOKE_INTERFACE.getValue(); + public static boolean isMethodRef(int tag) { + return tag == Kind.REF_INVOKE_VIRTUAL.getValue() + || tag == Kind.REF_INVOKE_STATIC.getValue() + || tag == Kind.REF_INVOKE_SPECIAL.getValue() + || tag == Kind.REF_INVOKE_CONSTRUCTOR.getValue() + || tag == Kind.REF_INVOKE_INTERFACE.getValue(); + } + + public static boolean isFieldRef(int tag) { + return tag == Kind.REF_GET_FIELD.getValue() + || tag == Kind.REF_PUT_FIELD.getValue() + || tag == Kind.REF_PUT_FIELD_STATIC.getValue() + || tag == Kind.REF_GET_FIELD_STATIC.getValue(); + } + + public boolean isMethodRef() { + return MethodHandle.isMethodRef(this.kind.getValue()); + } + + public boolean isFieldRef() { + return MethodHandle.isFieldRef(this.kind.getValue()); } @Override - // FIXME: [ms] serialize in a way it can be restored with the same parameters; adapt Jimple.g4 and - // JimpleConverter.java public String toString() { - return "handle: " - + (methodSignature == null ? "" : methodSignature) - + (fieldSignature == null ? "" : fieldSignature); + return "methodhandle: \"" + kind.valStr + "\" " + referenceSignature; } @Nonnull @@ -121,8 +160,8 @@ public Type getType() { return type; } - public MethodSignature getMethodSignature() { - return methodSignature; + public SootClassMemberSignature getReferenceSignature() { + return referenceSignature; } @Override @@ -132,9 +171,9 @@ public void accept(@Nonnull ConstantVisitor v) { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((methodSignature == null) ? 0 : methodSignature.hashCode()); + int result = type.hashCode(); + result = 31 * result + referenceSignature.hashCode(); + result = 31 * result + kind.hashCode(); return result; } @@ -150,10 +189,6 @@ public boolean equals(Object obj) { return false; } MethodHandle other = (MethodHandle) obj; - if (methodSignature == null) { - return other.methodSignature == null; - } else { - return methodSignature.equals(other.methodSignature); - } + return referenceSignature.equals(other.referenceSignature); } } diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java14/RecordTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java14/RecordTest.java index 154bd616084..c56e28548c9 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java14/RecordTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java14/RecordTest.java @@ -1,5 +1,8 @@ package sootup.java.bytecode.minimaltestsuite.java14; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import categories.Java9Test; import java.util.ArrayList; import java.util.Collections; @@ -8,10 +11,17 @@ import java.util.stream.Stream; import org.junit.Test; import org.junit.experimental.categories.Category; +import sootup.core.jimple.basic.Immediate; +import sootup.core.jimple.common.expr.JDynamicInvokeExpr; +import sootup.core.jimple.common.stmt.Stmt; import sootup.core.model.SootMethod; +import sootup.core.signatures.FieldSignature; import sootup.core.signatures.MethodSignature; +import sootup.core.signatures.PackageName; +import sootup.core.types.PrimitiveType; import sootup.java.bytecode.minimaltestsuite.MinimalBytecodeTestSuiteBase; import sootup.java.core.JavaIdentifierFactory; +import sootup.java.core.language.JavaJimple; import sootup.java.core.types.JavaClassType; /** @author Jonas Klauke */ @@ -38,7 +48,7 @@ public List expectedBodyStmts() { return Stream.of( "l0 := @this: RecordTest", "l1 := @parameter0: java.lang.Object", - "$stack2 = dynamicinvoke \"equals\" (l0, l1) (class \"LRecordTest;\", \"a;b\", handle: , handle: )", + "$stack2 = dynamicinvoke \"equals\" (l0, l1) (class \"LRecordTest;\", \"a;b\", methodhandle: \"REF_GET_FIELD\" , methodhandle: \"REF_GET_FIELD\" )", "return $stack2") .collect(Collectors.toCollection(ArrayList::new)); } @@ -47,5 +57,37 @@ public List expectedBodyStmts() { public void test() { SootMethod method = loadMethod(getMethodSignature()); assertJimpleStmts(method, expectedBodyStmts()); + List dynamicInvokes = + method.getBody().getStmts().stream() + .filter(Stmt::containsInvokeExpr) + .map(Stmt::getInvokeExpr) + .filter(abstractInvokeExpr -> abstractInvokeExpr instanceof JDynamicInvokeExpr) + .map(abstractInvokeExpr -> (JDynamicInvokeExpr) abstractInvokeExpr) + .collect(Collectors.toList()); + assertEquals(1, dynamicInvokes.size()); + JDynamicInvokeExpr invoke = dynamicInvokes.get(0); + + // test bootstrap args + List bootTrapArgs = invoke.getBootstrapArgs(); + assertTrue(bootTrapArgs.contains(JavaJimple.getInstance().newClassConstant("LRecordTest;"))); + assertTrue(bootTrapArgs.contains(JavaJimple.getInstance().newStringConstant("a;b"))); + assertTrue( + bootTrapArgs.contains( + JavaJimple.getInstance() + .newMethodHandle( + new FieldSignature( + new JavaClassType("RecordTest", new PackageName("")), + "a", + PrimitiveType.getInt()), + 1))); + assertTrue( + bootTrapArgs.contains( + JavaJimple.getInstance() + .newMethodHandle( + new FieldSignature( + new JavaClassType("RecordTest", new PackageName("")), + "b", + new JavaClassType("String", new PackageName("java.lang"))), + 1))); } } diff --git a/sootup.java.core/src/main/java/sootup/java/core/language/JavaJimple.java b/sootup.java.core/src/main/java/sootup/java/core/language/JavaJimple.java index 3ec7d04c4ca..5d238bf85b8 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/language/JavaJimple.java +++ b/sootup.java.core/src/main/java/sootup/java/core/language/JavaJimple.java @@ -32,8 +32,8 @@ import sootup.core.jimple.common.constant.MethodType; import sootup.core.jimple.common.constant.StringConstant; import sootup.core.jimple.common.ref.JCaughtExceptionRef; -import sootup.core.signatures.FieldSignature; -import sootup.core.signatures.MethodSignature; +import sootup.core.signatures.SootClassMemberSignature; +import sootup.core.signatures.SootClassMemberSubSignature; import sootup.core.types.NullType; import sootup.core.types.PrimitiveType; import sootup.core.types.Type; @@ -86,14 +86,16 @@ public StringConstant newStringConstant(String value) { return new StringConstant(value, getIdentifierFactory().getType("java.lang.String")); } - public MethodHandle newMethodHandle(FieldSignature ref, int tag) { + public MethodHandle newMethodHandle( + SootClassMemberSignature ref, int tag) { return new MethodHandle( ref, tag, getIdentifierFactory().getType("java.lang.invoke.MethodHandle")); } - public MethodHandle newMethodHandle(MethodSignature ref, int tag) { + public MethodHandle newMethodHandle( + SootClassMemberSignature ref, MethodHandle.Kind kind) { return new MethodHandle( - ref, tag, getIdentifierFactory().getType("java.lang.invoke.MethodHandle")); + ref, kind, getIdentifierFactory().getType("java.lang.invoke.MethodHandle")); } public MethodType newMethodType(List parameterTypes, Type returnType) { diff --git a/sootup.jimple.parser/src/main/antlr4/sootup/jimple/Jimple.g4 b/sootup.jimple.parser/src/main/antlr4/sootup/jimple/Jimple.g4 index 31082f1cd23..ecfbf9debcb 100644 --- a/sootup.jimple.parser/src/main/antlr4/sootup/jimple/Jimple.g4 +++ b/sootup.jimple.parser/src/main/antlr4/sootup/jimple/Jimple.g4 @@ -280,6 +280,9 @@ grammar Jimple; /*local*/ local=identifier | /*constant*/ constant; + methodhandle: + 'methodhandle: ' STRING_CONSTANT (method_signature|field_signature); + constant : /*boolean*/ BOOL_CONSTANT | /*integer*/ integer_constant | @@ -287,7 +290,7 @@ grammar Jimple; /*string*/ STRING_CONSTANT | /*clazz*/ CLASS STRING_CONSTANT | /*null*/ NULL | - methodhandle='handle:' method_signature | + methodhandle | methodtype='methodtype:' method_subsignature ; binop : diff --git a/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleConverter.java b/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleConverter.java index 6dda6e812b3..66334b3caf0 100644 --- a/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleConverter.java +++ b/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleConverter.java @@ -23,6 +23,8 @@ import sootup.core.model.*; import sootup.core.signatures.FieldSignature; import sootup.core.signatures.MethodSignature; +import sootup.core.signatures.SootClassMemberSignature; +import sootup.core.signatures.SootClassMemberSubSignature; import sootup.core.transform.BodyInterceptor; import sootup.core.types.*; import sootup.java.core.JavaIdentifierFactory; @@ -696,13 +698,19 @@ public Constant visitConstant(JimpleParser.ConstantContext ctx) { return BooleanConstant.getInstance(firstChar == 't' || firstChar == 'T'); } else if (ctx.NULL() != null) { return NullConstant.getInstance(); - } else if (ctx.methodhandle != null && ctx.method_signature() != null) { - final MethodSignature methodSignature = - util.getMethodSignature(ctx.method_signature(), ctx); - // TODO: [ms] support handles with JFieldRef too - // FIXME: [ms] update/specify tag when its printed - // return JavaJimple.getInstance().newMethodHandle( , 0); - return JavaJimple.getInstance().newMethodHandle(methodSignature, 0); + } else if (ctx.methodhandle() != null) { + JimpleParser.MethodhandleContext methodhandleContext = ctx.methodhandle(); + final String kindName = methodhandleContext.STRING_CONSTANT().getText(); + final SootClassMemberSignature + referenceSignature = + (methodhandleContext.method_signature() != null) + ? util.getMethodSignature( + methodhandleContext.method_signature(), methodhandleContext) + : util.getFieldSignature(methodhandleContext.field_signature()); + return JavaJimple.getInstance() + .newMethodHandle( + referenceSignature, + MethodHandle.Kind.getKind(kindName.substring(1, kindName.length() - 1))); } else if (ctx.methodtype != null && ctx.method_subsignature() != null) { final JimpleParser.Type_listContext typelist = ctx.method_subsignature().type_list(); final List typeList = util.getTypeList(typelist); diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/MethodAcceptingLamExpr.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/MethodAcceptingLamExpr.jimple index edace00f545..e2c37e9db00 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/MethodAcceptingLamExpr.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/MethodAcceptingLamExpr.jimple @@ -19,7 +19,7 @@ public super class MethodAcceptingLamExpr extends java.lang.Object l0 := @this: MethodAcceptingLamExpr; - $stack2 = dynamicinvoke "calcPercentage" () (methodtype: double __METHODTYPE__(double), handle: , methodtype: double __METHODTYPE__(double)); + $stack2 = dynamicinvoke "calcPercentage" () (methodtype: double __METHODTYPE__(double), methodhandle: "REF_INVOKE_STATIC" , methodtype: double __METHODTYPE__(double)); l1 = $stack2; diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/MethodReference.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/MethodReference.jimple index e433a96e522..33aeb4fc0ff 100644 --- a/sootup.jimple.parser/src/test/java/resources/jimple/MethodReference.jimple +++ b/sootup.jimple.parser/src/test/java/resources/jimple/MethodReference.jimple @@ -41,7 +41,7 @@ public super class MethodReference extends java.lang.Object $stack4 = staticinvoke (l1); - $stack5 = dynamicinvoke "display" (l1) (methodtype: void __METHODTYPE__(), handle: , methodtype: void __METHODTYPE__()); + $stack5 = dynamicinvoke "display" (l1) (methodtype: void __METHODTYPE__(), methodhandle: "REF_INVOKE_VIRTUAL" , methodtype: void __METHODTYPE__()); l2 = $stack5; diff --git a/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java8/MethodAcceptingLamExprTest.java b/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java8/MethodAcceptingLamExprTest.java index 3710d168925..fd4e0f5269d 100644 --- a/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java8/MethodAcceptingLamExprTest.java +++ b/sootup.jimple.parser/src/test/java/sootup/jimple/parser/javatestsuite/java8/MethodAcceptingLamExprTest.java @@ -30,7 +30,7 @@ public void test() { public List expectedBodyStmts() { return Stream.of( "l0 := @this: MethodAcceptingLamExpr", - "$stack2 = dynamicinvoke \"calcPercentage\" () (methodtype: double __METHODTYPE__(double), handle: , methodtype: double __METHODTYPE__(double))", + "$stack2 = dynamicinvoke \"calcPercentage\" () (methodtype: double __METHODTYPE__(double), methodhandle: \"REF_INVOKE_STATIC\" , methodtype: double __METHODTYPE__(double))", "l1 = $stack2", "$stack4 = ", "$stack3 = new java.lang.StringBuilder", From 859304efe89dd3541453fb0f17646605cff50cd2 Mon Sep 17 00:00:00 2001 From: Jonas Klauke Date: Mon, 14 Aug 2023 18:29:39 +0200 Subject: [PATCH 60/90] Adapted bytecode testcases to new methodhandle serialization --- .../minimaltestsuite/java11/TypeInferenceLambdaTest.java | 2 +- .../minimaltestsuite/java8/MethodAcceptingLamExprTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java11/TypeInferenceLambdaTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java11/TypeInferenceLambdaTest.java index f640bfc4714..454822e66e8 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java11/TypeInferenceLambdaTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java11/TypeInferenceLambdaTest.java @@ -33,7 +33,7 @@ public MethodSignature getMethodSignature() { public List expectedBodyStmts() { return Stream.of( "l0 := @this: TypeInferenceLambda", - "l1 = dynamicinvoke \"apply\" () (methodtype: java.lang.Object __METHODTYPE__(java.lang.Object,java.lang.Object), handle: , methodtype: java.lang.Integer __METHODTYPE__(java.lang.Integer,java.lang.Integer))", + "l1 = dynamicinvoke \"apply\" () (methodtype: java.lang.Object __METHODTYPE__(java.lang.Object,java.lang.Object), methodhandle: \"REF_INVOKE_STATIC\" , methodtype: java.lang.Integer __METHODTYPE__(java.lang.Integer,java.lang.Integer))", "$stack4 = staticinvoke (2)", "$stack3 = staticinvoke (3)", "$stack5 = interfaceinvoke l1.($stack4, $stack3)", diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java8/MethodAcceptingLamExprTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java8/MethodAcceptingLamExprTest.java index 9042cd14b7d..7901fb7612d 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java8/MethodAcceptingLamExprTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java8/MethodAcceptingLamExprTest.java @@ -43,7 +43,7 @@ public void test() { public List expectedBodyStmts() { return Stream.of( "l0 := @this: MethodAcceptingLamExpr", - "l1 = dynamicinvoke \"calcPercentage\" () (methodtype: double __METHODTYPE__(double), handle: , methodtype: double __METHODTYPE__(double))", + "l1 = dynamicinvoke \"calcPercentage\" () (methodtype: double __METHODTYPE__(double), methodhandle: \"REF_INVOKE_STATIC\" , methodtype: double __METHODTYPE__(double))", "$stack3 = ", "$stack2 = new java.lang.StringBuilder", "specialinvoke $stack2.()>()", From d13cc919a98e9f5be31b31546f3ede075cabfadf Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Mon, 14 Aug 2023 22:42:50 +0200 Subject: [PATCH 61/90] fix annotations --- .../src/test/java/sootup/java/bytecode/Soot1577.java | 7 ++++++- .../src/test/java/sootup/java/bytecode/Soot1580.java | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/Soot1577.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/Soot1577.java index 5e76875a2fa..56bb29a92d2 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/Soot1577.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/Soot1577.java @@ -1,7 +1,10 @@ package sootup.java.bytecode; +import categories.Java8Test; import org.junit.Assert; +import org.junit.Ignore; import org.junit.Test; +import org.junit.experimental.categories.Category; import sootup.core.inputlocation.AnalysisInputLocation; import sootup.core.model.SootMethod; import sootup.java.bytecode.inputlocation.JavaClassPathAnalysisInputLocation; @@ -10,16 +13,18 @@ import sootup.java.core.language.JavaLanguage; import sootup.java.core.views.JavaView; +@Category(Java8Test.class) public class Soot1577 { final String directory = "../shared-test-resources/soot-1577/"; @Test + @Ignore("conversion fails - could be a dex2jar conversion problem") public void test() { AnalysisInputLocation inputLocation = new JavaClassPathAnalysisInputLocation(directory); JavaProject project = - JavaProject.builder(new JavaLanguage(7)).addInputLocation(inputLocation).build(); + JavaProject.builder(new JavaLanguage(8)).addInputLocation(inputLocation).build(); JavaView view = project.createView(); diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/Soot1580.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/Soot1580.java index 9cecd0aa910..0d5555d72ec 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/Soot1580.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/Soot1580.java @@ -1,9 +1,11 @@ package sootup.java.bytecode; +import categories.Java8Test; import java.nio.file.Path; import java.nio.file.Paths; import org.junit.Assert; import org.junit.Test; +import org.junit.experimental.categories.Category; import sootup.core.inputlocation.AnalysisInputLocation; import sootup.core.model.SootMethod; import sootup.core.types.ClassType; @@ -15,6 +17,7 @@ import sootup.java.core.language.JavaLanguage; import sootup.java.core.views.JavaView; +@Category(Java8Test.class) public class Soot1580 { final Path jar = Paths.get("../shared-test-resources/soot-1580/jpush-android_v3.0.5.jar"); From 03b20238b96fafa5b7f4c09a2ec6583239165e4f Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Mon, 14 Aug 2023 22:44:20 +0200 Subject: [PATCH 62/90] add proposed indy testcase - rhs is null --- shared-test-resources/bugfixes/Indy.java | 15 ++++++++++ .../core/jimple/common/stmt/JAssignStmt.java | 4 ++- .../java/sootup/java/bytecode/IndyTests.java | 30 +++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 shared-test-resources/bugfixes/Indy.java create mode 100644 sootup.java.bytecode/src/test/java/sootup/java/bytecode/IndyTests.java diff --git a/shared-test-resources/bugfixes/Indy.java b/shared-test-resources/bugfixes/Indy.java new file mode 100644 index 00000000000..800203ab873 --- /dev/null +++ b/shared-test-resources/bugfixes/Indy.java @@ -0,0 +1,15 @@ +import java.time.LocalDate; +import java.time.Period; +import java.util.stream.LongStream; +import java.util.stream.Stream; +class Indy{ + public Stream test(LocalDate endExclusive, Period step) { + long months = step.toTotalMonths(); + long days = step.getDays(); + int sign = months > 0 || days > 0 ? 1 : -1; + long steps = 200000 / (months + days); + return LongStream.rangeClosed(0, steps).mapToObj( + n -> endExclusive.plusDays(days * n)); + } + +} \ No newline at end of file diff --git a/sootup.core/src/main/java/sootup/core/jimple/common/stmt/JAssignStmt.java b/sootup.core/src/main/java/sootup/core/jimple/common/stmt/JAssignStmt.java index 389f13edb12..01e871d4abe 100644 --- a/sootup.core/src/main/java/sootup/core/jimple/common/stmt/JAssignStmt.java +++ b/sootup.core/src/main/java/sootup/core/jimple/common/stmt/JAssignStmt.java @@ -53,7 +53,9 @@ public JAssignStmt( } if (!validateValue(rValue)) { throw new RuntimeException( - "Illegal Assignment statement. Make sure that right hand side has a valid operand."); + "Illegal Assignment statement. Make sure that right hand side (" + + rValue + + ") has a valid operand."); } } diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/IndyTests.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/IndyTests.java new file mode 100644 index 00000000000..f1ced45cb93 --- /dev/null +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/IndyTests.java @@ -0,0 +1,30 @@ +package sootup.java.bytecode; + +import org.junit.Assert; +import org.junit.Test; +import sootup.core.inputlocation.AnalysisInputLocation; +import sootup.core.model.SootMethod; +import sootup.java.bytecode.inputlocation.JavaClassPathAnalysisInputLocation; +import sootup.java.core.JavaProject; +import sootup.java.core.JavaSootClass; +import sootup.java.core.language.JavaLanguage; +import sootup.java.core.views.JavaView; + +/** InvokeDynamics and the Operand stack.. */ +public class IndyTests { + final String directory = "../shared-test-resources/misc/"; + + @Test + public void test() { + AnalysisInputLocation inputLocation = + new JavaClassPathAnalysisInputLocation(directory); + + JavaProject project = + JavaProject.builder(new JavaLanguage(8)).addInputLocation(inputLocation).build(); + + JavaView view = project.createView(); + Assert.assertEquals(1, view.getClasses().size()); + + view.getClasses().stream().findFirst().get().getMethods().forEach(SootMethod::getBody); + } +} From 6bf2fb7ae0dc0d936c6075c03164347b8cd058d2 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Mon, 14 Aug 2023 22:54:44 +0200 Subject: [PATCH 63/90] fix errmsg and directory --- .../main/java/sootup/core/jimple/common/stmt/JAssignStmt.java | 2 +- .../src/test/java/sootup/java/bytecode/IndyTests.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/jimple/common/stmt/JAssignStmt.java b/sootup.core/src/main/java/sootup/core/jimple/common/stmt/JAssignStmt.java index 01e871d4abe..865223653cb 100644 --- a/sootup.core/src/main/java/sootup/core/jimple/common/stmt/JAssignStmt.java +++ b/sootup.core/src/main/java/sootup/core/jimple/common/stmt/JAssignStmt.java @@ -55,7 +55,7 @@ public JAssignStmt( throw new RuntimeException( "Illegal Assignment statement. Make sure that right hand side (" + rValue - + ") has a valid operand."); + + ") is a valid operand."); } } diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/IndyTests.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/IndyTests.java index f1ced45cb93..45fb8cd0e82 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/IndyTests.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/IndyTests.java @@ -12,7 +12,7 @@ /** InvokeDynamics and the Operand stack.. */ public class IndyTests { - final String directory = "../shared-test-resources/misc/"; + final String directory = "../shared-test-resources/bugfixes/"; @Test public void test() { From 1472cb74ea15fdd5e7b00888a6a52c9863486fdb Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Tue, 15 Aug 2023 09:24:10 +0200 Subject: [PATCH 64/90] add missing annotation --- .../src/test/java/sootup/java/bytecode/IndyTests.java | 3 +++ .../minimaltestsuite/java14/SwitchExprWithYieldTest.java | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/IndyTests.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/IndyTests.java index 45fb8cd0e82..c0cc8ba5e63 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/IndyTests.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/IndyTests.java @@ -1,7 +1,9 @@ package sootup.java.bytecode; +import categories.Java9Test; import org.junit.Assert; import org.junit.Test; +import org.junit.experimental.categories.Category; import sootup.core.inputlocation.AnalysisInputLocation; import sootup.core.model.SootMethod; import sootup.java.bytecode.inputlocation.JavaClassPathAnalysisInputLocation; @@ -11,6 +13,7 @@ import sootup.java.core.views.JavaView; /** InvokeDynamics and the Operand stack.. */ +@Category(Java9Test.class) public class IndyTests { final String directory = "../shared-test-resources/bugfixes/"; diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java14/SwitchExprWithYieldTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java14/SwitchExprWithYieldTest.java index a0c7f2a48fe..f03a07a699a 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java14/SwitchExprWithYieldTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java14/SwitchExprWithYieldTest.java @@ -25,7 +25,6 @@ public JavaClassType getDeclaredClassSignature() { @Override public MethodSignature getMethodSignature() { - System.out.println(getDeclaredClassSignature()); return identifierFactory.getMethodSignature( getDeclaredClassSignature(), "switchSomething", "void", Collections.emptyList()); } From c4297293b00bd642a8f4fa627c19456c83937ce0 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Tue, 15 Aug 2023 10:27:28 +0200 Subject: [PATCH 65/90] simplified test input; add missing .class --- shared-test-resources/bugfixes/Indy.class | Bin 0 -> 1064 bytes shared-test-resources/bugfixes/Indy.java | 18 +++++++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 shared-test-resources/bugfixes/Indy.class diff --git a/shared-test-resources/bugfixes/Indy.class b/shared-test-resources/bugfixes/Indy.class new file mode 100644 index 0000000000000000000000000000000000000000..1b83ecee8411bf2eeb26e8c39f3437f23313f6e7 GIT binary patch literal 1064 zcmbVL%Wl&^6g?A%m^cmzg#rzvKuKvHPy@>bkRTEwQc96hy6B2YGA(YLv1N}d<7hFp;%!0Xc^95kKaR$K|23 zGdL1M#gKdIN>@E+FzSuH0xlwN!m?3-%}`0)W952Iq(Z?bPFJdaA~9HQ^p=O*^MscK z?=KPMB^xD_$;gAio4$z1pJAik=$#=Q#B!)yUuvv(l84isK!jZRVOz5=*|>tM1UTUV zL#O^vfob?Z6K$Kg#*ppG(Ud+NekQVv}M0T$BD*uL+vT>S9+~k6CkYhZr;TzyX5}EfW~7lT@WI)0*a2urDMq z+@M>VXZH#!Bx~0#0?-i4trM6GA7QjkQ3OtKIfKt+$Rwe9Wuf00MF rRdPruE9K_(*BJjTi|FGdj} literal 0 HcmV?d00001 diff --git a/shared-test-resources/bugfixes/Indy.java b/shared-test-resources/bugfixes/Indy.java index 800203ab873..2143e237efe 100644 --- a/shared-test-resources/bugfixes/Indy.java +++ b/shared-test-resources/bugfixes/Indy.java @@ -1,15 +1,15 @@ import java.time.LocalDate; import java.time.Period; -import java.util.stream.LongStream; 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 Stream test(LocalDate endExclusive, Period step) { - long months = step.toTotalMonths(); - long days = step.getDays(); - int sign = months > 0 || days > 0 ? 1 : -1; - long steps = 200000 / (months + days); - return LongStream.rangeClosed(0, steps).mapToObj( - n -> endExclusive.plusDays(days * n)); + public IntStream test(IntStream s) { + int sign; + if (s.isParallel()) { + sign = 1; + } + return s.map(n -> n+42); } - } \ No newline at end of file From bc74bf541c3797656d5e75dc77b6dd5248357ece Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Tue, 15 Aug 2023 10:36:20 +0200 Subject: [PATCH 66/90] that input was too simple.. --- shared-test-resources/bugfixes/Indy.class | Bin 1064 -> 1083 bytes shared-test-resources/bugfixes/Indy.java | 2 ++ 2 files changed, 2 insertions(+) diff --git a/shared-test-resources/bugfixes/Indy.class b/shared-test-resources/bugfixes/Indy.class index 1b83ecee8411bf2eeb26e8c39f3437f23313f6e7..4e5ccd49f98348a241eed9f6fb7e62fc4b6d4c33 100644 GIT binary patch delta 110 zcmWN`y%B;?5Jlm$`*7X^Mow1inHy84KK`uXk57IIPBbE$7b4T?dda8Dz5Ws5 B4hjGO delta 75 zcmdnZv4Uem2eSej10#bZgA|YyXJBBkVqgM71_n{>oeb=Z3^N&+C$DD~72yI4axic* Ya5G2)rI{HRIVV41)?(zI%+I0&0CvC$JOBUy diff --git a/shared-test-resources/bugfixes/Indy.java b/shared-test-resources/bugfixes/Indy.java index 2143e237efe..98441621cd4 100644 --- a/shared-test-resources/bugfixes/Indy.java +++ b/shared-test-resources/bugfixes/Indy.java @@ -9,6 +9,8 @@ public IntStream test(IntStream s) { int sign; if (s.isParallel()) { sign = 1; + }else{ + sign = -1; } return s.map(n -> n+42); } From a12a41dfcd231e4425899433e564b1932620ec59 Mon Sep 17 00:00:00 2001 From: Jonas Klauke Date: Fri, 18 Aug 2023 12:16:37 +0200 Subject: [PATCH 67/90] fixed extension checking in the analysis location --- .../java-miniapps/MiniApp.jar | Bin 4316 -> 4475 bytes .../java-miniapps/src/junkclass | 1 + .../requires_exports/jar/modb.jar | Bin 1074 -> 1243 bytes .../requires_exports/src/modb/pkgb/junkclass | 1 + .../sootup/core/inputlocation/FileType.java | 5 +++ .../main/java/sootup/core/util/PathUtils.java | 2 +- .../JrtFileSystemAnalysisInputLocation.java | 32 ++++++++---------- .../PathBasedAnalysisInputLocation.java | 12 ++++--- .../AnalysisInputLocationTest.java | 9 ++--- .../PathBasedAnalysisInputLocationTest.java | 8 ++--- 10 files changed, 35 insertions(+), 35 deletions(-) create mode 100644 shared-test-resources/java-miniapps/src/junkclass create mode 100644 shared-test-resources/jigsaw-examples/requires_exports/src/modb/pkgb/junkclass diff --git a/shared-test-resources/java-miniapps/MiniApp.jar b/shared-test-resources/java-miniapps/MiniApp.jar index bb7ebf378d97a9b8379ef5939d265c49e513ea0c..a8f33af1e9217117ca71af9ddf811ca2028775e7 100644 GIT binary patch delta 189 zcmcbk_*-d1FkcEYiwFY;2M0q=xKKC)65s@~vr6-_lXDV_i+K+@ay1wTFdta|B>VKN zTL~Kziavd{@>$kXuUKNRr6cD{O8kX}ruMz(qxJcxTwMKzKfs%vLv8yuaYLXfW(=GC s`6`*b8JR>F5OyJC85lrzAwVD>lFb3$tZX1DZXjI4#K5o|eGoO%W* diff --git a/shared-test-resources/java-miniapps/src/junkclass b/shared-test-resources/java-miniapps/src/junkclass new file mode 100644 index 00000000000..e3bc908497b --- /dev/null +++ b/shared-test-resources/java-miniapps/src/junkclass @@ -0,0 +1 @@ +this is a test file to check if it recognized as class \ No newline at end of file diff --git a/shared-test-resources/jigsaw-examples/requires_exports/jar/modb.jar b/shared-test-resources/jigsaw-examples/requires_exports/jar/modb.jar index 3079df5844ceca92eea3e410699dae387217ecba..154aa390259fc423b67199306763c83d9b9c5536 100644 GIT binary patch delta 322 zcmdnQahr3(Q7$e91`Y;>mPn!S&8rx_8S9x@L>M?YI2dxmg~Az-03VQDke!~SpH-Td zot%?cT+DmOk*mQ#fce1sC)uZG-AdS)Q1t1mmCv%Cdc_ihEgd;uQsOT(G_~(NAFaKl$`~lwV9BSLQi5miqG6UiOZ03m)*9{>OV delta 145 zcmcc3xrt-K(TOZ#ljk!X=3!>xVqoB4VAva3;=l2{H{;|a=6ZDz1`!4h4i1KEDW(42 ztv-Tt7#J8X1F;|wBf!DQ3z$R%0=yZSxEK(IOn%EO#WaU;GAE0n+I~g`hJx($Bz-5n Yb%7 diff --git a/shared-test-resources/jigsaw-examples/requires_exports/src/modb/pkgb/junkclass b/shared-test-resources/jigsaw-examples/requires_exports/src/modb/pkgb/junkclass new file mode 100644 index 00000000000..e3bc908497b --- /dev/null +++ b/shared-test-resources/jigsaw-examples/requires_exports/src/modb/pkgb/junkclass @@ -0,0 +1 @@ +this is a test file to check if it recognized as class \ No newline at end of file diff --git a/sootup.core/src/main/java/sootup/core/inputlocation/FileType.java b/sootup.core/src/main/java/sootup/core/inputlocation/FileType.java index 06e5f3c9852..67fb9267614 100644 --- a/sootup.core/src/main/java/sootup/core/inputlocation/FileType.java +++ b/sootup.core/src/main/java/sootup/core/inputlocation/FileType.java @@ -47,6 +47,11 @@ public enum FileType { this.extension = fileExtension; } + @Nonnull + public String getExtensionWithDot() { + return "." + extension; + } + @Nonnull public String getExtension() { return extension; diff --git a/sootup.core/src/main/java/sootup/core/util/PathUtils.java b/sootup.core/src/main/java/sootup/core/util/PathUtils.java index 2253e4d7c39..613f2e3088a 100644 --- a/sootup.core/src/main/java/sootup/core/util/PathUtils.java +++ b/sootup.core/src/main/java/sootup/core/util/PathUtils.java @@ -60,7 +60,7 @@ public static boolean hasExtension(@Nonnull Path path, @Nonnull Collection> getClassSource( Path filepath = theFileSystem.getPath( klassType.getFullyQualifiedName().replace('.', '/') - + "." - + classProvider.getHandledFileType().getExtension()); + + classProvider.getHandledFileType().getExtensionWithDot()); // parse as module if (klassType.getPackageName() instanceof ModulePackageName) { @@ -136,8 +134,7 @@ protected Stream> getClassSourcesInternal( String moduleInfoFilename = JavaModuleIdentifierFactory.MODULE_INFO_FILE - + "." - + classProvider.getHandledFileType().getExtension(); + + classProvider.getHandledFileType().getExtensionWithDot(); final Path archiveRoot = theFileSystem.getPath("modules", moduleSignature.getModuleName()); try { @@ -148,20 +145,19 @@ protected Stream> getClassSourcesInternal( !Files.isDirectory(filePath) && filePath .toString() - .endsWith(classProvider.getHandledFileType().getExtension()) + .endsWith(classProvider.getHandledFileType().getExtensionWithDot()) && !filePath.toString().endsWith(moduleInfoFilename)) .flatMap( - p -> { - return StreamUtils.optionalToStream( - Optional.of( - classProvider.createClassSource( - this, - p, - this.fromPath( - p.subpath(2, p.getNameCount()), - p.subpath(1, 2), - identifierFactory)))); - }); + p -> + StreamUtils.optionalToStream( + Optional.of( + classProvider.createClassSource( + this, + p, + this.fromPath( + p.subpath(2, p.getNameCount()), + p.subpath(1, 2), + identifierFactory))))); } catch (IOException e) { throw new ResolveException("Error loading module " + moduleSignature, archiveRoot, e); } @@ -246,7 +242,7 @@ public Set getModules(View view) { return Collections.unmodifiableSet(moduleInfoMap.keySet()); } - @Nullable + @Nonnull @Override public SourceType getSourceType() { return sourceType; diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java index 8c7b8ace543..262fe3cbbbc 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java @@ -177,8 +177,7 @@ protected Optional> getClassSourceI path.getFileSystem() .getPath( signature.getFullyQualifiedName().replace('.', '/') - + "." - + classProvider.getHandledFileType().getExtension())); + + classProvider.getHandledFileType().getExtensionWithDot())); if (!Files.exists(pathToClass)) { return Optional.empty(); @@ -653,7 +652,8 @@ protected void extractWarFile(Path warFilePath, final Path destDirectory) { dest.deleteOnExit(); } - ZipInputStream zis = new ZipInputStream(new FileInputStream(warFilePath.toString())); + ZipInputStream zis = + new ZipInputStream(Files.newInputStream(Paths.get(warFilePath.toString()))); ZipEntry zipEntry; while ((zipEntry = zis.getNextEntry()) != null) { Path filepath = destDirectory.resolve(zipEntry.getName()); @@ -668,7 +668,8 @@ protected void extractWarFile(Path warFilePath, final Path destDirectory) { if (file.exists()) { // compare contents -> does it contain the extracted war already? int readBytesExistingFile; - final BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file)); + final BufferedInputStream bis = + new BufferedInputStream(Files.newInputStream(file.toPath())); byte[] bisBuf = new byte[4096]; while ((readBytesZip = zis.read(incomingValues)) != -1) { if (extractedSize > maxAllowedBytesToExtract) { @@ -693,7 +694,8 @@ protected void extractWarFile(Path warFilePath, final Path destDirectory) { } } else { - BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file)); + BufferedOutputStream bos = + new BufferedOutputStream(Files.newOutputStream(file.toPath())); while ((readBytesZip = zis.read(incomingValues)) != -1) { if (extractedSize > maxAllowedBytesToExtract) { throw new RuntimeException( diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/AnalysisInputLocationTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/AnalysisInputLocationTest.java index e29df69cd36..dab4fe1236c 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/AnalysisInputLocationTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/AnalysisInputLocationTest.java @@ -8,10 +8,8 @@ import java.util.Optional; import sootup.core.IdentifierFactory; import sootup.core.frontend.AbstractClassSource; -import sootup.core.frontend.ClassProvider; import sootup.core.inputlocation.AnalysisInputLocation; import sootup.core.types.ClassType; -import sootup.java.bytecode.frontend.AsmJavaClassProvider; import sootup.java.core.JavaIdentifierFactory; import sootup.java.core.JavaProject; import sootup.java.core.JavaSootClass; @@ -52,19 +50,16 @@ public abstract class AnalysisInputLocationTest { final Path mmrj = Paths.get("../shared-test-resources/multi-release-jar-modular/mrjar.jar"); final Path apk = Paths.get("../shared-test-resources/apk/SimpleApk.apk"); - private ClassProvider classProvider; - protected IdentifierFactory getIdentifierFactory() { return JavaIdentifierFactory.getInstance(); } protected void testClassReceival( - AnalysisInputLocation ns, ClassType sig, int minClassesFound) { + AnalysisInputLocation ns, ClassType sig, int classesFound) { final JavaProject project = JavaProject.builder(new JavaLanguage(8)).addInputLocation(ns).build(); final JavaView view = project.createView(); - classProvider = new AsmJavaClassProvider(view); final Optional> clazzOpt = ns.getClassSource(sig, view); @@ -73,6 +68,6 @@ protected void testClassReceival( final Collection> classSources = ns.getClassSources(view); - assertTrue(classSources.size() >= minClassesFound); + assertEquals(classSources.size(), classesFound); } } diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java index 6830c69b2a1..273bd2be66e 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java @@ -273,7 +273,7 @@ public void testApk() { PathBasedAnalysisInputLocation.create(apk, null); final ClassType mainClass = getIdentifierFactory().getClassType("de.upb.futuresoot.fields.MainActivity"); - testClassReceival(pathBasedNamespace, mainClass, 1); + testClassReceival(pathBasedNamespace, mainClass, 1392); } @Test @@ -283,8 +283,8 @@ public void testJar() { final ClassType class1 = getIdentifierFactory().getClassType("Employee", "ds"); final ClassType mainClass = getIdentifierFactory().getClassType("MiniApp"); - testClassReceival(pathBasedNamespace, class1, 4); - testClassReceival(pathBasedNamespace, mainClass, 4); + testClassReceival(pathBasedNamespace, class1, 6); + testClassReceival(pathBasedNamespace, mainClass, 6); } @Test @@ -292,7 +292,7 @@ public void testWar() { PathBasedAnalysisInputLocation pathBasedNamespace = PathBasedAnalysisInputLocation.create(war, null); final ClassType warClass1 = getIdentifierFactory().getClassType("SimpleWarRead"); - testClassReceival(pathBasedNamespace, warClass1, 2); + testClassReceival(pathBasedNamespace, warClass1, 19); } @Test From 6b59bbf052505b67e8f9969d945e0f44ada6790c Mon Sep 17 00:00:00 2001 From: Jonas Klauke Date: Fri, 18 Aug 2023 14:17:57 +0200 Subject: [PATCH 68/90] fixed extension checking in the analysis location and added handling of source resolve errors --- .../java-miniapps/MiniApp.jar | Bin 4475 -> 4612 bytes .../java-miniapps/src/NoClass.class | 1 + .../wala-tests/FakeJava.java | 1 + .../sootup/core/frontend/ClassProvider.java | 6 ++-- .../frontend/AsmJavaClassProvider.java | 33 +++++++++++------- .../JrtFileSystemAnalysisInputLocation.java | 19 +++++----- .../PathBasedAnalysisInputLocation.java | 5 ++- .../AnalysisInputLocationTest.java | 14 ++++---- .../PathBasedAnalysisInputLocationTest.java | 13 +++---- .../frontend/WalaJavaClassProvider.java | 4 +-- .../JavaSourcePathAnalysisInputLocation.java | 2 +- .../frontend/WalaJavaClassProviderTest.java | 14 +++++++- .../parser/JimpleAnalysisInputLocation.java | 5 ++- .../jimple/parser/JimpleClassProvider.java | 24 ++++++++++--- .../java/resources/jimple/FakeJimple.jimple | 1 + .../JimpleAnalysisInputLocationTest.java | 25 +++++++++++++ 16 files changed, 115 insertions(+), 52 deletions(-) create mode 100644 shared-test-resources/java-miniapps/src/NoClass.class create mode 100644 shared-test-resources/wala-tests/FakeJava.java create mode 100644 sootup.jimple.parser/src/test/java/resources/jimple/FakeJimple.jimple diff --git a/shared-test-resources/java-miniapps/MiniApp.jar b/shared-test-resources/java-miniapps/MiniApp.jar index a8f33af1e9217117ca71af9ddf811ca2028775e7..64f7fb6d76194ce5a8391ea934a2d2577262902d 100644 GIT binary patch delta 166 zcmeyZ)S|LsH=idniwFY;2M2>|u247w65s{0{qmi25{rxVl0hW*$rCzZ42$;s5o&d5 zeKP0Bqa=m^Z*~s#S@pYxfog>}Z{yp@3v#@_~2&l=%i? diff --git a/shared-test-resources/java-miniapps/src/NoClass.class b/shared-test-resources/java-miniapps/src/NoClass.class new file mode 100644 index 00000000000..b8e300dcb2c --- /dev/null +++ b/shared-test-resources/java-miniapps/src/NoClass.class @@ -0,0 +1 @@ +This is not a class \ No newline at end of file diff --git a/shared-test-resources/wala-tests/FakeJava.java b/shared-test-resources/wala-tests/FakeJava.java new file mode 100644 index 00000000000..69d3f89baec --- /dev/null +++ b/shared-test-resources/wala-tests/FakeJava.java @@ -0,0 +1 @@ +This is a fake java file \ No newline at end of file diff --git a/sootup.core/src/main/java/sootup/core/frontend/ClassProvider.java b/sootup.core/src/main/java/sootup/core/frontend/ClassProvider.java index 60f352d9be2..99a67c278f0 100644 --- a/sootup.core/src/main/java/sootup/core/frontend/ClassProvider.java +++ b/sootup.core/src/main/java/sootup/core/frontend/ClassProvider.java @@ -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; @@ -34,9 +34,9 @@ * * @author Manuel Benz */ -public interface ClassProvider>> { +public interface ClassProvider>> { - AbstractClassSource createClassSource( + Optional> createClassSource( AnalysisInputLocation> inputLocation, Path sourcePath, ClassType classSignature); diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmJavaClassProvider.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmJavaClassProvider.java index b026a595382..e6bb38027a2 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmJavaClassProvider.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmJavaClassProvider.java @@ -22,15 +22,16 @@ */ import java.io.IOException; import java.nio.file.Path; +import java.util.Optional; import javax.annotation.Nonnull; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.tree.ClassNode; -import sootup.core.frontend.AbstractClassSource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import sootup.core.frontend.ClassProvider; -import sootup.core.frontend.ResolveException; +import sootup.core.frontend.SootClassSource; import sootup.core.inputlocation.AnalysisInputLocation; import sootup.core.inputlocation.FileType; -import sootup.core.jimple.basic.NoPositionInformation; import sootup.core.model.SootClass; import sootup.core.types.ClassType; import sootup.core.views.View; @@ -44,13 +45,14 @@ public class AsmJavaClassProvider implements ClassProvider { @Nonnull private final View view; + private static final @Nonnull Logger logger = LoggerFactory.getLogger(AsmJavaClassProvider.class); public AsmJavaClassProvider(@Nonnull View view) { this.view = view; } @Override - public AbstractClassSource createClassSource( + public Optional> createClassSource( AnalysisInputLocation> analysisInputLocation, Path sourcePath, ClassType classType) { @@ -58,23 +60,30 @@ public AbstractClassSource createClassSource( try { AsmUtil.initAsmClassSource(sourcePath, classNode); - } catch (IOException exception) { - throw new ResolveException( - exception.getMessage(), sourcePath, NoPositionInformation.getInstance(), exception); + } catch (IOException | IllegalArgumentException exception) { + logger.warn( + "ASM could not resolve class source of " + + classType + + " in " + + sourcePath + + " causing " + + exception.getMessage()); + return Optional.empty(); } JavaClassType klassType = (JavaClassType) classType; if (klassType instanceof ModuleJavaClassType && klassType.getClassName().equals(JavaModuleIdentifierFactory.MODULE_INFO_FILE)) { - throw new ResolveException( - "Can not create ClassSource from a module info descriptor!", sourcePath); + logger.warn("Can not create ClassSource from a module info descriptor! path:" + sourcePath); + return Optional.empty(); } else { if (klassType instanceof AnnotationType) { - return new AsmAnnotationClassSource( - analysisInputLocation, sourcePath, klassType, classNode); + return Optional.of( + new AsmAnnotationClassSource(analysisInputLocation, sourcePath, klassType, classNode)); } - return new AsmClassSource(analysisInputLocation, sourcePath, klassType, classNode); + return Optional.of( + new AsmClassSource(analysisInputLocation, sourcePath, klassType, classNode)); } } diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JrtFileSystemAnalysisInputLocation.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JrtFileSystemAnalysisInputLocation.java index 80df4e0d727..d3803134f6f 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JrtFileSystemAnalysisInputLocation.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JrtFileSystemAnalysisInputLocation.java @@ -90,7 +90,7 @@ public Optional> getClassSource( "modules", modulePackageSignature.getModuleSignature().getModuleName()); Path foundClass = module.resolve(filepath); if (Files.isRegularFile(foundClass)) { - return Optional.of(classProvider.createClassSource(this, foundClass, klassType)); + return classProvider.createClassSource(this, foundClass, klassType); } else { return Optional.empty(); } @@ -104,7 +104,7 @@ public Optional> getClassSource( // check each module folder for the class Path foundfile = entry.resolve(filepath); if (Files.isRegularFile(foundfile)) { - return Optional.of(classProvider.createClassSource(this, foundfile, klassType)); + return classProvider.createClassSource(this, foundfile, klassType); } } } @@ -150,14 +150,13 @@ protected Stream> getClassSourcesInternal( .flatMap( p -> StreamUtils.optionalToStream( - Optional.of( - classProvider.createClassSource( - this, - p, - this.fromPath( - p.subpath(2, p.getNameCount()), - p.subpath(1, 2), - identifierFactory))))); + classProvider.createClassSource( + this, + p, + this.fromPath( + p.subpath(2, p.getNameCount()), + p.subpath(1, 2), + identifierFactory)))); } catch (IOException e) { throw new ResolveException("Error loading module " + moduleSignature, archiveRoot, e); } diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java index 262fe3cbbbc..9ba65dda6f7 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java @@ -157,8 +157,7 @@ Collection> walkDirectory( .flatMap( p -> StreamUtils.optionalToStream( - Optional.of( - classProvider.createClassSource(this, p, factory.fromPath(dirPath, p))))) + classProvider.createClassSource(this, p, factory.fromPath(dirPath, p)))) .collect(Collectors.toList()); } catch (IOException e) { @@ -183,7 +182,7 @@ protected Optional> getClassSourceI return Optional.empty(); } - return Optional.of(classProvider.createClassSource(this, pathToClass, signature)); + return classProvider.createClassSource(this, pathToClass, signature); } private static class DirectoryBasedAnalysisInputLocation extends PathBasedAnalysisInputLocation { diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/AnalysisInputLocationTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/AnalysisInputLocationTest.java index dab4fe1236c..bc1f9b0ae1e 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/AnalysisInputLocationTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/AnalysisInputLocationTest.java @@ -5,6 +5,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.Collection; +import java.util.List; import java.util.Optional; import sootup.core.IdentifierFactory; import sootup.core.frontend.AbstractClassSource; @@ -55,17 +56,18 @@ protected IdentifierFactory getIdentifierFactory() { } protected void testClassReceival( - AnalysisInputLocation ns, ClassType sig, int classesFound) { + AnalysisInputLocation ns, List sigs, int classesFound) { final JavaProject project = JavaProject.builder(new JavaLanguage(8)).addInputLocation(ns).build(); final JavaView view = project.createView(); - final Optional> clazzOpt = - ns.getClassSource(sig, view); - assertTrue(clazzOpt.isPresent()); - assertEquals(sig, clazzOpt.get().getClassType()); - + for (ClassType classType:sigs) { + final Optional> clazzOpt = + ns.getClassSource(classType, view); + assertTrue(clazzOpt.isPresent()); + assertEquals(classType, clazzOpt.get().getClassType()); + } final Collection> classSources = ns.getClassSources(view); assertEquals(classSources.size(), classesFound); diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java index 273bd2be66e..33f4c877747 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java @@ -29,6 +29,7 @@ import categories.Java8Test; import java.io.File; import java.nio.file.Paths; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.EnumSet; @@ -273,7 +274,7 @@ public void testApk() { PathBasedAnalysisInputLocation.create(apk, null); final ClassType mainClass = getIdentifierFactory().getClassType("de.upb.futuresoot.fields.MainActivity"); - testClassReceival(pathBasedNamespace, mainClass, 1392); + testClassReceival(pathBasedNamespace, Collections.singletonList(mainClass), 1392); } @Test @@ -281,10 +282,10 @@ public void testJar() { PathBasedAnalysisInputLocation pathBasedNamespace = PathBasedAnalysisInputLocation.create(jar, null); - final ClassType class1 = getIdentifierFactory().getClassType("Employee", "ds"); - final ClassType mainClass = getIdentifierFactory().getClassType("MiniApp"); - testClassReceival(pathBasedNamespace, class1, 6); - testClassReceival(pathBasedNamespace, mainClass, 6); + ArrayList sigs=new ArrayList<>(); + sigs.add(getIdentifierFactory().getClassType("Employee", "ds")); + sigs.add(getIdentifierFactory().getClassType("MiniApp")); + testClassReceival(pathBasedNamespace, sigs, 6); } @Test @@ -292,7 +293,7 @@ public void testWar() { PathBasedAnalysisInputLocation pathBasedNamespace = PathBasedAnalysisInputLocation.create(war, null); final ClassType warClass1 = getIdentifierFactory().getClassType("SimpleWarRead"); - testClassReceival(pathBasedNamespace, warClass1, 19); + testClassReceival(pathBasedNamespace, Collections.singletonList(warClass1), 19); } @Test diff --git a/sootup.java.sourcecode/src/main/java/sootup/java/sourcecode/frontend/WalaJavaClassProvider.java b/sootup.java.sourcecode/src/main/java/sootup/java/sourcecode/frontend/WalaJavaClassProvider.java index 7f43e7a72a9..e241bb39334 100644 --- a/sootup.java.sourcecode/src/main/java/sootup/java/sourcecode/frontend/WalaJavaClassProvider.java +++ b/sootup.java.sourcecode/src/main/java/sootup/java/sourcecode/frontend/WalaJavaClassProvider.java @@ -347,9 +347,9 @@ private void setExclusions(@Nullable String exclusionFilePath) { } @Override - public SootClassSource createClassSource( + public Optional> createClassSource( AnalysisInputLocation> srcNamespace, Path sourcePath, ClassType type) { - return getClassSource(type).orElse(null); + return getClassSource(type); } @Override diff --git a/sootup.java.sourcecode/src/main/java/sootup/java/sourcecode/inputlocation/JavaSourcePathAnalysisInputLocation.java b/sootup.java.sourcecode/src/main/java/sootup/java/sourcecode/inputlocation/JavaSourcePathAnalysisInputLocation.java index 4876bed564c..7fd91ca9cfd 100644 --- a/sootup.java.sourcecode/src/main/java/sootup/java/sourcecode/inputlocation/JavaSourcePathAnalysisInputLocation.java +++ b/sootup.java.sourcecode/src/main/java/sootup/java/sourcecode/inputlocation/JavaSourcePathAnalysisInputLocation.java @@ -159,7 +159,7 @@ public Optional> getClassSource( @Nonnull ClassType type, @Nonnull View view) { for (String path : sourcePaths) { try { - return Optional.ofNullable(classProvider.createClassSource(this, Paths.get(path), type)); + return classProvider.createClassSource(this, Paths.get(path), type); } catch (ResolveException e) { log.debug(type + " not found in sourcePath " + path, e); } diff --git a/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/frontend/WalaJavaClassProviderTest.java b/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/frontend/WalaJavaClassProviderTest.java index ae1887fb03f..ca29d2cc1b8 100644 --- a/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/frontend/WalaJavaClassProviderTest.java +++ b/sootup.java.sourcecode/src/test/java/sootup/java/sourcecode/frontend/WalaJavaClassProviderTest.java @@ -1,15 +1,19 @@ package sootup.java.sourcecode.frontend; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import categories.Java8Test; import java.nio.file.Paths; +import java.util.Optional; import org.junit.Test; import org.junit.experimental.categories.Category; import sootup.core.frontend.SootClassSource; import sootup.core.signatures.PackageName; import sootup.core.util.ImmutableUtils; +import sootup.java.core.JavaSootClass; import sootup.java.core.types.JavaClassType; import sootup.java.sourcecode.inputlocation.JavaSourcePathAnalysisInputLocation; @@ -26,10 +30,18 @@ public void testCreateClassSource() { new JavaSourcePathAnalysisInputLocation( ImmutableUtils.immutableSet(srcDir), exclusionFilePath); JavaClassType type = new JavaClassType("Array1", PackageName.DEFAULT_PACKAGE); + JavaClassType faketype = new JavaClassType("FakeJava", PackageName.DEFAULT_PACKAGE); WalaJavaClassProvider provider = new WalaJavaClassProvider(srcDir, exclusionFilePath); - SootClassSource classSource = + + Optional> opFakeClass = + provider.createClassSource(inputLocation, Paths.get(srcDir), faketype); + assertFalse(opFakeClass.isPresent()); + + Optional> opClass = provider.createClassSource(inputLocation, Paths.get(srcDir), type); + assertTrue(opClass.isPresent()); + SootClassSource classSource = opClass.get(); assertEquals(type, classSource.getClassType()); diff --git a/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleAnalysisInputLocation.java b/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleAnalysisInputLocation.java index cc961cb0ea4..6b4c77f9e5b 100644 --- a/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleAnalysisInputLocation.java +++ b/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleAnalysisInputLocation.java @@ -85,8 +85,7 @@ List>> walkDirectory( .flatMap( p -> StreamUtils.optionalToStream( - Optional.of( - classProvider.createClassSource(this, p, factory.fromPath(dirPath, p))))) + classProvider.createClassSource(this, p, factory.fromPath(dirPath, p)))) .collect(Collectors.toList()); } catch (IOException e) { @@ -126,7 +125,7 @@ public Optional> getClassSource( } } - return Optional.of(classProvider.createClassSource(this, pathToClass, type)); + return classProvider.createClassSource(this, pathToClass, type); } @Override diff --git a/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleClassProvider.java b/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleClassProvider.java index 1f50f58fc94..ea0ffa2c960 100644 --- a/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleClassProvider.java +++ b/sootup.jimple.parser/src/main/java/sootup/jimple/parser/JimpleClassProvider.java @@ -3,9 +3,13 @@ import java.io.IOException; import java.nio.file.Path; import java.util.List; +import java.util.Optional; import javax.annotation.Nonnull; import org.antlr.v4.runtime.CharStreams; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import sootup.core.frontend.ClassProvider; +import sootup.core.frontend.ResolveException; import sootup.core.frontend.SootClassSource; import sootup.core.inputlocation.AnalysisInputLocation; import sootup.core.inputlocation.FileType; @@ -19,22 +23,32 @@ public class JimpleClassProvider bodyInterceptors; + private static final @Nonnull Logger logger = LoggerFactory.getLogger(JimpleClassProvider.class); + public JimpleClassProvider(List bodyInterceptors) { this.bodyInterceptors = bodyInterceptors; } @Override - public SootClassSource createClassSource( + public Optional> createClassSource( AnalysisInputLocation> inputlocation, Path sourcePath, ClassType classSignature) { try { final JimpleConverter jimpleConverter = new JimpleConverter(); - return jimpleConverter.run( - CharStreams.fromPath(sourcePath), inputlocation, sourcePath, bodyInterceptors); - } catch (IOException e) { - throw new RuntimeException(e); + return Optional.of( + jimpleConverter.run( + CharStreams.fromPath(sourcePath), inputlocation, sourcePath, bodyInterceptors)); + } catch (IOException | ResolveException e) { + logger.warn( + "The jimple file of " + + classSignature + + " in path: " + + sourcePath + + " could not be converted because of: " + + e.getMessage()); + return Optional.empty(); } } diff --git a/sootup.jimple.parser/src/test/java/resources/jimple/FakeJimple.jimple b/sootup.jimple.parser/src/test/java/resources/jimple/FakeJimple.jimple new file mode 100644 index 00000000000..e320f3f2c48 --- /dev/null +++ b/sootup.jimple.parser/src/test/java/resources/jimple/FakeJimple.jimple @@ -0,0 +1 @@ +This is not a correct jimple file \ No newline at end of file diff --git a/sootup.jimple.parser/src/test/java/sootup/jimple/parser/JimpleAnalysisInputLocationTest.java b/sootup.jimple.parser/src/test/java/sootup/jimple/parser/JimpleAnalysisInputLocationTest.java index a05bc8bd7ad..ce86f569cb0 100644 --- a/sootup.jimple.parser/src/test/java/sootup/jimple/parser/JimpleAnalysisInputLocationTest.java +++ b/sootup.jimple.parser/src/test/java/sootup/jimple/parser/JimpleAnalysisInputLocationTest.java @@ -69,6 +69,29 @@ public PackageName getPackageName() { } }; + final ClassType classTypeFake = + new ClassType() { + @Override + public boolean isBuiltInClass() { + return false; + } + + @Override + public String getFullyQualifiedName() { + return "jimple.FakeJimple"; + } + + @Override + public String getClassName() { + return "FakeJimple"; + } + + @Override + public PackageName getPackageName() { + return new PackageName("jimple"); + } + }; + final String resourceDir = "src/test/java/resources/"; // files direct in dir @@ -79,6 +102,8 @@ public PackageName getPackageName() { assertTrue(classSource1.isPresent()); final Optional> classSource2 = jv1.getClass(classType); assertFalse(classSource2.isPresent()); + final Optional> classSourceNon = jv1.getClass(classTypeFake); + assertFalse(classSourceNon.isPresent()); // files in subdir structure final JimpleAnalysisInputLocation inputLocation2 = From aab87242fa1cee1b2a8776d6c0a79e246a5c602a Mon Sep 17 00:00:00 2001 From: Jonas Klauke Date: Fri, 18 Aug 2023 14:18:30 +0200 Subject: [PATCH 69/90] fmt --- .../java/bytecode/inputlocation/AnalysisInputLocationTest.java | 2 +- .../inputlocation/PathBasedAnalysisInputLocationTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/AnalysisInputLocationTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/AnalysisInputLocationTest.java index bc1f9b0ae1e..c740571158b 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/AnalysisInputLocationTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/AnalysisInputLocationTest.java @@ -62,7 +62,7 @@ protected void testClassReceival( JavaProject.builder(new JavaLanguage(8)).addInputLocation(ns).build(); final JavaView view = project.createView(); - for (ClassType classType:sigs) { + for (ClassType classType : sigs) { final Optional> clazzOpt = ns.getClassSource(classType, view); assertTrue(clazzOpt.isPresent()); diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java index 33f4c877747..b60892e6002 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java @@ -282,7 +282,7 @@ public void testJar() { PathBasedAnalysisInputLocation pathBasedNamespace = PathBasedAnalysisInputLocation.create(jar, null); - ArrayList sigs=new ArrayList<>(); + ArrayList sigs = new ArrayList<>(); sigs.add(getIdentifierFactory().getClassType("Employee", "ds")); sigs.add(getIdentifierFactory().getClassType("MiniApp")); testClassReceival(pathBasedNamespace, sigs, 6); From 95496b3cb45ebb58dd31b6157d45093243667fd8 Mon Sep 17 00:00:00 2001 From: stschott Date: Fri, 1 Sep 2023 12:24:06 +0200 Subject: [PATCH 70/90] update doc --- docs/getting-started.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/getting-started.md b/docs/getting-started.md index 4e5d609bb81..d2b41ac9e60 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -53,6 +53,10 @@ 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 From 51afb96c50832d874e575296b0d51a62924c3bb4 Mon Sep 17 00:00:00 2001 From: Jonas Klauke Date: Fri, 8 Sep 2023 10:45:13 +0200 Subject: [PATCH 71/90] remove incomplete multi release handling in the class type generation via a given path --- .../java/core/JavaIdentifierFactory.java | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/sootup.java.core/src/main/java/sootup/java/core/JavaIdentifierFactory.java b/sootup.java.core/src/main/java/sootup/java/core/JavaIdentifierFactory.java index c9742affc49..963179dfd0d 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/JavaIdentifierFactory.java +++ b/sootup.java.core/src/main/java/sootup/java/core/JavaIdentifierFactory.java @@ -33,7 +33,6 @@ import javax.annotation.Nonnull; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.ClassUtils; -import org.apache.commons.lang3.StringUtils; import sootup.core.IdentifierFactory; import sootup.core.model.SootClass; import sootup.core.signatures.FieldSignature; @@ -234,24 +233,15 @@ public AnnotationType getAnnotationType(final String fullyQualifiedClassName) { @Override @Nonnull public JavaClassType fromPath(@Nonnull final Path rootDirectory, @Nonnull final Path file) { - String path = file.toString(); - String separator = file.getFileSystem().getSeparator(); - - // for multi release jars, remove beginning of path - // /META-INF/versions/15/de/upb... - // we only want /de/upb... - if (path.startsWith("/META-INF/")) { - // start at 4th separator - int index = StringUtils.ordinalIndexOf(path, separator, 4); - path = path.substring(index); - } final int nameCountBaseDir = rootDirectory.toString().isEmpty() ? 0 : rootDirectory.getNameCount(); String fullyQualifiedName = FilenameUtils.removeExtension( - file.subpath(nameCountBaseDir, file.getNameCount()).toString().replace(separator, ".")); + file.subpath(nameCountBaseDir, file.getNameCount()) + .toString() + .replace(file.getFileSystem().getSeparator(), ".")); return getClassType(fullyQualifiedName); } @@ -524,7 +514,7 @@ public MethodSubSignature parseMethodSubSignature(@Nonnull String subSignature) return true; }) - .map(typeName -> getType(typeName)) + .map(this::getType) .collect(Collectors.toList()); return getMethodSubSignature(methodName, getType(returnName), argsList); From 1ec5b1256639b21b4f6249de2918694386723f03 Mon Sep 17 00:00:00 2001 From: Jonas Klauke Date: Fri, 8 Sep 2023 10:57:35 +0200 Subject: [PATCH 72/90] adapted incompleteSuperclassesOf to the new thrown exception in the class resolving method --- .../src/main/java/sootup/core/typehierarchy/TypeHierarchy.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/typehierarchy/TypeHierarchy.java b/sootup.core/src/main/java/sootup/core/typehierarchy/TypeHierarchy.java index 6e70a97ae20..5efed1cff0c 100644 --- a/sootup.core/src/main/java/sootup/core/typehierarchy/TypeHierarchy.java +++ b/sootup.core/src/main/java/sootup/core/typehierarchy/TypeHierarchy.java @@ -28,7 +28,6 @@ import javax.annotation.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import sootup.core.frontend.ResolveException; import sootup.core.types.*; import sootup.core.views.View; @@ -198,7 +197,7 @@ default List incompleteSuperClassesOf(@Nonnull ClassType classType) { superClasses.add(currentSuperClass); currentSuperClass = superClassOf(currentSuperClass); } - } catch (ResolveException ex) { + } catch (IllegalArgumentException ex) { logger.warn( "Could not find " + (currentSuperClass != null ? currentSuperClass : classType) From 32f856e4189f79471d1f6b7daa449b0a0f423d3a Mon Sep 17 00:00:00 2001 From: Jonas Klauke Date: Fri, 8 Sep 2023 11:39:38 +0200 Subject: [PATCH 73/90] added test case for incomplete Superclasses --- .../IncompleteSuperclassTest.java | 31 +++++++++++++++++++ .../IncompleteSuperclass/SubClassA.java | 3 ++ .../IncompleteSuperclass/SubClassB.java | 3 ++ 3 files changed, 37 insertions(+) create mode 100644 sootup.tests/src/test/java/sootup/tests/typehierarchy/viewtypehierarchytestcase/IncompleteSuperclassTest.java create mode 100644 sootup.tests/src/test/resources/javatypehierarchy/IncompleteSuperclass/SubClassA.java create mode 100644 sootup.tests/src/test/resources/javatypehierarchy/IncompleteSuperclass/SubClassB.java diff --git a/sootup.tests/src/test/java/sootup/tests/typehierarchy/viewtypehierarchytestcase/IncompleteSuperclassTest.java b/sootup.tests/src/test/java/sootup/tests/typehierarchy/viewtypehierarchytestcase/IncompleteSuperclassTest.java new file mode 100644 index 00000000000..c51a52b0a8f --- /dev/null +++ b/sootup.tests/src/test/java/sootup/tests/typehierarchy/viewtypehierarchytestcase/IncompleteSuperclassTest.java @@ -0,0 +1,31 @@ +package sootup.tests.typehierarchy.viewtypehierarchytestcase; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static sootup.core.util.ImmutableUtils.immutableList; + +import categories.Java8Test; +import com.google.common.collect.ImmutableList; +import java.util.List; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import sootup.core.typehierarchy.ViewTypeHierarchy; +import sootup.core.types.ClassType; +import sootup.tests.typehierarchy.JavaTypeHierarchyTestBase; + +/** @author Jonas Klauke * */ +@Category(Java8Test.class) +public class IncompleteSuperclassTest extends JavaTypeHierarchyTestBase { + @Test + public void method() { + ViewTypeHierarchy typeHierarchy = + (ViewTypeHierarchy) customTestWatcher.getView().getTypeHierarchy(); + List superclasses = + typeHierarchy.incompleteSuperClassesOf(getClassType("SubClassB")); + ClassType object = getClassType("java.lang.Object"); + ImmutableList expectedSuperClasses = + immutableList(getClassType("SubClassA"), object); + assertEquals(expectedSuperClasses, superclasses); + assertFalse(customTestWatcher.getView().getClass(object).isPresent()); + } +} diff --git a/sootup.tests/src/test/resources/javatypehierarchy/IncompleteSuperclass/SubClassA.java b/sootup.tests/src/test/resources/javatypehierarchy/IncompleteSuperclass/SubClassA.java new file mode 100644 index 00000000000..b3301dd276e --- /dev/null +++ b/sootup.tests/src/test/resources/javatypehierarchy/IncompleteSuperclass/SubClassA.java @@ -0,0 +1,3 @@ +public class SubClassA { + +} \ No newline at end of file diff --git a/sootup.tests/src/test/resources/javatypehierarchy/IncompleteSuperclass/SubClassB.java b/sootup.tests/src/test/resources/javatypehierarchy/IncompleteSuperclass/SubClassB.java new file mode 100644 index 00000000000..d278f9127fc --- /dev/null +++ b/sootup.tests/src/test/resources/javatypehierarchy/IncompleteSuperclass/SubClassB.java @@ -0,0 +1,3 @@ +public class SubClassB extends SubClassA { + +} \ No newline at end of file From f2e01b2091d5a00dbbc0a4d6c9b20accce6e6b5d Mon Sep 17 00:00:00 2001 From: Stefan Schott <64211065+stschott@users.noreply.github.com> Date: Thu, 14 Sep 2023 14:28:07 +0200 Subject: [PATCH 74/90] add javadoc link to readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9ba2e4492ff..051d37be1da 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@

-# 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). From 7047cdfa09c0031d379ecf3a55ceccd5dca065a6 Mon Sep 17 00:00:00 2001 From: Jonas Klauke Date: Fri, 15 Sep 2023 18:45:36 +0200 Subject: [PATCH 75/90] fixed that nrArgs can be -1 if the while condition is false but the -- instruction is still performed --- .../java/sootup/java/bytecode/frontend/AsmMethodSource.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java index 5b43a1771a1..a7ba0680728 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java @@ -1394,7 +1394,8 @@ private void convertInvokeDynamicInsn(@Nonnull InvokeDynamicInsnNode insn) { oprs = new Operand[nrArgs + 1]; } if (oprs != null) { - while (nrArgs-- > 0) { + while (nrArgs > 0) { + nrArgs--; oprs[nrArgs] = operandStack.pop(types.get(nrArgs)); } if (!isStaticInvokeExpr) { From 725710f19c09bf1cf3373207dd349be2bcdc5039 Mon Sep 17 00:00:00 2001 From: Jonas Klauke Date: Tue, 19 Sep 2023 13:01:47 +0200 Subject: [PATCH 76/90] improved the getting started documentation --- docs/getting-started.md | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/docs/getting-started.md b/docs/getting-started.md index d2b41ac9e60..ece9f35b4d7 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -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 inputLocation = - PathBasedAnalysisInputLocation.createForClassContainer(pathToBinary); + new JavaClassPathAnalysisInputLocation("path2Binary"); JavaLanguage language = new JavaLanguage(8); @@ -60,10 +58,8 @@ If you have access to the source code, it is also possible to create a project f !!! example "Create a project to analyze Java source code" ~~~java - Path pathToSource = Paths.get("src/test/resources/BasicSetup/source"); - AnalysisInputLocation inputLocation = - new JavaSourcePathAnalysisInputLocation(pathToSource.toString()); + new JavaSourcePathAnalysisInputLocation("path2Source"); JavaLanguage language = new JavaLanguage(8); @@ -76,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 inputLocation = new JimpleAnalysisInputLocation(pathToJimple); @@ -124,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() { + } } @@ -213,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 inputLocation = - PathBasedAnalysisInputLocation.createForClassContainer(pathToBinary); + new JavaClassPathAnalysisInputLocation("path2Binary"); JavaLanguage language = new JavaLanguage(8); From 9343413bb5121d57f4ea03cda209e3ad0e20b81a Mon Sep 17 00:00:00 2001 From: Jonas Klauke Date: Tue, 19 Sep 2023 13:05:20 +0200 Subject: [PATCH 77/90] fixed example --- docs/getting-started.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/getting-started.md b/docs/getting-started.md index ece9f35b4d7..d913d88bd55 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -121,7 +121,7 @@ Let's say the following is the target program that we want to analyze: } public static void main(String[] args) { - HelloWorld hw = new HelloWorld; + HelloWorld hw = new HelloWorld(); hw.hello(); } From e5086703a4f8b6244cf001e8885f1cc435f3a500 Mon Sep 17 00:00:00 2001 From: liyiwei <979621500@qq.com> Date: Mon, 9 Oct 2023 21:36:02 +0800 Subject: [PATCH 78/90] format --- .../core/typehierarchy/MethodDispatchResolver.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/typehierarchy/MethodDispatchResolver.java b/sootup.core/src/main/java/sootup/core/typehierarchy/MethodDispatchResolver.java index 16c604ceb09..80cd7734ac9 100644 --- a/sootup.core/src/main/java/sootup/core/typehierarchy/MethodDispatchResolver.java +++ b/sootup.core/src/main/java/sootup/core/typehierarchy/MethodDispatchResolver.java @@ -22,12 +22,6 @@ */ import com.google.common.collect.Sets; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; -import javax.annotation.Nonnull; import sootup.core.frontend.ResolveException; import sootup.core.jimple.common.expr.JSpecialInvokeExpr; import sootup.core.model.Method; @@ -37,6 +31,13 @@ import sootup.core.types.ClassType; import sootup.core.views.View; +import javax.annotation.Nonnull; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + public final class MethodDispatchResolver { private MethodDispatchResolver() {} From e4e5d762e62d5b67e0bb3a22e66638c81a4960da Mon Sep 17 00:00:00 2001 From: liyiwei <979621500@qq.com> Date: Mon, 9 Oct 2023 21:41:13 +0800 Subject: [PATCH 79/90] inline findConcreteMethodInSootClass with sootClass.getMethod --- .../typehierarchy/MethodDispatchResolver.java | 31 +++---------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/typehierarchy/MethodDispatchResolver.java b/sootup.core/src/main/java/sootup/core/typehierarchy/MethodDispatchResolver.java index 80cd7734ac9..2b168fcef17 100644 --- a/sootup.core/src/main/java/sootup/core/typehierarchy/MethodDispatchResolver.java +++ b/sootup.core/src/main/java/sootup/core/typehierarchy/MethodDispatchResolver.java @@ -86,7 +86,7 @@ public static Set resolveAbstractDispatch( () -> new ResolveException( "Could not resolve " + subtype + ", but found it in hierarchy."))) - .map(sootClass -> findConcreteMethodInSootClass(sootClass, m)) + .map(sootClass -> sootClass.getMethod(m.getSubSignature())) .filter(Optional::isPresent) .map(Optional::get) .filter(method -> !method.isAbstract()) @@ -112,7 +112,7 @@ public static Set resolveAllDispatchesInClasses( new ResolveException( "Could not resolve " + subtype + ", but found it in hierarchy."))) .filter(c -> classes.contains(c.getType())) - .map(sootClass -> findConcreteMethodInSootClass(sootClass, m)) + .map(sootClass -> sootClass.getMethod(m.getSubSignature())) .filter(Optional::isPresent) .map(Optional::get) .filter(method -> !method.isAbstract()) @@ -198,7 +198,7 @@ public static Optional resolveConcreteDispatch( classesInHierachyOrder.add(superClass); - SootMethod concreteMethod = findConcreteMethodInSootClass(superClass, m).orElse(null); + SootMethod concreteMethod = superClass.getMethod(m.getSubSignature()).orElse(null); if (concreteMethod != null && !concreteMethod.isAbstract()) { // found method is not abstract return Optional.of(concreteMethod.getSignature()); @@ -234,7 +234,7 @@ public static Optional resolveConcreteDispatch( // add found default method to possibleDefaultMethods Optional concreteMethod = - findConcreteMethodInSootClass(currentInterface, m); + currentInterface.getMethod(m.getSubSignature()); concreteMethod.ifPresent(possibleDefaultMethods::add); // if no default message is found search the default message in super interfaces @@ -283,29 +283,6 @@ private static List> getSootClassesOfInterfaces( .collect(Collectors.toList()); } - /** - * finds the concrete method in a SootClass - * - *

this method returns the concrete method of given method signature in a SootClass. Due to - * covariant, the given method signature can differ from the concrete method at the return type - * The method goes through all methods of the given SootClass and searches for a method which can - * dispatch. - * - * @param sootClass The method is searched in this SootClass - * @param methodSignature the signature of the searched method - * @return an Optional Object that can contain the found concrete method in the given SootClass - */ - private static Optional findConcreteMethodInSootClass( - SootClass sootClass, MethodSignature methodSignature) { - return sootClass.getMethods().stream() - .filter( - potentialTarget -> - methodSignature - .getSubSignature() - .equals(potentialTarget.getSignature().getSubSignature())) - .findAny(); - } - /** * Resolves the actual method called by the specialInvokeExpr that is contained by * container. From 7ba783f2bb928d32801f37f43c56f6507b0b44cc Mon Sep 17 00:00:00 2001 From: liyiwei <979621500@qq.com> Date: Mon, 9 Oct 2023 21:41:52 +0800 Subject: [PATCH 80/90] typo cleanup --- .../sootup/core/typehierarchy/MethodDispatchResolver.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/typehierarchy/MethodDispatchResolver.java b/sootup.core/src/main/java/sootup/core/typehierarchy/MethodDispatchResolver.java index 2b168fcef17..e6bf587f51f 100644 --- a/sootup.core/src/main/java/sootup/core/typehierarchy/MethodDispatchResolver.java +++ b/sootup.core/src/main/java/sootup/core/typehierarchy/MethodDispatchResolver.java @@ -184,7 +184,7 @@ public static Optional resolveConcreteDispatch( TypeHierarchy hierarchy = view.getTypeHierarchy(); ClassType superClassType = m.getDeclClassType(); SootClass startClass = view.getClass(superClassType).orElse(null); - ArrayList> classesInHierachyOrder = new ArrayList<>(); + ArrayList> classesInHierarchyOrder = new ArrayList<>(); // search concrete method in the class itself and its super classes do { @@ -196,7 +196,7 @@ public static Optional resolveConcreteDispatch( new ResolveException( "Did not find class " + finalSuperClassType + " in View")); - classesInHierachyOrder.add(superClass); + classesInHierarchyOrder.add(superClass); SootMethod concreteMethod = superClass.getMethod(m.getSubSignature()).orElse(null); if (concreteMethod != null && !concreteMethod.isAbstract()) { @@ -209,7 +209,7 @@ public static Optional resolveConcreteDispatch( // A not implemented method of an abstract class results into an abstract method return Optional.empty(); } - // found method is abstract and the startclass is not abstract + // found method is abstract and the start class is not abstract throw new ResolveException( "Could not find concrete method for " + m + " because the method is abstract"); } @@ -220,7 +220,7 @@ public static Optional resolveConcreteDispatch( // No super class contains the implemented method, search the concrete method in interfaces // first collect all interfaces and super interfaces List> worklist = - classesInHierachyOrder.stream() + classesInHierarchyOrder.stream() .flatMap(sootClass -> getSootClassesOfInterfaces(view, sootClass).stream()) .collect(Collectors.toList()); ArrayList> processedInterface = new ArrayList<>(); From fc3bd0df7a175b5bb9e684c1892aabb82f96c571 Mon Sep 17 00:00:00 2001 From: liyiwei <979621500@qq.com> Date: Mon, 9 Oct 2023 22:37:48 +0800 Subject: [PATCH 81/90] refactor resolveConcreteDispatch --- .../typehierarchy/MethodDispatchResolver.java | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/typehierarchy/MethodDispatchResolver.java b/sootup.core/src/main/java/sootup/core/typehierarchy/MethodDispatchResolver.java index e6bf587f51f..56f17a25832 100644 --- a/sootup.core/src/main/java/sootup/core/typehierarchy/MethodDispatchResolver.java +++ b/sootup.core/src/main/java/sootup/core/typehierarchy/MethodDispatchResolver.java @@ -37,6 +37,7 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; +import java.util.stream.Stream; public final class MethodDispatchResolver { private MethodDispatchResolver() {} @@ -173,6 +174,19 @@ public static boolean canDispatch( || hierarchy.isSubtype(called.getType(), potentialTarget.getType())); // covariant } + /** + * Returns all superclasses of classType(inclusive) up to java.lang.Object, which + * will be the last entry in the list, or till one of the superclasses is not contained in view. + */ + private static List> findSuperClassesInclusive( + View> view, ClassType classType) { + return Stream.concat( + Stream.of(classType), + view.getTypeHierarchy().incompleteSuperClassesOf(classType).stream() + ).flatMap(t -> view.getClass(t).map(Stream::of).orElseGet(Stream::empty)) + .collect(Collectors.toList()); + } + /** * Searches for the signature of the method that is the concrete implementation of m. * This is done by checking each superclass and the class itself for whether it contains the @@ -182,23 +196,12 @@ public static boolean canDispatch( public static Optional resolveConcreteDispatch( View> view, MethodSignature m) { TypeHierarchy hierarchy = view.getTypeHierarchy(); - ClassType superClassType = m.getDeclClassType(); - SootClass startClass = view.getClass(superClassType).orElse(null); - ArrayList> classesInHierarchyOrder = new ArrayList<>(); - - // search concrete method in the class itself and its super classes - do { - ClassType finalSuperClassType = superClassType; - SootClass superClass = - view.getClass(superClassType) - .orElseThrow( - () -> - new ResolveException( - "Did not find class " + finalSuperClassType + " in View")); + ClassType current = m.getDeclClassType(); + SootClass startClass = view.getClass(current).orElse(null); + List> classesInHierarchyOrder = findSuperClassesInclusive(view, current); - classesInHierarchyOrder.add(superClass); - - SootMethod concreteMethod = superClass.getMethod(m.getSubSignature()).orElse(null); + for (SootClass currentClass : classesInHierarchyOrder) { + SootMethod concreteMethod = currentClass.getMethod(m.getSubSignature()).orElse(null); if (concreteMethod != null && !concreteMethod.isAbstract()) { // found method is not abstract return Optional.of(concreteMethod.getSignature()); @@ -209,13 +212,12 @@ public static Optional resolveConcreteDispatch( // A not implemented method of an abstract class results into an abstract method return Optional.empty(); } - // found method is abstract and the start class is not abstract + // found method is abstract and the startClass is not abstract throw new ResolveException( "Could not find concrete method for " + m + " because the method is abstract"); } + } - superClassType = hierarchy.superClassOf(superClassType); - } while (superClassType != null); // No super class contains the implemented method, search the concrete method in interfaces // first collect all interfaces and super interfaces From 4705075c2a312e4c9262c16714bd3c5bd249b841 Mon Sep 17 00:00:00 2001 From: liyiwei <979621500@qq.com> Date: Mon, 9 Oct 2023 23:33:03 +0800 Subject: [PATCH 82/90] format --- .../typehierarchy/MethodDispatchResolver.java | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/typehierarchy/MethodDispatchResolver.java b/sootup.core/src/main/java/sootup/core/typehierarchy/MethodDispatchResolver.java index 56f17a25832..11f83a7e73e 100644 --- a/sootup.core/src/main/java/sootup/core/typehierarchy/MethodDispatchResolver.java +++ b/sootup.core/src/main/java/sootup/core/typehierarchy/MethodDispatchResolver.java @@ -22,6 +22,13 @@ */ import com.google.common.collect.Sets; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import javax.annotation.Nonnull; import sootup.core.frontend.ResolveException; import sootup.core.jimple.common.expr.JSpecialInvokeExpr; import sootup.core.model.Method; @@ -31,14 +38,6 @@ import sootup.core.types.ClassType; import sootup.core.views.View; -import javax.annotation.Nonnull; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; - public final class MethodDispatchResolver { private MethodDispatchResolver() {} @@ -87,7 +86,7 @@ public static Set resolveAbstractDispatch( () -> new ResolveException( "Could not resolve " + subtype + ", but found it in hierarchy."))) - .map(sootClass -> sootClass.getMethod(m.getSubSignature())) + .map(sootClass -> sootClass.getMethod(m.getSubSignature())) .filter(Optional::isPresent) .map(Optional::get) .filter(method -> !method.isAbstract()) @@ -113,7 +112,7 @@ public static Set resolveAllDispatchesInClasses( new ResolveException( "Could not resolve " + subtype + ", but found it in hierarchy."))) .filter(c -> classes.contains(c.getType())) - .map(sootClass -> sootClass.getMethod(m.getSubSignature())) + .map(sootClass -> sootClass.getMethod(m.getSubSignature())) .filter(Optional::isPresent) .map(Optional::get) .filter(method -> !method.isAbstract()) @@ -175,16 +174,17 @@ public static boolean canDispatch( } /** - * Returns all superclasses of classType(inclusive) up to java.lang.Object, which - * will be the last entry in the list, or till one of the superclasses is not contained in view. + * Returns all superclasses of classType(inclusive) up to java.lang.Object + * , which will be the last entry in the list, or till one of the superclasses is not + * contained in view. */ private static List> findSuperClassesInclusive( - View> view, ClassType classType) { + View> view, ClassType classType) { return Stream.concat( - Stream.of(classType), - view.getTypeHierarchy().incompleteSuperClassesOf(classType).stream() - ).flatMap(t -> view.getClass(t).map(Stream::of).orElseGet(Stream::empty)) - .collect(Collectors.toList()); + Stream.of(classType), + view.getTypeHierarchy().incompleteSuperClassesOf(classType).stream()) + .flatMap(t -> view.getClass(t).map(Stream::of).orElseGet(Stream::empty)) + .collect(Collectors.toList()); } /** @@ -218,11 +218,10 @@ public static Optional resolveConcreteDispatch( } } - // No super class contains the implemented method, search the concrete method in interfaces // first collect all interfaces and super interfaces List> worklist = - classesInHierarchyOrder.stream() + classesInHierarchyOrder.stream() .flatMap(sootClass -> getSootClassesOfInterfaces(view, sootClass).stream()) .collect(Collectors.toList()); ArrayList> processedInterface = new ArrayList<>(); @@ -236,7 +235,7 @@ public static Optional resolveConcreteDispatch( // add found default method to possibleDefaultMethods Optional concreteMethod = - currentInterface.getMethod(m.getSubSignature()); + currentInterface.getMethod(m.getSubSignature()); concreteMethod.ifPresent(possibleDefaultMethods::add); // if no default message is found search the default message in super interfaces From 312465ce31605328f3cadc5271107ac40f256742 Mon Sep 17 00:00:00 2001 From: liyiwei <979621500@qq.com> Date: Tue, 10 Oct 2023 22:47:38 +0800 Subject: [PATCH 83/90] unify conditions --- .../typehierarchy/MethodDispatchResolver.java | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/typehierarchy/MethodDispatchResolver.java b/sootup.core/src/main/java/sootup/core/typehierarchy/MethodDispatchResolver.java index 11f83a7e73e..ff6f94fb36d 100644 --- a/sootup.core/src/main/java/sootup/core/typehierarchy/MethodDispatchResolver.java +++ b/sootup.core/src/main/java/sootup/core/typehierarchy/MethodDispatchResolver.java @@ -201,20 +201,21 @@ public static Optional resolveConcreteDispatch( List> classesInHierarchyOrder = findSuperClassesInclusive(view, current); for (SootClass currentClass : classesInHierarchyOrder) { - SootMethod concreteMethod = currentClass.getMethod(m.getSubSignature()).orElse(null); - if (concreteMethod != null && !concreteMethod.isAbstract()) { - // found method is not abstract - return Optional.of(concreteMethod.getSignature()); - } - if (concreteMethod != null && concreteMethod.isAbstract()) { - if (startClass.isAbstract() - && !startClass.getType().equals(concreteMethod.getDeclaringClassType())) { - // A not implemented method of an abstract class results into an abstract method - return Optional.empty(); + SootMethod method = currentClass.getMethod(m.getSubSignature()).orElse(null); + if (method != null) { + if (!method.isAbstract()) { + // found method is not abstract + return Optional.of(method.getSignature()); + } else { + if (startClass.isAbstract() + && !startClass.getType().equals(method.getDeclaringClassType())) { + // A not implemented method of an abstract class results into an abstract method + return Optional.empty(); + } + // found method is abstract and the startClass is not abstract + throw new ResolveException( + "Could not find concrete method for " + m + " because the method is abstract"); } - // found method is abstract and the startClass is not abstract - throw new ResolveException( - "Could not find concrete method for " + m + " because the method is abstract"); } } From ee41bafa92304eb345dc52bb17ae410cd4d40dd4 Mon Sep 17 00:00:00 2001 From: Jonas Klauke Date: Mon, 16 Oct 2023 18:31:07 +0200 Subject: [PATCH 84/90] removed static invoke handling caused by wrongly adaption of soot code for SootUp. SootUp does not model lambda expressions as static method calls. --- .../java/bytecode/frontend/AsmMethodSource.java | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java index a7ba0680728..857b4d21349 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java @@ -73,7 +73,6 @@ import sootup.core.jimple.common.expr.JInstanceOfExpr; import sootup.core.jimple.common.expr.JNewArrayExpr; import sootup.core.jimple.common.expr.JNewMultiArrayExpr; -import sootup.core.jimple.common.expr.JStaticInvokeExpr; import sootup.core.jimple.common.ref.*; import sootup.core.jimple.common.stmt.*; import sootup.core.jimple.javabytecode.stmt.JSwitchStmt; @@ -1387,20 +1386,12 @@ private void convertInvokeDynamicInsn(@Nonnull InvokeDynamicInsnNode insn) { List types = expr.getMethodSignature().getParameterTypes(); Operand[] oprs; int nrArgs = types.size(); - final boolean isStaticInvokeExpr = expr instanceof JStaticInvokeExpr; - if (isStaticInvokeExpr) { - oprs = (nrArgs == 0) ? null : new Operand[nrArgs]; - } else { - oprs = new Operand[nrArgs + 1]; - } + oprs = (nrArgs == 0) ? null : new Operand[nrArgs]; if (oprs != null) { while (nrArgs > 0) { nrArgs--; oprs[nrArgs] = operandStack.pop(types.get(nrArgs)); } - if (!isStaticInvokeExpr) { - oprs[oprs.length - 1] = operandStack.pop(); - } frame.mergeIn(currentLineNumber, oprs); } returnType = expr.getType(); From 74da0deb0dc141068fe0bd838d025b66d97bd43c Mon Sep 17 00:00:00 2001 From: liyiwei <979621500@qq.com> Date: Tue, 17 Oct 2023 00:34:56 +0800 Subject: [PATCH 85/90] clean up assertions --- .../java/sootup/callgraph/AbstractCallGraphAlgorithm.java | 8 +++++--- .../java/sootup/core/typehierarchy/TypeHierarchy.java | 2 +- .../src/main/java/sootup/java/core/views/JavaView.java | 6 +----- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/sootup.callgraph/src/main/java/sootup/callgraph/AbstractCallGraphAlgorithm.java b/sootup.callgraph/src/main/java/sootup/callgraph/AbstractCallGraphAlgorithm.java index eb899f1e0af..0cb5d0c7275 100644 --- a/sootup.callgraph/src/main/java/sootup/callgraph/AbstractCallGraphAlgorithm.java +++ b/sootup.callgraph/src/main/java/sootup/callgraph/AbstractCallGraphAlgorithm.java @@ -291,7 +291,7 @@ protected final T findMethodInHierarchy( if (optSc.isPresent()) { SootClass sc = optSc.get(); - List superClasses = view.getTypeHierarchy().superClassesOf(sc.getType()); + List superClasses = view.getTypeHierarchy().incompleteSuperClassesOf(sc.getType()); Set interfaces = view.getTypeHierarchy().implementedInterfacesOf(sc.getType()); superClasses.addAll(interfaces); @@ -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 superClasses = view.getTypeHierarchy().superClassesOf(classType); + List superClasses = view.getTypeHierarchy().incompleteSuperClassesOf(classType); Set implementedInterfaces = view.getTypeHierarchy().implementedInterfacesOf(classType); Stream superTypes = @@ -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( diff --git a/sootup.core/src/main/java/sootup/core/typehierarchy/TypeHierarchy.java b/sootup.core/src/main/java/sootup/core/typehierarchy/TypeHierarchy.java index 5efed1cff0c..5a5b0e1ab59 100644 --- a/sootup.core/src/main/java/sootup/core/typehierarchy/TypeHierarchy.java +++ b/sootup.core/src/main/java/sootup/core/typehierarchy/TypeHierarchy.java @@ -154,7 +154,7 @@ default boolean isSubtype(@Nonnull Type supertype, @Nonnull Type potentialSubtyp return (supertypeName.equals("java.lang.Object") && !potentialSubtypeName.equals("java.lang.Object")) || supertype.equals(superClassOf((ClassType) potentialSubtype)) - || superClassesOf((ClassType) potentialSubtype).contains(supertype) + || incompleteSuperClassesOf((ClassType) potentialSubtype).contains(supertype) || implementedInterfacesOf((ClassType) potentialSubtype).contains(supertype); } else if (potentialSubtype instanceof ArrayType) { // Arrays are subtypes of java.lang.Object, java.io.Serializable and java.lang.Cloneable diff --git a/sootup.java.core/src/main/java/sootup/java/core/views/JavaView.java b/sootup.java.core/src/main/java/sootup/java/core/views/JavaView.java index 682edb9333a..f891055ad5f 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/views/JavaView.java +++ b/sootup.java.core/src/main/java/sootup/java/core/views/JavaView.java @@ -130,11 +130,7 @@ public synchronized Optional getClass(@Nonnull ClassType type) { Optional> abstractClass = getAbstractClass(type); - if (!abstractClass.isPresent()) { - return Optional.empty(); - } - - return buildClassFrom(abstractClass.get()); + return abstractClass.flatMap(this::buildClassFrom); } /** Returns the amount of classes that are currently stored in the cache. */ From 884c62820ba90381069176975b5dfba68333c975 Mon Sep 17 00:00:00 2001 From: Jonas Klauke Date: Tue, 17 Oct 2023 17:48:24 +0200 Subject: [PATCH 86/90] removed unnecessary constructor in MethodHandle --- .../core/jimple/common/constant/MethodHandle.java | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/jimple/common/constant/MethodHandle.java b/sootup.core/src/main/java/sootup/core/jimple/common/constant/MethodHandle.java index fd1792c29e4..f26729b0a8c 100644 --- a/sootup.core/src/main/java/sootup/core/jimple/common/constant/MethodHandle.java +++ b/sootup.core/src/main/java/sootup/core/jimple/common/constant/MethodHandle.java @@ -94,19 +94,7 @@ public MethodHandle( @Nonnull SootClassMemberSignature referenceSignature, int tag, @Nonnull Type type) { - this.kind = Kind.getKind(tag); - this.type = type; - this.referenceSignature = referenceSignature; - if ((this.isMethodRef() && !(referenceSignature instanceof MethodSignature)) - || (this.isFieldRef() && !(referenceSignature instanceof FieldSignature))) { - throw new IllegalArgumentException( - "Tag:" - + tag - + " " - + kind.valStr - + " does not match with the given signature:" - + referenceSignature.getClass()); - } + this(referenceSignature, Kind.getKind(tag), type); } public MethodHandle( From 1ed3ab1a3266190027c42bbd59b6495b0a3fda9f Mon Sep 17 00:00:00 2001 From: Jonas Klauke Date: Tue, 17 Oct 2023 17:48:40 +0200 Subject: [PATCH 87/90] added tests for MethodHandle --- .../jimple/common/constant/MethodHandle.java | 4 + .../common/constant/MethodHandleTest.java | 114 ++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 sootup.core/src/test/java/sootup/core/jimple/common/constant/MethodHandleTest.java diff --git a/sootup.core/src/main/java/sootup/core/jimple/common/constant/MethodHandle.java b/sootup.core/src/main/java/sootup/core/jimple/common/constant/MethodHandle.java index f26729b0a8c..8c02e3246f8 100644 --- a/sootup.core/src/main/java/sootup/core/jimple/common/constant/MethodHandle.java +++ b/sootup.core/src/main/java/sootup/core/jimple/common/constant/MethodHandle.java @@ -148,6 +148,10 @@ public Type getType() { return type; } + public Kind getKind() { + return kind; + } + public SootClassMemberSignature getReferenceSignature() { return referenceSignature; } diff --git a/sootup.core/src/test/java/sootup/core/jimple/common/constant/MethodHandleTest.java b/sootup.core/src/test/java/sootup/core/jimple/common/constant/MethodHandleTest.java new file mode 100644 index 00000000000..e6db3b602dd --- /dev/null +++ b/sootup.core/src/test/java/sootup/core/jimple/common/constant/MethodHandleTest.java @@ -0,0 +1,114 @@ +package sootup.core.jimple.common.constant; + +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertThrows; + +import categories.Java8Test; +import java.util.Collections; +import junit.framework.TestCase; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import sootup.core.jimple.common.constant.MethodHandle.Kind; +import sootup.core.signatures.FieldSignature; +import sootup.core.signatures.MethodSignature; +import sootup.core.signatures.PackageName; +import sootup.core.types.ClassType; +import sootup.core.types.PrimitiveType.IntType; +import sootup.core.types.VoidType; + +@Category(Java8Test.class) +public class MethodHandleTest extends TestCase { + + @Test + public void testMethodHandle() { + assertEquals(Kind.REF_GET_FIELD.toString(), "REF_GET_FIELD"); + assertEquals(Kind.REF_GET_FIELD.getValueName(), "REF_GET_FIELD"); + assertEquals(Kind.REF_GET_FIELD.getValue(), 1); + + for (Kind currentKind : Kind.values()) { + assertEquals(currentKind, Kind.getKind(currentKind.getValueName())); + assertEquals(currentKind, Kind.getKind(currentKind.getValue())); + } + // not valid kinds + assertThrows(RuntimeException.class, () -> Kind.getKind(0)); + assertThrows(RuntimeException.class, () -> Kind.getKind("invalid")); + + assertTrue(MethodHandle.isMethodRef(Kind.REF_INVOKE_VIRTUAL.getValue())); + assertTrue(MethodHandle.isMethodRef(Kind.REF_INVOKE_STATIC.getValue())); + assertTrue(MethodHandle.isMethodRef(Kind.REF_INVOKE_SPECIAL.getValue())); + assertTrue(MethodHandle.isMethodRef(Kind.REF_INVOKE_CONSTRUCTOR.getValue())); + assertTrue(MethodHandle.isMethodRef(Kind.REF_INVOKE_INTERFACE.getValue())); + assertFalse(MethodHandle.isMethodRef(Kind.REF_GET_FIELD.getValue())); + assertFalse(MethodHandle.isMethodRef(Kind.REF_PUT_FIELD.getValue())); + assertFalse(MethodHandle.isMethodRef(Kind.REF_PUT_FIELD_STATIC.getValue())); + assertFalse(MethodHandle.isMethodRef(Kind.REF_GET_FIELD_STATIC.getValue())); + + assertFalse(MethodHandle.isFieldRef(Kind.REF_INVOKE_VIRTUAL.getValue())); + assertFalse(MethodHandle.isFieldRef(Kind.REF_INVOKE_STATIC.getValue())); + assertFalse(MethodHandle.isFieldRef(Kind.REF_INVOKE_SPECIAL.getValue())); + assertFalse(MethodHandle.isFieldRef(Kind.REF_INVOKE_CONSTRUCTOR.getValue())); + assertFalse(MethodHandle.isFieldRef(Kind.REF_INVOKE_INTERFACE.getValue())); + assertTrue(MethodHandle.isFieldRef(Kind.REF_GET_FIELD.getValue())); + assertTrue(MethodHandle.isFieldRef(Kind.REF_PUT_FIELD.getValue())); + assertTrue(MethodHandle.isFieldRef(Kind.REF_PUT_FIELD_STATIC.getValue())); + assertTrue(MethodHandle.isFieldRef(Kind.REF_GET_FIELD_STATIC.getValue())); + + ClassType classType = + new ClassType() { + @Override + public boolean isBuiltInClass() { + return false; + } + + @Override + public String getFullyQualifiedName() { + return "test.A"; + } + + @Override + public String getClassName() { + return "A"; + } + + @Override + public PackageName getPackageName() { + return new PackageName("test"); + } + }; + MethodSignature ms = + new MethodSignature(classType, "m1", Collections.emptyList(), VoidType.getInstance()); + FieldSignature fs = new FieldSignature(classType, "f", IntType.getInstance()); + + MethodHandle mhms = new MethodHandle(ms, Kind.REF_INVOKE_VIRTUAL.getValue(), classType); + MethodHandle mhfs = new MethodHandle(fs, Kind.REF_GET_FIELD, classType); + + // not valid Method handles + assertThrows( + IllegalArgumentException.class, + () -> new MethodHandle(fs, Kind.REF_INVOKE_CONSTRUCTOR, classType)); + assertThrows( + IllegalArgumentException.class, () -> new MethodHandle(ms, Kind.REF_GET_FIELD, classType)); + + assertTrue(mhms.isMethodRef()); + assertFalse(mhms.isFieldRef()); + + assertFalse(mhfs.isMethodRef()); + assertTrue(mhfs.isFieldRef()); + + assertEquals(mhfs.getType(), classType); + assertEquals( + mhfs.toString(), + "methodhandle: \"" + mhfs.getKind() + "\" " + mhfs.getReferenceSignature()); + + MethodHandle mhms2 = new MethodHandle(ms, Kind.REF_INVOKE_VIRTUAL.getValue(), classType); + assertTrue(mhfs.equals(mhfs)); + assertFalse(mhfs.equals(mhms)); + assertFalse(mhfs.equals(null)); + assertFalse(mhfs.equals(classType)); + assertFalse(mhfs.equals(mhms2)); + + assertEquals(mhfs.hashCode(), mhfs.hashCode()); + assertEquals(mhms.hashCode(), mhms2.hashCode()); + assertNotEquals(mhfs.hashCode(), mhms.hashCode()); + } +} From 1f2614b037961a110f14121a982cdeae8012130f Mon Sep 17 00:00:00 2001 From: Indrale Dnyaneshwar <118615488+Dnyanu76@users.noreply.github.com> Date: Wed, 18 Oct 2023 18:52:54 +0530 Subject: [PATCH 88/90] Remove typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 051d37be1da..5d2b9119d87 100644 --- a/README.md +++ b/README.md @@ -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 From 5f6a1cd377e1a4f38aed5d96253b1f2349743936 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Wed, 25 Oct 2023 13:51:19 +0200 Subject: [PATCH 89/90] unify the parameter order; remove 'convenvience' method with unnecessary mix of layers Signatures<->SootClass --- .../main/java/sootup/core/IdentifierFactory.java | 16 ++-------------- .../PathBasedAnalysisInputLocationTest.java | 2 +- .../bytecode/interceptors/AggregatorTest.java | 2 +- .../interceptors/CastAndReturnInlinerTest.java | 4 ++-- .../ConditionalBranchFolderTest.java | 4 ++-- .../ConstantPropagatorAndFolderTest.java | 2 +- .../DeadAssignmentEliminatorTest.java | 2 +- .../bytecode/interceptors/NopEliminatorTest.java | 2 +- .../interceptors/UnusedLocalEliminatorTest.java | 2 +- .../sootup/java/core/JavaIdentifierFactory.java | 16 ++++------------ .../java/core/JavaModuleIdentifierFactory.java | 4 ++-- .../core/jimple/common/stmt/JInvokeStmtTest.java | 10 +++++----- .../sootup/java/core/model/SootMethodTest.java | 2 +- .../java/core/printer/JimplePrinterTest.java | 4 ++-- .../core/printer/LegacyJimplePrinterTest.java | 2 +- .../signatures/JavaIdentifierFactoryTest.java | 16 ++++++++-------- .../frontend/InstructionConverter.java | 10 +++++----- .../java/sootup/tests/MutableSootClientTest.java | 2 +- 18 files changed, 41 insertions(+), 61 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/IdentifierFactory.java b/sootup.core/src/main/java/sootup/core/IdentifierFactory.java index 2c094925636..cd747f44586 100644 --- a/sootup.core/src/main/java/sootup/core/IdentifierFactory.java +++ b/sootup.core/src/main/java/sootup/core/IdentifierFactory.java @@ -26,7 +26,6 @@ import java.util.List; import java.util.Optional; import javax.annotation.Nonnull; -import sootup.core.model.SootClass; import sootup.core.signatures.FieldSignature; import sootup.core.signatures.FieldSubSignature; import sootup.core.signatures.MethodSignature; @@ -54,15 +53,15 @@ public interface IdentifierFactory { /** * Gets the method signature. * - * @param methodName the method name * @param fullyQualifiedNameDeclClass the fully qualified name decl class + * @param methodName the method name * @param fqReturnType the fq return type * @param parameters the parameters * @return the method signature */ MethodSignature getMethodSignature( - String methodName, String fullyQualifiedNameDeclClass, + String methodName, String fqReturnType, List parameters); @@ -96,17 +95,6 @@ MethodSignature getMethodSignature( Type fqReturnType, List parameters); - /** - * Gets the method signature. - * - * @param declaringClass the declaring class - * @param subSignature the sub signature - * @return the method signature - */ - @Nonnull - MethodSignature getMethodSignature( - @Nonnull SootClass declaringClass, @Nonnull MethodSubSignature subSignature); - /** * Gets the method signature. * diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java index b60892e6002..80ff26614ac 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java @@ -380,7 +380,7 @@ public Object resolveAnnotationsDefaultValue() { public MethodSignature getSignature() { return JavaIdentifierFactory.getInstance() .getMethodSignature( - utilsClass, optionalToStreamMethodSubSignature); + utilsClass.getType(), optionalToStreamMethodSubSignature); } }) .withSignature( diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/AggregatorTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/AggregatorTest.java index ca6666af81c..4d3f8635f0c 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/AggregatorTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/AggregatorTest.java @@ -88,7 +88,7 @@ private static Body.BodyBuilder createBodyBuilder(boolean withAggregation) { builder.setStartingStmt(intToA); builder.setMethodSignature( JavaIdentifierFactory.getInstance() - .getMethodSignature("test", "ab.c", "void", Collections.emptyList())); + .getMethodSignature("ab.c", "test", "void", Collections.emptyList())); builder.addFlow(intToA, intToB); builder.addFlow(intToB, ret); diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/CastAndReturnInlinerTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/CastAndReturnInlinerTest.java index cf5541c65cf..65cf0a8d025 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/CastAndReturnInlinerTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/CastAndReturnInlinerTest.java @@ -66,7 +66,7 @@ public void testModification() { bodyBuilder.setMethodSignature( JavaIdentifierFactory.getInstance() - .getMethodSignature("test", "ab.c", "void", Collections.emptyList())); + .getMethodSignature("ab.c", "test", "void", Collections.emptyList())); Body testBody = bodyBuilder.build(); new CastAndReturnInliner().interceptBody(bodyBuilder, null); @@ -119,7 +119,7 @@ public void testNoModification() { bodyBuilder.addFlow(bToA, ret); bodyBuilder.setMethodSignature( JavaIdentifierFactory.getInstance() - .getMethodSignature("test", "ab.c", "void", Collections.emptyList())); + .getMethodSignature("ab.c", "test", "void", Collections.emptyList())); Body testBody = bodyBuilder.build(); new CastAndReturnInliner().interceptBody(bodyBuilder, null); diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/ConditionalBranchFolderTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/ConditionalBranchFolderTest.java index 8666144261e..a512b1d72a7 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/ConditionalBranchFolderTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/ConditionalBranchFolderTest.java @@ -111,7 +111,7 @@ private static Body.BodyBuilder createBodyBuilder(int constantCondition) { final MethodSignature methodSignature = JavaIdentifierFactory.getInstance() .getMethodSignature( - "toString", "java.lang.Object", "String", Collections.emptyList()); + "java.lang.Object", "toString", "String", Collections.emptyList()); Local base = new Local( "someObjectThatHasSomethingToString", @@ -140,7 +140,7 @@ private static Body.BodyBuilder createBodyBuilder(int constantCondition) { bodyBuilder.addFlow(ifStmt, retb); bodyBuilder.setMethodSignature( JavaIdentifierFactory.getInstance() - .getMethodSignature("test", "ab.c", "void", Collections.emptyList())); + .getMethodSignature("ab.c", "test", "void", Collections.emptyList())); return bodyBuilder; } } diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/ConstantPropagatorAndFolderTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/ConstantPropagatorAndFolderTest.java index e6e4ad668af..ddc7872b716 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/ConstantPropagatorAndFolderTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/ConstantPropagatorAndFolderTest.java @@ -99,7 +99,7 @@ private static Body.BodyBuilder createBody(boolean constantFolding) { builder.setStartingStmt(assignA); builder.setMethodSignature( JavaIdentifierFactory.getInstance() - .getMethodSignature("test", "ab.c", "void", Collections.emptyList())); + .getMethodSignature("ab.c", "test", "void", Collections.emptyList())); builder.addFlow(assignA, assignB); builder.addFlow(assignB, assignC); diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/DeadAssignmentEliminatorTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/DeadAssignmentEliminatorTest.java index 51125d4d4de..dc1772c3a57 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/DeadAssignmentEliminatorTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/DeadAssignmentEliminatorTest.java @@ -63,7 +63,7 @@ private static Body.BodyBuilder createBody(boolean essentialOption) { builder.setStartingStmt(strToA); builder.setMethodSignature( JavaIdentifierFactory.getInstance() - .getMethodSignature("test", "ab.c", "void", Collections.emptyList())); + .getMethodSignature("ab.c", "test", "void", Collections.emptyList())); if (essentialOption) { Stmt newToB = JavaJimple.newAssignStmt(b, JavaJimple.newNewExpr(objectType), noPositionInfo); diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/NopEliminatorTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/NopEliminatorTest.java index 06ba6e2aa86..71b633cc385 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/NopEliminatorTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/NopEliminatorTest.java @@ -91,7 +91,7 @@ private static Body.BodyBuilder createBody(boolean withNop) { builder.setStartingStmt(strToA); builder.setMethodSignature( JavaIdentifierFactory.getInstance() - .getMethodSignature("test", "ab.c", "void", Collections.emptyList())); + .getMethodSignature("ab.c", "test", "void", Collections.emptyList())); builder.addFlow(strToA, jump); builder.addFlow(jump, bToA); diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/UnusedLocalEliminatorTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/UnusedLocalEliminatorTest.java index 50d82a9c1d9..a058cd0c069 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/UnusedLocalEliminatorTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/UnusedLocalEliminatorTest.java @@ -83,7 +83,7 @@ private static Body.BodyBuilder createBody(boolean unusedLocals) { builder.setMethodSignature( JavaIdentifierFactory.getInstance() - .getMethodSignature("test", "a.b.c", "void", Collections.emptyList())); + .getMethodSignature("a.b.c", "test", "void", Collections.emptyList())); return builder; } } diff --git a/sootup.java.core/src/main/java/sootup/java/core/JavaIdentifierFactory.java b/sootup.java.core/src/main/java/sootup/java/core/JavaIdentifierFactory.java index 963179dfd0d..6384ef1ff8b 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/JavaIdentifierFactory.java +++ b/sootup.java.core/src/main/java/sootup/java/core/JavaIdentifierFactory.java @@ -34,7 +34,6 @@ import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.ClassUtils; import sootup.core.IdentifierFactory; -import sootup.core.model.SootClass; import sootup.core.signatures.FieldSignature; import sootup.core.signatures.FieldSubSignature; import sootup.core.signatures.MethodSignature; @@ -264,16 +263,16 @@ public PackageName getPackageName(@Nonnull final String packageName) { /** * Always creates a new MethodSignature AND a new ClassSignature. * - * @param methodName the method's name * @param fullyQualifiedNameDeclClass the fully-qualified name of the declaring class - * @param parameters the methods parameters fully-qualified name or a primitive's name + * @param methodName the method's name * @param fqReturnType the fully-qualified name of the return type or a primitive's name + * @param parameters the methods parameters fully-qualified name or a primitive's name * @return a MethodSignature */ @Override public MethodSignature getMethodSignature( - final String methodName, final String fullyQualifiedNameDeclClass, + final String methodName, final String fqReturnType, final List parameters) { JavaClassType declaringClass = getClassType(fullyQualifiedNameDeclClass); @@ -321,13 +320,6 @@ public MethodSignature getMethodSignature( return new MethodSignature(declaringClassSignature, methodName, parameters, fqReturnType); } - @Override - @Nonnull - public MethodSignature getMethodSignature( - @Nonnull SootClass declaringClass, @Nonnull MethodSubSignature subSignature) { - return getMethodSignature(declaringClass.getType(), subSignature); - } - @Override @Nonnull public MethodSignature getMethodSignature( @@ -425,7 +417,7 @@ public MethodSignature parseMethodSignature(@Nonnull String methodSignature) { }) .collect(Collectors.toList()); - return getMethodSignature(methodName, className, returnName, argsList); + return getMethodSignature(className, methodName, returnName, argsList); } @Nonnull diff --git a/sootup.java.core/src/main/java/sootup/java/core/JavaModuleIdentifierFactory.java b/sootup.java.core/src/main/java/sootup/java/core/JavaModuleIdentifierFactory.java index 2f504ac914f..0a24d88ac3f 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/JavaModuleIdentifierFactory.java +++ b/sootup.java.core/src/main/java/sootup/java/core/JavaModuleIdentifierFactory.java @@ -206,12 +206,12 @@ public ModuleJavaClassType getClassType(String fullyQualifiedClassName) { @Override public MethodSignature getMethodSignature( - String methodName, String fullyQualifiedNameDeclClass, + String methodName, String fqReturnType, List parameters) { return super.getMethodSignature( - methodName, fullyQualifiedNameDeclClass, fqReturnType, parameters); + fullyQualifiedNameDeclClass, methodName, fqReturnType, parameters); } } } diff --git a/sootup.java.core/src/test/java/sootup/java/core/jimple/common/stmt/JInvokeStmtTest.java b/sootup.java.core/src/test/java/sootup/java/core/jimple/common/stmt/JInvokeStmtTest.java index dba62305329..6bb00884cfb 100644 --- a/sootup.java.core/src/test/java/sootup/java/core/jimple/common/stmt/JInvokeStmtTest.java +++ b/sootup.java.core/src/test/java/sootup/java/core/jimple/common/stmt/JInvokeStmtTest.java @@ -93,7 +93,7 @@ public void test() { // JStaticInvokeExpr MethodSignature statMethodSig = dif.getMethodSignature( - "print", "java.system.Out", "void", Collections.singletonList("String")); + "java.system.Out", "print", "void", Collections.singletonList("String")); Stmt staticInvokeStmt = new JInvokeStmt( new JStaticInvokeExpr( @@ -112,7 +112,7 @@ public void test() { // JSpecialInvoke MethodSignature smethodSig = - dif.getMethodSignature("", "java.lang.Object", "void", Collections.emptyList()); + dif.getMethodSignature("java.lang.Object", "", "void", Collections.emptyList()); Stmt specialInvokeStmt = new JInvokeStmt( new JSpecialInvokeExpr( @@ -129,7 +129,7 @@ public void test() { // JInterfaceInvoke MethodSignature imethodSig = - dif.getMethodSignature("remove", "java.util.Iterator", "void", Collections.emptyList()); + dif.getMethodSignature("java.util.Iterator", "remove", "void", Collections.emptyList()); Stmt interfaceInvokeStmt = new JInvokeStmt( new JInterfaceInvokeExpr( @@ -147,12 +147,12 @@ public void test() { // JDynamicInvoke MethodSignature dmethodSig = dif.getMethodSignature( - "mylambda", JDynamicInvokeExpr.INVOKEDYNAMIC_DUMMY_CLASS_NAME, + "mylambda", "void", Collections.emptyList()); MethodSignature bootstrapMethodSig = - dif.getMethodSignature("run", "Runnable", "void", Collections.emptyList()); + dif.getMethodSignature("Runnable", "run", "void", Collections.emptyList()); List bootstrapArgs = Collections.emptyList(); List methodArgs = Collections.emptyList(); diff --git a/sootup.java.core/src/test/java/sootup/java/core/model/SootMethodTest.java b/sootup.java.core/src/test/java/sootup/java/core/model/SootMethodTest.java index 3d031009c1b..6efbcc3d058 100644 --- a/sootup.java.core/src/test/java/sootup/java/core/model/SootMethodTest.java +++ b/sootup.java.core/src/test/java/sootup/java/core/model/SootMethodTest.java @@ -50,7 +50,7 @@ public void testCreateMethod() { LocalGenerator generator = new LocalGenerator(new HashSet<>()); MethodSignature methodSignature = view.getIdentifierFactory() - .getMethodSignature("main", "dummyMain", "void", Collections.emptyList()); + .getMethodSignature("dummyMain", "main", "void", Collections.emptyList()); Body.BodyBuilder bodyBuilder = Body.builder(); final JIdentityStmt firstStmt = diff --git a/sootup.java.core/src/test/java/sootup/java/core/printer/JimplePrinterTest.java b/sootup.java.core/src/test/java/sootup/java/core/printer/JimplePrinterTest.java index 6938330d8eb..b2be615cb61 100644 --- a/sootup.java.core/src/test/java/sootup/java/core/printer/JimplePrinterTest.java +++ b/sootup.java.core/src/test/java/sootup/java/core/printer/JimplePrinterTest.java @@ -63,7 +63,7 @@ private SootClass buildClass() { String className = "some.package.SomeClass"; MethodSignature methodSignatureOne = view.getIdentifierFactory() - .getMethodSignature("main", className, "void", Collections.emptyList()); + .getMethodSignature(className, "main", "void", Collections.emptyList()); StmtPositionInfo noPosInfo = StmtPositionInfo.createNoStmtPositionInfo(); final JReturnVoidStmt returnVoidStmt = new JReturnVoidStmt(noPosInfo); @@ -87,7 +87,7 @@ private SootClass buildClass() { MethodSignature methodSignatureTwo = view.getIdentifierFactory() - .getMethodSignature("otherMethod", className, "int", Collections.emptyList()); + .getMethodSignature(className, "otherMethod", "int", Collections.emptyList()); bodyBuilder .setMethodSignature(methodSignatureTwo) .setPosition(NoPositionInformation.getInstance()); diff --git a/sootup.java.core/src/test/java/sootup/java/core/printer/LegacyJimplePrinterTest.java b/sootup.java.core/src/test/java/sootup/java/core/printer/LegacyJimplePrinterTest.java index d3c8c45bc76..d53c06192af 100644 --- a/sootup.java.core/src/test/java/sootup/java/core/printer/LegacyJimplePrinterTest.java +++ b/sootup.java.core/src/test/java/sootup/java/core/printer/LegacyJimplePrinterTest.java @@ -36,7 +36,7 @@ SootClass buildClass(Body.BodyBuilder builder) { MethodSignature methodSignature = view.getIdentifierFactory() - .getMethodSignature("main", "dummyMain", "void", Collections.emptyList()); + .getMethodSignature("dummyMain", "main", "void", Collections.emptyList()); Body body = builder .setMethodSignature(methodSignature) diff --git a/sootup.java.core/src/test/java/sootup/java/core/signatures/JavaIdentifierFactoryTest.java b/sootup.java.core/src/test/java/sootup/java/core/signatures/JavaIdentifierFactoryTest.java index a5fcf27b61d..c3cc1cf74d4 100644 --- a/sootup.java.core/src/test/java/sootup/java/core/signatures/JavaIdentifierFactoryTest.java +++ b/sootup.java.core/src/test/java/sootup/java/core/signatures/JavaIdentifierFactoryTest.java @@ -189,7 +189,7 @@ public void getMethodSignature() { List parameters = Collections.singletonList("java.lang.Class"); MethodSignature methodSignature = - identifierFactory.getMethodSignature("foo", "java.lang.System", "java.lang.A", parameters); + identifierFactory.getMethodSignature("java.lang.System", "foo", "java.lang.A", parameters); assertEquals(declClass, methodSignature.getDeclClassType()); assertEquals(returnType, methodSignature.getType()); assertEquals(parameter, methodSignature.getParameterTypes().get(0)); @@ -203,7 +203,7 @@ public void getMethodSignatureString() { List parameters = Collections.singletonList("java.lang.Class"); MethodSignature methodSignature = - identifierFactory.getMethodSignature("foo", "java.lang.System", "java.lang.A", parameters); + identifierFactory.getMethodSignature("java.lang.System", "foo", "java.lang.A", parameters); assertEquals( "", methodSignature.toString()); } @@ -215,7 +215,7 @@ public void getMethodSignatureString2() { List parameters = Collections.singletonList("java.lang.Class"); MethodSignature methodSignature = - identifierFactory.getMethodSignature("foo", "java.lang.System", "void", parameters); + identifierFactory.getMethodSignature("java.lang.System", "foo", "void", parameters); assertEquals("", methodSignature.toString()); } @@ -226,7 +226,7 @@ public void getMethodSignatureString3() { List parameters = Collections.emptyList(); MethodSignature methodSignature = - identifierFactory.getMethodSignature("foo", "java.lang.System", "void", parameters); + identifierFactory.getMethodSignature("java.lang.System", "foo", "void", parameters); assertEquals("", methodSignature.toString()); } @@ -258,10 +258,10 @@ public void compMethodSignature2() { List parameters = new ArrayList<>(); MethodSignature methodSignature = - identifierFactory.getMethodSignature("foo", "java.lang.System", "void", parameters); + identifierFactory.getMethodSignature("java.lang.System", "foo", "void", parameters); parameters.add("boolean"); MethodSignature methodSignature2 = - identifierFactory.getMethodSignature("foo", "java.lang.System", "void", parameters); + identifierFactory.getMethodSignature("java.lang.System", "foo", "void", parameters); assertNotEquals(methodSignature, methodSignature2); assertNotEquals(methodSignature.hashCode(), methodSignature2.hashCode()); @@ -274,9 +274,9 @@ public void compMethodSignature1() { List parameters = Collections.emptyList(); MethodSignature methodSignature = - identifierFactory.getMethodSignature("foo", "java.lang.System", "void", parameters); + identifierFactory.getMethodSignature("java.lang.System", "foo", "void", parameters); MethodSignature methodSignature2 = - identifierFactory.getMethodSignature("foo", "java.lang.System", "void", parameters); + identifierFactory.getMethodSignature("java.lang.System", "foo", "void", parameters); assertEquals(methodSignature, methodSignature2); assertEquals(methodSignature.hashCode(), methodSignature2.hashCode()); diff --git a/sootup.java.sourcecode/src/main/java/sootup/java/sourcecode/frontend/InstructionConverter.java b/sootup.java.sourcecode/src/main/java/sootup/java/sourcecode/frontend/InstructionConverter.java index 37606aac35d..737a7c92145 100644 --- a/sootup.java.sourcecode/src/main/java/sootup/java/sourcecode/frontend/InstructionConverter.java +++ b/sootup.java.sourcecode/src/main/java/sootup/java/sourcecode/frontend/InstructionConverter.java @@ -379,7 +379,7 @@ private List convertAssertInstruction( stmts.add(newAssignStmt); MethodSignature methodSig = identifierFactory.getMethodSignature( - "", "java.lang.AssertionError", "void", Collections.emptyList()); + "java.lang.AssertionError", "", "void", Collections.emptyList()); JSpecialInvokeExpr invoke = Jimple.newSpecialInvokeExpr(failureLocal, methodSig); JInvokeStmt invokeStmt = Jimple.newInvokeStmt( @@ -795,7 +795,7 @@ private Stmt convertInvokeInstruction(AstJavaInvokeInstruction invokeInst) { MethodSignature methodSig = identifierFactory.getMethodSignature( - target.getName().toString(), declaringClassSignature, returnType, parameters); + declaringClassSignature, target.getName().toString(), returnType, parameters); if (!callee.isStatic()) { int receiver = invokeInst.getReceiver(); @@ -940,8 +940,8 @@ private List convertStringAddition( MethodSignature initMethod = identifierFactory.getMethodSignature( - "", sbType.getFullyQualifiedName(), + "", VoidType.getInstance().toString(), Collections.singletonList(type.toString())); CAstSourcePositionMap.Position[] pos1 = new CAstSourcePositionMap.Position[2]; @@ -957,8 +957,8 @@ private List convertStringAddition( MethodSignature appendMethod = identifierFactory.getMethodSignature( - "append", sbType.getFullyQualifiedName(), + "append", sbType.toString(), Collections.singletonList(type.toString())); Local strBuilderLocal2 = localGenerator.generateLocal(sbType); @@ -976,7 +976,7 @@ private List convertStringAddition( MethodSignature toStringMethod = identifierFactory.getMethodSignature( - "toString", sbType.getFullyQualifiedName(), sbType.toString(), Collections.emptyList()); + sbType.getFullyQualifiedName(), "toString", sbType.toString(), Collections.emptyList()); Stmt toStringStmt = Jimple.newAssignStmt( diff --git a/sootup.tests/src/test/java/sootup/tests/MutableSootClientTest.java b/sootup.tests/src/test/java/sootup/tests/MutableSootClientTest.java index cccf19b9a7d..68198d20df5 100644 --- a/sootup.tests/src/test/java/sootup/tests/MutableSootClientTest.java +++ b/sootup.tests/src/test/java/sootup/tests/MutableSootClientTest.java @@ -129,7 +129,7 @@ public void methodRemovalTest() { public void methodAdditionTest() { MethodSignature methodSignature = p.getIdentifierFactory() - .getMethodSignature("addedMethod", "utils.Operations", "void", Collections.emptyList()); + .getMethodSignature("utils.Operations", "addedMethod", "void", Collections.emptyList()); Body.BodyBuilder bodyBuilder = Body.builder(); Body body = bodyBuilder.setMethodSignature(methodSignature).build(); JavaSootMethod newMethod = From 4af7a74d11eb9fd945b728bbb44f174f6668b1ee Mon Sep 17 00:00:00 2001 From: Bhargav Shirin Nalamati Date: Wed, 25 Oct 2023 21:51:22 +0530 Subject: [PATCH 90/90] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5d2b9119d87..051ff3107c3 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ See our [Todo list](https://github.com/soot-oss/SootUp/wiki/TODOs). ## Feel free to improve Soot! ### Feedback and Feature Requests -For feedbacks and feature requests, best create appropriate [issues](../../issues). +For feedback and feature requests, best create appropriate [issues](../../issues). ### Collaboration You want to collaborate? Please read our [coding guidelines and the contributors notice](../../wiki/contribution-to-SootUp).