Remove recursive dummy arguments

bzip2
Graham 5 years ago
parent 2621e503f2
commit a7c1ae3597
  1. 51
      deob/src/main/java/dev/openrs2/deob/analysis/SourcedIntValue.java
  2. 20
      deob/src/main/java/dev/openrs2/deob/transform/DummyArgTransformer.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<MemberRef> source;
private final IntValue intValue;
public SourcedIntValue(DisjointSet.Partition<MemberRef> source, IntValue intValue) {
this.source = source;
this.intValue = intValue;
}
public DisjointSet.Partition<MemberRef> 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();
}
}

@ -18,7 +18,7 @@ import dev.openrs2.asm.classpath.Library;
import dev.openrs2.asm.transform.Transformer; import dev.openrs2.asm.transform.Transformer;
import dev.openrs2.deob.ArgRef; import dev.openrs2.deob.ArgRef;
import dev.openrs2.deob.analysis.IntInterpreter; 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 dev.openrs2.util.collect.DisjointSet;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type; import org.objectweb.asm.Type;
@ -115,15 +115,21 @@ public final class DummyArgTransformer extends Transformer {
} }
} }
private static ImmutableSet<Integer> union(Collection<IntValue> intValues) { private static ImmutableSet<Integer> union(DisjointSet.Partition<MemberRef> method, Collection<SourcedIntValue> intValues) {
var builder = ImmutableSet.<Integer>builder(); var builder = ImmutableSet.<Integer>builder();
for (var value : intValues) { for (var value : intValues) {
if (value.isUnknown()) { var intValue = value.getIntValue();
if (intValue.isUnknown()) {
return null; return null;
} }
builder.addAll(value.getIntValues()); var source = value.getSource();
if (source.equals(method)) {
continue;
}
builder.addAll(intValue.getIntValues());
} }
var set = builder.build(); var set = builder.build();
@ -134,7 +140,7 @@ public final class DummyArgTransformer extends Transformer {
return set; return set;
} }
private final Multimap<ArgRef, IntValue> argValues = HashMultimap.create(); private final Multimap<ArgRef, SourcedIntValue> argValues = HashMultimap.create();
private final Map<DisjointSet.Partition<MemberRef>, ImmutableSet<Integer>[]> constArgs = new HashMap<>(); private final Map<DisjointSet.Partition<MemberRef>, ImmutableSet<Integer>[]> constArgs = new HashMap<>();
private DisjointSet<MemberRef> inheritedMethodSets; private DisjointSet<MemberRef> inheritedMethodSets;
private int branchesSimplified, constantsInlined; private int branchesSimplified, constantsInlined;
@ -188,7 +194,7 @@ public final class DummyArgTransformer extends Transformer {
var args = Type.getArgumentTypes(invoke.desc).length; var args = Type.getArgumentTypes(invoke.desc).length;
for (int j = 0, k = 0; j < args; j++) { for (int j = 0, k = 0; j < args; j++) {
var arg = frame.getStack(stackSize - 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(); k += arg.getSize();
} }
break; break;
@ -297,7 +303,7 @@ public final class DummyArgTransformer extends Transformer {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
var parameters = (ImmutableSet<Integer>[]) new ImmutableSet<?>[args]; var parameters = (ImmutableSet<Integer>[]) new ImmutableSet<?>[args];
for (var i = 0; i < args; i++) { 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) { if (parameter != null) {
allUnknown = false; allUnknown = false;
} }

Loading…
Cancel
Save