Commit 68d074ae authored by Skylot's avatar Skylot

fix: change type update collection to produce deterministic results

parent 0df5aa80
...@@ -18,7 +18,6 @@ import jadx.core.dex.instructions.args.InsnArg; ...@@ -18,7 +18,6 @@ import jadx.core.dex.instructions.args.InsnArg;
import jadx.core.dex.instructions.args.PrimitiveType; import jadx.core.dex.instructions.args.PrimitiveType;
import jadx.core.dex.instructions.args.RegisterArg; import jadx.core.dex.instructions.args.RegisterArg;
import jadx.core.dex.instructions.args.SSAVar; 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.InsnNode;
import jadx.core.dex.nodes.RootNode; import jadx.core.dex.nodes.RootNode;
import jadx.core.utils.exceptions.JadxOverflowException; import jadx.core.utils.exceptions.JadxOverflowException;
...@@ -57,11 +56,11 @@ public final class TypeUpdate { ...@@ -57,11 +56,11 @@ public final class TypeUpdate {
if (result == REJECT) { if (result == REJECT) {
return result; return result;
} }
Map<InsnArg, ArgType> updates = updateInfo.getUpdates(); List<TypeUpdateEntry> updates = updateInfo.getUpdates();
if (updates.isEmpty()) { if (updates.isEmpty()) {
return SAME; return SAME;
} }
updates.forEach(Typed::setType); updates.forEach(TypeUpdateEntry::apply);
return CHANGED; return CHANGED;
} }
......
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 + '}';
}
}
package jadx.core.dex.visitors.typeinference; package jadx.core.dex.visitors.typeinference;
import java.util.IdentityHashMap; import java.util.ArrayList;
import java.util.Map; import java.util.List;
import jadx.core.dex.instructions.args.ArgType; import jadx.core.dex.instructions.args.ArgType;
import jadx.core.dex.instructions.args.InsnArg; import jadx.core.dex.instructions.args.InsnArg;
public class TypeUpdateInfo { public class TypeUpdateInfo {
private final List<TypeUpdateEntry> updates = new ArrayList<>();
private final Map<InsnArg, ArgType> updates = new IdentityHashMap<>();
public void requestUpdate(InsnArg arg, ArgType changeType) { public void requestUpdate(InsnArg arg, ArgType changeType) {
updates.put(arg, changeType); updates.add(new TypeUpdateEntry(arg, changeType));
} }
public boolean isProcessed(InsnArg arg) { 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) { 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; return updates;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment