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

Fix the handling of certain floating point operations in dex #2135

Merged
merged 1 commit into from
Jan 4, 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
44 changes: 25 additions & 19 deletions src/main/java/soot/dexpler/DexBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -1410,8 +1410,7 @@ private void handleKnownDexTypes(Body b, final Jimple jimple) {
l.setType(t);
}

}
if (rop instanceof BinopExpr) {
} else if (rop instanceof BinopExpr) {
boolean isDouble = u.hasTag(DoubleOpTag.NAME);
boolean isFloat = u.hasTag(FloatOpTag.NAME);
boolean isInt = u.hasTag(IntOpTag.NAME);
Expand Down Expand Up @@ -1459,6 +1458,30 @@ private void handleKnownDexTypes(Body b, final Jimple jimple) {
}
}
}
} else if (rop instanceof CastExpr) {
CastExpr ce = (CastExpr) rop;
Value op = ce.getOp();
if (op instanceof Constant) {
boolean isDouble = u.hasTag(DoubleOpTag.NAME);
boolean isFloat = u.hasTag(FloatOpTag.NAME);
if (isFloat) {
if (op instanceof IntConstant) {
int vVal = ((IntConstant) op).value;
ce.setOp(FloatConstant.v(Float.intBitsToFloat(vVal)));
} else if (op instanceof LongConstant) {
long vVal = ((LongConstant) op).value;
ce.setOp(FloatConstant.v(Float.intBitsToFloat((int) vVal)));
}
} else if (isDouble) {
if (op instanceof LongConstant) {
long vVal = ((LongConstant) op).value;
ce.setOp(DoubleConstant.v(Double.longBitsToDouble(vVal)));
} else if (op instanceof IntConstant) {
int vVal = ((IntConstant) op).value;
ce.setOp(DoubleConstant.v(Double.longBitsToDouble(vVal)));
}
}
}
}

}
Expand Down Expand Up @@ -1487,23 +1510,6 @@ private void handleKnownDexTypes(Body b, final Jimple jimple) {
AssignStmt assign = (AssignStmt) u1;
Type tl = assign.getLeftOp().getType();
Value rop = assign.getRightOp();
if (rop instanceof CastExpr) {
CastExpr ce = (CastExpr) rop;
if (ce.getCastType() instanceof DoubleType) {
if (ce.getOp() instanceof LongConstant) {
LongConstant lc = (LongConstant) ce.getOp();
long vVal = lc.value;
assign.setRightOp(DoubleConstant.v(Double.longBitsToDouble(vVal)));
}
}
if (ce.getCastType() instanceof FloatType) {
if (ce.getOp() instanceof IntConstant) {
IntConstant ic = (IntConstant) ce.getOp();
int vVal = ic.value;
assign.setRightOp(FloatConstant.v(Float.intBitsToFloat(vVal)));
}
}
}
if (rop instanceof Constant) {
Constant c = (Constant) assign.getRightOp();
if (tl instanceof DoubleType && c instanceof LongConstant) {
Expand Down
Loading