Skip to content

Commit

Permalink
Merge pull request #2131 from MarcMil/fixdex
Browse files Browse the repository at this point in the history
Fix bugs in dexpler and toDex
  • Loading branch information
StevenArzt authored Nov 29, 2024
2 parents 4d6fcfa + a55a62b commit 1388b67
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
23 changes: 21 additions & 2 deletions src/main/java/soot/dexpler/DexBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,16 @@ private static BooleanConstant fixBooleanConstant(IntConstant arg) {
* type constraints (these might be multiple valid possibilities)
*/
private void handleKnownDexArrayTypes(Body b, Jimple jimple, MultiMap<Local, Type> typeConstraints) {

Map<Local, Integer> localsSingleDefinitions = new HashMap<>();
for (Unit u : b.getUnits()) {
if (u instanceof DefinitionStmt) {
Value l = ((DefinitionStmt) u).getLeftOp();
if (l instanceof Local) {
int counter = localsSingleDefinitions.getOrDefault(l, 0);
localsSingleDefinitions.put((Local) l, counter + 1);
}
}
}
UnitPatchingChain units = jBody.getUnits();
Unit u = units.getFirst();
while (u != null) {
Expand All @@ -1321,7 +1330,17 @@ private void handleKnownDexArrayTypes(Body b, Jimple jimple, MultiMap<Local, Typ
Type definiteType = dexplerTypeTag.getDefiniteType();
if (definiteType != null) {
Local prev = (Local) assign.getLeftOp();
prev.setType(definiteType);
if (!(definiteType instanceof PrimType) || localsSingleDefinitions.getOrDefault(prev, 0) == 1) {
prev.setType(definiteType);
} else {
//Since there are multiple definitions, e.g. for a byte retrieved from a byte[],
//there could be another non-distinct definition which uses the same variable as an int.
PrimType[] wider = DexType.getWiderTypes((PrimType) definiteType);
if (wider.length == 1) {
prev.setType(wider[0]);
}
}

ArrayType tp = ArrayType.v(definiteType, 1);

ArrayRef array = (ArrayRef) rop;
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/soot/dexpler/DexType.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import soot.FloatType;
import soot.IntType;
import soot.LongType;
import soot.PrimType;
import soot.RefType;
import soot.ShortType;
import soot.Type;
Expand Down Expand Up @@ -226,4 +227,14 @@ public static String toSootAT(String type) {
public String toString() {
return name;
}

public static PrimType[] getWiderTypes(PrimType tp) {
if (tp instanceof ByteType) {
return new PrimType[] { tp, IntType.v(), ShortType.v() };
}
if (tp instanceof ShortType) {
return new PrimType[] { tp, IntType.v() };
}
return new PrimType[] { tp };
}
}
2 changes: 1 addition & 1 deletion src/main/java/soot/toDex/ExprVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ private boolean isCallToConstructor(SpecialInvokeExpr sie) {
}

private boolean isCallToSuper(SpecialInvokeExpr sie) {
SootClass classWithInvokation = sie.getMethod().getDeclaringClass();
SootClass classWithInvokation = sie.getMethodRef().getDeclaringClass();
SootClass currentClass = stmtV.getBelongingClass();

while (currentClass != null) {
Expand Down

0 comments on commit 1388b67

Please sign in to comment.