Skip to content

Commit 6238e13

Browse files
committed
Bugfix: Soot inlined overwritten array values. Also added an additional
sanity check
1 parent a8217b9 commit 6238e13

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/soot/dexpler/DexArrayInitReducer.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ protected void internalTransform(Body b, String phaseName,
6565
// preceding constant assignments
6666
AssignStmt assignStmt = (AssignStmt) u;
6767
if (assignStmt.getLeftOp() instanceof ArrayRef) {
68-
if (u1 != null && u2 != null) {
68+
if (u1 != null && u2 != null && u2.getBoxesPointingToThis().isEmpty()
69+
&& assignStmt.getBoxesPointingToThis().isEmpty()) {
6970
ArrayRef arrayRef = (ArrayRef) assignStmt.getLeftOp();
7071

7172
Value u1val = u1.getDefBoxes().get(0).getValue();
@@ -157,6 +158,15 @@ else if (vb.getValue() == u2val)
157158
}
158159
else if (u2 == null) {
159160
u2 = assignStmt;
161+
162+
// If the last value is overwritten again, we start again at the beginning
163+
if (u1 != null) {
164+
Value op1 = ((AssignStmt) u1).getLeftOp();
165+
if (op1 == ((AssignStmt) u2).getLeftOp()) {
166+
u1 = u2;
167+
u2 = null;
168+
}
169+
}
160170
}
161171
else {
162172
u1 = u2;

src/soot/toDex/ExprVisitor.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import soot.LongType;
1818
import soot.NullType;
1919
import soot.PrimType;
20+
import soot.RefType;
2021
import soot.SootClass;
2122
import soot.Type;
2223
import soot.Value;
@@ -591,7 +592,10 @@ private void castPrimitive(Register sourceReg, Value source, Type castSootType)
591592
source = IntConstant.v(0);
592593

593594
// select fitting conversion opcode, depending on the source and cast type
594-
PrimitiveType sourceType = PrimitiveType.getByName(source.getType().toString());
595+
Type srcType = source.getType();
596+
if (srcType instanceof RefType)
597+
throw new RuntimeException("Trying to cast reference type " + srcType + " to a primitive");
598+
PrimitiveType sourceType = PrimitiveType.getByName(srcType.toString());
595599
if (castType == PrimitiveType.BOOLEAN) {
596600
// there is no "-to-boolean" opcode, so just pretend to move an int to an int
597601
castType = PrimitiveType.INT;

0 commit comments

Comments
 (0)