From 2bfbe1f239a2593b61acec64f885d02c48be9b2a Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 9 Feb 2016 19:45:39 -0500 Subject: [PATCH] This can map some but not nearly enough. Main problem seems to be the order of the packet handlers is scrambled, as well as their ids. Maybe try detecting/treating the packet handlers as separate "functions" and compare them by seeing if PME can run over both? Maybe try hardening PME mapper to fail more easily (eg setfield of field of two different types, or invoke with wrong signatures?), and then try and brute force methods in general. Can also map methods with unique signatures that are non static method<->method. client clinit? --- .../code/instructions/InvokeStatic.java | 2 +- .../code/instructions/InvokeVirtual.java | 2 +- .../rename/MappingExecutorUtil.java | 12 +++- .../runelite/deob/execution/Execution.java | 2 +- .../execution/ParallellMappingExecutor.java | 5 ++ .../deobfuscators/rename/MapStaticTest.java | 71 +++++++++++++------ 6 files changed, 69 insertions(+), 25 deletions(-) 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 7ed1133e68..af581b3b3f 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 @@ -48,7 +48,7 @@ public class InvokeStatic extends Instruction implements InvokeInstruction @Override public String toString() { - return "invokestatic " + method + " in " + this.getInstructions().getCode().getAttributes().getMethod(); + return "invokestatic " + method + " in " + this.getInstructions().getCode().getAttributes().getMethod() + " at pc 0x" + Integer.toHexString(this.getPc()); } @Override 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 4cc24c5507..dbd3f93a34 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 @@ -42,7 +42,7 @@ public class InvokeVirtual extends Instruction implements InvokeInstruction @Override public String toString() { - return "invokevirtual " + method + " in " + this.getInstructions().getCode().getAttributes().getMethod(); + return "invokevirtual " + method + " in " + this.getInstructions().getCode().getAttributes().getMethod() + " at pc 0x" + Integer.toHexString(this.getPc()); } @Override 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 72525e93d1..c344293a41 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/rename/MappingExecutorUtil.java +++ b/src/main/java/net/runelite/deob/deobfuscators/rename/MappingExecutorUtil.java @@ -117,6 +117,7 @@ public class MappingExecutorUtil { p1.getFrame().stop(); p2.getFrame().stop(); + e.paused = e2.paused = false; continue; // if (!hit) // { @@ -168,7 +169,16 @@ public class MappingExecutorUtil // continue; } - mi1.map(mappings, p1, p2); + try + { + mi1.map(mappings, p1, p2); + } + catch (Throwable ex) + { + p1.getFrame().stop(); + p2.getFrame().stop(); + ex.printStackTrace(); + } e.paused = e2.paused = false; } diff --git a/src/main/java/net/runelite/deob/execution/Execution.java b/src/main/java/net/runelite/deob/execution/Execution.java index 58aaa7b9a3..488ffdb9d3 100644 --- a/src/main/java/net/runelite/deob/execution/Execution.java +++ b/src/main/java/net/runelite/deob/execution/Execution.java @@ -88,7 +88,7 @@ public class Execution } } - private boolean hasInvoked(InstructionContext from, Method to) + public boolean hasInvoked(InstructionContext from, Method to) { // this is wrong because the called of the method of from // might be different, for building graph diff --git a/src/main/java/net/runelite/deob/execution/ParallellMappingExecutor.java b/src/main/java/net/runelite/deob/execution/ParallellMappingExecutor.java index ab8f5e8ddb..bcf7737766 100644 --- a/src/main/java/net/runelite/deob/execution/ParallellMappingExecutor.java +++ b/src/main/java/net/runelite/deob/execution/ParallellMappingExecutor.java @@ -278,6 +278,7 @@ public class ParallellMappingExecutor stepf1.otherStatic = stepf2; stepf2.otherStatic = stepf1; + doubleStep.add(stepf1.getMethod()); System.out.println("STEP " + stepf1.getMethod() + " <-> " + stepf2.getMethod()); return step(); @@ -288,6 +289,7 @@ public class ParallellMappingExecutor return true; } + public static Set doubleStep = new HashSet(); public InstructionContext getP1() { @@ -332,6 +334,9 @@ public class ParallellMappingExecutor if (isLoop(f)) return null; + + if (e.hasInvoked(i, to)) + return null; //assert e.methods.contains(to) == false; //e.methods.add(to); 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 be632f7e7c..04215c0391 100644 --- a/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java +++ b/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java @@ -15,6 +15,7 @@ import net.runelite.deob.ClassGroup; import net.runelite.deob.Deob; import net.runelite.deob.Field; import net.runelite.deob.Method; +import net.runelite.deob.execution.ParallellMappingExecutor; import net.runelite.deob.util.JarUtil; import org.junit.Assert; import org.junit.Test; @@ -120,6 +121,12 @@ public class MapStaticTest HashMap all = new HashMap(); List pmes = new ArrayList<>(); map(all, pmes, m1, m2); + + ParallelExecutorMapping finalm = new ParallelExecutorMapping(); + for (ParallelExecutorMapping pme : pmes) + finalm.merge(pme); + + summary(finalm); } //@Test @@ -141,6 +148,31 @@ public class MapStaticTest } } + private void summary(ParallelExecutorMapping finalm) + { + int fields = 0, staticMethod = 0, method = 0, total = 0; + for (Entry e : finalm.getMap().entrySet()) + { + System.out.println(e.getKey() + " <-> " + e.getValue()); + + Object o = e.getKey(); + if (o instanceof Field) + ++fields; + else if (o instanceof Method) + { + Method m = (Method) o; + + if (m.isStatic()) + ++staticMethod; + else + ++method; + } + + ++total; + } + System.out.println("Total " + total + ". " + fields + " fields, " + staticMethod + " static methods, " + method + " methods"); + } + @Test public void testAllMap() throws Exception { @@ -168,33 +200,20 @@ public class MapStaticTest for (ParallelExecutorMapping pme : pmes) finalm.merge(pme); - int fields = 0, staticMethod = 0, method = 0, total = 0; - for (Entry e : finalm.getMap().entrySet()) - { - System.out.println(e.getKey() + " <-> " + e.getValue()); - - Object o = e.getKey(); - if (o instanceof Field) - ++fields; - else if (o instanceof Method) - { - Method m = (Method) o; - - if (m.isStatic()) - ++staticMethod; - else - ++method; - } - - ++total; - } - System.out.println("Total " + total + ". " + fields + " fields, " + staticMethod + " static methods, " + method + " methods"); + summary(finalm); + print(group1); + System.out.println("db step " + ParallellMappingExecutor.doubleStep.size()); for (Method m : group1.findClass("client").getMethods().getMethods()) { if (!finalm.getMap().containsKey(m) && !m.isStatic()) System.out.println("missing " + m); } + for (Field m : group1.findClass("client").getFields().getFields()) + { + if (!finalm.getMap().containsKey(m)) + System.out.println("missing " + m); + } } public List getInitialMethods(ClassGroup group) @@ -242,6 +261,15 @@ public class MapStaticTest if (m1.getCode() == null) return; + // XXX this is the packet stuff.. + if (m1.getName().equals("vmethod3096")) + return; + + if (m1.getName().equals("method32")) + { + int i=5; + } + ParallelExecutorMapping mappings; try { @@ -249,6 +277,7 @@ public class MapStaticTest } catch (Throwable ex) { + ex.printStackTrace(); System.err.println("Error mapping " + m1 + " to " + m2); //if (test) // throw ex;