From c1876b062ba9e07ca6bb1bf995ec4da3fc10d2cd Mon Sep 17 00:00:00 2001 From: Marc Miltenberger Date: Fri, 3 Jan 2025 20:18:07 +0100 Subject: [PATCH] Fix the handling of certain floating point operations in dex --- src/main/java/soot/dexpler/DexBody.java | 44 ++++++++++++++----------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/main/java/soot/dexpler/DexBody.java b/src/main/java/soot/dexpler/DexBody.java index e7aa9a8c347..4ba92ca8ea8 100755 --- a/src/main/java/soot/dexpler/DexBody.java +++ b/src/main/java/soot/dexpler/DexBody.java @@ -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); @@ -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))); + } + } + } } } @@ -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) {