From a56e2b27836956390ddd70e922ee12ea70a60db0 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 24 Jan 2016 13:22:10 -0500 Subject: [PATCH] Experimenting with using parallel executor for all mapping --- .../types/MappableInstruction.java | 2 + .../deob/attributes/code/instructions/If.java | 6 ++ .../attributes/code/instructions/If0.java | 6 ++ .../code/instructions/IfICmpEq.java | 16 ++++- .../code/instructions/InvokeInterface.java | 6 ++ .../code/instructions/InvokeSpecial.java | 6 ++ .../code/instructions/InvokeStatic.java | 6 ++ .../code/instructions/InvokeVirtual.java | 7 +++ .../code/instructions/PutField.java | 6 ++ .../code/instructions/PutStatic.java | 6 ++ .../rename/MappingExecutorUtil.java | 22 ++++++- .../net/runelite/deob/execution/Frame.java | 8 ++- .../java/net/runelite/deob/util/IdGen.java | 2 +- .../deobfuscators/rename/MapStaticTest.java | 62 ++++++++++++++++++- 14 files changed, 153 insertions(+), 8 deletions(-) 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 19f28200be..e3cd78ab4a 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 @@ -8,4 +8,6 @@ public interface MappableInstruction void map(ParallelExecutorMapping mappings, InstructionContext ctx, InstructionContext other); boolean isSame(InstructionContext thisIc, InstructionContext otherIc); + + boolean canMap(); } 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 af360771ad..7941d1f14e 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 @@ -152,4 +152,10 @@ public abstract class If extends Instruction implements JumpingInstruction, Comp { return thisIc.getInstruction().getClass() == otherIc.getInstruction().getClass(); } + + @Override + public boolean canMap() + { + return true; + } } 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 dbb6c11e2a..3adc73fcc1 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 @@ -155,4 +155,10 @@ public abstract class If0 extends Instruction implements JumpingInstruction, Com { return thisIc.getInstruction().getClass() == otherIc.getInstruction().getClass(); } + + @Override + public boolean canMap() + { + return true; + } } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IfICmpEq.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IfICmpEq.java index 6d37698835..d62bce4ccb 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IfICmpEq.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IfICmpEq.java @@ -3,6 +3,7 @@ package net.runelite.deob.attributes.code.instructions; import net.runelite.deob.attributes.code.InstructionType; import net.runelite.deob.attributes.code.Instructions; import net.runelite.deob.attributes.code.instruction.types.PushConstantInstruction; +import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.StackContext; @@ -34,7 +35,7 @@ public class IfICmpEq extends If return true; // check for other being ifeq and this has a constant 0 - if (otherIc.getInstruction() instanceof IfEq) + if (otherIc.getInstruction() instanceof IfEq || otherIc.getInstruction() instanceof IfNe) { StackContext s1 = thisIc.getPops().get(0), s2 = thisIc.getPops().get(1); @@ -45,4 +46,17 @@ public class IfICmpEq extends If return false; } + + @Override + public void map(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other) + { + if (other.getInstruction() instanceof IfNe) + { + super.mapOtherBranch(mapping, ctx, other); + } + else + { + super.map(mapping, ctx, other); + } + } } 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 6a0182ef36..981534b5f7 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 @@ -177,4 +177,10 @@ public class InvokeInterface extends Instruction implements InvokeInstruction { return thisIc.getInstruction().getClass() == otherIc.getInstruction().getClass(); } + + @Override + public boolean canMap() + { + return true; + } } 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 777df73e50..5ecfae0c77 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 @@ -178,4 +178,10 @@ public class InvokeSpecial extends Instruction implements InvokeInstruction { return thisIc.getInstruction().getClass() == otherIc.getInstruction().getClass(); } + + @Override + public boolean canMap() + { + return true; + } } 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 b7e0298943..c65c0ccc4f 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 @@ -180,4 +180,10 @@ public class InvokeStatic extends Instruction implements InvokeInstruction { return thisIc.getInstruction().getClass() == otherIc.getInstruction().getClass(); } + + @Override + public boolean canMap() + { + return true; + } } 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 12a406432a..df5d24b787 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 @@ -23,6 +23,7 @@ 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.MappingExecutorUtil; import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping; import net.runelite.deob.execution.Execution; import net.runelite.deob.execution.Value; @@ -187,4 +188,10 @@ public class InvokeVirtual extends Instruction implements InvokeInstruction { return thisIc.getInstruction().getClass() == otherIc.getInstruction().getClass(); } + + @Override + public boolean canMap() + { + return MappingExecutorUtil.isMappable(this); + } } 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 2555d0a801..3b1f2525f9 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 @@ -128,4 +128,10 @@ public class PutField extends Instruction implements SetFieldInstruction { return thisIc.getInstruction().getClass() == otherIc.getInstruction().getClass(); } + + @Override + public boolean canMap() + { + return true; + } } 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 eaa92b03f2..3f2cb7584b 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 @@ -110,4 +110,10 @@ public class PutStatic extends Instruction implements SetFieldInstruction { return thisIc.getInstruction().getClass() == otherIc.getInstruction().getClass(); } + + @Override + public boolean canMap() + { + return true; + } } 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 0cdc87ed59..c402682e99 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/rename/MappingExecutorUtil.java +++ b/src/main/java/net/runelite/deob/deobfuscators/rename/MappingExecutorUtil.java @@ -1,7 +1,5 @@ package net.runelite.deob.deobfuscators.rename; -import java.io.File; -import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -9,12 +7,12 @@ import java.util.stream.Collectors; import net.runelite.deob.ClassGroup; import net.runelite.deob.Method; import net.runelite.deob.attributes.code.Instruction; +import net.runelite.deob.attributes.code.instruction.types.InvokeInstruction; import net.runelite.deob.attributes.code.instruction.types.MappableInstruction; import net.runelite.deob.execution.Execution; import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.ParallellMappingExecutor; -import net.runelite.deob.util.JarUtil; public class MappingExecutorUtil { @@ -112,4 +110,22 @@ public class MappingExecutorUtil return mappings; } + + public static boolean isMappable(InvokeInstruction ii) + { + net.runelite.deob.pool.Method m = (net.runelite.deob.pool.Method) ii.getMethod(); + String className = m.getClassEntry().getName(); + + if (className.startsWith("java/")) + return false; +// switch (className) +// { +// case "java/lang/String": +// +// } +// if (m.getClassEntry().getName().equals("java/lang/String")) +// return false; + + return true; + } } diff --git a/src/main/java/net/runelite/deob/execution/Frame.java b/src/main/java/net/runelite/deob/execution/Frame.java index 035f9c3da0..6e55018c69 100644 --- a/src/main/java/net/runelite/deob/execution/Frame.java +++ b/src/main/java/net/runelite/deob/execution/Frame.java @@ -229,8 +229,12 @@ public class Frame if (execution.step && oldCur instanceof MappableInstruction) { - execution.paused = true; - return; + MappableInstruction mi = (MappableInstruction) oldCur; + if (mi.canMap()) + { + execution.paused = true; + return; + } } } } diff --git a/src/main/java/net/runelite/deob/util/IdGen.java b/src/main/java/net/runelite/deob/util/IdGen.java index d6d8d0bf56..884559d007 100644 --- a/src/main/java/net/runelite/deob/util/IdGen.java +++ b/src/main/java/net/runelite/deob/util/IdGen.java @@ -2,7 +2,7 @@ package net.runelite.deob.util; public class IdGen { - private volatile int cur = 1; + private int cur = 1; public synchronized int get() { 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 9cf23a5c04..566a830b3c 100644 --- a/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java +++ b/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java @@ -3,7 +3,12 @@ package net.runelite.deob.deobfuscators.rename; import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; import net.runelite.deob.ClassFile; import net.runelite.deob.ClassGroup; import net.runelite.deob.Method; @@ -24,6 +29,8 @@ public class MapStaticTest { "class40.method851", "class40.method803" }, { "class55.method1187", "class55.method1140" }, { "class107.method2427", "class107.method2344" }, + { "client.init", "client.init" }, + { "class162.method3270", "class86.method2020" }, }; // @Test @@ -68,10 +75,63 @@ 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("class162").findMethod("method3270"); + Method m2 = group2.findClass("class86").findMethod("method2020"); + + ParallelExecutorMapping mappings = MappingExecutorUtil.map(m1, m2); + + System.out.println("BEGIN OF MAPPING"); + for (Entry e : mappings.getMap().entrySet()) + { + System.out.println(e.getKey() + " <-> " + e.getValue()); + } + } + + //@Test + public void testAllMap() throws Exception + { + 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("init"); Method m2 = group2.findClass("client").findMethod("init"); - ParallelExecutorMapping mappings = MappingExecutorUtil.map(m1, m2); + HashMap all = new HashMap(); + map(all, new HashSet(), m1, m2); + + for (Entry e : all.entrySet()) + { + System.out.println(e.getKey() + " <-> " + e.getValue()); + } + System.out.println("Total " + all.size()); + } + + private void map(Map all, Set invalid, Method m1, Method m2) + { + if (all.containsKey(m1)) + return; + all.put(m1, m2); + + ParallelExecutorMapping mappings; + try + { + mappings = MappingExecutorUtil.map(m1, m2); + } + catch (Throwable ex) + { + System.err.println("Error mapping " + m1 + " to " + m2); + return; + } + + for (Entry e : mappings.getMap().entrySet()) + { + if (e.getKey() instanceof Method) + map(all, invalid, (Method) e.getKey(), (Method) e.getValue()); + else + all.put(e.getKey(), e.getValue()); + //assert all + //all.put(e.getKey(), e.getValue()); + } } //@Test