Skip to content

Commit

Permalink
fix: change type update collection to produce deterministic results
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Feb 27, 2019
1 parent 0df5aa8 commit 68d074a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import jadx.core.dex.instructions.args.PrimitiveType;
import jadx.core.dex.instructions.args.RegisterArg;
import jadx.core.dex.instructions.args.SSAVar;
import jadx.core.dex.instructions.args.Typed;
import jadx.core.dex.nodes.InsnNode;
import jadx.core.dex.nodes.RootNode;
import jadx.core.utils.exceptions.JadxOverflowException;
Expand Down Expand Up @@ -57,11 +56,11 @@ public TypeUpdateResult apply(SSAVar ssaVar, ArgType candidateType) {
if (result == REJECT) {
return result;
}
Map<InsnArg, ArgType> updates = updateInfo.getUpdates();
List<TypeUpdateEntry> updates = updateInfo.getUpdates();
if (updates.isEmpty()) {
return SAME;
}
updates.forEach(Typed::setType);
updates.forEach(TypeUpdateEntry::apply);
return CHANGED;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package jadx.core.dex.visitors.typeinference;

import jadx.core.dex.instructions.args.ArgType;
import jadx.core.dex.instructions.args.InsnArg;

public final class TypeUpdateEntry {
private final InsnArg arg;
private final ArgType type;

public TypeUpdateEntry(InsnArg arg, ArgType type) {
this.arg = arg;
this.type = type;
}

public void apply() {
arg.setType(type);
}

public InsnArg getArg() {
return arg;
}

public ArgType getType() {
return type;
}

@Override
public String toString() {
return "TypeUpdateEntry{" + arg + " -> " + type + '}';
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
package jadx.core.dex.visitors.typeinference;

import java.util.IdentityHashMap;
import java.util.Map;
import java.util.ArrayList;
import java.util.List;

import jadx.core.dex.instructions.args.ArgType;
import jadx.core.dex.instructions.args.InsnArg;

public class TypeUpdateInfo {

private final Map<InsnArg, ArgType> updates = new IdentityHashMap<>();
private final List<TypeUpdateEntry> updates = new ArrayList<>();

public void requestUpdate(InsnArg arg, ArgType changeType) {
updates.put(arg, changeType);
updates.add(new TypeUpdateEntry(arg, changeType));
}

public boolean isProcessed(InsnArg arg) {
return updates.containsKey(arg);
if (updates.isEmpty()) {
return false;
}
for (TypeUpdateEntry entry : updates) {
if (entry.getArg() == arg) {
return true;
}
}
return false;
}

public void rollbackUpdate(InsnArg arg) {
updates.remove(arg);
updates.removeIf(updateEntry -> updateEntry.getArg() == arg);
}

public Map<InsnArg, ArgType> getUpdates() {
public List<TypeUpdateEntry> getUpdates() {
return updates;
}
}

0 comments on commit 68d074a

Please sign in to comment.