Skip to content

Commit

Permalink
Fix the handling of certain floating point operations in dex
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcMil committed Jan 3, 2025
1 parent d81f939 commit c1876b0
Showing 1 changed file with 25 additions and 19 deletions.
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

0 comments on commit c1876b0

Please sign in to comment.