diff --git a/src/main/java/net/runelite/deob/attributes/code/instruction/types/MappableInstruction.java b/src/main/java/net/runelite/deob/attributes/code/instruction/types/MappableInstruction.java index af1bed491a..d42d15986e 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instruction/types/MappableInstruction.java +++ b/src/main/java/net/runelite/deob/attributes/code/instruction/types/MappableInstruction.java @@ -6,4 +6,6 @@ import net.runelite.deob.execution.InstructionContext; public interface MappableInstruction { void map(ParallelExecutorMapping mappings, InstructionContext ctx, InstructionContext other); + + boolean isSame(MappableInstruction other); } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/If.java b/src/main/java/net/runelite/deob/attributes/code/instructions/If.java index 333e969e85..15d7905fbc 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/If.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/If.java @@ -118,4 +118,10 @@ public abstract class If extends Instruction implements JumpingInstruction, Comp // we can map these if they are getfield instructions? } + + @Override + public boolean isSame(MappableInstruction other) + { + return this.getClass() == other.getClass(); + } } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/If0.java b/src/main/java/net/runelite/deob/attributes/code/instructions/If0.java index a67fe11b4c..839866bd60 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/If0.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/If0.java @@ -116,4 +116,10 @@ public abstract class If0 extends Instruction implements JumpingInstruction, Com branch1.other = branch2; branch2.other = branch1; } + + @Override + public boolean isSame(MappableInstruction other) + { + return this.getClass() == other.getClass(); + } } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeInterface.java b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeInterface.java index dcc4c5d5ca..fe547b6de9 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeInterface.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeInterface.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import net.runelite.deob.attributes.code.instruction.types.MappableInstruction; import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping; import net.runelite.deob.execution.Execution; import net.runelite.deob.execution.Value; @@ -170,4 +171,10 @@ public class InvokeInterface extends Instruction implements InvokeInstruction for (int i = 0; i < myMethods.size(); ++i) mapping.map(myMethods.get(i), otherMethods.get(i)); } + + @Override + public boolean isSame(MappableInstruction other) + { + return this.getClass() == other.getClass(); + } } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeSpecial.java b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeSpecial.java index 41303a95d5..15a22f4d58 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeSpecial.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeSpecial.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import net.runelite.deob.attributes.code.instruction.types.MappableInstruction; import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping; import net.runelite.deob.execution.Execution; import net.runelite.deob.execution.Value; @@ -165,4 +166,10 @@ public class InvokeSpecial extends Instruction implements InvokeInstruction for (int i = 0; i < myMethods.size(); ++i) mapping.map(myMethods.get(i), otherMethods.get(i)); } + + @Override + public boolean isSame(MappableInstruction other) + { + return this.getClass() == other.getClass(); + } } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeStatic.java b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeStatic.java index e72518c8fb..62fc29f1a5 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeStatic.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeStatic.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import net.runelite.deob.attributes.code.instruction.types.MappableInstruction; import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping; import net.runelite.deob.execution.Execution; import net.runelite.deob.execution.Value; @@ -173,4 +174,10 @@ public class InvokeStatic extends Instruction implements InvokeInstruction for (int i = 0; i < myMethods.size(); ++i) mapping.map(myMethods.get(i), otherMethods.get(i)); } + + @Override + public boolean isSame(MappableInstruction other) + { + return this.getClass() == other.getClass(); + } } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeVirtual.java b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeVirtual.java index 099e8ce342..70b7012832 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeVirtual.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeVirtual.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import net.runelite.deob.attributes.code.instruction.types.MappableInstruction; import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping; import net.runelite.deob.execution.Execution; import net.runelite.deob.execution.Value; @@ -174,4 +175,10 @@ public class InvokeVirtual extends Instruction implements InvokeInstruction for (int i = 0; i < myMethods.size(); ++i) mapping.map(myMethods.get(i), otherMethods.get(i)); } + + @Override + public boolean isSame(MappableInstruction other) + { + return this.getClass() == other.getClass(); + } } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/PutField.java b/src/main/java/net/runelite/deob/attributes/code/instructions/PutField.java index 024285e9e2..149db154a2 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/PutField.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/PutField.java @@ -17,6 +17,7 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import net.runelite.deob.Method; +import net.runelite.deob.attributes.code.instruction.types.MappableInstruction; import net.runelite.deob.attributes.code.instruction.types.PushConstantInstruction; import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping; @@ -121,4 +122,10 @@ public class PutField extends Instruction implements SetFieldInstruction mapping.map(myField, otherField); } + + @Override + public boolean isSame(MappableInstruction other) + { + return this.getClass() == other.getClass(); + } } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/PutStatic.java b/src/main/java/net/runelite/deob/attributes/code/instructions/PutStatic.java index 515624eaaf..117e0734fe 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/PutStatic.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/PutStatic.java @@ -17,6 +17,7 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import net.runelite.deob.Method; +import net.runelite.deob.attributes.code.instruction.types.MappableInstruction; import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping; public class PutStatic extends Instruction implements SetFieldInstruction @@ -103,4 +104,10 @@ public class PutStatic extends Instruction implements SetFieldInstruction mapping.map(myField, otherField); } + + @Override + public boolean isSame(MappableInstruction other) + { + return this.getClass() == other.getClass(); + } } diff --git a/src/main/java/net/runelite/deob/deobfuscators/rename/MappingExecutorUtil.java b/src/main/java/net/runelite/deob/deobfuscators/rename/MappingExecutorUtil.java index 8bb8bb4a74..2a30c15c34 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/rename/MappingExecutorUtil.java +++ b/src/main/java/net/runelite/deob/deobfuscators/rename/MappingExecutorUtil.java @@ -98,9 +98,10 @@ public class MappingExecutorUtil assert p1.getInstruction() instanceof MappableInstruction; assert p2.getInstruction() instanceof MappableInstruction; - assert p1.getInstruction().getClass().equals(p2.getInstruction().getClass()); - - MappableInstruction mi1 = (MappableInstruction) p1.getInstruction(); + MappableInstruction mi1 = (MappableInstruction) p1.getInstruction(), + mi2 = (MappableInstruction) p2.getInstruction(); + assert mi1.isSame(mi2); + //assert p1.getInstruction().getClass().equals(p2.getInstruction().getClass()); mi1.map(mappings, p1, p2); diff --git a/src/main/java/net/runelite/deob/deobfuscators/rename/Rename2.java b/src/main/java/net/runelite/deob/deobfuscators/rename/Rename2.java index 297a494c99..a04a8f1931 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/rename/Rename2.java +++ b/src/main/java/net/runelite/deob/deobfuscators/rename/Rename2.java @@ -309,6 +309,7 @@ public class Rename2 } } + static int pass = 0, asserts = 0; private void executeNewMethods() { for (Vertex v : g1.getVerticies()) @@ -318,13 +319,26 @@ public class Rename2 if (other == null || !(v.getObject() instanceof Method)) continue; - executeMethod((Method) v.getObject(), (Method) other.getObject()); + try + { + executeMethod((Method) v.getObject(), (Method) other.getObject()); + ++pass; + } + catch (Exception | AssertionError ex) + { + ex.printStackTrace(); + ++asserts; + } } } static int count = 0; + private Set executed = new HashSet<>(); private void executeMethod(Method m1, Method m2) { + if (executed.contains(m1)) + return; + executed.add(m1); // assert (m1.getCode() == null) == (m2.getCode() == null); // // if (m1.getCode() == null) @@ -343,9 +357,23 @@ public class Rename2 { if (e.getKey() instanceof Method) { + try + { + executeMethod((Method) e.getKey(), (Method) e.getValue()); + ++pass; + } + catch (Exception | AssertionError ex) + { + ex.printStackTrace(); + ++asserts; + } + Method m = (Method) e.getKey(); if (m.isStatic()) + { + // we can map execute these, though. continue; + } } Vertex v1 = g1.getVertexFor(e.getKey()), v2 = g2.getVertexFor(e.getValue()); @@ -433,13 +461,12 @@ public class Rename2 solve(); g1.getVerticies().forEach(v -> v.finish()); - //g2 + + executeNewMethods(); int after = g1.solved(null); System.out.println("After " + after); - executeNewMethods(); - if (before == after) break; } @@ -488,6 +515,7 @@ public class Rename2 // show(mappings); System.out.println("Solved methods "+ g1.solved(VertexType.METHOD) + ", solved fields " + g1.solved(VertexType.FIELD) + ", unsolved methods " +g1.unsolved(VertexType.METHOD) + ", unsolved fields " + g1.unsolved(VertexType.FIELD)); + System.out.println("asserts " + asserts + ", pass " + pass); //rename(mappings, two); diff --git a/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java b/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java index ec715f200e..0e65a0e7ec 100644 --- a/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java +++ b/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java @@ -28,8 +28,8 @@ public class MapStaticTest ClassGroup group1 = JarUtil.loadJar(new File("d:/rs/07/adamin1.jar")); ClassGroup group2 = JarUtil.loadJar(new File("d:/rs/07/adamin2.jar")); - Method m1 = group1.findClass("client").findMethod("vmethod3050"); - Method m2 = group2.findClass("client").findMethod("vmethod3007"); + Method m1 = group1.findClass("client").findMethod("vmethod3054"); + Method m2 = group2.findClass("client").findMethod("vmethod2973"); ParallelExecutorMapping mappings = MappingExecutorUtil.map(m1, m2); }