From 4a5b415228cadeb64c1e53f5ccfb426f5376d545 Mon Sep 17 00:00:00 2001 From: Marc Miltenberger Date: Sat, 4 Dec 2021 11:17:54 +0100 Subject: [PATCH 1/4] Convenience methods to get more information of primitive types --- src/main/java/soot/BooleanType.java | 10 ++++++++++ src/main/java/soot/ByteType.java | 10 ++++++++++ src/main/java/soot/CharType.java | 10 ++++++++++ src/main/java/soot/DoubleType.java | 10 ++++++++++ src/main/java/soot/FloatType.java | 10 ++++++++++ src/main/java/soot/IntType.java | 11 +++++++++++ src/main/java/soot/LongType.java | 11 +++++++++++ src/main/java/soot/PrimType.java | 4 ++++ src/main/java/soot/Scene.java | 2 ++ src/main/java/soot/ShortType.java | 11 +++++++++++ src/main/java/soot/SootMethodRefImpl.java | 1 - .../jimple/toolkits/typing/fast/Integer127Type.java | 10 ++++++++++ .../jimple/toolkits/typing/fast/Integer1Type.java | 10 ++++++++++ .../jimple/toolkits/typing/fast/Integer32767Type.java | 10 ++++++++++ 14 files changed, 119 insertions(+), 1 deletion(-) diff --git a/src/main/java/soot/BooleanType.java b/src/main/java/soot/BooleanType.java index e46d7b38568..2016d80ea73 100644 --- a/src/main/java/soot/BooleanType.java +++ b/src/main/java/soot/BooleanType.java @@ -61,4 +61,14 @@ public void apply(Switch sw) { public RefType boxedType() { return RefType.v("java.lang.Boolean"); } + + @Override + public Class getJavaBoxedType() { + return Boolean.class; + } + + @Override + public Class getJavaPrimitiveType() { + return boolean.class; + } } diff --git a/src/main/java/soot/ByteType.java b/src/main/java/soot/ByteType.java index faafb721f03..f98b6251649 100644 --- a/src/main/java/soot/ByteType.java +++ b/src/main/java/soot/ByteType.java @@ -61,4 +61,14 @@ public void apply(Switch sw) { public RefType boxedType() { return RefType.v("java.lang.Byte"); } + + @Override + public Class getJavaBoxedType() { + return Byte.class; + } + + @Override + public Class getJavaPrimitiveType() { + return byte.class; + } } diff --git a/src/main/java/soot/CharType.java b/src/main/java/soot/CharType.java index 9d8ae1d0b68..38e50a83f69 100644 --- a/src/main/java/soot/CharType.java +++ b/src/main/java/soot/CharType.java @@ -61,4 +61,14 @@ public void apply(Switch sw) { public RefType boxedType() { return RefType.v("java.lang.Character"); } + + @Override + public Class getJavaBoxedType() { + return Character.class; + } + + @Override + public Class getJavaPrimitiveType() { + return char.class; + } } diff --git a/src/main/java/soot/DoubleType.java b/src/main/java/soot/DoubleType.java index 80b8144cdc3..18bde97270a 100644 --- a/src/main/java/soot/DoubleType.java +++ b/src/main/java/soot/DoubleType.java @@ -61,4 +61,14 @@ public void apply(Switch sw) { public RefType boxedType() { return RefType.v("java.lang.Double"); } + + @Override + public Class getJavaBoxedType() { + return Double.class; + } + + @Override + public Class getJavaPrimitiveType() { + return double.class; + } } diff --git a/src/main/java/soot/FloatType.java b/src/main/java/soot/FloatType.java index 14a859b6095..177a0c3f105 100644 --- a/src/main/java/soot/FloatType.java +++ b/src/main/java/soot/FloatType.java @@ -61,4 +61,14 @@ public void apply(Switch sw) { public RefType boxedType() { return RefType.v("java.lang.Float"); } + + @Override + public Class getJavaBoxedType() { + return Float.class; + } + + @Override + public Class getJavaPrimitiveType() { + return float.class; + } } diff --git a/src/main/java/soot/IntType.java b/src/main/java/soot/IntType.java index 7f90bcf3bdc..e0dbd92f1f7 100644 --- a/src/main/java/soot/IntType.java +++ b/src/main/java/soot/IntType.java @@ -61,4 +61,15 @@ public void apply(Switch sw) { public RefType boxedType() { return RefType.v("java.lang.Integer"); } + + @Override + public Class getJavaBoxedType() { + return Integer.class; + } + + @Override + public Class getJavaPrimitiveType() { + return int.class; + } + } diff --git a/src/main/java/soot/LongType.java b/src/main/java/soot/LongType.java index c5d0d106feb..bb4ef3511d8 100644 --- a/src/main/java/soot/LongType.java +++ b/src/main/java/soot/LongType.java @@ -61,4 +61,15 @@ public void apply(Switch sw) { public RefType boxedType() { return RefType.v("java.lang.Long"); } + + @Override + public Class getJavaBoxedType() { + return Long.class; + } + + @Override + public Class getJavaPrimitiveType() { + return long.class; + } + } diff --git a/src/main/java/soot/PrimType.java b/src/main/java/soot/PrimType.java index 16ef949e97d..75fa8f9129f 100644 --- a/src/main/java/soot/PrimType.java +++ b/src/main/java/soot/PrimType.java @@ -33,6 +33,10 @@ public abstract class PrimType extends Type { public abstract RefType boxedType(); + public abstract Class getJavaBoxedType(); + + public abstract Class getJavaPrimitiveType(); + @Override public boolean isAllowedInFinalCode() { return true; diff --git a/src/main/java/soot/Scene.java b/src/main/java/soot/Scene.java index fab1ed3b725..fe4b647f5db 100755 --- a/src/main/java/soot/Scene.java +++ b/src/main/java/soot/Scene.java @@ -143,6 +143,8 @@ public class Scene { private AndroidVersionInfo androidSDKVersionInfo; private int androidAPIVersion = -1; + private int released; + public Scene(Singletons.Global g) { setReservedNames(); diff --git a/src/main/java/soot/ShortType.java b/src/main/java/soot/ShortType.java index fd1b8d1f33a..83cbd32865a 100644 --- a/src/main/java/soot/ShortType.java +++ b/src/main/java/soot/ShortType.java @@ -61,4 +61,15 @@ public void apply(Switch sw) { public RefType boxedType() { return RefType.v("java.lang.Short"); } + + @Override + public Class getJavaBoxedType() { + return Short.class; + } + + @Override + public Class getJavaPrimitiveType() { + return short.class; + } + } diff --git a/src/main/java/soot/SootMethodRefImpl.java b/src/main/java/soot/SootMethodRefImpl.java index debca777213..0468f1e8671 100644 --- a/src/main/java/soot/SootMethodRefImpl.java +++ b/src/main/java/soot/SootMethodRefImpl.java @@ -29,7 +29,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import soot.javaToJimple.DefaultLocalGenerator; import soot.jimple.AssignStmt; import soot.jimple.InvokeStmt; import soot.jimple.Jimple; diff --git a/src/main/java/soot/jimple/toolkits/typing/fast/Integer127Type.java b/src/main/java/soot/jimple/toolkits/typing/fast/Integer127Type.java index 9337bdaebbc..cbde418c8d4 100644 --- a/src/main/java/soot/jimple/toolkits/typing/fast/Integer127Type.java +++ b/src/main/java/soot/jimple/toolkits/typing/fast/Integer127Type.java @@ -70,4 +70,14 @@ public Type getDefaultFinalType() { return ByteType.v(); } + @Override + public Class getJavaBoxedType() { + return Integer.class; + } + + @Override + public Class getJavaPrimitiveType() { + return int.class; + } + } diff --git a/src/main/java/soot/jimple/toolkits/typing/fast/Integer1Type.java b/src/main/java/soot/jimple/toolkits/typing/fast/Integer1Type.java index f88cb3a3ef1..22acccff998 100644 --- a/src/main/java/soot/jimple/toolkits/typing/fast/Integer1Type.java +++ b/src/main/java/soot/jimple/toolkits/typing/fast/Integer1Type.java @@ -70,4 +70,14 @@ public Type getDefaultFinalType() { return BooleanType.v(); } + @Override + public Class getJavaBoxedType() { + return Integer.class; + } + + @Override + public Class getJavaPrimitiveType() { + return int.class; + } + } diff --git a/src/main/java/soot/jimple/toolkits/typing/fast/Integer32767Type.java b/src/main/java/soot/jimple/toolkits/typing/fast/Integer32767Type.java index a311e15b378..a3e541ae1b2 100644 --- a/src/main/java/soot/jimple/toolkits/typing/fast/Integer32767Type.java +++ b/src/main/java/soot/jimple/toolkits/typing/fast/Integer32767Type.java @@ -69,4 +69,14 @@ public Type getDefaultFinalType() { return ShortType.v(); } + @Override + public Class getJavaBoxedType() { + return Integer.class; + } + + @Override + public Class getJavaPrimitiveType() { + return int.class; + } + } From c9685d1f29986000ebb8d6e25cc14843f8d6678f Mon Sep 17 00:00:00 2001 From: Marc Miltenberger Date: Sat, 4 Dec 2021 11:43:43 +0100 Subject: [PATCH 2/4] Move Hashcode to a constant --- src/main/java/soot/BooleanType.java | 4 +++- src/main/java/soot/ByteType.java | 4 +++- src/main/java/soot/CharType.java | 4 +++- src/main/java/soot/DoubleType.java | 4 +++- src/main/java/soot/FloatType.java | 4 +++- src/main/java/soot/IntType.java | 4 +++- src/main/java/soot/LongType.java | 4 +++- src/main/java/soot/ShortType.java | 4 +++- 8 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/main/java/soot/BooleanType.java b/src/main/java/soot/BooleanType.java index 2016d80ea73..ce72c7d82f3 100644 --- a/src/main/java/soot/BooleanType.java +++ b/src/main/java/soot/BooleanType.java @@ -30,6 +30,8 @@ @SuppressWarnings("serial") public class BooleanType extends PrimType implements IntegerType { + public static final int HASHCODE = 0x1C4585DA; + public BooleanType(Singletons.Global g) { } @@ -44,7 +46,7 @@ public boolean equals(Object t) { @Override public int hashCode() { - return 0x1C4585DA; + return HASHCODE; } @Override diff --git a/src/main/java/soot/ByteType.java b/src/main/java/soot/ByteType.java index f98b6251649..99057e037d8 100644 --- a/src/main/java/soot/ByteType.java +++ b/src/main/java/soot/ByteType.java @@ -30,6 +30,8 @@ @SuppressWarnings("serial") public class ByteType extends PrimType implements IntegerType { + public static final int HASHCODE = 0x813D1329; + public ByteType(Singletons.Global g) { } @@ -39,7 +41,7 @@ public static ByteType v() { @Override public int hashCode() { - return 0x813D1329; + return HASHCODE; } @Override diff --git a/src/main/java/soot/CharType.java b/src/main/java/soot/CharType.java index 38e50a83f69..246cab4b85a 100644 --- a/src/main/java/soot/CharType.java +++ b/src/main/java/soot/CharType.java @@ -30,6 +30,8 @@ @SuppressWarnings("serial") public class CharType extends PrimType implements IntegerType { + public static final int HASHCODE = 0x739EA474; + public CharType(Singletons.Global g) { } @@ -49,7 +51,7 @@ public String toString() { @Override public int hashCode() { - return 0x739EA474; + return HASHCODE; } @Override diff --git a/src/main/java/soot/DoubleType.java b/src/main/java/soot/DoubleType.java index 18bde97270a..02a0e82a633 100644 --- a/src/main/java/soot/DoubleType.java +++ b/src/main/java/soot/DoubleType.java @@ -30,6 +30,8 @@ @SuppressWarnings("serial") public class DoubleType extends PrimType { + public static final int HASHCODE = 0x4B9D7242; + public DoubleType(Singletons.Global g) { } @@ -44,7 +46,7 @@ public boolean equals(Object t) { @Override public int hashCode() { - return 0x4B9D7242; + return HASHCODE; } @Override diff --git a/src/main/java/soot/FloatType.java b/src/main/java/soot/FloatType.java index 177a0c3f105..5e145660376 100644 --- a/src/main/java/soot/FloatType.java +++ b/src/main/java/soot/FloatType.java @@ -30,6 +30,8 @@ @SuppressWarnings("serial") public class FloatType extends PrimType { + public static final int HASHCODE = 0xA84373FA; + public FloatType(Singletons.Global g) { } @@ -44,7 +46,7 @@ public boolean equals(Object t) { @Override public int hashCode() { - return 0xA84373FA; + return HASHCODE; } @Override diff --git a/src/main/java/soot/IntType.java b/src/main/java/soot/IntType.java index e0dbd92f1f7..8c389a1b170 100644 --- a/src/main/java/soot/IntType.java +++ b/src/main/java/soot/IntType.java @@ -30,6 +30,8 @@ @SuppressWarnings("serial") public class IntType extends PrimType implements IntegerType { + public static final int HASHCODE = 0xB747239F; + public IntType(Singletons.Global g) { } @@ -44,7 +46,7 @@ public boolean equals(Object t) { @Override public int hashCode() { - return 0xB747239F; + return HASHCODE; } @Override diff --git a/src/main/java/soot/LongType.java b/src/main/java/soot/LongType.java index bb4ef3511d8..488ac049199 100644 --- a/src/main/java/soot/LongType.java +++ b/src/main/java/soot/LongType.java @@ -30,6 +30,8 @@ @SuppressWarnings("serial") public class LongType extends PrimType { + public static final int HASHCODE = 0x023DA077; + public LongType(Singletons.Global g) { } @@ -44,7 +46,7 @@ public boolean equals(Object t) { @Override public int hashCode() { - return 0x023DA077; + return HASHCODE; } @Override diff --git a/src/main/java/soot/ShortType.java b/src/main/java/soot/ShortType.java index 83cbd32865a..159e94143ef 100644 --- a/src/main/java/soot/ShortType.java +++ b/src/main/java/soot/ShortType.java @@ -30,6 +30,8 @@ @SuppressWarnings("serial") public class ShortType extends PrimType implements IntegerType { + public static final int HASHCODE = 0x8B817DD3; + public ShortType(Singletons.Global g) { } @@ -39,7 +41,7 @@ public static ShortType v() { @Override public int hashCode() { - return 0x8B817DD3; + return HASHCODE; } @Override From 9dd26021e209525fd224b8f8bc56255b40c9eba4 Mon Sep 17 00:00:00 2001 From: Marc Miltenberger Date: Mon, 6 Dec 2021 09:27:57 +0100 Subject: [PATCH 3/4] Remove debug field --- src/main/java/soot/Scene.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/soot/Scene.java b/src/main/java/soot/Scene.java index fe4b647f5db..fab1ed3b725 100755 --- a/src/main/java/soot/Scene.java +++ b/src/main/java/soot/Scene.java @@ -143,8 +143,6 @@ public class Scene { private AndroidVersionInfo androidSDKVersionInfo; private int androidAPIVersion = -1; - private int released; - public Scene(Singletons.Global g) { setReservedNames(); From 502e09ba58a55cb08359e65e2e0d19b1609a2318 Mon Sep 17 00:00:00 2001 From: Marc Miltenberger Date: Wed, 8 Dec 2021 11:11:22 +0100 Subject: [PATCH 4/4] Fix potentially never-ending loop --- .../java/soot/jimple/toolkits/typing/fast/UseChecker.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/soot/jimple/toolkits/typing/fast/UseChecker.java b/src/main/java/soot/jimple/toolkits/typing/fast/UseChecker.java index c5a25aec3ea..f960c9ab38e 100644 --- a/src/main/java/soot/jimple/toolkits/typing/fast/UseChecker.java +++ b/src/main/java/soot/jimple/toolkits/typing/fast/UseChecker.java @@ -27,8 +27,10 @@ import heros.solver.Pair; import java.util.ArrayDeque; +import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -294,9 +296,14 @@ public void caseAssignStmt(AssignStmt stmt) { // First, we check the definitions. If we can see the definitions and know the array type // that way, we are safe. ArrayDeque> worklist = new ArrayDeque>(); + Set> seen = new HashSet<>(); worklist.add(new Pair<>(stmt, (Local) ((ArrayRef) rhs).getBase())); while (!worklist.isEmpty()) { Pair r = worklist.removeFirst(); + if (!seen.add(r)) { + // Make sure we only process each entry once + continue; + } List d = defs.getDefsOfAt(r.getO2(), r.getO1()); if (d.isEmpty()) {