From a7c1ae35974e5a099900de39f10d33b11f934965 Mon Sep 17 00:00:00 2001 From: Graham Date: Sun, 29 Sep 2019 17:24:27 +0100 Subject: [PATCH] Remove recursive dummy arguments --- .../deob/analysis/SourcedIntValue.java | 51 +++++++++++++++++++ .../deob/transform/DummyArgTransformer.java | 20 +++++--- 2 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 deob/src/main/java/dev/openrs2/deob/analysis/SourcedIntValue.java diff --git a/deob/src/main/java/dev/openrs2/deob/analysis/SourcedIntValue.java b/deob/src/main/java/dev/openrs2/deob/analysis/SourcedIntValue.java new file mode 100644 index 0000000000..c40d18594d --- /dev/null +++ b/deob/src/main/java/dev/openrs2/deob/analysis/SourcedIntValue.java @@ -0,0 +1,51 @@ +package dev.openrs2.deob.analysis; + +import java.util.Objects; + +import com.google.common.base.MoreObjects; +import dev.openrs2.asm.MemberRef; +import dev.openrs2.util.collect.DisjointSet; + +public final class SourcedIntValue { + private final DisjointSet.Partition source; + private final IntValue intValue; + + public SourcedIntValue(DisjointSet.Partition source, IntValue intValue) { + this.source = source; + this.intValue = intValue; + } + + public DisjointSet.Partition getSource() { + return source; + } + + public IntValue getIntValue() { + return intValue; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + SourcedIntValue that = (SourcedIntValue) o; + return source.equals(that.source) && + intValue.equals(that.intValue); + } + + @Override + public int hashCode() { + return Objects.hash(source, intValue); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("source", source) + .add("intValue", intValue) + .toString(); + } +} diff --git a/deob/src/main/java/dev/openrs2/deob/transform/DummyArgTransformer.java b/deob/src/main/java/dev/openrs2/deob/transform/DummyArgTransformer.java index d93cd4ffa2..cd586d57d9 100644 --- a/deob/src/main/java/dev/openrs2/deob/transform/DummyArgTransformer.java +++ b/deob/src/main/java/dev/openrs2/deob/transform/DummyArgTransformer.java @@ -18,7 +18,7 @@ import dev.openrs2.asm.classpath.Library; import dev.openrs2.asm.transform.Transformer; import dev.openrs2.deob.ArgRef; import dev.openrs2.deob.analysis.IntInterpreter; -import dev.openrs2.deob.analysis.IntValue; +import dev.openrs2.deob.analysis.SourcedIntValue; import dev.openrs2.util.collect.DisjointSet; import org.objectweb.asm.Opcodes; import org.objectweb.asm.Type; @@ -115,15 +115,21 @@ public final class DummyArgTransformer extends Transformer { } } - private static ImmutableSet union(Collection intValues) { + private static ImmutableSet union(DisjointSet.Partition method, Collection intValues) { var builder = ImmutableSet.builder(); for (var value : intValues) { - if (value.isUnknown()) { + var intValue = value.getIntValue(); + if (intValue.isUnknown()) { return null; } - builder.addAll(value.getIntValues()); + var source = value.getSource(); + if (source.equals(method)) { + continue; + } + + builder.addAll(intValue.getIntValues()); } var set = builder.build(); @@ -134,7 +140,7 @@ public final class DummyArgTransformer extends Transformer { return set; } - private final Multimap argValues = HashMultimap.create(); + private final Multimap argValues = HashMultimap.create(); private final Map, ImmutableSet[]> constArgs = new HashMap<>(); private DisjointSet inheritedMethodSets; private int branchesSimplified, constantsInlined; @@ -188,7 +194,7 @@ public final class DummyArgTransformer extends Transformer { var args = Type.getArgumentTypes(invoke.desc).length; for (int j = 0, k = 0; j < args; j++) { var arg = frame.getStack(stackSize - args + j); - argValues.put(new ArgRef(invokedMethod, k), arg); + argValues.put(new ArgRef(invokedMethod, k), new SourcedIntValue(parentMethod, arg)); k += arg.getSize(); } break; @@ -297,7 +303,7 @@ public final class DummyArgTransformer extends Transformer { @SuppressWarnings("unchecked") var parameters = (ImmutableSet[]) new ImmutableSet[args]; for (var i = 0; i < args; i++) { - var parameter = union(argValues.get(new ArgRef(method, i))); + var parameter = union(method, argValues.get(new ArgRef(method, i))); if (parameter != null) { allUnknown = false; }