Skip to content

Commit

Permalink
Fix a bug where the types in Dalvik code are not accurate for floats …
Browse files Browse the repository at this point in the history
…in certain conditions
  • Loading branch information
MarcMil committed Oct 10, 2024
1 parent e730d90 commit 09ffeb9
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/main/java/soot/dexpler/DexBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,15 @@
import soot.dexpler.tags.DoubleOpTag;
import soot.dexpler.tags.FloatOpTag;
import soot.dexpler.typing.DalvikTyper;
import soot.jimple.AddExpr;
import soot.jimple.AssignStmt;
import soot.jimple.BinopExpr;
import soot.jimple.CastExpr;
import soot.jimple.CaughtExceptionRef;
import soot.jimple.ConditionExpr;
import soot.jimple.Constant;
import soot.jimple.DefinitionStmt;
import soot.jimple.DivExpr;
import soot.jimple.DoubleConstant;
import soot.jimple.EqExpr;
import soot.jimple.FloatConstant;
Expand All @@ -109,9 +111,12 @@
import soot.jimple.Jimple;
import soot.jimple.JimpleBody;
import soot.jimple.LongConstant;
import soot.jimple.MulExpr;
import soot.jimple.NeExpr;
import soot.jimple.NullConstant;
import soot.jimple.NumericConstant;
import soot.jimple.RemExpr;
import soot.jimple.SubExpr;
import soot.jimple.internal.JIdentityStmt;
import soot.jimple.toolkits.base.Aggregator;
import soot.jimple.toolkits.scalar.ConditionalBranchFolder;
Expand Down Expand Up @@ -784,6 +789,8 @@ public Body jimplify(Body b, SootMethod m) {
UnconditionalBranchFolder.v().transform(jBody);
}
DexFillArrayDataTransformer.v().transform(jBody);
//SharedInitializationLocalSplitter destroys the inserted casts, so we have to reintroduce them
convertFloatsAndDoubles(b, jimple);

TypeAssigner.v().transform(jBody);

Expand Down Expand Up @@ -1005,15 +1012,37 @@ public Body jimplify(Body b, SootMethod m) {
public void convertFloatsAndDoubles(Body b, final Jimple jimple) {
UnitPatchingChain units = jBody.getUnits();
Unit u = units.getFirst();
Local convResultFloat = null;
Local convResultDouble = null;
Local[] convFloat = new Local[2], convDouble = new Local[2];

while (u != null) {
if (u instanceof AssignStmt) {
AssignStmt def = (AssignStmt) u;
Value rop = def.getRightOp();
if (rop instanceof BinopExpr) {
boolean isDouble = u.hasTag(DoubleOpTag.NAME);
boolean isFloat = u.hasTag(FloatOpTag.NAME);
if (rop instanceof AddExpr || rop instanceof SubExpr || rop instanceof MulExpr || rop instanceof DivExpr
|| rop instanceof RemExpr) {
if (isDouble) {
if (convResultDouble == null) {
convResultDouble = jimple.newLocal("lclConvToDouble", DoubleType.v());
b.getLocals().add(convResultDouble);
}
Value prev = def.getLeftOp();
def.setLeftOp(convResultDouble);
units.insertAfter(jimple.newAssignStmt(prev, jimple.newCastExpr(convResultDouble, DoubleType.v())), u);
}
if (isFloat) {
if (convResultFloat == null) {
convResultFloat = jimple.newLocal("lclConvToFloat", FloatType.v());
b.getLocals().add(convResultFloat);
}
Value prev = def.getLeftOp();
def.setLeftOp(convResultFloat);
units.insertAfter(jimple.newAssignStmt(prev, jimple.newCastExpr(convResultFloat, FloatType.v())), u);
}
}
BinopExpr bop = (BinopExpr) rop;
int idxConvVar = 0;
for (ValueBox cmp : bop.getUseBoxes()) {
Expand Down

0 comments on commit 09ffeb9

Please sign in to comment.