Skip to content

Commit

Permalink
fixed a regression
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenArzt committed Oct 18, 2024
1 parent 8a42f4f commit dc9ff54
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions src/main/java/soot/dexpler/DexBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ 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
// SharedInitializationLocalSplitter destroys the inserted casts, so we have to reintroduce them
MultiMap<Local, Type> maybetypeConstraints = new HashMultiMap<>();
handleKnownDexTypes(b, jimple);
handleKnownDexArrayTypes(b, jimple, maybetypeConstraints);
Expand All @@ -832,7 +832,7 @@ protected Collection<Type> reduceToAllowedTypesForLocal(Collection<Type> lcas, L
Set<Type> res = new HashSet<>(lcas);
res.retainAll(constraints);
if (res.isEmpty()) {
//No typing left
// No typing left
res.addAll(lcas);
res.addAll(constraints);
return res;
Expand All @@ -852,11 +852,11 @@ protected CastInsertionUseVisitor createCastInsertionUseVisitor(soot.jimple.tool
@Override
public Value visit(Value op, Type useType, Stmt stmt, boolean checkOnly) {
if (op instanceof LongConstant && useType instanceof DoubleType) {
//no cast necessary for Dex
// no cast necessary for Dex
return op;
}
if (op instanceof IntConstant && useType instanceof FloatType) {
//no cast necessary for Dex
// no cast necessary for Dex
return op;
}
return super.visit(op, useType, stmt, checkOnly);
Expand Down Expand Up @@ -1083,12 +1083,15 @@ public Value visit(Value op, Type useType, Stmt stmt, boolean checkOnly) {
}

/**
* For non-object array instructions, we know from the bytecode already what the types are, or at least
* we can reduce it to two possibilities (int/float or float/double).
* For non-object array instructions, we know from the bytecode already what the types are, or at least we can reduce it to
* two possibilities (int/float or float/double).
*
* @param b the body
* @param jimple the jimple instance to use (caching is slightly faster)
* @param typeConstraints type constraints (these might be multiple valid possibilities)
* @param b
* the body
* @param jimple
* the jimple instance to use (caching is slightly faster)
* @param typeConstraints
* type constraints (these might be multiple valid possibilities)
*/
private void handleKnownDexArrayTypes(Body b, Jimple jimple, MultiMap<Local, Type> typeConstraints) {

Expand Down Expand Up @@ -1119,8 +1122,8 @@ private void handleKnownDexArrayTypes(Body b, Jimple jimple, MultiMap<Local, Typ
typeConstraints.put(l, tp);

} else if (tg instanceof IntOrFloatOpTag || tg instanceof LongOrDoubleOpTag) {
//sadly, we don't know for sure. But: we know that it's either of these two.
//we need a fresh local or each instance, no re-use allowed.
// sadly, we don't know for sure. But: we know that it's either of these two.
// we need a fresh local or each instance, no re-use allowed.
Local l = jimple.newLocal(freshLocalName("lcl" + tg.getName()), UnknownType.v());
b.getLocals().add(l);
ArrayRef array = (ArrayRef) rop;
Expand All @@ -1145,10 +1148,13 @@ private void handleKnownDexArrayTypes(Body b, Jimple jimple, MultiMap<Local, Typ
}

/**
* For several instructions, we know from the bytecode already what the types are.
* We use that knowledge here to help the type assigner.
* @param b the body
* @param jimple the jimple instance to use (caching is slightly faster)
* For several instructions, we know from the bytecode already what the types are. We use that knowledge here to help the
* type assigner.
*
* @param b
* the body
* @param jimple
* the jimple instance to use (caching is slightly faster)
*/
private void handleKnownDexTypes(Body b, final Jimple jimple) {
UnitPatchingChain units = jBody.getUnits();
Expand Down Expand Up @@ -1270,14 +1276,16 @@ private Local createOrGetVariableOfType(Body b, Map<Type, Local> map, Type t) {

/**
* Removes all dexpler specific tags. Saves some memory.
* @param unit the statement
*
* @param unit
* the statement
*/
private void removeDexplerTags(Unit unit) {
for (Tag t : unit.getTags()) {
for (Iterator<Tag> it = unit.getTags().iterator(); it.hasNext();) {
Tag t = it.next();
if (t instanceof DexplerTag) {
unit.removeTag(t.getName());
it.remove();
}

}
}

Expand Down

0 comments on commit dc9ff54

Please sign in to comment.