Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/Sable/soot into fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcMil committed Oct 18, 2024
2 parents c0ba420 + 8cb447c commit 87ba387
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions src/main/java/soot/dexpler/DexBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -807,7 +808,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 Down Expand Up @@ -852,7 +853,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 @@ -872,11 +873,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 @@ -1103,12 +1104,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 @@ -1139,8 +1143,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 @@ -1165,10 +1169,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 @@ -1290,14 +1297,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 87ba387

Please sign in to comment.