Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure that we do not have branch statements within array initializers #2136

Merged
merged 2 commits into from
Jan 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/main/java/soot/toDex/DexArrayInitDetector.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@
import soot.Value;
import soot.jimple.ArrayRef;
import soot.jimple.AssignStmt;
import soot.jimple.BranchableStmt;
import soot.jimple.Constant;
import soot.jimple.DoubleConstant;
import soot.jimple.FloatConstant;
import soot.jimple.IntConstant;
import soot.jimple.LongConstant;
import soot.jimple.NewArrayExpr;
import soot.jimple.Stmt;

/**
* Detector class that identifies array initializations and packs them into a single instruction:
Expand Down Expand Up @@ -76,6 +78,12 @@ public void constructArrayInitializations(Body body) {
Set<Unit> curIgnoreUnits = null;
int arraySize = 0;
Value concernedArray = null;
Set<Stmt> directGotoTargets = new HashSet<>();
for (Unit u : body.getUnits()) {
if (u instanceof BranchableStmt) {
directGotoTargets.add((Stmt) ((BranchableStmt) u).getTarget());
}
}
for (Unit u : body.getUnits()) {
if (!(u instanceof AssignStmt)) {
arrayValues = null;
Expand Down Expand Up @@ -105,7 +113,7 @@ public void constructArrayInitializations(Body body) {
if (rop instanceof IntConstant || rop instanceof LongConstant || rop instanceof FloatConstant
|| rop instanceof DoubleConstant) {
ArrayRef aref = (ArrayRef) assignStmt.getLeftOp();
if (aref.getBase() != concernedArray) {
if (aref.getBase() != concernedArray || directGotoTargets.contains(assignStmt)) {
arrayValues = null;
continue;
}
Expand Down
Loading